Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

eztemplatecontroloperator.php
Go to the documentation of this file.
1 <?php
25 class eZTemplateControlOperator
26 {
33 public function __construct(
34 $condName = 'cond',
35 $firstSetName = 'first_set' )
36 {
37 $this->Operators = array( $condName, $firstSetName );
38 $this->CondName = $condName;
39 $this->FirstSetName = $firstSetName;
40 }
41
45 function operatorList()
46 {
47 return $this->Operators;
48 }
49
50 function operatorTemplateHints()
51 {
52 return array( $this->CondName => array( 'input' => false,
53 'output' => true,
54 'parameters' => true,
55 'element-transformation' => true,
56 'transform-parameters' => true,
57 'input-as-parameter' => false,
58 'element-transformation-func' => 'condTransform' ),
59 $this->FirstSetName => array( 'input' => false,
60 'output' => true,
61 'parameters' => true,
62 'element-transformation' => true,
63 'transform-parameters' => true,
64 'input-as-parameter' => false,
65 'element-transformation-func' => 'condTransform' ) );
66 }
67
68 function condTransform( $operatorName, &$node, $tpl, &$resourceData,
69 $element, $lastElement, $elementList, $elementTree, &$parameters )
70 {
71 switch( $operatorName )
72 {
73 case $this->CondName:
74 {
75 $paramCount = count( $parameters );
76 $clauseCount = floor( $paramCount / 2 );
77 $hasDefaultClause = ( $paramCount % 2 ) != 0;
78
79 if ( $paramCount == 1 )
80 {
81 return $parameters[0];
82 }
83
84 $values = array();
85 $code = '';
86 $spacing = 0;
87 $spacingCode = '';
88 for ( $i = 0; $i < $clauseCount; ++$i )
89 {
90 $prevSpacingCode = $spacingCode;
91 $spacingCode = str_repeat( " ", $spacing*4 );
92 if ( $i > 0 )
93 {
94 $code .= $prevSpacingCode . "else\n" . $prevSpacingCode . "{\n";
95 }
96
97 $values[] = $parameters[$i*2];
98 if ( $i > 0 )
99 {
100 $code .= $spacingCode . "%code" . count( $values ) . "%\n";
101 }
102 $code .= $spacingCode. 'if ( %' . count( $values ) . "% )\n" . $spacingCode . "{\n";
103
104 if ( !eZTemplateNodeTool::isConstantElement( $parameters[$i*2 + 1] ) )
105 {
106 $values[] = $parameters[$i*2 + 1];
107 $code .= ( $spacingCode . " %code" . count( $values ) . "%\n" .
108 $spacingCode . " %output% = %" . count( $values ) . "%;\n" );
109 }
110 else
111 {
112 $code .= $spacingCode . ' %output% = ' . eZPHPCreator::variableText( eZTemplateNodeTool::elementConstantValue( $parameters[$i*2 + 1] ), 0, 0, false ) . ';' . "\n";
113 }
114 $code .= $spacingCode . "}\n";
115 ++$spacing;
116 }
117 $bracketCount = $clauseCount - 1;
118 if ( $hasDefaultClause )
119 {
120 ++$bracketCount;
121 $values[] = $parameters[$paramCount - 1];
122 if ( $clauseCount > 0 )
123 {
124 $code .= $spacingCode . "else\n" . $spacingCode . "{\n" . $spacingCode . " %code" . count( $values ) . "%\n ";
125 }
126
127 $code .= $spacingCode . '%output% = %' . count( $values ) . "%;\n";
128 }
129 for ( $clauseIndex = 0; $clauseIndex < $bracketCount; ++$clauseIndex )
130 {
131 $spacingCode = str_repeat( " ", ( $bracketCount - $clauseIndex - 1 ) *4 );
132 $code .= $spacingCode . "}\n";
133 }
134
135 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) );
136 } break;
137
138 case $this->FirstSetName:
139 {
140 $values = array();
141 $code = '';
142 $spacing = 0;
143 $spacingCode = '';
144 $nestCount = 0;
145 for( $i = 0; $i < count( $parameters ); ++$i )
146 {
147 if ( $i != 0 )
148 {
149 $code .= "$spacingCode}\n" . $spacingCode . "else\n$spacingCode{\n";
150 }
151 $spacingCode = str_repeat( ' ', $spacing*4 );
152 ++$spacing;
153
154 if ( eZTemplateNodeTool::isConstantElement( $parameters[$i] ) )
155 {
156 $code .= "$spacingCode%output% = " . eZPHPCreator::variableText( eZTemplateNodeTool::elementConstantValue( $parameters[$i] ), 0, 0, false ) . ";\n";
157 break;
158 }
159 ++$nestCount;
160
161 $values[] = $parameters[$i];
162 $code .= ( $spacingCode . "%code" . count( $values ) . "%\n" .
163 $spacingCode . 'if ( isset( %' . count( $values ) . "% ) )\n" .
164 $spacingCode . "{\n" .
165 $spacingCode . " %output% = %" . count( $values ) . '%;' . "\n" );
166 }
167 for ( $i = 0; $i < $nestCount; ++$i )
168 {
169 $spacing = $nestCount - $i - 1;
170 $spacingCode = str_repeat( ' ', $spacing*4 );
171 $code .= $spacingCode . "}\n";
172 }
173
174 return array( eZTemplateNodeTool::createCodePieceElement( $code, $values ) );
175 } break;
176 }
177 }
178
182 function namedParameterPerOperator()
183 {
184 return true;
185 }
186
190 function namedParameterList()
191 {
192 return array();
193 }
194
198 function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$value, $namedParameters,
199 $placement )
200 {
201 switch ( $operatorName )
202 {
203 case $this->CondName:
204 {
205 $parameterCount = count( $operatorParameters );
206 $clauseCount = floor( $parameterCount / 2 );
207 $clauseMod = $parameterCount % 2;
208 $conditionSuccess = false;
209 for ( $i = 0; $i < $clauseCount; ++$i )
210 {
211 $condition = $tpl->elementValue( $operatorParameters[$i*2], $rootNamespace, $currentNamespace, $placement );
212 if ( $condition )
213 {
214 $body = $tpl->elementValue( $operatorParameters[$i*2 + 1], $rootNamespace, $currentNamespace, $placement );
215 $conditionSuccess = true;
216 $value = $body;
217 break;
218 }
219 }
220 if ( !$conditionSuccess and
221 $clauseMod > 0 )
222 {
223 $condition = $tpl->elementValue( $operatorParameters[count($operatorParameters) - 1], $rootNamespace, $currentNamespace, $placement );
224 if ( $condition )
225 {
226 $conditionSuccess = true;
227 $value = $condition;
228 }
229 }
230 } break;
231 case $this->FirstSetName:
232 {
233 if ( count( $operatorParameters ) > 0 )
234 {
235 for ( $i = 0; $i < count( $operatorParameters ); ++$i )
236 {
237 $operand = $tpl->elementValue( $operatorParameters[$i], $rootNamespace, $currentNamespace, $placement, true );
238 if ( $operand !== null )
239 {
240 $value = $operand;
241 return;
242 }
243 }
244 }
245 $value = null;
246 } break;
247 }
248 }
249
251 public $Operators;
252 public $CondName;
253 public $FirstSetName;
254 }
255
256 ?>
eZTemplateControlOperator
Operators for checking variable type.
Definition: eztemplatecontroloperator.php:26
eZTemplateControlOperator\$FirstSetName
$FirstSetName
Definition: eztemplatecontroloperator.php:253
eZTemplateControlOperator\__construct
__construct($condName='cond', $firstSetName='first_set')
Definition: eztemplatecontroloperator.php:33
eZTemplateControlOperator\namedParameterPerOperator
namedParameterPerOperator()
Definition: eztemplatecontroloperator.php:182
eZTemplateControlOperator\condTransform
condTransform( $operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters)
Definition: eztemplatecontroloperator.php:68
eZTemplateControlOperator\operatorList
operatorList()
Definition: eztemplatecontroloperator.php:45
eZTemplateControlOperator\$Operators
$Operators
The array of operators.
Definition: eztemplatecontroloperator.php:251
eZTemplateControlOperator\operatorTemplateHints
operatorTemplateHints()
Definition: eztemplatecontroloperator.php:50
eZTemplateControlOperator\namedParameterList
namedParameterList()
Definition: eztemplatecontroloperator.php:190
eZTemplateControlOperator\modify
modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$value, $namedParameters, $placement)
Definition: eztemplatecontroloperator.php:198
eZTemplateControlOperator\$CondName
$CondName
Definition: eztemplatecontroloperator.php:252
eZTemplateNodeTool\elementConstantValue
static elementConstantValue( $elements)
Definition: eztemplatenodetool.php:197
eZTemplateNodeTool\createCodePieceElement
static createCodePieceElement( $codePiece, $values=false, $placement=false, $tmpValues=false, $knownTypes=true)
Definition: eztemplatenodetool.php:437
eZTemplateNodeTool\isConstantElement
static isConstantElement( $elements)
Definition: eztemplatenodetool.php:233
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.