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.

eZ debug

Timing: Jan 17 2025 22:59:31
Script start
Timing: Jan 17 2025 22:59:31
Module start 'content'
Timing: Jan 17 2025 22:59:31
Module end 'content'
Timing: Jan 17 2025 22:59:31
Script end

Main resources:

Total runtime0.1423 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0056 587.7109180.8359
Module start 'content' 0.00560.0053 768.5469102.9609
Module end 'content' 0.01090.1313 871.5078530.5234
Script end 0.1422  1,402.0313 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00372.5906200.0002
Check MTime0.00130.9255200.0001
Mysql Total
Database connection0.00060.412410.0006
Mysqli_queries0.096467.76301410.0007
Looping result0.00120.86971390.0000
Template Total0.130992.010.1309
Template load0.00090.629510.0009
Template processing0.130091.339210.1300
Override
Cache load0.00060.438410.0006
Sytem overhead
Fetch class attribute can translate value0.00080.540410.0008
XML
Image XML parsing0.00020.162310.0002
General
dbfile0.00634.4354200.0003
String conversion0.00000.003530.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0002 secs