Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

eztemplatearithmeticoperator.php
Go to the documentation of this file.
1 <?php
39 class eZTemplateArithmeticOperator
40 {
41 public function __construct()
42 {
43 $this->Operators = array( 'sum', 'sub', 'inc', 'dec',
44 'div', 'mod', 'mul',
45 'max', 'min',
46 'abs', 'ceil', 'floor', 'round',
47 'int', 'float',
48 'count',
49 'roman',
50 'rand' );
51 foreach ( $this->Operators as $operator )
52 {
53 $name = $operator . 'Name';
54 $name[0] = $name[0] & "\xdf";
55 $this->$name = $operator;
56 }
57 }
58
62 function operatorList()
63 {
64 return $this->Operators;
65 }
66
67 function operatorTemplateHints()
68 {
69 return array( $this->SumName => array( 'input' => true,
70 'output' => true,
71 'parameters' => true,
72 'element-transformation' => true,
73 'transform-parameters' => true,
74 'input-as-parameter' => true,
75 'element-transformation-func' => 'basicTransformation'),
76 $this->SubName => array( 'input' => true,
77 'output' => true,
78 'parameters' => true,
79 'element-transformation' => true,
80 'transform-parameters' => true,
81 'input-as-parameter' => true,
82 'element-transformation-func' => 'basicTransformation'),
83 $this->MulName => array( 'input' => true,
84 'output' => true,
85 'parameters' => true,
86 'element-transformation' => true,
87 'transform-parameters' => true,
88 'input-as-parameter' => true,
89 'element-transformation-func' => 'basicTransformation'),
90 $this->DivName => array( 'input' => true,
91 'output' => true,
92 'parameters' => true,
93 'element-transformation' => true,
94 'transform-parameters' => true,
95 'input-as-parameter' => true,
96 'element-transformation-func' => 'basicTransformation'),
97
98 $this->IncName => array( 'input' => true,
99 'output' => true,
100 'parameters' => 1,
101 'element-transformation' => true,
102 'transform-parameters' => true,
103 'input-as-parameter' => true,
104 'element-transformation-func' => 'decIncTransformation'),
105 $this->DecName => array( 'input' => true,
106 'output' => true,
107 'parameters' => 1,
108 'element-transformation' => true,
109 'transform-parameters' => true,
110 'input-as-parameter' => true,
111 'element-transformation-func' => 'decIncTransformation'),
112
113 $this->ModName => array( 'input' => true,
114 'output' => true,
115 'parameters' => 2,
116 'element-transformation' => true,
117 'transform-parameters' => true,
118 'input-as-parameter' => true,
119 'element-transformation-func' => 'modTransformation'),
120
121 $this->MaxName => array( 'input' => true,
122 'output' => true,
123 'parameters' => true,
124 'element-transformation' => true,
125 'transform-parameters' => true,
126 'input-as-parameter' => true,
127 'element-transformation-func' => 'minMaxTransformation'),
128 $this->MinName => array( 'input' => true,
129 'output' => true,
130 'parameters' => true,
131 'element-transformation' => true,
132 'transform-parameters' => true,
133 'input-as-parameter' => true,
134 'element-transformation-func' => 'minMaxTransformation'),
135
136 $this->AbsName => array( 'input' => true,
137 'output' => true,
138 'parameters' => 1,
139 'element-transformation' => true,
140 'transform-parameters' => true,
141 'input-as-parameter' => true,
142 'element-transformation-func' => 'roundTransformation'),
143 $this->CeilName => array( 'input' => true,
144 'output' => true,
145 'parameters' => 1,
146 'element-transformation' => true,
147 'transform-parameters' => true,
148 'input-as-parameter' => true,
149 'element-transformation-func' => 'roundTransformation'),
150 $this->FloorName => array( 'input' => true,
151 'output' => true,
152 'parameters' => 1,
153 'element-transformation' => true,
154 'transform-parameters' => true,
155 'input-as-parameter' => true,
156 'element-transformation-func' => 'roundTransformation'),
157 $this->RoundName => array( 'input' => true,
158 'output' => true,
159 'parameters' => 1,
160 'element-transformation' => true,
161 'transform-parameters' => true,
162 'input-as-parameter' => true,
163 'element-transformation-func' => 'roundTransformation'),
164
165 $this->IntName => array( 'input' => true,
166 'output' => true,
167 'parameters' => 1,
168 'element-transformation' => true,
169 'transform-parameters' => true,
170 'input-as-parameter' => true,
171 'element-transformation-func' => 'castTransformation'),
172 $this->FloatName => array( 'input' => true,
173 'output' => true,
174 'parameters' => 1,
175 'element-transformation' => true,
176 'transform-parameters' => true,
177 'input-as-parameter' => true,
178 'element-transformation-func' => 'castTransformation'),
179
180 $this->RomanName => array( 'input' => true,
181 'output' => true,
182 'parameters' => 1,
183 'element-transformation' => true,
184 'transform-parameters' => true,
185 'input-as-parameter' => true,
186 'element-transformation-func' => 'romanTransformation'),
187
188 $this->CountName => array( 'input' => true,
189 'output' => true,
190 'parameters' => 1 ),
191
192 $this->RandName => array( 'input' => true,
193 'output' => true,
194 'parameters' => true,
195 'element-transformation' => true,
196 'transform-parameters' => true,
197 'input-as-parameter' => true,
198 'element-transformation-func' => 'randTransformation') );
199 }
200
201 function basicTransformation( $operatorName, &$node, $tpl, &$resourceData,
202 $element, $lastElement, $elementList, $elementTree, &$parameters )
203 {
204 $values = array();
205 $function = $operatorName;
206 $divOperation = false;
207 if ( $function == $this->SumName )
208 {
209 $operator = '+';
210 }
211 else if ( $function == $this->SubName )
212 {
213 $operator = '-';
214 }
215 else if ( $function == $this->MulName )
216 {
217 $operator = '*';
218 }
219 else
220 {
221 $divOperation = true;
222 $operator = '/';
223 }
224
225 if ( count( $parameters ) == 0 )
226 return false;
227 $newElements = array();
228
229 // Reorder parameters, dynamic elements first then static ones
230 // Also combine multiple static ones into a single element
231 $notInitialised = true;
232 $staticResult = 0;
233 $isStaticFirst = false;
234 $allNumeric = true;
235 $newParameters = array();
236 $endParameters = array();
237 $parameterIndex = 0;
238 foreach ( $parameters as $parameter )
239 {
240 if ( !eZTemplateNodeTool::isConstantElement( $parameter ) )
241 {
242 $allNumeric = false;
243 $endParameters[] = $parameter;
244 }
245 else
246 {
247 $staticValue = (int) eZTemplateNodeTool::elementConstantValue( $parameter );
248 if ( $notInitialised )
249 {
250 $staticResult = $staticValue;
251 if ( $parameterIndex == 0 )
252 $isStaticFirst = true;
253 $notInitialised = false;
254 }
255 else
256 {
257 if ( $function == 'sum' )
258 {
259 $staticResult += $staticValue;
260 }
261 else if ( $function == 'sub' )
262 {
263 if ( $isStaticFirst )
264 $staticResult -= $staticValue;
265 else
266 $staticResult += $staticValue;
267 }
268 else if ( $function == 'mul' )
269 {
270 $staticResult *= $staticValue;
271 }
272 else
273 {
274 if ( $isStaticFirst )
275 $staticResult /= $staticValue;
276 else
277 $staticResult *= $staticValue;
278 }
279 }
280 $isPreviousStatic = true;
281 }
282 ++$parameterIndex;
283 }
284
285 if ( $allNumeric )
286 {
287 $newElements[] = eZTemplateNodeTool::createNumericElement( $staticResult );
288 return $newElements;
289 }
290 else
291 {
292 if ( !$notInitialised )
293 {
294 if ( $isStaticFirst )
295 $newParameters[] = array( eZTemplateNodeTool::createNumericElement( $staticResult ) );
296 else
297 $endParameters[] = array( eZTemplateNodeTool::createNumericElement( $staticResult ) );
298 }
299 $newParameters = array_merge( $newParameters, $endParameters );
300
301 $code = '';
302 if ( $divOperation )
303 {
304 $code .= '@';
305 }
306 $code .= '%output% =';
307 $counter = 1;
308 $index = 0;
309
310 foreach ( $newParameters as $parameter )
311 {
312 if ( $index > 0 )
313 {
314 $code .= " $operator";
315 }
316 if ( eZTemplateNodeTool::isConstantElement( $parameter ) )
317 {
318 $staticValue = eZTemplateNodeTool::elementConstantValue( $parameter );
319 if ( !is_numeric( $staticValue ) )
320 $staticValue = (int)$staticValue;
321 $code .= sprintf(" %F", $staticValue);
322 }
323 else
324 {
325 $code .= " %$counter%";
326 $values[] = $parameter;
327 ++$counter;
328 }
329 ++$index;
330 }
331 $code .= ";\n";
332 }
333 $knownType = 'integer';
334 $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values, false, false, $knownType );
335 return $newElements;
336 }
337
338 function minMaxTransformation( $operatorName, &$node, $tpl, &$resourceData,
339 $element, $lastElement, $elementList, $elementTree, &$parameters )
340 {
341 $values = array();
342 $function = $operatorName;
343
344 if ( count( $parameters ) == 0 )
345 return false;
346 $newElements = array();
347
348 /* Check if all variables are integers. This is for optimization */
349 $staticResult = array();
350 $allNumeric = true;
351 foreach ( $parameters as $parameter )
352 {
353 if ( !eZTemplateNodeTool::isConstantElement( $parameter ) )
354 {
355 $allNumeric = false;
356 }
357 else
358 {
359 $staticResult[] = eZTemplateNodeTool::elementConstantValue( $parameter );
360 }
361 }
362
363 if ( $allNumeric )
364 {
365 $staticResult = $function( $staticResult );
366 return array( eZTemplateNodeTool::createNumericElement( $staticResult ) );
367 }
368 else
369 {
370 $code = "%output% = $function(";
371 $counter = 1;
372 foreach ( $parameters as $parameter )
373 {
374 if ( $counter > 1 )
375 {
376 $code .= ', ';
377 }
378 $code .= " %$counter%";
379 $values[] = $parameter;
380 ++$counter;
381 }
382 $code .= ");\n";
383 }
384 $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values );
385 return $newElements;
386 }
387
388 function modTransformation( $operatorName, &$node, $tpl, &$resourceData,
389 $element, $lastElement, $elementList, $elementTree, &$parameters )
390 {
391 $values = array();
392 if ( count( $parameters ) != 2 )
393 return false;
394 $newElements = array();
395
396 if ( eZTemplateNodeTool::isConstantElement( $parameters[0] ) && eZTemplateNodeTool::isConstantElement( $parameters[1] ) )
397 {
398 $staticResult = eZTemplateNodeTool::elementConstantValue( $parameters[0] ) % eZTemplateNodeTool::elementConstantValue( $parameters[1] );
399 return array( eZTemplateNodeTool::createNumericElement( $staticResult ) );
400 }
401 else
402 {
403 $code = "%output% = %1% % %2%;\n";
404 $values[] = $parameters[0];
405 $values[] = $parameters[1];
406 }
407 $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values );
408 return $newElements;
409 }
410
411 function roundTransformation( $operatorName, &$node, $tpl, &$resourceData,
412 $element, $lastElement, $elementList, $elementTree, &$parameters )
413 {
414 $values = array();
415 $function = $operatorName;
416
417 if ( count( $parameters ) != 1 )
418 return false;
419 $newElements = array();
420
421 if ( eZTemplateNodeTool::isConstantElement( $parameters[0] ) )
422 {
423 $staticResult = $function( eZTemplateNodeTool::elementConstantValue( $parameters[0] ) );
424 return array( eZTemplateNodeTool::createNumericElement( $staticResult ) );
425 }
426 else
427 {
428 $code = "%output% = $function( %1% );\n";
429 $values[] = $parameters[0];
430 }
431 $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values );
432 return $newElements;
433 }
434
435 function decIncTransformation( $operatorName, &$node, $tpl, &$resourceData,
436 $element, $lastElement, $elementList, $elementTree, &$parameters )
437 {
438 $values = array();
439 $function = $operatorName;
440 $direction = $this->DecName == $function ? -1 : 1;
441
442 if ( count( $parameters ) < 1 )
443 return false;
444 $newElements = array();
445
446 if ( eZTemplateNodeTool::isConstantElement( $parameters[0] ) )
447 {
448 return array( eZTemplateNodeTool::createNumericElement( eZTemplateNodeTool::elementConstantValue( $parameters[0] ) + $direction ) );
449 }
450 else
451 {
452 $code = "%output% = %1% + $direction;\n";
453 $values[] = $parameters[0];
454 }
455 $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values );
456 return $newElements;
457 }
458
459 function castTransformation( $operatorName, &$node, $tpl, &$resourceData,
460 $element, $lastElement, $elementList, $elementTree, &$parameters )
461 {
462 $values = array();
463 if ( count( $parameters ) != 1 )
464 return false;
465 $newElements = array();
466
467 if ( eZTemplateNodeTool::isConstantElement( $parameters[0] ) )
468 {
469 $staticResult = ( $operatorName == $this->IntName ) ? (int) eZTemplateNodeTool::elementConstantValue( $parameters[0] ) : (float) eZTemplateNodeTool::elementConstantValue( $parameters[0] );
470 return array( eZTemplateNodeTool::createNumericElement( $staticResult ) );
471 }
472 else
473 {
474 $code = "%output% = ($operatorName)%1%;\n";
475 $values[] = $parameters[0];
476 }
477 $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values );
478 return $newElements;
479 }
480
481 function randTransformation( $operatorName, &$node, $tpl, &$resourceData,
482 $element, $lastElement, $elementList, $elementTree, &$parameters )
483 {
484 $paramCount = count( $parameters );
485 if ( $paramCount != 0 ||
486 $paramCount != 2 )
487 {
488 return false;
489 }
490 $values = array();
491 $newElements = array();
492
493 if ( $paramCount == 2 )
494 {
495 $code = "%output% = mt_rand( %1%, %2% );\n";
496 $values[] = $parameters[0];
497 $values[] = $parameters[1];
498 }
499 else
500 {
501 $code = "%output% = mt_rand();\n";
502 }
503
504 $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values );
505 return $newElements;
506 }
507
508 function romanTransformation( $operatorName, &$node, $tpl, &$resourceData,
509 $element, $lastElement, $elementList, $elementTree, &$parameters )
510 {
511 $values = array();
512 if ( count( $parameters ) != 1 )
513 return false;
514 $newElements = array();
515
516 if ( eZTemplateNodeTool::isConstantElement( $parameters[0] ) )
517 {
518 $staticResult = $this->buildRoman( eZTemplateNodeTool::elementConstantValue( $parameters[0] ) );
519 return array( eZTemplateNodeTool::createNumericElement( $staticResult ) );
520 }
521 else
522 {
523 return false;
524 }
525 }
526
530 function namedParameterPerOperator()
531 {
532 return true;
533 }
534
538 function namedParameterList()
539 {
540 return array( $this->IncName => array( 'value' => array( 'type' => 'mixed',
541 'required' => false,
542 'default' => false ) ),
543 $this->DecName => array( 'value' => array( 'type' => 'mixed',
544 'required' => false,
545 'default' => false ) ),
546 $this->RomanName => array( 'value' => array( 'type' => 'mixed',
547 'required' => false,
548 'default' => false ) ) );
549 }
550
555 function numericalValue( $mixedValue )
556 {
557 if ( is_array( $mixedValue ) )
558 {
559 return count( $mixedValue );
560 }
561 else if ( is_object( $mixedValue ) )
562 {
563 if ( method_exists( $mixedValue, 'attributes' ) )
564 return count( $mixedValue->attributes() );
565 else if ( method_exists( $mixedValue, 'numericalValue' ) )
566 return $mixedValue->numericalValue();
567 }
568 else if ( is_numeric( $mixedValue ) )
569 return $mixedValue;
570 else
571 return 0;
572 }
573
577 function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters,
578 $placement )
579 {
580 switch ( $operatorName )
581 {
582 case $this->RomanName:
583 {
584 if ( $namedParameters['value'] !== false )
585 $value = $namedParameters['value'];
586 else
587 $value = $operatorValue;
588
589 $operatorValue = $this->buildRoman( $value );
590 } break;
591 case $this->CountName:
592 {
593 if ( count( $operatorParameters ) == 0 )
594 $mixedValue =& $operatorValue;
595 else
596 $mixedValue = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement );
597 if ( count( $operatorParameters ) > 1 )
598 $tpl->extraParameters( $operatorName, count( $operatorParameters ), 1 );
599 if ( is_array( $mixedValue ) )
600 $operatorValue = count( $mixedValue );
601 else if ( is_object( $mixedValue ) and
602 method_exists( $mixedValue, 'attributes' ) )
603 $operatorValue = count( $mixedValue->attributes() );
604 else if ( is_string( $mixedValue ) )
605 $operatorValue = strlen( $mixedValue );
606 else
607 $operatorValue = 0;
608 } break;
609 case $this->SumName:
610 {
611 $value = 0;
612 if ( $operatorValue !== null )
613 $value = (int) $operatorValue;
614 for ( $i = 0; $i < count( $operatorParameters ); ++$i )
615 {
616 $tmpValue = $tpl->elementValue( $operatorParameters[$i], $rootNamespace, $currentNamespace, $placement );
617 $value += (int) $tmpValue;
618 }
619 $operatorValue = $value;
620 } break;
621 case $this->SubName:
622 {
623 $values = array();
624 if ( $operatorValue !== null )
625 $values[] = (int) $operatorValue;
626 for ( $i = 0; $i < count( $operatorParameters ); ++$i )
627 {
628 $values[] = $tpl->elementValue( $operatorParameters[$i], $rootNamespace, $currentNamespace, $placement );
629 }
630 $value = 0;
631 if ( count( $values ) > 0 )
632 {
633 $value = $values[0];
634 for ( $i = 1; $i < count( $values ); ++$i )
635 {
636 $value -= (int) $values[$i];
637 }
638 }
639 $operatorValue = $value;
640 } break;
641 case $this->IncName:
642 case $this->DecName:
643 {
644 if ( $operatorValue !== null )
645 $value = $operatorValue;
646 else
647 $value = $namedParameters['value'];
648 if ( $operatorName == $this->DecName )
649 --$value;
650 else
651 ++$value;
652 $operatorValue = $value;
653 } break;
654 case $this->DivName:
655 {
656 if ( count( $operatorParameters ) < 1 )
657 {
658 $tpl->warning( $operatorName, 'Requires at least 1 parameter value', $placement );
659 return;
660 }
661 $i = 0;
662 if ( $operatorValue !== null )
663 $value = (int) $operatorValue;
664 else
665 $value = (int) $tpl->elementValue( $operatorParameters[$i++], $rootNamespace, $currentNamespace, $placement );
666 for ( ; $i < count( $operatorParameters ); ++$i )
667 {
668 $tmpValue = $tpl->elementValue( $operatorParameters[$i], $rootNamespace, $currentNamespace, $placement );
669 if ( (int) $tmpValue == 0 )
670 $value = 0;
671 else
672 @$value /= (int) $tmpValue;
673
674
675 }
676 $operatorValue = $value;
677 } break;
678 case $this->ModName:
679 {
680 if ( count( $operatorParameters ) < 1 )
681 {
682 $tpl->warning( $operatorName, 'Missing dividend and divisor', $placement );
683 return;
684 }
685 if ( count( $operatorParameters ) == 1 )
686 {
687 $dividend = $operatorValue;
688 $divisor = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement );
689 }
690 else
691 {
692 $dividend = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement );
693 $divisor = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace, $placement );
694 }
695 $operatorValue = $dividend % $divisor;
696 } break;
697 case $this->MulName:
698 {
699 if ( count( $operatorParameters ) < 1 )
700 {
701 $tpl->warning( $operatorName, 'Requires at least 1 parameter value', $placement );
702 return;
703 }
704 $i = 0;
705 if ( $operatorValue !== null )
706 $value = $operatorValue;
707 else
708 $value = $tpl->elementValue( $operatorParameters[$i++], $rootNamespace, $currentNamespace, $placement );
709 for ( ; $i < count( $operatorParameters ); ++$i )
710 {
711 $tmpValue = $tpl->elementValue( $operatorParameters[$i], $rootNamespace, $currentNamespace, $placement );
712 $value *= (float) $tmpValue;
713 }
714 $operatorValue = $value;
715 } break;
716 case $this->MaxName:
717 {
718 if ( count( $operatorParameters ) < 1 )
719 {
720 $tpl->warning( $operatorName, 'Requires at least 1 parameter value', $placement );
721 return;
722 }
723 $i = 0;
724 if ( $operatorValue !== null )
725 {
726 $value = $operatorValue;
727 }
728 else
729 {
730 $value = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement );
731 ++$i;
732 }
733 for ( ; $i < count( $operatorParameters ); ++$i )
734 {
735 $tmpValue = $tpl->elementValue( $operatorParameters[$i], $rootNamespace, $currentNamespace, $placement );
736 if ( $tmpValue > $value )
737 $value = $tmpValue;
738 }
739 $operatorValue = $value;
740 } break;
741 case $this->MinName:
742 {
743 if ( count( $operatorParameters ) < 1 )
744 {
745 $tpl->warning( $operatorName, 'Requires at least 1 parameter value', $placement );
746 return;
747 }
748 $value = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement );
749 for ( $i = 1; $i < count( $operatorParameters ); ++$i )
750 {
751 $tmpValue = $tpl->elementValue( $operatorParameters[$i], $rootNamespace, $currentNamespace, $placement );
752 if ( $tmpValue < $value )
753 $value = $tmpValue;
754 }
755 $operatorValue = $value;
756 } break;
757 case $this->AbsName:
758 case $this->CeilName:
759 case $this->FloorName:
760 case $this->RoundName:
761 {
762 if ( count( $operatorParameters ) < 1 )
763 $value = $operatorValue;
764 else
765 $value = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement );
766 switch ( $operatorName )
767 {
768 case $this->AbsName:
769 {
770 $operatorValue = abs( $value );
771 } break;
772 case $this->CeilName:
773 {
774 $operatorValue = ceil( $value );
775 } break;
776 case $this->FloorName:
777 {
778 $operatorValue = floor( $value );
779 } break;
780 case $this->RoundName:
781 {
782 $operatorValue = round( $value );
783 } break;
784 }
785 } break;
786 case $this->IntName:
787 {
788 if ( count( $operatorParameters ) > 0 )
789 $value = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement );
790 else
791 $value = $operatorValue;
792 $operatorValue = (int)$value;
793 } break;
794 case $this->FloatName:
795 {
796 if ( count( $operatorParameters ) > 0 )
797 $value = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement );
798 else
799 $value = $operatorValue;
800 $operatorValue = (float)$value;
801 } break;
802 case $this->RandName:
803 {
804 if ( count( $operatorParameters ) == 2 )
805 {
806 $operatorValue = mt_rand( $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement ),
807 $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace, $placement ) );
808 }
809 else
810 {
811 $operatorValue = mt_rand();
812 }
813 } break;
814 }
815 }
816
818
827 function buildRoman( $value )
828 {
829 if ( $value >= 1000 )
830 return 'M'.$this->buildRoman( $value - 1000 );
831 if ( $value >= 500 )
832 {
833 if ( $value >= 900 )
834 return 'CM'.$this->buildRoman( $value - 900 );
835 else
836 return 'D'.$this->buildRoman( $value - 500 );
837 }
838 if ( $value >= 100 )
839 {
840 if( $value >= 400 )
841 return 'CD'.$this->buildRoman( $value - 400 );
842 else
843 return 'C'.$this->buildRoman( $value - 100 );
844 }
845 if ( $value >= 50 )
846 {
847 if( $value >= 90 )
848 return 'XC'.$this->buildRoman( $value - 90 );
849 else
850 return 'L'.$this->buildRoman( $value - 50 );
851 }
852 if ( $value >= 10 )
853 {
854 if( $value >= 40 )
855 return 'XL'.$this->buildRoman( $value - 40 );
856 else
857 return 'X'.$this->buildRoman( $value - 10 );
858 }
859 if ( $value >= 5 )
860 {
861 if( $value == 9 )
862 return 'IX'.$this->buildRoman( $value - 9 );
863 else
864 return 'V'.$this->buildRoman( $value - 5 );
865 }
866 if ( $value >= 1 )
867 {
868 if( $value == 4 )
869 return 'IV'.$this->buildRoman( $value - 4 );
870 else
871 return 'I'.$this->buildRoman( $value - 1 );
872 }
873 return '';
874 }
875
876 public $Operators;
877 public $SumName;
878 public $SubName;
879 public $IncName;
880 public $DecName;
881
882 public $DivName;
883 public $ModName;
884 public $MulName;
885
886 public $MaxName;
887 public $MinName;
888
889 public $AbsName;
890 public $CeilName;
891 public $FloorName;
892 public $RoundName;
893
894 public $IntName;
895 public $FloatName;
896
897 public $CountName;
898
899 public $RomanName;
900
901 public $RandName;
902 }
903
904 ?>
eZTemplateArithmeticOperator
The class eZTemplateArithmeticOperator does.
Definition: eztemplatearithmeticoperator.php:40
eZTemplateArithmeticOperator\minMaxTransformation
minMaxTransformation( $operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters)
Definition: eztemplatearithmeticoperator.php:338
eZTemplateArithmeticOperator\$RomanName
$RomanName
Definition: eztemplatearithmeticoperator.php:899
eZTemplateArithmeticOperator\$MaxName
$MaxName
Definition: eztemplatearithmeticoperator.php:886
eZTemplateArithmeticOperator\namedParameterList
namedParameterList()
Definition: eztemplatearithmeticoperator.php:538
eZTemplateArithmeticOperator\__construct
__construct()
Definition: eztemplatearithmeticoperator.php:41
eZTemplateArithmeticOperator\numericalValue
numericalValue( $mixedValue)
Definition: eztemplatearithmeticoperator.php:555
eZTemplateArithmeticOperator\roundTransformation
roundTransformation( $operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters)
Definition: eztemplatearithmeticoperator.php:411
eZTemplateArithmeticOperator\romanTransformation
romanTransformation( $operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters)
Definition: eztemplatearithmeticoperator.php:508
eZTemplateArithmeticOperator\modify
modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement)
Definition: eztemplatearithmeticoperator.php:577
eZTemplateArithmeticOperator\operatorTemplateHints
operatorTemplateHints()
Definition: eztemplatearithmeticoperator.php:67
eZTemplateArithmeticOperator\castTransformation
castTransformation( $operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters)
Definition: eztemplatearithmeticoperator.php:459
eZTemplateArithmeticOperator\randTransformation
randTransformation( $operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters)
Definition: eztemplatearithmeticoperator.php:481
eZTemplateArithmeticOperator\$DivName
$DivName
Definition: eztemplatearithmeticoperator.php:882
eZTemplateArithmeticOperator\$FloorName
$FloorName
Definition: eztemplatearithmeticoperator.php:891
eZTemplateArithmeticOperator\modTransformation
modTransformation( $operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters)
Definition: eztemplatearithmeticoperator.php:388
eZTemplateArithmeticOperator\operatorList
operatorList()
Definition: eztemplatearithmeticoperator.php:62
eZTemplateArithmeticOperator\$CountName
$CountName
Definition: eztemplatearithmeticoperator.php:897
eZTemplateArithmeticOperator\$SumName
$SumName
Definition: eztemplatearithmeticoperator.php:877
eZTemplateArithmeticOperator\$AbsName
$AbsName
Definition: eztemplatearithmeticoperator.php:889
eZTemplateArithmeticOperator\$Operators
$Operators
Definition: eztemplatearithmeticoperator.php:876
eZTemplateArithmeticOperator\$MinName
$MinName
Definition: eztemplatearithmeticoperator.php:887
eZTemplateArithmeticOperator\$SubName
$SubName
Definition: eztemplatearithmeticoperator.php:878
eZTemplateArithmeticOperator\$CeilName
$CeilName
Definition: eztemplatearithmeticoperator.php:890
eZTemplateArithmeticOperator\$FloatName
$FloatName
Definition: eztemplatearithmeticoperator.php:895
eZTemplateArithmeticOperator\$ModName
$ModName
Definition: eztemplatearithmeticoperator.php:883
eZTemplateArithmeticOperator\$IntName
$IntName
Definition: eztemplatearithmeticoperator.php:894
eZTemplateArithmeticOperator\$DecName
$DecName
Definition: eztemplatearithmeticoperator.php:880
eZTemplateArithmeticOperator\$RandName
$RandName
Definition: eztemplatearithmeticoperator.php:901
eZTemplateArithmeticOperator\$IncName
$IncName
Definition: eztemplatearithmeticoperator.php:879
eZTemplateArithmeticOperator\$MulName
$MulName
Definition: eztemplatearithmeticoperator.php:884
eZTemplateArithmeticOperator\$RoundName
$RoundName
Definition: eztemplatearithmeticoperator.php:892
eZTemplateArithmeticOperator\basicTransformation
basicTransformation( $operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters)
Definition: eztemplatearithmeticoperator.php:201
eZTemplateArithmeticOperator\buildRoman
buildRoman( $value)
Definition: eztemplatearithmeticoperator.php:827
eZTemplateArithmeticOperator\namedParameterPerOperator
namedParameterPerOperator()
Definition: eztemplatearithmeticoperator.php:530
eZTemplateArithmeticOperator\decIncTransformation
decIncTransformation( $operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters)
Definition: eztemplatearithmeticoperator.php:435
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\createNumericElement
static createNumericElement( $number, $variablePlacement=false)
Definition: eztemplatenodetool.php:89
eZTemplateNodeTool\isConstantElement
static isConstantElement( $elements)
Definition: eztemplatenodetool.php:233
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.