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) *}




Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.