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