eZ Publish  [4.0]
eztemplatearithmeticoperator.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZTemplateArithmeticOperator class
00004 //
00005 // Created on: <06-Oct-2002 18:47:48 amos>
00006 //
00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00008 // SOFTWARE NAME: eZ Publish
00009 // SOFTWARE RELEASE: 4.0.x
00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS
00011 // SOFTWARE LICENSE: GNU General Public License v2.0
00012 // NOTICE: >
00013 //   This program is free software; you can redistribute it and/or
00014 //   modify it under the terms of version 2.0  of the GNU General
00015 //   Public License as published by the Free Software Foundation.
00016 //
00017 //   This program is distributed in the hope that it will be useful,
00018 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //   GNU General Public License for more details.
00021 //
00022 //   You should have received a copy of version 2.0 of the GNU General
00023 //   Public License along with this program; if not, write to the Free
00024 //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00025 //   MA 02110-1301, USA.
00026 //
00027 //
00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00029 //
00030 
00031 /*! \file eztemplatearithmeticoperator.php
00032 */
00033 
00034 /*!
00035   \class eZTemplateArithmeticOperator eztemplatearithmeticoperator.php
00036   \brief The class eZTemplateArithmeticOperator does
00037 
00038   sum
00039   sub
00040   inc
00041   dec
00042 
00043   div
00044   mod
00045   mul
00046 
00047   max
00048   min
00049 
00050   abs
00051   ceil
00052   floor
00053   round
00054 
00055   int
00056   float
00057 
00058   count
00059 
00060 */
00061 
00062 class eZTemplateArithmeticOperator
00063 {
00064     /*!
00065      Constructor
00066     */
00067     function eZTemplateArithmeticOperator()
00068     {
00069         $this->Operators = array( 'sum', 'sub', 'inc', 'dec',
00070                                   'div', 'mod', 'mul',
00071                                   'max', 'min',
00072                                   'abs', 'ceil', 'floor', 'round',
00073                                   'int', 'float',
00074                                   'count',
00075                                   'roman',
00076                                   'rand' );
00077         foreach ( $this->Operators as $operator )
00078         {
00079             $name = $operator . 'Name';
00080             $name[0] = $name[0] & "\xdf";
00081             $this->$name = $operator;
00082         }
00083     }
00084 
00085     /*!
00086      Returns the operators in this class.
00087     */
00088     function operatorList()
00089     {
00090         return $this->Operators;
00091     }
00092 
00093     function operatorTemplateHints()
00094     {
00095         return array( $this->SumName => array( 'input' => true,
00096                                                'output' => true,
00097                                                'parameters' => true,
00098                                                'element-transformation' => true,
00099                                                'transform-parameters' => true,
00100                                                'input-as-parameter' => true,
00101                                                'element-transformation-func' => 'basicTransformation'),
00102                       $this->SubName => array( 'input' => true,
00103                                                'output' => true,
00104                                                'parameters' => true,
00105                                                'element-transformation' => true,
00106                                                'transform-parameters' => true,
00107                                                'input-as-parameter' => true,
00108                                                'element-transformation-func' => 'basicTransformation'),
00109                       $this->MulName => array( 'input' => true,
00110                                                'output' => true,
00111                                                'parameters' => true,
00112                                                'element-transformation' => true,
00113                                                'transform-parameters' => true,
00114                                                'input-as-parameter' => true,
00115                                                'element-transformation-func' => 'basicTransformation'),
00116                       $this->DivName => array( 'input' => true,
00117                                                'output' => true,
00118                                                'parameters' => true,
00119                                                'element-transformation' => true,
00120                                                'transform-parameters' => true,
00121                                                'input-as-parameter' => true,
00122                                                'element-transformation-func' => 'basicTransformation'),
00123 
00124                       $this->IncName => array( 'input' => true,
00125                                                'output' => true,
00126                                                'parameters' => 1,
00127                                                'element-transformation' => true,
00128                                                'transform-parameters' => true,
00129                                                'input-as-parameter' => true,
00130                                                'element-transformation-func' => 'decIncTransformation'),
00131                       $this->DecName => array( 'input' => true,
00132                                                'output' => true,
00133                                                'parameters' => 1,
00134                                                'element-transformation' => true,
00135                                                'transform-parameters' => true,
00136                                                'input-as-parameter' => true,
00137                                                'element-transformation-func' => 'decIncTransformation'),
00138 
00139                       $this->ModName => array( 'input' => true,
00140                                                'output' => true,
00141                                                'parameters' => 2,
00142                                                'element-transformation' => true,
00143                                                'transform-parameters' => true,
00144                                                'input-as-parameter' => true,
00145                                                'element-transformation-func' => 'modTransformation'),
00146 
00147                       $this->MaxName => array( 'input' => true,
00148                                                'output' => true,
00149                                                'parameters' => true,
00150                                                'element-transformation' => true,
00151                                                'transform-parameters' => true,
00152                                                'input-as-parameter' => true,
00153                                                'element-transformation-func' => 'minMaxTransformation'),
00154                       $this->MinName => array( 'input' => true,
00155                                                'output' => true,
00156                                                'parameters' => true,
00157                                                'element-transformation' => true,
00158                                                'transform-parameters' => true,
00159                                                'input-as-parameter' => true,
00160                                                'element-transformation-func' => 'minMaxTransformation'),
00161 
00162                       $this->AbsName => array( 'input' => true,
00163                                                'output' => true,
00164                                                'parameters' => 1,
00165                                                'element-transformation' => true,
00166                                                'transform-parameters' => true,
00167                                                'input-as-parameter' => true,
00168                                                'element-transformation-func' => 'roundTransformation'),
00169                       $this->CeilName => array( 'input' => true,
00170                                                 'output' => true,
00171                                                 'parameters' => 1,
00172                                                 'element-transformation' => true,
00173                                                 'transform-parameters' => true,
00174                                                 'input-as-parameter' => true,
00175                                                 'element-transformation-func' => 'roundTransformation'),
00176                       $this->FloorName => array( 'input' => true,
00177                                                  'output' => true,
00178                                                  'parameters' => 1,
00179                                                  'element-transformation' => true,
00180                                                  'transform-parameters' => true,
00181                                                  'input-as-parameter' => true,
00182                                                  'element-transformation-func' => 'roundTransformation'),
00183                       $this->RoundName => array( 'input' => true,
00184                                                  'output' => true,
00185                                                  'parameters' => 1,
00186                                                  'element-transformation' => true,
00187                                                  'transform-parameters' => true,
00188                                                  'input-as-parameter' => true,
00189                                                  'element-transformation-func' => 'roundTransformation'),
00190 
00191                       $this->IntName => array( 'input' => true,
00192                                                'output' => true,
00193                                                'parameters' => 1,
00194                                                'element-transformation' => true,
00195                                                'transform-parameters' => true,
00196                                                'input-as-parameter' => true,
00197                                                'element-transformation-func' => 'castTransformation'),
00198                       $this->FloatName => array( 'input' => true,
00199                                                  'output' => true,
00200                                                  'parameters' => 1,
00201                                                  'element-transformation' => true,
00202                                                  'transform-parameters' => true,
00203                                                  'input-as-parameter' => true,
00204                                                  'element-transformation-func' => 'castTransformation'),
00205 
00206                       $this->RomanName => array( 'input' => true,
00207                                                  'output' => true,
00208                                                  'parameters' => 1,
00209                                                  'element-transformation' => true,
00210                                                  'transform-parameters' => true,
00211                                                  'input-as-parameter' => true,
00212                                                  'element-transformation-func' => 'romanTransformation'),
00213 
00214                       $this->CountName => array( 'input' => true,
00215                                                  'output' => true,
00216                                                  'parameters' => 1 ),
00217 
00218                       $this->RandName => array( 'input' => true,
00219                                                 'output' => true,
00220                                                 'parameters' => true,
00221                                                 'element-transformation' => true,
00222                                                 'transform-parameters' => true,
00223                                                 'input-as-parameter' => true,
00224                                                 'element-transformation-func' => 'randTransformation') );
00225     }
00226 
00227     function basicTransformation( $operatorName, &$node, $tpl, &$resourceData,
00228                                   $element, $lastElement, $elementList, $elementTree, &$parameters )
00229     {
00230         $values = array();
00231         $function = $operatorName;
00232         $divOperation = false;
00233         if ( $function == $this->SumName )
00234         {
00235             $operator = '+';
00236         }
00237         else if ( $function == $this->SubName )
00238         {
00239             $operator = '-';
00240         }
00241         else if ( $function == $this->MulName )
00242         {
00243             $operator = '*';
00244         }
00245         else
00246         {
00247             $divOperation = true;
00248             $operator = '/';
00249         }
00250 
00251         if ( count( $parameters ) == 0 )
00252             return false;
00253         $newElements = array();
00254 
00255         // Reorder parameters, dynamic elements first then static ones
00256         // Also combine multiple static ones into a single element
00257         $notInitialised = true;
00258         $staticResult = 0;
00259         $isStaticFirst = false;
00260         $allNumeric = true;
00261         $newParameters = array();
00262         $endParameters = array();
00263         $parameterIndex = 0;
00264         foreach ( $parameters as $parameter )
00265         {
00266             if ( !eZTemplateNodeTool::isStaticElement( $parameter ) )
00267             {
00268                 $allNumeric = false;
00269                 $endParameters[] = $parameter;
00270             }
00271             else
00272             {
00273                 $staticValue = eZTemplateNodeTool::elementStaticValue( $parameter );
00274                 if ( $notInitialised )
00275                 {
00276                     $staticResult = $staticValue;
00277                     if ( $parameterIndex == 0 )
00278                         $isStaticFirst = true;
00279                     $notInitialised = false;
00280                 }
00281                 else
00282                 {
00283                     if ( $function == 'sum' )
00284                     {
00285                         $staticResult += $staticValue;
00286                     }
00287                     else if ( $function == 'sub' )
00288                     {
00289                         if ( $isStaticFirst )
00290                             $staticResult -= $staticValue;
00291                         else
00292                             $staticResult += $staticValue;
00293                     }
00294                     else if ( $function == 'mul' )
00295                     {
00296                         $staticResult *= $staticValue;
00297                     }
00298                     else
00299                     {
00300                         if ( $isStaticFirst )
00301                             $staticResult /= $staticValue;
00302                         else
00303                             $staticResult *= $staticValue;
00304                     }
00305                 }
00306                 $isPreviousStatic = true;
00307             }
00308             ++$parameterIndex;
00309         }
00310 
00311         if ( $allNumeric )
00312         {
00313             $newElements[] = eZTemplateNodeTool::createNumericElement( $staticResult );
00314             return $newElements;
00315         }
00316         else
00317         {
00318             if ( !$notInitialised )
00319             {
00320                 if ( $isStaticFirst )
00321                     $newParameters[] = array( eZTemplateNodeTool::createNumericElement( $staticResult ) );
00322                 else
00323                     $endParameters[] = array( eZTemplateNodeTool::createNumericElement( $staticResult ) );
00324             }
00325             $newParameters = array_merge( $newParameters, $endParameters );
00326 
00327             $code = '';
00328             if ( $divOperation )
00329             {
00330                 $code .= '@';
00331             }
00332             $code .= '%output% =';
00333             $counter = 1;
00334             $index = 0;
00335 
00336             foreach ( $newParameters as $parameter )
00337             {
00338                 if ( $index > 0 )
00339                 {
00340                     $code .= " $operator";
00341                 }
00342                 if ( eZTemplateNodeTool::isStaticElement( $parameter ) )
00343                 {
00344                     $staticValue = eZTemplateNodeTool::elementStaticValue( $parameter );
00345                     if ( !is_numeric( $staticValue ) )
00346                         $staticValue = (int)$staticValue;
00347                     $code .= sprintf(" %F", $staticValue);
00348                 }
00349                 else
00350                 {
00351                     $code .= " %$counter%";
00352                     $values[] = $parameter;
00353                     ++$counter;
00354                 }
00355                 ++$index;
00356             }
00357             $code .= ";\n";
00358         }
00359         $knownType = 'integer';
00360         $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values, false, false, $knownType );
00361         return $newElements;
00362     }
00363 
00364     function minMaxTransformation( $operatorName, &$node, $tpl, &$resourceData,
00365                                    $element, $lastElement, $elementList, $elementTree, &$parameters )
00366     {
00367         $values = array();
00368         $function = $operatorName;
00369 
00370         if ( count( $parameters ) == 0 )
00371             return false;
00372         $newElements = array();
00373 
00374         /* Check if all variables are integers. This is for optimization */
00375         $staticResult = array();
00376         $allNumeric = true;
00377         foreach ( $parameters as $parameter )
00378         {
00379             if ( !eZTemplateNodeTool::isStaticElement( $parameter ) )
00380             {
00381                 $allNumeric = false;
00382             }
00383             else
00384             {
00385                 $staticResult[] = eZTemplateNodeTool::elementStaticValue( $parameter );
00386             }
00387         }
00388 
00389         if ( $allNumeric )
00390         {
00391             $staticResult = $function( $staticResult );
00392             return array( eZTemplateNodeTool::createNumericElement( $staticResult ) );
00393         }
00394         else
00395         {
00396             $code = "%output% = $function(";
00397             $counter = 1;
00398             foreach ( $parameters as $parameter )
00399             {
00400                 if ( $counter > 1 )
00401                 {
00402                     $code .= ', ';
00403                 }
00404                 $code .= " %$counter%";
00405                 $values[] = $parameter;
00406                 ++$counter;
00407             }
00408             $code .= ");\n";
00409         }
00410         $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values );
00411         return $newElements;
00412     }
00413 
00414     function modTransformation( $operatorName, &$node, $tpl, &$resourceData,
00415                                   $element, $lastElement, $elementList, $elementTree, &$parameters )
00416     {
00417         $values = array();
00418         if ( count( $parameters ) != 2 )
00419             return false;
00420         $newElements = array();
00421 
00422         if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) && eZTemplateNodeTool::isStaticElement( $parameters[1] ) )
00423         {
00424             $staticResult = eZTemplateNodeTool::elementStaticValue( $parameters[0] ) % eZTemplateNodeTool::elementStaticValue( $parameters[1] );
00425             return array( eZTemplateNodeTool::createNumericElement( $staticResult ) );
00426         }
00427         else
00428         {
00429             $code = "%output% = %1% % %2%;\n";
00430             $values[] = $parameters[0];
00431             $values[] = $parameters[1];
00432         }
00433         $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values );
00434         return $newElements;
00435     }
00436 
00437     function roundTransformation( $operatorName, &$node, $tpl, &$resourceData,
00438                                   $element, $lastElement, $elementList, $elementTree, &$parameters )
00439     {
00440         $values = array();
00441         $function = $operatorName;
00442 
00443         if ( count( $parameters ) != 1 )
00444             return false;
00445         $newElements = array();
00446 
00447         if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) )
00448         {
00449             $staticResult = $function( eZTemplateNodeTool::elementStaticValue( $parameters[0] ) );
00450             return array( eZTemplateNodeTool::createNumericElement( $staticResult ) );
00451         }
00452         else
00453         {
00454             $code = "%output% = $function( %1% );\n";
00455             $values[] = $parameters[0];
00456         }
00457         $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values );
00458         return $newElements;
00459     }
00460 
00461     function decIncTransformation( $operatorName, &$node, $tpl, &$resourceData,
00462                                   $element, $lastElement, $elementList, $elementTree, &$parameters )
00463     {
00464         $values = array();
00465         $function = $operatorName;
00466         $direction = $this->DecName == $function ? -1 : 1;
00467 
00468         if ( count( $parameters ) < 1 )
00469             return false;
00470         $newElements = array();
00471 
00472         if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) )
00473         {
00474             return array( eZTemplateNodeTool::createNumericElement( eZTemplateNodeTool::elementStaticValue( $parameters[0] ) + $direction ) );
00475         }
00476         else
00477         {
00478             $code = "%output% = %1% + $direction;\n";
00479             $values[] = $parameters[0];
00480         }
00481         $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values );
00482         return $newElements;
00483     }
00484 
00485     function castTransformation( $operatorName, &$node, $tpl, &$resourceData,
00486                                  $element, $lastElement, $elementList, $elementTree, &$parameters )
00487     {
00488         $values = array();
00489         if ( count( $parameters ) != 1 )
00490             return false;
00491         $newElements = array();
00492 
00493         if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) )
00494         {
00495             $staticResult = ( $operatorName == $this->IntName ) ? (int) eZTemplateNodeTool::elementStaticValue( $parameters[0] ) : (float) eZTemplateNodeTool::elementStaticValue( $parameters[0] );
00496             return array( eZTemplateNodeTool::createNumericElement( $staticResult ) );
00497         }
00498         else
00499         {
00500             $code = "%output% = ($operatorName)%1%;\n";
00501             $values[] = $parameters[0];
00502         }
00503         $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values );
00504         return $newElements;
00505     }
00506 
00507     function randTransformation( $operatorName, &$node, $tpl, &$resourceData,
00508                                  $element, $lastElement, $elementList, $elementTree, &$parameters )
00509     {
00510         $paramCount = count( $parameters );
00511         if ( $paramCount != 0 ||
00512              $paramCount != 2 )
00513         {
00514             return false;
00515         }
00516         $values = array();
00517         $newElements = array();
00518 
00519         if ( $paramCount == 2 )
00520         {
00521             $code = "%output% = mt_rand( %1%, %2% );\n";
00522             $values[] = $parameters[0];
00523             $values[] = $parameters[1];
00524         }
00525         else
00526         {
00527             $code = "%output% = mt_rand();\n";
00528         }
00529 
00530         $newElements[] = eZTemplateNodeTool::createCodePieceElement( $code, $values );
00531         return $newElements;
00532     }
00533 
00534     function romanTransformation( $operatorName, &$node, $tpl, &$resourceData,
00535                                   $element, $lastElement, $elementList, $elementTree, &$parameters )
00536     {
00537         $values = array();
00538         if ( count( $parameters ) != 1 )
00539             return false;
00540         $newElements = array();
00541 
00542         if ( eZTemplateNodeTool::isStaticElement( $parameters[0] ) )
00543         {
00544             $staticResult = $this->buildRoman( eZTemplateNodeTool::elementStaticValue( $parameters[0] ) );
00545             return array( eZTemplateNodeTool::createNumericElement( $staticResult ) );
00546         }
00547         else
00548         {
00549             return false;
00550         }
00551     }
00552 
00553     /*!
00554      \return true to tell the template engine that the parameter list exists per operator type.
00555     */
00556     function namedParameterPerOperator()
00557     {
00558         return true;
00559     }
00560 
00561     /*!
00562      See eZTemplateOperator::namedParameterList
00563     */
00564     function namedParameterList()
00565     {
00566         return array( $this->IncName => array( 'value' => array( 'type' => 'mixed',
00567                                                                  'required' => false,
00568                                                                  'default' => false ) ),
00569                       $this->DecName => array( 'value' => array( 'type' => 'mixed',
00570                                                                  'required' => false,
00571                                                                  'default' => false ) ),
00572                       $this->RomanName => array( 'value' => array( 'type' => 'mixed',
00573                                                                    'required' => false,
00574                                                                    'default' => false ) ) );
00575     }
00576 
00577     /*!
00578      \private
00579      \obsolete This function adds too much complexity, don't use it anymore
00580     */
00581     function numericalValue( $mixedValue )
00582     {
00583         if ( is_array( $mixedValue ) )
00584         {
00585             return count( $mixedValue );
00586         }
00587         else if ( is_object( $mixedValue ) )
00588         {
00589             if ( method_exists( $mixedValue, 'attributes' ) )
00590                 return count( $mixedValue->attributes() );
00591             else if ( method_exists( $mixedValue, 'numericalValue' ) )
00592                 return $mixedValue->numericalValue();
00593         }
00594         else if ( is_numeric( $mixedValue ) )
00595             return $mixedValue;
00596         else
00597             return 0;
00598     }
00599 
00600     /*!
00601      Examines the input value and outputs a boolean value. See class documentation for more information.
00602     */
00603     function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters,
00604                      $placement )
00605     {
00606         switch ( $operatorName )
00607         {
00608             case $this->RomanName:
00609             {
00610                 if ( $namedParameters['value'] !== false )
00611                     $value = $namedParameters['value'];
00612                 else
00613                     $value = $operatorValue;
00614 
00615                 $operatorValue = $this->buildRoman( $value );
00616             } break;
00617             case $this->CountName:
00618             {
00619                 if ( count( $operatorParameters ) == 0 )
00620                     $mixedValue =& $operatorValue;
00621                 else
00622                     $mixedValue = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement );
00623                 if ( count( $operatorParameters ) > 1 )
00624                     $tpl->extraParameters( $operatorName, count( $operatorParameters ), 1 );
00625                 if ( is_array( $mixedValue ) )
00626                     $operatorValue = count( $mixedValue );
00627                 else if ( is_object( $mixedValue ) and
00628                           method_exists( $mixedValue, 'attributes' ) )
00629                     $operatorValue = count( $mixedValue->attributes() );
00630                 else if ( is_string( $mixedValue ) )
00631                     $operatorValue = strlen( $mixedValue );
00632                 else
00633                     $operatorValue = 0;
00634             } break;
00635             case $this->SumName:
00636             {
00637                 $value = 0;
00638                 if ( $operatorValue !== null )
00639                     $value = $operatorValue;
00640                 for ( $i = 0; $i < count( $operatorParameters ); ++$i )
00641                 {
00642                     $tmpValue = $tpl->elementValue( $operatorParameters[$i], $rootNamespace, $currentNamespace, $placement );
00643                     $value += $tmpValue;
00644                 }
00645                 $operatorValue = $value;
00646             } break;
00647             case $this->SubName:
00648             {
00649                 $values = array();
00650                 if ( $operatorValue !== null )
00651                     $values[] = $operatorValue;
00652                 for ( $i = 0; $i < count( $operatorParameters ); ++$i )
00653                 {
00654                     $values[] = $tpl->elementValue( $operatorParameters[$i], $rootNamespace, $currentNamespace, $placement );
00655                 }
00656                 $value = 0;
00657                 if ( count( $values ) > 0 )
00658                 {
00659                     $value = $values[0];
00660                     for ( $i = 1; $i < count( $values ); ++$i )
00661                     {
00662                         $value -= $values[$i];
00663                     }
00664                 }
00665                 $operatorValue = $value;
00666             } break;
00667             case $this->IncName:
00668             case $this->DecName:
00669             {
00670                 if ( $operatorValue !== null )
00671                     $value = $operatorValue;
00672                 else
00673                     $value = $namedParameters['value'];
00674                 if ( $operatorName == $this->DecName )
00675                     --$value;
00676                 else
00677                     ++$value;
00678                 $operatorValue = $value;
00679             } break;
00680             case $this->DivName:
00681             {
00682                 if ( count( $operatorParameters ) < 1 )
00683                 {
00684                     $tpl->warning( $operatorName, 'Requires at least 1 parameter value', $placement );
00685                     return;
00686                 }
00687                 $i = 0;
00688                 if ( $operatorValue !== null )
00689                     $value = $operatorValue;
00690                 else
00691                     $value = $tpl->elementValue( $operatorParameters[$i++], $rootNamespace, $currentNamespace, $placement );
00692                 for ( ; $i < count( $operatorParameters ); ++$i )
00693                 {
00694                     $tmpValue = $tpl->elementValue( $operatorParameters[$i], $rootNamespace, $currentNamespace, $placement );
00695                     @$value /= $tmpValue;
00696                 }
00697                 $operatorValue = $value;
00698             } break;
00699             case $this->ModName:
00700             {
00701                 if ( count( $operatorParameters ) < 1 )
00702                 {
00703                     $tpl->warning( $operatorName, 'Missing dividend and divisor', $placement );
00704                     return;
00705                 }
00706                 if ( count( $operatorParameters ) == 1 )
00707                 {
00708                     $dividend = $operatorValue;
00709                     $divisor = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement );
00710                 }
00711                 else
00712                 {
00713                     $dividend = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement );
00714                     $divisor = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace, $placement );
00715                 }
00716                 $operatorValue = $dividend % $divisor;
00717             } break;
00718             case $this->MulName:
00719             {
00720                 if ( count( $operatorParameters ) < 1 )
00721                 {
00722                     $tpl->warning( $operatorName, 'Requires at least 1 parameter value', $placement );
00723                     return;
00724                 }
00725                 $i = 0;
00726                 if ( $operatorValue !== null )
00727                     $value = $operatorValue;
00728                 else
00729                     $value = $tpl->elementValue( $operatorParameters[$i++], $rootNamespace, $currentNamespace, $placement );
00730                 for ( ; $i < count( $operatorParameters ); ++$i )
00731                 {
00732                     $tmpValue = $tpl->elementValue( $operatorParameters[$i], $rootNamespace, $currentNamespace, $placement );
00733                     $value *= $tmpValue;
00734                 }
00735                 $operatorValue = $value;
00736             } break;
00737             case $this->MaxName:
00738             {
00739                 if ( count( $operatorParameters ) < 1 )
00740                 {
00741                     $tpl->warning( $operatorName, 'Requires at least 1 parameter value', $placement );
00742                     return;
00743                 }
00744                 $i = 0;
00745                 if ( $operatorValue !== null )
00746                 {
00747                     $value = $operatorValue;
00748                 }
00749                 else
00750                 {
00751                     $value = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement );
00752                     ++$i;
00753                 }
00754                 for ( ; $i < count( $operatorParameters ); ++$i )
00755                 {
00756                     $tmpValue = $tpl->elementValue( $operatorParameters[$i], $rootNamespace, $currentNamespace, $placement );
00757                     if ( $tmpValue > $value )
00758                         $value = $tmpValue;
00759                 }
00760                 $operatorValue = $value;
00761             } break;
00762             case $this->MinName:
00763             {
00764                 if ( count( $operatorParameters ) < 1 )
00765                 {
00766                     $tpl->warning( $operatorName, 'Requires at least 1 parameter value', $placement );
00767                     return;
00768                 }
00769                 $value = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement );
00770                 for ( $i = 1; $i < count( $operatorParameters ); ++$i )
00771                 {
00772                     $tmpValue = $tpl->elementValue( $operatorParameters[$i], $rootNamespace, $currentNamespace, $placement );
00773                     if ( $tmpValue < $value )
00774                         $value = $tmpValue;
00775                 }
00776                 $operatorValue = $value;
00777             } break;
00778             case $this->AbsName:
00779             case $this->CeilName:
00780             case $this->FloorName:
00781             case $this->RoundName:
00782             {
00783                 if ( count( $operatorParameters ) < 1 )
00784                     $value = $operatorValue;
00785                 else
00786                     $value = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement );
00787                 switch ( $operatorName )
00788                 {
00789                     case $this->AbsName:
00790                     {
00791                         $operatorValue = abs( $value );
00792                     } break;
00793                     case $this->CeilName:
00794                     {
00795                         $operatorValue = ceil( $value );
00796                     } break;
00797                     case $this->FloorName:
00798                     {
00799                         $operatorValue = floor( $value );
00800                     } break;
00801                     case $this->RoundName:
00802                     {
00803                         $operatorValue = round( $value );
00804                     } break;
00805                 }
00806             } break;
00807             case $this->IntName:
00808             {
00809                 if ( count( $operatorParameters ) > 0 )
00810                     $value = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement );
00811                 else
00812                     $value = $operatorValue;
00813                 $operatorValue = (int)$value;
00814             } break;
00815             case $this->FloatName:
00816             {
00817                 if ( count( $operatorParameters ) > 0 )
00818                     $value = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement );
00819                 else
00820                     $value = $operatorValue;
00821                 $operatorValue = (float)$value;
00822             } break;
00823             case $this->RandName:
00824             {
00825                 if ( count( $operatorParameters ) == 2 )
00826                 {
00827                     $operatorValue = mt_rand( $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace, $placement ),
00828                                               $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace, $placement ) );
00829                 }
00830                 else
00831                 {
00832                     $operatorValue = mt_rand();
00833                 }
00834             } break;
00835         }
00836     }
00837 
00838     /// \privatesection
00839 
00840     /*!
00841      \private
00842 
00843      Recursive function for calculating roman numeral from integer
00844 
00845      \param integer value
00846      \return next chars for for current value
00847     */
00848     function buildRoman( $value )
00849     {
00850         if ( $value >= 1000 )
00851             return 'M'.$this->buildRoman( $value - 1000 );
00852         if ( $value >= 500 )
00853         {
00854             if ( $value >= 900 )
00855                 return 'CM'.$this->buildRoman( $value - 900 );
00856             else
00857                 return 'D'.$this->buildRoman( $value - 500 );
00858         }
00859         if ( $value >= 100 )
00860         {
00861             if( $value >= 400 )
00862                 return 'CD'.$this->buildRoman( $value - 400 );
00863             else
00864                 return 'C'.$this->buildRoman( $value - 100 );
00865         }
00866         if ( $value >= 50 )
00867         {
00868             if( $value >= 90 )
00869                 return 'XC'.$this->buildRoman( $value - 90 );
00870             else
00871                 return 'L'.$this->buildRoman( $value - 50 );
00872         }
00873         if ( $value >= 10 )
00874         {
00875             if( $value >= 40 )
00876                 return 'XL'.$this->buildRoman( $value - 40 );
00877             else
00878                 return 'X'.$this->buildRoman( $value - 10 );
00879         }
00880         if ( $value >= 5 )
00881         {
00882             if( $value == 9 )
00883                 return 'IX'.$this->buildRoman( $value - 9 );
00884             else
00885                 return 'V'.$this->buildRoman( $value - 5 );
00886         }
00887         if ( $value >= 1 )
00888         {
00889             if( $value == 4 )
00890                 return 'IV'.$this->buildRoman( $value - 4 );
00891             else
00892                 return 'I'.$this->buildRoman( $value - 1 );
00893         }
00894         return '';
00895     }
00896 
00897     public $Operators;
00898     public $SumName;
00899     public $SubName;
00900     public $IncName;
00901     public $DecName;
00902 
00903     public $DivName;
00904     public $ModName;
00905     public $MulName;
00906 
00907     public $MaxName;
00908     public $MinName;
00909 
00910     public $AbsName;
00911     public $CeilName;
00912     public $FloorName;
00913     public $RoundName;
00914 
00915     public $IntName;
00916     public $FloatName;
00917 
00918     public $CountName;
00919 
00920     public $RomanName;
00921 
00922     public $RandName;
00923 }
00924 
00925 ?>