Exemplo n.º 1
0
 function process($tpl, &$textElements, $functionName, $functionChildren, $functionParameters, $functionPlacement, $rootNamespace, $currentNamespace)
 {
     /*
      * Check function parameters
      */
     $loop = new eZTemplateLoop(eZTemplateForFunction::FUNCTION_NAME, $functionParameters, $functionChildren, $functionPlacement, $tpl, $textElements, $rootNamespace, $currentNamespace);
     if (!$loop->initialized()) {
         return;
     }
     $loop->parseScalarParamValue('first_val', $firstVal, $firstValIsProxy);
     $loop->parseScalarParamValue('last_val', $lastVal, $lastValIsProxy);
     if ($firstValIsProxy || $lastValIsProxy) {
         $tpl->error(eZTemplateForFunction::FUNCTION_NAME, "Proxy objects ({section} loop iterators) cannot be used to specify the range \n" . "(this will lead to indefinite loops in compiled mode).\n" . "Please explicitly dereference the proxy object like this: \$current_node.item.");
         return;
     }
     $loop->parseParamVarName('loop_var', $loopVarName);
     if ($firstVal === null || $lastVal === null || !$loopVarName) {
         $tpl->error(eZTemplateForFunction::FUNCTION_NAME, "Wrong arguments passed.");
         return;
     }
     if (!is_numeric($firstVal) || !is_numeric($lastVal)) {
         $tpl->error(eZTemplateForFunction::FUNCTION_NAME, "Both 'from' and 'to' values can only be numeric.");
         return;
     }
     $loop->initLoopVariable($loopVarName);
     /*
      * Everything is ok, run the 'for' loop itself
      */
     for ($i = $firstVal; $firstVal < $lastVal ? $i <= $lastVal : $i >= $lastVal;) {
         // set loop variable
         $tpl->setVariable($loopVarName, $i, $rootNamespace);
         $loop->setSequenceVar();
         // set sequence variable (if specified)
         $loop->processDelimiter();
         $loop->resetIteration();
         if ($loop->processChildren()) {
             break;
         }
         // increment loop variable here for delimiter to be processed correctly
         $firstVal < $lastVal ? $i++ : $i--;
         $loop->incrementSequence();
     }
     // for
     $loop->cleanup();
 }