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

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

Main resources:

Total runtime0.7259 sec
Peak memory usage4,096.0000 KB
Database Queries68

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0058 589.2891152.6563
Module start 'layout' 0.00580.0029 741.945339.5078
Module start 'content' 0.00870.7161 781.4531613.9375
Module end 'content' 0.72480.0011 1,395.390616.0938
Script end 0.7259  1,411.4844 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00320.4376160.0002
Check MTime0.00140.1878160.0001
Mysql Total
Database connection0.00090.124210.0009
Mysqli_queries0.664091.4717680.0098
Looping result0.00080.1089660.0000
Template Total0.696495.920.3482
Template load0.00250.340320.0012
Template processing0.694095.596220.3470
Template load and register function0.00040.052110.0004
states
state_id_array0.00090.123110.0009
state_identifier_array0.00060.081220.0003
Override
Cache load0.00210.2934430.0000
Sytem overhead
Fetch class attribute can translate value0.00080.107530.0003
Fetch class attribute name0.00120.170470.0002
XML
Image XML parsing0.00080.107730.0003
class_abstraction
Instantiating content class attribute0.00000.002180.0000
General
dbfile0.00080.1146170.0000
String conversion0.00000.001540.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
6content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
12content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
3content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
3content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 28
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs