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.

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 02:15:47
Script start
Timing: Jan 18 2025 02:15:47
Module start 'layout'
Timing: Jan 18 2025 02:15:47
Module start 'content'
Timing: Jan 18 2025 02:15:47
Module end 'content'
Timing: Jan 18 2025 02:15:47
Script end

Main resources:

Total runtime0.7182 sec
Peak memory usage4,096.0000 KB
Database Queries70

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0047 587.9141152.6250
Module start 'layout' 0.00470.0022 740.539139.4453
Module start 'content' 0.00690.7100 779.9844604.9141
Module end 'content' 0.71680.0013 1,384.898420.1641
Script end 0.7181  1,405.0625 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00280.3899160.0002
Check MTime0.00130.1765160.0001
Mysql Total
Database connection0.00070.093010.0007
Mysqli_queries0.653590.9914700.0093
Looping result0.00050.0672680.0000
Template Total0.696697.020.3483
Template load0.00170.238220.0009
Template processing0.694896.749520.3474
Template load and register function0.00010.013410.0001
states
state_id_array0.00090.123410.0009
state_identifier_array0.00060.077120.0003
Override
Cache load0.00150.2128690.0000
Sytem overhead
Fetch class attribute can translate value0.00050.068720.0002
Fetch class attribute name0.00080.114690.0001
XML
Image XML parsing0.00080.117320.0004
class_abstraction
Instantiating content class attribute0.00000.0039140.0000
General
dbfile0.00070.0921220.0000
String conversion0.00000.001040.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
7content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
7content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
13content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
3content/datatype/view/ezxmltags/strong.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/strong.tplEdit templateOverride template
1content/datatype/view/ezxmltags/sup.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/sup.tplEdit templateOverride template
3content/datatype/view/ezxmltags/li.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/li.tplEdit templateOverride template
1content/datatype/view/ezxmltags/ol.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/ol.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1content/datatype/view/ezxmltags/link.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/link.tplEdit templateOverride template
1content/datatype/view/ezxmltags/emphasize.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/emphasize.tplEdit templateOverride template
1content/datatype/view/ezxmltags/ul.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/ul.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 44
 Number of unique templates used: 14

Time used to render debug report: 0.0002 secs