repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6 values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1 value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
oat-sa/qti-sdk | src/qtism/data/content/interactions/Choice.php | Choice.setShowHide | public function setShowHide($showHide)
{
if (in_array($showHide, ShowHide::asArray()) === true) {
$this->showHide = $showHide;
} else {
$msg = "The 'showHide' argument must be a value from the ShowHide enumeration.";
throw new InvalidArgumentException($msg);
}
} | php | public function setShowHide($showHide)
{
if (in_array($showHide, ShowHide::asArray()) === true) {
$this->showHide = $showHide;
} else {
$msg = "The 'showHide' argument must be a value from the ShowHide enumeration.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setShowHide",
"(",
"$",
"showHide",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"showHide",
",",
"ShowHide",
"::",
"asArray",
"(",
")",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"showHide",
"=",
"$",
"showHide",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'showHide' argument must be a value from the ShowHide enumeration.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the visibility of the choice.
@param integer $showHide A value from the ShowHide enumeration.
@throws \InvalidArgumentException If $showHide is not a value from the ShowHide enumeration. | [
"Set",
"the",
"visibility",
"of",
"the",
"choice",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/interactions/Choice.php#L212-L220 |
oat-sa/qti-sdk | src/qtism/runtime/storage/binary/LocalQtiBinaryStorage.php | LocalQtiBinaryStorage.persistStream | protected function persistStream(AssessmentTestSession $assessmentTestSession, MemoryStream $stream)
{
$sessionId = $assessmentTestSession->getSessionId();
$path = $this->getPath() . DIRECTORY_SEPARATOR . md5($sessionId) . '.bin';
$written = @file_put_contents($path, $stream->getBinary());
if ($written === false || $written === 0) {
$msg = "An error occured while persisting the binary stream at '${path}'.";
throw new RuntimeException($msg);
}
} | php | protected function persistStream(AssessmentTestSession $assessmentTestSession, MemoryStream $stream)
{
$sessionId = $assessmentTestSession->getSessionId();
$path = $this->getPath() . DIRECTORY_SEPARATOR . md5($sessionId) . '.bin';
$written = @file_put_contents($path, $stream->getBinary());
if ($written === false || $written === 0) {
$msg = "An error occured while persisting the binary stream at '${path}'.";
throw new RuntimeException($msg);
}
} | [
"protected",
"function",
"persistStream",
"(",
"AssessmentTestSession",
"$",
"assessmentTestSession",
",",
"MemoryStream",
"$",
"stream",
")",
"{",
"$",
"sessionId",
"=",
"$",
"assessmentTestSession",
"->",
"getSessionId",
"(",
")",
";",
"$",
"path",
"=",
"$",
"this",
"->",
"getPath",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"md5",
"(",
"$",
"sessionId",
")",
".",
"'.bin'",
";",
"$",
"written",
"=",
"@",
"file_put_contents",
"(",
"$",
"path",
",",
"$",
"stream",
"->",
"getBinary",
"(",
")",
")",
";",
"if",
"(",
"$",
"written",
"===",
"false",
"||",
"$",
"written",
"===",
"0",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while persisting the binary stream at '${path}'.\"",
";",
"throw",
"new",
"RuntimeException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Persist the binary stream $stream which contains the binary equivalent of $assessmentTestSession in
the temporary directory of the file system.
@param \qtism\runtime\tests\AssessmentTestSession $assessmentTestSession The AssessmentTestSession to be persisted.
@param \qtism\common\storage\MemoryStream $stream The MemoryStream to be stored in the temporary directory of the host file system.
@throws \RuntimeException If the binary stream cannot be persisted. | [
"Persist",
"the",
"binary",
"stream",
"$stream",
"which",
"contains",
"the",
"binary",
"equivalent",
"of",
"$assessmentTestSession",
"in",
"the",
"temporary",
"directory",
"of",
"the",
"file",
"system",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/storage/binary/LocalQtiBinaryStorage.php#L96-L107 |
oat-sa/qti-sdk | src/qtism/runtime/storage/binary/LocalQtiBinaryStorage.php | LocalQtiBinaryStorage.getRetrievalStream | protected function getRetrievalStream($sessionId)
{
$path = $this->getPath() . DIRECTORY_SEPARATOR . md5($sessionId) . '.bin';
$read = @file_get_contents($path);
if ($read === false || strlen($read) === 0) {
$msg = "An error occured while retrieving the binary stream at '${path}'. Nothing could be read. The file is empty or missing.";
throw new RuntimeException($msg);
}
return new MemoryStream($read);
} | php | protected function getRetrievalStream($sessionId)
{
$path = $this->getPath() . DIRECTORY_SEPARATOR . md5($sessionId) . '.bin';
$read = @file_get_contents($path);
if ($read === false || strlen($read) === 0) {
$msg = "An error occured while retrieving the binary stream at '${path}'. Nothing could be read. The file is empty or missing.";
throw new RuntimeException($msg);
}
return new MemoryStream($read);
} | [
"protected",
"function",
"getRetrievalStream",
"(",
"$",
"sessionId",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"getPath",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"md5",
"(",
"$",
"sessionId",
")",
".",
"'.bin'",
";",
"$",
"read",
"=",
"@",
"file_get_contents",
"(",
"$",
"path",
")",
";",
"if",
"(",
"$",
"read",
"===",
"false",
"||",
"strlen",
"(",
"$",
"read",
")",
"===",
"0",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while retrieving the binary stream at '${path}'. Nothing could be read. The file is empty or missing.\"",
";",
"throw",
"new",
"RuntimeException",
"(",
"$",
"msg",
")",
";",
"}",
"return",
"new",
"MemoryStream",
"(",
"$",
"read",
")",
";",
"}"
] | Retrieve the binary representation of the AssessmentTestSession identified by $sessionId which was
instantiated from $assessmentTest from the temporary directory of the file system.
@param string $sessionId The session ID of the AssessmentTestSession to retrieve.
@return \qtism\common\storage\MemoryStream A MemoryStream object.
@throws \RuntimeException If the binary stream cannot be persisted. | [
"Retrieve",
"the",
"binary",
"representation",
"of",
"the",
"AssessmentTestSession",
"identified",
"by",
"$sessionId",
"which",
"was",
"instantiated",
"from",
"$assessmentTest",
"from",
"the",
"temporary",
"directory",
"of",
"the",
"file",
"system",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/storage/binary/LocalQtiBinaryStorage.php#L117-L129 |
oat-sa/qti-sdk | src/qtism/data/expressions/operators/Operator.php | Operator.setMinOperands | public function setMinOperands($minOperands)
{
if (is_int($minOperands) && $minOperands >= 0) {
$this->minOperands = $minOperands;
} else {
$msg = "The minOperands argument must be an integer >= 0, '" . $minOperands . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setMinOperands($minOperands)
{
if (is_int($minOperands) && $minOperands >= 0) {
$this->minOperands = $minOperands;
} else {
$msg = "The minOperands argument must be an integer >= 0, '" . $minOperands . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setMinOperands",
"(",
"$",
"minOperands",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"minOperands",
")",
"&&",
"$",
"minOperands",
">=",
"0",
")",
"{",
"$",
"this",
"->",
"minOperands",
"=",
"$",
"minOperands",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The minOperands argument must be an integer >= 0, '\"",
".",
"$",
"minOperands",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the minimum operands count for this Operator.
@param int $minOperands An integer which is >= 0.
@throws \InvalidArgumentException If $minOperands is not an integer >= 0. | [
"Set",
"the",
"minimum",
"operands",
"count",
"for",
"this",
"Operator",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/expressions/operators/Operator.php#L133-L141 |
oat-sa/qti-sdk | src/qtism/data/expressions/operators/Operator.php | Operator.setMaxOperands | public function setMaxOperands($maxOperands)
{
if (is_int($maxOperands)) {
$this->maxOperands = $maxOperands;
} else {
$msg = "The maxOperands argument must be an integer, '" . gettype($maxOperands) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setMaxOperands($maxOperands)
{
if (is_int($maxOperands)) {
$this->maxOperands = $maxOperands;
} else {
$msg = "The maxOperands argument must be an integer, '" . gettype($maxOperands) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setMaxOperands",
"(",
"$",
"maxOperands",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"maxOperands",
")",
")",
"{",
"$",
"this",
"->",
"maxOperands",
"=",
"$",
"maxOperands",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The maxOperands argument must be an integer, '\"",
".",
"gettype",
"(",
"$",
"maxOperands",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the maxmimum operands count for this Operator. The value
is -1 if unlimited.
@param int $maxOperands
@throws \InvalidArgumentException If $maxOperands is not an integer. | [
"Set",
"the",
"maxmimum",
"operands",
"count",
"for",
"this",
"Operator",
".",
"The",
"value",
"is",
"-",
"1",
"if",
"unlimited",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/expressions/operators/Operator.php#L160-L168 |
oat-sa/qti-sdk | src/qtism/data/expressions/operators/Operator.php | Operator.setAcceptedCardinalities | public function setAcceptedCardinalities(array $acceptedCardinalities)
{
foreach ($acceptedCardinalities as $cardinality) {
if (!in_array($cardinality, OperatorCardinality::asArray(), true)) {
$msg = "Accepted cardinalities must be values from the Cardinality enumeration, '" . $cardinality . "' given";
throw new InvalidArgumentException($msg);
}
}
$this->acceptedCardinalities = $acceptedCardinalities;
} | php | public function setAcceptedCardinalities(array $acceptedCardinalities)
{
foreach ($acceptedCardinalities as $cardinality) {
if (!in_array($cardinality, OperatorCardinality::asArray(), true)) {
$msg = "Accepted cardinalities must be values from the Cardinality enumeration, '" . $cardinality . "' given";
throw new InvalidArgumentException($msg);
}
}
$this->acceptedCardinalities = $acceptedCardinalities;
} | [
"public",
"function",
"setAcceptedCardinalities",
"(",
"array",
"$",
"acceptedCardinalities",
")",
"{",
"foreach",
"(",
"$",
"acceptedCardinalities",
"as",
"$",
"cardinality",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"cardinality",
",",
"OperatorCardinality",
"::",
"asArray",
"(",
")",
",",
"true",
")",
")",
"{",
"$",
"msg",
"=",
"\"Accepted cardinalities must be values from the Cardinality enumeration, '\"",
".",
"$",
"cardinality",
".",
"\"' given\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}",
"$",
"this",
"->",
"acceptedCardinalities",
"=",
"$",
"acceptedCardinalities",
";",
"}"
] | Set the accepted operand cardinalities.
@param array $acceptedCardinalities An array of values from the Cardinality enumeration.
@throws \InvalidArgumentException If a value from $acceptedCardinalities is not a value from the Cardinality enumeration. | [
"Set",
"the",
"accepted",
"operand",
"cardinalities",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/expressions/operators/Operator.php#L197-L207 |
oat-sa/qti-sdk | src/qtism/data/expressions/operators/Operator.php | Operator.setAcceptedBaseTypes | public function setAcceptedBaseTypes(array $acceptedBaseTypes)
{
foreach ($acceptedBaseTypes as $baseType) {
if (!in_array($baseType, OperatorBaseType::asArray(), true)) {
$msg = "Accepted baseTypes must be values from the OperatorBaseType enumeration, '" . $baseType . "' given.";
throw new InvalidArgumentException($msg);
}
}
$this->acceptedBaseTypes = $acceptedBaseTypes;
} | php | public function setAcceptedBaseTypes(array $acceptedBaseTypes)
{
foreach ($acceptedBaseTypes as $baseType) {
if (!in_array($baseType, OperatorBaseType::asArray(), true)) {
$msg = "Accepted baseTypes must be values from the OperatorBaseType enumeration, '" . $baseType . "' given.";
throw new InvalidArgumentException($msg);
}
}
$this->acceptedBaseTypes = $acceptedBaseTypes;
} | [
"public",
"function",
"setAcceptedBaseTypes",
"(",
"array",
"$",
"acceptedBaseTypes",
")",
"{",
"foreach",
"(",
"$",
"acceptedBaseTypes",
"as",
"$",
"baseType",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"baseType",
",",
"OperatorBaseType",
"::",
"asArray",
"(",
")",
",",
"true",
")",
")",
"{",
"$",
"msg",
"=",
"\"Accepted baseTypes must be values from the OperatorBaseType enumeration, '\"",
".",
"$",
"baseType",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}",
"$",
"this",
"->",
"acceptedBaseTypes",
"=",
"$",
"acceptedBaseTypes",
";",
"}"
] | Set the accepted operand accepted baseTypes.
@param array $acceptedBaseTypes An array of values from the OperatorBaseType enumeration.
@throws \InvalidArgumentException If a value from the $acceptedBaseTypes is not a value from the OperatorBaseType. | [
"Set",
"the",
"accepted",
"operand",
"accepted",
"baseTypes",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/expressions/operators/Operator.php#L225-L235 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/StringMatchProcessor.php | StringMatchProcessor.process | public function process()
{
$operands = $this->getOperands();
if ($operands->containsNull() === true) {
return null;
}
if ($operands->exclusivelySingle() === false) {
$msg = "The StringMatch operator only accepts operands with a single cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
if ($operands->exclusivelyString() === false) {
$msg = "The StringMatch operator only accepts operands with a string baseType.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
}
$expression = $this->getExpression();
// choose the correct comparison function according comparison rules
// of the operator.
// Please note that strcmp and strcasecmp are binary-safe *\0/* Hourray! *\0/*
$func = ($expression->isCaseSensitive() === true) ? 'strcmp' : 'strcasecmp';
return new QtiBoolean($func($operands[0]->getValue(), $operands[1]->getValue()) === 0);
} | php | public function process()
{
$operands = $this->getOperands();
if ($operands->containsNull() === true) {
return null;
}
if ($operands->exclusivelySingle() === false) {
$msg = "The StringMatch operator only accepts operands with a single cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
if ($operands->exclusivelyString() === false) {
$msg = "The StringMatch operator only accepts operands with a string baseType.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
}
$expression = $this->getExpression();
// choose the correct comparison function according comparison rules
// of the operator.
// Please note that strcmp and strcasecmp are binary-safe *\0/* Hourray! *\0/*
$func = ($expression->isCaseSensitive() === true) ? 'strcmp' : 'strcasecmp';
return new QtiBoolean($func($operands[0]->getValue(), $operands[1]->getValue()) === 0);
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"operands",
"=",
"$",
"this",
"->",
"getOperands",
"(",
")",
";",
"if",
"(",
"$",
"operands",
"->",
"containsNull",
"(",
")",
"===",
"true",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"operands",
"->",
"exclusivelySingle",
"(",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The StringMatch operator only accepts operands with a single cardinality.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_CARDINALITY",
")",
";",
"}",
"if",
"(",
"$",
"operands",
"->",
"exclusivelyString",
"(",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The StringMatch operator only accepts operands with a string baseType.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_BASETYPE",
")",
";",
"}",
"$",
"expression",
"=",
"$",
"this",
"->",
"getExpression",
"(",
")",
";",
"// choose the correct comparison function according comparison rules",
"// of the operator.",
"// Please note that strcmp and strcasecmp are binary-safe *\\0/* Hourray! *\\0/*",
"$",
"func",
"=",
"(",
"$",
"expression",
"->",
"isCaseSensitive",
"(",
")",
"===",
"true",
")",
"?",
"'strcmp'",
":",
"'strcasecmp'",
";",
"return",
"new",
"QtiBoolean",
"(",
"$",
"func",
"(",
"$",
"operands",
"[",
"0",
"]",
"->",
"getValue",
"(",
")",
",",
"$",
"operands",
"[",
"1",
"]",
"->",
"getValue",
"(",
")",
")",
"===",
"0",
")",
";",
"}"
] | Process the StringMatch operator.
@return boolean Whether the two string match according to the comparison rules of the operator's attributes or NULL if either of the sub-expressions is NULL.
@throws \qtism\runtime\expressions\operators\OperatorProcessingException | [
"Process",
"the",
"StringMatch",
"operator",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/StringMatchProcessor.php#L55-L81 |
oat-sa/qti-sdk | src/qtism/common/utils/Reflection.php | Reflection.newInstance | static public function newInstance(ReflectionClass $class, $args = array())
{
if (empty($args) === true) {
$fqName = $class->getName();
return new $fqName();
} else {
return $class->newInstanceArgs($args);
}
} | php | static public function newInstance(ReflectionClass $class, $args = array())
{
if (empty($args) === true) {
$fqName = $class->getName();
return new $fqName();
} else {
return $class->newInstanceArgs($args);
}
} | [
"static",
"public",
"function",
"newInstance",
"(",
"ReflectionClass",
"$",
"class",
",",
"$",
"args",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"args",
")",
"===",
"true",
")",
"{",
"$",
"fqName",
"=",
"$",
"class",
"->",
"getName",
"(",
")",
";",
"return",
"new",
"$",
"fqName",
"(",
")",
";",
"}",
"else",
"{",
"return",
"$",
"class",
"->",
"newInstanceArgs",
"(",
"$",
"args",
")",
";",
"}",
"}"
] | An abstraction of the call to ReflectionClass::newInstanceArgs. The main
goal of this method is to avoid to encounter the issue with empty $args
argument described at: http://www.php.net/manual/en/reflectionclass.newinstanceargs.php#99517
@param \ReflectionClass $class
@param array $args
@return mixed An instance of $class
@throws \ReflectionException
@see http://www.php.net/manual/en/reflectionclass.newinstanceargs.php#99517 The awful bug! | [
"An",
"abstraction",
"of",
"the",
"call",
"to",
"ReflectionClass",
"::",
"newInstanceArgs",
".",
"The",
"main",
"goal",
"of",
"this",
"method",
"is",
"to",
"avoid",
"to",
"encounter",
"the",
"issue",
"with",
"empty",
"$args",
"argument",
"described",
"at",
":",
"http",
":",
"//",
"www",
".",
"php",
".",
"net",
"/",
"manual",
"/",
"en",
"/",
"reflectionclass",
".",
"newinstanceargs",
".",
"php#99517"
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/utils/Reflection.php#L47-L56 |
oat-sa/qti-sdk | src/qtism/common/utils/Reflection.php | Reflection.shortClassName | static public function shortClassName($object)
{
$shortClassName = false;
if (is_object($object) === true) {
$parts = explode("\\", get_class($object));
$shortClassName = array_pop($parts);
} elseif (is_string($object) === true && empty($object) === false) {
$parts = explode("\\", $object);
$shortClassName = array_pop($parts);
}
return empty($shortClassName) ? false : $shortClassName;
} | php | static public function shortClassName($object)
{
$shortClassName = false;
if (is_object($object) === true) {
$parts = explode("\\", get_class($object));
$shortClassName = array_pop($parts);
} elseif (is_string($object) === true && empty($object) === false) {
$parts = explode("\\", $object);
$shortClassName = array_pop($parts);
}
return empty($shortClassName) ? false : $shortClassName;
} | [
"static",
"public",
"function",
"shortClassName",
"(",
"$",
"object",
")",
"{",
"$",
"shortClassName",
"=",
"false",
";",
"if",
"(",
"is_object",
"(",
"$",
"object",
")",
"===",
"true",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"\"\\\\\"",
",",
"get_class",
"(",
"$",
"object",
")",
")",
";",
"$",
"shortClassName",
"=",
"array_pop",
"(",
"$",
"parts",
")",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"object",
")",
"===",
"true",
"&&",
"empty",
"(",
"$",
"object",
")",
"===",
"false",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"\"\\\\\"",
",",
"$",
"object",
")",
";",
"$",
"shortClassName",
"=",
"array_pop",
"(",
"$",
"parts",
")",
";",
"}",
"return",
"empty",
"(",
"$",
"shortClassName",
")",
"?",
"false",
":",
"$",
"shortClassName",
";",
"}"
] | Obtains the short class name of a given $object.
If $object is not an object, false is returned instead of a string.
Examples:
+ my\namespace\A -> A
+ A -> A
+ \my\A -> A
@param mixed $object An object or a fully qualified class name.
@return boolean|string A short class name or false if $object is not an object nor a string. | [
"Obtains",
"the",
"short",
"class",
"name",
"of",
"a",
"given",
"$object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/utils/Reflection.php#L72-L86 |
oat-sa/qti-sdk | src/qtism/common/utils/Reflection.php | Reflection.isInstanceOf | static public function isInstanceOf($object, $className)
{
$givenType = get_class($object);
return $givenType === $className || is_subclass_of($givenType, $className) === true || in_array($className, class_implements($givenType)) === true;
} | php | static public function isInstanceOf($object, $className)
{
$givenType = get_class($object);
return $givenType === $className || is_subclass_of($givenType, $className) === true || in_array($className, class_implements($givenType)) === true;
} | [
"static",
"public",
"function",
"isInstanceOf",
"(",
"$",
"object",
",",
"$",
"className",
")",
"{",
"$",
"givenType",
"=",
"get_class",
"(",
"$",
"object",
")",
";",
"return",
"$",
"givenType",
"===",
"$",
"className",
"||",
"is_subclass_of",
"(",
"$",
"givenType",
",",
"$",
"className",
")",
"===",
"true",
"||",
"in_array",
"(",
"$",
"className",
",",
"class_implements",
"(",
"$",
"givenType",
")",
")",
"===",
"true",
";",
"}"
] | Whether or not a given $object is an instance of $className. This method
exists because is_sublcass_of() does not take into account interfaces
in PHP 5.3.
@param mixed $object The object you want to know it is an instance of $className.
@param string $className A class name. It can be fully qualified.
@return boolean | [
"Whether",
"or",
"not",
"a",
"given",
"$object",
"is",
"an",
"instance",
"of",
"$className",
".",
"This",
"method",
"exists",
"because",
"is_sublcass_of",
"()",
"does",
"not",
"take",
"into",
"account",
"interfaces",
"in",
"PHP",
"5",
".",
"3",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/utils/Reflection.php#L97-L102 |
oat-sa/qti-sdk | src/qtism/common/datatypes/QtiDirectedPair.php | QtiDirectedPair.equals | public function equals($obj)
{
if (gettype($obj) === 'object' && $obj instanceof self) {
return $obj->getFirst() === $this->getFirst() && $obj->getSecond() === $this->getSecond();
}
return false;
} | php | public function equals($obj)
{
if (gettype($obj) === 'object' && $obj instanceof self) {
return $obj->getFirst() === $this->getFirst() && $obj->getSecond() === $this->getSecond();
}
return false;
} | [
"public",
"function",
"equals",
"(",
"$",
"obj",
")",
"{",
"if",
"(",
"gettype",
"(",
"$",
"obj",
")",
"===",
"'object'",
"&&",
"$",
"obj",
"instanceof",
"self",
")",
"{",
"return",
"$",
"obj",
"->",
"getFirst",
"(",
")",
"===",
"$",
"this",
"->",
"getFirst",
"(",
")",
"&&",
"$",
"obj",
"->",
"getSecond",
"(",
")",
"===",
"$",
"this",
"->",
"getSecond",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Whether or not $obj is equal to $this. Two DirectedPair objects
are considered to be equal if their first and second values are the same.
@return boolean | [
"Whether",
"or",
"not",
"$obj",
"is",
"equal",
"to",
"$this",
".",
"Two",
"DirectedPair",
"objects",
"are",
"considered",
"to",
"be",
"equal",
"if",
"their",
"first",
"and",
"second",
"values",
"are",
"the",
"same",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/datatypes/QtiDirectedPair.php#L45-L52 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/OrProcessor.php | OrProcessor.process | public function process()
{
$operands = $this->getOperands();
$allFalse = true;
foreach ($operands as $op) {
if ($op instanceof Container) {
$msg = "The Or Expression only accept operands with single cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
} elseif ($op === null) {
continue;
} else {
if (!$op instanceof QtiBoolean) {
$msg = "The Or Expression only accept operands with boolean baseType.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
} else {
if ($op->getValue() !== false) {
$allFalse = false;
}
}
}
}
if ($allFalse === true && $operands->containsNull() === true) {
return null;
}
foreach ($operands as $operand) {
if ($operand !== null && $operand->getValue() === true) {
return new QtiBoolean(true);
}
}
return new QtiBoolean(false);
} | php | public function process()
{
$operands = $this->getOperands();
$allFalse = true;
foreach ($operands as $op) {
if ($op instanceof Container) {
$msg = "The Or Expression only accept operands with single cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
} elseif ($op === null) {
continue;
} else {
if (!$op instanceof QtiBoolean) {
$msg = "The Or Expression only accept operands with boolean baseType.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
} else {
if ($op->getValue() !== false) {
$allFalse = false;
}
}
}
}
if ($allFalse === true && $operands->containsNull() === true) {
return null;
}
foreach ($operands as $operand) {
if ($operand !== null && $operand->getValue() === true) {
return new QtiBoolean(true);
}
}
return new QtiBoolean(false);
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"operands",
"=",
"$",
"this",
"->",
"getOperands",
"(",
")",
";",
"$",
"allFalse",
"=",
"true",
";",
"foreach",
"(",
"$",
"operands",
"as",
"$",
"op",
")",
"{",
"if",
"(",
"$",
"op",
"instanceof",
"Container",
")",
"{",
"$",
"msg",
"=",
"\"The Or Expression only accept operands with single cardinality.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_CARDINALITY",
")",
";",
"}",
"elseif",
"(",
"$",
"op",
"===",
"null",
")",
"{",
"continue",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"$",
"op",
"instanceof",
"QtiBoolean",
")",
"{",
"$",
"msg",
"=",
"\"The Or Expression only accept operands with boolean baseType.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_BASETYPE",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"op",
"->",
"getValue",
"(",
")",
"!==",
"false",
")",
"{",
"$",
"allFalse",
"=",
"false",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"$",
"allFalse",
"===",
"true",
"&&",
"$",
"operands",
"->",
"containsNull",
"(",
")",
"===",
"true",
")",
"{",
"return",
"null",
";",
"}",
"foreach",
"(",
"$",
"operands",
"as",
"$",
"operand",
")",
"{",
"if",
"(",
"$",
"operand",
"!==",
"null",
"&&",
"$",
"operand",
"->",
"getValue",
"(",
")",
"===",
"true",
")",
"{",
"return",
"new",
"QtiBoolean",
"(",
"true",
")",
";",
"}",
"}",
"return",
"new",
"QtiBoolean",
"(",
"false",
")",
";",
"}"
] | Process the current expression.
@return boolean True if the expression is true, false otherwise.
@throws \qtism\runtime\expressions\operators\OperatorProcessingException | [
"Process",
"the",
"current",
"expression",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/OrProcessor.php#L54-L88 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/AssessmentItemRefMarshaller.php | AssessmentItemRefMarshaller.marshall | protected function marshall(QtiComponent $component)
{
$element = parent::marshall($component);
$this->setDOMElementAttribute($element, 'href', $component->getHref());
// Deal with categories.
$categories = $component->getCategories();
if (count($categories) > 0) {
$this->setDOMElementAttribute($element, 'category', implode("\x20", $categories->getArrayCopy()));
}
// Deal with variableMappings.
$variableMappings = $component->getVariableMappings();
foreach ($variableMappings as $mapping) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($mapping);
$element->appendChild($marshaller->marshall($mapping));
}
// Deal with weights.
$weights = $component->getWeights();
foreach ($weights as $weight) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($weight);
$element->appendChild($marshaller->marshall($weight));
}
// Deal with templateDefaults.
$templateDefaults = $component->getTemplateDefaults();
foreach ($templateDefaults as $default) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($default);
$element->appendChild($marshaller->marshall($default));
}
return $element;
} | php | protected function marshall(QtiComponent $component)
{
$element = parent::marshall($component);
$this->setDOMElementAttribute($element, 'href', $component->getHref());
// Deal with categories.
$categories = $component->getCategories();
if (count($categories) > 0) {
$this->setDOMElementAttribute($element, 'category', implode("\x20", $categories->getArrayCopy()));
}
// Deal with variableMappings.
$variableMappings = $component->getVariableMappings();
foreach ($variableMappings as $mapping) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($mapping);
$element->appendChild($marshaller->marshall($mapping));
}
// Deal with weights.
$weights = $component->getWeights();
foreach ($weights as $weight) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($weight);
$element->appendChild($marshaller->marshall($weight));
}
// Deal with templateDefaults.
$templateDefaults = $component->getTemplateDefaults();
foreach ($templateDefaults as $default) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($default);
$element->appendChild($marshaller->marshall($default));
}
return $element;
} | [
"protected",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"$",
"element",
"=",
"parent",
"::",
"marshall",
"(",
"$",
"component",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'href'",
",",
"$",
"component",
"->",
"getHref",
"(",
")",
")",
";",
"// Deal with categories.",
"$",
"categories",
"=",
"$",
"component",
"->",
"getCategories",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"categories",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'category'",
",",
"implode",
"(",
"\"\\x20\"",
",",
"$",
"categories",
"->",
"getArrayCopy",
"(",
")",
")",
")",
";",
"}",
"// Deal with variableMappings.",
"$",
"variableMappings",
"=",
"$",
"component",
"->",
"getVariableMappings",
"(",
")",
";",
"foreach",
"(",
"$",
"variableMappings",
"as",
"$",
"mapping",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"mapping",
")",
";",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"marshaller",
"->",
"marshall",
"(",
"$",
"mapping",
")",
")",
";",
"}",
"// Deal with weights.",
"$",
"weights",
"=",
"$",
"component",
"->",
"getWeights",
"(",
")",
";",
"foreach",
"(",
"$",
"weights",
"as",
"$",
"weight",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"weight",
")",
";",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"marshaller",
"->",
"marshall",
"(",
"$",
"weight",
")",
")",
";",
"}",
"// Deal with templateDefaults.",
"$",
"templateDefaults",
"=",
"$",
"component",
"->",
"getTemplateDefaults",
"(",
")",
";",
"foreach",
"(",
"$",
"templateDefaults",
"as",
"$",
"default",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"default",
")",
";",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"marshaller",
"->",
"marshall",
"(",
"$",
"default",
")",
")",
";",
"}",
"return",
"$",
"element",
";",
"}"
] | Marshall an AssessmentItemRef object into a DOMElement object.
@param \qtism\data\QtiComponent $component An assessmentItemRef object.
@return \DOMElement The according DOMElement object.
@throws \qtism\data\storage\xml\marshalling\MarshallingException | [
"Marshall",
"an",
"AssessmentItemRef",
"object",
"into",
"a",
"DOMElement",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/AssessmentItemRefMarshaller.php#L48-L82 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/AssessmentItemRefMarshaller.php | AssessmentItemRefMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
$baseComponent = parent::unmarshall($element);
if (($href = $this->getDOMElementAttributeAs($element, 'href')) !== null) {
$object = new AssessmentItemRef($baseComponent->getIdentifier(), $href);
$object->setRequired($baseComponent->isRequired());
$object->setFixed($baseComponent->isFixed());
$object->setPreConditions($baseComponent->getPreConditions());
$object->setBranchRules($baseComponent->getBranchRules());
$object->setItemSessionControl($baseComponent->getItemSessionControl());
$object->setTimeLimits($baseComponent->getTimeLimits());
// Deal with categories.
if (($category = $this->getDOMElementAttributeAs($element, 'category')) !== null) {
$object->setCategories(new IdentifierCollection(explode("\x20", $category)));
}
// Deal with variableMappings.
$variableMappingElts = $element->getElementsByTagName('variableMapping');
$variableMappings = new VariableMappingCollection();
for ($i = 0; $i < $variableMappingElts->length; $i++) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($variableMappingElts->item($i));
$variableMappings[] = $marshaller->unmarshall($variableMappingElts->item($i));
}
$object->setVariableMappings($variableMappings);
// Deal with weights.
$weightElts = $element->getElementsByTagName('weight');
$weights = new WeightCollection();
for ($i = 0; $i < $weightElts->length; $i++) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($weightElts->item($i));
$weights[] = $marshaller->unmarshall($weightElts->item($i));
}
$object->setWeights($weights);
// Deal with templateDefaults.
$templateDefaultElts = $element->getElementsByTagName('templateDefault');
$templateDefaults = new TemplateDefaultCollection();
for ($i = 0; $i < $templateDefaultElts->length; $i++) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($templateDefaultElts->item($i));
$templateDefaults[] = $marshaller->unmarshall($templateDefaultElts->item($i));
}
$object->setTemplateDefaults($templateDefaults);
return $object;
} else {
$msg = "The mandatory attribute 'href' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} | php | protected function unmarshall(DOMElement $element)
{
$baseComponent = parent::unmarshall($element);
if (($href = $this->getDOMElementAttributeAs($element, 'href')) !== null) {
$object = new AssessmentItemRef($baseComponent->getIdentifier(), $href);
$object->setRequired($baseComponent->isRequired());
$object->setFixed($baseComponent->isFixed());
$object->setPreConditions($baseComponent->getPreConditions());
$object->setBranchRules($baseComponent->getBranchRules());
$object->setItemSessionControl($baseComponent->getItemSessionControl());
$object->setTimeLimits($baseComponent->getTimeLimits());
// Deal with categories.
if (($category = $this->getDOMElementAttributeAs($element, 'category')) !== null) {
$object->setCategories(new IdentifierCollection(explode("\x20", $category)));
}
// Deal with variableMappings.
$variableMappingElts = $element->getElementsByTagName('variableMapping');
$variableMappings = new VariableMappingCollection();
for ($i = 0; $i < $variableMappingElts->length; $i++) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($variableMappingElts->item($i));
$variableMappings[] = $marshaller->unmarshall($variableMappingElts->item($i));
}
$object->setVariableMappings($variableMappings);
// Deal with weights.
$weightElts = $element->getElementsByTagName('weight');
$weights = new WeightCollection();
for ($i = 0; $i < $weightElts->length; $i++) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($weightElts->item($i));
$weights[] = $marshaller->unmarshall($weightElts->item($i));
}
$object->setWeights($weights);
// Deal with templateDefaults.
$templateDefaultElts = $element->getElementsByTagName('templateDefault');
$templateDefaults = new TemplateDefaultCollection();
for ($i = 0; $i < $templateDefaultElts->length; $i++) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($templateDefaultElts->item($i));
$templateDefaults[] = $marshaller->unmarshall($templateDefaultElts->item($i));
}
$object->setTemplateDefaults($templateDefaults);
return $object;
} else {
$msg = "The mandatory attribute 'href' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"$",
"baseComponent",
"=",
"parent",
"::",
"unmarshall",
"(",
"$",
"element",
")",
";",
"if",
"(",
"(",
"$",
"href",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'href'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"object",
"=",
"new",
"AssessmentItemRef",
"(",
"$",
"baseComponent",
"->",
"getIdentifier",
"(",
")",
",",
"$",
"href",
")",
";",
"$",
"object",
"->",
"setRequired",
"(",
"$",
"baseComponent",
"->",
"isRequired",
"(",
")",
")",
";",
"$",
"object",
"->",
"setFixed",
"(",
"$",
"baseComponent",
"->",
"isFixed",
"(",
")",
")",
";",
"$",
"object",
"->",
"setPreConditions",
"(",
"$",
"baseComponent",
"->",
"getPreConditions",
"(",
")",
")",
";",
"$",
"object",
"->",
"setBranchRules",
"(",
"$",
"baseComponent",
"->",
"getBranchRules",
"(",
")",
")",
";",
"$",
"object",
"->",
"setItemSessionControl",
"(",
"$",
"baseComponent",
"->",
"getItemSessionControl",
"(",
")",
")",
";",
"$",
"object",
"->",
"setTimeLimits",
"(",
"$",
"baseComponent",
"->",
"getTimeLimits",
"(",
")",
")",
";",
"// Deal with categories.",
"if",
"(",
"(",
"$",
"category",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'category'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"object",
"->",
"setCategories",
"(",
"new",
"IdentifierCollection",
"(",
"explode",
"(",
"\"\\x20\"",
",",
"$",
"category",
")",
")",
")",
";",
"}",
"// Deal with variableMappings.",
"$",
"variableMappingElts",
"=",
"$",
"element",
"->",
"getElementsByTagName",
"(",
"'variableMapping'",
")",
";",
"$",
"variableMappings",
"=",
"new",
"VariableMappingCollection",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"variableMappingElts",
"->",
"length",
";",
"$",
"i",
"++",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"variableMappingElts",
"->",
"item",
"(",
"$",
"i",
")",
")",
";",
"$",
"variableMappings",
"[",
"]",
"=",
"$",
"marshaller",
"->",
"unmarshall",
"(",
"$",
"variableMappingElts",
"->",
"item",
"(",
"$",
"i",
")",
")",
";",
"}",
"$",
"object",
"->",
"setVariableMappings",
"(",
"$",
"variableMappings",
")",
";",
"// Deal with weights.",
"$",
"weightElts",
"=",
"$",
"element",
"->",
"getElementsByTagName",
"(",
"'weight'",
")",
";",
"$",
"weights",
"=",
"new",
"WeightCollection",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"weightElts",
"->",
"length",
";",
"$",
"i",
"++",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"weightElts",
"->",
"item",
"(",
"$",
"i",
")",
")",
";",
"$",
"weights",
"[",
"]",
"=",
"$",
"marshaller",
"->",
"unmarshall",
"(",
"$",
"weightElts",
"->",
"item",
"(",
"$",
"i",
")",
")",
";",
"}",
"$",
"object",
"->",
"setWeights",
"(",
"$",
"weights",
")",
";",
"// Deal with templateDefaults.",
"$",
"templateDefaultElts",
"=",
"$",
"element",
"->",
"getElementsByTagName",
"(",
"'templateDefault'",
")",
";",
"$",
"templateDefaults",
"=",
"new",
"TemplateDefaultCollection",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"templateDefaultElts",
"->",
"length",
";",
"$",
"i",
"++",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"templateDefaultElts",
"->",
"item",
"(",
"$",
"i",
")",
")",
";",
"$",
"templateDefaults",
"[",
"]",
"=",
"$",
"marshaller",
"->",
"unmarshall",
"(",
"$",
"templateDefaultElts",
"->",
"item",
"(",
"$",
"i",
")",
")",
";",
"}",
"$",
"object",
"->",
"setTemplateDefaults",
"(",
"$",
"templateDefaults",
")",
";",
"return",
"$",
"object",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory attribute 'href' is missing from element '\"",
".",
"$",
"element",
"->",
"localName",
".",
"\"'.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}"
] | Unmarshall a DOMElement object corresponding to a QTI assessmentItemRef element.
@param \DOMElement $element A DOMElement object.
@return \qtism\data\QtiComponent An AssessmentItemRef object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException If the mandatory attribute 'href' is missing. | [
"Unmarshall",
"a",
"DOMElement",
"object",
"corresponding",
"to",
"a",
"QTI",
"assessmentItemRef",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/AssessmentItemRefMarshaller.php#L91-L141 |
oat-sa/qti-sdk | src/qtism/data/expressions/RandomInteger.php | RandomInteger.setMin | public function setMin($min)
{
if (is_int($min) || Format::isVariableRef($max)) {
$this->min = $min;
} else {
$msg = "'Min' must be an integer, '" . gettype($min) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setMin($min)
{
if (is_int($min) || Format::isVariableRef($max)) {
$this->min = $min;
} else {
$msg = "'Min' must be an integer, '" . gettype($min) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setMin",
"(",
"$",
"min",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"min",
")",
"||",
"Format",
"::",
"isVariableRef",
"(",
"$",
"max",
")",
")",
"{",
"$",
"this",
"->",
"min",
"=",
"$",
"min",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"'Min' must be an integer, '\"",
".",
"gettype",
"(",
"$",
"min",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the value of the min attribute.
@param integer $min
@throws \InvalidArgumentException | [
"Set",
"the",
"value",
"of",
"the",
"min",
"attribute",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/expressions/RandomInteger.php#L94-L102 |
oat-sa/qti-sdk | src/qtism/data/expressions/RandomInteger.php | RandomInteger.setStep | public function setStep($step)
{
if (is_int($step)) {
$this->step = $step;
} else {
$msg = "'Step' must be an integer, '" . gettype($step) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setStep($step)
{
if (is_int($step)) {
$this->step = $step;
} else {
$msg = "'Step' must be an integer, '" . gettype($step) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setStep",
"(",
"$",
"step",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"step",
")",
")",
"{",
"$",
"this",
"->",
"step",
"=",
"$",
"step",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"'Step' must be an integer, '\"",
".",
"gettype",
"(",
"$",
"step",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the value of the step attribute.
@param integer $step
@throws \InvalidArgumentException | [
"Set",
"the",
"value",
"of",
"the",
"step",
"attribute",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/expressions/RandomInteger.php#L146-L154 |
oat-sa/qti-sdk | src/qtism/data/content/xhtml/Param.php | Param.setName | public function setName($name)
{
if (is_string($name) === true) {
$this->name = $name;
} else {
$msg = "The 'name' argument must be a string, '" . gettype($name) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setName($name)
{
if (is_string($name) === true) {
$this->name = $name;
} else {
$msg = "The 'name' argument must be a string, '" . gettype($name) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setName",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"name",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"name",
"=",
"$",
"name",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'name' argument must be a string, '\"",
".",
"gettype",
"(",
"$",
"name",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the name of the parameter, as interpreted by the object.
@param string $name A string.
@throws \InvalidArgumentException If $name is not a string. | [
"Set",
"the",
"name",
"of",
"the",
"parameter",
"as",
"interpreted",
"by",
"the",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/xhtml/Param.php#L116-L124 |
oat-sa/qti-sdk | src/qtism/data/content/xhtml/Param.php | Param.setValue | public function setValue($value)
{
if (is_string($value) === true) {
$this->value = $value;
} else {
$msg = "The 'value' argument must be a string, '" . gettype($value) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setValue($value)
{
if (is_string($value) === true) {
$this->value = $value;
} else {
$msg = "The 'value' argument must be a string, '" . gettype($value) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setValue",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"value",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'value' argument must be a string, '\"",
".",
"gettype",
"(",
"$",
"value",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the value to pass to the object for the named parameter.
@param string $value A value as a string.
@throws \InvalidArgumentException If $value is not a string. | [
"Set",
"the",
"value",
"to",
"pass",
"to",
"the",
"object",
"for",
"the",
"named",
"parameter",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/xhtml/Param.php#L142-L150 |
oat-sa/qti-sdk | src/qtism/data/content/xhtml/Param.php | Param.setValueType | public function setValueType($valueType)
{
if (in_array($valueType, ParamType::asArray(), true) === true) {
$this->valueType = $valueType;
} else {
$msg = "The 'valueType' argument must be a value from the ParamType enumeration, '" . gettype($valueType) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setValueType($valueType)
{
if (in_array($valueType, ParamType::asArray(), true) === true) {
$this->valueType = $valueType;
} else {
$msg = "The 'valueType' argument must be a value from the ParamType enumeration, '" . gettype($valueType) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setValueType",
"(",
"$",
"valueType",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"valueType",
",",
"ParamType",
"::",
"asArray",
"(",
")",
",",
"true",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"valueType",
"=",
"$",
"valueType",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'valueType' argument must be a value from the ParamType enumeration, '\"",
".",
"gettype",
"(",
"$",
"valueType",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the valueType attribute.
@param integer $valueType A value from the ParamType enumeration.
@throws \InvalidArgumentException If $valueType is not a value from the ParamType enumeration. | [
"Set",
"the",
"valueType",
"attribute",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/xhtml/Param.php#L168-L176 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/SelectionMarshaller.php | SelectionMarshaller.marshall | protected function marshall(QtiComponent $component)
{
$element = static::getDOMCradle()->createElement($component->getQtiClassName());
$this->setDOMElementAttribute($element, 'select', $component->getSelect());
$this->setDOMElementAttribute($element, 'withReplacement', $component->isWithReplacement());
if (($xml = $component->getXml()) !== null) {
$selectionElt = $xml->documentElement->cloneNode(true);
Utils::importChildNodes($selectionElt, $element);
Utils::importAttributes($selectionElt, $element);
}
return $element;
} | php | protected function marshall(QtiComponent $component)
{
$element = static::getDOMCradle()->createElement($component->getQtiClassName());
$this->setDOMElementAttribute($element, 'select', $component->getSelect());
$this->setDOMElementAttribute($element, 'withReplacement', $component->isWithReplacement());
if (($xml = $component->getXml()) !== null) {
$selectionElt = $xml->documentElement->cloneNode(true);
Utils::importChildNodes($selectionElt, $element);
Utils::importAttributes($selectionElt, $element);
}
return $element;
} | [
"protected",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"$",
"element",
"=",
"static",
"::",
"getDOMCradle",
"(",
")",
"->",
"createElement",
"(",
"$",
"component",
"->",
"getQtiClassName",
"(",
")",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'select'",
",",
"$",
"component",
"->",
"getSelect",
"(",
")",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'withReplacement'",
",",
"$",
"component",
"->",
"isWithReplacement",
"(",
")",
")",
";",
"if",
"(",
"(",
"$",
"xml",
"=",
"$",
"component",
"->",
"getXml",
"(",
")",
")",
"!==",
"null",
")",
"{",
"$",
"selectionElt",
"=",
"$",
"xml",
"->",
"documentElement",
"->",
"cloneNode",
"(",
"true",
")",
";",
"Utils",
"::",
"importChildNodes",
"(",
"$",
"selectionElt",
",",
"$",
"element",
")",
";",
"Utils",
"::",
"importAttributes",
"(",
"$",
"selectionElt",
",",
"$",
"element",
")",
";",
"}",
"return",
"$",
"element",
";",
"}"
] | Marshall a Selection object into a DOMElement object.
@param \qtism\data\QtiComponent $component A Selection object.
@return \DOMElement The according DOMElement object. | [
"Marshall",
"a",
"Selection",
"object",
"into",
"a",
"DOMElement",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/SelectionMarshaller.php#L44-L59 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/SelectionMarshaller.php | SelectionMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
// Retrieve XML content as a string.
$frag = $element->ownerDocument->createDocumentFragment();
$element = $element->cloneNode(true);
$frag->appendChild($element);
$xmlString = $frag->ownerDocument->saveXML($frag);
// select is a mandatory value, retrieve it first.
if (($value = $this->getDOMElementAttributeAs($element, 'select', 'integer')) !== null) {
$withReplacement = false;
if (($withReplacementValue = $this->getDOMElementAttributeAs($element, 'withReplacement', 'boolean')) !== null) {
$withReplacement = $withReplacementValue;
}
$object = new Selection($value, $withReplacement, $xmlString);
} else {
$msg = "The mandatory attribute 'select' is missing.";
throw new UnmarshallingException($msg, $element);
}
return $object;
} | php | protected function unmarshall(DOMElement $element)
{
// Retrieve XML content as a string.
$frag = $element->ownerDocument->createDocumentFragment();
$element = $element->cloneNode(true);
$frag->appendChild($element);
$xmlString = $frag->ownerDocument->saveXML($frag);
// select is a mandatory value, retrieve it first.
if (($value = $this->getDOMElementAttributeAs($element, 'select', 'integer')) !== null) {
$withReplacement = false;
if (($withReplacementValue = $this->getDOMElementAttributeAs($element, 'withReplacement', 'boolean')) !== null) {
$withReplacement = $withReplacementValue;
}
$object = new Selection($value, $withReplacement, $xmlString);
} else {
$msg = "The mandatory attribute 'select' is missing.";
throw new UnmarshallingException($msg, $element);
}
return $object;
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"// Retrieve XML content as a string.",
"$",
"frag",
"=",
"$",
"element",
"->",
"ownerDocument",
"->",
"createDocumentFragment",
"(",
")",
";",
"$",
"element",
"=",
"$",
"element",
"->",
"cloneNode",
"(",
"true",
")",
";",
"$",
"frag",
"->",
"appendChild",
"(",
"$",
"element",
")",
";",
"$",
"xmlString",
"=",
"$",
"frag",
"->",
"ownerDocument",
"->",
"saveXML",
"(",
"$",
"frag",
")",
";",
"// select is a mandatory value, retrieve it first.",
"if",
"(",
"(",
"$",
"value",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'select'",
",",
"'integer'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"withReplacement",
"=",
"false",
";",
"if",
"(",
"(",
"$",
"withReplacementValue",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'withReplacement'",
",",
"'boolean'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"withReplacement",
"=",
"$",
"withReplacementValue",
";",
"}",
"$",
"object",
"=",
"new",
"Selection",
"(",
"$",
"value",
",",
"$",
"withReplacement",
",",
"$",
"xmlString",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory attribute 'select' is missing.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"return",
"$",
"object",
";",
"}"
] | Unmarshall a DOMElement object corresponding to a QTI Selection object.
@param \DOMElement $element A DOMElement object.
@return \qtism\data\QtiComponent A Selection object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException If the mandatory 'select' attribute is missing from $element. | [
"Unmarshall",
"a",
"DOMElement",
"object",
"corresponding",
"to",
"a",
"QTI",
"Selection",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/SelectionMarshaller.php#L68-L92 |
oat-sa/qti-sdk | src/qtism/runtime/rendering/qtipl/rules/BranchRuleQtiPLRenderer.php | BranchRuleQtiPLRenderer.render | public function render($something)
{
$renderer = new QtiPLRenderer($this->getCRO());
$attributes = [];
$attributes['target'] = "\"" . $something->getTarget() . "\"";
return $something->getQtiClassName() . $renderer->writeAttributes($attributes)
. $renderer->writeChildElement($something->getExpression());
} | php | public function render($something)
{
$renderer = new QtiPLRenderer($this->getCRO());
$attributes = [];
$attributes['target'] = "\"" . $something->getTarget() . "\"";
return $something->getQtiClassName() . $renderer->writeAttributes($attributes)
. $renderer->writeChildElement($something->getExpression());
} | [
"public",
"function",
"render",
"(",
"$",
"something",
")",
"{",
"$",
"renderer",
"=",
"new",
"QtiPLRenderer",
"(",
"$",
"this",
"->",
"getCRO",
"(",
")",
")",
";",
"$",
"attributes",
"=",
"[",
"]",
";",
"$",
"attributes",
"[",
"'target'",
"]",
"=",
"\"\\\"\"",
".",
"$",
"something",
"->",
"getTarget",
"(",
")",
".",
"\"\\\"\"",
";",
"return",
"$",
"something",
"->",
"getQtiClassName",
"(",
")",
".",
"$",
"renderer",
"->",
"writeAttributes",
"(",
"$",
"attributes",
")",
".",
"$",
"renderer",
"->",
"writeChildElement",
"(",
"$",
"something",
"->",
"getExpression",
"(",
")",
")",
";",
"}"
] | Render a QtiComponent object into another constitution.
@param mixed $something Something to render into another consitution.
@return mixed The rendered component into another constitution.
@throws \qtism\runtime\rendering\RenderingException If something goes wrong while rendering the component. | [
"Render",
"a",
"QtiComponent",
"object",
"into",
"another",
"constitution",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/qtipl/rules/BranchRuleQtiPLRenderer.php#L45-L53 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/InterpolationTableEntryMarshaller.php | InterpolationTableEntryMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
if (($sourceValue = $this->getDOMElementAttributeAs($element, 'sourceValue', 'float')) !== null) {
if (($targetValue = $this->getDOMElementAttributeAs($element, 'targetValue', 'string')) !== null) {
$object = new InterpolationTableEntry($sourceValue, Utils::stringToDatatype($targetValue, $this->getBaseType()));
if (($includeBoundary = $this->getDOMElementAttributeAs($element, 'includeBoundary', 'boolean')) !== null) {
$object->setIncludeBoundary($includeBoundary);
}
return $object;
}
} else {
$msg = "The mandatory attribute 'sourceValue' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} | php | protected function unmarshall(DOMElement $element)
{
if (($sourceValue = $this->getDOMElementAttributeAs($element, 'sourceValue', 'float')) !== null) {
if (($targetValue = $this->getDOMElementAttributeAs($element, 'targetValue', 'string')) !== null) {
$object = new InterpolationTableEntry($sourceValue, Utils::stringToDatatype($targetValue, $this->getBaseType()));
if (($includeBoundary = $this->getDOMElementAttributeAs($element, 'includeBoundary', 'boolean')) !== null) {
$object->setIncludeBoundary($includeBoundary);
}
return $object;
}
} else {
$msg = "The mandatory attribute 'sourceValue' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"if",
"(",
"(",
"$",
"sourceValue",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'sourceValue'",
",",
"'float'",
")",
")",
"!==",
"null",
")",
"{",
"if",
"(",
"(",
"$",
"targetValue",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'targetValue'",
",",
"'string'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"object",
"=",
"new",
"InterpolationTableEntry",
"(",
"$",
"sourceValue",
",",
"Utils",
"::",
"stringToDatatype",
"(",
"$",
"targetValue",
",",
"$",
"this",
"->",
"getBaseType",
"(",
")",
")",
")",
";",
"if",
"(",
"(",
"$",
"includeBoundary",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'includeBoundary'",
",",
"'boolean'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"object",
"->",
"setIncludeBoundary",
"(",
"$",
"includeBoundary",
")",
";",
"}",
"return",
"$",
"object",
";",
"}",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory attribute 'sourceValue' is missing from element '\"",
".",
"$",
"element",
"->",
"localName",
".",
"\"'.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}"
] | Unmarshall a DOMElement object corresponding to a QTI InterpolationEntry element.
@param \DOMElement $element A DOMElement object.
@return \qtism\data\QtiComponent An InterpolationTableEntry object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException | [
"Unmarshall",
"a",
"DOMElement",
"object",
"corresponding",
"to",
"a",
"QTI",
"InterpolationEntry",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/InterpolationTableEntryMarshaller.php#L107-L124 |
oat-sa/qti-sdk | src/qtism/data/QtiComponentCollection.php | QtiComponentCollection.exclusivelyContainsComponentsWithClassName | public function exclusivelyContainsComponentsWithClassName($className, $recursive = true)
{
$data = $this->getDataPlaceHolder();
foreach ($data as $component) {
if ($component->getQtiClassName() !== $className) {
return false;
} else if ($recursive === true) {
foreach ($component->getIterator() as $subComponent) {
if ($subComponent->getQtiClassName() !== $className) {
return false;
}
}
}
}
return true;
} | php | public function exclusivelyContainsComponentsWithClassName($className, $recursive = true)
{
$data = $this->getDataPlaceHolder();
foreach ($data as $component) {
if ($component->getQtiClassName() !== $className) {
return false;
} else if ($recursive === true) {
foreach ($component->getIterator() as $subComponent) {
if ($subComponent->getQtiClassName() !== $className) {
return false;
}
}
}
}
return true;
} | [
"public",
"function",
"exclusivelyContainsComponentsWithClassName",
"(",
"$",
"className",
",",
"$",
"recursive",
"=",
"true",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"getDataPlaceHolder",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"component",
")",
"{",
"if",
"(",
"$",
"component",
"->",
"getQtiClassName",
"(",
")",
"!==",
"$",
"className",
")",
"{",
"return",
"false",
";",
"}",
"else",
"if",
"(",
"$",
"recursive",
"===",
"true",
")",
"{",
"foreach",
"(",
"$",
"component",
"->",
"getIterator",
"(",
")",
"as",
"$",
"subComponent",
")",
"{",
"if",
"(",
"$",
"subComponent",
"->",
"getQtiClassName",
"(",
")",
"!==",
"$",
"className",
")",
"{",
"return",
"false",
";",
"}",
"}",
"}",
"}",
"return",
"true",
";",
"}"
] | Whether the collection contains exclusively QtiComponent objects having a given $className.
@param string $className A QTI class name.
@param boolean $recursive Wether to check children QtiComponent objects.
@return boolean | [
"Whether",
"the",
"collection",
"contains",
"exclusively",
"QtiComponent",
"objects",
"having",
"a",
"given",
"$className",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/QtiComponentCollection.php#L85-L103 |
oat-sa/qti-sdk | src/qtism/runtime/common/State.php | State.setVariable | public function setVariable(Variable $variable)
{
$this->checkType($variable);
$data = &$this->getDataPlaceHolder();
$data[$variable->getIdentifier()] = $variable;
} | php | public function setVariable(Variable $variable)
{
$this->checkType($variable);
$data = &$this->getDataPlaceHolder();
$data[$variable->getIdentifier()] = $variable;
} | [
"public",
"function",
"setVariable",
"(",
"Variable",
"$",
"variable",
")",
"{",
"$",
"this",
"->",
"checkType",
"(",
"$",
"variable",
")",
";",
"$",
"data",
"=",
"&",
"$",
"this",
"->",
"getDataPlaceHolder",
"(",
")",
";",
"$",
"data",
"[",
"$",
"variable",
"->",
"getIdentifier",
"(",
")",
"]",
"=",
"$",
"variable",
";",
"}"
] | Set a variable to the state. It will be accessible by it's variable name.
@param \qtism\runtime\common\Variable $variable | [
"Set",
"a",
"variable",
"to",
"the",
"state",
".",
"It",
"will",
"be",
"accessible",
"by",
"it",
"s",
"variable",
"name",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/common/State.php#L67-L72 |
oat-sa/qti-sdk | src/qtism/runtime/common/State.php | State.getVariable | public function getVariable($variableIdentifier)
{
$data = &$this->getDataPlaceHolder();
if (isset($data[$variableIdentifier])) {
return $data[$variableIdentifier];
} else {
return null;
}
} | php | public function getVariable($variableIdentifier)
{
$data = &$this->getDataPlaceHolder();
if (isset($data[$variableIdentifier])) {
return $data[$variableIdentifier];
} else {
return null;
}
} | [
"public",
"function",
"getVariable",
"(",
"$",
"variableIdentifier",
")",
"{",
"$",
"data",
"=",
"&",
"$",
"this",
"->",
"getDataPlaceHolder",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"$",
"variableIdentifier",
"]",
")",
")",
"{",
"return",
"$",
"data",
"[",
"$",
"variableIdentifier",
"]",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] | Get a variable with the identifier $variableIdentifier.
@param string $variableIdentifier A QTI identifier.
@return \qtism\runtime\common\Variable A Variable object or null if the $variableIdentifier does not match any Variable object stored in the State. | [
"Get",
"a",
"variable",
"with",
"the",
"identifier",
"$variableIdentifier",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/common/State.php#L80-L88 |
oat-sa/qti-sdk | src/qtism/runtime/common/State.php | State.unsetVariable | public function unsetVariable($variable)
{
$data = &$this->getDataPlaceHolder();
if (gettype($variable) === 'string') {
$variableIdentifier = $variable;
} elseif ($variable instanceof Variable) {
$variableIdentifier = $variable->getIdentifier();
} else {
$msg = "The variable argument must be a Variable object or a string, '" . $variable . "' given";
throw new InvalidArgumentException($msg);
}
if (isset($data[$variableIdentifier])) {
unset($data[$variableIdentifier]);
} else {
$msg = "No Variable object with identifier '${variableIdentifier}' found in the current State object.";
throw new OutOfBoundsException($msg);
}
} | php | public function unsetVariable($variable)
{
$data = &$this->getDataPlaceHolder();
if (gettype($variable) === 'string') {
$variableIdentifier = $variable;
} elseif ($variable instanceof Variable) {
$variableIdentifier = $variable->getIdentifier();
} else {
$msg = "The variable argument must be a Variable object or a string, '" . $variable . "' given";
throw new InvalidArgumentException($msg);
}
if (isset($data[$variableIdentifier])) {
unset($data[$variableIdentifier]);
} else {
$msg = "No Variable object with identifier '${variableIdentifier}' found in the current State object.";
throw new OutOfBoundsException($msg);
}
} | [
"public",
"function",
"unsetVariable",
"(",
"$",
"variable",
")",
"{",
"$",
"data",
"=",
"&",
"$",
"this",
"->",
"getDataPlaceHolder",
"(",
")",
";",
"if",
"(",
"gettype",
"(",
"$",
"variable",
")",
"===",
"'string'",
")",
"{",
"$",
"variableIdentifier",
"=",
"$",
"variable",
";",
"}",
"elseif",
"(",
"$",
"variable",
"instanceof",
"Variable",
")",
"{",
"$",
"variableIdentifier",
"=",
"$",
"variable",
"->",
"getIdentifier",
"(",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The variable argument must be a Variable object or a string, '\"",
".",
"$",
"variable",
".",
"\"' given\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"$",
"variableIdentifier",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"data",
"[",
"$",
"variableIdentifier",
"]",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"No Variable object with identifier '${variableIdentifier}' found in the current State object.\"",
";",
"throw",
"new",
"OutOfBoundsException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Unset a variable from the current state. In other words
the relevant Variable object is removed from the state.
@param string|Variable $variable The identifier of the variable or a Variable object to unset.
@throws \InvalidArgumentException If $variable is not a string nor a Variable object.
@throws \OutOfBoundsException If no variable in the current state matches $variable. | [
"Unset",
"a",
"variable",
"from",
"the",
"current",
"state",
".",
"In",
"other",
"words",
"the",
"relevant",
"Variable",
"object",
"is",
"removed",
"from",
"the",
"state",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/common/State.php#L108-L127 |
oat-sa/qti-sdk | src/qtism/runtime/common/State.php | State.resetOutcomeVariables | public function resetOutcomeVariables($preserveBuiltIn = true)
{
$data = &$this->getDataPlaceHolder();
foreach (array_keys($data) as $k) {
if ($data[$k] instanceof OutcomeVariable) {
if ($preserveBuiltIn === true && $k === 'completionStatus') {
continue;
} else {
$data[$k]->applyDefaultValue();
}
}
}
} | php | public function resetOutcomeVariables($preserveBuiltIn = true)
{
$data = &$this->getDataPlaceHolder();
foreach (array_keys($data) as $k) {
if ($data[$k] instanceof OutcomeVariable) {
if ($preserveBuiltIn === true && $k === 'completionStatus') {
continue;
} else {
$data[$k]->applyDefaultValue();
}
}
}
} | [
"public",
"function",
"resetOutcomeVariables",
"(",
"$",
"preserveBuiltIn",
"=",
"true",
")",
"{",
"$",
"data",
"=",
"&",
"$",
"this",
"->",
"getDataPlaceHolder",
"(",
")",
";",
"foreach",
"(",
"array_keys",
"(",
"$",
"data",
")",
"as",
"$",
"k",
")",
"{",
"if",
"(",
"$",
"data",
"[",
"$",
"k",
"]",
"instanceof",
"OutcomeVariable",
")",
"{",
"if",
"(",
"$",
"preserveBuiltIn",
"===",
"true",
"&&",
"$",
"k",
"===",
"'completionStatus'",
")",
"{",
"continue",
";",
"}",
"else",
"{",
"$",
"data",
"[",
"$",
"k",
"]",
"->",
"applyDefaultValue",
"(",
")",
";",
"}",
"}",
"}",
"}"
] | Reset all outcome variables to their defaults.
@param boolean $preserveBuiltIn Whether the built-in outcome variable 'completionStatus' should be preserved. | [
"Reset",
"all",
"outcome",
"variables",
"to",
"their",
"defaults",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/common/State.php#L172-L185 |
oat-sa/qti-sdk | src/qtism/runtime/common/State.php | State.resetTemplateVariables | public function resetTemplateVariables()
{
$data = &$this->getDataPlaceHolder();
foreach (array_keys($data) as $k) {
if ($data[$k] instanceof TemplateVariable) {
$data[$k]->applyDefaultValue();
}
}
} | php | public function resetTemplateVariables()
{
$data = &$this->getDataPlaceHolder();
foreach (array_keys($data) as $k) {
if ($data[$k] instanceof TemplateVariable) {
$data[$k]->applyDefaultValue();
}
}
} | [
"public",
"function",
"resetTemplateVariables",
"(",
")",
"{",
"$",
"data",
"=",
"&",
"$",
"this",
"->",
"getDataPlaceHolder",
"(",
")",
";",
"foreach",
"(",
"array_keys",
"(",
"$",
"data",
")",
"as",
"$",
"k",
")",
"{",
"if",
"(",
"$",
"data",
"[",
"$",
"k",
"]",
"instanceof",
"TemplateVariable",
")",
"{",
"$",
"data",
"[",
"$",
"k",
"]",
"->",
"applyDefaultValue",
"(",
")",
";",
"}",
"}",
"}"
] | Reset all template variables to their defaults.
@return void | [
"Reset",
"all",
"template",
"variables",
"to",
"their",
"defaults",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/common/State.php#L192-L201 |
oat-sa/qti-sdk | src/qtism/runtime/common/State.php | State.containsNullOnly | public function containsNullOnly()
{
$data = $this->getDataPlaceHolder();
foreach ($data as $variable) {
$value = $variable->getValue();
if ($variable->isNull() === false) {
return false;
}
}
return true;
} | php | public function containsNullOnly()
{
$data = $this->getDataPlaceHolder();
foreach ($data as $variable) {
$value = $variable->getValue();
if ($variable->isNull() === false) {
return false;
}
}
return true;
} | [
"public",
"function",
"containsNullOnly",
"(",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"getDataPlaceHolder",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"variable",
")",
"{",
"$",
"value",
"=",
"$",
"variable",
"->",
"getValue",
"(",
")",
";",
"if",
"(",
"$",
"variable",
"->",
"isNull",
"(",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Whether or not the State contains NULL only values.
Please note that in QTI terms, empty containers and empty strings are considered
to be NULL as well. Moreover, if the State is empty of any variable, the method
will return true.
@return boolean | [
"Whether",
"or",
"not",
"the",
"State",
"contains",
"NULL",
"only",
"values",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/common/State.php#L212-L225 |
oat-sa/qti-sdk | src/qtism/runtime/common/State.php | State.containsValuesEqualToVariableDefaultOnly | public function containsValuesEqualToVariableDefaultOnly()
{
$data = $this->getDataPlaceHolder();
foreach ($data as $variable) {
$value = $variable->getValue();
$default = $variable->getDefaultValue();
if (Utils::isNull($value) === true) {
if (Utils::isNull($default) === false) {
return false;
}
} elseif ($value->equals($default) === false) {
return false;
}
}
return true;
} | php | public function containsValuesEqualToVariableDefaultOnly()
{
$data = $this->getDataPlaceHolder();
foreach ($data as $variable) {
$value = $variable->getValue();
$default = $variable->getDefaultValue();
if (Utils::isNull($value) === true) {
if (Utils::isNull($default) === false) {
return false;
}
} elseif ($value->equals($default) === false) {
return false;
}
}
return true;
} | [
"public",
"function",
"containsValuesEqualToVariableDefaultOnly",
"(",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"getDataPlaceHolder",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"variable",
")",
"{",
"$",
"value",
"=",
"$",
"variable",
"->",
"getValue",
"(",
")",
";",
"$",
"default",
"=",
"$",
"variable",
"->",
"getDefaultValue",
"(",
")",
";",
"if",
"(",
"Utils",
"::",
"isNull",
"(",
"$",
"value",
")",
"===",
"true",
")",
"{",
"if",
"(",
"Utils",
"::",
"isNull",
"(",
"$",
"default",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"}",
"elseif",
"(",
"$",
"value",
"->",
"equals",
"(",
"$",
"default",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Whether or not the State contains only values that are equals to their variable default value only.
@return boolean | [
"Whether",
"or",
"not",
"the",
"State",
"contains",
"only",
"values",
"that",
"are",
"equals",
"to",
"their",
"variable",
"default",
"value",
"only",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/common/State.php#L232-L250 |
oat-sa/qti-sdk | src/qtism/runtime/processing/TemplateProcessingEngine.php | TemplateProcessingEngine.setComponent | public function setComponent(QtiComponent $templateProcessing)
{
if ($templateProcessing instanceof TemplateProcessing) {
parent::setComponent($templateProcessing);
} else {
$msg = "The TemplateProcessing class only accepts TemplateProcessing objects to be executed.";
throw new InvalidArgumentException($msg);
}
} | php | public function setComponent(QtiComponent $templateProcessing)
{
if ($templateProcessing instanceof TemplateProcessing) {
parent::setComponent($templateProcessing);
} else {
$msg = "The TemplateProcessing class only accepts TemplateProcessing objects to be executed.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setComponent",
"(",
"QtiComponent",
"$",
"templateProcessing",
")",
"{",
"if",
"(",
"$",
"templateProcessing",
"instanceof",
"TemplateProcessing",
")",
"{",
"parent",
"::",
"setComponent",
"(",
"$",
"templateProcessing",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The TemplateProcessing class only accepts TemplateProcessing objects to be executed.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the TemplateProcessing object to be executed by the engine depending
on the current context.
@param \qtism\data\QtiComponent $templateProcessing A TemplateProcessing object.
@throws \InvalidArgumentException If $templateProcessing is not A TemplateProcessing object. | [
"Set",
"the",
"TemplateProcessing",
"object",
"to",
"be",
"executed",
"by",
"the",
"engine",
"depending",
"on",
"the",
"current",
"context",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/processing/TemplateProcessingEngine.php#L73-L81 |
oat-sa/qti-sdk | src/qtism/runtime/processing/TemplateProcessingEngine.php | TemplateProcessingEngine.process | public function process()
{
$context = $this->getContext();
$templateProcessing = $this->getComponent();
$trialCount = 0;
// Make a copy of possibly impacted variables.
$impactedVariables = Utils::templateProcessingImpactedVariables($templateProcessing);
$tplVarCopies = array();
foreach ($impactedVariables as $varIdentifier) {
$tplVarCopies[] = clone $context->getVariable($varIdentifier);
}
do {
$validConstraints = true;
try {
$trialCount++;
foreach ($templateProcessing->getTemplateRules() as $rule) {
$processor = $this->getRuleProcessorFactory()->createProcessor($rule);
$processor->setState($context);
$processor->process();
$this->trace($rule->getQtiClassName() . ' executed.');
}
} catch (RuleProcessingException $e) {
if ($e->getCode() === RuleProcessingException::EXIT_TEMPLATE) {
$this->trace('Termination of template processing.');
} else if ($e->getCode() === RuleProcessingException::TEMPLATE_CONSTRAINT_UNSATISFIED) {
$this->trace('Unsatisfied template constraint.');
// Reset variables with their originals.
foreach ($tplVarCopies as $copy) {
$context->getVariable($copy->getIdentifier())->setValue($copy->getDefaultValue());
$context->getVariable($copy->getIdentifier())->setDefaultValue($copy->getDefaultValue());
if ($copy instanceof ResponseVariable) {
$context->getVariable($copy->getIdentifier())->setCorrectResponse($copy->getCorrectResponse());
}
}
$validConstraints = false;
} else {
throw $e;
}
}
} while ($validConstraints === false && $trialCount < 100);
} | php | public function process()
{
$context = $this->getContext();
$templateProcessing = $this->getComponent();
$trialCount = 0;
// Make a copy of possibly impacted variables.
$impactedVariables = Utils::templateProcessingImpactedVariables($templateProcessing);
$tplVarCopies = array();
foreach ($impactedVariables as $varIdentifier) {
$tplVarCopies[] = clone $context->getVariable($varIdentifier);
}
do {
$validConstraints = true;
try {
$trialCount++;
foreach ($templateProcessing->getTemplateRules() as $rule) {
$processor = $this->getRuleProcessorFactory()->createProcessor($rule);
$processor->setState($context);
$processor->process();
$this->trace($rule->getQtiClassName() . ' executed.');
}
} catch (RuleProcessingException $e) {
if ($e->getCode() === RuleProcessingException::EXIT_TEMPLATE) {
$this->trace('Termination of template processing.');
} else if ($e->getCode() === RuleProcessingException::TEMPLATE_CONSTRAINT_UNSATISFIED) {
$this->trace('Unsatisfied template constraint.');
// Reset variables with their originals.
foreach ($tplVarCopies as $copy) {
$context->getVariable($copy->getIdentifier())->setValue($copy->getDefaultValue());
$context->getVariable($copy->getIdentifier())->setDefaultValue($copy->getDefaultValue());
if ($copy instanceof ResponseVariable) {
$context->getVariable($copy->getIdentifier())->setCorrectResponse($copy->getCorrectResponse());
}
}
$validConstraints = false;
} else {
throw $e;
}
}
} while ($validConstraints === false && $trialCount < 100);
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"context",
"=",
"$",
"this",
"->",
"getContext",
"(",
")",
";",
"$",
"templateProcessing",
"=",
"$",
"this",
"->",
"getComponent",
"(",
")",
";",
"$",
"trialCount",
"=",
"0",
";",
"// Make a copy of possibly impacted variables.",
"$",
"impactedVariables",
"=",
"Utils",
"::",
"templateProcessingImpactedVariables",
"(",
"$",
"templateProcessing",
")",
";",
"$",
"tplVarCopies",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"impactedVariables",
"as",
"$",
"varIdentifier",
")",
"{",
"$",
"tplVarCopies",
"[",
"]",
"=",
"clone",
"$",
"context",
"->",
"getVariable",
"(",
"$",
"varIdentifier",
")",
";",
"}",
"do",
"{",
"$",
"validConstraints",
"=",
"true",
";",
"try",
"{",
"$",
"trialCount",
"++",
";",
"foreach",
"(",
"$",
"templateProcessing",
"->",
"getTemplateRules",
"(",
")",
"as",
"$",
"rule",
")",
"{",
"$",
"processor",
"=",
"$",
"this",
"->",
"getRuleProcessorFactory",
"(",
")",
"->",
"createProcessor",
"(",
"$",
"rule",
")",
";",
"$",
"processor",
"->",
"setState",
"(",
"$",
"context",
")",
";",
"$",
"processor",
"->",
"process",
"(",
")",
";",
"$",
"this",
"->",
"trace",
"(",
"$",
"rule",
"->",
"getQtiClassName",
"(",
")",
".",
"' executed.'",
")",
";",
"}",
"}",
"catch",
"(",
"RuleProcessingException",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"e",
"->",
"getCode",
"(",
")",
"===",
"RuleProcessingException",
"::",
"EXIT_TEMPLATE",
")",
"{",
"$",
"this",
"->",
"trace",
"(",
"'Termination of template processing.'",
")",
";",
"}",
"else",
"if",
"(",
"$",
"e",
"->",
"getCode",
"(",
")",
"===",
"RuleProcessingException",
"::",
"TEMPLATE_CONSTRAINT_UNSATISFIED",
")",
"{",
"$",
"this",
"->",
"trace",
"(",
"'Unsatisfied template constraint.'",
")",
";",
"// Reset variables with their originals.",
"foreach",
"(",
"$",
"tplVarCopies",
"as",
"$",
"copy",
")",
"{",
"$",
"context",
"->",
"getVariable",
"(",
"$",
"copy",
"->",
"getIdentifier",
"(",
")",
")",
"->",
"setValue",
"(",
"$",
"copy",
"->",
"getDefaultValue",
"(",
")",
")",
";",
"$",
"context",
"->",
"getVariable",
"(",
"$",
"copy",
"->",
"getIdentifier",
"(",
")",
")",
"->",
"setDefaultValue",
"(",
"$",
"copy",
"->",
"getDefaultValue",
"(",
")",
")",
";",
"if",
"(",
"$",
"copy",
"instanceof",
"ResponseVariable",
")",
"{",
"$",
"context",
"->",
"getVariable",
"(",
"$",
"copy",
"->",
"getIdentifier",
"(",
")",
")",
"->",
"setCorrectResponse",
"(",
"$",
"copy",
"->",
"getCorrectResponse",
"(",
")",
")",
";",
"}",
"}",
"$",
"validConstraints",
"=",
"false",
";",
"}",
"else",
"{",
"throw",
"$",
"e",
";",
"}",
"}",
"}",
"while",
"(",
"$",
"validConstraints",
"===",
"false",
"&&",
"$",
"trialCount",
"<",
"100",
")",
";",
"}"
] | Process the template processing.
@throws \qtism\runtime\common\ProcessingException If an error occurs while executing the TemplateProcessing. | [
"Process",
"the",
"template",
"processing",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/processing/TemplateProcessingEngine.php#L108-L156 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/RandomFloatMarshaller.php | RandomFloatMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
// max attribute is mandatory.
if (($max = $this->getDOMElementAttributeAs($element, 'max')) !== null) {
$max = (Format::isVariableRef($max)) ? $max : floatval($max);
$object = new RandomFloat(0.0, $max);
if (($min = $this->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);
}
} | php | protected function unmarshall(DOMElement $element)
{
// max attribute is mandatory.
if (($max = $this->getDOMElementAttributeAs($element, 'max')) !== null) {
$max = (Format::isVariableRef($max)) ? $max : floatval($max);
$object = new RandomFloat(0.0, $max);
if (($min = $this->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);
}
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"// max attribute is mandatory.",
"if",
"(",
"(",
"$",
"max",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'max'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"max",
"=",
"(",
"Format",
"::",
"isVariableRef",
"(",
"$",
"max",
")",
")",
"?",
"$",
"max",
":",
"floatval",
"(",
"$",
"max",
")",
";",
"$",
"object",
"=",
"new",
"RandomFloat",
"(",
"0.0",
",",
"$",
"max",
")",
";",
"if",
"(",
"(",
"$",
"min",
"=",
"$",
"this",
"->",
"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 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. | [
"Unmarshall",
"a",
"DOMElement",
"object",
"corresponding",
"to",
"a",
"QTI",
"randomFloat",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/RandomFloatMarshaller.php#L61-L79 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/MathConstantProcessor.php | MathConstantProcessor.process | public function process()
{
$expr = $this->getExpression();
if ($expr->getName() === MathEnumeration::E) {
return new QtiFloat(M_E);
} else {
return new QtiFloat(M_PI);
}
} | php | public function process()
{
$expr = $this->getExpression();
if ($expr->getName() === MathEnumeration::E) {
return new QtiFloat(M_E);
} else {
return new QtiFloat(M_PI);
}
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"expr",
"=",
"$",
"this",
"->",
"getExpression",
"(",
")",
";",
"if",
"(",
"$",
"expr",
"->",
"getName",
"(",
")",
"===",
"MathEnumeration",
"::",
"E",
")",
"{",
"return",
"new",
"QtiFloat",
"(",
"M_E",
")",
";",
"}",
"else",
"{",
"return",
"new",
"QtiFloat",
"(",
"M_PI",
")",
";",
"}",
"}"
] | Process the MathConstant Expression.
@return float A float value (e or pi). | [
"Process",
"the",
"MathConstant",
"Expression",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/MathConstantProcessor.php#L48-L56 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/custom/Explode.php | Explode.process | public function process()
{
$operands = $this->getOperands();
if (($c = count($operands)) < 2) {
$msg = "The 'qtism.runtime.expressions.operators.custom.Explode' custom operator takes 2 sub-expressions as parameters, ${c} given.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::NOT_ENOUGH_OPERANDS);
} elseif ($operands->containsNull() === true) {
return null;
} elseif ($operands->exclusivelySingle() === false) {
$msg = "The 'qtism.runtime.expressions.operators.custom.Explode' custom operator only accepts operands with single cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
} elseif ($operands->exclusivelyString() === false) {
$msg = "The 'qtism.runtime.expressions.operators.custom.Explode' custom operator only accepts operands with a string baseType.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
}
$delimiter = $operands[0]->getValue();
$string = $operands[1]->getValue();
// Note: explode() is binary-safe \0/!
$strings = explode($delimiter, $string);
$ordered = new OrderedContainer(BaseType::STRING);
foreach ($strings as $str) {
$ordered[] = new QtiString($str);
}
return $ordered;
} | php | public function process()
{
$operands = $this->getOperands();
if (($c = count($operands)) < 2) {
$msg = "The 'qtism.runtime.expressions.operators.custom.Explode' custom operator takes 2 sub-expressions as parameters, ${c} given.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::NOT_ENOUGH_OPERANDS);
} elseif ($operands->containsNull() === true) {
return null;
} elseif ($operands->exclusivelySingle() === false) {
$msg = "The 'qtism.runtime.expressions.operators.custom.Explode' custom operator only accepts operands with single cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
} elseif ($operands->exclusivelyString() === false) {
$msg = "The 'qtism.runtime.expressions.operators.custom.Explode' custom operator only accepts operands with a string baseType.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
}
$delimiter = $operands[0]->getValue();
$string = $operands[1]->getValue();
// Note: explode() is binary-safe \0/!
$strings = explode($delimiter, $string);
$ordered = new OrderedContainer(BaseType::STRING);
foreach ($strings as $str) {
$ordered[] = new QtiString($str);
}
return $ordered;
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"operands",
"=",
"$",
"this",
"->",
"getOperands",
"(",
")",
";",
"if",
"(",
"(",
"$",
"c",
"=",
"count",
"(",
"$",
"operands",
")",
")",
"<",
"2",
")",
"{",
"$",
"msg",
"=",
"\"The 'qtism.runtime.expressions.operators.custom.Explode' custom operator takes 2 sub-expressions as parameters, ${c} given.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"NOT_ENOUGH_OPERANDS",
")",
";",
"}",
"elseif",
"(",
"$",
"operands",
"->",
"containsNull",
"(",
")",
"===",
"true",
")",
"{",
"return",
"null",
";",
"}",
"elseif",
"(",
"$",
"operands",
"->",
"exclusivelySingle",
"(",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The 'qtism.runtime.expressions.operators.custom.Explode' custom operator only accepts operands with single cardinality.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_CARDINALITY",
")",
";",
"}",
"elseif",
"(",
"$",
"operands",
"->",
"exclusivelyString",
"(",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The 'qtism.runtime.expressions.operators.custom.Explode' custom operator only accepts operands with a string baseType.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_BASETYPE",
")",
";",
"}",
"$",
"delimiter",
"=",
"$",
"operands",
"[",
"0",
"]",
"->",
"getValue",
"(",
")",
";",
"$",
"string",
"=",
"$",
"operands",
"[",
"1",
"]",
"->",
"getValue",
"(",
")",
";",
"// Note: explode() is binary-safe \\0/!",
"$",
"strings",
"=",
"explode",
"(",
"$",
"delimiter",
",",
"$",
"string",
")",
";",
"$",
"ordered",
"=",
"new",
"OrderedContainer",
"(",
"BaseType",
"::",
"STRING",
")",
";",
"foreach",
"(",
"$",
"strings",
"as",
"$",
"str",
")",
"{",
"$",
"ordered",
"[",
"]",
"=",
"new",
"QtiString",
"(",
"$",
"str",
")",
";",
"}",
"return",
"$",
"ordered",
";",
"}"
] | Process the expression by implementing PHP core's explode function.
@return \qtism\runtime\common\OrderedContainer The split value of the second sub-expression given as a parameter.
@throws \qtism\runtime\expressions\operators\OperatorProcessingException If something goes wrong. | [
"Process",
"the",
"expression",
"by",
"implementing",
"PHP",
"core",
"s",
"explode",
"function",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/custom/Explode.php#L59-L88 |
oat-sa/qti-sdk | src/qtism/data/content/FeedbackBlock.php | FeedbackBlock.setOutcomeIdentifier | public function setOutcomeIdentifier($outcomeIdentifier)
{
if (Format::isIdentifier($outcomeIdentifier, false) === true) {
$this->outcomeIdentifier = $outcomeIdentifier;
} else {
$msg = "The 'outcomeIdentifier' argument must be a valid QTI identifier, '" . $outcomeIdentifier . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setOutcomeIdentifier($outcomeIdentifier)
{
if (Format::isIdentifier($outcomeIdentifier, false) === true) {
$this->outcomeIdentifier = $outcomeIdentifier;
} else {
$msg = "The 'outcomeIdentifier' argument must be a valid QTI identifier, '" . $outcomeIdentifier . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setOutcomeIdentifier",
"(",
"$",
"outcomeIdentifier",
")",
"{",
"if",
"(",
"Format",
"::",
"isIdentifier",
"(",
"$",
"outcomeIdentifier",
",",
"false",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"outcomeIdentifier",
"=",
"$",
"outcomeIdentifier",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'outcomeIdentifier' argument must be a valid QTI identifier, '\"",
".",
"$",
"outcomeIdentifier",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | The identifier of an outcome variable ruling the visibility of the feedbackBlock.
@param string $identifier A QTI identifier.
@throws \InvalidArgumentException If $outcomeIdentifier is an invalid identifier. | [
"The",
"identifier",
"of",
"an",
"outcome",
"variable",
"ruling",
"the",
"visibility",
"of",
"the",
"feedbackBlock",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/FeedbackBlock.php#L113-L121 |
oat-sa/qti-sdk | src/qtism/data/content/FeedbackBlock.php | FeedbackBlock.setIdentifier | public function setIdentifier($identifier)
{
if (Format::isIdentifier($identifier, false) === true) {
$this->identifier = $identifier;
} else {
$msg = "The 'identifier' argument must be a valid QTI identifier, '" . $identifier . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setIdentifier($identifier)
{
if (Format::isIdentifier($identifier, false) === true) {
$this->identifier = $identifier;
} else {
$msg = "The 'identifier' argument must be a valid QTI identifier, '" . $identifier . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setIdentifier",
"(",
"$",
"identifier",
")",
"{",
"if",
"(",
"Format",
"::",
"isIdentifier",
"(",
"$",
"identifier",
",",
"false",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"identifier",
"=",
"$",
"identifier",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'identifier' argument must be a valid QTI identifier, '\"",
".",
"$",
"identifier",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the identifier to match in order to show/hide the feedbackBlock.
@param string $identifier A QTI identifier.
@throws \InvalidArgumentException If $identifier is not a valid QTI identifier. | [
"Set",
"the",
"identifier",
"to",
"match",
"in",
"order",
"to",
"show",
"/",
"hide",
"the",
"feedbackBlock",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/FeedbackBlock.php#L166-L174 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/RoundProcessor.php | RoundProcessor.process | public function process()
{
$operands = $this->getOperands();
if ($operands->containsNull() === true) {
return null;
}
if ($operands->exclusivelySingle() === false) {
$msg = "The Round operator only accepts operands with a single cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
if ($operands->exclusivelyNumeric() === false) {
$msg = "The Round operator only accepts operands with baseType integer or float.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
}
$operand = $operands[0];
$mode = ($operand->getValue() >= 0) ? PHP_ROUND_HALF_UP : PHP_ROUND_HALF_DOWN;
return new QtiInteger(intval(round($operand->getValue(), 0, $mode)));
} | php | public function process()
{
$operands = $this->getOperands();
if ($operands->containsNull() === true) {
return null;
}
if ($operands->exclusivelySingle() === false) {
$msg = "The Round operator only accepts operands with a single cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
if ($operands->exclusivelyNumeric() === false) {
$msg = "The Round operator only accepts operands with baseType integer or float.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
}
$operand = $operands[0];
$mode = ($operand->getValue() >= 0) ? PHP_ROUND_HALF_UP : PHP_ROUND_HALF_DOWN;
return new QtiInteger(intval(round($operand->getValue(), 0, $mode)));
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"operands",
"=",
"$",
"this",
"->",
"getOperands",
"(",
")",
";",
"if",
"(",
"$",
"operands",
"->",
"containsNull",
"(",
")",
"===",
"true",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"operands",
"->",
"exclusivelySingle",
"(",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The Round operator only accepts operands with a single cardinality.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_CARDINALITY",
")",
";",
"}",
"if",
"(",
"$",
"operands",
"->",
"exclusivelyNumeric",
"(",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The Round operator only accepts operands with baseType integer or float.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_BASETYPE",
")",
";",
"}",
"$",
"operand",
"=",
"$",
"operands",
"[",
"0",
"]",
";",
"$",
"mode",
"=",
"(",
"$",
"operand",
"->",
"getValue",
"(",
")",
">=",
"0",
")",
"?",
"PHP_ROUND_HALF_UP",
":",
"PHP_ROUND_HALF_DOWN",
";",
"return",
"new",
"QtiInteger",
"(",
"intval",
"(",
"round",
"(",
"$",
"operand",
"->",
"getValue",
"(",
")",
",",
"0",
",",
"$",
"mode",
")",
")",
")",
";",
"}"
] | Process the Round operator.
@return integer|null An integer value formed by rounding the value of the sub-expression or NULL if the sub-expression is NULL.
@throws \qtism\runtime\expressions\operators\OperatorProcessingException | [
"Process",
"the",
"Round",
"operator",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/RoundProcessor.php#L54-L76 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/AssociationValidityConstraintMarshaller.php | AssociationValidityConstraintMarshaller.marshall | public function marshall(QtiComponent $component)
{
$element = self::getDOMCradle()->createElement($component->getQtiClassName());
$this->setDOMElementAttribute($element, 'identifier', $component->getIdentifier());
$this->setDOMElementAttribute($element, 'minConstraint', $component->getMinConstraint());
$this->setDOMElementAttribute($element, 'maxConstraint', $component->getMaxConstraint());
return $element;
} | php | public function marshall(QtiComponent $component)
{
$element = self::getDOMCradle()->createElement($component->getQtiClassName());
$this->setDOMElementAttribute($element, 'identifier', $component->getIdentifier());
$this->setDOMElementAttribute($element, 'minConstraint', $component->getMinConstraint());
$this->setDOMElementAttribute($element, 'maxConstraint', $component->getMaxConstraint());
return $element;
} | [
"public",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"$",
"element",
"=",
"self",
"::",
"getDOMCradle",
"(",
")",
"->",
"createElement",
"(",
"$",
"component",
"->",
"getQtiClassName",
"(",
")",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'identifier'",
",",
"$",
"component",
"->",
"getIdentifier",
"(",
")",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'minConstraint'",
",",
"$",
"component",
"->",
"getMinConstraint",
"(",
")",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'maxConstraint'",
",",
"$",
"component",
"->",
"getMaxConstraint",
"(",
")",
")",
";",
"return",
"$",
"element",
";",
"}"
] | Marshall an AssociationValidityConstraint object to its XML counterpart.
@param \qtism\data\QtiComponent $component
@return \DOMElement | [
"Marshall",
"an",
"AssociationValidityConstraint",
"object",
"to",
"its",
"XML",
"counterpart",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/AssociationValidityConstraintMarshaller.php#L44-L52 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/AssociationValidityConstraintMarshaller.php | AssociationValidityConstraintMarshaller.unmarshall | public function unmarshall(DOMElement $element)
{
if (($identifier = $this->getDOMElementAttributeAs($element, 'identifier')) !== null) {
if (($minConstraint = $this->getDOMElementAttributeAs($element, 'minConstraint', 'integer')) !== null) {
if (($maxConstraint = $this->getDOMElementAttributeAs($element, 'maxConstraint', 'integer')) !== null) {
try {
return new AssociationValidityConstraint($identifier, $minConstraint, $maxConstraint);
} catch (InvalidArgumentException $e) {
throw new UnmarshallingException(
"An error occured while unmarshalling an 'associationValidityConstraint' element. See chained exceptions for more information.",
$element,
$e
);
}
} else {
throw new UnmarshallingException(
"The mandatory 'maxConstraint' attribute is missing from element 'associationValididtyConstraint'.",
$element
);
}
} else {
throw new UnmarshallingException(
"The mandatory 'minConstraint' attribute is missing from element 'associationValididtyConstraint'.",
$element
);
}
} else {
throw new UnmarshallingException(
"The mandatory 'identifier' attribute is missing from element 'associationValididtyConstraint'.",
$element
);
}
} | php | public function unmarshall(DOMElement $element)
{
if (($identifier = $this->getDOMElementAttributeAs($element, 'identifier')) !== null) {
if (($minConstraint = $this->getDOMElementAttributeAs($element, 'minConstraint', 'integer')) !== null) {
if (($maxConstraint = $this->getDOMElementAttributeAs($element, 'maxConstraint', 'integer')) !== null) {
try {
return new AssociationValidityConstraint($identifier, $minConstraint, $maxConstraint);
} catch (InvalidArgumentException $e) {
throw new UnmarshallingException(
"An error occured while unmarshalling an 'associationValidityConstraint' element. See chained exceptions for more information.",
$element,
$e
);
}
} else {
throw new UnmarshallingException(
"The mandatory 'maxConstraint' attribute is missing from element 'associationValididtyConstraint'.",
$element
);
}
} else {
throw new UnmarshallingException(
"The mandatory 'minConstraint' attribute is missing from element 'associationValididtyConstraint'.",
$element
);
}
} else {
throw new UnmarshallingException(
"The mandatory 'identifier' attribute is missing from element 'associationValididtyConstraint'.",
$element
);
}
} | [
"public",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"if",
"(",
"(",
"$",
"identifier",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'identifier'",
")",
")",
"!==",
"null",
")",
"{",
"if",
"(",
"(",
"$",
"minConstraint",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'minConstraint'",
",",
"'integer'",
")",
")",
"!==",
"null",
")",
"{",
"if",
"(",
"(",
"$",
"maxConstraint",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'maxConstraint'",
",",
"'integer'",
")",
")",
"!==",
"null",
")",
"{",
"try",
"{",
"return",
"new",
"AssociationValidityConstraint",
"(",
"$",
"identifier",
",",
"$",
"minConstraint",
",",
"$",
"maxConstraint",
")",
";",
"}",
"catch",
"(",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"throw",
"new",
"UnmarshallingException",
"(",
"\"An error occured while unmarshalling an 'associationValidityConstraint' element. See chained exceptions for more information.\"",
",",
"$",
"element",
",",
"$",
"e",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"UnmarshallingException",
"(",
"\"The mandatory 'maxConstraint' attribute is missing from element 'associationValididtyConstraint'.\"",
",",
"$",
"element",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"UnmarshallingException",
"(",
"\"The mandatory 'minConstraint' attribute is missing from element 'associationValididtyConstraint'.\"",
",",
"$",
"element",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"UnmarshallingException",
"(",
"\"The mandatory 'identifier' attribute is missing from element 'associationValididtyConstraint'.\"",
",",
"$",
"element",
")",
";",
"}",
"}"
] | Unmarshall a DOMElement to its AssociationValidityConstraint data model representation.
@param \DOMElement $element
@return \qtism\data\QtiComponent An AssociationValidityConstraint object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException | [
"Unmarshall",
"a",
"DOMElement",
"to",
"its",
"AssociationValidityConstraint",
"data",
"model",
"representation",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/AssociationValidityConstraintMarshaller.php#L61-L97 |
oat-sa/qti-sdk | src/qtism/data/storage/php/marshalling/PhpCollectionMarshaller.php | PhpCollectionMarshaller.marshall | public function marshall()
{
$collection = $this->getToMarshall();
$ctx = $this->getContext();
$access = $ctx->getStreamAccess();
$valueArray = $collection->getArrayCopy();
$valueArrayVarName = $ctx->generateVariableName($valueArray);
$arrayArgs = new PhpArgumentCollection();
if (($count = count($collection)) > 0) {
foreach ($ctx->popFromVariableStack($count) as $itemName) {
$arrayArgs[] = new PhpArgument(new PhpVariable($itemName));
}
}
try {
$access->writeVariable($valueArrayVarName);
$access->writeEquals($ctx->mustFormatOutput());
$access->writeFunctionCall('array', $arrayArgs);
$access->writeSemicolon($ctx->mustFormatOutput());
$collectionVarName = $ctx->generateVariableName($collection);
$access->writeVariable($collectionVarName);
$access->writeEquals($ctx->mustFormatOutput());
$collectionArgs = new PhpArgumentCollection(array(new PhpArgument(new PhpVariable($valueArrayVarName))));
$access->writeInstantiation(get_class($collection), $collectionArgs);
$access->writeSemicolon($ctx->mustFormatOutput());
$ctx->pushOnVariableStack($collectionVarName);
} catch (StreamAccessException $e) {
$msg = "An error occured while marshalling a collection into PHP source code.";
throw new PhpMarshallingException($msg, PhpMarshallingException::STREAM, $e);
}
} | php | public function marshall()
{
$collection = $this->getToMarshall();
$ctx = $this->getContext();
$access = $ctx->getStreamAccess();
$valueArray = $collection->getArrayCopy();
$valueArrayVarName = $ctx->generateVariableName($valueArray);
$arrayArgs = new PhpArgumentCollection();
if (($count = count($collection)) > 0) {
foreach ($ctx->popFromVariableStack($count) as $itemName) {
$arrayArgs[] = new PhpArgument(new PhpVariable($itemName));
}
}
try {
$access->writeVariable($valueArrayVarName);
$access->writeEquals($ctx->mustFormatOutput());
$access->writeFunctionCall('array', $arrayArgs);
$access->writeSemicolon($ctx->mustFormatOutput());
$collectionVarName = $ctx->generateVariableName($collection);
$access->writeVariable($collectionVarName);
$access->writeEquals($ctx->mustFormatOutput());
$collectionArgs = new PhpArgumentCollection(array(new PhpArgument(new PhpVariable($valueArrayVarName))));
$access->writeInstantiation(get_class($collection), $collectionArgs);
$access->writeSemicolon($ctx->mustFormatOutput());
$ctx->pushOnVariableStack($collectionVarName);
} catch (StreamAccessException $e) {
$msg = "An error occured while marshalling a collection into PHP source code.";
throw new PhpMarshallingException($msg, PhpMarshallingException::STREAM, $e);
}
} | [
"public",
"function",
"marshall",
"(",
")",
"{",
"$",
"collection",
"=",
"$",
"this",
"->",
"getToMarshall",
"(",
")",
";",
"$",
"ctx",
"=",
"$",
"this",
"->",
"getContext",
"(",
")",
";",
"$",
"access",
"=",
"$",
"ctx",
"->",
"getStreamAccess",
"(",
")",
";",
"$",
"valueArray",
"=",
"$",
"collection",
"->",
"getArrayCopy",
"(",
")",
";",
"$",
"valueArrayVarName",
"=",
"$",
"ctx",
"->",
"generateVariableName",
"(",
"$",
"valueArray",
")",
";",
"$",
"arrayArgs",
"=",
"new",
"PhpArgumentCollection",
"(",
")",
";",
"if",
"(",
"(",
"$",
"count",
"=",
"count",
"(",
"$",
"collection",
")",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"ctx",
"->",
"popFromVariableStack",
"(",
"$",
"count",
")",
"as",
"$",
"itemName",
")",
"{",
"$",
"arrayArgs",
"[",
"]",
"=",
"new",
"PhpArgument",
"(",
"new",
"PhpVariable",
"(",
"$",
"itemName",
")",
")",
";",
"}",
"}",
"try",
"{",
"$",
"access",
"->",
"writeVariable",
"(",
"$",
"valueArrayVarName",
")",
";",
"$",
"access",
"->",
"writeEquals",
"(",
"$",
"ctx",
"->",
"mustFormatOutput",
"(",
")",
")",
";",
"$",
"access",
"->",
"writeFunctionCall",
"(",
"'array'",
",",
"$",
"arrayArgs",
")",
";",
"$",
"access",
"->",
"writeSemicolon",
"(",
"$",
"ctx",
"->",
"mustFormatOutput",
"(",
")",
")",
";",
"$",
"collectionVarName",
"=",
"$",
"ctx",
"->",
"generateVariableName",
"(",
"$",
"collection",
")",
";",
"$",
"access",
"->",
"writeVariable",
"(",
"$",
"collectionVarName",
")",
";",
"$",
"access",
"->",
"writeEquals",
"(",
"$",
"ctx",
"->",
"mustFormatOutput",
"(",
")",
")",
";",
"$",
"collectionArgs",
"=",
"new",
"PhpArgumentCollection",
"(",
"array",
"(",
"new",
"PhpArgument",
"(",
"new",
"PhpVariable",
"(",
"$",
"valueArrayVarName",
")",
")",
")",
")",
";",
"$",
"access",
"->",
"writeInstantiation",
"(",
"get_class",
"(",
"$",
"collection",
")",
",",
"$",
"collectionArgs",
")",
";",
"$",
"access",
"->",
"writeSemicolon",
"(",
"$",
"ctx",
"->",
"mustFormatOutput",
"(",
")",
")",
";",
"$",
"ctx",
"->",
"pushOnVariableStack",
"(",
"$",
"collectionVarName",
")",
";",
"}",
"catch",
"(",
"StreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while marshalling a collection into PHP source code.\"",
";",
"throw",
"new",
"PhpMarshallingException",
"(",
"$",
"msg",
",",
"PhpMarshallingException",
"::",
"STREAM",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Marshall AbstractCollection objects into PHP source code.
@throws \qtism\data\storage\php\marshalling\PhpMarshallingException If something wrong happens during marshalling. | [
"Marshall",
"AbstractCollection",
"objects",
"into",
"PHP",
"source",
"code",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/php/marshalling/PhpCollectionMarshaller.php#L44-L78 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/SectionPartMarshaller.php | SectionPartMarshaller.marshall | protected function marshall(QtiComponent $component)
{
$element = static::getDOMCradle()->createElement($component->getQtiClassName());
$this->setDOMElementAttribute($element, 'identifier', $component->getIdentifier());
$this->setDOMElementAttribute($element, 'required', $component->isRequired());
$this->setDOMElementAttribute($element, 'fixed', $component->isFixed());
foreach ($component->getPreConditions() as $preCondition) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($preCondition);
$element->appendChild($marshaller->marshall($preCondition));
}
foreach ($component->getBranchRules() as $branchRule) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($branchRule);
$element->appendChild($marshaller->marshall($branchRule));
}
if ($component->getItemSessionControl() != null) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($component->getItemSessionControl());
$element->appendChild($marshaller->marshall($component->getItemSessionControl()));
}
if ($component->getTimeLimits() != null) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($component->getTimeLimits());
$element->appendChild($marshaller->marshall($component->getTimeLimits()));
}
return $element;
} | php | protected function marshall(QtiComponent $component)
{
$element = static::getDOMCradle()->createElement($component->getQtiClassName());
$this->setDOMElementAttribute($element, 'identifier', $component->getIdentifier());
$this->setDOMElementAttribute($element, 'required', $component->isRequired());
$this->setDOMElementAttribute($element, 'fixed', $component->isFixed());
foreach ($component->getPreConditions() as $preCondition) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($preCondition);
$element->appendChild($marshaller->marshall($preCondition));
}
foreach ($component->getBranchRules() as $branchRule) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($branchRule);
$element->appendChild($marshaller->marshall($branchRule));
}
if ($component->getItemSessionControl() != null) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($component->getItemSessionControl());
$element->appendChild($marshaller->marshall($component->getItemSessionControl()));
}
if ($component->getTimeLimits() != null) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($component->getTimeLimits());
$element->appendChild($marshaller->marshall($component->getTimeLimits()));
}
return $element;
} | [
"protected",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"$",
"element",
"=",
"static",
"::",
"getDOMCradle",
"(",
")",
"->",
"createElement",
"(",
"$",
"component",
"->",
"getQtiClassName",
"(",
")",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'identifier'",
",",
"$",
"component",
"->",
"getIdentifier",
"(",
")",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'required'",
",",
"$",
"component",
"->",
"isRequired",
"(",
")",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'fixed'",
",",
"$",
"component",
"->",
"isFixed",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"component",
"->",
"getPreConditions",
"(",
")",
"as",
"$",
"preCondition",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"preCondition",
")",
";",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"marshaller",
"->",
"marshall",
"(",
"$",
"preCondition",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"component",
"->",
"getBranchRules",
"(",
")",
"as",
"$",
"branchRule",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"branchRule",
")",
";",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"marshaller",
"->",
"marshall",
"(",
"$",
"branchRule",
")",
")",
";",
"}",
"if",
"(",
"$",
"component",
"->",
"getItemSessionControl",
"(",
")",
"!=",
"null",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"component",
"->",
"getItemSessionControl",
"(",
")",
")",
";",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"marshaller",
"->",
"marshall",
"(",
"$",
"component",
"->",
"getItemSessionControl",
"(",
")",
")",
")",
";",
"}",
"if",
"(",
"$",
"component",
"->",
"getTimeLimits",
"(",
")",
"!=",
"null",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"component",
"->",
"getTimeLimits",
"(",
")",
")",
";",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"marshaller",
"->",
"marshall",
"(",
"$",
"component",
"->",
"getTimeLimits",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"element",
";",
"}"
] | Marshall a SectionPart object into a DOMElement object.
@param \qtism\data\QtiComponent $component A SectionPart object.
@return \DOMElement The according DOMElement object. | [
"Marshall",
"a",
"SectionPart",
"object",
"into",
"a",
"DOMElement",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/SectionPartMarshaller.php#L47-L76 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/SectionPartMarshaller.php | SectionPartMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
if (($identifier = $this->getDOMElementAttributeAs($element, 'identifier')) !== null) {
$object = new SectionPart($identifier);
if (($required = $this->getDOMElementAttributeAs($element, 'required', 'boolean')) !== null) {
$object->setRequired($required);
}
if (($fixed = $this->getDOMElementAttributeAs($element, 'fixed', 'boolean')) !== null) {
$object->setFixed($fixed);
}
$preConditionElts = $this->getChildElementsByTagName($element, 'preCondition');
if (count($preConditionElts) > 0) {
$preConditions = new PreConditionCollection();
for ($i = 0; $i < count($preConditionElts); $i++) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($preConditionElts[$i]);
$preConditions[] = $marshaller->unmarshall($preConditionElts[$i]);
}
$object->setPreConditions($preConditions);
}
$branchRuleElts = $this->getChildElementsByTagName($element, 'branchRule');
if (count($branchRuleElts) > 0) {
$branchRules = new BranchRuleCollection();
for ($i = 0; $i < count($branchRuleElts); $i++) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($branchRuleElts[$i]);
$branchRules[] = $marshaller->unmarshall($branchRuleElts[$i]);
}
$object->setBranchRules($branchRules);
}
$itemSessionControlElts = $this->getChildElementsByTagName($element, 'itemSessionControl');
if (count($itemSessionControlElts) == 1) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($itemSessionControlElts[0]);
$object->setItemSessionControl($marshaller->unmarshall($itemSessionControlElts[0]));
}
$timeLimitsElts = $this->getChildElementsByTagName($element, 'timeLimits');
if (count($timeLimitsElts) == 1) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($timeLimitsElts[0]);
$object->setTimeLimits($marshaller->unmarshall($timeLimitsElts[0]));
}
return $object;
} else {
$msg = "The mandatory attribute 'identifier' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} | php | protected function unmarshall(DOMElement $element)
{
if (($identifier = $this->getDOMElementAttributeAs($element, 'identifier')) !== null) {
$object = new SectionPart($identifier);
if (($required = $this->getDOMElementAttributeAs($element, 'required', 'boolean')) !== null) {
$object->setRequired($required);
}
if (($fixed = $this->getDOMElementAttributeAs($element, 'fixed', 'boolean')) !== null) {
$object->setFixed($fixed);
}
$preConditionElts = $this->getChildElementsByTagName($element, 'preCondition');
if (count($preConditionElts) > 0) {
$preConditions = new PreConditionCollection();
for ($i = 0; $i < count($preConditionElts); $i++) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($preConditionElts[$i]);
$preConditions[] = $marshaller->unmarshall($preConditionElts[$i]);
}
$object->setPreConditions($preConditions);
}
$branchRuleElts = $this->getChildElementsByTagName($element, 'branchRule');
if (count($branchRuleElts) > 0) {
$branchRules = new BranchRuleCollection();
for ($i = 0; $i < count($branchRuleElts); $i++) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($branchRuleElts[$i]);
$branchRules[] = $marshaller->unmarshall($branchRuleElts[$i]);
}
$object->setBranchRules($branchRules);
}
$itemSessionControlElts = $this->getChildElementsByTagName($element, 'itemSessionControl');
if (count($itemSessionControlElts) == 1) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($itemSessionControlElts[0]);
$object->setItemSessionControl($marshaller->unmarshall($itemSessionControlElts[0]));
}
$timeLimitsElts = $this->getChildElementsByTagName($element, 'timeLimits');
if (count($timeLimitsElts) == 1) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($timeLimitsElts[0]);
$object->setTimeLimits($marshaller->unmarshall($timeLimitsElts[0]));
}
return $object;
} else {
$msg = "The mandatory attribute 'identifier' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"if",
"(",
"(",
"$",
"identifier",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'identifier'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"object",
"=",
"new",
"SectionPart",
"(",
"$",
"identifier",
")",
";",
"if",
"(",
"(",
"$",
"required",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'required'",
",",
"'boolean'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"object",
"->",
"setRequired",
"(",
"$",
"required",
")",
";",
"}",
"if",
"(",
"(",
"$",
"fixed",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'fixed'",
",",
"'boolean'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"object",
"->",
"setFixed",
"(",
"$",
"fixed",
")",
";",
"}",
"$",
"preConditionElts",
"=",
"$",
"this",
"->",
"getChildElementsByTagName",
"(",
"$",
"element",
",",
"'preCondition'",
")",
";",
"if",
"(",
"count",
"(",
"$",
"preConditionElts",
")",
">",
"0",
")",
"{",
"$",
"preConditions",
"=",
"new",
"PreConditionCollection",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"preConditionElts",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"preConditionElts",
"[",
"$",
"i",
"]",
")",
";",
"$",
"preConditions",
"[",
"]",
"=",
"$",
"marshaller",
"->",
"unmarshall",
"(",
"$",
"preConditionElts",
"[",
"$",
"i",
"]",
")",
";",
"}",
"$",
"object",
"->",
"setPreConditions",
"(",
"$",
"preConditions",
")",
";",
"}",
"$",
"branchRuleElts",
"=",
"$",
"this",
"->",
"getChildElementsByTagName",
"(",
"$",
"element",
",",
"'branchRule'",
")",
";",
"if",
"(",
"count",
"(",
"$",
"branchRuleElts",
")",
">",
"0",
")",
"{",
"$",
"branchRules",
"=",
"new",
"BranchRuleCollection",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"branchRuleElts",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"branchRuleElts",
"[",
"$",
"i",
"]",
")",
";",
"$",
"branchRules",
"[",
"]",
"=",
"$",
"marshaller",
"->",
"unmarshall",
"(",
"$",
"branchRuleElts",
"[",
"$",
"i",
"]",
")",
";",
"}",
"$",
"object",
"->",
"setBranchRules",
"(",
"$",
"branchRules",
")",
";",
"}",
"$",
"itemSessionControlElts",
"=",
"$",
"this",
"->",
"getChildElementsByTagName",
"(",
"$",
"element",
",",
"'itemSessionControl'",
")",
";",
"if",
"(",
"count",
"(",
"$",
"itemSessionControlElts",
")",
"==",
"1",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"itemSessionControlElts",
"[",
"0",
"]",
")",
";",
"$",
"object",
"->",
"setItemSessionControl",
"(",
"$",
"marshaller",
"->",
"unmarshall",
"(",
"$",
"itemSessionControlElts",
"[",
"0",
"]",
")",
")",
";",
"}",
"$",
"timeLimitsElts",
"=",
"$",
"this",
"->",
"getChildElementsByTagName",
"(",
"$",
"element",
",",
"'timeLimits'",
")",
";",
"if",
"(",
"count",
"(",
"$",
"timeLimitsElts",
")",
"==",
"1",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"timeLimitsElts",
"[",
"0",
"]",
")",
";",
"$",
"object",
"->",
"setTimeLimits",
"(",
"$",
"marshaller",
"->",
"unmarshall",
"(",
"$",
"timeLimitsElts",
"[",
"0",
"]",
")",
")",
";",
"}",
"return",
"$",
"object",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory attribute 'identifier' is missing from element '\"",
".",
"$",
"element",
"->",
"localName",
".",
"\"'.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}"
] | Unmarshall a DOMElement object corresponding to a QTI sectionPart element.
@param \DOMElement $element A DOMElement object.
@return \qtism\data\QtiComponent A SectionPart object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException | [
"Unmarshall",
"a",
"DOMElement",
"object",
"corresponding",
"to",
"a",
"QTI",
"sectionPart",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/SectionPartMarshaller.php#L85-L136 |
oat-sa/qti-sdk | src/qtism/data/storage/LocalFileResolver.php | LocalFileResolver.resolve | public function resolve($url)
{
$baseUrl = Utils::sanitizeUri($this->getBasePath());
$baseDir = pathinfo($baseUrl, PATHINFO_DIRNAME);
if (empty($baseDir)) {
$msg = "The base directory of the document ('${baseDir}') could not be resolved.";
throw new ResolutionException($msg);
}
$href = $baseDir . '/' . ltrim($url, '/');
return $href;
} | php | public function resolve($url)
{
$baseUrl = Utils::sanitizeUri($this->getBasePath());
$baseDir = pathinfo($baseUrl, PATHINFO_DIRNAME);
if (empty($baseDir)) {
$msg = "The base directory of the document ('${baseDir}') could not be resolved.";
throw new ResolutionException($msg);
}
$href = $baseDir . '/' . ltrim($url, '/');
return $href;
} | [
"public",
"function",
"resolve",
"(",
"$",
"url",
")",
"{",
"$",
"baseUrl",
"=",
"Utils",
"::",
"sanitizeUri",
"(",
"$",
"this",
"->",
"getBasePath",
"(",
")",
")",
";",
"$",
"baseDir",
"=",
"pathinfo",
"(",
"$",
"baseUrl",
",",
"PATHINFO_DIRNAME",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"baseDir",
")",
")",
"{",
"$",
"msg",
"=",
"\"The base directory of the document ('${baseDir}') could not be resolved.\"",
";",
"throw",
"new",
"ResolutionException",
"(",
"$",
"msg",
")",
";",
"}",
"$",
"href",
"=",
"$",
"baseDir",
".",
"'/'",
".",
"ltrim",
"(",
"$",
"url",
",",
"'/'",
")",
";",
"return",
"$",
"href",
";",
"}"
] | Resolve a relative $url to a canonical path based
on the LocalFileResolver's base path.
@param string $url A URL to be resolved.
@throws \qtism\common\ResolutionException If $url cannot be resolved. | [
"Resolve",
"a",
"relative",
"$url",
"to",
"a",
"canonical",
"path",
"based",
"on",
"the",
"LocalFileResolver",
"s",
"base",
"path",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/LocalFileResolver.php#L54-L67 |
oat-sa/qti-sdk | src/qtism/runtime/rendering/qtipl/expressions/operators/RoundToQtiPLRenderer.php | RoundToQtiPLRenderer.render | public function render($something)
{
$renderer = new QtiPLRenderer($this->getCRO());
$attributes = [];
if ($something->getRoundingMode() != RoundingMode::SIGNIFICANT_FIGURES) {
$attributes['roundingMode'] = "\"" . RoundingMode::getNameByConstant($something->getRoundingMode()) . "\"";
}
$attributes['figures'] = $something->getFigures();
return $something->getQtiClassName() . $renderer->writeAttributes($attributes)
. $renderer->writeChildElements($something->getExpressions());
} | php | public function render($something)
{
$renderer = new QtiPLRenderer($this->getCRO());
$attributes = [];
if ($something->getRoundingMode() != RoundingMode::SIGNIFICANT_FIGURES) {
$attributes['roundingMode'] = "\"" . RoundingMode::getNameByConstant($something->getRoundingMode()) . "\"";
}
$attributes['figures'] = $something->getFigures();
return $something->getQtiClassName() . $renderer->writeAttributes($attributes)
. $renderer->writeChildElements($something->getExpressions());
} | [
"public",
"function",
"render",
"(",
"$",
"something",
")",
"{",
"$",
"renderer",
"=",
"new",
"QtiPLRenderer",
"(",
"$",
"this",
"->",
"getCRO",
"(",
")",
")",
";",
"$",
"attributes",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"something",
"->",
"getRoundingMode",
"(",
")",
"!=",
"RoundingMode",
"::",
"SIGNIFICANT_FIGURES",
")",
"{",
"$",
"attributes",
"[",
"'roundingMode'",
"]",
"=",
"\"\\\"\"",
".",
"RoundingMode",
"::",
"getNameByConstant",
"(",
"$",
"something",
"->",
"getRoundingMode",
"(",
")",
")",
".",
"\"\\\"\"",
";",
"}",
"$",
"attributes",
"[",
"'figures'",
"]",
"=",
"$",
"something",
"->",
"getFigures",
"(",
")",
";",
"return",
"$",
"something",
"->",
"getQtiClassName",
"(",
")",
".",
"$",
"renderer",
"->",
"writeAttributes",
"(",
"$",
"attributes",
")",
".",
"$",
"renderer",
"->",
"writeChildElements",
"(",
"$",
"something",
"->",
"getExpressions",
"(",
")",
")",
";",
"}"
] | Render a QtiComponent object into another constitution.
@param mixed $something Something to render into another consitution.
@return mixed The rendered component into another constitution.
@throws \qtism\runtime\rendering\RenderingException If something goes wrong while rendering the component. | [
"Render",
"a",
"QtiComponent",
"object",
"into",
"another",
"constitution",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/qtipl/expressions/operators/RoundToQtiPLRenderer.php#L47-L60 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/DefaultProcessor.php | DefaultProcessor.process | public function process()
{
$expr = $this->getExpression();
$state = $this->getState();
$var = $state->getVariable($expr->getIdentifier());
return ($var === null) ? null : $var->getDefaultValue();
} | php | public function process()
{
$expr = $this->getExpression();
$state = $this->getState();
$var = $state->getVariable($expr->getIdentifier());
return ($var === null) ? null : $var->getDefaultValue();
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"expr",
"=",
"$",
"this",
"->",
"getExpression",
"(",
")",
";",
"$",
"state",
"=",
"$",
"this",
"->",
"getState",
"(",
")",
";",
"$",
"var",
"=",
"$",
"state",
"->",
"getVariable",
"(",
"$",
"expr",
"->",
"getIdentifier",
"(",
")",
")",
";",
"return",
"(",
"$",
"var",
"===",
"null",
")",
"?",
"null",
":",
"$",
"var",
"->",
"getDefaultValue",
"(",
")",
";",
"}"
] | Returns the defaultValue of the current Expression to be processed. If no Variable
with the given identifier is found, null is returned. If the Variable has no defaultValue,
null is returned.
@return mixed A QTI Runtime compliant value. | [
"Returns",
"the",
"defaultValue",
"of",
"the",
"current",
"Expression",
"to",
"be",
"processed",
".",
"If",
"no",
"Variable",
"with",
"the",
"given",
"identifier",
"is",
"found",
"null",
"is",
"returned",
".",
"If",
"the",
"Variable",
"has",
"no",
"defaultValue",
"null",
"is",
"returned",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/DefaultProcessor.php#L51-L59 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/SsmlSubMarshaller.php | SsmlSubMarshaller.marshall | protected function marshall(QtiComponent $component)
{
return self::getDOMCradle()->importNode($component->getXml()->documentElement, true);
} | php | protected function marshall(QtiComponent $component)
{
return self::getDOMCradle()->importNode($component->getXml()->documentElement, true);
} | [
"protected",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"return",
"self",
"::",
"getDOMCradle",
"(",
")",
"->",
"importNode",
"(",
"$",
"component",
"->",
"getXml",
"(",
")",
"->",
"documentElement",
",",
"true",
")",
";",
"}"
] | Marshall an SSML sub object into a DOMElement object.
@param \qtism\data\QtiComponent $component An SSML sub object.
@return \DOMElement The according DOMElement object.
@throws \MarshallingException | [
"Marshall",
"an",
"SSML",
"sub",
"object",
"into",
"a",
"DOMElement",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/SsmlSubMarshaller.php#L44-L47 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/SsmlSubMarshaller.php | SsmlSubMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
$node = $element->cloneNode(true);
return new Sub($element->ownerDocument->saveXML($node));
} | php | protected function unmarshall(DOMElement $element)
{
$node = $element->cloneNode(true);
return new Sub($element->ownerDocument->saveXML($node));
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"$",
"node",
"=",
"$",
"element",
"->",
"cloneNode",
"(",
"true",
")",
";",
"return",
"new",
"Sub",
"(",
"$",
"element",
"->",
"ownerDocument",
"->",
"saveXML",
"(",
"$",
"node",
")",
")",
";",
"}"
] | Unmarshall a DOMElement object corresponding to an SSML sub element.
@param \DOMElement $element A DOMElement object.
@return \qtism\data\QtiComponent An SSML sub object.
@throws \UnmarshallingException | [
"Unmarshall",
"a",
"DOMElement",
"object",
"corresponding",
"to",
"an",
"SSML",
"sub",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/SsmlSubMarshaller.php#L56-L61 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/OutcomeMaximumMarshaller.php | OutcomeMaximumMarshaller.marshall | protected function marshall(QtiComponent $component)
{
$element = parent::marshall($component);
$this->setDOMElementAttribute($element, 'outcomeIdentifier', $component->getOutcomeIdentifier());
$weightIdentifier = $component->getWeightIdentifier();
if (!empty($weightIdentifier)) {
$this->setDOMElementAttribute($element, 'weightIdentifier', $weightIdentifier);
}
return $element;
} | php | protected function marshall(QtiComponent $component)
{
$element = parent::marshall($component);
$this->setDOMElementAttribute($element, 'outcomeIdentifier', $component->getOutcomeIdentifier());
$weightIdentifier = $component->getWeightIdentifier();
if (!empty($weightIdentifier)) {
$this->setDOMElementAttribute($element, 'weightIdentifier', $weightIdentifier);
}
return $element;
} | [
"protected",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"$",
"element",
"=",
"parent",
"::",
"marshall",
"(",
"$",
"component",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'outcomeIdentifier'",
",",
"$",
"component",
"->",
"getOutcomeIdentifier",
"(",
")",
")",
";",
"$",
"weightIdentifier",
"=",
"$",
"component",
"->",
"getWeightIdentifier",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"weightIdentifier",
")",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'weightIdentifier'",
",",
"$",
"weightIdentifier",
")",
";",
"}",
"return",
"$",
"element",
";",
"}"
] | Marshall an outcomeMaximum object in its DOMElement equivalent.
@param \qtism\data\QtiComponent A OutcomeMaximum object.
@return \DOMElement The corresponding outcomeMaximum QTI element. | [
"Marshall",
"an",
"outcomeMaximum",
"object",
"in",
"its",
"DOMElement",
"equivalent",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/OutcomeMaximumMarshaller.php#L43-L54 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/TextInteractionMarshaller.php | TextInteractionMarshaller.marshall | protected function marshall(QtiComponent $component)
{
$element = $this->createElement($component);
$version = $this->getVersion();
$this->setDOMElementAttribute($element, 'responseIdentifier', $component->getResponseIdentifier());
if ($component->getBase() !== 10) {
$this->setDOMElementAttribute($element, 'base', $component->getBase());
}
if ($component->hasStringIdentifier() === true) {
$this->setDOMElementAttribute($element, 'stringIdentifier', $component->getStringIdentifier());
}
if ($component->hasExpectedLength() === true) {
$this->setDOMElementAttribute($element, 'expectedLength', $component->getExpectedLength());
}
if ($component->hasPatternMask() === true) {
$this->setDOMElementAttribute($element, 'patternMask', $component->getPatternMask());
}
if ($component->hasPlaceholderText() === true) {
$this->setDOMElementAttribute($element, 'placeholderText', $component->getPlaceholderText());
}
if ($component->hasXmlBase() === true) {
self::setXmlBase($element, $component->setXmlBase());
}
if ($element->localName === 'extendedTextInteraction') {
if ($component->hasMaxStrings() === true) {
$this->setDOMElementAttribute($element, 'maxStrings', $component->getMaxStrings());
}
if (Version::compare($version, '2.1.0', '>=') === true && $component->getMinStrings() !== 0) {
$this->setDOMElementAttribute($element, 'minStrings', $component->getMinStrings());
}
if ($component->hasExpectedLines() === true) {
$this->setDOMElementAttribute($element, 'expectedLines', $component->getExpectedLines());
}
if (Version::compare($version, '2.1.0', '>=') === true && $component->getFormat() !== TextFormat::PLAIN) {
$this->setDOMElementAttribute($element, 'format', TextFormat::getNameByConstant($component->getFormat()));
}
if ($component->hasPrompt() === true) {
$element->appendChild($this->getMarshallerFactory()->createMarshaller($component->getPrompt())->marshall($component->getPrompt()));
}
}
$this->fillElement($element, $component);
return $element;
} | php | protected function marshall(QtiComponent $component)
{
$element = $this->createElement($component);
$version = $this->getVersion();
$this->setDOMElementAttribute($element, 'responseIdentifier', $component->getResponseIdentifier());
if ($component->getBase() !== 10) {
$this->setDOMElementAttribute($element, 'base', $component->getBase());
}
if ($component->hasStringIdentifier() === true) {
$this->setDOMElementAttribute($element, 'stringIdentifier', $component->getStringIdentifier());
}
if ($component->hasExpectedLength() === true) {
$this->setDOMElementAttribute($element, 'expectedLength', $component->getExpectedLength());
}
if ($component->hasPatternMask() === true) {
$this->setDOMElementAttribute($element, 'patternMask', $component->getPatternMask());
}
if ($component->hasPlaceholderText() === true) {
$this->setDOMElementAttribute($element, 'placeholderText', $component->getPlaceholderText());
}
if ($component->hasXmlBase() === true) {
self::setXmlBase($element, $component->setXmlBase());
}
if ($element->localName === 'extendedTextInteraction') {
if ($component->hasMaxStrings() === true) {
$this->setDOMElementAttribute($element, 'maxStrings', $component->getMaxStrings());
}
if (Version::compare($version, '2.1.0', '>=') === true && $component->getMinStrings() !== 0) {
$this->setDOMElementAttribute($element, 'minStrings', $component->getMinStrings());
}
if ($component->hasExpectedLines() === true) {
$this->setDOMElementAttribute($element, 'expectedLines', $component->getExpectedLines());
}
if (Version::compare($version, '2.1.0', '>=') === true && $component->getFormat() !== TextFormat::PLAIN) {
$this->setDOMElementAttribute($element, 'format', TextFormat::getNameByConstant($component->getFormat()));
}
if ($component->hasPrompt() === true) {
$element->appendChild($this->getMarshallerFactory()->createMarshaller($component->getPrompt())->marshall($component->getPrompt()));
}
}
$this->fillElement($element, $component);
return $element;
} | [
"protected",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"$",
"element",
"=",
"$",
"this",
"->",
"createElement",
"(",
"$",
"component",
")",
";",
"$",
"version",
"=",
"$",
"this",
"->",
"getVersion",
"(",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'responseIdentifier'",
",",
"$",
"component",
"->",
"getResponseIdentifier",
"(",
")",
")",
";",
"if",
"(",
"$",
"component",
"->",
"getBase",
"(",
")",
"!==",
"10",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'base'",
",",
"$",
"component",
"->",
"getBase",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"component",
"->",
"hasStringIdentifier",
"(",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'stringIdentifier'",
",",
"$",
"component",
"->",
"getStringIdentifier",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"component",
"->",
"hasExpectedLength",
"(",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'expectedLength'",
",",
"$",
"component",
"->",
"getExpectedLength",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"component",
"->",
"hasPatternMask",
"(",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'patternMask'",
",",
"$",
"component",
"->",
"getPatternMask",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"component",
"->",
"hasPlaceholderText",
"(",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'placeholderText'",
",",
"$",
"component",
"->",
"getPlaceholderText",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"component",
"->",
"hasXmlBase",
"(",
")",
"===",
"true",
")",
"{",
"self",
"::",
"setXmlBase",
"(",
"$",
"element",
",",
"$",
"component",
"->",
"setXmlBase",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"element",
"->",
"localName",
"===",
"'extendedTextInteraction'",
")",
"{",
"if",
"(",
"$",
"component",
"->",
"hasMaxStrings",
"(",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'maxStrings'",
",",
"$",
"component",
"->",
"getMaxStrings",
"(",
")",
")",
";",
"}",
"if",
"(",
"Version",
"::",
"compare",
"(",
"$",
"version",
",",
"'2.1.0'",
",",
"'>='",
")",
"===",
"true",
"&&",
"$",
"component",
"->",
"getMinStrings",
"(",
")",
"!==",
"0",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'minStrings'",
",",
"$",
"component",
"->",
"getMinStrings",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"component",
"->",
"hasExpectedLines",
"(",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'expectedLines'",
",",
"$",
"component",
"->",
"getExpectedLines",
"(",
")",
")",
";",
"}",
"if",
"(",
"Version",
"::",
"compare",
"(",
"$",
"version",
",",
"'2.1.0'",
",",
"'>='",
")",
"===",
"true",
"&&",
"$",
"component",
"->",
"getFormat",
"(",
")",
"!==",
"TextFormat",
"::",
"PLAIN",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'format'",
",",
"TextFormat",
"::",
"getNameByConstant",
"(",
"$",
"component",
"->",
"getFormat",
"(",
")",
")",
")",
";",
"}",
"if",
"(",
"$",
"component",
"->",
"hasPrompt",
"(",
")",
"===",
"true",
")",
"{",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"component",
"->",
"getPrompt",
"(",
")",
")",
"->",
"marshall",
"(",
"$",
"component",
"->",
"getPrompt",
"(",
")",
")",
")",
";",
"}",
"}",
"$",
"this",
"->",
"fillElement",
"(",
"$",
"element",
",",
"$",
"component",
")",
";",
"return",
"$",
"element",
";",
"}"
] | Marshall a TextEntryInteraction/ExtendedTextInteraction object into a DOMElement object.
@param \qtism\data\QtiComponent $component A TextEntryInteraction/ExtendedTextInteraction object.
@return \DOMElement The according DOMElement object.
@throws \qtism\data\storage\xml\marshalling\MarshallingException | [
"Marshall",
"a",
"TextEntryInteraction",
"/",
"ExtendedTextInteraction",
"object",
"into",
"a",
"DOMElement",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/TextInteractionMarshaller.php#L47-L103 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/TextInteractionMarshaller.php | TextInteractionMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
$version = $this->getVersion();
if (($responseIdentifier = $this->getDOMElementAttributeAs($element, 'responseIdentifier')) !== null) {
try {
$localName = $element->localName;
$name = ($this->isWebComponentFriendly()) ? ucfirst(XmlUtils::qtiFriendlyName($localName)) : ucfirst($localName);
$class = 'qtism\\data\\content\\interactions\\' . ucfirst($name);
$component = new $class($responseIdentifier);
} catch (InvalidArgumentException $e) {
$msg = "The value '${responseIdentifier}' of the 'responseIdentifier' attribute of the '" . $element->localName . "' element is not a valid identifier.";
throw new UnmarshallingException($msg, $element, $e);
}
if (($base = $this->getDOMElementAttributeAs($element, 'base', 'integer')) !== null) {
$component->setBase($base);
}
if (($stringIdentifier = $this->getDOMElementAttributeAs($element, 'stringIdentifier')) !== null) {
$component->setStringIdentifier($stringIdentifier);
}
if (($expectedLength = $this->getDOMElementAttributeAs($element, 'expectedLength', 'integer')) !== null) {
$component->setExpectedLength($expectedLength);
}
if (($patternMask = $this->getDOMElementAttributeAs($element, 'patternMask')) !== null) {
$component->setPatternMask($patternMask);
}
if (($placeholderText = $this->getDOMElementAttributeAs($element, 'placeholderText')) !== null) {
$component->setPlaceholderText($placeholderText);
}
if (($xmlBase = self::getXmlBase($element)) !== false) {
$component->setXmlBase($xmlBase);
}
if ($element->localName === 'extendedTextInteraction') {
if (($maxStrings = $this->getDOMElementAttributeAs($element, 'maxStrings', 'integer')) !== null) {
$component->setMaxStrings($maxStrings);
}
if (Version::compare($version, '2.1.0', '>=') === true && ($minStrings = $this->getDOMElementAttributeAs($element, 'minStrings', 'integer')) !== null) {
$component->setMinStrings($minStrings);
}
if (($expectedLines = $this->getDOMElementAttributeAs($element, 'expectedLines', 'integer')) !== null) {
$component->setExpectedLines($expectedLines);
}
if (Version::compare($version, '2.1.0', '>=') === true && ($format = $this->getDOMElementAttributeAs($element, 'format')) !== null) {
$component->setFormat(TextFormat::getConstantByName($format));
}
$promptElts = $this->getChildElementsByTagName($element, 'prompt');
if (count($promptElts) > 0) {
$component->setPrompt($this->getMarshallerFactory()->createMarshaller($promptElts[0])->unmarshall($promptElts[0]));
}
}
$this->fillBodyElement($component, $element);
return $component;
} else {
$msg = "The mandatory 'responseIdentifier' attribute is missing from the '" . $element->localName . "' element.";
throw new UnmarshallingException($msg, $element);
}
} | php | protected function unmarshall(DOMElement $element)
{
$version = $this->getVersion();
if (($responseIdentifier = $this->getDOMElementAttributeAs($element, 'responseIdentifier')) !== null) {
try {
$localName = $element->localName;
$name = ($this->isWebComponentFriendly()) ? ucfirst(XmlUtils::qtiFriendlyName($localName)) : ucfirst($localName);
$class = 'qtism\\data\\content\\interactions\\' . ucfirst($name);
$component = new $class($responseIdentifier);
} catch (InvalidArgumentException $e) {
$msg = "The value '${responseIdentifier}' of the 'responseIdentifier' attribute of the '" . $element->localName . "' element is not a valid identifier.";
throw new UnmarshallingException($msg, $element, $e);
}
if (($base = $this->getDOMElementAttributeAs($element, 'base', 'integer')) !== null) {
$component->setBase($base);
}
if (($stringIdentifier = $this->getDOMElementAttributeAs($element, 'stringIdentifier')) !== null) {
$component->setStringIdentifier($stringIdentifier);
}
if (($expectedLength = $this->getDOMElementAttributeAs($element, 'expectedLength', 'integer')) !== null) {
$component->setExpectedLength($expectedLength);
}
if (($patternMask = $this->getDOMElementAttributeAs($element, 'patternMask')) !== null) {
$component->setPatternMask($patternMask);
}
if (($placeholderText = $this->getDOMElementAttributeAs($element, 'placeholderText')) !== null) {
$component->setPlaceholderText($placeholderText);
}
if (($xmlBase = self::getXmlBase($element)) !== false) {
$component->setXmlBase($xmlBase);
}
if ($element->localName === 'extendedTextInteraction') {
if (($maxStrings = $this->getDOMElementAttributeAs($element, 'maxStrings', 'integer')) !== null) {
$component->setMaxStrings($maxStrings);
}
if (Version::compare($version, '2.1.0', '>=') === true && ($minStrings = $this->getDOMElementAttributeAs($element, 'minStrings', 'integer')) !== null) {
$component->setMinStrings($minStrings);
}
if (($expectedLines = $this->getDOMElementAttributeAs($element, 'expectedLines', 'integer')) !== null) {
$component->setExpectedLines($expectedLines);
}
if (Version::compare($version, '2.1.0', '>=') === true && ($format = $this->getDOMElementAttributeAs($element, 'format')) !== null) {
$component->setFormat(TextFormat::getConstantByName($format));
}
$promptElts = $this->getChildElementsByTagName($element, 'prompt');
if (count($promptElts) > 0) {
$component->setPrompt($this->getMarshallerFactory()->createMarshaller($promptElts[0])->unmarshall($promptElts[0]));
}
}
$this->fillBodyElement($component, $element);
return $component;
} else {
$msg = "The mandatory 'responseIdentifier' attribute is missing from the '" . $element->localName . "' element.";
throw new UnmarshallingException($msg, $element);
}
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"$",
"version",
"=",
"$",
"this",
"->",
"getVersion",
"(",
")",
";",
"if",
"(",
"(",
"$",
"responseIdentifier",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'responseIdentifier'",
")",
")",
"!==",
"null",
")",
"{",
"try",
"{",
"$",
"localName",
"=",
"$",
"element",
"->",
"localName",
";",
"$",
"name",
"=",
"(",
"$",
"this",
"->",
"isWebComponentFriendly",
"(",
")",
")",
"?",
"ucfirst",
"(",
"XmlUtils",
"::",
"qtiFriendlyName",
"(",
"$",
"localName",
")",
")",
":",
"ucfirst",
"(",
"$",
"localName",
")",
";",
"$",
"class",
"=",
"'qtism\\\\data\\\\content\\\\interactions\\\\'",
".",
"ucfirst",
"(",
"$",
"name",
")",
";",
"$",
"component",
"=",
"new",
"$",
"class",
"(",
"$",
"responseIdentifier",
")",
";",
"}",
"catch",
"(",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"The value '${responseIdentifier}' of the 'responseIdentifier' attribute of the '\"",
".",
"$",
"element",
"->",
"localName",
".",
"\"' element is not a valid identifier.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
",",
"$",
"e",
")",
";",
"}",
"if",
"(",
"(",
"$",
"base",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'base'",
",",
"'integer'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"component",
"->",
"setBase",
"(",
"$",
"base",
")",
";",
"}",
"if",
"(",
"(",
"$",
"stringIdentifier",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'stringIdentifier'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"component",
"->",
"setStringIdentifier",
"(",
"$",
"stringIdentifier",
")",
";",
"}",
"if",
"(",
"(",
"$",
"expectedLength",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'expectedLength'",
",",
"'integer'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"component",
"->",
"setExpectedLength",
"(",
"$",
"expectedLength",
")",
";",
"}",
"if",
"(",
"(",
"$",
"patternMask",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'patternMask'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"component",
"->",
"setPatternMask",
"(",
"$",
"patternMask",
")",
";",
"}",
"if",
"(",
"(",
"$",
"placeholderText",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'placeholderText'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"component",
"->",
"setPlaceholderText",
"(",
"$",
"placeholderText",
")",
";",
"}",
"if",
"(",
"(",
"$",
"xmlBase",
"=",
"self",
"::",
"getXmlBase",
"(",
"$",
"element",
")",
")",
"!==",
"false",
")",
"{",
"$",
"component",
"->",
"setXmlBase",
"(",
"$",
"xmlBase",
")",
";",
"}",
"if",
"(",
"$",
"element",
"->",
"localName",
"===",
"'extendedTextInteraction'",
")",
"{",
"if",
"(",
"(",
"$",
"maxStrings",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'maxStrings'",
",",
"'integer'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"component",
"->",
"setMaxStrings",
"(",
"$",
"maxStrings",
")",
";",
"}",
"if",
"(",
"Version",
"::",
"compare",
"(",
"$",
"version",
",",
"'2.1.0'",
",",
"'>='",
")",
"===",
"true",
"&&",
"(",
"$",
"minStrings",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'minStrings'",
",",
"'integer'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"component",
"->",
"setMinStrings",
"(",
"$",
"minStrings",
")",
";",
"}",
"if",
"(",
"(",
"$",
"expectedLines",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'expectedLines'",
",",
"'integer'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"component",
"->",
"setExpectedLines",
"(",
"$",
"expectedLines",
")",
";",
"}",
"if",
"(",
"Version",
"::",
"compare",
"(",
"$",
"version",
",",
"'2.1.0'",
",",
"'>='",
")",
"===",
"true",
"&&",
"(",
"$",
"format",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'format'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"component",
"->",
"setFormat",
"(",
"TextFormat",
"::",
"getConstantByName",
"(",
"$",
"format",
")",
")",
";",
"}",
"$",
"promptElts",
"=",
"$",
"this",
"->",
"getChildElementsByTagName",
"(",
"$",
"element",
",",
"'prompt'",
")",
";",
"if",
"(",
"count",
"(",
"$",
"promptElts",
")",
">",
"0",
")",
"{",
"$",
"component",
"->",
"setPrompt",
"(",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"promptElts",
"[",
"0",
"]",
")",
"->",
"unmarshall",
"(",
"$",
"promptElts",
"[",
"0",
"]",
")",
")",
";",
"}",
"}",
"$",
"this",
"->",
"fillBodyElement",
"(",
"$",
"component",
",",
"$",
"element",
")",
";",
"return",
"$",
"component",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory 'responseIdentifier' attribute is missing from the '\"",
".",
"$",
"element",
"->",
"localName",
".",
"\"' element.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}"
] | Unmarshall a DOMElement object corresponding to a textEntryInteraction/extendedTextInteraction element.
@param \DOMElement $element A DOMElement object.
@return \qtism\data\QtiComponent A TextEntryInteraction/ExtendedTextInteraction object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException | [
"Unmarshall",
"a",
"DOMElement",
"object",
"corresponding",
"to",
"a",
"textEntryInteraction",
"/",
"extendedTextInteraction",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/TextInteractionMarshaller.php#L112-L183 |
oat-sa/qti-sdk | src/qtism/data/content/interactions/GraphicOrderInteraction.php | GraphicOrderInteraction.setHotspotChoices | public function setHotspotChoices(HotspotChoiceCollection $hotspotChoices)
{
if (count($hotspotChoices) > 0) {
$this->hotspotChoices = $hotspotChoices;
} else {
$msg = "A GraphicOrderInteraction must contain at least 1 hotspotChoice object. None given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setHotspotChoices(HotspotChoiceCollection $hotspotChoices)
{
if (count($hotspotChoices) > 0) {
$this->hotspotChoices = $hotspotChoices;
} else {
$msg = "A GraphicOrderInteraction must contain at least 1 hotspotChoice object. None given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setHotspotChoices",
"(",
"HotspotChoiceCollection",
"$",
"hotspotChoices",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"hotspotChoices",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"hotspotChoices",
"=",
"$",
"hotspotChoices",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"A GraphicOrderInteraction must contain at least 1 hotspotChoice object. None given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the hotspots that define the choices that are to be ordered by the candidate.
@param \qtism\data\content\interactions\HotspotChoiceCollection $hotspotChoices A collection of HotspotChoice objects.
@throws \InvalidArgumentException If the given $hotspotChoices collection is empty. | [
"Set",
"the",
"hotspots",
"that",
"define",
"the",
"choices",
"that",
"are",
"to",
"be",
"ordered",
"by",
"the",
"candidate",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/interactions/GraphicOrderInteraction.php#L119-L127 |
oat-sa/qti-sdk | src/qtism/data/content/interactions/GraphicOrderInteraction.php | GraphicOrderInteraction.setMinChoices | public function setMinChoices($minChoices)
{
if (is_int($minChoices) && $minChoices !== 0) {
if ($minChoices > count($this->getHotspotChoices())) {
$msg = "The 'minChoices' argument must not exceed the number of choices available.";
throw new InvalidArgumentException($msg);
}
$this->minChoices = $minChoices;
} else {
$msg = "The 'minChoices' argument must be a strictly negative or positive integer, '" . gettype($minChoices) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setMinChoices($minChoices)
{
if (is_int($minChoices) && $minChoices !== 0) {
if ($minChoices > count($this->getHotspotChoices())) {
$msg = "The 'minChoices' argument must not exceed the number of choices available.";
throw new InvalidArgumentException($msg);
}
$this->minChoices = $minChoices;
} else {
$msg = "The 'minChoices' argument must be a strictly negative or positive integer, '" . gettype($minChoices) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setMinChoices",
"(",
"$",
"minChoices",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"minChoices",
")",
"&&",
"$",
"minChoices",
"!==",
"0",
")",
"{",
"if",
"(",
"$",
"minChoices",
">",
"count",
"(",
"$",
"this",
"->",
"getHotspotChoices",
"(",
")",
")",
")",
"{",
"$",
"msg",
"=",
"\"The 'minChoices' argument must not exceed the number of choices available.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"$",
"this",
"->",
"minChoices",
"=",
"$",
"minChoices",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'minChoices' argument must be a strictly negative or positive integer, '\"",
".",
"gettype",
"(",
"$",
"minChoices",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the minimum number of choices that the candidate must select and order to form a valid response. A negative
value indicates that no minChoice is indicated.
@param integer $minChoices A strictly negative or positive integer.
@throws \InvalidArgumentException If $minChoice is not a strictly negative or positive integer. | [
"Set",
"the",
"minimum",
"number",
"of",
"choices",
"that",
"the",
"candidate",
"must",
"select",
"and",
"order",
"to",
"form",
"a",
"valid",
"response",
".",
"A",
"negative",
"value",
"indicates",
"that",
"no",
"minChoice",
"is",
"indicated",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/interactions/GraphicOrderInteraction.php#L146-L160 |
oat-sa/qti-sdk | src/qtism/data/content/interactions/GraphicOrderInteraction.php | GraphicOrderInteraction.setMaxChoices | public function setMaxChoices($maxChoices)
{
if (is_int($maxChoices) && $maxChoices !== 0) {
if ($this->getMinChoices() > 0 && $maxChoices < $this->getMinChoices()) {
$msg = "The 'maxChoices' argument must be greater than or equal to the 'minChoices' attribute.";
throw new InvalidArgumentException($msg);
}
$this->maxChoices = $maxChoices;
} else {
$msg = "The 'maxChoices' argument must be a strictly negative or positive integer, '" . gettype($maxChoices) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setMaxChoices($maxChoices)
{
if (is_int($maxChoices) && $maxChoices !== 0) {
if ($this->getMinChoices() > 0 && $maxChoices < $this->getMinChoices()) {
$msg = "The 'maxChoices' argument must be greater than or equal to the 'minChoices' attribute.";
throw new InvalidArgumentException($msg);
}
$this->maxChoices = $maxChoices;
} else {
$msg = "The 'maxChoices' argument must be a strictly negative or positive integer, '" . gettype($maxChoices) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setMaxChoices",
"(",
"$",
"maxChoices",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"maxChoices",
")",
"&&",
"$",
"maxChoices",
"!==",
"0",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getMinChoices",
"(",
")",
">",
"0",
"&&",
"$",
"maxChoices",
"<",
"$",
"this",
"->",
"getMinChoices",
"(",
")",
")",
"{",
"$",
"msg",
"=",
"\"The 'maxChoices' argument must be greater than or equal to the 'minChoices' attribute.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"$",
"this",
"->",
"maxChoices",
"=",
"$",
"maxChoices",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'maxChoices' argument must be a strictly negative or positive integer, '\"",
".",
"gettype",
"(",
"$",
"maxChoices",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the maximum number of choices that the candidate must select and order to form a valid response. A negative
value indicates that no maxChoice is indicated.
@param integer $maxChoices A strictly negative or positive integer.
@throws \InvalidArgumentException If $maxChoices is not a strictly negative or positive integer. | [
"Set",
"the",
"maximum",
"number",
"of",
"choices",
"that",
"the",
"candidate",
"must",
"select",
"and",
"order",
"to",
"form",
"a",
"valid",
"response",
".",
"A",
"negative",
"value",
"indicates",
"that",
"no",
"maxChoice",
"is",
"indicated",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/interactions/GraphicOrderInteraction.php#L190-L204 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/TemplateDefaultMarshaller.php | TemplateDefaultMarshaller.marshall | protected function marshall(QtiComponent $component)
{
$element = static::getDOMCradle()->createElement($component->getQtiClassName());
$this->setDOMElementAttribute($element, 'templateIdentifier', $component->getTemplateIdentifier());
$expr = $component->getExpression();
$exprMarshaller = $this->getMarshallerFactory()->createMarshaller($expr);
$exprElt = $exprMarshaller->marshall($expr);
$element->appendChild($exprElt);
return $element;
} | php | protected function marshall(QtiComponent $component)
{
$element = static::getDOMCradle()->createElement($component->getQtiClassName());
$this->setDOMElementAttribute($element, 'templateIdentifier', $component->getTemplateIdentifier());
$expr = $component->getExpression();
$exprMarshaller = $this->getMarshallerFactory()->createMarshaller($expr);
$exprElt = $exprMarshaller->marshall($expr);
$element->appendChild($exprElt);
return $element;
} | [
"protected",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"$",
"element",
"=",
"static",
"::",
"getDOMCradle",
"(",
")",
"->",
"createElement",
"(",
"$",
"component",
"->",
"getQtiClassName",
"(",
")",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'templateIdentifier'",
",",
"$",
"component",
"->",
"getTemplateIdentifier",
"(",
")",
")",
";",
"$",
"expr",
"=",
"$",
"component",
"->",
"getExpression",
"(",
")",
";",
"$",
"exprMarshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"expr",
")",
";",
"$",
"exprElt",
"=",
"$",
"exprMarshaller",
"->",
"marshall",
"(",
"$",
"expr",
")",
";",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"exprElt",
")",
";",
"return",
"$",
"element",
";",
"}"
] | Marshall a TemplateDefault object into a DOMElement object.
@param \qtism\data\QtiComponent $component A TemplateDefault object.
@return \DOMElement The according DOMElement object. | [
"Marshall",
"a",
"TemplateDefault",
"object",
"into",
"a",
"DOMElement",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/TemplateDefaultMarshaller.php#L43-L56 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/TemplateDefaultMarshaller.php | TemplateDefaultMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
if (($tplIdentifier = $this->getDOMElementAttributeAs($element, 'templateIdentifier')) !== null) {
$expressionElt = self::getFirstChildElement($element);
if ($expressionElt !== false) {
$exprMarshaller = $this->getMarshallerFactory()->createMarshaller($expressionElt);
$expr = $exprMarshaller->unmarshall($expressionElt);
} else {
$msg = "Element '" . $element->localName . "' does not contain its mandatory expression.";
throw new UnmarshallingException($msg, $element);
}
$object = new TemplateDefault($tplIdentifier, $expr);
return $object;
} else {
$msg = "The mandatory attribute 'templateIdentifier' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} | php | protected function unmarshall(DOMElement $element)
{
if (($tplIdentifier = $this->getDOMElementAttributeAs($element, 'templateIdentifier')) !== null) {
$expressionElt = self::getFirstChildElement($element);
if ($expressionElt !== false) {
$exprMarshaller = $this->getMarshallerFactory()->createMarshaller($expressionElt);
$expr = $exprMarshaller->unmarshall($expressionElt);
} else {
$msg = "Element '" . $element->localName . "' does not contain its mandatory expression.";
throw new UnmarshallingException($msg, $element);
}
$object = new TemplateDefault($tplIdentifier, $expr);
return $object;
} else {
$msg = "The mandatory attribute 'templateIdentifier' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"if",
"(",
"(",
"$",
"tplIdentifier",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'templateIdentifier'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"expressionElt",
"=",
"self",
"::",
"getFirstChildElement",
"(",
"$",
"element",
")",
";",
"if",
"(",
"$",
"expressionElt",
"!==",
"false",
")",
"{",
"$",
"exprMarshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"expressionElt",
")",
";",
"$",
"expr",
"=",
"$",
"exprMarshaller",
"->",
"unmarshall",
"(",
"$",
"expressionElt",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"Element '\"",
".",
"$",
"element",
"->",
"localName",
".",
"\"' does not contain its mandatory expression.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"$",
"object",
"=",
"new",
"TemplateDefault",
"(",
"$",
"tplIdentifier",
",",
"$",
"expr",
")",
";",
"return",
"$",
"object",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory attribute 'templateIdentifier' is missing from element '\"",
".",
"$",
"element",
"->",
"localName",
".",
"\"'.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}"
] | Unmarshall a DOMElement object corresponding to a QTI templateDefault element.
@param \DOMElement $element A DOMElement object.
@return \qtism\data\QtiComponent A templateDefault object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException If the mandatory attribute 'templateIdentifier' is missing or has an unexpected number of expressions. | [
"Unmarshall",
"a",
"DOMElement",
"object",
"corresponding",
"to",
"a",
"QTI",
"templateDefault",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/TemplateDefaultMarshaller.php#L65-L86 |
oat-sa/qti-sdk | src/qtism/data/content/interactions/AssociableHotspot.php | AssociableHotspot.setMatchMax | public function setMatchMax($matchMax)
{
if (is_int($matchMax) === true && $matchMax >= 0) {
$this->matchMax = $matchMax;
} else {
$msg = "The 'matchMax' argument must be a positive integer, '" . gettype($matchMax) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setMatchMax($matchMax)
{
if (is_int($matchMax) === true && $matchMax >= 0) {
$this->matchMax = $matchMax;
} else {
$msg = "The 'matchMax' argument must be a positive integer, '" . gettype($matchMax) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setMatchMax",
"(",
"$",
"matchMax",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"matchMax",
")",
"===",
"true",
"&&",
"$",
"matchMax",
">=",
"0",
")",
"{",
"$",
"this",
"->",
"matchMax",
"=",
"$",
"matchMax",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'matchMax' argument must be a positive integer, '\"",
".",
"gettype",
"(",
"$",
"matchMax",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the matchMax of the associableHotspot.
@param integer $matchMax A positive (>= 0) integer.
@throws \InvalidArgumentException If $matchMax is not a positive integer. | [
"Set",
"the",
"matchMax",
"of",
"the",
"associableHotspot",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/interactions/AssociableHotspot.php#L137-L145 |
oat-sa/qti-sdk | src/qtism/data/content/interactions/AssociableHotspot.php | AssociableHotspot.setMatchMin | public function setMatchMin($matchMin)
{
if (is_int($matchMin) === true && $matchMin >= 0) {
$this->matchMin = $matchMin;
} else {
$msg = "The 'matchMin' argument must be a positive integer, '" . gettype($matchMin) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setMatchMin($matchMin)
{
if (is_int($matchMin) === true && $matchMin >= 0) {
$this->matchMin = $matchMin;
} else {
$msg = "The 'matchMin' argument must be a positive integer, '" . gettype($matchMin) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setMatchMin",
"(",
"$",
"matchMin",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"matchMin",
")",
"===",
"true",
"&&",
"$",
"matchMin",
">=",
"0",
")",
"{",
"$",
"this",
"->",
"matchMin",
"=",
"$",
"matchMin",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'matchMin' argument must be a positive integer, '\"",
".",
"gettype",
"(",
"$",
"matchMin",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the matchMin of the associableHotspot.
@param integer $matchMin A positive (>= 0) integer.
@throws \InvalidArgumentException If $matchMin is not a positive integer. | [
"Set",
"the",
"matchMin",
"of",
"the",
"associableHotspot",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/interactions/AssociableHotspot.php#L163-L171 |
oat-sa/qti-sdk | src/qtism/data/content/interactions/AssociableHotspot.php | AssociableHotspot.setHotspotLabel | public function setHotspotLabel($hotspotLabel)
{
if (Format::isString256($hotspotLabel) === true) {
$this->hotspotLabel = $hotspotLabel;
} else {
$msg = "The 'hotspotLabel' argument must be a string value with at most 256 characters.";
throw new InvalidArgumentException($msg);
}
} | php | public function setHotspotLabel($hotspotLabel)
{
if (Format::isString256($hotspotLabel) === true) {
$this->hotspotLabel = $hotspotLabel;
} else {
$msg = "The 'hotspotLabel' argument must be a string value with at most 256 characters.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setHotspotLabel",
"(",
"$",
"hotspotLabel",
")",
"{",
"if",
"(",
"Format",
"::",
"isString256",
"(",
"$",
"hotspotLabel",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"hotspotLabel",
"=",
"$",
"hotspotLabel",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'hotspotLabel' argument must be a string value with at most 256 characters.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the hotspotLabel of the associableHotspot.
@param string $hotspotLabel A string with at most 256 characters.
@throws \InvalidArgumentException If $hotspotLabel has more than 256 characters. | [
"Set",
"the",
"hotspotLabel",
"of",
"the",
"associableHotspot",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/interactions/AssociableHotspot.php#L234-L242 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/CustomInteractionMarshaller.php | CustomInteractionMarshaller.marshall | protected function marshall(QtiComponent $component)
{
$element = $this->createElement($component);
$this->fillElement($element, $component);
$this->setDOMElementAttribute($element, 'responseIdentifier', $component->getResponseIdentifier());
if ($component->hasXmlBase() === true) {
self::setXmlBase($element, $component->getXmlBase());
}
$xml = $component->getXml();
Utils::importChildNodes($xml->documentElement, $element);
Utils::importAttributes($xml->documentElement, $element);
return $element;
} | php | protected function marshall(QtiComponent $component)
{
$element = $this->createElement($component);
$this->fillElement($element, $component);
$this->setDOMElementAttribute($element, 'responseIdentifier', $component->getResponseIdentifier());
if ($component->hasXmlBase() === true) {
self::setXmlBase($element, $component->getXmlBase());
}
$xml = $component->getXml();
Utils::importChildNodes($xml->documentElement, $element);
Utils::importAttributes($xml->documentElement, $element);
return $element;
} | [
"protected",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"$",
"element",
"=",
"$",
"this",
"->",
"createElement",
"(",
"$",
"component",
")",
";",
"$",
"this",
"->",
"fillElement",
"(",
"$",
"element",
",",
"$",
"component",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'responseIdentifier'",
",",
"$",
"component",
"->",
"getResponseIdentifier",
"(",
")",
")",
";",
"if",
"(",
"$",
"component",
"->",
"hasXmlBase",
"(",
")",
"===",
"true",
")",
"{",
"self",
"::",
"setXmlBase",
"(",
"$",
"element",
",",
"$",
"component",
"->",
"getXmlBase",
"(",
")",
")",
";",
"}",
"$",
"xml",
"=",
"$",
"component",
"->",
"getXml",
"(",
")",
";",
"Utils",
"::",
"importChildNodes",
"(",
"$",
"xml",
"->",
"documentElement",
",",
"$",
"element",
")",
";",
"Utils",
"::",
"importAttributes",
"(",
"$",
"xml",
"->",
"documentElement",
",",
"$",
"element",
")",
";",
"return",
"$",
"element",
";",
"}"
] | Marshall a CustomInteraction object into a DOMElement object.
@param \qtism\data\QtiComponent $component A CustomInteraction object.
@return \DOMElement The according DOMElement object. | [
"Marshall",
"a",
"CustomInteraction",
"object",
"into",
"a",
"DOMElement",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/CustomInteractionMarshaller.php#L44-L59 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/CustomInteractionMarshaller.php | CustomInteractionMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
if (($responseIdentifier = $this->getDOMElementAttributeAs($element, 'responseIdentifier')) !== null) {
$frag = $element->ownerDocument->createDocumentFragment();
$element = $element->cloneNode(true);
$frag->appendChild($element);
$xmlString = $frag->ownerDocument->saveXML($frag);
$component = new CustomInteraction($responseIdentifier, $xmlString);
$this->fillBodyElement($component, $element);
}
return $component;
} | php | protected function unmarshall(DOMElement $element)
{
if (($responseIdentifier = $this->getDOMElementAttributeAs($element, 'responseIdentifier')) !== null) {
$frag = $element->ownerDocument->createDocumentFragment();
$element = $element->cloneNode(true);
$frag->appendChild($element);
$xmlString = $frag->ownerDocument->saveXML($frag);
$component = new CustomInteraction($responseIdentifier, $xmlString);
$this->fillBodyElement($component, $element);
}
return $component;
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"if",
"(",
"(",
"$",
"responseIdentifier",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'responseIdentifier'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"frag",
"=",
"$",
"element",
"->",
"ownerDocument",
"->",
"createDocumentFragment",
"(",
")",
";",
"$",
"element",
"=",
"$",
"element",
"->",
"cloneNode",
"(",
"true",
")",
";",
"$",
"frag",
"->",
"appendChild",
"(",
"$",
"element",
")",
";",
"$",
"xmlString",
"=",
"$",
"frag",
"->",
"ownerDocument",
"->",
"saveXML",
"(",
"$",
"frag",
")",
";",
"$",
"component",
"=",
"new",
"CustomInteraction",
"(",
"$",
"responseIdentifier",
",",
"$",
"xmlString",
")",
";",
"$",
"this",
"->",
"fillBodyElement",
"(",
"$",
"component",
",",
"$",
"element",
")",
";",
"}",
"return",
"$",
"component",
";",
"}"
] | Unmarshall a DOMElement object corresponding to a QTI customInteraction element.
@param \DOMElement $element A DOMElement object.
@return \qtism\data\QtiComponent A CustomInteraction object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException | [
"Unmarshall",
"a",
"DOMElement",
"object",
"corresponding",
"to",
"a",
"QTI",
"customInteraction",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/CustomInteractionMarshaller.php#L68-L82 |
oat-sa/qti-sdk | src/qtism/data/content/xhtml/text/Blockquote.php | Blockquote.setCite | public function setCite($cite)
{
if (Format::isUri($cite) === true) {
$this->cite = $cite;
} else {
$msg = "The 'cite' argument must be a valid URI, '" . $cite . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setCite($cite)
{
if (Format::isUri($cite) === true) {
$this->cite = $cite;
} else {
$msg = "The 'cite' argument must be a valid URI, '" . $cite . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setCite",
"(",
"$",
"cite",
")",
"{",
"if",
"(",
"Format",
"::",
"isUri",
"(",
"$",
"cite",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"cite",
"=",
"$",
"cite",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'cite' argument must be a valid URI, '\"",
".",
"$",
"cite",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the cite attribute's value.
@param string $cite
@throws InvalidArgumentException If $cite is not a valid URI. | [
"Set",
"the",
"cite",
"attribute",
"s",
"value",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/xhtml/text/Blockquote.php#L77-L85 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/HotspotMarshaller.php | HotspotMarshaller.marshall | protected function marshall(QtiComponent $component)
{
$version = $this->getVersion();
$element = $this->createElement($component);
$this->setDOMElementAttribute($element, 'identifier', $component->getIdentifier());
$this->setDOMElementAttribute($element, 'shape', QtiShape::getNameByConstant($component->getShape()));
$this->setDOMElementAttribute($element, 'coords', $component->getCoords()->__toString());
if ($component->isFixed() === true) {
$this->setDOMElementAttribute($element, 'fixed', true);
}
if (Version::compare($version, '2.1.0', '>=') === true && $component->hasTemplateIdentifier() === true) {
$this->setDOMElementAttribute($element, 'templateIdentifier', $component->getTemplateIdentifier());
}
if (Version::compare($version, '2.1.0', '>=') === true && $component->getShowHide() === ShowHide::HIDE) {
$this->setDOMElementAttribute($element, 'showHide', ShowHide::getNameByConstant($component->getShowHide()));
}
if ($component->hasHotspotLabel() === true) {
$this->setDOMElementAttribute($element, 'hotspotLabel', $component->getHotspotLabel());
}
if ($component instanceof AssociableHotspot) {
if (Version::compare($version, '2.1.0', '<') === true) {
$matchGroup = $component->getMatchGroup();
if (count($matchGroup) > 0) {
$this->setDOMElementAttribute($element, 'matchGroup', implode(' ', $matchGroup->getArrayCopy()));
}
}
if (Version::compare($version, '2.1.0', '>=') === true) {
if ($component->getMatchMin() !== 0) {
$this->setDOMElementAttribute($element, 'matchMin', $component->getMatchMin());
}
}
}
if ($component instanceof AssociableHotspot) {
$this->setDOMElementAttribute($element, 'matchMax', $component->getMatchMax());
}
$this->fillElement($element, $component);
return $element;
} | php | protected function marshall(QtiComponent $component)
{
$version = $this->getVersion();
$element = $this->createElement($component);
$this->setDOMElementAttribute($element, 'identifier', $component->getIdentifier());
$this->setDOMElementAttribute($element, 'shape', QtiShape::getNameByConstant($component->getShape()));
$this->setDOMElementAttribute($element, 'coords', $component->getCoords()->__toString());
if ($component->isFixed() === true) {
$this->setDOMElementAttribute($element, 'fixed', true);
}
if (Version::compare($version, '2.1.0', '>=') === true && $component->hasTemplateIdentifier() === true) {
$this->setDOMElementAttribute($element, 'templateIdentifier', $component->getTemplateIdentifier());
}
if (Version::compare($version, '2.1.0', '>=') === true && $component->getShowHide() === ShowHide::HIDE) {
$this->setDOMElementAttribute($element, 'showHide', ShowHide::getNameByConstant($component->getShowHide()));
}
if ($component->hasHotspotLabel() === true) {
$this->setDOMElementAttribute($element, 'hotspotLabel', $component->getHotspotLabel());
}
if ($component instanceof AssociableHotspot) {
if (Version::compare($version, '2.1.0', '<') === true) {
$matchGroup = $component->getMatchGroup();
if (count($matchGroup) > 0) {
$this->setDOMElementAttribute($element, 'matchGroup', implode(' ', $matchGroup->getArrayCopy()));
}
}
if (Version::compare($version, '2.1.0', '>=') === true) {
if ($component->getMatchMin() !== 0) {
$this->setDOMElementAttribute($element, 'matchMin', $component->getMatchMin());
}
}
}
if ($component instanceof AssociableHotspot) {
$this->setDOMElementAttribute($element, 'matchMax', $component->getMatchMax());
}
$this->fillElement($element, $component);
return $element;
} | [
"protected",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"$",
"version",
"=",
"$",
"this",
"->",
"getVersion",
"(",
")",
";",
"$",
"element",
"=",
"$",
"this",
"->",
"createElement",
"(",
"$",
"component",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'identifier'",
",",
"$",
"component",
"->",
"getIdentifier",
"(",
")",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'shape'",
",",
"QtiShape",
"::",
"getNameByConstant",
"(",
"$",
"component",
"->",
"getShape",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'coords'",
",",
"$",
"component",
"->",
"getCoords",
"(",
")",
"->",
"__toString",
"(",
")",
")",
";",
"if",
"(",
"$",
"component",
"->",
"isFixed",
"(",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'fixed'",
",",
"true",
")",
";",
"}",
"if",
"(",
"Version",
"::",
"compare",
"(",
"$",
"version",
",",
"'2.1.0'",
",",
"'>='",
")",
"===",
"true",
"&&",
"$",
"component",
"->",
"hasTemplateIdentifier",
"(",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'templateIdentifier'",
",",
"$",
"component",
"->",
"getTemplateIdentifier",
"(",
")",
")",
";",
"}",
"if",
"(",
"Version",
"::",
"compare",
"(",
"$",
"version",
",",
"'2.1.0'",
",",
"'>='",
")",
"===",
"true",
"&&",
"$",
"component",
"->",
"getShowHide",
"(",
")",
"===",
"ShowHide",
"::",
"HIDE",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'showHide'",
",",
"ShowHide",
"::",
"getNameByConstant",
"(",
"$",
"component",
"->",
"getShowHide",
"(",
")",
")",
")",
";",
"}",
"if",
"(",
"$",
"component",
"->",
"hasHotspotLabel",
"(",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'hotspotLabel'",
",",
"$",
"component",
"->",
"getHotspotLabel",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"component",
"instanceof",
"AssociableHotspot",
")",
"{",
"if",
"(",
"Version",
"::",
"compare",
"(",
"$",
"version",
",",
"'2.1.0'",
",",
"'<'",
")",
"===",
"true",
")",
"{",
"$",
"matchGroup",
"=",
"$",
"component",
"->",
"getMatchGroup",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"matchGroup",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'matchGroup'",
",",
"implode",
"(",
"' '",
",",
"$",
"matchGroup",
"->",
"getArrayCopy",
"(",
")",
")",
")",
";",
"}",
"}",
"if",
"(",
"Version",
"::",
"compare",
"(",
"$",
"version",
",",
"'2.1.0'",
",",
"'>='",
")",
"===",
"true",
")",
"{",
"if",
"(",
"$",
"component",
"->",
"getMatchMin",
"(",
")",
"!==",
"0",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'matchMin'",
",",
"$",
"component",
"->",
"getMatchMin",
"(",
")",
")",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"component",
"instanceof",
"AssociableHotspot",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'matchMax'",
",",
"$",
"component",
"->",
"getMatchMax",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"fillElement",
"(",
"$",
"element",
",",
"$",
"component",
")",
";",
"return",
"$",
"element",
";",
"}"
] | Marshall a HotspotChoice/AssociableHotspot object into a DOMElement object.
@param \qtism\data\QtiComponent $component A HotspotChoice/AssociableHotspot object.
@return \DOMElement The according DOMElement object.
@throws \qtism\data\storage\xml\marshalling\MarshallingException | [
"Marshall",
"a",
"HotspotChoice",
"/",
"AssociableHotspot",
"object",
"into",
"a",
"DOMElement",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/HotspotMarshaller.php#L52-L99 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/HotspotMarshaller.php | HotspotMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
$version = $this->getVersion();
if (($identifier = $this->getDOMElementAttributeAs($element, 'identifier')) !== null) {
if (($shape = $this->getDOMElementAttributeAs($element, 'shape')) !== null) {
if (($coords = $this->getDOMElementAttributeAs($element, 'coords')) !== null) {
$shape = QtiShape::getConstantByName($shape);
if ($shape === false) {
$msg = "The value of the mandatory attribute 'shape' is not a value from the 'shape' enumeration.";
throw new UnmarshallingException($msg, $element);
}
try {
$coords = Utils::stringToCoords($coords, $shape);
} catch (UnexpectedValueException $e) {
$msg = "The coordinates 'coords' of element '" . $element->localName . "' are not valid regarding the shape they are bound to.";
throw new UnmarshallingException($msg, $element, $e);
} catch (InvalidArgumentException $e) {
$msg = "The coordinates 'coords' of element '" . $element->localName . "' could not be converted.";
throw new UnmarshallingException($msg, $element, $e);
}
if ($element->localName === 'hotspotChoice') {
$component = new HotspotChoice($identifier, $shape, $coords);
} else {
if (($matchMax = $this->getDOMElementAttributeAs($element, 'matchMax', 'integer')) !== null) {
$component = new AssociableHotspot($identifier, $matchMax, $shape, $coords);
} else {
$msg = "The mandatory attribute 'matchMax' is missing from element 'associableHotspot'.";
throw new UnmarshallingException($msg, $element);
}
}
if (($hotspotLabel = $this->getDOMElementAttributeAs($element, 'hotspotLabel')) !== null) {
$component->setHotspotLabel($hotspotLabel);
}
if (($fixed = $this->getDOMElementAttributeAs($element, 'fixed', 'boolean')) !== null) {
$component->setFixed($fixed);
}
if (($templateIdentifier = $this->getDOMElementAttributeAs($element, 'templateIdentifier')) !== null) {
$component->setTemplateIdentifier($templateIdentifier);
}
if (($showHide = $this->getDOMElementAttributeAs($element, 'showHide')) !== null) {
if (($showHide = ShowHide::getConstantByName($showHide)) !== false) {
$component->setShowHide($showHide);
} else {
$msg = "The value of the 'showHide' attribute of element '" . $element->localName . "' is not a value from the 'showHide' enumeration.";
throw new UnmarshallingException($msg, $element);
}
}
if ($element->localName === 'associableHotspot') {
if (Version::compare($version, '2.1.0', '<') === true) {
if (($matchGroup = $this->getDOMElementAttributeAs($element, 'matchGroup')) !== null) {
$component->setMatchGroup(new IdentifierCollection(explode("\x20", $matchGroup)));
}
}
if (Version::compare($version, '2.1.0', '>=') === true) {
if (($matchMin = $this->getDOMElementAttributeAs($element, 'matchMin', 'integer')) !== null) {
$component->setMatchMin($matchMin);
}
}
}
$this->fillBodyElement($component, $element);
return $component;
} else {
$msg = "The mandatory attribute 'coords' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} else {
$msg = "The mandatory attribute 'shape' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} else {
$msg = "The mandatory attribute 'identifier' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} | php | protected function unmarshall(DOMElement $element)
{
$version = $this->getVersion();
if (($identifier = $this->getDOMElementAttributeAs($element, 'identifier')) !== null) {
if (($shape = $this->getDOMElementAttributeAs($element, 'shape')) !== null) {
if (($coords = $this->getDOMElementAttributeAs($element, 'coords')) !== null) {
$shape = QtiShape::getConstantByName($shape);
if ($shape === false) {
$msg = "The value of the mandatory attribute 'shape' is not a value from the 'shape' enumeration.";
throw new UnmarshallingException($msg, $element);
}
try {
$coords = Utils::stringToCoords($coords, $shape);
} catch (UnexpectedValueException $e) {
$msg = "The coordinates 'coords' of element '" . $element->localName . "' are not valid regarding the shape they are bound to.";
throw new UnmarshallingException($msg, $element, $e);
} catch (InvalidArgumentException $e) {
$msg = "The coordinates 'coords' of element '" . $element->localName . "' could not be converted.";
throw new UnmarshallingException($msg, $element, $e);
}
if ($element->localName === 'hotspotChoice') {
$component = new HotspotChoice($identifier, $shape, $coords);
} else {
if (($matchMax = $this->getDOMElementAttributeAs($element, 'matchMax', 'integer')) !== null) {
$component = new AssociableHotspot($identifier, $matchMax, $shape, $coords);
} else {
$msg = "The mandatory attribute 'matchMax' is missing from element 'associableHotspot'.";
throw new UnmarshallingException($msg, $element);
}
}
if (($hotspotLabel = $this->getDOMElementAttributeAs($element, 'hotspotLabel')) !== null) {
$component->setHotspotLabel($hotspotLabel);
}
if (($fixed = $this->getDOMElementAttributeAs($element, 'fixed', 'boolean')) !== null) {
$component->setFixed($fixed);
}
if (($templateIdentifier = $this->getDOMElementAttributeAs($element, 'templateIdentifier')) !== null) {
$component->setTemplateIdentifier($templateIdentifier);
}
if (($showHide = $this->getDOMElementAttributeAs($element, 'showHide')) !== null) {
if (($showHide = ShowHide::getConstantByName($showHide)) !== false) {
$component->setShowHide($showHide);
} else {
$msg = "The value of the 'showHide' attribute of element '" . $element->localName . "' is not a value from the 'showHide' enumeration.";
throw new UnmarshallingException($msg, $element);
}
}
if ($element->localName === 'associableHotspot') {
if (Version::compare($version, '2.1.0', '<') === true) {
if (($matchGroup = $this->getDOMElementAttributeAs($element, 'matchGroup')) !== null) {
$component->setMatchGroup(new IdentifierCollection(explode("\x20", $matchGroup)));
}
}
if (Version::compare($version, '2.1.0', '>=') === true) {
if (($matchMin = $this->getDOMElementAttributeAs($element, 'matchMin', 'integer')) !== null) {
$component->setMatchMin($matchMin);
}
}
}
$this->fillBodyElement($component, $element);
return $component;
} else {
$msg = "The mandatory attribute 'coords' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} else {
$msg = "The mandatory attribute 'shape' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} else {
$msg = "The mandatory attribute 'identifier' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"$",
"version",
"=",
"$",
"this",
"->",
"getVersion",
"(",
")",
";",
"if",
"(",
"(",
"$",
"identifier",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'identifier'",
")",
")",
"!==",
"null",
")",
"{",
"if",
"(",
"(",
"$",
"shape",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'shape'",
")",
")",
"!==",
"null",
")",
"{",
"if",
"(",
"(",
"$",
"coords",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'coords'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"shape",
"=",
"QtiShape",
"::",
"getConstantByName",
"(",
"$",
"shape",
")",
";",
"if",
"(",
"$",
"shape",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The value of the mandatory attribute 'shape' is not a value from the 'shape' enumeration.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"try",
"{",
"$",
"coords",
"=",
"Utils",
"::",
"stringToCoords",
"(",
"$",
"coords",
",",
"$",
"shape",
")",
";",
"}",
"catch",
"(",
"UnexpectedValueException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"The coordinates 'coords' of element '\"",
".",
"$",
"element",
"->",
"localName",
".",
"\"' are not valid regarding the shape they are bound to.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
",",
"$",
"e",
")",
";",
"}",
"catch",
"(",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"The coordinates 'coords' of element '\"",
".",
"$",
"element",
"->",
"localName",
".",
"\"' could not be converted.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
",",
"$",
"e",
")",
";",
"}",
"if",
"(",
"$",
"element",
"->",
"localName",
"===",
"'hotspotChoice'",
")",
"{",
"$",
"component",
"=",
"new",
"HotspotChoice",
"(",
"$",
"identifier",
",",
"$",
"shape",
",",
"$",
"coords",
")",
";",
"}",
"else",
"{",
"if",
"(",
"(",
"$",
"matchMax",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'matchMax'",
",",
"'integer'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"component",
"=",
"new",
"AssociableHotspot",
"(",
"$",
"identifier",
",",
"$",
"matchMax",
",",
"$",
"shape",
",",
"$",
"coords",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory attribute 'matchMax' is missing from element 'associableHotspot'.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}",
"if",
"(",
"(",
"$",
"hotspotLabel",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'hotspotLabel'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"component",
"->",
"setHotspotLabel",
"(",
"$",
"hotspotLabel",
")",
";",
"}",
"if",
"(",
"(",
"$",
"fixed",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'fixed'",
",",
"'boolean'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"component",
"->",
"setFixed",
"(",
"$",
"fixed",
")",
";",
"}",
"if",
"(",
"(",
"$",
"templateIdentifier",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'templateIdentifier'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"component",
"->",
"setTemplateIdentifier",
"(",
"$",
"templateIdentifier",
")",
";",
"}",
"if",
"(",
"(",
"$",
"showHide",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'showHide'",
")",
")",
"!==",
"null",
")",
"{",
"if",
"(",
"(",
"$",
"showHide",
"=",
"ShowHide",
"::",
"getConstantByName",
"(",
"$",
"showHide",
")",
")",
"!==",
"false",
")",
"{",
"$",
"component",
"->",
"setShowHide",
"(",
"$",
"showHide",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The value of the 'showHide' attribute of element '\"",
".",
"$",
"element",
"->",
"localName",
".",
"\"' is not a value from the 'showHide' enumeration.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}",
"if",
"(",
"$",
"element",
"->",
"localName",
"===",
"'associableHotspot'",
")",
"{",
"if",
"(",
"Version",
"::",
"compare",
"(",
"$",
"version",
",",
"'2.1.0'",
",",
"'<'",
")",
"===",
"true",
")",
"{",
"if",
"(",
"(",
"$",
"matchGroup",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'matchGroup'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"component",
"->",
"setMatchGroup",
"(",
"new",
"IdentifierCollection",
"(",
"explode",
"(",
"\"\\x20\"",
",",
"$",
"matchGroup",
")",
")",
")",
";",
"}",
"}",
"if",
"(",
"Version",
"::",
"compare",
"(",
"$",
"version",
",",
"'2.1.0'",
",",
"'>='",
")",
"===",
"true",
")",
"{",
"if",
"(",
"(",
"$",
"matchMin",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'matchMin'",
",",
"'integer'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"component",
"->",
"setMatchMin",
"(",
"$",
"matchMin",
")",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"fillBodyElement",
"(",
"$",
"component",
",",
"$",
"element",
")",
";",
"return",
"$",
"component",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory attribute 'coords' is missing from element '\"",
".",
"$",
"element",
"->",
"localName",
".",
"\"'.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory attribute 'shape' is missing from element '\"",
".",
"$",
"element",
"->",
"localName",
".",
"\"'.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory attribute 'identifier' is missing from element '\"",
".",
"$",
"element",
"->",
"localName",
".",
"\"'.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}"
] | Unmarshall a DOMElement object corresponding to a hotspotChoice/associableHotspot element.
@param \DOMElement $element A DOMElement object.
@return \qtism\data\QtiComponent A HotspotChoice/AssociableHotspot object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException | [
"Unmarshall",
"a",
"DOMElement",
"object",
"corresponding",
"to",
"a",
"hotspotChoice",
"/",
"associableHotspot",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/HotspotMarshaller.php#L108-L195 |
oat-sa/qti-sdk | src/qtism/common/datatypes/Utils.php | Utils.isQtiInteger | public static function isQtiInteger($integer)
{
// QTI integers are twos-complement 32-bits integers.
if (is_int($integer) === false) {
return false;
} elseif ($integer > 2147483647) {
return false;
} elseif ($integer < -2147483647) {
return false;
} else {
return true;
}
} | php | public static function isQtiInteger($integer)
{
// QTI integers are twos-complement 32-bits integers.
if (is_int($integer) === false) {
return false;
} elseif ($integer > 2147483647) {
return false;
} elseif ($integer < -2147483647) {
return false;
} else {
return true;
}
} | [
"public",
"static",
"function",
"isQtiInteger",
"(",
"$",
"integer",
")",
"{",
"// QTI integers are twos-complement 32-bits integers.",
"if",
"(",
"is_int",
"(",
"$",
"integer",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"elseif",
"(",
"$",
"integer",
">",
"2147483647",
")",
"{",
"return",
"false",
";",
"}",
"elseif",
"(",
"$",
"integer",
"<",
"-",
"2147483647",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"return",
"true",
";",
"}",
"}"
] | Whether a given $integer value is a QTI compliant
integer in the [-2147483647, 2147483647] range.
@param mixed $integer
@return boolean | [
"Whether",
"a",
"given",
"$integer",
"value",
"is",
"a",
"QTI",
"compliant",
"integer",
"in",
"the",
"[",
"-",
"2147483647",
"2147483647",
"]",
"range",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/datatypes/Utils.php#L41-L53 |
oat-sa/qti-sdk | src/qtism/common/collections/Container.php | Container.equals | public function equals($obj)
{
if (gettype($obj) === 'object' && $obj instanceof static && count($obj) === count($this)) {
foreach (array_keys($this->getDataPlaceHolder()) as $key) {
$t = $this[$key];
$occurencesA = $this->occurences($t);
$occurencesB = $obj->occurences($t);
if ($occurencesA !== $occurencesB) {
return false;
}
}
return true;
} else {
// Not the same type or different item count.
return false;
}
} | php | public function equals($obj)
{
if (gettype($obj) === 'object' && $obj instanceof static && count($obj) === count($this)) {
foreach (array_keys($this->getDataPlaceHolder()) as $key) {
$t = $this[$key];
$occurencesA = $this->occurences($t);
$occurencesB = $obj->occurences($t);
if ($occurencesA !== $occurencesB) {
return false;
}
}
return true;
} else {
// Not the same type or different item count.
return false;
}
} | [
"public",
"function",
"equals",
"(",
"$",
"obj",
")",
"{",
"if",
"(",
"gettype",
"(",
"$",
"obj",
")",
"===",
"'object'",
"&&",
"$",
"obj",
"instanceof",
"static",
"&&",
"count",
"(",
"$",
"obj",
")",
"===",
"count",
"(",
"$",
"this",
")",
")",
"{",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"getDataPlaceHolder",
"(",
")",
")",
"as",
"$",
"key",
")",
"{",
"$",
"t",
"=",
"$",
"this",
"[",
"$",
"key",
"]",
";",
"$",
"occurencesA",
"=",
"$",
"this",
"->",
"occurences",
"(",
"$",
"t",
")",
";",
"$",
"occurencesB",
"=",
"$",
"obj",
"->",
"occurences",
"(",
"$",
"t",
")",
";",
"if",
"(",
"$",
"occurencesA",
"!==",
"$",
"occurencesB",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}",
"else",
"{",
"// Not the same type or different item count.",
"return",
"false",
";",
"}",
"}"
] | Wheter the container is equal to $obj.
* If $obj is not an instance of Container, false is returned.
* If $obj is [A,B,C] and the container is [C,A,B], true is returned because the order does not matter.
* If $obj is [A,B,C] and the container is [B,C,D], false is returned.
* If $obj is [] and the container is [], true is returned.
@param mixed $obj A value to compare to this one.
@return boolean Whether the container is equal to $obj. | [
"Wheter",
"the",
"container",
"is",
"equal",
"to",
"$obj",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/collections/Container.php#L133-L151 |
oat-sa/qti-sdk | src/qtism/common/collections/Container.php | Container.occurences | public function occurences($obj)
{
$occurences = 0;
foreach (array_keys($this->getDataPlaceHolder()) as $key) {
$t = $this[$key];
if (gettype($obj) === 'object' && $obj instanceof Comparable) {
// try to use Comparable.
if ($obj->equals($t)) {
$occurences++;
}
} elseif (gettype($t) === 'object' && $t instanceof Comparable) {
// Again, use Comparable.
if ($t->equals($obj)) {
$occurences++;
}
} else {
// Both primitive.
if ($obj === $t) {
$occurences++;
}
}
}
return $occurences;
} | php | public function occurences($obj)
{
$occurences = 0;
foreach (array_keys($this->getDataPlaceHolder()) as $key) {
$t = $this[$key];
if (gettype($obj) === 'object' && $obj instanceof Comparable) {
// try to use Comparable.
if ($obj->equals($t)) {
$occurences++;
}
} elseif (gettype($t) === 'object' && $t instanceof Comparable) {
// Again, use Comparable.
if ($t->equals($obj)) {
$occurences++;
}
} else {
// Both primitive.
if ($obj === $t) {
$occurences++;
}
}
}
return $occurences;
} | [
"public",
"function",
"occurences",
"(",
"$",
"obj",
")",
"{",
"$",
"occurences",
"=",
"0",
";",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"getDataPlaceHolder",
"(",
")",
")",
"as",
"$",
"key",
")",
"{",
"$",
"t",
"=",
"$",
"this",
"[",
"$",
"key",
"]",
";",
"if",
"(",
"gettype",
"(",
"$",
"obj",
")",
"===",
"'object'",
"&&",
"$",
"obj",
"instanceof",
"Comparable",
")",
"{",
"// try to use Comparable.",
"if",
"(",
"$",
"obj",
"->",
"equals",
"(",
"$",
"t",
")",
")",
"{",
"$",
"occurences",
"++",
";",
"}",
"}",
"elseif",
"(",
"gettype",
"(",
"$",
"t",
")",
"===",
"'object'",
"&&",
"$",
"t",
"instanceof",
"Comparable",
")",
"{",
"// Again, use Comparable.",
"if",
"(",
"$",
"t",
"->",
"equals",
"(",
"$",
"obj",
")",
")",
"{",
"$",
"occurences",
"++",
";",
"}",
"}",
"else",
"{",
"// Both primitive.",
"if",
"(",
"$",
"obj",
"===",
"$",
"t",
")",
"{",
"$",
"occurences",
"++",
";",
"}",
"}",
"}",
"return",
"$",
"occurences",
";",
"}"
] | Get the number of occurences of a given $obj in the container.
* If $obj is an instance of Comparable, an equality check will be performed using the Comparable::equals method of $obj.
* If $obj is a primitive type, a strict comparison (===) will be applied.
@param mixed $obj The object you want to find the number of occurences in the container.
@return int A number of occurences. | [
"Get",
"the",
"number",
"of",
"occurences",
"of",
"a",
"given",
"$obj",
"in",
"the",
"container",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/collections/Container.php#L162-L187 |
oat-sa/qti-sdk | src/qtism/common/collections/Container.php | Container.createFromDataModel | public static function createFromDataModel(ValueCollection $valueCollection)
{
$container = new static();
foreach ($valueCollection as $value) {
$container[] = RuntimeUtils::valueToRuntime($value->getValue(), $value->getBaseType());
}
return $container;
} | php | public static function createFromDataModel(ValueCollection $valueCollection)
{
$container = new static();
foreach ($valueCollection as $value) {
$container[] = RuntimeUtils::valueToRuntime($value->getValue(), $value->getBaseType());
}
return $container;
} | [
"public",
"static",
"function",
"createFromDataModel",
"(",
"ValueCollection",
"$",
"valueCollection",
")",
"{",
"$",
"container",
"=",
"new",
"static",
"(",
")",
";",
"foreach",
"(",
"$",
"valueCollection",
"as",
"$",
"value",
")",
"{",
"$",
"container",
"[",
"]",
"=",
"RuntimeUtils",
"::",
"valueToRuntime",
"(",
"$",
"value",
"->",
"getValue",
"(",
")",
",",
"$",
"value",
"->",
"getBaseType",
"(",
")",
")",
";",
"}",
"return",
"$",
"container",
";",
"}"
] | Create a Container object from a Data Model ValueCollection object.
@param \qtism\data\state\ValueCollection $valueCollection A collection of qtism\data\state\Value objects.
@return \qtism\common\collections\Container A Container object populated with the values found in $valueCollection.
@throws \InvalidArgumentException If a value from $valueCollection is not compliant with the QTI Runtime Model or the container type. | [
"Create",
"a",
"Container",
"object",
"from",
"a",
"Data",
"Model",
"ValueCollection",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/collections/Container.php#L196-L204 |
oat-sa/qti-sdk | src/qtism/common/collections/Container.php | Container.distinct | public function distinct()
{
$container = clone $this;
$newDataPlaceHolder = [];
foreach ($this->getDataPlaceHolder() as $key => $value) {
$found = false;
foreach ($newDataPlaceHolder as $newValue) {
if (gettype($value) === 'object' && $value instanceof Comparable && $value->equals($newValue)) {
$found = true;
break;
} elseif (gettype($newValue) === 'object' && $newValue instanceof Comparable && $newValue->equals($value)) {
$found = true;
break;
} else if ($value === $newValue) {
$found = true;
break;
}
}
if ($found === false) {
if (is_string($key) === true) {
$newDataPlaceHolder[$key] = $value;
} else {
$newDataPlaceHolder[] = $value;
}
}
}
$container->setDataPlaceHolder($newDataPlaceHolder);
return $container;
} | php | public function distinct()
{
$container = clone $this;
$newDataPlaceHolder = [];
foreach ($this->getDataPlaceHolder() as $key => $value) {
$found = false;
foreach ($newDataPlaceHolder as $newValue) {
if (gettype($value) === 'object' && $value instanceof Comparable && $value->equals($newValue)) {
$found = true;
break;
} elseif (gettype($newValue) === 'object' && $newValue instanceof Comparable && $newValue->equals($value)) {
$found = true;
break;
} else if ($value === $newValue) {
$found = true;
break;
}
}
if ($found === false) {
if (is_string($key) === true) {
$newDataPlaceHolder[$key] = $value;
} else {
$newDataPlaceHolder[] = $value;
}
}
}
$container->setDataPlaceHolder($newDataPlaceHolder);
return $container;
} | [
"public",
"function",
"distinct",
"(",
")",
"{",
"$",
"container",
"=",
"clone",
"$",
"this",
";",
"$",
"newDataPlaceHolder",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getDataPlaceHolder",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"found",
"=",
"false",
";",
"foreach",
"(",
"$",
"newDataPlaceHolder",
"as",
"$",
"newValue",
")",
"{",
"if",
"(",
"gettype",
"(",
"$",
"value",
")",
"===",
"'object'",
"&&",
"$",
"value",
"instanceof",
"Comparable",
"&&",
"$",
"value",
"->",
"equals",
"(",
"$",
"newValue",
")",
")",
"{",
"$",
"found",
"=",
"true",
";",
"break",
";",
"}",
"elseif",
"(",
"gettype",
"(",
"$",
"newValue",
")",
"===",
"'object'",
"&&",
"$",
"newValue",
"instanceof",
"Comparable",
"&&",
"$",
"newValue",
"->",
"equals",
"(",
"$",
"value",
")",
")",
"{",
"$",
"found",
"=",
"true",
";",
"break",
";",
"}",
"else",
"if",
"(",
"$",
"value",
"===",
"$",
"newValue",
")",
"{",
"$",
"found",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"found",
"===",
"false",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"key",
")",
"===",
"true",
")",
"{",
"$",
"newDataPlaceHolder",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"newDataPlaceHolder",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}",
"$",
"container",
"->",
"setDataPlaceHolder",
"(",
"$",
"newDataPlaceHolder",
")",
";",
"return",
"$",
"container",
";",
"}"
] | Get Distinct Container Copy.
Provides a copy of the container, with distinct values. In other words,
any duplicated values from the container will not appear in the returned
container.
Please note that the container copy is a shallow copy of the original, not
a deep copy.
@return \qtism\common\collections\Container | [
"Get",
"Distinct",
"Container",
"Copy",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/collections/Container.php#L278-L313 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/RepeatProcessor.php | RepeatProcessor.process | public function process()
{
$operands = $this->getOperands();
// get the value of numberRepeats
$expression = $this->getExpression();
$numberRepeats = $expression->getNumberRepeats();
if (gettype($numberRepeats) === 'string') {
// Variable reference found.
$state = $this->getState();
$varName = ExprUtils::sanitizeVariableRef($numberRepeats);
$varValue = $state[$varName];
if (is_null($varValue) === true) {
$msg = "The variable with name '${varName}' could not be resolved.";
throw new OperatorProcessingException($msg, $this);
} elseif (!$varValue instanceof QtiInteger) {
$msg = "The variable with name '${varName}' is not an integer value.";
throw new OperatorProcessingException($msg, $this);
}
$numberRepeats = $varValue->getValue();
}
if ($numberRepeats < 1) {
return null;
}
$result = null;
for ($i = 0; $i < $numberRepeats; $i++) {
$refType = null;
foreach ($operands as $operand) {
// If null, ignore
if (is_null($operand) || ($operand instanceof Container && $operand->isNull())) {
continue;
}
// Check cardinality.
if ($operand->getCardinality() !== Cardinality::SINGLE && $operand->getCardinality() !== Cardinality::ORDERED) {
$msg = "The Repeat operator only accepts operands with a single or ordered cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
// Check baseType.
$currentType = RuntimeUtils::inferBaseType($operand);
if ($refType !== null && $currentType !== $refType) {
$msg = "The Repeat operator only accepts operands with the same baseType.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
} elseif (is_null($result)) {
$refType = $currentType;
$result = new OrderedContainer($refType);
}
// Okay we are good...
$operandCardinality = RuntimeUtils::inferCardinality($operand);
if ($operandCardinality !== Cardinality::ORDERED) {
$operand = new OrderedContainer($currentType, array($operand));
}
foreach ($operand as $o) {
$result[] = ($o instanceof QtiDatatype) ? clone $o : $o;
}
}
}
if (isset($result) && $result->isNull() !== true) {
return $result;
} else {
return null;
}
} | php | public function process()
{
$operands = $this->getOperands();
// get the value of numberRepeats
$expression = $this->getExpression();
$numberRepeats = $expression->getNumberRepeats();
if (gettype($numberRepeats) === 'string') {
// Variable reference found.
$state = $this->getState();
$varName = ExprUtils::sanitizeVariableRef($numberRepeats);
$varValue = $state[$varName];
if (is_null($varValue) === true) {
$msg = "The variable with name '${varName}' could not be resolved.";
throw new OperatorProcessingException($msg, $this);
} elseif (!$varValue instanceof QtiInteger) {
$msg = "The variable with name '${varName}' is not an integer value.";
throw new OperatorProcessingException($msg, $this);
}
$numberRepeats = $varValue->getValue();
}
if ($numberRepeats < 1) {
return null;
}
$result = null;
for ($i = 0; $i < $numberRepeats; $i++) {
$refType = null;
foreach ($operands as $operand) {
// If null, ignore
if (is_null($operand) || ($operand instanceof Container && $operand->isNull())) {
continue;
}
// Check cardinality.
if ($operand->getCardinality() !== Cardinality::SINGLE && $operand->getCardinality() !== Cardinality::ORDERED) {
$msg = "The Repeat operator only accepts operands with a single or ordered cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
// Check baseType.
$currentType = RuntimeUtils::inferBaseType($operand);
if ($refType !== null && $currentType !== $refType) {
$msg = "The Repeat operator only accepts operands with the same baseType.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
} elseif (is_null($result)) {
$refType = $currentType;
$result = new OrderedContainer($refType);
}
// Okay we are good...
$operandCardinality = RuntimeUtils::inferCardinality($operand);
if ($operandCardinality !== Cardinality::ORDERED) {
$operand = new OrderedContainer($currentType, array($operand));
}
foreach ($operand as $o) {
$result[] = ($o instanceof QtiDatatype) ? clone $o : $o;
}
}
}
if (isset($result) && $result->isNull() !== true) {
return $result;
} else {
return null;
}
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"operands",
"=",
"$",
"this",
"->",
"getOperands",
"(",
")",
";",
"// get the value of numberRepeats",
"$",
"expression",
"=",
"$",
"this",
"->",
"getExpression",
"(",
")",
";",
"$",
"numberRepeats",
"=",
"$",
"expression",
"->",
"getNumberRepeats",
"(",
")",
";",
"if",
"(",
"gettype",
"(",
"$",
"numberRepeats",
")",
"===",
"'string'",
")",
"{",
"// Variable reference found.",
"$",
"state",
"=",
"$",
"this",
"->",
"getState",
"(",
")",
";",
"$",
"varName",
"=",
"ExprUtils",
"::",
"sanitizeVariableRef",
"(",
"$",
"numberRepeats",
")",
";",
"$",
"varValue",
"=",
"$",
"state",
"[",
"$",
"varName",
"]",
";",
"if",
"(",
"is_null",
"(",
"$",
"varValue",
")",
"===",
"true",
")",
"{",
"$",
"msg",
"=",
"\"The variable with name '${varName}' could not be resolved.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
")",
";",
"}",
"elseif",
"(",
"!",
"$",
"varValue",
"instanceof",
"QtiInteger",
")",
"{",
"$",
"msg",
"=",
"\"The variable with name '${varName}' is not an integer value.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
")",
";",
"}",
"$",
"numberRepeats",
"=",
"$",
"varValue",
"->",
"getValue",
"(",
")",
";",
"}",
"if",
"(",
"$",
"numberRepeats",
"<",
"1",
")",
"{",
"return",
"null",
";",
"}",
"$",
"result",
"=",
"null",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"numberRepeats",
";",
"$",
"i",
"++",
")",
"{",
"$",
"refType",
"=",
"null",
";",
"foreach",
"(",
"$",
"operands",
"as",
"$",
"operand",
")",
"{",
"// If null, ignore",
"if",
"(",
"is_null",
"(",
"$",
"operand",
")",
"||",
"(",
"$",
"operand",
"instanceof",
"Container",
"&&",
"$",
"operand",
"->",
"isNull",
"(",
")",
")",
")",
"{",
"continue",
";",
"}",
"// Check cardinality.",
"if",
"(",
"$",
"operand",
"->",
"getCardinality",
"(",
")",
"!==",
"Cardinality",
"::",
"SINGLE",
"&&",
"$",
"operand",
"->",
"getCardinality",
"(",
")",
"!==",
"Cardinality",
"::",
"ORDERED",
")",
"{",
"$",
"msg",
"=",
"\"The Repeat operator only accepts operands with a single or ordered cardinality.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_CARDINALITY",
")",
";",
"}",
"// Check baseType.",
"$",
"currentType",
"=",
"RuntimeUtils",
"::",
"inferBaseType",
"(",
"$",
"operand",
")",
";",
"if",
"(",
"$",
"refType",
"!==",
"null",
"&&",
"$",
"currentType",
"!==",
"$",
"refType",
")",
"{",
"$",
"msg",
"=",
"\"The Repeat operator only accepts operands with the same baseType.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_BASETYPE",
")",
";",
"}",
"elseif",
"(",
"is_null",
"(",
"$",
"result",
")",
")",
"{",
"$",
"refType",
"=",
"$",
"currentType",
";",
"$",
"result",
"=",
"new",
"OrderedContainer",
"(",
"$",
"refType",
")",
";",
"}",
"// Okay we are good...",
"$",
"operandCardinality",
"=",
"RuntimeUtils",
"::",
"inferCardinality",
"(",
"$",
"operand",
")",
";",
"if",
"(",
"$",
"operandCardinality",
"!==",
"Cardinality",
"::",
"ORDERED",
")",
"{",
"$",
"operand",
"=",
"new",
"OrderedContainer",
"(",
"$",
"currentType",
",",
"array",
"(",
"$",
"operand",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"operand",
"as",
"$",
"o",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"(",
"$",
"o",
"instanceof",
"QtiDatatype",
")",
"?",
"clone",
"$",
"o",
":",
"$",
"o",
";",
"}",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"result",
")",
"&&",
"$",
"result",
"->",
"isNull",
"(",
")",
"!==",
"true",
")",
"{",
"return",
"$",
"result",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] | Process the Repeat operator.
Note: NULL values are simply ignored. If all sub-expressions are NULL, NULL is
returned.
@return \qtism\runtime\common\OrderedContainer An ordered container filled sequentially by evaluating each sub-expressions, repeated a 'numberRepeats' of times. NULL is returned if all sub-expressions are NULL or numberRepeats < 1.
@throws \qtism\runtime\expressions\operators\OperatorProcessingException | [
"Process",
"the",
"Repeat",
"operator",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/RepeatProcessor.php#L67-L141 |
oat-sa/qti-sdk | src/qtism/runtime/rendering/markup/AbstractMarkupRenderer.php | AbstractMarkupRenderer.transformUri | protected function transformUri($url, $baseUrl)
{
// Only relative URIs must be transformed while
// taking xml:base into account.
if (Url::isRelative($url) === false) {
return $url;
}
$xmlBasePolicy = $this->getRenderingEngine()->getXmlBasePolicy();
switch ($xmlBasePolicy) {
case AbstractMarkupRenderingEngine::XMLBASE_PROCESS:
if (empty($baseUrl) === false) {
return Url::rtrim($baseUrl) . '/' . Url::ltrim($url);
} else {
return $url;
}
break;
default:
return $url;
break;
}
} | php | protected function transformUri($url, $baseUrl)
{
// Only relative URIs must be transformed while
// taking xml:base into account.
if (Url::isRelative($url) === false) {
return $url;
}
$xmlBasePolicy = $this->getRenderingEngine()->getXmlBasePolicy();
switch ($xmlBasePolicy) {
case AbstractMarkupRenderingEngine::XMLBASE_PROCESS:
if (empty($baseUrl) === false) {
return Url::rtrim($baseUrl) . '/' . Url::ltrim($url);
} else {
return $url;
}
break;
default:
return $url;
break;
}
} | [
"protected",
"function",
"transformUri",
"(",
"$",
"url",
",",
"$",
"baseUrl",
")",
"{",
"// Only relative URIs must be transformed while",
"// taking xml:base into account.",
"if",
"(",
"Url",
"::",
"isRelative",
"(",
"$",
"url",
")",
"===",
"false",
")",
"{",
"return",
"$",
"url",
";",
"}",
"$",
"xmlBasePolicy",
"=",
"$",
"this",
"->",
"getRenderingEngine",
"(",
")",
"->",
"getXmlBasePolicy",
"(",
")",
";",
"switch",
"(",
"$",
"xmlBasePolicy",
")",
"{",
"case",
"AbstractMarkupRenderingEngine",
"::",
"XMLBASE_PROCESS",
":",
"if",
"(",
"empty",
"(",
"$",
"baseUrl",
")",
"===",
"false",
")",
"{",
"return",
"Url",
"::",
"rtrim",
"(",
"$",
"baseUrl",
")",
".",
"'/'",
".",
"Url",
"::",
"ltrim",
"(",
"$",
"url",
")",
";",
"}",
"else",
"{",
"return",
"$",
"url",
";",
"}",
"break",
";",
"default",
":",
"return",
"$",
"url",
";",
"break",
";",
"}",
"}"
] | Transform a URL depending on a given $baseUrl and how the
rendering engine is considering them.
@param string $url A given URL (Uniform Resource Locator).
@param string $baseUrl a baseUrl (xml:base).
@return string A transformed URL. | [
"Transform",
"a",
"URL",
"depending",
"on",
"a",
"given",
"$baseUrl",
"and",
"how",
"the",
"rendering",
"engine",
"is",
"considering",
"them",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/markup/AbstractMarkupRenderer.php#L75-L99 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/NumberIncorrectProcessor.php | NumberIncorrectProcessor.process | public function process()
{
$testSession = $this->getState();
$itemSubset = $this->getItemSubset();
$numberIncorrect = 0;
foreach ($itemSubset as $item) {
$itemSessions = $testSession->getAssessmentItemSessions($item->getIdentifier());
if ($itemSessions !== false) {
foreach ($itemSessions as $itemSession) {
if ($itemSession->isAttempted() === true && $itemSession->isCorrect() === false) {
$numberIncorrect++;
}
}
}
}
return new QtiInteger($numberIncorrect);
} | php | public function process()
{
$testSession = $this->getState();
$itemSubset = $this->getItemSubset();
$numberIncorrect = 0;
foreach ($itemSubset as $item) {
$itemSessions = $testSession->getAssessmentItemSessions($item->getIdentifier());
if ($itemSessions !== false) {
foreach ($itemSessions as $itemSession) {
if ($itemSession->isAttempted() === true && $itemSession->isCorrect() === false) {
$numberIncorrect++;
}
}
}
}
return new QtiInteger($numberIncorrect);
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"testSession",
"=",
"$",
"this",
"->",
"getState",
"(",
")",
";",
"$",
"itemSubset",
"=",
"$",
"this",
"->",
"getItemSubset",
"(",
")",
";",
"$",
"numberIncorrect",
"=",
"0",
";",
"foreach",
"(",
"$",
"itemSubset",
"as",
"$",
"item",
")",
"{",
"$",
"itemSessions",
"=",
"$",
"testSession",
"->",
"getAssessmentItemSessions",
"(",
"$",
"item",
"->",
"getIdentifier",
"(",
")",
")",
";",
"if",
"(",
"$",
"itemSessions",
"!==",
"false",
")",
"{",
"foreach",
"(",
"$",
"itemSessions",
"as",
"$",
"itemSession",
")",
"{",
"if",
"(",
"$",
"itemSession",
"->",
"isAttempted",
"(",
")",
"===",
"true",
"&&",
"$",
"itemSession",
"->",
"isCorrect",
"(",
")",
"===",
"false",
")",
"{",
"$",
"numberIncorrect",
"++",
";",
"}",
"}",
"}",
"}",
"return",
"new",
"QtiInteger",
"(",
"$",
"numberIncorrect",
")",
";",
"}"
] | Process the related NumberIncorrect expression.
@return integer The number of items in the given sub-set for which at least one of the defined response does not match its associated correct response.
@throws \qtism\runtime\expressions\ExpressionProcessingException | [
"Process",
"the",
"related",
"NumberIncorrect",
"expression",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/NumberIncorrectProcessor.php#L53-L72 |
oat-sa/qti-sdk | src/qtism/data/content/interactions/AssociateInteraction.php | AssociateInteraction.setMaxAssociations | public function setMaxAssociations($maxAssociations)
{
if (is_int($maxAssociations) === true && $maxAssociations >= 0) {
$this->maxAssociations = $maxAssociations;
} else {
$msg = "The 'maxAssociations' argument must be a positive (>= 0) integer, '" . gettype($maxAssociations) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setMaxAssociations($maxAssociations)
{
if (is_int($maxAssociations) === true && $maxAssociations >= 0) {
$this->maxAssociations = $maxAssociations;
} else {
$msg = "The 'maxAssociations' argument must be a positive (>= 0) integer, '" . gettype($maxAssociations) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setMaxAssociations",
"(",
"$",
"maxAssociations",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"maxAssociations",
")",
"===",
"true",
"&&",
"$",
"maxAssociations",
">=",
"0",
")",
"{",
"$",
"this",
"->",
"maxAssociations",
"=",
"$",
"maxAssociations",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'maxAssociations' argument must be a positive (>= 0) integer, '\"",
".",
"gettype",
"(",
"$",
"maxAssociations",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the maximum number of associations the candidate is required to make. If $maxAssociations
is 0, there is no maximum number of associations.
@param integer $maxAssociations A positive (>= 0) integer.
@throws \InvalidArgumentException If $maxAssociations is not a positive integer. | [
"Set",
"the",
"maximum",
"number",
"of",
"associations",
"the",
"candidate",
"is",
"required",
"to",
"make",
".",
"If",
"$maxAssociations",
"is",
"0",
"there",
"is",
"no",
"maximum",
"number",
"of",
"associations",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/interactions/AssociateInteraction.php#L146-L154 |
oat-sa/qti-sdk | src/qtism/data/content/interactions/AssociateInteraction.php | AssociateInteraction.setMinAssociations | public function setMinAssociations($minAssociations)
{
if (is_int($minAssociations) === true && $minAssociations >= 0) {
if ($this->hasMaxAssociations() === true && $minAssociations > $this->getMaxAssociations()) {
$msg = "The 'minAssociation' argument must be less than or equal to the limit imposed by 'maxAssociations'.";
throw new InvalidArgumentException($msg);
}
$this->minAssociations = $minAssociations;
} else {
$msg = "The 'minAssociations' argument must be a positive (>= 0) integer, '" . gettype($minAssociations) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setMinAssociations($minAssociations)
{
if (is_int($minAssociations) === true && $minAssociations >= 0) {
if ($this->hasMaxAssociations() === true && $minAssociations > $this->getMaxAssociations()) {
$msg = "The 'minAssociation' argument must be less than or equal to the limit imposed by 'maxAssociations'.";
throw new InvalidArgumentException($msg);
}
$this->minAssociations = $minAssociations;
} else {
$msg = "The 'minAssociations' argument must be a positive (>= 0) integer, '" . gettype($minAssociations) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setMinAssociations",
"(",
"$",
"minAssociations",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"minAssociations",
")",
"===",
"true",
"&&",
"$",
"minAssociations",
">=",
"0",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasMaxAssociations",
"(",
")",
"===",
"true",
"&&",
"$",
"minAssociations",
">",
"$",
"this",
"->",
"getMaxAssociations",
"(",
")",
")",
"{",
"$",
"msg",
"=",
"\"The 'minAssociation' argument must be less than or equal to the limit imposed by 'maxAssociations'.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"$",
"this",
"->",
"minAssociations",
"=",
"$",
"minAssociations",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'minAssociations' argument must be a positive (>= 0) integer, '\"",
".",
"gettype",
"(",
"$",
"minAssociations",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the minimum number of associations that the candidate is required to make. If
$minAssociations is 0, there is no minimum number of associations required.
@param integer $minAssociations A positive (>= 0) integer.
@throws \InvalidArgumentException If $minAssociations is not a positive integer or if $minAssociations is not less than or equal to the limit imposed by 'maxAssociations'. | [
"Set",
"the",
"minimum",
"number",
"of",
"associations",
"that",
"the",
"candidate",
"is",
"required",
"to",
"make",
".",
"If",
"$minAssociations",
"is",
"0",
"there",
"is",
"no",
"minimum",
"number",
"of",
"associations",
"required",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/interactions/AssociateInteraction.php#L184-L198 |
oat-sa/qti-sdk | src/qtism/data/content/interactions/AssociateInteraction.php | AssociateInteraction.setSimpleAssociableChoices | public function setSimpleAssociableChoices(SimpleAssociableChoiceCollection $simpleAssociableChoices)
{
if (count($simpleAssociableChoices) > 0) {
$this->simpleAssociableChoices = $simpleAssociableChoices;
} else {
$msg = "An AssociateInteraction object must be composed of at lease one SimpleAssociableChoice object, none given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setSimpleAssociableChoices(SimpleAssociableChoiceCollection $simpleAssociableChoices)
{
if (count($simpleAssociableChoices) > 0) {
$this->simpleAssociableChoices = $simpleAssociableChoices;
} else {
$msg = "An AssociateInteraction object must be composed of at lease one SimpleAssociableChoice object, none given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setSimpleAssociableChoices",
"(",
"SimpleAssociableChoiceCollection",
"$",
"simpleAssociableChoices",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"simpleAssociableChoices",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"simpleAssociableChoices",
"=",
"$",
"simpleAssociableChoices",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"An AssociateInteraction object must be composed of at lease one SimpleAssociableChoice object, none given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the choices.
@param \qtism\data\content\interactions\SimpleAssociableChoiceCollection $simpleAssociableChoices A collection of at least one SimpleAssociableChoice object.
@throws \InvalidArgumentException If $simpleAssociableChoices is empty. | [
"Set",
"the",
"choices",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/interactions/AssociateInteraction.php#L227-L235 |
oat-sa/qti-sdk | src/qtism/data/content/RubricBlock.php | RubricBlock.setViews | public function setViews(ViewCollection $views)
{
if (count($views) > 0) {
$this->views = $views;
} else {
$msg = "A RubricBlock object must contain at least one View.";
throw new InvalidArgumentException($msg);
}
} | php | public function setViews(ViewCollection $views)
{
if (count($views) > 0) {
$this->views = $views;
} else {
$msg = "A RubricBlock object must contain at least one View.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setViews",
"(",
"ViewCollection",
"$",
"views",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"views",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"views",
"=",
"$",
"views",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"A RubricBlock object must contain at least one View.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the views in which the rubric block's content are to be shown.
@param \qtism\data\ViewCollection $views A collection of values that belong to the View enumeration.
@throws \InvalidArgumentException If $views is an empty collection. | [
"Set",
"the",
"views",
"in",
"which",
"the",
"rubric",
"block",
"s",
"content",
"are",
"to",
"be",
"shown",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/RubricBlock.php#L111-L119 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/Utils.php | Utils.sanitizeVariableRef | public static function sanitizeVariableRef($variableRef)
{
if (gettype($variableRef) === 'string') {
return trim($variableRef, '{}');
} else {
$msg = "The Utils::sanitizeVariableRef method only accepts a string argument, '" . gettype($variableRef) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public static function sanitizeVariableRef($variableRef)
{
if (gettype($variableRef) === 'string') {
return trim($variableRef, '{}');
} else {
$msg = "The Utils::sanitizeVariableRef method only accepts a string argument, '" . gettype($variableRef) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"static",
"function",
"sanitizeVariableRef",
"(",
"$",
"variableRef",
")",
"{",
"if",
"(",
"gettype",
"(",
"$",
"variableRef",
")",
"===",
"'string'",
")",
"{",
"return",
"trim",
"(",
"$",
"variableRef",
",",
"'{}'",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The Utils::sanitizeVariableRef method only accepts a string argument, '\"",
".",
"gettype",
"(",
"$",
"variableRef",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Removes trailing and ending braces ('{' and '}') from a variableRef.
@return string A sanitized variableRef. | [
"Removes",
"trailing",
"and",
"ending",
"braces",
"(",
"{",
"and",
"}",
")",
"from",
"a",
"variableRef",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/Utils.php#L42-L50 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/ExpressionEngine.php | ExpressionEngine.setComponent | public function setComponent(QtiComponent $expression)
{
if ($expression instanceof Expression) {
parent::setComponent($expression);
} else {
$msg = "The ExpressionEngine class only accepts QTI Data Model Expression objects to be processed.";
throw new InvalidArgumentException($msg);
}
} | php | public function setComponent(QtiComponent $expression)
{
if ($expression instanceof Expression) {
parent::setComponent($expression);
} else {
$msg = "The ExpressionEngine class only accepts QTI Data Model Expression objects to be processed.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setComponent",
"(",
"QtiComponent",
"$",
"expression",
")",
"{",
"if",
"(",
"$",
"expression",
"instanceof",
"Expression",
")",
"{",
"parent",
"::",
"setComponent",
"(",
"$",
"expression",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The ExpressionEngine class only accepts QTI Data Model Expression objects to be processed.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the Expression object to be processed.
@param \qtism\data\QtiComponent $expression An Expression object.
@throws \InvalidArgumentException If $expression is not an Expression object. | [
"Set",
"the",
"Expression",
"object",
"to",
"be",
"processed",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/ExpressionEngine.php#L105-L113 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/ExpressionEngine.php | ExpressionEngine.pushTrail | protected function pushTrail($expression)
{
if ($expression instanceof Expression) {
array_push($this->trail, $expression);
} else {
// Add the collection in reverse order.
$i = count($expression);
while ($i >= 1) {
$i--;
array_push($this->trail, $expression[$i]);
}
}
} | php | protected function pushTrail($expression)
{
if ($expression instanceof Expression) {
array_push($this->trail, $expression);
} else {
// Add the collection in reverse order.
$i = count($expression);
while ($i >= 1) {
$i--;
array_push($this->trail, $expression[$i]);
}
}
} | [
"protected",
"function",
"pushTrail",
"(",
"$",
"expression",
")",
"{",
"if",
"(",
"$",
"expression",
"instanceof",
"Expression",
")",
"{",
"array_push",
"(",
"$",
"this",
"->",
"trail",
",",
"$",
"expression",
")",
";",
"}",
"else",
"{",
"// Add the collection in reverse order.",
"$",
"i",
"=",
"count",
"(",
"$",
"expression",
")",
";",
"while",
"(",
"$",
"i",
">=",
"1",
")",
"{",
"$",
"i",
"--",
";",
"array_push",
"(",
"$",
"this",
"->",
"trail",
",",
"$",
"expression",
"[",
"$",
"i",
"]",
")",
";",
"}",
"}",
"}"
] | Push an Expression object on the trail stack.
@param \qtism\data\expressions\Expression|\qtism\data\expressions\ExpressionCollection $expression An Expression/ExpressionCollection object to be pushed on top of the trail stack. | [
"Push",
"an",
"Expression",
"object",
"on",
"the",
"trail",
"stack",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/ExpressionEngine.php#L150-L162 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/ExpressionEngine.php | ExpressionEngine.process | public function process()
{
$expression = $this->getComponent();
// Reset trail and marker arrays.
$this->trail = array();
$this->marker = array();
$this->pushTrail($expression);
while (count($this->getTrail()) > 0) {
$expression = $this->popTrail();
if ($this->isMarked($expression) === false && $expression instanceof Operator) {
// This is an operator, first pass. Repush for a second pass.
$this->mark($expression);
$this->pushTrail($expression);
$this->pushTrail($expression->getExpressions());
} elseif ($this->isMarked($expression)) {
// Operator, second pass. Process it.
$popCount = count($expression->getExpressions());
$operands = $this->operands->pop($popCount);
$processor = $this->operatorProcessorFactory->createProcessor($expression, $operands);
$processor->setState($this->getContext());
$result = $processor->process();
// trace the processing of the operator.
$qtiName = $expression->getQtiClassName();
$trace = "Operator '${qtiName}' processed.";
$this->traceOperator($processor, $result);
if ($expression !== $this->getComponent()) {
$this->operands->push($result);
}
} else {
// Simple expression, process it.
$processor = $this->expressionProcessorFactory->createProcessor($expression);
$processor->setState($this->getContext());
$result = $processor->process();
$this->operands->push($result);
// trace the processing of the expression.
$qtiName = $expression->getQtiClassName();
$trace = "Expression '${qtiName}' processed.";
$this->traceExpression($processor, $result);
}
}
return $result;
} | php | public function process()
{
$expression = $this->getComponent();
// Reset trail and marker arrays.
$this->trail = array();
$this->marker = array();
$this->pushTrail($expression);
while (count($this->getTrail()) > 0) {
$expression = $this->popTrail();
if ($this->isMarked($expression) === false && $expression instanceof Operator) {
// This is an operator, first pass. Repush for a second pass.
$this->mark($expression);
$this->pushTrail($expression);
$this->pushTrail($expression->getExpressions());
} elseif ($this->isMarked($expression)) {
// Operator, second pass. Process it.
$popCount = count($expression->getExpressions());
$operands = $this->operands->pop($popCount);
$processor = $this->operatorProcessorFactory->createProcessor($expression, $operands);
$processor->setState($this->getContext());
$result = $processor->process();
// trace the processing of the operator.
$qtiName = $expression->getQtiClassName();
$trace = "Operator '${qtiName}' processed.";
$this->traceOperator($processor, $result);
if ($expression !== $this->getComponent()) {
$this->operands->push($result);
}
} else {
// Simple expression, process it.
$processor = $this->expressionProcessorFactory->createProcessor($expression);
$processor->setState($this->getContext());
$result = $processor->process();
$this->operands->push($result);
// trace the processing of the expression.
$qtiName = $expression->getQtiClassName();
$trace = "Expression '${qtiName}' processed.";
$this->traceExpression($processor, $result);
}
}
return $result;
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"expression",
"=",
"$",
"this",
"->",
"getComponent",
"(",
")",
";",
"// Reset trail and marker arrays.",
"$",
"this",
"->",
"trail",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"marker",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"pushTrail",
"(",
"$",
"expression",
")",
";",
"while",
"(",
"count",
"(",
"$",
"this",
"->",
"getTrail",
"(",
")",
")",
">",
"0",
")",
"{",
"$",
"expression",
"=",
"$",
"this",
"->",
"popTrail",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isMarked",
"(",
"$",
"expression",
")",
"===",
"false",
"&&",
"$",
"expression",
"instanceof",
"Operator",
")",
"{",
"// This is an operator, first pass. Repush for a second pass.",
"$",
"this",
"->",
"mark",
"(",
"$",
"expression",
")",
";",
"$",
"this",
"->",
"pushTrail",
"(",
"$",
"expression",
")",
";",
"$",
"this",
"->",
"pushTrail",
"(",
"$",
"expression",
"->",
"getExpressions",
"(",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"isMarked",
"(",
"$",
"expression",
")",
")",
"{",
"// Operator, second pass. Process it.",
"$",
"popCount",
"=",
"count",
"(",
"$",
"expression",
"->",
"getExpressions",
"(",
")",
")",
";",
"$",
"operands",
"=",
"$",
"this",
"->",
"operands",
"->",
"pop",
"(",
"$",
"popCount",
")",
";",
"$",
"processor",
"=",
"$",
"this",
"->",
"operatorProcessorFactory",
"->",
"createProcessor",
"(",
"$",
"expression",
",",
"$",
"operands",
")",
";",
"$",
"processor",
"->",
"setState",
"(",
"$",
"this",
"->",
"getContext",
"(",
")",
")",
";",
"$",
"result",
"=",
"$",
"processor",
"->",
"process",
"(",
")",
";",
"// trace the processing of the operator.",
"$",
"qtiName",
"=",
"$",
"expression",
"->",
"getQtiClassName",
"(",
")",
";",
"$",
"trace",
"=",
"\"Operator '${qtiName}' processed.\"",
";",
"$",
"this",
"->",
"traceOperator",
"(",
"$",
"processor",
",",
"$",
"result",
")",
";",
"if",
"(",
"$",
"expression",
"!==",
"$",
"this",
"->",
"getComponent",
"(",
")",
")",
"{",
"$",
"this",
"->",
"operands",
"->",
"push",
"(",
"$",
"result",
")",
";",
"}",
"}",
"else",
"{",
"// Simple expression, process it.",
"$",
"processor",
"=",
"$",
"this",
"->",
"expressionProcessorFactory",
"->",
"createProcessor",
"(",
"$",
"expression",
")",
";",
"$",
"processor",
"->",
"setState",
"(",
"$",
"this",
"->",
"getContext",
"(",
")",
")",
";",
"$",
"result",
"=",
"$",
"processor",
"->",
"process",
"(",
")",
";",
"$",
"this",
"->",
"operands",
"->",
"push",
"(",
"$",
"result",
")",
";",
"// trace the processing of the expression.",
"$",
"qtiName",
"=",
"$",
"expression",
"->",
"getQtiClassName",
"(",
")",
";",
"$",
"trace",
"=",
"\"Expression '${qtiName}' processed.\"",
";",
"$",
"this",
"->",
"traceExpression",
"(",
"$",
"processor",
",",
"$",
"result",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Process the current Expression object according to the current
execution context.
@throws \qtism\runtime\expressions\ExpressionProcessingException|\qtism\runtime\expressions\operators\OperatorProcessingException If an error occurs during the Expression processing. | [
"Process",
"the",
"current",
"Expression",
"object",
"according",
"to",
"the",
"current",
"execution",
"context",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/ExpressionEngine.php#L210-L261 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/ExpressionEngine.php | ExpressionEngine.traceExpression | protected function traceExpression(ExpressionProcessor $processor, $result)
{
$qtiClassName = $processor->getExpression()->getQtiClassName();
$this->trace("${qtiClassName} [${result}]");
} | php | protected function traceExpression(ExpressionProcessor $processor, $result)
{
$qtiClassName = $processor->getExpression()->getQtiClassName();
$this->trace("${qtiClassName} [${result}]");
} | [
"protected",
"function",
"traceExpression",
"(",
"ExpressionProcessor",
"$",
"processor",
",",
"$",
"result",
")",
"{",
"$",
"qtiClassName",
"=",
"$",
"processor",
"->",
"getExpression",
"(",
")",
"->",
"getQtiClassName",
"(",
")",
";",
"$",
"this",
"->",
"trace",
"(",
"\"${qtiClassName} [${result}]\"",
")",
";",
"}"
] | Trace a given Expression $processor execution.
@param \qtism\runtime\expressions\ExpressionProcessor $processor The processor that undertook the processing.
@param mixed $result The result of the processing. | [
"Trace",
"a",
"given",
"Expression",
"$processor",
"execution",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/ExpressionEngine.php#L269-L273 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/ExpressionEngine.php | ExpressionEngine.traceOperator | protected function traceOperator(OperatorProcessor $processor, $result)
{
$stringOperands = array();
foreach ($processor->getOperands() as $operand) {
$stringOperands[] = '' . $operand;
}
$qtiClassName = $processor->getExpression()->getQtiClassName();
$msg = "${qtiClassName}(" . implode(', ', $stringOperands) . ") [${result}]";
$this->trace($msg);
} | php | protected function traceOperator(OperatorProcessor $processor, $result)
{
$stringOperands = array();
foreach ($processor->getOperands() as $operand) {
$stringOperands[] = '' . $operand;
}
$qtiClassName = $processor->getExpression()->getQtiClassName();
$msg = "${qtiClassName}(" . implode(', ', $stringOperands) . ") [${result}]";
$this->trace($msg);
} | [
"protected",
"function",
"traceOperator",
"(",
"OperatorProcessor",
"$",
"processor",
",",
"$",
"result",
")",
"{",
"$",
"stringOperands",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"processor",
"->",
"getOperands",
"(",
")",
"as",
"$",
"operand",
")",
"{",
"$",
"stringOperands",
"[",
"]",
"=",
"''",
".",
"$",
"operand",
";",
"}",
"$",
"qtiClassName",
"=",
"$",
"processor",
"->",
"getExpression",
"(",
")",
"->",
"getQtiClassName",
"(",
")",
";",
"$",
"msg",
"=",
"\"${qtiClassName}(\"",
".",
"implode",
"(",
"', '",
",",
"$",
"stringOperands",
")",
".",
"\") [${result}]\"",
";",
"$",
"this",
"->",
"trace",
"(",
"$",
"msg",
")",
";",
"}"
] | Trace a given Operator $processor execution.
@param \qtism\runtime\expressions\operators\OperatorProcessor $processor The processor that undertook the processing.
@param mixed $result The result of the processing. | [
"Trace",
"a",
"given",
"Operator",
"$processor",
"execution",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/ExpressionEngine.php#L281-L292 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/LteProcessor.php | LteProcessor.process | public function process()
{
$operands = $this->getOperands();
if ($operands->containsNull() === true) {
return null;
}
if ($operands->exclusivelySingle() === false) {
$msg = "The Lte operator only accepts operands with a single cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
if ($operands->exclusivelyNumeric() === false) {
$msg = "The Lte operator only accepts operands with a float or integer baseType.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
}
return new QtiBoolean($operands[0]->getValue() <= $operands[1]->getValue());
} | php | public function process()
{
$operands = $this->getOperands();
if ($operands->containsNull() === true) {
return null;
}
if ($operands->exclusivelySingle() === false) {
$msg = "The Lte operator only accepts operands with a single cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
if ($operands->exclusivelyNumeric() === false) {
$msg = "The Lte operator only accepts operands with a float or integer baseType.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
}
return new QtiBoolean($operands[0]->getValue() <= $operands[1]->getValue());
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"operands",
"=",
"$",
"this",
"->",
"getOperands",
"(",
")",
";",
"if",
"(",
"$",
"operands",
"->",
"containsNull",
"(",
")",
"===",
"true",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"operands",
"->",
"exclusivelySingle",
"(",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The Lte operator only accepts operands with a single cardinality.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_CARDINALITY",
")",
";",
"}",
"if",
"(",
"$",
"operands",
"->",
"exclusivelyNumeric",
"(",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The Lte operator only accepts operands with a float or integer baseType.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_BASETYPE",
")",
";",
"}",
"return",
"new",
"QtiBoolean",
"(",
"$",
"operands",
"[",
"0",
"]",
"->",
"getValue",
"(",
")",
"<=",
"$",
"operands",
"[",
"1",
"]",
"->",
"getValue",
"(",
")",
")",
";",
"}"
] | Process the Lte operator.
@return boolean|null Whether the first sub-expression is numerically less than or equal to the second or NULL if either sub-expression is NULL.
@throws \qtism\runtime\expressions\operators\OperatorProcessingException | [
"Process",
"the",
"Lte",
"operator",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/LteProcessor.php#L53-L72 |
oat-sa/qti-sdk | src/qtism/common/datatypes/files/FileSystemFile.php | FileSystemFile.getData | public function getData()
{
$fp = $this->getStream();
$data = '';
while (feof($fp) === false) {
$data .= fread($fp, self::CHUNK_SIZE);
}
@fclose($fp);
return $data;
} | php | public function getData()
{
$fp = $this->getStream();
$data = '';
while (feof($fp) === false) {
$data .= fread($fp, self::CHUNK_SIZE);
}
@fclose($fp);
return $data;
} | [
"public",
"function",
"getData",
"(",
")",
"{",
"$",
"fp",
"=",
"$",
"this",
"->",
"getStream",
"(",
")",
";",
"$",
"data",
"=",
"''",
";",
"while",
"(",
"feof",
"(",
"$",
"fp",
")",
"===",
"false",
")",
"{",
"$",
"data",
".=",
"fread",
"(",
"$",
"fp",
",",
"self",
"::",
"CHUNK_SIZE",
")",
";",
"}",
"@",
"fclose",
"(",
"$",
"fp",
")",
";",
"return",
"$",
"data",
";",
"}"
] | Get the sequence of bytes composing the content of the file.
@throws \RuntimeException If the data cannot be retrieved. | [
"Get",
"the",
"sequence",
"of",
"bytes",
"composing",
"the",
"content",
"of",
"the",
"file",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/datatypes/files/FileSystemFile.php#L164-L176 |
oat-sa/qti-sdk | src/qtism/common/datatypes/files/FileSystemFile.php | FileSystemFile.getStream | public function getStream()
{
$fp = @fopen($this->getPath(), 'rb');
if ($fp === false) {
$msg = "Cannot retrieve QTI File Stream from '" . $this->getPath() . "'.";
throw new RuntimeException($msg);
}
$len = current(unpack('S', fread($fp, 2)));
fseek($fp, $len, SEEK_CUR);
$len = current(unpack('S', fread($fp, 2)));
fseek($fp, $len, SEEK_CUR);
return $fp;
} | php | public function getStream()
{
$fp = @fopen($this->getPath(), 'rb');
if ($fp === false) {
$msg = "Cannot retrieve QTI File Stream from '" . $this->getPath() . "'.";
throw new RuntimeException($msg);
}
$len = current(unpack('S', fread($fp, 2)));
fseek($fp, $len, SEEK_CUR);
$len = current(unpack('S', fread($fp, 2)));
fseek($fp, $len, SEEK_CUR);
return $fp;
} | [
"public",
"function",
"getStream",
"(",
")",
"{",
"$",
"fp",
"=",
"@",
"fopen",
"(",
"$",
"this",
"->",
"getPath",
"(",
")",
",",
"'rb'",
")",
";",
"if",
"(",
"$",
"fp",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"Cannot retrieve QTI File Stream from '\"",
".",
"$",
"this",
"->",
"getPath",
"(",
")",
".",
"\"'.\"",
";",
"throw",
"new",
"RuntimeException",
"(",
"$",
"msg",
")",
";",
"}",
"$",
"len",
"=",
"current",
"(",
"unpack",
"(",
"'S'",
",",
"fread",
"(",
"$",
"fp",
",",
"2",
")",
")",
")",
";",
"fseek",
"(",
"$",
"fp",
",",
"$",
"len",
",",
"SEEK_CUR",
")",
";",
"$",
"len",
"=",
"current",
"(",
"unpack",
"(",
"'S'",
",",
"fread",
"(",
"$",
"fp",
",",
"2",
")",
")",
")",
";",
"fseek",
"(",
"$",
"fp",
",",
"$",
"len",
",",
"SEEK_CUR",
")",
";",
"return",
"$",
"fp",
";",
"}"
] | Get a stream resource on the file.
@throws \RuntimeException If the stream on the file cannot be open.
@return resource An open stream. | [
"Get",
"a",
"stream",
"resource",
"on",
"the",
"file",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/datatypes/files/FileSystemFile.php#L184-L200 |
oat-sa/qti-sdk | src/qtism/common/datatypes/files/FileSystemFile.php | FileSystemFile.createFromExistingFile | public static function createFromExistingFile($source, $destination, $mimeType, $withFilename = true)
{
if (is_file($source) === true) {
if (is_readable($source) === true) {
// Should we build the path to $destination?
$pathinfo = pathinfo($destination);
if (is_dir($pathinfo['dirname']) === false) {
if (($mkdir = @mkdir($pathinfo['dirname'], '0770', true)) === false) {
$msg = "Unable to create destination directory at '" . $pathinfo['dirname'] . "'.";
throw new RuntimeException($msg);
}
}
$pathinfo = pathinfo($source);
$filename = ($withFilename === true) ? ($pathinfo['filename'] . '.' . $pathinfo['extension']) : strval($withFilename);
// --- We store the file name and the mimetype in the file itself.
// filename.
$len = strlen($filename);
$packedFilename = pack('S', $len) . $filename;
// MIME type.
$len = strlen($mimeType);
$packedMimeType = pack('S', $len) . $mimeType;
$finalSize = strlen($packedFilename) + strlen($packedMimeType) + filesize($source);
$sourceFp = @fopen($source, 'r');
if ($sourceFp === false) {
throw new RuntimeException("Source file '${source}' could not be open.");
}
$destinationFp = @fopen($destination, 'w');
if ($destinationFp === false) {
throw new RuntimeException("Destination file '${destination}' could not be open.");
}
fwrite($destinationFp, $packedFilename . $packedMimeType);
// do not eat up memory ;)!
while (ftell($destinationFp) < $finalSize) {
$buffer = fread($sourceFp, self::CHUNK_SIZE);
fwrite($destinationFp, $buffer);
}
@fclose($sourceFp);
@fclose($destinationFp);
return new static($destination);
} else {
// Source file not readable.
$msg = "File '${source}' found but not readable.";
throw new RuntimeException($msg);
}
} else {
// Source file not found.
$msg = "Unable to find source file at '${source}'.";
throw new RuntimeException($msg);
}
} | php | public static function createFromExistingFile($source, $destination, $mimeType, $withFilename = true)
{
if (is_file($source) === true) {
if (is_readable($source) === true) {
// Should we build the path to $destination?
$pathinfo = pathinfo($destination);
if (is_dir($pathinfo['dirname']) === false) {
if (($mkdir = @mkdir($pathinfo['dirname'], '0770', true)) === false) {
$msg = "Unable to create destination directory at '" . $pathinfo['dirname'] . "'.";
throw new RuntimeException($msg);
}
}
$pathinfo = pathinfo($source);
$filename = ($withFilename === true) ? ($pathinfo['filename'] . '.' . $pathinfo['extension']) : strval($withFilename);
// --- We store the file name and the mimetype in the file itself.
// filename.
$len = strlen($filename);
$packedFilename = pack('S', $len) . $filename;
// MIME type.
$len = strlen($mimeType);
$packedMimeType = pack('S', $len) . $mimeType;
$finalSize = strlen($packedFilename) + strlen($packedMimeType) + filesize($source);
$sourceFp = @fopen($source, 'r');
if ($sourceFp === false) {
throw new RuntimeException("Source file '${source}' could not be open.");
}
$destinationFp = @fopen($destination, 'w');
if ($destinationFp === false) {
throw new RuntimeException("Destination file '${destination}' could not be open.");
}
fwrite($destinationFp, $packedFilename . $packedMimeType);
// do not eat up memory ;)!
while (ftell($destinationFp) < $finalSize) {
$buffer = fread($sourceFp, self::CHUNK_SIZE);
fwrite($destinationFp, $buffer);
}
@fclose($sourceFp);
@fclose($destinationFp);
return new static($destination);
} else {
// Source file not readable.
$msg = "File '${source}' found but not readable.";
throw new RuntimeException($msg);
}
} else {
// Source file not found.
$msg = "Unable to find source file at '${source}'.";
throw new RuntimeException($msg);
}
} | [
"public",
"static",
"function",
"createFromExistingFile",
"(",
"$",
"source",
",",
"$",
"destination",
",",
"$",
"mimeType",
",",
"$",
"withFilename",
"=",
"true",
")",
"{",
"if",
"(",
"is_file",
"(",
"$",
"source",
")",
"===",
"true",
")",
"{",
"if",
"(",
"is_readable",
"(",
"$",
"source",
")",
"===",
"true",
")",
"{",
"// Should we build the path to $destination?",
"$",
"pathinfo",
"=",
"pathinfo",
"(",
"$",
"destination",
")",
";",
"if",
"(",
"is_dir",
"(",
"$",
"pathinfo",
"[",
"'dirname'",
"]",
")",
"===",
"false",
")",
"{",
"if",
"(",
"(",
"$",
"mkdir",
"=",
"@",
"mkdir",
"(",
"$",
"pathinfo",
"[",
"'dirname'",
"]",
",",
"'0770'",
",",
"true",
")",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"Unable to create destination directory at '\"",
".",
"$",
"pathinfo",
"[",
"'dirname'",
"]",
".",
"\"'.\"",
";",
"throw",
"new",
"RuntimeException",
"(",
"$",
"msg",
")",
";",
"}",
"}",
"$",
"pathinfo",
"=",
"pathinfo",
"(",
"$",
"source",
")",
";",
"$",
"filename",
"=",
"(",
"$",
"withFilename",
"===",
"true",
")",
"?",
"(",
"$",
"pathinfo",
"[",
"'filename'",
"]",
".",
"'.'",
".",
"$",
"pathinfo",
"[",
"'extension'",
"]",
")",
":",
"strval",
"(",
"$",
"withFilename",
")",
";",
"// --- We store the file name and the mimetype in the file itself.",
"// filename.",
"$",
"len",
"=",
"strlen",
"(",
"$",
"filename",
")",
";",
"$",
"packedFilename",
"=",
"pack",
"(",
"'S'",
",",
"$",
"len",
")",
".",
"$",
"filename",
";",
"// MIME type.",
"$",
"len",
"=",
"strlen",
"(",
"$",
"mimeType",
")",
";",
"$",
"packedMimeType",
"=",
"pack",
"(",
"'S'",
",",
"$",
"len",
")",
".",
"$",
"mimeType",
";",
"$",
"finalSize",
"=",
"strlen",
"(",
"$",
"packedFilename",
")",
"+",
"strlen",
"(",
"$",
"packedMimeType",
")",
"+",
"filesize",
"(",
"$",
"source",
")",
";",
"$",
"sourceFp",
"=",
"@",
"fopen",
"(",
"$",
"source",
",",
"'r'",
")",
";",
"if",
"(",
"$",
"sourceFp",
"===",
"false",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Source file '${source}' could not be open.\"",
")",
";",
"}",
"$",
"destinationFp",
"=",
"@",
"fopen",
"(",
"$",
"destination",
",",
"'w'",
")",
";",
"if",
"(",
"$",
"destinationFp",
"===",
"false",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Destination file '${destination}' could not be open.\"",
")",
";",
"}",
"fwrite",
"(",
"$",
"destinationFp",
",",
"$",
"packedFilename",
".",
"$",
"packedMimeType",
")",
";",
"// do not eat up memory ;)!",
"while",
"(",
"ftell",
"(",
"$",
"destinationFp",
")",
"<",
"$",
"finalSize",
")",
"{",
"$",
"buffer",
"=",
"fread",
"(",
"$",
"sourceFp",
",",
"self",
"::",
"CHUNK_SIZE",
")",
";",
"fwrite",
"(",
"$",
"destinationFp",
",",
"$",
"buffer",
")",
";",
"}",
"@",
"fclose",
"(",
"$",
"sourceFp",
")",
";",
"@",
"fclose",
"(",
"$",
"destinationFp",
")",
";",
"return",
"new",
"static",
"(",
"$",
"destination",
")",
";",
"}",
"else",
"{",
"// Source file not readable.",
"$",
"msg",
"=",
"\"File '${source}' found but not readable.\"",
";",
"throw",
"new",
"RuntimeException",
"(",
"$",
"msg",
")",
";",
"}",
"}",
"else",
"{",
"// Source file not found.",
"$",
"msg",
"=",
"\"Unable to find source file at '${source}'.\"",
";",
"throw",
"new",
"RuntimeException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Create a PersistentFile object from an existing file.
@param string $source The source path.
@param string $destination Where the file resulting from $source will be stored.
@param string $mimeType The MIME type of the file.
@param mixed $withFilename Whether or not consider the $source's filename to be the $destination's file name. Give true to use the current file name. Give a string to select a different one. Default is true.
@throws \RuntimeException If something wrong happens.
@return \qtism\common\datatypes\files\FileSystemFile | [
"Create",
"a",
"PersistentFile",
"object",
"from",
"an",
"existing",
"file",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/datatypes/files/FileSystemFile.php#L212-L276 |
oat-sa/qti-sdk | src/qtism/common/datatypes/files/FileSystemFile.php | FileSystemFile.createFromData | public static function createFromData($data, $destination, $mimeType, $filename = '')
{
$tmp = tempnam('/tmp', 'qtism');
file_put_contents($tmp, $data);
$file = self::createFromExistingFile($tmp, $destination, $mimeType, $filename);
unlink($tmp);
return $file;
} | php | public static function createFromData($data, $destination, $mimeType, $filename = '')
{
$tmp = tempnam('/tmp', 'qtism');
file_put_contents($tmp, $data);
$file = self::createFromExistingFile($tmp, $destination, $mimeType, $filename);
unlink($tmp);
return $file;
} | [
"public",
"static",
"function",
"createFromData",
"(",
"$",
"data",
",",
"$",
"destination",
",",
"$",
"mimeType",
",",
"$",
"filename",
"=",
"''",
")",
"{",
"$",
"tmp",
"=",
"tempnam",
"(",
"'/tmp'",
",",
"'qtism'",
")",
";",
"file_put_contents",
"(",
"$",
"tmp",
",",
"$",
"data",
")",
";",
"$",
"file",
"=",
"self",
"::",
"createFromExistingFile",
"(",
"$",
"tmp",
",",
"$",
"destination",
",",
"$",
"mimeType",
",",
"$",
"filename",
")",
";",
"unlink",
"(",
"$",
"tmp",
")",
";",
"return",
"$",
"file",
";",
"}"
] | Create a File from existing data.
@param string $data
@param string $destination
@param string $mimeType
@param string $filename
@return \qtism\common\datatypes\files\FileSystemFile | [
"Create",
"a",
"File",
"from",
"existing",
"data",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/datatypes/files/FileSystemFile.php#L287-L296 |
oat-sa/qti-sdk | src/qtism/common/datatypes/files/FileSystemFile.php | FileSystemFile.equals | public function equals($obj)
{
if ($obj instanceof QtiFile) {
if ($this->getFilename() !== $obj->getFilename()) {
return false;
} elseif ($this->getMimeType() !== $obj->getMimeType()) {
return false;
} else {
// We have to check the content of the file.
$myStream = $this->getStream();
$objStream = $obj->getStream();
while (feof($myStream) === false && feof($objStream) === false) {
$myChunk = fread($myStream, self::CHUNK_SIZE);
$objChjunk = fread($objStream, self::CHUNK_SIZE);
if ($myChunk !== $objChjunk) {
@fclose($myStream);
@fclose($objStream);
return false;
}
}
@fclose($myStream);
@fclose($objStream);
return true;
}
}
return false;
} | php | public function equals($obj)
{
if ($obj instanceof QtiFile) {
if ($this->getFilename() !== $obj->getFilename()) {
return false;
} elseif ($this->getMimeType() !== $obj->getMimeType()) {
return false;
} else {
// We have to check the content of the file.
$myStream = $this->getStream();
$objStream = $obj->getStream();
while (feof($myStream) === false && feof($objStream) === false) {
$myChunk = fread($myStream, self::CHUNK_SIZE);
$objChjunk = fread($objStream, self::CHUNK_SIZE);
if ($myChunk !== $objChjunk) {
@fclose($myStream);
@fclose($objStream);
return false;
}
}
@fclose($myStream);
@fclose($objStream);
return true;
}
}
return false;
} | [
"public",
"function",
"equals",
"(",
"$",
"obj",
")",
"{",
"if",
"(",
"$",
"obj",
"instanceof",
"QtiFile",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getFilename",
"(",
")",
"!==",
"$",
"obj",
"->",
"getFilename",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"getMimeType",
"(",
")",
"!==",
"$",
"obj",
"->",
"getMimeType",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"// We have to check the content of the file.",
"$",
"myStream",
"=",
"$",
"this",
"->",
"getStream",
"(",
")",
";",
"$",
"objStream",
"=",
"$",
"obj",
"->",
"getStream",
"(",
")",
";",
"while",
"(",
"feof",
"(",
"$",
"myStream",
")",
"===",
"false",
"&&",
"feof",
"(",
"$",
"objStream",
")",
"===",
"false",
")",
"{",
"$",
"myChunk",
"=",
"fread",
"(",
"$",
"myStream",
",",
"self",
"::",
"CHUNK_SIZE",
")",
";",
"$",
"objChjunk",
"=",
"fread",
"(",
"$",
"objStream",
",",
"self",
"::",
"CHUNK_SIZE",
")",
";",
"if",
"(",
"$",
"myChunk",
"!==",
"$",
"objChjunk",
")",
"{",
"@",
"fclose",
"(",
"$",
"myStream",
")",
";",
"@",
"fclose",
"(",
"$",
"objStream",
")",
";",
"return",
"false",
";",
"}",
"}",
"@",
"fclose",
"(",
"$",
"myStream",
")",
";",
"@",
"fclose",
"(",
"$",
"objStream",
")",
";",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Whether or not two File objects are equals. Two File values
are considered to be identical if they have the same file name,
mime-type and data.
@return boolean | [
"Whether",
"or",
"not",
"two",
"File",
"objects",
"are",
"equals",
".",
"Two",
"File",
"values",
"are",
"considered",
"to",
"be",
"identical",
"if",
"they",
"have",
"the",
"same",
"file",
"name",
"mime",
"-",
"type",
"and",
"data",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/datatypes/files/FileSystemFile.php#L347-L379 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/DivideProcessor.php | DivideProcessor.process | public function process()
{
$operands = $this->getOperands();
if ($operands->containsNull() === true) {
return null;
}
if ($operands->exclusivelySingle() === false) {
$msg = "The Divide operator only accepts operands with a single cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
if ($operands->exclusivelyNumeric() === false) {
$msg = "The Divide operator only accepts operands with a baseType of integer or float.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
}
$operand1 = $operands[0];
$operand2 = $operands[1];
if ($operand2->getValue() == 0) {
return null;
}
$divide = floatval($operand1->getValue() / $operand2->getValue());
return is_nan($divide) ? null : new QtiFloat($divide);
} | php | public function process()
{
$operands = $this->getOperands();
if ($operands->containsNull() === true) {
return null;
}
if ($operands->exclusivelySingle() === false) {
$msg = "The Divide operator only accepts operands with a single cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
if ($operands->exclusivelyNumeric() === false) {
$msg = "The Divide operator only accepts operands with a baseType of integer or float.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
}
$operand1 = $operands[0];
$operand2 = $operands[1];
if ($operand2->getValue() == 0) {
return null;
}
$divide = floatval($operand1->getValue() / $operand2->getValue());
return is_nan($divide) ? null : new QtiFloat($divide);
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"operands",
"=",
"$",
"this",
"->",
"getOperands",
"(",
")",
";",
"if",
"(",
"$",
"operands",
"->",
"containsNull",
"(",
")",
"===",
"true",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"operands",
"->",
"exclusivelySingle",
"(",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The Divide operator only accepts operands with a single cardinality.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_CARDINALITY",
")",
";",
"}",
"if",
"(",
"$",
"operands",
"->",
"exclusivelyNumeric",
"(",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The Divide operator only accepts operands with a baseType of integer or float.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_BASETYPE",
")",
";",
"}",
"$",
"operand1",
"=",
"$",
"operands",
"[",
"0",
"]",
";",
"$",
"operand2",
"=",
"$",
"operands",
"[",
"1",
"]",
";",
"if",
"(",
"$",
"operand2",
"->",
"getValue",
"(",
")",
"==",
"0",
")",
"{",
"return",
"null",
";",
"}",
"$",
"divide",
"=",
"floatval",
"(",
"$",
"operand1",
"->",
"getValue",
"(",
")",
"/",
"$",
"operand2",
"->",
"getValue",
"(",
")",
")",
";",
"return",
"is_nan",
"(",
"$",
"divide",
")",
"?",
"null",
":",
"new",
"QtiFloat",
"(",
"$",
"divide",
")",
";",
"}"
] | Process the Divide operator.
@return float|null A float value that corresponds to the first expression divided by the second or NULL if either of the sub-expressions is NULL or the result is outside the value set defined by float.
@throws \qtism\runtime\expressions\operators\OperatorProcessingException | [
"Process",
"the",
"Divide",
"operator",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/DivideProcessor.php#L56-L84 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/MathOperatorMarshaller.php | MathOperatorMarshaller.unmarshallChildrenKnown | protected function unmarshallChildrenKnown(DOMElement $element, QtiComponentCollection $children)
{
if (($name = $this->getDOMElementAttributeAs($element, 'name')) !== null) {
$object = new MathOperator($children, MathFunctions::getConstantByName($name));
return $object;
} else {
$msg = "The mandatory attribute 'name' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} | php | protected function unmarshallChildrenKnown(DOMElement $element, QtiComponentCollection $children)
{
if (($name = $this->getDOMElementAttributeAs($element, 'name')) !== null) {
$object = new MathOperator($children, MathFunctions::getConstantByName($name));
return $object;
} else {
$msg = "The mandatory attribute 'name' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} | [
"protected",
"function",
"unmarshallChildrenKnown",
"(",
"DOMElement",
"$",
"element",
",",
"QtiComponentCollection",
"$",
"children",
")",
"{",
"if",
"(",
"(",
"$",
"name",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'name'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"object",
"=",
"new",
"MathOperator",
"(",
"$",
"children",
",",
"MathFunctions",
"::",
"getConstantByName",
"(",
"$",
"name",
")",
")",
";",
"return",
"$",
"object",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory attribute 'name' is missing from element '\"",
".",
"$",
"element",
"->",
"localName",
".",
"\"'.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}"
] | Unmarshall a QTI mathOperator operator element into a MathsOperator object.
@param \DOMElement $element The mathOperator element to unmarshall.
@param \qtism\data\QtiComponentCollection $children A collection containing the child Expression objects composing the Operator.
@return \qtism\data\QtiComponent A MathOperator object.
@throws \UnmarshallingException | [
"Unmarshall",
"a",
"QTI",
"mathOperator",
"operator",
"element",
"into",
"a",
"MathsOperator",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/MathOperatorMarshaller.php#L68-L79 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/RandomFloatProcessor.php | RandomFloatProcessor.process | public function process()
{
$expr = $this->getExpression();
$min = $expr->getMin();
$max = $expr->getMax();
$state = $this->getState();
$min = (is_float($min)) ? $min : $state[Utils::sanitizeVariableRef($min)]->getValue();
$max = (is_float($max)) ? $max : $state[Utils::sanitizeVariableRef($max)]->getValue();
if (is_float($min) && is_float($max)) {
if ($min <= $max) {
return new QtiFloat(($min + lcg_value() * (abs($max - $min))));
} else {
$msg = "'min':'${min}' is greater than 'max':'${max}'.";
throw new ExpressionProcessingException($msg, $this, ExpressionProcessingException::LOGIC_ERROR);
}
} else {
$msg = "At least one of the following values is not a float: 'min', 'max'.";
throw new ExpressionProcessingException($msg, $this, ExpressionProcessingException::WRONG_VARIABLE_BASETYPE);
}
} | php | public function process()
{
$expr = $this->getExpression();
$min = $expr->getMin();
$max = $expr->getMax();
$state = $this->getState();
$min = (is_float($min)) ? $min : $state[Utils::sanitizeVariableRef($min)]->getValue();
$max = (is_float($max)) ? $max : $state[Utils::sanitizeVariableRef($max)]->getValue();
if (is_float($min) && is_float($max)) {
if ($min <= $max) {
return new QtiFloat(($min + lcg_value() * (abs($max - $min))));
} else {
$msg = "'min':'${min}' is greater than 'max':'${max}'.";
throw new ExpressionProcessingException($msg, $this, ExpressionProcessingException::LOGIC_ERROR);
}
} else {
$msg = "At least one of the following values is not a float: 'min', 'max'.";
throw new ExpressionProcessingException($msg, $this, ExpressionProcessingException::WRONG_VARIABLE_BASETYPE);
}
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"expr",
"=",
"$",
"this",
"->",
"getExpression",
"(",
")",
";",
"$",
"min",
"=",
"$",
"expr",
"->",
"getMin",
"(",
")",
";",
"$",
"max",
"=",
"$",
"expr",
"->",
"getMax",
"(",
")",
";",
"$",
"state",
"=",
"$",
"this",
"->",
"getState",
"(",
")",
";",
"$",
"min",
"=",
"(",
"is_float",
"(",
"$",
"min",
")",
")",
"?",
"$",
"min",
":",
"$",
"state",
"[",
"Utils",
"::",
"sanitizeVariableRef",
"(",
"$",
"min",
")",
"]",
"->",
"getValue",
"(",
")",
";",
"$",
"max",
"=",
"(",
"is_float",
"(",
"$",
"max",
")",
")",
"?",
"$",
"max",
":",
"$",
"state",
"[",
"Utils",
"::",
"sanitizeVariableRef",
"(",
"$",
"max",
")",
"]",
"->",
"getValue",
"(",
")",
";",
"if",
"(",
"is_float",
"(",
"$",
"min",
")",
"&&",
"is_float",
"(",
"$",
"max",
")",
")",
"{",
"if",
"(",
"$",
"min",
"<=",
"$",
"max",
")",
"{",
"return",
"new",
"QtiFloat",
"(",
"(",
"$",
"min",
"+",
"lcg_value",
"(",
")",
"*",
"(",
"abs",
"(",
"$",
"max",
"-",
"$",
"min",
")",
")",
")",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"'min':'${min}' is greater than 'max':'${max}'.\"",
";",
"throw",
"new",
"ExpressionProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"ExpressionProcessingException",
"::",
"LOGIC_ERROR",
")",
";",
"}",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"At least one of the following values is not a float: 'min', 'max'.\"",
";",
"throw",
"new",
"ExpressionProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"ExpressionProcessingException",
"::",
"WRONG_VARIABLE_BASETYPE",
")",
";",
"}",
"}"
] | Process the RandomFloat expression.
* Throws an ExpressionProcessingException if 'min' is greater than 'max'.
@return float A Random float value.
@throws \qtism\runtime\expressions\ExpressionProcessingException | [
"Process",
"the",
"RandomFloat",
"expression",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/RandomFloatProcessor.php#L50-L73 |
oat-sa/qti-sdk | src/qtism/runtime/processing/OutcomeProcessingEngine.php | OutcomeProcessingEngine.setComponent | public function setComponent(QtiComponent $outcomeProcessing)
{
if ($outcomeProcessing instanceof OutcomeProcessing) {
parent::setComponent($outcomeProcessing);
} else {
$msg = "The OutcomeProcessingEngine class only accepts OutcomeProcessing objects to be executed.";
throw new InvalidArgumentException($msg);
}
} | php | public function setComponent(QtiComponent $outcomeProcessing)
{
if ($outcomeProcessing instanceof OutcomeProcessing) {
parent::setComponent($outcomeProcessing);
} else {
$msg = "The OutcomeProcessingEngine class only accepts OutcomeProcessing objects to be executed.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setComponent",
"(",
"QtiComponent",
"$",
"outcomeProcessing",
")",
"{",
"if",
"(",
"$",
"outcomeProcessing",
"instanceof",
"OutcomeProcessing",
")",
"{",
"parent",
"::",
"setComponent",
"(",
"$",
"outcomeProcessing",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The OutcomeProcessingEngine class only accepts OutcomeProcessing objects to be executed.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the OutcomeProcessing object to be executed by the engine depending
on the current context.
@param \qtism\data\QtiComponent $outcomeProcessing An OutcomeProcessing object.
@throws \InvalidArgumentException If $outcomeProcessing is not An OutcomeProcessing object. | [
"Set",
"the",
"OutcomeProcessing",
"object",
"to",
"be",
"executed",
"by",
"the",
"engine",
"depending",
"on",
"the",
"current",
"context",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/processing/OutcomeProcessingEngine.php#L90-L98 |
oat-sa/qti-sdk | src/qtism/data/Utils.php | Utils.checkRecursion | private static function checkRecursion($component, $sections)
{
$sectparent = null;
foreach ($sections as $key => $sect) {
if (in_array($component, $sect->getSectionParts()->getArrayCopy())) {
$sectparent = $sect;
}
if ($sect->getIdentifier() == $component->getIdentifier()) {
break;
}
}
return $sectparent;
} | php | private static function checkRecursion($component, $sections)
{
$sectparent = null;
foreach ($sections as $key => $sect) {
if (in_array($component, $sect->getSectionParts()->getArrayCopy())) {
$sectparent = $sect;
}
if ($sect->getIdentifier() == $component->getIdentifier()) {
break;
}
}
return $sectparent;
} | [
"private",
"static",
"function",
"checkRecursion",
"(",
"$",
"component",
",",
"$",
"sections",
")",
"{",
"$",
"sectparent",
"=",
"null",
";",
"foreach",
"(",
"$",
"sections",
"as",
"$",
"key",
"=>",
"$",
"sect",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"component",
",",
"$",
"sect",
"->",
"getSectionParts",
"(",
")",
"->",
"getArrayCopy",
"(",
")",
")",
")",
"{",
"$",
"sectparent",
"=",
"$",
"sect",
";",
"}",
"if",
"(",
"$",
"sect",
"->",
"getIdentifier",
"(",
")",
"==",
"$",
"component",
"->",
"getIdentifier",
"(",
")",
")",
"{",
"break",
";",
"}",
"}",
"return",
"$",
"sectparent",
";",
"}"
] | Checks if the current section has a parent, and returns it, if any.
Gets the list of sections of this AssessmentTest, and checks if any has the AssessmentSection
set as parameter in its components. If some has, we keep the last section found (to take the
closest parent).
@param $component AssessmentSection The section from which we want to find the parent.
@param $sections AssessmentSectionCollection The collection of all sections in this AssessmentTest.
@return AssessmentSection|null The parent of the AssessmentSection set as parameter, if any. | [
"Checks",
"if",
"the",
"current",
"section",
"has",
"a",
"parent",
"and",
"returns",
"it",
"if",
"any",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/Utils.php#L39-L56 |
oat-sa/qti-sdk | src/qtism/data/Utils.php | Utils.getFirstItem | public static function getFirstItem($test, $component, $sections)
{
$currentCmp = $component;
$visitedNodes = [];
while (true) {
$visitedNodes[] = $currentCmp->getIdentifier();
switch ($currentCmp->getQtiClassName()) {
case "assessmentItemRef":
return $currentCmp;
break;
case "assessmentSection":
$items = $currentCmp->getComponentsByClassName("assessmentItemRef")->getArrayCopy();
if (count($items) == 0) {
// Check for recursion
$sectparent = Utils::checkRecursion($currentCmp, $sections);
if ($sectparent != null)
{
$nextSectpart = null;
$currentFound = false;
foreach ($sectparent->getSectionParts() as $key => $scpt)
{
if ($currentFound) {
$nextSectpart = $scpt;
break;
}
if ($scpt == $currentCmp) {
$currentFound = true;
}
}
if ($nextSectpart == null) { // Check end of file or at a higher level
$currentCmp = $sectparent;
} else { // Recursive part
$currentCmp = $nextSectpart;
}
}
else { // No recursion
$nextSect = null;
$keyFound = null;
foreach ($sections as $sect) {
if (($keyFound) and (!in_array($sect->getIdentifier(), $visitedNodes))) {
$nextSect = $sect;
break;
}
if ($sect->getIdentifier() == $currentCmp->getIdentifier()) {
$keyFound = true;
}
}
if ($nextSect == null) {
return null;
} else {
$currentCmp = $nextSect;
}
}
} else {
return $items[0];
}
break;
case "testPart":
$items = $currentCmp->getComponentsByClassName("assessmentItemRef")->getArrayCopy();
if (count($items) == 0) {
// First item of the next testpart
$nextTest = null;
$keyFound = null;
foreach ($test->getComponentsByClassName($currentCmp->getQtiClassName()) as $test) {
if ($keyFound) {
$nextTest = $test;
break;
}
if ($test->getIdentifier() == $currentCmp->getIdentifier()) {
$keyFound = true;
}
}
if ($nextTest != null) {
$currentCmp = $nextTest;
} else {
return null;
}
} else {
return $items[0];
}
break;
default:
return null;
}
}
} | php | public static function getFirstItem($test, $component, $sections)
{
$currentCmp = $component;
$visitedNodes = [];
while (true) {
$visitedNodes[] = $currentCmp->getIdentifier();
switch ($currentCmp->getQtiClassName()) {
case "assessmentItemRef":
return $currentCmp;
break;
case "assessmentSection":
$items = $currentCmp->getComponentsByClassName("assessmentItemRef")->getArrayCopy();
if (count($items) == 0) {
// Check for recursion
$sectparent = Utils::checkRecursion($currentCmp, $sections);
if ($sectparent != null)
{
$nextSectpart = null;
$currentFound = false;
foreach ($sectparent->getSectionParts() as $key => $scpt)
{
if ($currentFound) {
$nextSectpart = $scpt;
break;
}
if ($scpt == $currentCmp) {
$currentFound = true;
}
}
if ($nextSectpart == null) { // Check end of file or at a higher level
$currentCmp = $sectparent;
} else { // Recursive part
$currentCmp = $nextSectpart;
}
}
else { // No recursion
$nextSect = null;
$keyFound = null;
foreach ($sections as $sect) {
if (($keyFound) and (!in_array($sect->getIdentifier(), $visitedNodes))) {
$nextSect = $sect;
break;
}
if ($sect->getIdentifier() == $currentCmp->getIdentifier()) {
$keyFound = true;
}
}
if ($nextSect == null) {
return null;
} else {
$currentCmp = $nextSect;
}
}
} else {
return $items[0];
}
break;
case "testPart":
$items = $currentCmp->getComponentsByClassName("assessmentItemRef")->getArrayCopy();
if (count($items) == 0) {
// First item of the next testpart
$nextTest = null;
$keyFound = null;
foreach ($test->getComponentsByClassName($currentCmp->getQtiClassName()) as $test) {
if ($keyFound) {
$nextTest = $test;
break;
}
if ($test->getIdentifier() == $currentCmp->getIdentifier()) {
$keyFound = true;
}
}
if ($nextTest != null) {
$currentCmp = $nextTest;
} else {
return null;
}
} else {
return $items[0];
}
break;
default:
return null;
}
}
} | [
"public",
"static",
"function",
"getFirstItem",
"(",
"$",
"test",
",",
"$",
"component",
",",
"$",
"sections",
")",
"{",
"$",
"currentCmp",
"=",
"$",
"component",
";",
"$",
"visitedNodes",
"=",
"[",
"]",
";",
"while",
"(",
"true",
")",
"{",
"$",
"visitedNodes",
"[",
"]",
"=",
"$",
"currentCmp",
"->",
"getIdentifier",
"(",
")",
";",
"switch",
"(",
"$",
"currentCmp",
"->",
"getQtiClassName",
"(",
")",
")",
"{",
"case",
"\"assessmentItemRef\"",
":",
"return",
"$",
"currentCmp",
";",
"break",
";",
"case",
"\"assessmentSection\"",
":",
"$",
"items",
"=",
"$",
"currentCmp",
"->",
"getComponentsByClassName",
"(",
"\"assessmentItemRef\"",
")",
"->",
"getArrayCopy",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"items",
")",
"==",
"0",
")",
"{",
"// Check for recursion",
"$",
"sectparent",
"=",
"Utils",
"::",
"checkRecursion",
"(",
"$",
"currentCmp",
",",
"$",
"sections",
")",
";",
"if",
"(",
"$",
"sectparent",
"!=",
"null",
")",
"{",
"$",
"nextSectpart",
"=",
"null",
";",
"$",
"currentFound",
"=",
"false",
";",
"foreach",
"(",
"$",
"sectparent",
"->",
"getSectionParts",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"scpt",
")",
"{",
"if",
"(",
"$",
"currentFound",
")",
"{",
"$",
"nextSectpart",
"=",
"$",
"scpt",
";",
"break",
";",
"}",
"if",
"(",
"$",
"scpt",
"==",
"$",
"currentCmp",
")",
"{",
"$",
"currentFound",
"=",
"true",
";",
"}",
"}",
"if",
"(",
"$",
"nextSectpart",
"==",
"null",
")",
"{",
"// Check end of file or at a higher level",
"$",
"currentCmp",
"=",
"$",
"sectparent",
";",
"}",
"else",
"{",
"// Recursive part",
"$",
"currentCmp",
"=",
"$",
"nextSectpart",
";",
"}",
"}",
"else",
"{",
"// No recursion",
"$",
"nextSect",
"=",
"null",
";",
"$",
"keyFound",
"=",
"null",
";",
"foreach",
"(",
"$",
"sections",
"as",
"$",
"sect",
")",
"{",
"if",
"(",
"(",
"$",
"keyFound",
")",
"and",
"(",
"!",
"in_array",
"(",
"$",
"sect",
"->",
"getIdentifier",
"(",
")",
",",
"$",
"visitedNodes",
")",
")",
")",
"{",
"$",
"nextSect",
"=",
"$",
"sect",
";",
"break",
";",
"}",
"if",
"(",
"$",
"sect",
"->",
"getIdentifier",
"(",
")",
"==",
"$",
"currentCmp",
"->",
"getIdentifier",
"(",
")",
")",
"{",
"$",
"keyFound",
"=",
"true",
";",
"}",
"}",
"if",
"(",
"$",
"nextSect",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"else",
"{",
"$",
"currentCmp",
"=",
"$",
"nextSect",
";",
"}",
"}",
"}",
"else",
"{",
"return",
"$",
"items",
"[",
"0",
"]",
";",
"}",
"break",
";",
"case",
"\"testPart\"",
":",
"$",
"items",
"=",
"$",
"currentCmp",
"->",
"getComponentsByClassName",
"(",
"\"assessmentItemRef\"",
")",
"->",
"getArrayCopy",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"items",
")",
"==",
"0",
")",
"{",
"// First item of the next testpart",
"$",
"nextTest",
"=",
"null",
";",
"$",
"keyFound",
"=",
"null",
";",
"foreach",
"(",
"$",
"test",
"->",
"getComponentsByClassName",
"(",
"$",
"currentCmp",
"->",
"getQtiClassName",
"(",
")",
")",
"as",
"$",
"test",
")",
"{",
"if",
"(",
"$",
"keyFound",
")",
"{",
"$",
"nextTest",
"=",
"$",
"test",
";",
"break",
";",
"}",
"if",
"(",
"$",
"test",
"->",
"getIdentifier",
"(",
")",
"==",
"$",
"currentCmp",
"->",
"getIdentifier",
"(",
")",
")",
"{",
"$",
"keyFound",
"=",
"true",
";",
"}",
"}",
"if",
"(",
"$",
"nextTest",
"!=",
"null",
")",
"{",
"$",
"currentCmp",
"=",
"$",
"nextTest",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}",
"else",
"{",
"return",
"$",
"items",
"[",
"0",
"]",
";",
"}",
"break",
";",
"default",
":",
"return",
"null",
";",
"}",
"}",
"}"
] | Returns the first AssessmentItem that will be prompted if a branch targets the
QtiComponent set as parameter.
This method depends heavily of the QtiClass of the QtiComponent. Some require multiples loops where we need to
find the firstItem from another QtiComponent : this is then done iteratively.
@param $test \qtism\data\AssessmentTest The AssessmentTest where we are searching the item from where the branch
comes.
@param $component \qtism\data\QtiComponent The QtiComponent targeted by a branch.
@param $sections AssessmentSectionCollection The collection of all sections in this AssessmentTest.
@return \qtism\data\AssessmentItem|null The first AssessmentItem that will be prompted if a branch targets the
QtiComponent set as parameter. Returns null, if there are no more AssessmentItem because the end of the test
has been reached. | [
"Returns",
"the",
"first",
"AssessmentItem",
"that",
"will",
"be",
"prompted",
"if",
"a",
"branch",
"targets",
"the",
"QtiComponent",
"set",
"as",
"parameter",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/Utils.php#L73-L184 |
oat-sa/qti-sdk | src/qtism/data/Utils.php | Utils.getLastItem | public static function getLastItem($test, $component, $sections)
{
$currentCmp = $component;
// $sections = null;
while (true)
{
switch ($currentCmp->getQtiClassName()) {
case "assessmentItemRef":
return $currentCmp;
break;
case "assessmentSection":
$items = $currentCmp->getComponentsByClassName("assessmentItemRef")->getArrayCopy();
if (count($items) == 0) {
// Check for recursion
$sectparent = Utils::checkRecursion($currentCmp, $sections);
if ($sectparent != null) {
$prevSectPart = null;
foreach ($sectparent->getSectionParts() as $key => $scpt) {
if ($scpt == $currentCmp) {
break;
}
$prevSectPart = $scpt;
}
if ($prevSectPart == null)
{
$currentCmp = $sectparent;
} else {
$currentCmp = $prevSectPart;
}
}
else {
// No recursion
$prevSect = null;
$keyFound = null;
foreach ($sections as $sect) {
if ($sect->getIdentifier() == $currentCmp->getIdentifier()) {
break;
} else {
$prevSect = $sect;
}
}
if ($prevSect == null) {
return null;
} else {
$currentCmp = $prevSect;
}
}
} else { // Case with sub items
return $items[count($items) - 1];
}
break;
case "testPart":
$items = $currentCmp->getComponentsByClassName("assessmentItemRef")->getArrayCopy();
if (count($items) == 0) {
// First item of the next testpart
$prevTest = null;
$keyFound = null;
foreach ($test->getComponentsByClassName($currentCmp->getQtiClassName()) as $test) {
if ($test->getIdentifier() == $currentCmp->getIdentifier()) {
break;
} else {
$prevTest = $test;
}
}
if ($prevTest != null) {
$currentCmp = $prevTest;
} else {
return null;
}
} else {
return $items[count($items) - 1];
}
break;
default:
return null;
}
}
} | php | public static function getLastItem($test, $component, $sections)
{
$currentCmp = $component;
// $sections = null;
while (true)
{
switch ($currentCmp->getQtiClassName()) {
case "assessmentItemRef":
return $currentCmp;
break;
case "assessmentSection":
$items = $currentCmp->getComponentsByClassName("assessmentItemRef")->getArrayCopy();
if (count($items) == 0) {
// Check for recursion
$sectparent = Utils::checkRecursion($currentCmp, $sections);
if ($sectparent != null) {
$prevSectPart = null;
foreach ($sectparent->getSectionParts() as $key => $scpt) {
if ($scpt == $currentCmp) {
break;
}
$prevSectPart = $scpt;
}
if ($prevSectPart == null)
{
$currentCmp = $sectparent;
} else {
$currentCmp = $prevSectPart;
}
}
else {
// No recursion
$prevSect = null;
$keyFound = null;
foreach ($sections as $sect) {
if ($sect->getIdentifier() == $currentCmp->getIdentifier()) {
break;
} else {
$prevSect = $sect;
}
}
if ($prevSect == null) {
return null;
} else {
$currentCmp = $prevSect;
}
}
} else { // Case with sub items
return $items[count($items) - 1];
}
break;
case "testPart":
$items = $currentCmp->getComponentsByClassName("assessmentItemRef")->getArrayCopy();
if (count($items) == 0) {
// First item of the next testpart
$prevTest = null;
$keyFound = null;
foreach ($test->getComponentsByClassName($currentCmp->getQtiClassName()) as $test) {
if ($test->getIdentifier() == $currentCmp->getIdentifier()) {
break;
} else {
$prevTest = $test;
}
}
if ($prevTest != null) {
$currentCmp = $prevTest;
} else {
return null;
}
} else {
return $items[count($items) - 1];
}
break;
default:
return null;
}
}
} | [
"public",
"static",
"function",
"getLastItem",
"(",
"$",
"test",
",",
"$",
"component",
",",
"$",
"sections",
")",
"{",
"$",
"currentCmp",
"=",
"$",
"component",
";",
"// $sections = null;",
"while",
"(",
"true",
")",
"{",
"switch",
"(",
"$",
"currentCmp",
"->",
"getQtiClassName",
"(",
")",
")",
"{",
"case",
"\"assessmentItemRef\"",
":",
"return",
"$",
"currentCmp",
";",
"break",
";",
"case",
"\"assessmentSection\"",
":",
"$",
"items",
"=",
"$",
"currentCmp",
"->",
"getComponentsByClassName",
"(",
"\"assessmentItemRef\"",
")",
"->",
"getArrayCopy",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"items",
")",
"==",
"0",
")",
"{",
"// Check for recursion",
"$",
"sectparent",
"=",
"Utils",
"::",
"checkRecursion",
"(",
"$",
"currentCmp",
",",
"$",
"sections",
")",
";",
"if",
"(",
"$",
"sectparent",
"!=",
"null",
")",
"{",
"$",
"prevSectPart",
"=",
"null",
";",
"foreach",
"(",
"$",
"sectparent",
"->",
"getSectionParts",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"scpt",
")",
"{",
"if",
"(",
"$",
"scpt",
"==",
"$",
"currentCmp",
")",
"{",
"break",
";",
"}",
"$",
"prevSectPart",
"=",
"$",
"scpt",
";",
"}",
"if",
"(",
"$",
"prevSectPart",
"==",
"null",
")",
"{",
"$",
"currentCmp",
"=",
"$",
"sectparent",
";",
"}",
"else",
"{",
"$",
"currentCmp",
"=",
"$",
"prevSectPart",
";",
"}",
"}",
"else",
"{",
"// No recursion",
"$",
"prevSect",
"=",
"null",
";",
"$",
"keyFound",
"=",
"null",
";",
"foreach",
"(",
"$",
"sections",
"as",
"$",
"sect",
")",
"{",
"if",
"(",
"$",
"sect",
"->",
"getIdentifier",
"(",
")",
"==",
"$",
"currentCmp",
"->",
"getIdentifier",
"(",
")",
")",
"{",
"break",
";",
"}",
"else",
"{",
"$",
"prevSect",
"=",
"$",
"sect",
";",
"}",
"}",
"if",
"(",
"$",
"prevSect",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"else",
"{",
"$",
"currentCmp",
"=",
"$",
"prevSect",
";",
"}",
"}",
"}",
"else",
"{",
"// Case with sub items",
"return",
"$",
"items",
"[",
"count",
"(",
"$",
"items",
")",
"-",
"1",
"]",
";",
"}",
"break",
";",
"case",
"\"testPart\"",
":",
"$",
"items",
"=",
"$",
"currentCmp",
"->",
"getComponentsByClassName",
"(",
"\"assessmentItemRef\"",
")",
"->",
"getArrayCopy",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"items",
")",
"==",
"0",
")",
"{",
"// First item of the next testpart",
"$",
"prevTest",
"=",
"null",
";",
"$",
"keyFound",
"=",
"null",
";",
"foreach",
"(",
"$",
"test",
"->",
"getComponentsByClassName",
"(",
"$",
"currentCmp",
"->",
"getQtiClassName",
"(",
")",
")",
"as",
"$",
"test",
")",
"{",
"if",
"(",
"$",
"test",
"->",
"getIdentifier",
"(",
")",
"==",
"$",
"currentCmp",
"->",
"getIdentifier",
"(",
")",
")",
"{",
"break",
";",
"}",
"else",
"{",
"$",
"prevTest",
"=",
"$",
"test",
";",
"}",
"}",
"if",
"(",
"$",
"prevTest",
"!=",
"null",
")",
"{",
"$",
"currentCmp",
"=",
"$",
"prevTest",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}",
"else",
"{",
"return",
"$",
"items",
"[",
"count",
"(",
"$",
"items",
")",
"-",
"1",
"]",
";",
"}",
"break",
";",
"default",
":",
"return",
"null",
";",
"}",
"}",
"}"
] | Returns the last AssessmentItem that will be prompted before a BranchRule of the QtiComponent set as parameter
will be taken.
This method depends heavily of the QtiClass of the QtiComponent. Some require multiples loops where we need to
find the lastItem from another QtiComponent : this is then done iteratively.
@param $test \qtism\data\AssessmentTest The AssessmentTest where we are searching the item from where the branch
starts.
@param $component \qtism\data\QtiComponent The QtiComponent with a BranchRule.
@param $sections AssessmentSectionCollection The collection of all sections in this AssessmentTest.
@return \qtism\data\AssessmentItem|null The last AssessmentItem that will be prompted before taking a BranchRule
in the QtiComponent set as parameter. Returns null, if there are no more AssessmentItem because the begin of the
test has been reached. | [
"Returns",
"the",
"last",
"AssessmentItem",
"that",
"will",
"be",
"prompted",
"before",
"a",
"BranchRule",
"of",
"the",
"QtiComponent",
"set",
"as",
"parameter",
"will",
"be",
"taken",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/Utils.php#L201-L299 |
oat-sa/qti-sdk | src/qtism/data/state/AreaMapping.php | AreaMapping.setUpperBound | public function setUpperBound($upperBound)
{
if (is_float($upperBound) || (is_bool($upperBound) && $upperBound === false)) {
$this->upperBound = $upperBound;
} else {
$msg = "The upperBound argument must be a float or false if no upper bound, '" . gettype($upperBound) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setUpperBound($upperBound)
{
if (is_float($upperBound) || (is_bool($upperBound) && $upperBound === false)) {
$this->upperBound = $upperBound;
} else {
$msg = "The upperBound argument must be a float or false if no upper bound, '" . gettype($upperBound) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setUpperBound",
"(",
"$",
"upperBound",
")",
"{",
"if",
"(",
"is_float",
"(",
"$",
"upperBound",
")",
"||",
"(",
"is_bool",
"(",
"$",
"upperBound",
")",
"&&",
"$",
"upperBound",
"===",
"false",
")",
")",
"{",
"$",
"this",
"->",
"upperBound",
"=",
"$",
"upperBound",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The upperBound argument must be a float or false if no upper bound, '\"",
".",
"gettype",
"(",
"$",
"upperBound",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the upper bound.
@param boolean|float $upperBound An upper bound.
@throws \InvalidArgumentException If $upperBound is not a float value nor false. | [
"Set",
"the",
"upper",
"bound",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/state/AreaMapping.php#L124-L132 |
oat-sa/qti-sdk | src/qtism/data/state/AreaMapping.php | AreaMapping.setDefaultValue | public function setDefaultValue($defaultValue)
{
if (is_float($defaultValue)) {
$this->defaultValue = $defaultValue;
} else {
$msg = "The defaultValue argument must be a numeric value, '" . gettype($defaultValue) . "'.";
throw new InvalidArgumentException($msg);
}
} | php | public function setDefaultValue($defaultValue)
{
if (is_float($defaultValue)) {
$this->defaultValue = $defaultValue;
} else {
$msg = "The defaultValue argument must be a numeric value, '" . gettype($defaultValue) . "'.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setDefaultValue",
"(",
"$",
"defaultValue",
")",
"{",
"if",
"(",
"is_float",
"(",
"$",
"defaultValue",
")",
")",
"{",
"$",
"this",
"->",
"defaultValue",
"=",
"$",
"defaultValue",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The defaultValue argument must be a numeric value, '\"",
".",
"gettype",
"(",
"$",
"defaultValue",
")",
".",
"\"'.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the default value.
@param float $defaultValue A default value.
@throws \InvalidArgumentException If $defaultValue is not a float value. | [
"Set",
"the",
"default",
"value",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/state/AreaMapping.php#L150-L158 |
oat-sa/qti-sdk | src/qtism/data/state/AreaMapping.php | AreaMapping.setAreaMapEntries | public function setAreaMapEntries(AreaMapEntryCollection $areaMapEntries)
{
if (count($areaMapEntries) >= 1) {
$this->areaMapEntries = $areaMapEntries;
} else {
$msg = "An AreaMapping object must contain at least one AreaMapEntry object. none given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setAreaMapEntries(AreaMapEntryCollection $areaMapEntries)
{
if (count($areaMapEntries) >= 1) {
$this->areaMapEntries = $areaMapEntries;
} else {
$msg = "An AreaMapping object must contain at least one AreaMapEntry object. none given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setAreaMapEntries",
"(",
"AreaMapEntryCollection",
"$",
"areaMapEntries",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"areaMapEntries",
")",
">=",
"1",
")",
"{",
"$",
"this",
"->",
"areaMapEntries",
"=",
"$",
"areaMapEntries",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"An AreaMapping object must contain at least one AreaMapEntry object. none given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the collection of AreaMapEntry objects composing the AreaMapping.
@param \qtism\data\state\AreaMapEntryCollection $areaMapEntries A collection of AreaMapEntry objects. | [
"Set",
"the",
"collection",
"of",
"AreaMapEntry",
"objects",
"composing",
"the",
"AreaMapping",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/state/AreaMapping.php#L175-L183 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.