Esempio n. 1
0
 public function executeFunction(FunctionJob $function, ExecutionContext $context)
 {
     /* @var $argumentValue Value */
     $argumentValue = current($function->getArguments());
     $beforeSourceRow = $context->getCurrentSourceRow();
     $sum = 0;
     foreach ($context->getCurrentSourceSet() as $row) {
         $context->setCurrentSourceRow($row);
         $value = $this->valueResolver->resolveValue($argumentValue, $context);
         if (is_numeric($value)) {
             $sum += $value;
         }
     }
     $context->setCurrentSourceRow($beforeSourceRow);
     return $sum;
 }
Esempio n. 2
0
 public function executeFunction(FunctionJob $function, ExecutionContext $context)
 {
     /* @var $result SelectResult */
     $result = $this->resultSet;
     /* @var $argumentValue Value */
     $argumentValue = current($function->getArguments());
     $count = 0;
     $beforeSourceRow = $context->getCurrentSourceRow();
     foreach ($context->getCurrentSourceSet() as $row) {
         $context->setCurrentSourceRow($row);
         $value = $this->valueResolver->resolveValue($argumentValue);
         if (!is_null($value)) {
             $count++;
         }
     }
     $context->setCurrentSourceRow($beforeSourceRow);
     return $count;
 }
Esempio n. 3
0
 public function resolveFunction(FunctionJob $functionJob, ExecutionContext $context)
 {
     $functionName = $functionJob->getName();
     $classNameFunctionPart = str_replace("_", " ", strtolower($functionName));
     $classNameFunctionPart = ucwords($classNameFunctionPart);
     $classNameFunctionPart = str_replace(" ", "", $classNameFunctionPart);
     $className = "\\Addiks\\PHPSQL\\{{$classNameFunctionPart}}";
     if (!class_exists($className)) {
         throw new ErrorException("Unknown or unimplemented function '{$functionName}' called! (No class '{$className}' found!)");
     }
     /* @var $functionExecuter FunctionResolver */
     $functionExecuter = new $className();
     $functionExecuter->setValueResolver($this);
     $functionArguments = array();
     foreach ($functionJob->getArguments() as $argument) {
         if ($argument instanceof Parameter) {
             $value = $argument->getValue();
         } else {
             $value = $argument;
         }
         $value = $this->resolveValue($value, $context);
         $functionArguments[] = $value;
     }
     return $functionExecuter->executeFunction($functionJob, $functionArguments);
 }