Пример #1
0
 /**
  * Set the default value of the Variable.
  *
  * @param \qtism\common\datatypes\QtiDatatype|null $defaultValue A QtiDatatype object or null.
  * @throws \InvalidArgumentException If $defaultValue's type is not compliant with the qti:baseType of the Variable.
  */
 public function setDefaultValue(QtiDatatype $defaultValue = null)
 {
     if (Utils::isBaseTypeCompliant($this->getBaseType(), $defaultValue) && Utils::isCardinalityCompliant($this->getCardinality(), $defaultValue)) {
         $this->defaultValue = $defaultValue;
         return;
     } else {
         Utils::throwBaseTypeTypingError($this->getBaseType(), $defaultValue);
     }
 }
Пример #2
0
 /**
  * Set the correct response.
  *
  * @param \qtism\common\datatypes\QtiDatatype|null $correctResponse A QtiDatatype object or null.
  * @throws \InvalidArgumentException If $correctResponse does not match baseType and/or cardinality of the variable.
  */
 public function setCorrectResponse(QtiDatatype $correctResponse = null)
 {
     if ($correctResponse === null) {
         $this->correctResponse = null;
     } elseif (Utils::isBaseTypeCompliant($this->getBaseType(), $correctResponse) === true && Utils::isCardinalityCompliant($this->getCardinality(), $correctResponse) === true) {
         $this->correctResponse = $correctResponse;
     } else {
         $msg = "The given correct response is not compliant with the associated response variable.";
         throw new InvalidArgumentException($msg);
     }
 }
 /**
  * Set the correct response.
  * 
  * @param mixed $correctResponse A QTI Runtime compliant object.
  */
 public function setCorrectResponse($correctResponse)
 {
     if (Utils::isBaseTypeCompliant($this->getBaseType(), $correctResponse) === true) {
         $this->correctResponse = $correctResponse;
         return;
     } else {
         if ($correctResponse instanceof Container) {
             if ($correctResponse->getCardinality() === $this->getCardinality()) {
                 if (get_class($correctResponse) === 'qtism\\runtime\\common\\Container' || $correctResponse->getBaseType() === $this->getBaseType()) {
                     // This is a simple container with no baseType restriction
                     // or a Multiple|Record|Ordered container with a compliant
                     // baseType.
                     $this->correctResponse = $correctResponse;
                     return;
                 } else {
                     $msg = "The baseType of the given container ('" . BaseType::getNameByConstant($correctResponse->getBaseType()) . "') ";
                     $msg .= "is not compliant with ";
                     $msg .= "the baseType of the variable ('" . BaseType::getNameByConstant($this->getBaseType()) . "').";
                     throw new InvalidArgumentException($msg);
                 }
             } else {
                 $msg = "The cardinality of the given container ('" . Cardinality::getNameByConstant($value->getCardinality()) . "') ";
                 $msg .= "is not compliant with ";
                 $msg .= "the cardinality of the variable ('" . Cardinality::getNameByConstant($this->getCardinality()) . "').";
                 throw new InvalidArgumentException($msg);
             }
         }
     }
     $msg = "The provided value is not compliant with the baseType of the ResponseVariable.";
     throw new InvalidArgumentException($msg);
 }
 protected function checkType($value)
 {
     parent::checkType($value);
     if (!Utils::isBaseTypeCompliant($this->getBaseType(), $value)) {
         Utils::throwBaseTypeTypingError($this->getBaseType(), $value);
     }
 }