Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

eztemplatesequencefunction.php
Go to the documentation of this file.
1 <?php
33 class eZTemplateSequenceFunction
34 {
35 public function __construct()
36 {
37 $this->SequenceName = 'sequence';
38 }
39
43 function functionList()
44 {
45 $functionList = array( $this->SequenceName );
46 return $functionList;
47 }
48
52 function functionTemplateHints()
53 {
54 return array( $this->SequenceName => array( 'parameters' => true,
55 'static' => false,
56 'transform-parameters' => true,
57 'tree-transformation' => true ) );
58 }
59
60 function templateNodeSequenceCreate( &$node, $tpl, $parameters, $nameValue, $loopValue )
61 {
62 $newNodes = array();
63
64 $newNodes[] = eZTemplateNodeTool::createVariableNode( false, $parameters['loop'],
65 eZTemplateNodeTool::extractFunctionNodePlacement( $node ),
66 array( 'text-result' => false ), '_array' );
67 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "\$GLOBALS['eZTemplateSequence-$nameValue'] = array( 'iteration' => 0, 'index' => 0, 'loop' => \$_array );\n" );
68 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "\$tpl->setVariable( 'item', \$GLOBALS['eZTemplateSequence-$nameValue']['loop'][0], \$namespace );\n" );
69 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "\$tpl->setVariable( 'iteration', 0, \$namespace );\n" );
70 $newNodes[] = eZTemplateNodeTool::createVariableUnsetNode( '_array' );
71
72 return $newNodes;
73 }
74
75 function templateNodeSequenceIterate( &$node, $tpl, $parameters, $nameValue )
76 {
77 $newNodes = array();
78
79 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "\$_seq_var = &\$GLOBALS['eZTemplateSequence-$nameValue'];\n" );
80 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "++\$_seq_var['index'];\n++\$_seq_var['iteration'];" );
81 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "if ( \$_seq_var['index'] >= count( \$_seq_var['loop'] ) )\n\t\$_seq_var['index'] = 0;\n" );
82 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "\$tpl->setVariable( 'item', \$_seq_var['loop'][\$_seq_var['index']], \$namespace );\n" );
83 $newNodes[] = eZTemplateNodeTool::createCodePieceNode( "\$tpl->setVariable( 'iteration', \$_seq_var['iteration'], \$namespace );\n" );
84
85 return $newNodes;
86 }
87
88 function templateNodeTransformation( $functionName, &$node,
89 $tpl, $parameters, $privateData )
90 {
91 $newNodes = array();
92 $namespaceValue = false;
93 $varName = 'match';
94
95 if ( !isset( $parameters['name'] ) )
96 return false;
97 if ( !eZTemplateNodeTool::isConstantElement( $parameters['name'] ) )
98 return false;
99
100 $nameData = $parameters['name'];
101 $nameValue = eZTemplateNodeTool::elementConstantValue( $nameData );
102
103 $nameSpaceNode = eZTemplateNodeTool::createCodePieceNode( "\$namespace = \$rootNamespace;
104 if ( \$namespace == '' )
105 \$namespace = \"$nameValue\";
106 else
107 \$namespace .= ':$nameValue';
108 " );
109 if ( isset( $parameters['loop'] ) )
110 {
111 $loopData = $parameters['loop'];
112 if ( !eZTemplateNodeTool::isConstantElement( $loopData ) )
113 return false;
114 $loopValue = eZTemplateNodeTool::elementConstantValue( $loopData );
115
116 $newNodes = $this->templateNodeSequenceCreate( $node, $tpl, $parameters, $nameValue, $loopValue );
117 }
118 else
119 {
120 $newNodes = $this->templateNodeSequenceIterate( $node, $tpl, $parameters, $nameValue );
121 }
122 $retNodes = array_merge( array( $nameSpaceNode ), $newNodes );
123 return $retNodes;
124 }
125
129 function process( $tpl, &$textElements, $functionName, $functionChildren, $functionParameters, $functionPlacement, $rootNamespace, $currentNamespace )
130 {
131 $params = $functionParameters;
132 $loop = null;
133 if ( isset( $params["loop"] ) )
134 {
135 $loop = $tpl->elementValue( $params["loop"], $rootNamespace, $currentNamespace, $functionPlacement );
136 }
137 if ( $loop !== null and !is_array( $loop ) )
138 {
139 $tpl->error( $functionName, "Can only loop arrays", $functionPlacement );
140 return;
141 }
142
143 $name = "";
144 if ( !isset( $params["name"] ) )
145 {
146 $tpl->missingParameter( $functionName, "name" );
147 return;
148 }
149 $name = $tpl->elementValue( $params["name"], $rootNamespace, $currentNamespace, $functionPlacement );
150 $seq_var =& $GLOBALS["eZTemplateSequence-$name"];
151 if ( !is_array( $seq_var ) )
152 $seq_var = array();
153 if ( $loop !== null )
154 {
155 $seq_var["loop"] = $loop;
156 $seq_var["iteration"] = 0;
157 $seq_var["index"] = 0;
158 }
159 else
160 {
161 $index =& $seq_var["index"];
162 $iteration =& $seq_var["iteration"];
163 ++$iteration;
164 ++$index;
165 if ( $index >= count( $seq_var["loop"] ) )
166 $index = 0 ;
167 }
168 $tpl->setVariable( "item", $seq_var["loop"][$seq_var["index"]], $tpl->mergeNamespace( $rootNamespace, $name ) );
169 $tpl->setVariable( "iteration", $seq_var["iteration"], $tpl->mergeNamespace( $rootNamespace, $name ) );
170 }
171
175 function hasChildren()
176 {
177 return false;
178 }
179
181 public $SequenceName;
182 }
183
184 ?>
eZTemplateNodeTool\createVariableNode
static createVariableNode( $originalNode=false, $variableData=false, $variablePlacement=false, $parameters=array(), $variableAssignmentName=false, $onlyExisting=false, $overWrite=true, $assignFromVariable=false, $rememberSet=false)
Definition: eztemplatenodetool.php:395
eZTemplateNodeTool\elementConstantValue
static elementConstantValue( $elements)
Definition: eztemplatenodetool.php:197
eZTemplateNodeTool\createVariableUnsetNode
static createVariableUnsetNode( $variableName, $parameters=array())
Definition: eztemplatenodetool.php:462
eZTemplateNodeTool\createCodePieceNode
static createCodePieceNode( $codePiece, $parameters=array())
Definition: eztemplatenodetool.php:457
eZTemplateNodeTool\extractFunctionNodePlacement
static extractFunctionNodePlacement(&$node)
Definition: eztemplatenodetool.php:660
eZTemplateNodeTool\isConstantElement
static isConstantElement( $elements)
Definition: eztemplatenodetool.php:233
eZTemplateSequenceFunction
Wrapped array looping in templates using function "sequence".
Definition: eztemplatesequencefunction.php:34
eZTemplateSequenceFunction\hasChildren
hasChildren()
Definition: eztemplatesequencefunction.php:175
eZTemplateSequenceFunction\process
process( $tpl, &$textElements, $functionName, $functionChildren, $functionParameters, $functionPlacement, $rootNamespace, $currentNamespace)
Definition: eztemplatesequencefunction.php:129
eZTemplateSequenceFunction\__construct
__construct()
Definition: eztemplatesequencefunction.php:35
eZTemplateSequenceFunction\functionTemplateHints
functionTemplateHints()
Definition: eztemplatesequencefunction.php:52
eZTemplateSequenceFunction\$SequenceName
$SequenceName
Name of sequence function.
Definition: eztemplatesequencefunction.php:181
eZTemplateSequenceFunction\templateNodeSequenceIterate
templateNodeSequenceIterate(&$node, $tpl, $parameters, $nameValue)
Definition: eztemplatesequencefunction.php:75
eZTemplateSequenceFunction\functionList
functionList()
Definition: eztemplatesequencefunction.php:43
eZTemplateSequenceFunction\templateNodeSequenceCreate
templateNodeSequenceCreate(&$node, $tpl, $parameters, $nameValue, $loopValue)
Definition: eztemplatesequencefunction.php:60
eZTemplateSequenceFunction\templateNodeTransformation
templateNodeTransformation( $functionName, &$node, $tpl, $parameters, $privateData)
Definition: eztemplatesequencefunction.php:88
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.