Forums / Setup & design / looping information collections

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.