예제 #1
0
파일: Repeat.php 프로젝트: nagyist/qti-sdk
 /**
  * Set the numberRepeats attribute.
  *
  * @param integer|string $numberRepeats An integer or a QTI variable reference.
  * @throws \InvalidArgumentException If $numberRepeats is not an integer nor a valid QTI variable reference.
  */
 public function setNumberRepeats($numberRepeats)
 {
     if (is_int($numberRepeats) || gettype($numberRepeats) === 'string' && Format::isVariableRef($numberRepeats)) {
         $this->numberRepeats = $numberRepeats;
     } else {
         $msg = "The numberRepeats argument must be an integer or a variable reference, '" . gettype($numberRepeats) . "' given.";
         throw new InvalidArgumentException($msg);
     }
 }
예제 #2
0
파일: Index.php 프로젝트: nagyist/qti-sdk
 /**
  * Set the n attribute.
  *
  * @param integer|string $n The index to lookup. It must be an integer or a variable reference.
  * @throws \InvalidArgumentException If $n is not an integer nor a variable reference.
  */
 public function setN($n)
 {
     if (is_int($n) || gettype($n) === 'string' && Format::isVariableRef($n)) {
         $this->n = $n;
     } else {
         $msg = "The n attribute must be an integer or a variable reference, '" . gettype($n) . "' given.";
         throw new InvalidArgumentException($msg);
     }
 }
예제 #3
0
 /**
  * Unmarshall a DOMElement object corresponding to a QTI randomFloat element.
  *
  * @param \DOMElement $element A DOMElement object.
  * @return \qtism\data\QtiComponent A RandomFloat object.
  * @throws \qtism\data\storage\xml\marshalling\UnmarshallingException If the mandatory attributes min or max ar missing.
  */
 protected function unmarshall(DOMElement $element)
 {
     // max attribute is mandatory.
     if (($max = static::getDOMElementAttributeAs($element, 'max')) !== null) {
         $max = Format::isVariableRef($max) ? $max : floatval($max);
         $object = new RandomFloat(0.0, $max);
         if (($min = static::getDOMElementAttributeAs($element, 'min')) !== null) {
             $min = Format::isVariableRef($min) ? $min : floatval($min);
             $object->setMin($min);
         }
         return $object;
     } else {
         $msg = "The mandatory attribute 'max' is missing from element '" . $element->localName . "'.";
         throw new UnmarshallingException($msg, $element);
     }
 }
 /**
  * Unmarshall a QTI roundTo operator element into a RoundTo object.
  *
  * @param DOMElement The roundTo element to unmarshall.
  * @param QtiComponentCollection A collection containing the child Expression objects composing the Operator.
  * @return QtiComponent A RoundTo object.
  * @throws UnmarshallingException
  */
 protected function unmarshallChildrenKnown(DOMElement $element, QtiComponentCollection $children)
 {
     if (($figures = static::getDOMElementAttributeAs($element, 'figures', 'string')) !== null) {
         if (!Format::isVariableRef($figures)) {
             $figures = intval($figures);
         }
         $object = new RoundTo($children, $figures);
         if (($roundingMode = static::getDOMElementAttributeAs($element, 'roundingMode')) !== null) {
             $object->setRoundingMode(RoundingMode::getConstantByName($roundingMode));
         }
         return $object;
     } else {
         $msg = "The mandatory attribute 'figures' is missing from element '" . $element->localName . "'.";
         throw new UnmarshallingException($msg, $element);
     }
 }
 /**
  * Unmarshall a DOMElement object corresponding to a QTI randomInteger element.
  * 
  * @param DOMElement $element A DOMElement object.
  * @return QtiComponent A RandomInteger object.
  * @throws UnmarshallingException If the mandatory attributes 'min' or 'max' are missing from $element.
  */
 protected function unmarshall(DOMElement $element)
 {
     if (($max = static::getDOMElementAttributeAs($element, 'max', 'string')) !== null) {
         $max = Format::isVariableRef($max) ? $max : intval($max);
         $object = new RandomInteger(0, $max);
         if (($step = static::getDOMElementAttributeAs($element, 'step')) !== null) {
             $object->setStep(abs(intval($step)));
         }
         if (($min = static::getDOMElementAttributeAs($element, 'min')) !== null) {
             $min = Format::isVariableRef($min) ? $min : intval($min);
             $object->setMin($min);
         }
         return $object;
     } else {
         $msg = "The mandatory attribute 'max' is missing from element '" . $element->localName . "'.";
         throw new UnmarshallingException($msg, $element);
     }
 }
예제 #6
0
 /**
  * Set the value of the max attribute.
  *
  * @param integer $max
  * @throws \InvalidArgumentException
  */
 public function setMax($max)
 {
     if (is_int($max) || Format::isVariableRef($max)) {
         $this->max = $max;
     } else {
         $msg = "'Max' must be an integer, '" . gettype($max) . "' given.";
         throw new InvalidArgumentException($msg);
     }
 }
 /**
  * Set the index to use when displaying a variable of ordered cardinality. Give a negative integer
  * if there is no index indicated.
  * 
  * @param integer|string $index An integer or variable reference.
  * @throws InvalidArgumentException If $index is not an integer nor a variable reference.
  */
 public function setIndex($index)
 {
     if (is_int($index) === true || Format::isVariableRef($index) === true) {
         $this->index = $index;
     } else {
         $msg = "The 'index' argument must be an integer or a variable reference, '" . $index . "' given.";
         throw new InvalidArgumentException($msg);
     }
 }
 /**
  * Set the number of figures to round to.
  * 
  * @param integer|string $figures An integer value or a variable reference.
  * @throws InvalidArgumentException If $figures is not an integer nor a variable reference.
  */
 public function setFigures($figures)
 {
     if (is_int($figures) || gettype($figures) === 'string' && Format::isVariableRef($figures)) {
         $this->figures = $figures;
     } else {
         $msg = "The figures argument must be an integer or a variable reference, '" . $figures . "' given.";
         throw new InvalidArgumentException($msg);
     }
 }
 /**
  * @dataProvider invalidVariableRefFormatProvider
  */
 public function testInvalidVariableRefFormat($string)
 {
     $this->assertFalse(Format::isVariableRef($string));
 }
예제 #10
0
 /**
  * Set the max attribute.
  *
  * @param number|string $max A numeric value or a variableRef.
  * @throws \InvalidArgumentException If $max is not a numeric value nor a variableRef.
  */
 public function setMax($max)
 {
     if (is_numeric($max) || Format::isVariableRef($max)) {
         $this->max = $max;
     } else {
         $msg = "'Max must be a numeric value or a variableRef, '" . gettype($max) . "' given.";
         throw new InvalidArgumentException($msg);
     }
 }
예제 #11
0
파일: AnyN.php 프로젝트: nagyist/qti-sdk
 /**
  * Set the max attribute.
  *
  * @param string|integer $max An integer or a variable reference.
  * @throws \InvalidArgumentException If $max is not an integer nor a variable reference.
  */
 public function setMax($max)
 {
     if (is_int($max) || gettype($max) === 'string' && Format::isVariableRef($max)) {
         $this->max = $max;
     } else {
         $msg = "The max attribute must be an integer or a variable reference, '" . $max . "' given.";
         throw new InvalidArgumentException($msg);
     }
 }