/** * Process the TemplateConstraint rule. It simply throws a RuleProcessingException with * the special code RuleProcessingException::TEMPLATE_CONSTRAINT_UNSATISFIED to warn client * code that the expression related to the constraint returned false or null. * * @throws \qtism\runtime\rules\RuleProcessingException with code = RuleProcessingException::TEMPLATE_CONSTRAINT_UNSATISFIED. */ public function process() { $state = $this->getState(); $rule = $this->getRule(); $expr = $rule->getExpression(); $expressionEngine = new ExpressionEngine($expr, $state); $val = $expressionEngine->process(); if (Utils::isNull($val) || $val->getValue() === false) { $msg = "Unsatisfied Template Constraint."; throw new RuleProcessingException($msg, $this, RuleProcessingException::TEMPLATE_CONSTRAINT_UNSATISFIED); } }
/** * Whether the item of the session has been attempted (at least once) and for which at least one response was given. * * @return boolean */ public function isResponded() { if ($this->isPresented() === false) { return false; } $excludedResponseVariables = array('numAttempts', 'duration'); foreach ($this->getKeys() as $k) { $var = $this->getVariable($k); if ($var instanceof ResponseVariable && in_array($k, $excludedResponseVariables) === false) { $value = $var->getValue(); $defaultValue = $var->getDefaultValue(); if (Utils::isNull($value) === true) { if (Utils::isNull($defaultValue) === false) { return true; } } else { if ($value->equals($defaultValue) === false) { return true; } } } } return false; }
/** * @dataProvider isNullDataProvider * * @param QtiDatatype $value * @param boolean $expected */ public function testIsNull(QtiDatatype $value = null, $expected) { $this->assertSame($expected, Utils::isNull($value)); }