- Posts: 6
COMMUNITY FORUM
Suggestion or is there a better way
- Jochen Daum
-
Topic Author
- Offline
- New Member
Less
More
12 years 4 months ago #108623
by Jochen Daum
Suggestion or is there a better way was created by Jochen Daum
Hi,
in mod_k2_content, when you order items from multiple categories by ordering or reverse ordering, wouldn't it make sense to sort by category ordering first? Otherwise items with the same ordering number in different categories would come after each other.
Ie. instead of
the code could be
another addition would be to offer
- category, item ordering
- category reverse, item forward ordering
- category forward, item reverse ordering
- category reverse, item reverse ordering
The items editor doesn't allow to order across categories either, so I can't really achieve an ordered multi category listing with this module.
Apart from that a grouping can be done in a template.
Or have I missed a better way?
in mod_k2_content, when you order items from multiple categories by ordering or reverse ordering, wouldn't it make sense to sort by category ordering first? Otherwise items with the same ordering number in different categories would come after each other.
Ie. instead of
case 'order' :
if ($params->get('FeaturedItems') == '2')
$orderby = 'i.featured_ordering';
else
$orderby = 'i.ordering';
break;
case 'rorder' :
if ($params->get('FeaturedItems') == '2')
$orderby = 'i.featured_ordering DESC';
else
$orderby = 'i.ordering DESC';
break;
the code could be
case 'order' :
if ($params->get('FeaturedItems') == '2')
$orderby = 'c.ordering, i.featured_ordering';
else
$orderby = 'c.ordering, i.ordering';
break;
case 'rorder' :
if ($params->get('FeaturedItems') == '2')
$orderby = 'c.ordering desc, i.featured_ordering DESC';
else
$orderby = 'c.ordering desc, i.ordering DESC';
break;
another addition would be to offer
- category, item ordering
- category reverse, item forward ordering
- category forward, item reverse ordering
- category reverse, item reverse ordering
The items editor doesn't allow to order across categories either, so I can't really achieve an ordered multi category listing with this module.
Apart from that a grouping can be done in a template.
Or have I missed a better way?
Please Log in or Create an account to join the conversation.
- william white
-
- Offline
- Platinum Member
Less
More
- Posts: 3722
12 years 4 months ago #108624
by william white
Replied by william white on topic Re: Suggestion or is there a better way
I would try to use
array_multisort
in an override of mod_k2_content
array_multisort
in an override of mod_k2_content
Please Log in or Create an account to join the conversation.
- Jochen Daum
-
Topic Author
- Offline
- New Member
Less
More
- Posts: 6
12 years 3 months ago - 12 years 3 months ago #108625
by Jochen Daum
Replied by Jochen Daum on topic Re: Suggestion or is there a better way
Thanks William,
I left this open until the 2.6.4 update.
Here is my solution for anyone interested:
(insert just after
I left this open until the 2.6.4 update.
Here is my solution for anyone interested:
$collectCatId = array();
foreach ($items as $i => $object) {
$collectCatId[] = $object->catid;
}
$db =& JFactory::getDBO();
$sql = 'select distinct id, ordering from #__k2_categories where id in ('.implode(',',$collectCatId).')';
$db->setQuery($sql);
$catOrderPos = $db->loadAssocList('id');
foreach ($items as $i => $object) {
$sortByCatOrdering[$i] = $catOrderPos[$object->catid]['ordering'];
$sortByOrdering[$i] = $object->ordering;
}
array_multisort($sortByCatOrdering, SORT_ASC|SORT_NUMERIC, $sortByOrdering, SORT_ASC|SORT_NUMERIC, $items);
(insert just after
<?php if(count($items)):
Please Log in or Create an account to join the conversation.
- Jochen Daum
-
Topic Author
- Offline
- New Member
Less
More
- Posts: 6
12 years 3 months ago #108626
by Jochen Daum
Replied by Jochen Daum on topic Re: Suggestion or is there a better way
Have added some bug fixes.
Jochen
Jochen
Please Log in or Create an account to join the conversation.
- william white
-
- Offline
- Platinum Member
Less
More
- Posts: 3722
12 years 3 months ago #108627
by william white
Replied by william white on topic Re: Suggestion or is there a better way
which file are you changing? are you doing it in an override? if so, could you not just resort and restore the array that k2 prepares and passes to the output view?
Please Log in or Create an account to join the conversation.
- Jochen Daum
-
Topic Author
- Offline
- New Member
Less
More
- Posts: 6
12 years 3 months ago #108628
by Jochen Daum
Replied by Jochen Daum on topic Re: Suggestion or is there a better way
Hi,
yes this is in an override.
I'm sort of using the items that the K2 module produces, but the category ordering position is not part of the query, so I have to draw this in.
Kind Regards,
Jochen
yes this is in an override.
I'm sort of using the items that the K2 module produces, but the category ordering position is not part of the query, so I have to draw this in.
Kind Regards,
Jochen
Please Log in or Create an account to join the conversation.