This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit ezplatform.com

eZ Community » Forums » Developer » Custom fetch or extendet sort
expandshrink

Custom fetch or extendet sort

Custom fetch or extendet sort

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 blunk.gif Emoticon

 

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..

Sunday 12 February 2012 7:28:19 pm

your solution is similar to my... it isn't a good solution... blunk.gif Emoticon

it's much more faster to sort it before it is in the template =)

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>

Saturday 10 March 2012 8:33:16 pm

It's a problem to fetch nodes I don't know blunk.gif Emoticon

I solved this Problem with an extendet attribute filter.

If it's finished I will publish it, but currently I have extremly less time...

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from