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

eZ Community » Forums » Developer » fetch distinct contentobject

fetch distinct contentobject

fetch distinct contentobject

Friday 16 April 2010 1:08:59 pm - 6 replies


I need to fetch a list of eZContentObjectTreeNode

fetch( content, list, hash( parent_node_id, $node_id, ... ) )

But, I need to fetch only distinct eZContentObject. So, the main_node_only parameter remove too much nodes inside the subtree. So I can't filter the list after the request cause I need to build a page system and to set the OFFSET and LIMIT parameters.

I looking at the extended_attribute_filter, but it doesn't seem to allow a DISCTINCT clause.

Is there anyone know how to do this ?

Thanks in advance,


Friday 16 April 2010 1:30:04 pm

Hello Fabien,

Well, the main_node_only parameter should do what you are willing to do. What do you exactly mean by : "So, the main_node_only parameter remove too much nodes inside the subtree."


Friday 16 April 2010 2:23:13 pm

Hi Nicolas,

The main_node_only parameter only retrieve the main location (or main node, as you want).The main_node_only parameter doesn't retrieve the content objects which the main node is outside the sub-tree.

I need to fetch all content objects in the sub-tree. But without the main_node_only parameter the query probably fetch same content object many times (cause of different locations in the sub-tree).

I need: one content object → one node.

Thanks for you help Nicolas.



Monday 19 April 2010 9:26:22 am

Ok, got it.

I'd go for a custom fetch function here, overriding the content/list one (to preserve the many useful parameters ), going as follows :

  1. Run the content/list fetch function from PHP ( use the magic eZFunctionHandler::execute(...) ) with 'as_object' [1] set to false --> performances performances.
  2. Loop over the results, building an intermediate associative array, with contentobject IDs as keys. Will automatically filter out duplicates object IDs by overriding the keys.
  3. Return the array values, or replace them by fetched eZContentObjectTreeNode objects, on a one-by-one basis.

Hope it helps !

[1] :

Monday 19 April 2010 6:34:54 pm

Hi Nicolas,

It works fine!

  • A custom operator,
  • The request to fetch all nodes ( with the useful eZFunctionHandler::execute ),
  • The loop to filter duplicates content object,
  • An array slice to apply the offset and limit,
  • And return the clean list.

Good job!



Monday 19 April 2010 7:52:55 pm

{def $beer_count = fetch( 'beer', 'count', 
                           hash( 'from', 'Fabien',
                                 'to', 'Nicolas', 
                                 'where', 'at the ez conference in Berlin' 
{$beer_count|attribute( 'show', 1, false() )}
  Displays :
    beer_count (1)

happy.gif Emoticon

The eZ Conference :

See you there !

Tuesday 20 April 2010 10:17:05 am

OK Nicolas,

Hope to see you next time for a beer! happy.gif Emoticon




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

36 542 Users on board!

Forums menu

Proudly Developed with from