/**
  * Unmarshall a QTI mathOperator operator element into a MathsOperator object.
  *
  * @param DOMElement The mathOperator element to unmarshall.
  * @param QtiComponentCollection A collection containing the child Expression objects composing the Operator.
  * @return QtiComponent A MathOperator object.
  * @throws UnmarshallingException
  */
 protected function unmarshallChildrenKnown(DOMElement $element, QtiComponentCollection $children)
 {
     if (($name = static::getDOMElementAttributeAs($element, 'name')) !== null) {
         $object = new MathOperator($children, MathFunctions::getConstantByName($name));
         return $object;
     } else {
         $msg = "The mandatory attribute 'name' is missing from element '" . $element->localName . "'.";
         throw new UnmarshallingException($msg, $element);
     }
 }
 /**
  * Set the name of the math function to use.
  * 
  * @param integer $name A value from the MathFunctions enumeration.
  * @throws InvalidArgumentException If $name is not a value from the MathFunctions enumeration.
  */
 public function setName($name)
 {
     if (in_array($name, MathFunctions::asArray())) {
         $this->name = $name;
     } else {
         $msg = "The name attribute must be a value from the MathFunctions enumeration, '" . $name . "' given.";
         throw new InvalidArgumentException($msg);
     }
 }
Ejemplo n.º 3
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;
     }
 }