looping information collections

Author Message

*- pike

Friday 18 August 2006 3:43:20 am

Hi

I must be completely missing the point here.

I have objects with information collectors. They collect information - I can see the collection in the admin (setup/collected info).

To set up some similar display in my design, I assumed a fetch would be available to get the Collected Information from an object or an attribute. Even a fetch to get all collections, or a fetch to get a count of all collections would do. Or some attribute on the object or attribute pointing to the collections of that object or attribute. But there isn't any of those ?

There is

- a fetch for an information collection given the collection id and object id
http://ez.no/doc/ez_publish/technical_manual/3_8/reference/modules/content/fetch_functions/collected_info_collection

- a count fetch for the number of information collections given a object id or attribute id
http://ez.no/doc/ez_publish/technical_manual/3_8/reference/modules/content/fetch_functions/collected_info_count

- a confusing kind of fetch used to do statistics given an attribute id
http://ez.no/doc/ez_publish/technical_manual/3_8/reference/modules/content/fetch_functions/collected_info_count_list

These are all quite useless in a template unless you happen to create a poll :-)

The admin page use a plain sql query behind the scenes, and tuck the results in a template variable before parsing the template. To mimic that, I have to create an extension.

Am I missing something ?

thanks,
*-pike

---------------
The class eZContentObjectTreeNode does.

*- pike

Friday 18 August 2006 5:33:24 am

Found a quick workaround tho

{let collections=array()
	numcollections=fetch( 'content', 'collected_info_count', hash( 'object_id', $node.object.id ))
	collidx=1
}
	{while lt($collections|count(),$numcollections)}
		<!-- checking collection {$collidx} -->
		{set $collection=fetch( 'content', 'collected_info_collection', 
			hash( 'collection_id',$collidx,'contentobject_id', $node.object.id ))}
		{if ne($collection, false())}
			<!-- collection is from this object -->
			{set $collections = $collections | append($collection) }
		{else}
			<!-- collection is not from this object -->
		{/if}
		{set $collidx=inc($collidx)}
	{/while}

      {* now do what you want with all $collections from this $node.object *}
      {foreach $collections as $collection}
            Collection {$collection.id}, {$collection.modified | datetime()  }
      {/foreach}

{/let}


What it does is way ugly .. it loops collidx from 1 to infinity and tries to get a collection from the current node with that collection id. It stops looping when the amount of collections found matches what the "collected_info_count" told us it should be.

Theoretically, this should never give an infinite loop. But I have to trust the inner workings of ezp for that.

---------------
The class eZContentObjectTreeNode does.

*- pike

Friday 18 August 2006 11:25:36 am

There is a little bug in the above

$collection=fetch( 'content', 'collected_info_collection', hash( 'collection_id',$collidx,'contentobject_id', $node.object.id )

returns collection $collidx regardless of $node.object.id, not false()
in ezp 3.7.6

since this 'feature' is not documented,
we should run the test ourself, using

 {if and($collection,eq($collection.contentobject_id, $node.object.id))}
	<!-- collection is from this object -->
       {set $collections = $collections | append($collection) }
{else}
       <!-- collection is not from this object -->
{/if}

and lament the wasted cpucycles ..

---------------
The class eZContentObjectTreeNode does.

*- pike

Friday 18 August 2006 11:34:55 am

after a long day of work, I finally have what I want - a (more or less generic) display of collections created by an object that has a few information collectors.

it seems to me the "information collection" mechanism is a bit underdeveloped. if you ask me, it might as well be skipped in a next version. The concept is confusing.

Looking back, I wish I had just created a plain content class and allow users to create objects of that class in a predestined folder, which
- is easier to setup
- has more options and flexibility
- is easier to understand for an admin

hope it helps anyone,
*pike

---------------
The class eZContentObjectTreeNode does.

*- pike

Friday 18 August 2006 3:15:11 pm

I've put the template source here, but it was too big too be usefull. Too bad there are no attachments in this forum. I felt like sharing today ! Now, I since can not remove this message, I'm typing this here. Ignore :-)

---------------
The class eZContentObjectTreeNode does.

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 30 2025 22:22:22
Script start
Timing: Jan 30 2025 22:22:22
Module start 'layout'
Timing: Jan 30 2025 22:22:22
Module start 'content'
Timing: Jan 30 2025 22:22:22
Module end 'content'
Timing: Jan 30 2025 22:22:22
Script end

Main resources:

Total runtime0.0480 sec
Peak memory usage4,096.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0056 588.1328151.2109
Module start 'layout' 0.00560.0048 739.3438220.7031
Module start 'content' 0.01030.0358 960.04691,001.8047
Module end 'content' 0.04620.0017 1,961.851637.9922
Script end 0.0479  1,999.8438 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00306.3220140.0002
Check MTime0.00142.9163140.0001
Mysql Total
Database connection0.00112.201110.0011
Mysqli_queries0.00306.339430.0010
Looping result0.00000.031310.0000
Template Total0.00122.610.0012
Template load0.00091.921810.0009
Template processing0.00030.627210.0003
Override
Cache load0.00061.313510.0006
General
dbfile0.015632.610680.0020
String conversion0.00000.018940.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

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

Time used to render debug report: 0.0001 secs