Thursday 09 February 2012 2:49:54 pm - 4 replies
Hey ez friends,
I want to get sorted children from different nodes.
Node 1 with Child A, Child D and Child F
Node 2 with Child B and Child E
Node 3 with Child C and Child G
I want to get a list with A, B, C, D, E, F, G for example.
Currently I do a content tree fetch and get node 1, 2 and 3 by filtering the class_identifier, add the children to an array and sort it with a operator, but I want to do it in a nice way ![]()
I would be very happy if anybody could explain me how to sort the children of multiple nodes with a custom fetch or a extendet sort.
Sunday 12 February 2012 4:06:38 pm
Hi scrieler,
I had to do with a situation similar to yours.
I first installed these extension BC Array Sort you can download at http://projects.ez.no/bcarraysort
then handled the fetched items in this way..
{def $items = fetch('content', 'tree', hash('parent_node_id', 2, 'class_filter_type', 'include', 'class_filter_array' , array('identifier_class1', 'identifier_class2', 'identifier_class3') )) $filtered_items = array()} {foreach $items as $item} {set $filtered_items = $filtered_items|append(hash('date', $item.data_map.event_date.content.timestamp, 'ezobject', $item))} {/foreach} {set $filtered_items = $filtered_items|rsort()} {foreach $filtered_items as $index => $item} ...
The fetched classes had a common 'event_date' attribute.
I created an associative array which a filled, inside the first foreach statement, with this attribute I needed to sort those items (event_date), then applied the rsort operator to sort them and eventually displayed the already sorted array inside another foreach statement.
Hope this may be of help..
Saturday 10 March 2012 4:31:10 pm
Have you tried fetching the children separately with an array of parent node IDs rather than a single parent? Something like:
{def $items = fetch('content', 'tree', hash('parent_node_id', array(node1.node_id, node2.node_id, node3.node_id)...}
You would fetch node1, node2, node3 in one fetch and have your class filter and sort condition for the children in this second fetch.
I'm not sure how efficient two fetches would be compared with the above method.
<span style="color: #66cc66;">{</span><a href="http://doc.ez.no/def" target="ez_no_documentation"><span style="color: #0600ff;">def</span></a> <span style="color: #0000bb;">$items</span> <span style="color: #66cc66;">=</span> <a href="http://doc.ez.no/fetch" target="ez_no_documentation"><span style="color: #0600ff;">fetch</span></a><span style="color: #66cc66;">(</span><span style="color: #dd0000;">'content'</span>, <span style="color: #dd0000;">'tree'</span>, <a href="http://doc.ez.no/hash" target="ez_no_documentation"><span style="color: #0600ff;">hash</span></a><span style="color: #66cc66;">(</span><span style="color: #dd0000;">'{def $items = fetch('content', 'tree', hash('</span>
You must be logged in to post messages in this topic!