/**
  * Unmarshall a MathOperator object into a QTI mathOperator element.
  * 
  * @param QtiComponent The MathOperator object to marshall.
  * @param array An array of child DOMEelement objects.
  * @return DOMElement The marshalled QTI mathOperator element.
  */
 protected function marshallChildrenKnown(QtiComponent $component, array $elements)
 {
     $element = self::getDOMCradle()->createElement($component->getQtiClassName());
     self::setDOMElementAttribute($element, 'name', MathFunctions::getNameByConstant($component->getName()));
     foreach ($elements as $elt) {
         $element->appendChild($elt);
     }
     return $element;
 }
Exemplo n.º 2
0
    public function createFakeExpression($constant)
    {
        return $this->createComponentFromXml('
			<mathOperator name="' . MathFunctions::getNameByConstant($constant) . '">
				<baseValue baseType="float">1.5708</baseValue>
			</mathOperator>
		');
    }
 /**
  * Process the MathOperator operator.
  * 
  * @return float|integer|null The result of the MathOperator call or NULL if any of the sub-expressions is NULL. See the class documentation for special cases.
  */
 public function process()
 {
     $operands = $this->getOperands();
     if ($operands->containsNull() === true) {
         return null;
     }
     if ($operands->exclusivelySingle() === false) {
         $msg = "The MathOperator operator only accepts operands with a single cardinality.";
         throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
     }
     if ($operands->exclusivelyNumeric() === false) {
         $msg = "The MathOperator operator only accepts operands with an integer or float baseType.";
         throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
     }
     $qtiFuncName = MathFunctions::getNameByConstant($this->getExpression()->getName());
     $methodName = 'process' . ucfirst($qtiFuncName);
     $result = call_user_func_array(array($this, $methodName), array());
     if ($result instanceof Float && is_nan($result->getValue()) === true) {
         // outside the domain of the function.
         return null;
     } else {
         return $result;
     }
 }