[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/eztemplate/classes/ -> eztemplatearithmeticoperator.php (source)

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


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7