Forums / Developer / Take content from multiple objects and put it into one array

Take content from multiple objects and put it into one array

Author Message

nathaniel burbank

Tuesday 03 August 2004 7:45:34 pm

Okay, so I have a seemingly simple problem that I have spent the last 4 hours trying in vain to find a solution for.

I have a series of objects in one folder, that each have an integer attribute , that I want to graph. Basically, each object is going to be a data point on one graph.

Now, I successfully wrote a quick templet operator that takes an array from a template, and passes it on to a JP Graph script, which generate the graph as a png file, and sends its address back to the templet. so I thought the hard part was done!

The problem I am having is getting ez publish to grab just this one attribute from each object, and put it into one simple array. I thought there should be two ways to do this: one, some variant of the fetch function, that does not fetch the entire node but just the content I specify for each node, or two, a section loop construct that loops through each object and appends the necessary data onto one array. The fetch function seems like the simple way to go here, but I can't find any documentation on how to do this, so I tried the section/loop construct idea. After searching through the documentation, this is the best I could come up with, but it still does not work.

{let myvar=array()}
{section name=polldata loop=fetch('content','list',hash(parent_node_id,$node.node_id,sort_by,$node.sort_array))}
{let kd=$polldata:item.data_map.polloutcome.content myvar=$myvar|append($kd)}
{set-block scope=root variable=myvar}{$polldata:myvar}{/set-block}
{/let} 
{/section}
{jpgraph('test1', $myvar, 2) }
{/let} 

 

The problem is that $myvar is still empty, even after is has gone through the loop and should be full of values. Any suggestions on how to improve the code above, or use a fetch function to implement the desired functionality would be greatly appreciated... :-)

-Nathaniel
http://politicalretort.org/

Paul Forsyth

Wednesday 04 August 2004 12:13:49 am

Well, assuming your loop is working, try this:

{let myvar=array()}

  {section var=Polldata loop=fetch('content','list',hash(parent_node_id,$node.node_id,sort_by,$node.sort_array))}

    {let kd=$Polldata.data_map.polloutcome.content}
    {set myvar=$myvar|append($kd)}
    {/let} 

  {/section}

  {set-block scope=root variable=myvar}{$myvar}{/set-block}
  {jpgraph('test1', $myvar, 2) }

{/let} 

paul

--
http://www.visionwt.com

Paul Borgermans

Wednesday 04 August 2004 12:14:37 am

Hi Nathaniel

I stumbled upon the same thing: a template operator for Gantt charts with jpgraph. Finally the template operator we wrote fetches the data itself. If this is not desirable, you could use an <b>{append-block}</b> to a global string variable, seperated for instance with a ','. After the loop you can use the explode operator to create an array out of the string and pass this to your template operator.

http://ez.no/ez_publish/documentation/reference/template_operators/strings/explode

hth

-paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

Paul Borgermans

Wednesday 04 August 2004 12:19:41 am

@paul forsyth

Does appending in a loop works the way you stated? I'm puzzled by your code :-)

-paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

Paul Forsyth

Wednesday 04 August 2004 12:54:04 am

Its a rewrite of the original code but it should work.... ;) I havent tested it.

paul

nathaniel burbank

Wednesday 04 August 2004 12:43:45 pm

Thanks for all your help guys. I really appreciate it.

So the code that Paul ( Forsyth) posted still returns an empty array. I think my confusion here comes from a lack of a in-depth understanding of how exactly the different name spaces work, and how to get data from a loop to the (global?) namespace, so I can use it as a single array.

However, the post by Paul (Borgermans) about using the append-block command got me thinking, and I ended up this code:

 
{let myvar=array() 

  {section var=Polldata loop=fetch('content','list',hash(parent_node_id,$node.node_id,sort_by,$node.sort_array))}
{append-block scope=global variable=myvar}{$Polldata.data_map.polloutcome.content}{/append-block}
{/section}

{jpgraph ("test2", $myvar, 2)}
{/let}  
{/let}

And what do you know, but it works! :-)

Thanks to everyone who responded,
Nathaniel
--
http://politicalretort.org