/** * Process an expression and return its boolean value * @param <type> $expr * @param <type> $groupSeq - needed to determine whether using variables before they are declared * @param <type> $questionSeq - needed to determine whether using variables before they are declared * @return <type> */ public function ProcessBooleanExpression($expr, $groupSeq = -1, $questionSeq = -1) { $this->groupSeq = $groupSeq; $this->questionSeq = $questionSeq; $expr = $this->ExpandThisVar($expr); $status = $this->RDP_Evaluate($expr); if (!$status) { return false; // if there are errors in the expression, hide it? } $result = $this->GetResult(); if (is_null($result)) { return false; // if there are errors in the expression, hide it? } // if ($result == 'false') { // return false; // since the string 'false' is not considered boolean false, but an expression in JavaScript can return 'false' // } // return !empty($result); // Check whether any variables are irrelevant - making this comparable to JavaScript which uses LEManyNA(varlist) to do the same thing foreach ($this->GetVarsUsed() as $var) { if (!preg_match("/^.*\\.(NAOK|relevanceStatus)\$/", $var)) { if (!LimeExpressionManager::GetVarAttribute($var, 'relevanceStatus', false, $groupSeq, $questionSeq)) { return false; } } } return (bool) $result; }
/** * Get information about the variable, including JavaScript name, read-write status, and whether set on current page. * @param <type> $varname * @return <type> */ private function GetVarAttribute($name, $attr, $default) { return LimeExpressionManager::GetVarAttribute($name, $attr, $default, $this->groupSeq, $this->questionSeq); }