Ejemplo n.º 1
0
 /**
  * Unmarshall a StatsOperator object into a QTI statsOperator element.
  *
  * @param \qtism\data\QtiComponent $component The StatsOperator object to marshall.
  * @param array $elements An array of child DOMEelement objects.
  * @return \DOMElement The marshalled QTI statsOperator element.
  */
 protected function marshallChildrenKnown(QtiComponent $component, array $elements)
 {
     $element = self::getDOMCradle()->createElement($component->getQtiClassName());
     self::setDOMElementAttribute($element, 'name', Statistics::getNameByConstant($component->getName()));
     foreach ($elements as $elt) {
         $element->appendChild($elt);
     }
     return $element;
 }
Ejemplo n.º 2
0
 /**
  * Process the StatsOperator.
  *
  * @return float A single float or NULL if the sub-expression or any value contained therein is NULL.
  * @throws \qtism\runtime\expressions\operators\OperatorProcessingException
  */
 public function process()
 {
     $operands = $this->getOperands();
     if ($operands->containsNull() === true) {
         return null;
     }
     if ($operands->exclusivelyMultipleOrOrdered() === false) {
         $msg = "The StatsOperator operator only accepts operands with a multiple or ordered cardinality.";
         throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
     }
     if ($operands->exclusivelyNumeric() === false) {
         $msg = "The StatsOperator operator only accepts operands with a multiple or ordered cardinality.";
         throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
     }
     $qtiFuncName = Statistics::getNameByConstant($this->getExpression()->getName());
     $methodName = 'process' . ucfirst($qtiFuncName);
     return call_user_func_array(array($this, $methodName), array());
 }
    public function createFakeExpression($name)
    {
        $name = Statistics::getNameByConstant($name);
        return $this->createComponentFromXml('
			<statsOperator name="' . $name . '">
				<multiple>
					<baseValue baseType="integer">10</baseValue>
					<baseValue baseType="integer">20</baseValue>
					<baseValue baseType="integer">30</baseValue>
				</multiple>
			</statsOperator>
		');
    }