adding up the value of one specific attribute of all the children in one node

Author Message

Nicolas Heiringhoff

Monday 26 April 2004 4:10:21 am

We have a folder (Node ID 47) with the children A, B, C, D, E,...

A (Node ID 118) - B (Node ID 119) - C (Node ID 120) - D (Node ID 121) - E (Node ID 122)
all these nodes are objects of a class called 'frabo' with the attribute "umsatz" and attribute id 200

Our goal is to get the sum of all attributes with the attribute id 200.

With this code we can show all the integer-values of the atribute "umsatz" of all children in node 47

{let nodes=fetch( 'content', 'tree', hash( 'parent_node_id', 47 ) ) }

{section loop=$nodes}
<br />
{$:item.data_map.umsatz.data_int}
{/section}

{/let}

with the following code we can add two or more values together:

{let ergebnis=hash('wert 1', 6, 'wert 2', 4)}
{$ergebnis|sum}
{/let}

now we want to add all these "umsatz"-values together. we have tried for three days, but we can not get theses two codes working together. has anybody a solution for the problem?

thanx from germany

http://www.heiringhoff.de

Balazs Halasy

Monday 26 April 2004 4:36:49 am

Look at the code that is presented here:

http://ez.no/ez_publish/documentation/building_an_ez_publish_site/the_guestbook/creating_the_template

Feel free to copy & use it. If so: change the line that says

{set counter=$:counter|inc}

to something like this:

{set counter=$:counter|sum($:item.object.data_map.umsatz)}

Balazs

Nicolas Heiringhoff

Monday 26 April 2004 6:05:34 am

we have modified the code the way you suggested:


{* Grab all the guestbook entries. *}
{let name=test counter=0 children=fetch( content,
                                         list,
                                         hash( parent_node_id,
                                               $node.node_id,
                                               sort_by,
                                               $node.sort_array
                                             )
                                        )
                                       
                                        
}
 Value of counter at this point: {$:counter}<br />
 
<table>

{* Loop through all the entries. *}
{section loop=$:children}
<br />
    {* Increment the counter by one. *}
    
{set counter=$:counter|sum($:item.object.data_map.umsatz)}   


<tr><td>

        Umsatz value: <i>{$:item.object.data_map.umsatz.content|wash}</i>
    </td></tr>

{* End of loop. *}
{/section}

    <tr><td><hr /></td></tr>
</table>

<div class="center">
    total Umsatz: {$:counter}
</div>

{* Release the counter and the children variable. *}
{/let}

It returns the values of the 4 objects of the class "frabo" in node 47:
Umsatz value: 1

Umsatz value: 12500

Umsatz value: 20000

Umsatz value: 500000

but wenn the code should return the sum of the "total umsatz" , it returns:

total Umsatz: 24

now that is rather strange, because all we don?t know where this value '24' comes from.
the total umsatz should add up to 532 501.

http://www.heiringhoff.de

Nicolas Heiringhoff

Wednesday 28 April 2004 6:54:33 am

After two days we finally got it:

{let counter=0}
	
			{let nodes=fetch( 'content', 'tree', hash( 'parent_node_id', 47 ) ) }
        	{section loop=$nodes}
        
			{set counter=$:counter|sum($:item.data_map.umsatz.data_int,$counter)}		
			

			{/let}
	
			{/section}
			
<!-- hier wird das Ergebnis ausgegeben-->

			{$counter}
			
<!-- hier wird das Ergebnis ausgegeben-->
{/let}

http://www.heiringhoff.de

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

Main resources:

Total runtime0.8662 sec
Peak memory usage4,096.0000 KB
Database Queries60

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0056 589.5391152.6875
Module start 'layout' 0.00560.0029 742.226639.5234
Module start 'content' 0.00850.8562 781.7500565.9297
Module end 'content' 0.86470.0015 1,347.679716.0625
Script end 0.8662  1,363.7422 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00350.4059160.0002
Check MTime0.00140.1572160.0001
Mysql Total
Database connection0.00090.101510.0009
Mysqli_queries0.798692.1967600.0133
Looping result0.00060.0740580.0000
Template Total0.830295.820.4151
Template load0.00230.264320.0011
Template processing0.827995.569420.4139
Template load and register function0.00010.012010.0001
states
state_id_array0.00130.144610.0013
state_identifier_array0.00080.086820.0004
Override
Cache load0.00190.2219400.0000
Sytem overhead
Fetch class attribute can translate value0.00110.132320.0006
Fetch class attribute name0.00220.248660.0004
XML
Image XML parsing0.00200.235220.0010
class_abstraction
Instantiating content class attribute0.00000.002380.0000
General
dbfile0.00220.2557220.0001
String conversion0.00000.000740.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
4content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
4content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
11content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
3content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
6content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 30
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs