Forums / Developer / fetch distinct contentobject

fetch distinct contentobject

Author Message

Fabien Scantamburlo

Friday 16 April 2010 4:08:59 am

Hi,

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,

Fabien.

Nicolas Pastorino

Friday 16 April 2010 4:30:04 am

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

Cheers,

--
Nicolas Pastorino
Director Community - eZ
Member of the Community Project Board

eZ Publish Community on twitter: http://twitter.com/ezcommunity

t : http://twitter.com/jeanvoye
G+ : http://plus.tl/jeanvoye

Fabien Scantamburlo

Friday 16 April 2010 5:23:13 am

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.

Cheers,

Fabien.

Nicolas Pastorino

Monday 19 April 2010 12: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 !
Cheers,

[1] : http://ez.no/doc/ez_publish/technical_manual/4_x/reference/modules/content/fetch_functions/list

--
Nicolas Pastorino
Director Community - eZ
Member of the Community Project Board

eZ Publish Community on twitter: http://twitter.com/ezcommunity

t : http://twitter.com/jeanvoye
G+ : http://plus.tl/jeanvoye

Fabien Scantamburlo

Monday 19 April 2010 9:34:54 am

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!

Thanks,

Fabien.

Nicolas Pastorino

Monday 19 April 2010 10:52:55 am

{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)
*}

:)

The eZ Conference : http://share.ez.no/blogs/ez/ez-conference-2010-in-berlin-next-june

See you there !
Cheers,

--
Nicolas Pastorino
Director Community - eZ
Member of the Community Project Board

eZ Publish Community on twitter: http://twitter.com/ezcommunity

t : http://twitter.com/jeanvoye
G+ : http://plus.tl/jeanvoye

Fabien Scantamburlo

Tuesday 20 April 2010 1:17:05 am

OK Nicolas,

Hope to see you next time for a beer! :)

Cheers,

Fabien.