31            '+' => array(
'precedence' => 1),
 
   32            '-' => array(
'precedence' => 1),
 
   33            '*' => array(
'precedence' => 2),
 
   34            '/' => array(
'precedence' => 2),
 
   35            '^' => array(
'precedence' => 3),
 
   88        if (isset(self::$cache_tokens[$this->field->getId()])) {
 
   89            $tokens = self::$cache_tokens[$this->field->getId()];
 
   92            self::$cache_tokens[$this->field->getId()] = $tokens;
 
   96        foreach ($tokens as 
$token) {
 
  110                if (strpos(
$token, 
'"') === 0) {
 
  111                    $parsed .= strip_tags(trim(
$token, 
'"'));
 
  112                } elseif (strpos(
$token, 
'[[') === 0) {
 
  113                    $parsed .= trim(strip_tags($this->substituteFieldValue(
$token)));
 
  115                    throw new ilException(
"Unrecognized string token: '$token'");
 
  131        if (abs($value) >= self::SCIENTIFIC_NOTATION_UPPER) {
 
  132            return sprintf(
"%e", $value);
 
  134        if (abs($value) <= self::SCIENTIFIC_NOTATION_LOWER && $value != 0) {
 
  135            return sprintf(
"%e", $value);
 
  137        if (is_float($value)) {
 
  172        if (isset(self::$cache_math_tokens[$this->field->getId()][
$token])) {
 
  173            return self::$cache_math_tokens[$this->field->getId()][
$token];
 
  175            if (strpos(
$token, 
'"') === 0) {
 
  178            $operators = array_keys(self::getOperators());
 
  181            self::$cache_math_tokens[$this->field->getId()][
$token] = 
$result;
 
  197        if (isset(self::$cache_math_function_tokens[$this->field->getId()][
$token])) {
 
  198            $result = self::$cache_math_function_tokens[$this->field->getId()][
$token];
 
  204            foreach (self::getFunctions() as $function) {
 
  205                $pattern .= 
"($function)\\(([^)]*)\\)|";
 
  207            if (!preg_match_all(rtrim($pattern, 
'|') . 
'#', 
$token, 
$result)) {
 
  209                self::$cache_math_function_tokens[$this->field->getId()][
$token] = 
false;
 
  215        foreach (
$result[0] as $k => $to_replace) {
 
  217            $function = $function_args[
'function'];
 
  243                $function = $_data[
$index];
 
  245                $return[
'function'] = $function;
 
  246                $return[
'args'] = $args;
 
  265        foreach ($tokens as 
$token) {
 
  266            if (strpos(
$token, 
'[[') === 0) {
 
  267                $replaced[] = $this->substituteFieldValue(
$token);
 
  285    protected function substituteFieldValue($placeholder)
 
  287        if (isset(self::$cache_fields[$placeholder])) {
 
  288            $field = self::$cache_fields[$placeholder];
 
  291            $field_title = preg_replace(
'#^\[\[(.*)\]\]#', 
"$1", $placeholder);
 
  302                    $lng->loadLanguageModule(
'dcl');
 
  304                    throw new ilException(sprintf(
$lng->txt(
'dcl_err_formula_field_not_found'), $field_title));
 
  307            self::$cache_fields[$placeholder] = 
$field;
 
  310        return $this->record->getRecordFieldFormulaValue(
$field->getId());
 
  329        foreach ($tokens as 
$token) {
 
  340                if ($new_precedence > $precedence || $in_bracket) {
 
  343                    $precedences->push($new_precedence);
 
  344                    $precedence = $new_precedence;
 
  347                    while ($new_precedence <= $precedence && $stack->count() > 1) {
 
  348                        $right = (float) $stack->pop();
 
  349                        $operator = $stack->pop();
 
  350                        $left = (float) $stack->pop();
 
  353                        $precedence = $precedences->pop();
 
  356                    $precedence = $new_precedence;
 
  357                    $precedences->push($new_precedence);
 
  359            } elseif (
$token === 
')') {
 
  362                $elem = $stack->pop();
 
  363                while ($elem !== 
'(' && !$stack->isEmpty()) {
 
  365                    $elem = $stack->pop();
 
  368                $stack->push($this->
parseMath(array_reverse($_tokens)));
 
  371                throw new ilException(
"Unrecognized token '$token'");
 
  376        if ($stack->count() == 1) {
 
  379            return (ctype_digit((
string) 
$result)) ? 
$result : number_format(
$result, self::N_DECIMALS, 
'.', 
"'");
 
  381            while ($stack->count() >= 2) {
 
  382                $right = $stack->pop();
 
  383                $operator = $stack->pop();
 
  384                $left = $stack->count() ? $stack->pop() : 0;
 
  385                $stack->push($this->
calculate($operator, $left, $right));
 
  407                $count = count($args);
 
  409                return ($count) ? array_sum($args) / $count : 0;
 
  411                return array_sum($args);
 
  417                throw new ilException(
"Unrecognized function '$function'");
 
  443                $result = ($right == 0) ? 0 : $left / $right;
 
  449                throw new ilException(
"Unrecognized operator '$operator'");
 
An exception for terminatinating execution or to throw for unit testing.
Class ilDclBaseFieldModel.
Class ilDclBaseRecordModel.
static getTableCache($table_id=0)
Class ilDclExpressionParser.
substituteFieldValues(array $tokens)
Given an array of tokens, replace each token that is a placeholder (e.g.
getFunctionArgs($index, array $data)
Helper method to return the function and its arguments from a preg_replace_all $result array.
calculateFunctions($token)
Execute any math functions inside a token.
const SCIENTIFIC_NOTATION_UPPER
const SCIENTIFIC_NOTATION_LOWER
static $cache_math_function_tokens
parseMath(array $tokens)
Parse a math expression.
parse()
Parse expression and return result.
isMathToken($token)
Check if a given token is a math expression.
calculateFunction($function, array $args=array())
Calculate a function with its arguments.
static $cache_math_tokens
__construct($expression, ilDclBaseRecordModel $record, ilDclBaseFieldModel $field)
calculate($operator, $left, $right)
static getMathTokens($math_expression)
Generate tokens for a math expression.
static getTokens($expression)
Split expression by & (ignore escaped &-symbols with backslash)
Base class for ILIAS Exception handling.
if(empty($password)) $table