/** * 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); } }
/** * 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); } }