Forums / Developer / HOw to Replace a while loop ??

HOw to Replace a while loop ??

Author Message

ludo thomas

Wednesday 07 December 2005 1:46:36 am

Hi!
what i need:
if my node's class name is "spot", I want to fetch his parent until parent's class name ="geopositionnement".
if this parent class type is not what I want, I have to find the parent of the parent ...until the class type is what I need.(u follow me?)

in 3.6 you can say:

{if eq( $object.class_name, "Spot" )}
	


{let mynode=fetch(content,node,hash(node_id,$main_node_id))}
 
     
   {while ne($mynode.object.class_name,"Geopositionnement")}
	{set mynode=$mynode.object.main_node.parent}
	
	{/while}
{$mynode.object.class_name}
{/if}

this code works perfectly in 3.6 or 3.7 versions but how can i do this in a 3.5 version without using the while loop?

for the if, i say:

{section name=if show=eq( $object.class_name, "Spot")}

but i can't do somethig like a while loop...
plz help..

Clemens T

Wednesday 07 December 2005 8:46:12 am

Heya!

Here are some snippets:

{$top.name}

{section var=node loop=$top.children}
================
    {$node.name}
    {section var=obj loop=$node.children}

----------------
        {$obj.name}

{section var=el loop=$obj.object.list}
{$el}{delimiter}:{/delimiter}
{/section}

----------------
    {/section}

================
{/section}

{let selected_id_array=$attribute.content} 
{section var=Options loop=$attribute.class_content.options} 
{section-exclude match=$selected_id_array|contains( $Options.item.id )|not} {$Options.item.name|wash( xhtml )}
{delimiter}<br/>
{/delimiter}
{/section}
 {/let}

so basically it's the loop=.... what you need.

Have phun!
Greets,
Clemens
ps: just out of curiosity, why do you still code in 3.5?

ludo thomas

Thursday 08 December 2005 8:51:09 am

hi clemens...
thanks for your reply.

first:
i try to code a while loop in 3.5 because of the php server version, and because I try to make an extension that could be used by each ez versions...

2ndly:
I spend more than 3 days on this loop.
no more results....
I dont see anything I could use in your reply (sory).
you say to use loop=
but loop=what?
do you have more informations?
thx in advance.

Clemens T

Thursday 08 December 2005 4:56:54 pm

Ok, this code took me about 3 hours.. and lots of thinking.. because I'm not very familiar with the section, section-else code etc...(cause I started from 3.6) I've checked this code in 3.7, should work with 3.5 though.

Here is the solution:

{let node=fetch('content','node', hash('node_id','63'))}
{let nodetest=$node}
	{*loop as much as the depth of the current item of the tree, otherwise parent could be NULL*}
	{section loop=$node.depth}
		{switch match=$nodetest.object.class_name}
		{case match="Geopositionnement"}
			Geopositionnement: {$nodetest.object.class_name},{$nodetest.node_id}<br/>
			{*if the current class_name=Geopositionnement*}
			{set $nodetest=$nodetest.parent}
		{/case}
		{case}
			Not a Geopositionnement: {$nodetest.object.class_name},{$nodetest.node_id}<br/>
			{*the default case, if the current class_name != Geopositionnement*}
		{/case}
		{/switch}
	{/section}
{* at this point, $nodetest is filled with the last Geopositionnement in the tree, exactly the same as your code does (correct me if I'm wrong) *}
{/let}
{/let}

Greets and all the best,
Clemens
ps: please mark your topic title 'solved' if it's solved...

Clemens T

Friday 09 December 2005 3:18:08 am

Ok, this code does exactly the opposite of what you want... that's the only thing you got to fix..now it goes up in the tree, as long as the parent = Geopositionnement, you need to make it so that it goes up the tree until it reaches the Geopositionnement, well at least.. does not do another replace of the $nodetest by it's parent, I'd say.. use a $match variable, so you can control it if you already found a match.

Greets,
Clemens

ludo thomas

Friday 16 December 2005 12:37:32 am

thx a lot Clemens.
this code is right.....

{switch match=$object.class_name}

     {case match="Spot"}
{let node=fetch('content','node', hash('node_id',$main_node_id))}


{let nodetest=$node}


        {*loop as much as the depth of the current item of the tree, otherwise parent could be NULL*}


        {section  loop=$node.depth}


                {switch match=$nodetest.object.class_name}


                {case match="Geoposition"}




                        {*if the current class_name=Geoposition*}

						
                        


                {/case}


                {case}



					{set nodetest=$nodetest.parent}
                        {*the default case, if the current class_name != Geoposition*}


                
				{/case}
{/switch}

{* at this point, $nodetest is filled with the last Geopositionnement in the tree, exactly the same as your code does (correct me if I'm wrong) *}




eZ debug

Timing: Jan 18 2025 19:26:51
Script start
Timing: Jan 18 2025 19:26:51
Module start 'content'
Timing: Jan 18 2025 19:26:51
Module end 'content'
Timing: Jan 18 2025 19:26:51
Script end

Main resources:

Total runtime0.1774 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.0051 587.7109180.8359
Module start 'content' 0.00510.0062 768.5469101.9922
Module end 'content' 0.01130.1660 870.5391531.2734
Script end 0.1773  1,401.8125 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00341.8928200.0002
Check MTime0.00130.7560200.0001
Mysql Total
Database connection0.00060.361910.0006
Mysqli_queries0.128772.55801410.0009
Looping result0.00150.82111390.0000
Template Total0.165693.410.1656
Template load0.00080.447010.0008
Template processing0.164892.923010.1648
Override
Cache load0.00050.307210.0005
Sytem overhead
Fetch class attribute can translate value0.00120.650510.0012
XML
Image XML parsing0.00030.146010.0003
General
dbfile0.00422.3657200.0002
String conversion0.00000.003430.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.0001 secs