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

eZ debug

Timing: Jan 18 2025 19:38:08
Script start
Timing: Jan 18 2025 19:38:08
Module start 'content'
Timing: Jan 18 2025 19:38:08
Module end 'content'
Timing: Jan 18 2025 19:38:08
Script end

Main resources:

Total runtime0.1602 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.0062 587.9688180.7969
Module start 'content' 0.00620.0060 768.7656102.1016
Module end 'content' 0.01220.1479 870.8672531.9219
Script end 0.1601  1,402.7891 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00362.2658200.0002
Check MTime0.00150.9074200.0001
Mysql Total
Database connection0.00080.491310.0008
Mysqli_queries0.116072.40291410.0008
Looping result0.00140.89411390.0000
Template Total0.147692.110.1476
Template load0.00090.540510.0009
Template processing0.146791.561510.1467
Override
Cache load0.00060.367610.0006
Sytem overhead
Fetch class attribute can translate value0.00090.586110.0009
XML
Image XML parsing0.00030.158610.0003
General
dbfile0.00171.0627200.0001
String conversion0.00000.003030.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.0003 secs