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/HottextInteraction.php | HottextInteraction.setContent | public function setContent(BlockStaticCollection $content)
{
if (count($content) > 0) {
$this->content = $content;
} else {
$msg = "A HottextInteraction object must be composed of at least one BlockStatic object, none given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setContent(BlockStaticCollection $content)
{
if (count($content) > 0) {
$this->content = $content;
} else {
$msg = "A HottextInteraction object must be composed of at least one BlockStatic object, none given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setContent",
"(",
"BlockStaticCollection",
"$",
"content",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"content",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"content",
"=",
"$",
"content",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"A HottextInteraction object must be composed of at least one BlockStatic object, none given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the content of the interaction, containing the hottext areas.
@param \qtism\data\content\BlockStaticCollection $content A collection of at least one BlockStatic object.
@throws \InvalidArgumentException If $content is empty. | [
"Set",
"the",
"content",
"of",
"the",
"interaction",
"containing",
"the",
"hottext",
"areas",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/interactions/HottextInteraction.php#L171-L179 |
oat-sa/qti-sdk | src/qtism/data/content/interactions/Interaction.php | Interaction.setResponseIdentifier | public function setResponseIdentifier($responseIdentifier)
{
if (Format::isIdentifier($responseIdentifier, false) === true) {
$this->responseIdentifier = $responseIdentifier;
} else {
$msg = "The 'responseIdentifier' argument must be a valid QTI identifier.";
throw new InvalidArgumentException($msg);
}
} | php | public function setResponseIdentifier($responseIdentifier)
{
if (Format::isIdentifier($responseIdentifier, false) === true) {
$this->responseIdentifier = $responseIdentifier;
} else {
$msg = "The 'responseIdentifier' argument must be a valid QTI identifier.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setResponseIdentifier",
"(",
"$",
"responseIdentifier",
")",
"{",
"if",
"(",
"Format",
"::",
"isIdentifier",
"(",
"$",
"responseIdentifier",
",",
"false",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"responseIdentifier",
"=",
"$",
"responseIdentifier",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'responseIdentifier' argument must be a valid QTI identifier.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the response variable associated with the interaction.
@param string $responseIdentifier A QTI identifier.
@throws \InvalidArgumentException If $responseIdentifier is not a valid QTI identifier. | [
"Set",
"the",
"response",
"variable",
"associated",
"with",
"the",
"interaction",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/interactions/Interaction.php#L93-L101 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/ContainsProcessor.php | ContainsProcessor.process | public function process()
{
$operands = $this->getOperands();
if ($operands->containsNull()) {
return null;
}
if ($operands->exclusivelyMultipleOrOrdered() === false) {
$msg = "The Contains Expression only accept operands with multiple or ordered cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
if ($operands->sameCardinality() === false) {
$msg = "The Contains Expression only accept operands with the same cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
if ($operands->sameBaseType() === false) {
$msg = "The Contains Expression only accept operands with the same baseType.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
}
$operand1 = $operands[0];
$operand2 = $operands[1];
if ($operand1->getCardinality() === Cardinality::MULTIPLE) {
foreach ($operand2 as $value) {
if ($operand1->contains($value) === false || $operand1->occurences($value) !== $operand2->occurences($value)) {
return new QtiBoolean(false);
}
}
return new QtiBoolean(true);
} else {
// $operand1->getCardinality() === Cardinality::ORDERED
$op1Index = 0;
$op2Index = 0;
$lastFoundIndex = -1;
$foundCount = 0;
while ($op1Index < count($operand1)) {
$op1Val = $operand1[$op1Index];
$op2Val = $operand2[$op2Index];
if ($op2Val === $op1Val || ($op2Val instanceof Comparable && $op2Val->equals($op1Val))) {
$op2Index++;
if ($lastFoundIndex >= 0 && ($op1Index - $lastFoundIndex) > 1) {
// Sequence not respected.
return new QtiBoolean(false);
} else {
$lastFoundIndex = $op1Index;
$foundCount++;
}
}
$op1Index++;
}
if ($foundCount > 0 && $foundCount === count($operand2)) {
return new QtiBoolean(true);
} else {
return new QtiBoolean(false);
}
}
} | php | public function process()
{
$operands = $this->getOperands();
if ($operands->containsNull()) {
return null;
}
if ($operands->exclusivelyMultipleOrOrdered() === false) {
$msg = "The Contains Expression only accept operands with multiple or ordered cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
if ($operands->sameCardinality() === false) {
$msg = "The Contains Expression only accept operands with the same cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
if ($operands->sameBaseType() === false) {
$msg = "The Contains Expression only accept operands with the same baseType.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
}
$operand1 = $operands[0];
$operand2 = $operands[1];
if ($operand1->getCardinality() === Cardinality::MULTIPLE) {
foreach ($operand2 as $value) {
if ($operand1->contains($value) === false || $operand1->occurences($value) !== $operand2->occurences($value)) {
return new QtiBoolean(false);
}
}
return new QtiBoolean(true);
} else {
// $operand1->getCardinality() === Cardinality::ORDERED
$op1Index = 0;
$op2Index = 0;
$lastFoundIndex = -1;
$foundCount = 0;
while ($op1Index < count($operand1)) {
$op1Val = $operand1[$op1Index];
$op2Val = $operand2[$op2Index];
if ($op2Val === $op1Val || ($op2Val instanceof Comparable && $op2Val->equals($op1Val))) {
$op2Index++;
if ($lastFoundIndex >= 0 && ($op1Index - $lastFoundIndex) > 1) {
// Sequence not respected.
return new QtiBoolean(false);
} else {
$lastFoundIndex = $op1Index;
$foundCount++;
}
}
$op1Index++;
}
if ($foundCount > 0 && $foundCount === count($operand2)) {
return new QtiBoolean(true);
} else {
return new QtiBoolean(false);
}
}
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"operands",
"=",
"$",
"this",
"->",
"getOperands",
"(",
")",
";",
"if",
"(",
"$",
"operands",
"->",
"containsNull",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"operands",
"->",
"exclusivelyMultipleOrOrdered",
"(",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The Contains Expression only accept operands with multiple or ordered cardinality.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_CARDINALITY",
")",
";",
"}",
"if",
"(",
"$",
"operands",
"->",
"sameCardinality",
"(",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The Contains Expression only accept operands with the same cardinality.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_CARDINALITY",
")",
";",
"}",
"if",
"(",
"$",
"operands",
"->",
"sameBaseType",
"(",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The Contains Expression only accept operands with the same baseType.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_BASETYPE",
")",
";",
"}",
"$",
"operand1",
"=",
"$",
"operands",
"[",
"0",
"]",
";",
"$",
"operand2",
"=",
"$",
"operands",
"[",
"1",
"]",
";",
"if",
"(",
"$",
"operand1",
"->",
"getCardinality",
"(",
")",
"===",
"Cardinality",
"::",
"MULTIPLE",
")",
"{",
"foreach",
"(",
"$",
"operand2",
"as",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"operand1",
"->",
"contains",
"(",
"$",
"value",
")",
"===",
"false",
"||",
"$",
"operand1",
"->",
"occurences",
"(",
"$",
"value",
")",
"!==",
"$",
"operand2",
"->",
"occurences",
"(",
"$",
"value",
")",
")",
"{",
"return",
"new",
"QtiBoolean",
"(",
"false",
")",
";",
"}",
"}",
"return",
"new",
"QtiBoolean",
"(",
"true",
")",
";",
"}",
"else",
"{",
"// $operand1->getCardinality() === Cardinality::ORDERED",
"$",
"op1Index",
"=",
"0",
";",
"$",
"op2Index",
"=",
"0",
";",
"$",
"lastFoundIndex",
"=",
"-",
"1",
";",
"$",
"foundCount",
"=",
"0",
";",
"while",
"(",
"$",
"op1Index",
"<",
"count",
"(",
"$",
"operand1",
")",
")",
"{",
"$",
"op1Val",
"=",
"$",
"operand1",
"[",
"$",
"op1Index",
"]",
";",
"$",
"op2Val",
"=",
"$",
"operand2",
"[",
"$",
"op2Index",
"]",
";",
"if",
"(",
"$",
"op2Val",
"===",
"$",
"op1Val",
"||",
"(",
"$",
"op2Val",
"instanceof",
"Comparable",
"&&",
"$",
"op2Val",
"->",
"equals",
"(",
"$",
"op1Val",
")",
")",
")",
"{",
"$",
"op2Index",
"++",
";",
"if",
"(",
"$",
"lastFoundIndex",
">=",
"0",
"&&",
"(",
"$",
"op1Index",
"-",
"$",
"lastFoundIndex",
")",
">",
"1",
")",
"{",
"// Sequence not respected.",
"return",
"new",
"QtiBoolean",
"(",
"false",
")",
";",
"}",
"else",
"{",
"$",
"lastFoundIndex",
"=",
"$",
"op1Index",
";",
"$",
"foundCount",
"++",
";",
"}",
"}",
"$",
"op1Index",
"++",
";",
"}",
"if",
"(",
"$",
"foundCount",
">",
"0",
"&&",
"$",
"foundCount",
"===",
"count",
"(",
"$",
"operand2",
")",
")",
"{",
"return",
"new",
"QtiBoolean",
"(",
"true",
")",
";",
"}",
"else",
"{",
"return",
"new",
"QtiBoolean",
"(",
"false",
")",
";",
"}",
"}",
"}"
] | Returns the logical negation of the sub-expressions.
@return boolean
@throws \qtism\runtime\expressions\operators\OperatorProcessingException | [
"Returns",
"the",
"logical",
"negation",
"of",
"the",
"sub",
"-",
"expressions",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/ContainsProcessor.php#L54-L120 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/Utils.php | Utils.getSchemaLocation | static public function getSchemaLocation($version = '2.1')
{
$version = Version::appendPatchVersion($version);
if ($version === '2.1.0') {
$filename = dirname(__FILE__) . '/schemes/qtiv2p1/imsqti_v2p1.xsd';
} elseif ($version === '2.1.1') {
$filename = dirname(__FILE__) . '/schemes/qtiv2p1p1/imsqti_v2p1p1.xsd';
} elseif ($version === '2.2.0') {
$filename = dirname(__FILE__) . '/schemes/qtiv2p2/imsqti_v2p2.xsd';
} elseif ($version === '2.2.1') {
$filename = dirname(__FILE__) . '/schemes/qtiv2p2p1/imsqti_v2p2p1.xsd';
} else {
$filename = dirname(__FILE__) . '/schemes/imsqti_v2p0.xsd';
}
return $filename;
} | php | static public function getSchemaLocation($version = '2.1')
{
$version = Version::appendPatchVersion($version);
if ($version === '2.1.0') {
$filename = dirname(__FILE__) . '/schemes/qtiv2p1/imsqti_v2p1.xsd';
} elseif ($version === '2.1.1') {
$filename = dirname(__FILE__) . '/schemes/qtiv2p1p1/imsqti_v2p1p1.xsd';
} elseif ($version === '2.2.0') {
$filename = dirname(__FILE__) . '/schemes/qtiv2p2/imsqti_v2p2.xsd';
} elseif ($version === '2.2.1') {
$filename = dirname(__FILE__) . '/schemes/qtiv2p2p1/imsqti_v2p2p1.xsd';
} else {
$filename = dirname(__FILE__) . '/schemes/imsqti_v2p0.xsd';
}
return $filename;
} | [
"static",
"public",
"function",
"getSchemaLocation",
"(",
"$",
"version",
"=",
"'2.1'",
")",
"{",
"$",
"version",
"=",
"Version",
"::",
"appendPatchVersion",
"(",
"$",
"version",
")",
";",
"if",
"(",
"$",
"version",
"===",
"'2.1.0'",
")",
"{",
"$",
"filename",
"=",
"dirname",
"(",
"__FILE__",
")",
".",
"'/schemes/qtiv2p1/imsqti_v2p1.xsd'",
";",
"}",
"elseif",
"(",
"$",
"version",
"===",
"'2.1.1'",
")",
"{",
"$",
"filename",
"=",
"dirname",
"(",
"__FILE__",
")",
".",
"'/schemes/qtiv2p1p1/imsqti_v2p1p1.xsd'",
";",
"}",
"elseif",
"(",
"$",
"version",
"===",
"'2.2.0'",
")",
"{",
"$",
"filename",
"=",
"dirname",
"(",
"__FILE__",
")",
".",
"'/schemes/qtiv2p2/imsqti_v2p2.xsd'",
";",
"}",
"elseif",
"(",
"$",
"version",
"===",
"'2.2.1'",
")",
"{",
"$",
"filename",
"=",
"dirname",
"(",
"__FILE__",
")",
".",
"'/schemes/qtiv2p2p1/imsqti_v2p2p1.xsd'",
";",
"}",
"else",
"{",
"$",
"filename",
"=",
"dirname",
"(",
"__FILE__",
")",
".",
"'/schemes/imsqti_v2p0.xsd'",
";",
"}",
"return",
"$",
"filename",
";",
"}"
] | Get the XML schema to use for a given QTI version.
@return string A filename pointing at an XML Schema file. | [
"Get",
"the",
"XML",
"schema",
"to",
"use",
"for",
"a",
"given",
"QTI",
"version",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/Utils.php#L43-L60 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/Utils.php | Utils.inferVersion | static public function inferVersion(DOMDocument $document)
{
$root = $document->documentElement;
$version = false;
if (empty($root) === false) {
$rootNs = $root->namespaceURI;
if ($rootNs === 'http://www.imsglobal.org/xsd/imsqti_v2p0') {
$nsLocation = self::getXsdLocation($document, 'http://www.imsglobal.org/xsd/imsqti_v2p0');
if ($nsLocation === 'http://www.imsglobal.org/xsd/imsqti_v2p0.xsd') {
$version = '2.0.0';
}
} elseif ($rootNs === 'http://www.imsglobal.org/xsd/imsqti_v2p1') {
$nsLocation = self::getXsdLocation($document, 'http://www.imsglobal.org/xsd/imsqti_v2p1');
if ($nsLocation === 'http://www.imsglobal.org/xsd/qti/qtiv2p1/imsqti_v2p1.xsd') {
$version = '2.1.0';
} else if ($nsLocation === 'http://www.imsglobal.org/xsd/qti/qtiv2p1/imsqti_v2p1p1.xsd') {
$version = '2.1.1';
}
} elseif ($rootNs === 'http://www.imsglobal.org/xsd/imsqti_v2p2') {
$nsLocation = self::getXsdLocation($document, 'http://www.imsglobal.org/xsd/imsqti_v2p2');
if ($nsLocation === 'http://www.imsglobal.org/xsd/qti/qtiv2p2/imsqti_v2p2.xsd') {
$version = '2.2.0';
} elseif ($nsLocation === 'http://www.imsglobal.org/xsd/qti/qtiv2p2/imsqti_v2p2p1.xsd') {
$version = '2.2.1';
}
} elseif ($rootNs === 'http://www.imsglobal.org/xsd/imsaqti_item_v1p0') {
$nsLocation = self::getXsdLocation($document, 'http://www.imsglobal.org/xsd/imsaqti_item_v1p0');
if ($nsLocation === 'http://www.imsglobal.org/xsd/qti/aqtiv1p0/imsaqti_itemv1p0_v1p0.xsd') {
$version = '3.0.0';
}
}
}
return $version;
} | php | static public function inferVersion(DOMDocument $document)
{
$root = $document->documentElement;
$version = false;
if (empty($root) === false) {
$rootNs = $root->namespaceURI;
if ($rootNs === 'http://www.imsglobal.org/xsd/imsqti_v2p0') {
$nsLocation = self::getXsdLocation($document, 'http://www.imsglobal.org/xsd/imsqti_v2p0');
if ($nsLocation === 'http://www.imsglobal.org/xsd/imsqti_v2p0.xsd') {
$version = '2.0.0';
}
} elseif ($rootNs === 'http://www.imsglobal.org/xsd/imsqti_v2p1') {
$nsLocation = self::getXsdLocation($document, 'http://www.imsglobal.org/xsd/imsqti_v2p1');
if ($nsLocation === 'http://www.imsglobal.org/xsd/qti/qtiv2p1/imsqti_v2p1.xsd') {
$version = '2.1.0';
} else if ($nsLocation === 'http://www.imsglobal.org/xsd/qti/qtiv2p1/imsqti_v2p1p1.xsd') {
$version = '2.1.1';
}
} elseif ($rootNs === 'http://www.imsglobal.org/xsd/imsqti_v2p2') {
$nsLocation = self::getXsdLocation($document, 'http://www.imsglobal.org/xsd/imsqti_v2p2');
if ($nsLocation === 'http://www.imsglobal.org/xsd/qti/qtiv2p2/imsqti_v2p2.xsd') {
$version = '2.2.0';
} elseif ($nsLocation === 'http://www.imsglobal.org/xsd/qti/qtiv2p2/imsqti_v2p2p1.xsd') {
$version = '2.2.1';
}
} elseif ($rootNs === 'http://www.imsglobal.org/xsd/imsaqti_item_v1p0') {
$nsLocation = self::getXsdLocation($document, 'http://www.imsglobal.org/xsd/imsaqti_item_v1p0');
if ($nsLocation === 'http://www.imsglobal.org/xsd/qti/aqtiv1p0/imsaqti_itemv1p0_v1p0.xsd') {
$version = '3.0.0';
}
}
}
return $version;
} | [
"static",
"public",
"function",
"inferVersion",
"(",
"DOMDocument",
"$",
"document",
")",
"{",
"$",
"root",
"=",
"$",
"document",
"->",
"documentElement",
";",
"$",
"version",
"=",
"false",
";",
"if",
"(",
"empty",
"(",
"$",
"root",
")",
"===",
"false",
")",
"{",
"$",
"rootNs",
"=",
"$",
"root",
"->",
"namespaceURI",
";",
"if",
"(",
"$",
"rootNs",
"===",
"'http://www.imsglobal.org/xsd/imsqti_v2p0'",
")",
"{",
"$",
"nsLocation",
"=",
"self",
"::",
"getXsdLocation",
"(",
"$",
"document",
",",
"'http://www.imsglobal.org/xsd/imsqti_v2p0'",
")",
";",
"if",
"(",
"$",
"nsLocation",
"===",
"'http://www.imsglobal.org/xsd/imsqti_v2p0.xsd'",
")",
"{",
"$",
"version",
"=",
"'2.0.0'",
";",
"}",
"}",
"elseif",
"(",
"$",
"rootNs",
"===",
"'http://www.imsglobal.org/xsd/imsqti_v2p1'",
")",
"{",
"$",
"nsLocation",
"=",
"self",
"::",
"getXsdLocation",
"(",
"$",
"document",
",",
"'http://www.imsglobal.org/xsd/imsqti_v2p1'",
")",
";",
"if",
"(",
"$",
"nsLocation",
"===",
"'http://www.imsglobal.org/xsd/qti/qtiv2p1/imsqti_v2p1.xsd'",
")",
"{",
"$",
"version",
"=",
"'2.1.0'",
";",
"}",
"else",
"if",
"(",
"$",
"nsLocation",
"===",
"'http://www.imsglobal.org/xsd/qti/qtiv2p1/imsqti_v2p1p1.xsd'",
")",
"{",
"$",
"version",
"=",
"'2.1.1'",
";",
"}",
"}",
"elseif",
"(",
"$",
"rootNs",
"===",
"'http://www.imsglobal.org/xsd/imsqti_v2p2'",
")",
"{",
"$",
"nsLocation",
"=",
"self",
"::",
"getXsdLocation",
"(",
"$",
"document",
",",
"'http://www.imsglobal.org/xsd/imsqti_v2p2'",
")",
";",
"if",
"(",
"$",
"nsLocation",
"===",
"'http://www.imsglobal.org/xsd/qti/qtiv2p2/imsqti_v2p2.xsd'",
")",
"{",
"$",
"version",
"=",
"'2.2.0'",
";",
"}",
"elseif",
"(",
"$",
"nsLocation",
"===",
"'http://www.imsglobal.org/xsd/qti/qtiv2p2/imsqti_v2p2p1.xsd'",
")",
"{",
"$",
"version",
"=",
"'2.2.1'",
";",
"}",
"}",
"elseif",
"(",
"$",
"rootNs",
"===",
"'http://www.imsglobal.org/xsd/imsaqti_item_v1p0'",
")",
"{",
"$",
"nsLocation",
"=",
"self",
"::",
"getXsdLocation",
"(",
"$",
"document",
",",
"'http://www.imsglobal.org/xsd/imsaqti_item_v1p0'",
")",
";",
"if",
"(",
"$",
"nsLocation",
"===",
"'http://www.imsglobal.org/xsd/qti/aqtiv1p0/imsaqti_itemv1p0_v1p0.xsd'",
")",
"{",
"$",
"version",
"=",
"'3.0.0'",
";",
"}",
"}",
"}",
"return",
"$",
"version",
";",
"}"
] | Infer the QTI version from a given DOM $document in a Semantic Versioning
format always containing a MAJOR, MINOR and PATCH version.
@param \DOMDocument $document
@return string|boolean A QTI version number if it could be infered, false otherwise. | [
"Infer",
"the",
"QTI",
"version",
"from",
"a",
"given",
"DOM",
"$document",
"in",
"a",
"Semantic",
"Versioning",
"format",
"always",
"containing",
"a",
"MAJOR",
"MINOR",
"and",
"PATCH",
"version",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/Utils.php#L69-L109 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/Utils.php | Utils.getXsdLocation | static public function getXsdLocation(DOMDocument $document, $namespaceUri)
{
$root = $document->documentElement;
$location = false;
if (empty($root) === false) {
$schemaLocation = $root->getAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'schemaLocation');
if (empty($schemaLocation) === false) {
$parts = preg_split('/\s+/', $schemaLocation);
// Look at pairs...
$partsCount = count($parts);
for ($i = 0; $i < $partsCount; $i += 2) {
if (isset($parts[$i + 1]) && $parts[$i] === $namespaceUri) {
$location = $parts[$i + 1];
break;
}
}
}
}
return $location;
} | php | static public function getXsdLocation(DOMDocument $document, $namespaceUri)
{
$root = $document->documentElement;
$location = false;
if (empty($root) === false) {
$schemaLocation = $root->getAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'schemaLocation');
if (empty($schemaLocation) === false) {
$parts = preg_split('/\s+/', $schemaLocation);
// Look at pairs...
$partsCount = count($parts);
for ($i = 0; $i < $partsCount; $i += 2) {
if (isset($parts[$i + 1]) && $parts[$i] === $namespaceUri) {
$location = $parts[$i + 1];
break;
}
}
}
}
return $location;
} | [
"static",
"public",
"function",
"getXsdLocation",
"(",
"DOMDocument",
"$",
"document",
",",
"$",
"namespaceUri",
")",
"{",
"$",
"root",
"=",
"$",
"document",
"->",
"documentElement",
";",
"$",
"location",
"=",
"false",
";",
"if",
"(",
"empty",
"(",
"$",
"root",
")",
"===",
"false",
")",
"{",
"$",
"schemaLocation",
"=",
"$",
"root",
"->",
"getAttributeNS",
"(",
"'http://www.w3.org/2001/XMLSchema-instance'",
",",
"'schemaLocation'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"schemaLocation",
")",
"===",
"false",
")",
"{",
"$",
"parts",
"=",
"preg_split",
"(",
"'/\\s+/'",
",",
"$",
"schemaLocation",
")",
";",
"// Look at pairs...",
"$",
"partsCount",
"=",
"count",
"(",
"$",
"parts",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"partsCount",
";",
"$",
"i",
"+=",
"2",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"parts",
"[",
"$",
"i",
"+",
"1",
"]",
")",
"&&",
"$",
"parts",
"[",
"$",
"i",
"]",
"===",
"$",
"namespaceUri",
")",
"{",
"$",
"location",
"=",
"$",
"parts",
"[",
"$",
"i",
"+",
"1",
"]",
";",
"break",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"location",
";",
"}"
] | Get the location of an XML Schema Definition file from a given namespace.
This utility method enables you to know what is the location of an XML Schema Definition
file to be used to validate a $document for a given target namespace.
@param DOMDocument $document A DOMDocument object.
@param string $namespaceUri A Namespace URI you want to know the related XSD file location.
@return boolean|string False if no location can be found for $namespaceUri, otherwise the location of the XSD file. | [
"Get",
"the",
"location",
"of",
"an",
"XML",
"Schema",
"Definition",
"file",
"from",
"a",
"given",
"namespace",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/Utils.php#L121-L143 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/Utils.php | Utils.changeElementName | static public function changeElementName(DOMElement $element, $name)
{
$newElement = $element->ownerDocument->createElement($name);
foreach ($element->childNodes as $child) {
$child = $element->ownerDocument->importNode($child, true);
$newElement->appendChild($child);
}
foreach ($element->attributes as $attrName => $attrNode) {
if ($attrNode->namespaceURI === null) {
$newElement->setAttribute($attrName, $attrNode->value);
} else {
$newElement->setAttributeNS($attrNode->namespaceURI, $attrNode->prefix . ':' . $attrName, $attrNode->value);
}
}
$newElement->ownerDocument->replaceChild($newElement, $element);
return $newElement;
} | php | static public function changeElementName(DOMElement $element, $name)
{
$newElement = $element->ownerDocument->createElement($name);
foreach ($element->childNodes as $child) {
$child = $element->ownerDocument->importNode($child, true);
$newElement->appendChild($child);
}
foreach ($element->attributes as $attrName => $attrNode) {
if ($attrNode->namespaceURI === null) {
$newElement->setAttribute($attrName, $attrNode->value);
} else {
$newElement->setAttributeNS($attrNode->namespaceURI, $attrNode->prefix . ':' . $attrName, $attrNode->value);
}
}
$newElement->ownerDocument->replaceChild($newElement, $element);
return $newElement;
} | [
"static",
"public",
"function",
"changeElementName",
"(",
"DOMElement",
"$",
"element",
",",
"$",
"name",
")",
"{",
"$",
"newElement",
"=",
"$",
"element",
"->",
"ownerDocument",
"->",
"createElement",
"(",
"$",
"name",
")",
";",
"foreach",
"(",
"$",
"element",
"->",
"childNodes",
"as",
"$",
"child",
")",
"{",
"$",
"child",
"=",
"$",
"element",
"->",
"ownerDocument",
"->",
"importNode",
"(",
"$",
"child",
",",
"true",
")",
";",
"$",
"newElement",
"->",
"appendChild",
"(",
"$",
"child",
")",
";",
"}",
"foreach",
"(",
"$",
"element",
"->",
"attributes",
"as",
"$",
"attrName",
"=>",
"$",
"attrNode",
")",
"{",
"if",
"(",
"$",
"attrNode",
"->",
"namespaceURI",
"===",
"null",
")",
"{",
"$",
"newElement",
"->",
"setAttribute",
"(",
"$",
"attrName",
",",
"$",
"attrNode",
"->",
"value",
")",
";",
"}",
"else",
"{",
"$",
"newElement",
"->",
"setAttributeNS",
"(",
"$",
"attrNode",
"->",
"namespaceURI",
",",
"$",
"attrNode",
"->",
"prefix",
".",
"':'",
".",
"$",
"attrName",
",",
"$",
"attrNode",
"->",
"value",
")",
";",
"}",
"}",
"$",
"newElement",
"->",
"ownerDocument",
"->",
"replaceChild",
"(",
"$",
"newElement",
",",
"$",
"element",
")",
";",
"return",
"$",
"newElement",
";",
"}"
] | Change the name of $element into $name.
@param \DOMElement $element A DOMElement object you want to change the name.
@param string $name The new name of $element.
@return \DOMElement | [
"Change",
"the",
"name",
"of",
"$element",
"into",
"$name",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/Utils.php#L153-L174 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/Utils.php | Utils.anonimizeElement | static public function anonimizeElement(DOMElement $element)
{
$stack = new SplStack();
$traversed = array();
$children = array();
$stack->push($element);
while ($stack->count() > 0) {
$node = $stack->pop();
if ($node->nodeType === XML_ELEMENT_NODE && $node->childNodes->length > 0 && in_array($node, $traversed, true) === false) {
array_push($traversed, $node);
$stack->push($node);
for ($i = 0; $i < $node->childNodes->length; $i++) {
$stack->push($node->childNodes->item($i));
}
} elseif ($node->nodeType === XML_ELEMENT_NODE && $node->childNodes->length > 0 && in_array($node, $traversed, true) === true) {
// Build hierarchical node copy from the current node. All the attributes
// of $node must be copied into $newNode.
$newNode = $node->ownerDocument->createElement($node->localName);
// Copy all attributes.
foreach ($node->attributes as $attr) {
$newNode->setAttribute($attr->localName, $attr->value);
}
for ($i = 0; $i < $node->childNodes->length; $i++) {
$newNode->appendChild(array_pop($children));
}
array_push($children, $newNode);
} else {
array_push($children, $node->cloneNode());
}
}
return $children[0];
} | php | static public function anonimizeElement(DOMElement $element)
{
$stack = new SplStack();
$traversed = array();
$children = array();
$stack->push($element);
while ($stack->count() > 0) {
$node = $stack->pop();
if ($node->nodeType === XML_ELEMENT_NODE && $node->childNodes->length > 0 && in_array($node, $traversed, true) === false) {
array_push($traversed, $node);
$stack->push($node);
for ($i = 0; $i < $node->childNodes->length; $i++) {
$stack->push($node->childNodes->item($i));
}
} elseif ($node->nodeType === XML_ELEMENT_NODE && $node->childNodes->length > 0 && in_array($node, $traversed, true) === true) {
// Build hierarchical node copy from the current node. All the attributes
// of $node must be copied into $newNode.
$newNode = $node->ownerDocument->createElement($node->localName);
// Copy all attributes.
foreach ($node->attributes as $attr) {
$newNode->setAttribute($attr->localName, $attr->value);
}
for ($i = 0; $i < $node->childNodes->length; $i++) {
$newNode->appendChild(array_pop($children));
}
array_push($children, $newNode);
} else {
array_push($children, $node->cloneNode());
}
}
return $children[0];
} | [
"static",
"public",
"function",
"anonimizeElement",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"$",
"stack",
"=",
"new",
"SplStack",
"(",
")",
";",
"$",
"traversed",
"=",
"array",
"(",
")",
";",
"$",
"children",
"=",
"array",
"(",
")",
";",
"$",
"stack",
"->",
"push",
"(",
"$",
"element",
")",
";",
"while",
"(",
"$",
"stack",
"->",
"count",
"(",
")",
">",
"0",
")",
"{",
"$",
"node",
"=",
"$",
"stack",
"->",
"pop",
"(",
")",
";",
"if",
"(",
"$",
"node",
"->",
"nodeType",
"===",
"XML_ELEMENT_NODE",
"&&",
"$",
"node",
"->",
"childNodes",
"->",
"length",
">",
"0",
"&&",
"in_array",
"(",
"$",
"node",
",",
"$",
"traversed",
",",
"true",
")",
"===",
"false",
")",
"{",
"array_push",
"(",
"$",
"traversed",
",",
"$",
"node",
")",
";",
"$",
"stack",
"->",
"push",
"(",
"$",
"node",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"node",
"->",
"childNodes",
"->",
"length",
";",
"$",
"i",
"++",
")",
"{",
"$",
"stack",
"->",
"push",
"(",
"$",
"node",
"->",
"childNodes",
"->",
"item",
"(",
"$",
"i",
")",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"node",
"->",
"nodeType",
"===",
"XML_ELEMENT_NODE",
"&&",
"$",
"node",
"->",
"childNodes",
"->",
"length",
">",
"0",
"&&",
"in_array",
"(",
"$",
"node",
",",
"$",
"traversed",
",",
"true",
")",
"===",
"true",
")",
"{",
"// Build hierarchical node copy from the current node. All the attributes",
"// of $node must be copied into $newNode.",
"$",
"newNode",
"=",
"$",
"node",
"->",
"ownerDocument",
"->",
"createElement",
"(",
"$",
"node",
"->",
"localName",
")",
";",
"// Copy all attributes.",
"foreach",
"(",
"$",
"node",
"->",
"attributes",
"as",
"$",
"attr",
")",
"{",
"$",
"newNode",
"->",
"setAttribute",
"(",
"$",
"attr",
"->",
"localName",
",",
"$",
"attr",
"->",
"value",
")",
";",
"}",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"node",
"->",
"childNodes",
"->",
"length",
";",
"$",
"i",
"++",
")",
"{",
"$",
"newNode",
"->",
"appendChild",
"(",
"array_pop",
"(",
"$",
"children",
")",
")",
";",
"}",
"array_push",
"(",
"$",
"children",
",",
"$",
"newNode",
")",
";",
"}",
"else",
"{",
"array_push",
"(",
"$",
"children",
",",
"$",
"node",
"->",
"cloneNode",
"(",
")",
")",
";",
"}",
"}",
"return",
"$",
"children",
"[",
"0",
"]",
";",
"}"
] | Anonimize a given DOMElement. By 'anonimize', we mean remove
all namespace membership of an element and its child nodes.
For instance, <m:math display="inline"><m:mi>x</m:mi></m:math> becomes
<math display="inline"><mi>x</mi></math>.
@param \DOMElement $element The DOMElement to be anonimized.
@return \DOMElement The anonimized DOMElement copy of $element. | [
"Anonimize",
"a",
"given",
"DOMElement",
".",
"By",
"anonimize",
"we",
"mean",
"remove",
"all",
"namespace",
"membership",
"of",
"an",
"element",
"and",
"its",
"child",
"nodes",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/Utils.php#L186-L225 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/Utils.php | Utils.importChildNodes | static public function importChildNodes(DOMElement $from, DOMElement $into, $deep = true)
{
for ($i = 0; $i < $from->childNodes->length; $i++) {
$node = $into->ownerDocument->importNode($from->childNodes->item($i), $deep);
$into->appendChild($node);
}
} | php | static public function importChildNodes(DOMElement $from, DOMElement $into, $deep = true)
{
for ($i = 0; $i < $from->childNodes->length; $i++) {
$node = $into->ownerDocument->importNode($from->childNodes->item($i), $deep);
$into->appendChild($node);
}
} | [
"static",
"public",
"function",
"importChildNodes",
"(",
"DOMElement",
"$",
"from",
",",
"DOMElement",
"$",
"into",
",",
"$",
"deep",
"=",
"true",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"from",
"->",
"childNodes",
"->",
"length",
";",
"$",
"i",
"++",
")",
"{",
"$",
"node",
"=",
"$",
"into",
"->",
"ownerDocument",
"->",
"importNode",
"(",
"$",
"from",
"->",
"childNodes",
"->",
"item",
"(",
"$",
"i",
")",
",",
"$",
"deep",
")",
";",
"$",
"into",
"->",
"appendChild",
"(",
"$",
"node",
")",
";",
"}",
"}"
] | Import all the child nodes of DOMElement $from to DOMElement $into.
@param \DOMElement $from The source DOMElement.
@param \DOMElement $into The target DOMElement.
@param boolean $deep Whether or not to import the whole node hierarchy. | [
"Import",
"all",
"the",
"child",
"nodes",
"of",
"DOMElement",
"$from",
"to",
"DOMElement",
"$into",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/Utils.php#L234-L240 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/Utils.php | Utils.importAttributes | static public function importAttributes(DOMElement $from, DOMElement $into)
{
for ($i = 0; $i < $from->attributes->length; $i++) {
$attr = $from->attributes->item($i);
if ($attr->localName !== 'schemaLocation') {
if (empty($attr->namespaceURI) === false) {
$into->setAttributeNS($attr->namespaceURI, $attr->prefix . ':' . $attr->localName, $attr->value);
} else {
$into->setAttribute($attr->localName, $attr->value);
}
}
}
} | php | static public function importAttributes(DOMElement $from, DOMElement $into)
{
for ($i = 0; $i < $from->attributes->length; $i++) {
$attr = $from->attributes->item($i);
if ($attr->localName !== 'schemaLocation') {
if (empty($attr->namespaceURI) === false) {
$into->setAttributeNS($attr->namespaceURI, $attr->prefix . ':' . $attr->localName, $attr->value);
} else {
$into->setAttribute($attr->localName, $attr->value);
}
}
}
} | [
"static",
"public",
"function",
"importAttributes",
"(",
"DOMElement",
"$",
"from",
",",
"DOMElement",
"$",
"into",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"from",
"->",
"attributes",
"->",
"length",
";",
"$",
"i",
"++",
")",
"{",
"$",
"attr",
"=",
"$",
"from",
"->",
"attributes",
"->",
"item",
"(",
"$",
"i",
")",
";",
"if",
"(",
"$",
"attr",
"->",
"localName",
"!==",
"'schemaLocation'",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"attr",
"->",
"namespaceURI",
")",
"===",
"false",
")",
"{",
"$",
"into",
"->",
"setAttributeNS",
"(",
"$",
"attr",
"->",
"namespaceURI",
",",
"$",
"attr",
"->",
"prefix",
".",
"':'",
".",
"$",
"attr",
"->",
"localName",
",",
"$",
"attr",
"->",
"value",
")",
";",
"}",
"else",
"{",
"$",
"into",
"->",
"setAttribute",
"(",
"$",
"attr",
"->",
"localName",
",",
"$",
"attr",
"->",
"value",
")",
";",
"}",
"}",
"}",
"}"
] | Import (gracefully i.e. by respecting namespaces) the attributes of DOMElement $from to
DOMElement $into.
@param \DOMElement $from The source DOMElement.
@param \DOMElement $into The target DOMElement. | [
"Import",
"(",
"gracefully",
"i",
".",
"e",
".",
"by",
"respecting",
"namespaces",
")",
"the",
"attributes",
"of",
"DOMElement",
"$from",
"to",
"DOMElement",
"$into",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/Utils.php#L249-L263 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/Utils.php | Utils.escapeXmlSpecialChars | static public function escapeXmlSpecialChars($string, $isAttribute = false)
{
if ($isAttribute === false) {
$fullSearch = array('"', "'", '<', '>');
$fullReplace = array('"', ''', '<', '>');
$string = str_replace('&', '&', $string);
$string = str_replace($fullSearch, $fullReplace, $string);
return $string;
} else {
$string = str_replace('&', '&', $string);
$string = str_replace('"', '"', $string);
return $string;
}
} | php | static public function escapeXmlSpecialChars($string, $isAttribute = false)
{
if ($isAttribute === false) {
$fullSearch = array('"', "'", '<', '>');
$fullReplace = array('"', ''', '<', '>');
$string = str_replace('&', '&', $string);
$string = str_replace($fullSearch, $fullReplace, $string);
return $string;
} else {
$string = str_replace('&', '&', $string);
$string = str_replace('"', '"', $string);
return $string;
}
} | [
"static",
"public",
"function",
"escapeXmlSpecialChars",
"(",
"$",
"string",
",",
"$",
"isAttribute",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"isAttribute",
"===",
"false",
")",
"{",
"$",
"fullSearch",
"=",
"array",
"(",
"'\"'",
",",
"\"'\"",
",",
"'<'",
",",
"'>'",
")",
";",
"$",
"fullReplace",
"=",
"array",
"(",
"'"'",
",",
"'''",
",",
"'<'",
",",
"'>'",
")",
";",
"$",
"string",
"=",
"str_replace",
"(",
"'&'",
",",
"'&'",
",",
"$",
"string",
")",
";",
"$",
"string",
"=",
"str_replace",
"(",
"$",
"fullSearch",
",",
"$",
"fullReplace",
",",
"$",
"string",
")",
";",
"return",
"$",
"string",
";",
"}",
"else",
"{",
"$",
"string",
"=",
"str_replace",
"(",
"'&'",
",",
"'&'",
",",
"$",
"string",
")",
";",
"$",
"string",
"=",
"str_replace",
"(",
"'\"'",
",",
"'"'",
",",
"$",
"string",
")",
";",
"return",
"$",
"string",
";",
"}",
"}"
] | Escape XML Special characters from a given string.
The list below describe each escaped character and its replacement.
* " --> "
* ' --> '
* < --> <
* > --> $gt;
* & --> &
@param string $string An input string.
@param boolean $isAttribute Whether or not to escape ', >, < which do not have to be escaped in attributes.
@return string An escaped string. | [
"Escape",
"XML",
"Special",
"characters",
"from",
"a",
"given",
"string",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/Utils.php#L280-L293 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/Utils.php | Utils.qtiFriendlyName | static public function qtiFriendlyName($wcName)
{
$qtiName = strtolower($wcName);
$qtiName = preg_replace('/^qti-/', '', $qtiName);
return lcfirst(str_replace('-', '', ucwords($qtiName, '-')));
} | php | static public function qtiFriendlyName($wcName)
{
$qtiName = strtolower($wcName);
$qtiName = preg_replace('/^qti-/', '', $qtiName);
return lcfirst(str_replace('-', '', ucwords($qtiName, '-')));
} | [
"static",
"public",
"function",
"qtiFriendlyName",
"(",
"$",
"wcName",
")",
"{",
"$",
"qtiName",
"=",
"strtolower",
"(",
"$",
"wcName",
")",
";",
"$",
"qtiName",
"=",
"preg_replace",
"(",
"'/^qti-/'",
",",
"''",
",",
"$",
"qtiName",
")",
";",
"return",
"lcfirst",
"(",
"str_replace",
"(",
"'-'",
",",
"''",
",",
"ucwords",
"(",
"$",
"qtiName",
",",
"'-'",
")",
")",
")",
";",
"}"
] | QTI friendly name of a Web Component friendly name.
This method returns the QTI friendly name of a Web Component friendly name.
Example: "qti-choice-interaction" becomes "choiceInteraction".
@param string $wcName
@return string | [
"QTI",
"friendly",
"name",
"of",
"a",
"Web",
"Component",
"friendly",
"name",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/Utils.php#L335-L341 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/Utils.php | Utils.getDOMElementAttributeAs | public static function getDOMElementAttributeAs(DOMElement $element, $attribute, $datatype = 'string')
{
$attr = $element->getAttribute($attribute);
if ($attr !== '') {
switch ($datatype) {
case 'string':
return $attr;
break;
case 'integer':
return intval($attr);
break;
case 'float':
return floatval($attr);
break;
case 'double':
return doubleval($attr);
break;
case 'boolean':
return ($attr == 'true') ? true : false;
break;
default:
throw new \InvalidArgumentException("Unknown datatype '${datatype}'.");
break;
}
} else {
return null;
}
} | php | public static function getDOMElementAttributeAs(DOMElement $element, $attribute, $datatype = 'string')
{
$attr = $element->getAttribute($attribute);
if ($attr !== '') {
switch ($datatype) {
case 'string':
return $attr;
break;
case 'integer':
return intval($attr);
break;
case 'float':
return floatval($attr);
break;
case 'double':
return doubleval($attr);
break;
case 'boolean':
return ($attr == 'true') ? true : false;
break;
default:
throw new \InvalidArgumentException("Unknown datatype '${datatype}'.");
break;
}
} else {
return null;
}
} | [
"public",
"static",
"function",
"getDOMElementAttributeAs",
"(",
"DOMElement",
"$",
"element",
",",
"$",
"attribute",
",",
"$",
"datatype",
"=",
"'string'",
")",
"{",
"$",
"attr",
"=",
"$",
"element",
"->",
"getAttribute",
"(",
"$",
"attribute",
")",
";",
"if",
"(",
"$",
"attr",
"!==",
"''",
")",
"{",
"switch",
"(",
"$",
"datatype",
")",
"{",
"case",
"'string'",
":",
"return",
"$",
"attr",
";",
"break",
";",
"case",
"'integer'",
":",
"return",
"intval",
"(",
"$",
"attr",
")",
";",
"break",
";",
"case",
"'float'",
":",
"return",
"floatval",
"(",
"$",
"attr",
")",
";",
"break",
";",
"case",
"'double'",
":",
"return",
"doubleval",
"(",
"$",
"attr",
")",
";",
"break",
";",
"case",
"'boolean'",
":",
"return",
"(",
"$",
"attr",
"==",
"'true'",
")",
"?",
"true",
":",
"false",
";",
"break",
";",
"default",
":",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Unknown datatype '${datatype}'.\"",
")",
";",
"break",
";",
"}",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] | Get the attribute value of a given DOMElement object, cast in a given datatype.
@param DOMElement $element The element the attribute you want to retrieve the value is bound to.
@param string $attribute The attribute name.
@param string $datatype The returned datatype. Accepted values are 'string', 'integer', 'float', 'double' and 'boolean'.
@throws \InvalidArgumentException If $datatype is not in the range of possible values.
@return mixed The attribute value with the provided $datatype, or null if the attribute does not exist in $element. | [
"Get",
"the",
"attribute",
"value",
"of",
"a",
"given",
"DOMElement",
"object",
"cast",
"in",
"a",
"given",
"datatype",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/Utils.php#L352-L385 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/Utils.php | Utils.setDOMElementAttribute | public static function setDOMElementAttribute(DOMElement $element, $attribute, $value)
{
switch (gettype($value)) {
case 'boolean':
$element->setAttribute($attribute, ($value === true) ? 'true' : 'false');
break;
default:
$element->setAttribute($attribute, '' . $value);
break;
}
} | php | public static function setDOMElementAttribute(DOMElement $element, $attribute, $value)
{
switch (gettype($value)) {
case 'boolean':
$element->setAttribute($attribute, ($value === true) ? 'true' : 'false');
break;
default:
$element->setAttribute($attribute, '' . $value);
break;
}
} | [
"public",
"static",
"function",
"setDOMElementAttribute",
"(",
"DOMElement",
"$",
"element",
",",
"$",
"attribute",
",",
"$",
"value",
")",
"{",
"switch",
"(",
"gettype",
"(",
"$",
"value",
")",
")",
"{",
"case",
"'boolean'",
":",
"$",
"element",
"->",
"setAttribute",
"(",
"$",
"attribute",
",",
"(",
"$",
"value",
"===",
"true",
")",
"?",
"'true'",
":",
"'false'",
")",
";",
"break",
";",
"default",
":",
"$",
"element",
"->",
"setAttribute",
"(",
"$",
"attribute",
",",
"''",
".",
"$",
"value",
")",
";",
"break",
";",
"}",
"}"
] | Set the attribute value of a given DOMElement object. Boolean values will be transformed
@param DOMElement $element A DOMElement object.
@param string $attribute An XML attribute name.
@param mixed $value A given value. | [
"Set",
"the",
"attribute",
"value",
"of",
"a",
"given",
"DOMElement",
"object",
".",
"Boolean",
"values",
"will",
"be",
"transformed"
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/Utils.php#L394-L405 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/Utils.php | Utils.getChildElementsByTagName | public static function getChildElementsByTagName($element, $tagName, $exclude = false, $withText = false)
{
if (!is_array($tagName)) {
$tagName = array($tagName);
}
$rawElts = self::getChildElements($element, $withText);
$returnValue = array();
foreach ($rawElts as $elt) {
if (in_array($elt->localName, $tagName) === !$exclude) {
$returnValue[] = $elt;
}
}
return $returnValue;
} | php | public static function getChildElementsByTagName($element, $tagName, $exclude = false, $withText = false)
{
if (!is_array($tagName)) {
$tagName = array($tagName);
}
$rawElts = self::getChildElements($element, $withText);
$returnValue = array();
foreach ($rawElts as $elt) {
if (in_array($elt->localName, $tagName) === !$exclude) {
$returnValue[] = $elt;
}
}
return $returnValue;
} | [
"public",
"static",
"function",
"getChildElementsByTagName",
"(",
"$",
"element",
",",
"$",
"tagName",
",",
"$",
"exclude",
"=",
"false",
",",
"$",
"withText",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"tagName",
")",
")",
"{",
"$",
"tagName",
"=",
"array",
"(",
"$",
"tagName",
")",
";",
"}",
"$",
"rawElts",
"=",
"self",
"::",
"getChildElements",
"(",
"$",
"element",
",",
"$",
"withText",
")",
";",
"$",
"returnValue",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"rawElts",
"as",
"$",
"elt",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"elt",
"->",
"localName",
",",
"$",
"tagName",
")",
"===",
"!",
"$",
"exclude",
")",
"{",
"$",
"returnValue",
"[",
"]",
"=",
"$",
"elt",
";",
"}",
"}",
"return",
"$",
"returnValue",
";",
"}"
] | Get the child elements of a given element by tag name. This method does
not behave like DOMElement::getElementsByTagName. It only returns the direct
child elements that matches $tagName but does not go recursive.
@param DOMElement $element A DOMElement object.
@param mixed $tagName The name of the tags you would like to retrieve or an array of tags to match.
@param boolean $exclude (optional) Wether the $tagName parameter must be considered as a blacklist.
@param boolean $withText (optional) Wether text nodes must be returned or not.
@return array An array of DOMElement objects. | [
"Get",
"the",
"child",
"elements",
"of",
"a",
"given",
"element",
"by",
"tag",
"name",
".",
"This",
"method",
"does",
"not",
"behave",
"like",
"DOMElement",
"::",
"getElementsByTagName",
".",
"It",
"only",
"returns",
"the",
"direct",
"child",
"elements",
"that",
"matches",
"$tagName",
"but",
"does",
"not",
"go",
"recursive",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/Utils.php#L418-L434 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/Utils.php | Utils.getChildElements | public static function getChildElements($element, $withText = false)
{
$children = $element->childNodes;
$returnValue = array();
for ($i = 0; $i < $children->length; $i++) {
if ($children->item($i)->nodeType === XML_ELEMENT_NODE || ($withText === true && ($children->item($i)->nodeType === XML_TEXT_NODE || $children->item($i)->nodeType === XML_CDATA_SECTION_NODE))) {
$returnValue[] = $children->item($i);
}
}
return $returnValue;
} | php | public static function getChildElements($element, $withText = false)
{
$children = $element->childNodes;
$returnValue = array();
for ($i = 0; $i < $children->length; $i++) {
if ($children->item($i)->nodeType === XML_ELEMENT_NODE || ($withText === true && ($children->item($i)->nodeType === XML_TEXT_NODE || $children->item($i)->nodeType === XML_CDATA_SECTION_NODE))) {
$returnValue[] = $children->item($i);
}
}
return $returnValue;
} | [
"public",
"static",
"function",
"getChildElements",
"(",
"$",
"element",
",",
"$",
"withText",
"=",
"false",
")",
"{",
"$",
"children",
"=",
"$",
"element",
"->",
"childNodes",
";",
"$",
"returnValue",
"=",
"array",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"children",
"->",
"length",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"$",
"children",
"->",
"item",
"(",
"$",
"i",
")",
"->",
"nodeType",
"===",
"XML_ELEMENT_NODE",
"||",
"(",
"$",
"withText",
"===",
"true",
"&&",
"(",
"$",
"children",
"->",
"item",
"(",
"$",
"i",
")",
"->",
"nodeType",
"===",
"XML_TEXT_NODE",
"||",
"$",
"children",
"->",
"item",
"(",
"$",
"i",
")",
"->",
"nodeType",
"===",
"XML_CDATA_SECTION_NODE",
")",
")",
")",
"{",
"$",
"returnValue",
"[",
"]",
"=",
"$",
"children",
"->",
"item",
"(",
"$",
"i",
")",
";",
"}",
"}",
"return",
"$",
"returnValue",
";",
"}"
] | Get the children DOM Nodes with nodeType attribute equals to XML_ELEMENT_NODE.
@param DOMElement $element A DOMElement object.
@param boolean $withText Wether text nodes must be returned or not.
@return array An array of DOMNode objects. | [
"Get",
"the",
"children",
"DOM",
"Nodes",
"with",
"nodeType",
"attribute",
"equals",
"to",
"XML_ELEMENT_NODE",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/Utils.php#L443-L455 |
oat-sa/qti-sdk | src/qtism/data/content/xhtml/tables/Tbody.php | Tbody.setContent | public function setContent(TrCollection $content)
{
if (count($content) > 0) {
$this->content = $content;
} else {
$msg = "A Tbody object must be composed of at least 1 Tr object, none given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setContent(TrCollection $content)
{
if (count($content) > 0) {
$this->content = $content;
} else {
$msg = "A Tbody object must be composed of at least 1 Tr object, none given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setContent",
"(",
"TrCollection",
"$",
"content",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"content",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"content",
"=",
"$",
"content",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"A Tbody object must be composed of at least 1 Tr object, none given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the collection of Tr objects composing the Tbody.
@param \qtism\data\content\xhtml\tables\TrCollection $content A non-empty TrCollection object.
@throws \InvalidArgumentException If $components is empty. | [
"Set",
"the",
"collection",
"of",
"Tr",
"objects",
"composing",
"the",
"Tbody",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/xhtml/tables/Tbody.php#L66-L74 |
oat-sa/qti-sdk | src/qtism/data/storage/php/marshalling/PhpScalarMarshaller.php | PhpScalarMarshaller.marshall | public function marshall()
{
$ctx = $this->getContext();
$streamAccess = $ctx->getStreamAccess();
try {
$scalar = $this->getToMarshall();
$varName = $this->getContext()->generateVariableName($scalar);
$streamAccess->writeVariable($varName);
$streamAccess->writeEquals($ctx->mustFormatOutput());
$streamAccess->writeScalar($scalar);
$streamAccess->writeSemicolon($ctx->mustFormatOutput());
$ctx->pushOnVariableStack($varName);
} catch (StreamAccessException $e) {
$msg = "An error occured while marshalling the scalar value '${scalar}'.";
throw new PhpMarshallingException($msg, PhpMarshallingException::STREAM, $e);
}
} | php | public function marshall()
{
$ctx = $this->getContext();
$streamAccess = $ctx->getStreamAccess();
try {
$scalar = $this->getToMarshall();
$varName = $this->getContext()->generateVariableName($scalar);
$streamAccess->writeVariable($varName);
$streamAccess->writeEquals($ctx->mustFormatOutput());
$streamAccess->writeScalar($scalar);
$streamAccess->writeSemicolon($ctx->mustFormatOutput());
$ctx->pushOnVariableStack($varName);
} catch (StreamAccessException $e) {
$msg = "An error occured while marshalling the scalar value '${scalar}'.";
throw new PhpMarshallingException($msg, PhpMarshallingException::STREAM, $e);
}
} | [
"public",
"function",
"marshall",
"(",
")",
"{",
"$",
"ctx",
"=",
"$",
"this",
"->",
"getContext",
"(",
")",
";",
"$",
"streamAccess",
"=",
"$",
"ctx",
"->",
"getStreamAccess",
"(",
")",
";",
"try",
"{",
"$",
"scalar",
"=",
"$",
"this",
"->",
"getToMarshall",
"(",
")",
";",
"$",
"varName",
"=",
"$",
"this",
"->",
"getContext",
"(",
")",
"->",
"generateVariableName",
"(",
"$",
"scalar",
")",
";",
"$",
"streamAccess",
"->",
"writeVariable",
"(",
"$",
"varName",
")",
";",
"$",
"streamAccess",
"->",
"writeEquals",
"(",
"$",
"ctx",
"->",
"mustFormatOutput",
"(",
")",
")",
";",
"$",
"streamAccess",
"->",
"writeScalar",
"(",
"$",
"scalar",
")",
";",
"$",
"streamAccess",
"->",
"writeSemicolon",
"(",
"$",
"ctx",
"->",
"mustFormatOutput",
"(",
")",
")",
";",
"$",
"ctx",
"->",
"pushOnVariableStack",
"(",
"$",
"varName",
")",
";",
"}",
"catch",
"(",
"StreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while marshalling the scalar value '${scalar}'.\"",
";",
"throw",
"new",
"PhpMarshallingException",
"(",
"$",
"msg",
",",
"PhpMarshallingException",
"::",
"STREAM",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Marshall the PHP scalar value to be marshalled into PHP source code.
@throws \qtism\data\storage\php\marshalling\PhpMarshallingException If an error occurs while marshalling. | [
"Marshall",
"the",
"PHP",
"scalar",
"value",
"to",
"be",
"marshalled",
"into",
"PHP",
"source",
"code",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/php/marshalling/PhpScalarMarshaller.php#L63-L82 |
oat-sa/qti-sdk | src/qtism/runtime/common/AbstractEngine.php | AbstractEngine.trace | protected function trace($message)
{
$item = new StackTraceItem($this->getComponent(), $message);
$this->stackTrace->push($item);
} | php | protected function trace($message)
{
$item = new StackTraceItem($this->getComponent(), $message);
$this->stackTrace->push($item);
} | [
"protected",
"function",
"trace",
"(",
"$",
"message",
")",
"{",
"$",
"item",
"=",
"new",
"StackTraceItem",
"(",
"$",
"this",
"->",
"getComponent",
"(",
")",
",",
"$",
"message",
")",
";",
"$",
"this",
"->",
"stackTrace",
"->",
"push",
"(",
"$",
"item",
")",
";",
"}"
] | Add an entry in the stack trace about the QtiComponent being
processed.
@param string $message A trace message. | [
"Add",
"an",
"entry",
"in",
"the",
"stack",
"trace",
"about",
"the",
"QtiComponent",
"being",
"processed",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/common/AbstractEngine.php#L140-L144 |
oat-sa/qti-sdk | src/qtism/runtime/common/ResponseVariable.php | ResponseVariable.setCorrectResponse | public function setCorrectResponse(QtiDatatype $correctResponse = null)
{
if ($correctResponse === null) {
$this->correctResponse = null;
} elseif (Utils::isBaseTypeCompliant($this->getBaseType(), $correctResponse) === true && Utils::isCardinalityCompliant($this->getCardinality(), $correctResponse) === true) {
$this->correctResponse = $correctResponse;
} else {
$msg = "The given correct response is not compliant with the associated response variable.";
throw new InvalidArgumentException($msg);
}
} | php | public function setCorrectResponse(QtiDatatype $correctResponse = null)
{
if ($correctResponse === null) {
$this->correctResponse = null;
} elseif (Utils::isBaseTypeCompliant($this->getBaseType(), $correctResponse) === true && Utils::isCardinalityCompliant($this->getCardinality(), $correctResponse) === true) {
$this->correctResponse = $correctResponse;
} else {
$msg = "The given correct response is not compliant with the associated response variable.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setCorrectResponse",
"(",
"QtiDatatype",
"$",
"correctResponse",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"correctResponse",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"correctResponse",
"=",
"null",
";",
"}",
"elseif",
"(",
"Utils",
"::",
"isBaseTypeCompliant",
"(",
"$",
"this",
"->",
"getBaseType",
"(",
")",
",",
"$",
"correctResponse",
")",
"===",
"true",
"&&",
"Utils",
"::",
"isCardinalityCompliant",
"(",
"$",
"this",
"->",
"getCardinality",
"(",
")",
",",
"$",
"correctResponse",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"correctResponse",
"=",
"$",
"correctResponse",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The given correct response is not compliant with the associated response variable.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the correct response.
@param \qtism\common\datatypes\QtiDatatype|null $correctResponse A QtiDatatype object or null.
@throws \InvalidArgumentException If $correctResponse does not match baseType and/or cardinality of the variable. | [
"Set",
"the",
"correct",
"response",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/common/ResponseVariable.php#L97-L107 |
oat-sa/qti-sdk | src/qtism/runtime/common/ResponseVariable.php | ResponseVariable.isCorrect | public function isCorrect()
{
if ($this->hasCorrectResponse() === true) {
$correctResponse = $this->getCorrectResponse();
if ($correctResponse instanceof Comparable) {
return $correctResponse->equals($this->getValue());
} else {
return $correctResponse === $this->getValue();
}
}
return false;
} | php | public function isCorrect()
{
if ($this->hasCorrectResponse() === true) {
$correctResponse = $this->getCorrectResponse();
if ($correctResponse instanceof Comparable) {
return $correctResponse->equals($this->getValue());
} else {
return $correctResponse === $this->getValue();
}
}
return false;
} | [
"public",
"function",
"isCorrect",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasCorrectResponse",
"(",
")",
"===",
"true",
")",
"{",
"$",
"correctResponse",
"=",
"$",
"this",
"->",
"getCorrectResponse",
"(",
")",
";",
"if",
"(",
"$",
"correctResponse",
"instanceof",
"Comparable",
")",
"{",
"return",
"$",
"correctResponse",
"->",
"equals",
"(",
"$",
"this",
"->",
"getValue",
"(",
")",
")",
";",
"}",
"else",
"{",
"return",
"$",
"correctResponse",
"===",
"$",
"this",
"->",
"getValue",
"(",
")",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Whether the value of the ResponseVariable matches its
correct response.
@return boolean | [
"Whether",
"the",
"value",
"of",
"the",
"ResponseVariable",
"matches",
"its",
"correct",
"response",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/common/ResponseVariable.php#L175-L188 |
oat-sa/qti-sdk | src/qtism/runtime/common/ResponseVariable.php | ResponseVariable.createFromDataModel | public static function createFromDataModel(VariableDeclaration $variableDeclaration)
{
$variable = parent::createFromDataModel($variableDeclaration);
if ($variableDeclaration instanceof ResponseDeclaration) {
$variable->setMapping($variableDeclaration->getMapping());
$variable->setAreaMapping($variableDeclaration->getAreaMapping());
$dataModelCorrectResponse = $variableDeclaration->getCorrectResponse();
if (!empty($dataModelCorrectResponse)) {
$baseType = $variable->getBaseType();
$cardinality = $variable->getCardinality();
$dataModelValues = $dataModelCorrectResponse->getValues();
$correctResponse = static::dataModelValuesToRuntime($dataModelValues, $baseType, $cardinality);
$variable->setCorrectResponse($correctResponse);
}
return $variable;
} else {
$msg = "ResponseVariable::createFromDataModel only accept 'qtism\\data\\state\\ResponseDeclaration' objects, '" . get_class($variableDeclaration) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public static function createFromDataModel(VariableDeclaration $variableDeclaration)
{
$variable = parent::createFromDataModel($variableDeclaration);
if ($variableDeclaration instanceof ResponseDeclaration) {
$variable->setMapping($variableDeclaration->getMapping());
$variable->setAreaMapping($variableDeclaration->getAreaMapping());
$dataModelCorrectResponse = $variableDeclaration->getCorrectResponse();
if (!empty($dataModelCorrectResponse)) {
$baseType = $variable->getBaseType();
$cardinality = $variable->getCardinality();
$dataModelValues = $dataModelCorrectResponse->getValues();
$correctResponse = static::dataModelValuesToRuntime($dataModelValues, $baseType, $cardinality);
$variable->setCorrectResponse($correctResponse);
}
return $variable;
} else {
$msg = "ResponseVariable::createFromDataModel only accept 'qtism\\data\\state\\ResponseDeclaration' objects, '" . get_class($variableDeclaration) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"static",
"function",
"createFromDataModel",
"(",
"VariableDeclaration",
"$",
"variableDeclaration",
")",
"{",
"$",
"variable",
"=",
"parent",
"::",
"createFromDataModel",
"(",
"$",
"variableDeclaration",
")",
";",
"if",
"(",
"$",
"variableDeclaration",
"instanceof",
"ResponseDeclaration",
")",
"{",
"$",
"variable",
"->",
"setMapping",
"(",
"$",
"variableDeclaration",
"->",
"getMapping",
"(",
")",
")",
";",
"$",
"variable",
"->",
"setAreaMapping",
"(",
"$",
"variableDeclaration",
"->",
"getAreaMapping",
"(",
")",
")",
";",
"$",
"dataModelCorrectResponse",
"=",
"$",
"variableDeclaration",
"->",
"getCorrectResponse",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"dataModelCorrectResponse",
")",
")",
"{",
"$",
"baseType",
"=",
"$",
"variable",
"->",
"getBaseType",
"(",
")",
";",
"$",
"cardinality",
"=",
"$",
"variable",
"->",
"getCardinality",
"(",
")",
";",
"$",
"dataModelValues",
"=",
"$",
"dataModelCorrectResponse",
"->",
"getValues",
"(",
")",
";",
"$",
"correctResponse",
"=",
"static",
"::",
"dataModelValuesToRuntime",
"(",
"$",
"dataModelValues",
",",
"$",
"baseType",
",",
"$",
"cardinality",
")",
";",
"$",
"variable",
"->",
"setCorrectResponse",
"(",
"$",
"correctResponse",
")",
";",
"}",
"return",
"$",
"variable",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"ResponseVariable::createFromDataModel only accept 'qtism\\\\data\\\\state\\\\ResponseDeclaration' objects, '\"",
".",
"get_class",
"(",
"$",
"variableDeclaration",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Create a ResponseVariable object from its data model representation.
@param \qtism\data\state\VariableDeclaration $variableDeclaration
@throws \InvalidArgumentException
@return \qtism\runtime\common\ResponseVariable | [
"Create",
"a",
"ResponseVariable",
"object",
"from",
"its",
"data",
"model",
"representation",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/common/ResponseVariable.php#L197-L221 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/MathOperatorProcessor.php | MathOperatorProcessor.process | public function process()
{
$operands = $this->getOperands();
if ($operands->containsNull() === true) {
return null;
}
if ($operands->exclusivelySingle() === false) {
$msg = "The MathOperator operator only accepts operands with a single cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
if ($operands->exclusivelyNumeric() === false) {
$msg = "The MathOperator operator only accepts operands with an integer or float baseType.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
}
$qtiFuncName = MathFunctions::getNameByConstant($this->getExpression()->getName());
$methodName = 'process' . ucfirst($qtiFuncName);
$result = call_user_func_array(array($this, $methodName), array());
if ($result instanceof QtiFloat && is_nan($result->getValue()) === true) {
// outside the domain of the function.
return null;
} else {
return $result;
}
} | php | public function process()
{
$operands = $this->getOperands();
if ($operands->containsNull() === true) {
return null;
}
if ($operands->exclusivelySingle() === false) {
$msg = "The MathOperator operator only accepts operands with a single cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
if ($operands->exclusivelyNumeric() === false) {
$msg = "The MathOperator operator only accepts operands with an integer or float baseType.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
}
$qtiFuncName = MathFunctions::getNameByConstant($this->getExpression()->getName());
$methodName = 'process' . ucfirst($qtiFuncName);
$result = call_user_func_array(array($this, $methodName), array());
if ($result instanceof QtiFloat && is_nan($result->getValue()) === true) {
// outside the domain of the function.
return null;
} else {
return $result;
}
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"operands",
"=",
"$",
"this",
"->",
"getOperands",
"(",
")",
";",
"if",
"(",
"$",
"operands",
"->",
"containsNull",
"(",
")",
"===",
"true",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"operands",
"->",
"exclusivelySingle",
"(",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The MathOperator operator only accepts operands with a single cardinality.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_CARDINALITY",
")",
";",
"}",
"if",
"(",
"$",
"operands",
"->",
"exclusivelyNumeric",
"(",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The MathOperator operator only accepts operands with an integer or float baseType.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_BASETYPE",
")",
";",
"}",
"$",
"qtiFuncName",
"=",
"MathFunctions",
"::",
"getNameByConstant",
"(",
"$",
"this",
"->",
"getExpression",
"(",
")",
"->",
"getName",
"(",
")",
")",
";",
"$",
"methodName",
"=",
"'process'",
".",
"ucfirst",
"(",
"$",
"qtiFuncName",
")",
";",
"$",
"result",
"=",
"call_user_func_array",
"(",
"array",
"(",
"$",
"this",
",",
"$",
"methodName",
")",
",",
"array",
"(",
")",
")",
";",
"if",
"(",
"$",
"result",
"instanceof",
"QtiFloat",
"&&",
"is_nan",
"(",
"$",
"result",
"->",
"getValue",
"(",
")",
")",
"===",
"true",
")",
"{",
"// outside the domain of the function.",
"return",
"null",
";",
"}",
"else",
"{",
"return",
"$",
"result",
";",
"}",
"}"
] | Process the MathOperator operator.
@return float|integer|null The result of the MathOperator call or NULL if any of the sub-expressions is NULL. See the class documentation for special cases. | [
"Process",
"the",
"MathOperator",
"operator",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/MathOperatorProcessor.php#L85-L113 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/MathOperatorProcessor.php | MathOperatorProcessor.processSignum | protected function processSignum()
{
$operands = $this->getOperands();
$operand = $operands[0];
if (is_nan($operand->getValue())) {
return null;
} elseif ($operand->getValue() < 0) {
return new QtiInteger(-1);
} elseif ($operand->getValue() > 0) {
return new QtiInteger(1);
} else {
return new QtiInteger(0);
}
} | php | protected function processSignum()
{
$operands = $this->getOperands();
$operand = $operands[0];
if (is_nan($operand->getValue())) {
return null;
} elseif ($operand->getValue() < 0) {
return new QtiInteger(-1);
} elseif ($operand->getValue() > 0) {
return new QtiInteger(1);
} else {
return new QtiInteger(0);
}
} | [
"protected",
"function",
"processSignum",
"(",
")",
"{",
"$",
"operands",
"=",
"$",
"this",
"->",
"getOperands",
"(",
")",
";",
"$",
"operand",
"=",
"$",
"operands",
"[",
"0",
"]",
";",
"if",
"(",
"is_nan",
"(",
"$",
"operand",
"->",
"getValue",
"(",
")",
")",
")",
"{",
"return",
"null",
";",
"}",
"elseif",
"(",
"$",
"operand",
"->",
"getValue",
"(",
")",
"<",
"0",
")",
"{",
"return",
"new",
"QtiInteger",
"(",
"-",
"1",
")",
";",
"}",
"elseif",
"(",
"$",
"operand",
"->",
"getValue",
"(",
")",
">",
"0",
")",
"{",
"return",
"new",
"QtiInteger",
"(",
"1",
")",
";",
"}",
"else",
"{",
"return",
"new",
"QtiInteger",
"(",
"0",
")",
";",
"}",
"}"
] | Process the signum (a.k.a. sign) function.
@link https://en.wikipedia.org/wiki/Sign_function | [
"Process",
"the",
"signum",
"(",
"a",
".",
"k",
".",
"a",
".",
"sign",
")",
"function",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/MathOperatorProcessor.php#L445-L459 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/MathConstantMarshaller.php | MathConstantMarshaller.marshall | protected function marshall(QtiComponent $component)
{
$element = static::getDOMCradle()->createElement($component->getQtiClassName());
$this->setDOMElementAttribute($element, 'name', MathEnumeration::getNameByConstant($component->getName()));
return $element;
} | php | protected function marshall(QtiComponent $component)
{
$element = static::getDOMCradle()->createElement($component->getQtiClassName());
$this->setDOMElementAttribute($element, 'name', MathEnumeration::getNameByConstant($component->getName()));
return $element;
} | [
"protected",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"$",
"element",
"=",
"static",
"::",
"getDOMCradle",
"(",
")",
"->",
"createElement",
"(",
"$",
"component",
"->",
"getQtiClassName",
"(",
")",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'name'",
",",
"MathEnumeration",
"::",
"getNameByConstant",
"(",
"$",
"component",
"->",
"getName",
"(",
")",
")",
")",
";",
"return",
"$",
"element",
";",
"}"
] | Marshall a MathConstant object into a DOMElement object.
@param \qtism\data\QtiComponent $component A MathConstant object.
@return \DOMElement The according DOMElement object. | [
"Marshall",
"a",
"MathConstant",
"object",
"into",
"a",
"DOMElement",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/MathConstantMarshaller.php#L44-L51 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/MathConstantMarshaller.php | MathConstantMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
if (($name = $this->getDOMElementAttributeAs($element, 'name')) !== null) {
if (($cst = MathEnumeration::getConstantByName($name)) !== false) {
$object = new MathConstant($cst);
return $object;
} else {
$msg = "'${name}' is not a valid value for the attribute 'name' from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} else {
$msg = "The mandatory attribute 'name' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} | php | protected function unmarshall(DOMElement $element)
{
if (($name = $this->getDOMElementAttributeAs($element, 'name')) !== null) {
if (($cst = MathEnumeration::getConstantByName($name)) !== false) {
$object = new MathConstant($cst);
return $object;
} else {
$msg = "'${name}' is not a valid value for the attribute 'name' from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} else {
$msg = "The mandatory attribute 'name' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"if",
"(",
"(",
"$",
"name",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'name'",
")",
")",
"!==",
"null",
")",
"{",
"if",
"(",
"(",
"$",
"cst",
"=",
"MathEnumeration",
"::",
"getConstantByName",
"(",
"$",
"name",
")",
")",
"!==",
"false",
")",
"{",
"$",
"object",
"=",
"new",
"MathConstant",
"(",
"$",
"cst",
")",
";",
"return",
"$",
"object",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"'${name}' is not a valid value for the attribute 'name' from element '\"",
".",
"$",
"element",
"->",
"localName",
".",
"\"'.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory attribute 'name' is missing from element '\"",
".",
"$",
"element",
"->",
"localName",
".",
"\"'.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}"
] | Unmarshall a DOMElement object corresponding to a QTI mathConstant element.
@param \DOMElement $element A DOMElement object.
@return \qtism\data\QtiComponent A MathConstant object.
@throws \UnmarshallingException If the mandatory attribute 'name' is missing. | [
"Unmarshall",
"a",
"DOMElement",
"object",
"corresponding",
"to",
"a",
"QTI",
"mathConstant",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/MathConstantMarshaller.php#L60-L75 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/RoundToProcessor.php | RoundToProcessor.process | public function process()
{
$operands = $this->getOperands();
$state = $this->getState();
$operand = $operands[0];
// If the value is null, return null.
if ($operands->containsNull()) {
return null;
}
if (!$operands->exclusivelySingle()) {
$msg = "The RoundTo operator accepts 1 operand with single cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
// Accept only numerical operands.
if (!$operands->exclusivelyNumeric()) {
$msg = "The RoundTo operand accepts 1 operand with numerical baseType.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
}
// As per QTI 2.1 spec...
if (is_nan($operand->getValue())) {
return null;
} elseif (is_infinite($operand->getValue())) {
return $operand;
}
$roundingMode = $this->getExpression()->getRoundingMode();
$figures = $this->getExpression()->getFigures();
if (gettype($figures) === 'string') {
// try to recover the value from the state.
$figuresIdentifier = ExprUtils::sanitizeVariableRef($figures);
$figures = $state[$figuresIdentifier];
if (is_null($figures)) {
$msg = "The variable '${figuresIdentifier}' used to set up the 'figures' attribute is null or nonexisting.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::NONEXISTENT_VARIABLE);
} elseif (!$figures instanceof QtiInteger) {
$msg = "The variable '${figuresIdentifier}' used to set up the 'figures' attribute is not an integer.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_VARIABLE_BASETYPE);
}
$figures = $figures->getValue();
}
if ($roundingMode === RoundingMode::SIGNIFICANT_FIGURES) {
if ($figures <= 0) {
// As per QTI 2.1 spec.
$msg = "The 'figures' attribute must be a non-zero positive integer when mode 'significantFigures' is used, '${figures}' given.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::LOGIC_ERROR);
}
if ($operand->getValue() == 0) {
return new QtiFloat(0.0);
}
$d = ceil(log10($operand->getValue() < 0 ? -$operand->getValue() : $operand->getValue()));
$power = $figures - intval($d);
$magnitude = pow(10, $power);
$shifted = round($operand->getValue() * $magnitude);
return new QtiFloat(floatval($shifted / $magnitude));
} else {
// As per QTI 2.1 spec.
if ($figures < 0) {
$msg = "The 'figures' attribute must be a integer greater than or equal to zero when mode 'decimalPlaces' is used, '${figures}' given.";
throw new OperatorProcessingException($msg, $this);
}
return new QtiFloat(round($operand->getValue(), $figures));
}
} | php | public function process()
{
$operands = $this->getOperands();
$state = $this->getState();
$operand = $operands[0];
// If the value is null, return null.
if ($operands->containsNull()) {
return null;
}
if (!$operands->exclusivelySingle()) {
$msg = "The RoundTo operator accepts 1 operand with single cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
// Accept only numerical operands.
if (!$operands->exclusivelyNumeric()) {
$msg = "The RoundTo operand accepts 1 operand with numerical baseType.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
}
// As per QTI 2.1 spec...
if (is_nan($operand->getValue())) {
return null;
} elseif (is_infinite($operand->getValue())) {
return $operand;
}
$roundingMode = $this->getExpression()->getRoundingMode();
$figures = $this->getExpression()->getFigures();
if (gettype($figures) === 'string') {
// try to recover the value from the state.
$figuresIdentifier = ExprUtils::sanitizeVariableRef($figures);
$figures = $state[$figuresIdentifier];
if (is_null($figures)) {
$msg = "The variable '${figuresIdentifier}' used to set up the 'figures' attribute is null or nonexisting.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::NONEXISTENT_VARIABLE);
} elseif (!$figures instanceof QtiInteger) {
$msg = "The variable '${figuresIdentifier}' used to set up the 'figures' attribute is not an integer.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_VARIABLE_BASETYPE);
}
$figures = $figures->getValue();
}
if ($roundingMode === RoundingMode::SIGNIFICANT_FIGURES) {
if ($figures <= 0) {
// As per QTI 2.1 spec.
$msg = "The 'figures' attribute must be a non-zero positive integer when mode 'significantFigures' is used, '${figures}' given.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::LOGIC_ERROR);
}
if ($operand->getValue() == 0) {
return new QtiFloat(0.0);
}
$d = ceil(log10($operand->getValue() < 0 ? -$operand->getValue() : $operand->getValue()));
$power = $figures - intval($d);
$magnitude = pow(10, $power);
$shifted = round($operand->getValue() * $magnitude);
return new QtiFloat(floatval($shifted / $magnitude));
} else {
// As per QTI 2.1 spec.
if ($figures < 0) {
$msg = "The 'figures' attribute must be a integer greater than or equal to zero when mode 'decimalPlaces' is used, '${figures}' given.";
throw new OperatorProcessingException($msg, $this);
}
return new QtiFloat(round($operand->getValue(), $figures));
}
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"operands",
"=",
"$",
"this",
"->",
"getOperands",
"(",
")",
";",
"$",
"state",
"=",
"$",
"this",
"->",
"getState",
"(",
")",
";",
"$",
"operand",
"=",
"$",
"operands",
"[",
"0",
"]",
";",
"// If the value is null, return null.",
"if",
"(",
"$",
"operands",
"->",
"containsNull",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"$",
"operands",
"->",
"exclusivelySingle",
"(",
")",
")",
"{",
"$",
"msg",
"=",
"\"The RoundTo operator accepts 1 operand with single cardinality.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_CARDINALITY",
")",
";",
"}",
"// Accept only numerical operands.",
"if",
"(",
"!",
"$",
"operands",
"->",
"exclusivelyNumeric",
"(",
")",
")",
"{",
"$",
"msg",
"=",
"\"The RoundTo operand accepts 1 operand with numerical baseType.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_BASETYPE",
")",
";",
"}",
"// As per QTI 2.1 spec...",
"if",
"(",
"is_nan",
"(",
"$",
"operand",
"->",
"getValue",
"(",
")",
")",
")",
"{",
"return",
"null",
";",
"}",
"elseif",
"(",
"is_infinite",
"(",
"$",
"operand",
"->",
"getValue",
"(",
")",
")",
")",
"{",
"return",
"$",
"operand",
";",
"}",
"$",
"roundingMode",
"=",
"$",
"this",
"->",
"getExpression",
"(",
")",
"->",
"getRoundingMode",
"(",
")",
";",
"$",
"figures",
"=",
"$",
"this",
"->",
"getExpression",
"(",
")",
"->",
"getFigures",
"(",
")",
";",
"if",
"(",
"gettype",
"(",
"$",
"figures",
")",
"===",
"'string'",
")",
"{",
"// try to recover the value from the state.",
"$",
"figuresIdentifier",
"=",
"ExprUtils",
"::",
"sanitizeVariableRef",
"(",
"$",
"figures",
")",
";",
"$",
"figures",
"=",
"$",
"state",
"[",
"$",
"figuresIdentifier",
"]",
";",
"if",
"(",
"is_null",
"(",
"$",
"figures",
")",
")",
"{",
"$",
"msg",
"=",
"\"The variable '${figuresIdentifier}' used to set up the 'figures' attribute is null or nonexisting.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"NONEXISTENT_VARIABLE",
")",
";",
"}",
"elseif",
"(",
"!",
"$",
"figures",
"instanceof",
"QtiInteger",
")",
"{",
"$",
"msg",
"=",
"\"The variable '${figuresIdentifier}' used to set up the 'figures' attribute is not an integer.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_VARIABLE_BASETYPE",
")",
";",
"}",
"$",
"figures",
"=",
"$",
"figures",
"->",
"getValue",
"(",
")",
";",
"}",
"if",
"(",
"$",
"roundingMode",
"===",
"RoundingMode",
"::",
"SIGNIFICANT_FIGURES",
")",
"{",
"if",
"(",
"$",
"figures",
"<=",
"0",
")",
"{",
"// As per QTI 2.1 spec.",
"$",
"msg",
"=",
"\"The 'figures' attribute must be a non-zero positive integer when mode 'significantFigures' is used, '${figures}' given.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"LOGIC_ERROR",
")",
";",
"}",
"if",
"(",
"$",
"operand",
"->",
"getValue",
"(",
")",
"==",
"0",
")",
"{",
"return",
"new",
"QtiFloat",
"(",
"0.0",
")",
";",
"}",
"$",
"d",
"=",
"ceil",
"(",
"log10",
"(",
"$",
"operand",
"->",
"getValue",
"(",
")",
"<",
"0",
"?",
"-",
"$",
"operand",
"->",
"getValue",
"(",
")",
":",
"$",
"operand",
"->",
"getValue",
"(",
")",
")",
")",
";",
"$",
"power",
"=",
"$",
"figures",
"-",
"intval",
"(",
"$",
"d",
")",
";",
"$",
"magnitude",
"=",
"pow",
"(",
"10",
",",
"$",
"power",
")",
";",
"$",
"shifted",
"=",
"round",
"(",
"$",
"operand",
"->",
"getValue",
"(",
")",
"*",
"$",
"magnitude",
")",
";",
"return",
"new",
"QtiFloat",
"(",
"floatval",
"(",
"$",
"shifted",
"/",
"$",
"magnitude",
")",
")",
";",
"}",
"else",
"{",
"// As per QTI 2.1 spec.",
"if",
"(",
"$",
"figures",
"<",
"0",
")",
"{",
"$",
"msg",
"=",
"\"The 'figures' attribute must be a integer greater than or equal to zero when mode 'decimalPlaces' is used, '${figures}' given.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
")",
";",
"}",
"return",
"new",
"QtiFloat",
"(",
"round",
"(",
"$",
"operand",
"->",
"getValue",
"(",
")",
",",
"$",
"figures",
")",
")",
";",
"}",
"}"
] | Process the RoundTo operator.
An OperatorProcessingException will be thrown if:
* The given operand is not a numeric value.
* The cardinality of the operand is not single.
* The value of the 'figures' attribute comes from a templateVariable which does not exist or is not numeric or null.
@return null|float A single float with the value nearest to that of the expression's value or NULL if the sub-expression is NaN.
@throws \qtism\runtime\expressions\operators\OperatorProcessingException | [
"Process",
"the",
"RoundTo",
"operator",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/RoundToProcessor.php#L75-L151 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/WeightMarshaller.php | WeightMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
// identifier is a mandatory value.
if (($identifier = $this->getDOMElementAttributeAs($element, 'identifier', 'string')) !== null) {
if (($value = $this->getDOMElementAttributeAs($element, 'value', 'string')) !== null) {
if (Format::isFloat($value)) {
try {
$object = new Weight($identifier, floatval($value));
return $object;
} catch (InvalidArgumentException $e) {
$msg = "The value of 'identifier' from element '" . $element->localName . "' is not a valid QTI Identifier.";
throw new UnmarshallingException($msg, $element, $e);
}
} else {
$msg = "The value of attribute 'value' from element '" . $element->localName . "' cannot be converted into a float.";
throw new UnmarshallingException($msg, $element);
}
} else {
$msg = "The mandatory attribute 'value' 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)
{
// identifier is a mandatory value.
if (($identifier = $this->getDOMElementAttributeAs($element, 'identifier', 'string')) !== null) {
if (($value = $this->getDOMElementAttributeAs($element, 'value', 'string')) !== null) {
if (Format::isFloat($value)) {
try {
$object = new Weight($identifier, floatval($value));
return $object;
} catch (InvalidArgumentException $e) {
$msg = "The value of 'identifier' from element '" . $element->localName . "' is not a valid QTI Identifier.";
throw new UnmarshallingException($msg, $element, $e);
}
} else {
$msg = "The value of attribute 'value' from element '" . $element->localName . "' cannot be converted into a float.";
throw new UnmarshallingException($msg, $element);
}
} else {
$msg = "The mandatory attribute 'value' 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",
")",
"{",
"// identifier is a mandatory value.",
"if",
"(",
"(",
"$",
"identifier",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'identifier'",
",",
"'string'",
")",
")",
"!==",
"null",
")",
"{",
"if",
"(",
"(",
"$",
"value",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'value'",
",",
"'string'",
")",
")",
"!==",
"null",
")",
"{",
"if",
"(",
"Format",
"::",
"isFloat",
"(",
"$",
"value",
")",
")",
"{",
"try",
"{",
"$",
"object",
"=",
"new",
"Weight",
"(",
"$",
"identifier",
",",
"floatval",
"(",
"$",
"value",
")",
")",
";",
"return",
"$",
"object",
";",
"}",
"catch",
"(",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"The value of 'identifier' from element '\"",
".",
"$",
"element",
"->",
"localName",
".",
"\"' is not a valid QTI Identifier.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
",",
"$",
"e",
")",
";",
"}",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The value of attribute 'value' from element '\"",
".",
"$",
"element",
"->",
"localName",
".",
"\"' cannot be converted into a float.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory attribute 'value' 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 QTI weight element.
@param \DOMElement $element A DOMElement object.
@return \qtism\data\QtiComponent A Weight object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException If the mandatory attributes 'identifier' or 'value' are missing from $element but also if 'value' cannot be converted to a float value or 'identifier' is not a valid QTI Identifier. | [
"Unmarshall",
"a",
"DOMElement",
"object",
"corresponding",
"to",
"a",
"QTI",
"weight",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/WeightMarshaller.php#L62-L88 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/TimeLimitsMarshaller.php | TimeLimitsMarshaller.marshall | protected function marshall(QtiComponent $component)
{
$element = static::getDOMCradle()->createElement($component->getQtiClassName());
if ($component->hasMinTime() === true) {
$this->setDOMElementAttribute($element, 'minTime', $component->getMinTime()->getSeconds(true));
}
if ($component->hasMaxTime() === true) {
$this->setDOMElementAttribute($element, 'maxTime', $component->getMaxTime()->getSeconds(true));
}
$this->setDOMElementAttribute($element, 'allowLateSubmission', $component->doesAllowLateSubmission());
return $element;
} | php | protected function marshall(QtiComponent $component)
{
$element = static::getDOMCradle()->createElement($component->getQtiClassName());
if ($component->hasMinTime() === true) {
$this->setDOMElementAttribute($element, 'minTime', $component->getMinTime()->getSeconds(true));
}
if ($component->hasMaxTime() === true) {
$this->setDOMElementAttribute($element, 'maxTime', $component->getMaxTime()->getSeconds(true));
}
$this->setDOMElementAttribute($element, 'allowLateSubmission', $component->doesAllowLateSubmission());
return $element;
} | [
"protected",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"$",
"element",
"=",
"static",
"::",
"getDOMCradle",
"(",
")",
"->",
"createElement",
"(",
"$",
"component",
"->",
"getQtiClassName",
"(",
")",
")",
";",
"if",
"(",
"$",
"component",
"->",
"hasMinTime",
"(",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'minTime'",
",",
"$",
"component",
"->",
"getMinTime",
"(",
")",
"->",
"getSeconds",
"(",
"true",
")",
")",
";",
"}",
"if",
"(",
"$",
"component",
"->",
"hasMaxTime",
"(",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'maxTime'",
",",
"$",
"component",
"->",
"getMaxTime",
"(",
")",
"->",
"getSeconds",
"(",
"true",
")",
")",
";",
"}",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'allowLateSubmission'",
",",
"$",
"component",
"->",
"doesAllowLateSubmission",
"(",
")",
")",
";",
"return",
"$",
"element",
";",
"}"
] | Marshall a TimeLimits object into a DOMElement object.
@param \qtism\data\QtiComponent $component A TimeLimits object.
@return \DOMElement The according DOMElement object. | [
"Marshall",
"a",
"TimeLimits",
"object",
"into",
"a",
"DOMElement",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/TimeLimitsMarshaller.php#L45-L60 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/TimeLimitsMarshaller.php | TimeLimitsMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
$object = new TimeLimits();
if (($value = $this->getDOMElementAttributeAs($element, 'minTime', 'string')) !== null) {
$object->setMinTime(StorageUtils::stringToDatatype("PT${value}S", BaseType::DURATION));
}
if (($value = $this->getDOMElementAttributeAs($element, 'maxTime', 'string')) !== null) {
$object->setMaxTime(StorageUtils::stringToDatatype("PT${value}S", BaseType::DURATION));
}
if (($value = $this->getDOMElementAttributeAs($element, 'allowLateSubmission', 'boolean')) !== null) {
$object->setAllowLateSubmission($value);
}
return $object;
} | php | protected function unmarshall(DOMElement $element)
{
$object = new TimeLimits();
if (($value = $this->getDOMElementAttributeAs($element, 'minTime', 'string')) !== null) {
$object->setMinTime(StorageUtils::stringToDatatype("PT${value}S", BaseType::DURATION));
}
if (($value = $this->getDOMElementAttributeAs($element, 'maxTime', 'string')) !== null) {
$object->setMaxTime(StorageUtils::stringToDatatype("PT${value}S", BaseType::DURATION));
}
if (($value = $this->getDOMElementAttributeAs($element, 'allowLateSubmission', 'boolean')) !== null) {
$object->setAllowLateSubmission($value);
}
return $object;
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"$",
"object",
"=",
"new",
"TimeLimits",
"(",
")",
";",
"if",
"(",
"(",
"$",
"value",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'minTime'",
",",
"'string'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"object",
"->",
"setMinTime",
"(",
"StorageUtils",
"::",
"stringToDatatype",
"(",
"\"PT${value}S\"",
",",
"BaseType",
"::",
"DURATION",
")",
")",
";",
"}",
"if",
"(",
"(",
"$",
"value",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'maxTime'",
",",
"'string'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"object",
"->",
"setMaxTime",
"(",
"StorageUtils",
"::",
"stringToDatatype",
"(",
"\"PT${value}S\"",
",",
"BaseType",
"::",
"DURATION",
")",
")",
";",
"}",
"if",
"(",
"(",
"$",
"value",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'allowLateSubmission'",
",",
"'boolean'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"object",
"->",
"setAllowLateSubmission",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"object",
";",
"}"
] | Unmarshall a DOMElement object corresponding to a QTI timeLimits element.
@param \DOMElement $element A DOMElement object.
@return \qtism\data\QtiComponent A TimeLimits object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException If the attribute 'allowLateSubmission' is not a valid boolean value. | [
"Unmarshall",
"a",
"DOMElement",
"object",
"corresponding",
"to",
"a",
"QTI",
"timeLimits",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/TimeLimitsMarshaller.php#L69-L86 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/OperandsCollection.php | OperandsCollection.checkType | protected function checkType($value)
{
if (RuntimeUtils::isQtiScalarDatatypeCompliant($value)) {
return;
} else {
$value = (gettype($value) === 'object') ? get_class($value) : $value;
$msg = "The OperandsCollection only accepts QTI Runtime compliant values, '" . $value . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | protected function checkType($value)
{
if (RuntimeUtils::isQtiScalarDatatypeCompliant($value)) {
return;
} else {
$value = (gettype($value) === 'object') ? get_class($value) : $value;
$msg = "The OperandsCollection only accepts QTI Runtime compliant values, '" . $value . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"protected",
"function",
"checkType",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"RuntimeUtils",
"::",
"isQtiScalarDatatypeCompliant",
"(",
"$",
"value",
")",
")",
"{",
"return",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"(",
"gettype",
"(",
"$",
"value",
")",
"===",
"'object'",
")",
"?",
"get_class",
"(",
"$",
"value",
")",
":",
"$",
"value",
";",
"$",
"msg",
"=",
"\"The OperandsCollection only accepts QTI Runtime compliant values, '\"",
".",
"$",
"value",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Check if $value is a QTI Runtime compliant value.
@throws \InvalidArgumentException If $value is not a QTI Runtime compliant value. | [
"Check",
"if",
"$value",
"is",
"a",
"QTI",
"Runtime",
"compliant",
"value",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/OperandsCollection.php#L55-L64 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/OperandsCollection.php | OperandsCollection.containsNull | public function containsNull()
{
foreach (array_keys($this->getDataPlaceHolder()) as $key) {
$v = $this[$key];
if ($v instanceof Container && $v->isNull()) {
return true;
} elseif (($v instanceof QtiString && $v->getValue() === '') || is_null($v)) {
return true;
}
}
return false;
} | php | public function containsNull()
{
foreach (array_keys($this->getDataPlaceHolder()) as $key) {
$v = $this[$key];
if ($v instanceof Container && $v->isNull()) {
return true;
} elseif (($v instanceof QtiString && $v->getValue() === '') || is_null($v)) {
return true;
}
}
return false;
} | [
"public",
"function",
"containsNull",
"(",
")",
"{",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"getDataPlaceHolder",
"(",
")",
")",
"as",
"$",
"key",
")",
"{",
"$",
"v",
"=",
"$",
"this",
"[",
"$",
"key",
"]",
";",
"if",
"(",
"$",
"v",
"instanceof",
"Container",
"&&",
"$",
"v",
"->",
"isNull",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"elseif",
"(",
"(",
"$",
"v",
"instanceof",
"QtiString",
"&&",
"$",
"v",
"->",
"getValue",
"(",
")",
"===",
"''",
")",
"||",
"is_null",
"(",
"$",
"v",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Wether the collection contains a QTI Runtime compliant value which is
considered to be NULL.
* If the collection of operands is empty, true is returned.
* If the collection of operands contains null, an empty container, or an empty string, true is returned.
* In any other case, false is returned.
@return boolean | [
"Wether",
"the",
"collection",
"contains",
"a",
"QTI",
"Runtime",
"compliant",
"value",
"which",
"is",
"considered",
"to",
"be",
"NULL",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/OperandsCollection.php#L76-L88 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/OperandsCollection.php | OperandsCollection.exclusivelyBoolean | public function exclusivelyBoolean()
{
if (count($this) === 0) {
return false;
}
foreach (array_keys($this->getDataPlaceHolder()) as $key) {
$v = $this[$key];
if (($v instanceof MultipleContainer || $v instanceof OrderedContainer) && ($v->isNull() || $v->getBaseType() !== BaseType::BOOLEAN)) {
return false;
} elseif (!$v instanceof QtiBoolean && !$v instanceof MultipleContainer && !$v instanceof OrderedContainer) {
return false;
}
}
return true;
} | php | public function exclusivelyBoolean()
{
if (count($this) === 0) {
return false;
}
foreach (array_keys($this->getDataPlaceHolder()) as $key) {
$v = $this[$key];
if (($v instanceof MultipleContainer || $v instanceof OrderedContainer) && ($v->isNull() || $v->getBaseType() !== BaseType::BOOLEAN)) {
return false;
} elseif (!$v instanceof QtiBoolean && !$v instanceof MultipleContainer && !$v instanceof OrderedContainer) {
return false;
}
}
return true;
} | [
"public",
"function",
"exclusivelyBoolean",
"(",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
")",
"===",
"0",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"getDataPlaceHolder",
"(",
")",
")",
"as",
"$",
"key",
")",
"{",
"$",
"v",
"=",
"$",
"this",
"[",
"$",
"key",
"]",
";",
"if",
"(",
"(",
"$",
"v",
"instanceof",
"MultipleContainer",
"||",
"$",
"v",
"instanceof",
"OrderedContainer",
")",
"&&",
"(",
"$",
"v",
"->",
"isNull",
"(",
")",
"||",
"$",
"v",
"->",
"getBaseType",
"(",
")",
"!==",
"BaseType",
"::",
"BOOLEAN",
")",
")",
"{",
"return",
"false",
";",
"}",
"elseif",
"(",
"!",
"$",
"v",
"instanceof",
"QtiBoolean",
"&&",
"!",
"$",
"v",
"instanceof",
"MultipleContainer",
"&&",
"!",
"$",
"v",
"instanceof",
"OrderedContainer",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Wether the collection contains exclusively boolean values or containers.
* If the collection of operands is empty, false is returned.
* If the collection of operands contains a NULL value or a NULL container, false is returned.
* If the collection of operands contains a value or container which is not boolean, false is returned.
* If the collection of operands contains a RECORD container, false is returned, because records are not typed.
@return boolean | [
"Wether",
"the",
"collection",
"contains",
"exclusively",
"boolean",
"values",
"or",
"containers",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/OperandsCollection.php#L130-L146 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/OperandsCollection.php | OperandsCollection.exclusivelySingle | public function exclusivelySingle()
{
if (count($this) === 0) {
return false;
}
foreach (array_keys($this->getDataPlaceHolder()) as $key) {
$v = $this[$key];
if (is_null($v) || $v instanceof Container) {
return false;
}
}
return true;
} | php | public function exclusivelySingle()
{
if (count($this) === 0) {
return false;
}
foreach (array_keys($this->getDataPlaceHolder()) as $key) {
$v = $this[$key];
if (is_null($v) || $v instanceof Container) {
return false;
}
}
return true;
} | [
"public",
"function",
"exclusivelySingle",
"(",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
")",
"===",
"0",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"getDataPlaceHolder",
"(",
")",
")",
"as",
"$",
"key",
")",
"{",
"$",
"v",
"=",
"$",
"this",
"[",
"$",
"key",
"]",
";",
"if",
"(",
"is_null",
"(",
"$",
"v",
")",
"||",
"$",
"v",
"instanceof",
"Container",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Wether the collection contains exclusively single cardinality values. If the container
is empty or contains a null value, false is returned.
@return boolean | [
"Wether",
"the",
"collection",
"contains",
"exclusively",
"single",
"cardinality",
"values",
".",
"If",
"the",
"container",
"is",
"empty",
"or",
"contains",
"a",
"null",
"value",
"false",
"is",
"returned",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/OperandsCollection.php#L154-L168 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/OperandsCollection.php | OperandsCollection.exclusivelyString | public function exclusivelyString()
{
if (count($this) === 0) {
return false;
}
foreach (array_keys($this->getDataPlaceHolder()) as $key) {
$v = $this[$key];
if (($v instanceof MultipleContainer || $v instanceof OrderedContainer) && ($v->isNull() || $v->getBaseType() !== BaseType::STRING)) {
return false;
} elseif (!$v instanceof MultipleContainer && !$v instanceof OrderedContainer && (!$v instanceof QtiString || $v->getValue() === '')) {
return false;
}
}
return true;
} | php | public function exclusivelyString()
{
if (count($this) === 0) {
return false;
}
foreach (array_keys($this->getDataPlaceHolder()) as $key) {
$v = $this[$key];
if (($v instanceof MultipleContainer || $v instanceof OrderedContainer) && ($v->isNull() || $v->getBaseType() !== BaseType::STRING)) {
return false;
} elseif (!$v instanceof MultipleContainer && !$v instanceof OrderedContainer && (!$v instanceof QtiString || $v->getValue() === '')) {
return false;
}
}
return true;
} | [
"public",
"function",
"exclusivelyString",
"(",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
")",
"===",
"0",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"getDataPlaceHolder",
"(",
")",
")",
"as",
"$",
"key",
")",
"{",
"$",
"v",
"=",
"$",
"this",
"[",
"$",
"key",
"]",
";",
"if",
"(",
"(",
"$",
"v",
"instanceof",
"MultipleContainer",
"||",
"$",
"v",
"instanceof",
"OrderedContainer",
")",
"&&",
"(",
"$",
"v",
"->",
"isNull",
"(",
")",
"||",
"$",
"v",
"->",
"getBaseType",
"(",
")",
"!==",
"BaseType",
"::",
"STRING",
")",
")",
"{",
"return",
"false",
";",
"}",
"elseif",
"(",
"!",
"$",
"v",
"instanceof",
"MultipleContainer",
"&&",
"!",
"$",
"v",
"instanceof",
"OrderedContainer",
"&&",
"(",
"!",
"$",
"v",
"instanceof",
"QtiString",
"||",
"$",
"v",
"->",
"getValue",
"(",
")",
"===",
"''",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Whether the collection is exclusively composed of string values: primitive or Containers.
Please note that:
* A primitive with the NULL value is not considered as a string.
* An empty string is considered to be NULL and then not considered a valid string as per QTI 2.1 specification.
* An empty Multiple/OrderedContainer with baseType string is not considered to contain strings.
* If the collection contains a container with cardinality RECORD, it is not considered exclusively string.
* If the the current OperandsCollection is empty, false is returned.
@return boolean | [
"Whether",
"the",
"collection",
"is",
"exclusively",
"composed",
"of",
"string",
"values",
":",
"primitive",
"or",
"Containers",
".",
"Please",
"note",
"that",
":"
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/OperandsCollection.php#L182-L198 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/OperandsCollection.php | OperandsCollection.exclusivelyMultipleOrOrdered | public function exclusivelyMultipleOrOrdered()
{
if (count($this) === 0) {
return false;
}
foreach (array_keys($this->getDataPlaceHolder()) as $key) {
$v = $this[$key];
if (!$v instanceof MultipleContainer && !$v instanceof OrderedContainer) {
return false;
}
}
return true;
} | php | public function exclusivelyMultipleOrOrdered()
{
if (count($this) === 0) {
return false;
}
foreach (array_keys($this->getDataPlaceHolder()) as $key) {
$v = $this[$key];
if (!$v instanceof MultipleContainer && !$v instanceof OrderedContainer) {
return false;
}
}
return true;
} | [
"public",
"function",
"exclusivelyMultipleOrOrdered",
"(",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
")",
"===",
"0",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"getDataPlaceHolder",
"(",
")",
")",
"as",
"$",
"key",
")",
"{",
"$",
"v",
"=",
"$",
"this",
"[",
"$",
"key",
"]",
";",
"if",
"(",
"!",
"$",
"v",
"instanceof",
"MultipleContainer",
"&&",
"!",
"$",
"v",
"instanceof",
"OrderedContainer",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Whether the collection contains only MultipleContainer OR OrderedContainer.
@return boolean | [
"Whether",
"the",
"collection",
"contains",
"only",
"MultipleContainer",
"OR",
"OrderedContainer",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/OperandsCollection.php#L205-L219 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/OperandsCollection.php | OperandsCollection.exclusivelyInteger | public function exclusivelyInteger()
{
if (count($this) === 0) {
return false;
}
foreach (array_keys($this->getDataPlaceHolder()) as $key) {
$v = $this[$key];
if (($v instanceof MultipleContainer || $v instanceof OrderedContainer) && ($v->isNull() || $v->getBaseType() !== BaseType::INTEGER)) {
return false;
} elseif (!$v instanceof QtiInteger && !$v instanceof MultipleContainer && !$v instanceof OrderedContainer) {
return false;
}
}
return true;
} | php | public function exclusivelyInteger()
{
if (count($this) === 0) {
return false;
}
foreach (array_keys($this->getDataPlaceHolder()) as $key) {
$v = $this[$key];
if (($v instanceof MultipleContainer || $v instanceof OrderedContainer) && ($v->isNull() || $v->getBaseType() !== BaseType::INTEGER)) {
return false;
} elseif (!$v instanceof QtiInteger && !$v instanceof MultipleContainer && !$v instanceof OrderedContainer) {
return false;
}
}
return true;
} | [
"public",
"function",
"exclusivelyInteger",
"(",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
")",
"===",
"0",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"getDataPlaceHolder",
"(",
")",
")",
"as",
"$",
"key",
")",
"{",
"$",
"v",
"=",
"$",
"this",
"[",
"$",
"key",
"]",
";",
"if",
"(",
"(",
"$",
"v",
"instanceof",
"MultipleContainer",
"||",
"$",
"v",
"instanceof",
"OrderedContainer",
")",
"&&",
"(",
"$",
"v",
"->",
"isNull",
"(",
")",
"||",
"$",
"v",
"->",
"getBaseType",
"(",
")",
"!==",
"BaseType",
"::",
"INTEGER",
")",
")",
"{",
"return",
"false",
";",
"}",
"elseif",
"(",
"!",
"$",
"v",
"instanceof",
"QtiInteger",
"&&",
"!",
"$",
"v",
"instanceof",
"MultipleContainer",
"&&",
"!",
"$",
"v",
"instanceof",
"OrderedContainer",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Whether the collection is exclusively composed of integer values: primitive
or Containers. Please note that:
* A primitive with the NULL value is not considered as an integer.
* Only integer primitives and non-NULL Multiple/OrderedContainer objects are considered valid integers.
* If the the current OperandsCollection is empty, false is returned.
@return boolean. | [
"Whether",
"the",
"collection",
"is",
"exclusively",
"composed",
"of",
"integer",
"values",
":",
"primitive",
"or",
"Containers",
".",
"Please",
"note",
"that",
":"
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/OperandsCollection.php#L231-L247 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/OperandsCollection.php | OperandsCollection.exclusivelySingleOrMultiple | public function exclusivelySingleOrMultiple()
{
if (count($this) === 0) {
return false;
}
foreach (array_keys($this->getDataPlaceHolder()) as $key) {
$v = $this[$key];
if ($v instanceof RecordContainer || $v instanceof OrderedContainer) {
return false;
}
}
return true;
} | php | public function exclusivelySingleOrMultiple()
{
if (count($this) === 0) {
return false;
}
foreach (array_keys($this->getDataPlaceHolder()) as $key) {
$v = $this[$key];
if ($v instanceof RecordContainer || $v instanceof OrderedContainer) {
return false;
}
}
return true;
} | [
"public",
"function",
"exclusivelySingleOrMultiple",
"(",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
")",
"===",
"0",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"getDataPlaceHolder",
"(",
")",
")",
"as",
"$",
"key",
")",
"{",
"$",
"v",
"=",
"$",
"this",
"[",
"$",
"key",
"]",
";",
"if",
"(",
"$",
"v",
"instanceof",
"RecordContainer",
"||",
"$",
"v",
"instanceof",
"OrderedContainer",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Wether the collection contains only Single primitive values or MultipleContainer objects.
* If the collection of operands is empty, false is returned.
* If the collection of operands contains a RecordContainer object, false is returned.
* If the collection of operands contains an OrderedContainer object, false is returned.
* In any other case, true is returned.
@return boolean | [
"Wether",
"the",
"collection",
"contains",
"only",
"Single",
"primitive",
"values",
"or",
"MultipleContainer",
"objects",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/OperandsCollection.php#L259-L274 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/OperandsCollection.php | OperandsCollection.exclusivelySingleOrOrdered | public function exclusivelySingleOrOrdered()
{
if (count($this) === 0) {
return false;
}
foreach (array_keys($this->getDataPlaceHolder()) as $key) {
$v = $this[$key];
if ($v instanceof RecordContainer || ($v instanceof MultipleContainer && $v->getCardinality() === Cardinality::MULTIPLE)) {
return false;
}
}
return true;
} | php | public function exclusivelySingleOrOrdered()
{
if (count($this) === 0) {
return false;
}
foreach (array_keys($this->getDataPlaceHolder()) as $key) {
$v = $this[$key];
if ($v instanceof RecordContainer || ($v instanceof MultipleContainer && $v->getCardinality() === Cardinality::MULTIPLE)) {
return false;
}
}
return true;
} | [
"public",
"function",
"exclusivelySingleOrOrdered",
"(",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
")",
"===",
"0",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"getDataPlaceHolder",
"(",
")",
")",
"as",
"$",
"key",
")",
"{",
"$",
"v",
"=",
"$",
"this",
"[",
"$",
"key",
"]",
";",
"if",
"(",
"$",
"v",
"instanceof",
"RecordContainer",
"||",
"(",
"$",
"v",
"instanceof",
"MultipleContainer",
"&&",
"$",
"v",
"->",
"getCardinality",
"(",
")",
"===",
"Cardinality",
"::",
"MULTIPLE",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Wether the collection contains only Single primitive values or OrderedContainer objects.
* If the collection of operands is empty, false is returned.
* If the collection of operands contains a RecordContainer object, false is returned.
* If the collection of operands contains a MultipleContainer object, false is returned.
* In any other case, true is returned.
@return boolean | [
"Wether",
"the",
"collection",
"contains",
"only",
"Single",
"primitive",
"values",
"or",
"OrderedContainer",
"objects",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/OperandsCollection.php#L286-L301 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/OperandsCollection.php | OperandsCollection.exclusivelyRecord | public function exclusivelyRecord()
{
if (count($this) === 0) {
return false;
}
foreach (array_keys($this->getDataPlaceHolder()) as $key) {
$v = $this[$key];
if (!$v instanceof RecordContainer) {
return false;
}
}
return true;
} | php | public function exclusivelyRecord()
{
if (count($this) === 0) {
return false;
}
foreach (array_keys($this->getDataPlaceHolder()) as $key) {
$v = $this[$key];
if (!$v instanceof RecordContainer) {
return false;
}
}
return true;
} | [
"public",
"function",
"exclusivelyRecord",
"(",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
")",
"===",
"0",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"getDataPlaceHolder",
"(",
")",
")",
"as",
"$",
"key",
")",
"{",
"$",
"v",
"=",
"$",
"this",
"[",
"$",
"key",
"]",
";",
"if",
"(",
"!",
"$",
"v",
"instanceof",
"RecordContainer",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Whether the collection contains exclusively RecordContainer objects.
* Returns false if the collection of operands is empty.
* Returns false if any of the value contained in the collection of operands is not a RecordContainer object.
* In any other case, returns true;
@return boolean | [
"Whether",
"the",
"collection",
"contains",
"exclusively",
"RecordContainer",
"objects",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/OperandsCollection.php#L312-L326 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/OperandsCollection.php | OperandsCollection.exclusivelyOrdered | public function exclusivelyOrdered()
{
if (count($this) === 0) {
return false;
}
foreach (array_keys($this->getDataPlaceHolder()) as $key) {
$v = $this[$key];
if (!$v instanceof OrderedContainer) {
return false;
}
}
return true;
} | php | public function exclusivelyOrdered()
{
if (count($this) === 0) {
return false;
}
foreach (array_keys($this->getDataPlaceHolder()) as $key) {
$v = $this[$key];
if (!$v instanceof OrderedContainer) {
return false;
}
}
return true;
} | [
"public",
"function",
"exclusivelyOrdered",
"(",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
")",
"===",
"0",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"getDataPlaceHolder",
"(",
")",
")",
"as",
"$",
"key",
")",
"{",
"$",
"v",
"=",
"$",
"this",
"[",
"$",
"key",
"]",
";",
"if",
"(",
"!",
"$",
"v",
"instanceof",
"OrderedContainer",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Wether the collection contains exclusively OrderedContainer objects.
* Returns false if the collection of operands is empty.
* Returns false if any of the value contained in the collection of operands is not an OrderedContainer object.
* Returns true in any other case.
@return boolean | [
"Wether",
"the",
"collection",
"contains",
"exclusively",
"OrderedContainer",
"objects",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/OperandsCollection.php#L337-L351 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/OperandsCollection.php | OperandsCollection.anythingButRecord | public function anythingButRecord()
{
foreach (array_keys($this->getDataPlaceHolder()) as $key) {
$v = $this[$key];
if ($v instanceof RecordContainer) {
return false;
}
}
return true;
} | php | public function anythingButRecord()
{
foreach (array_keys($this->getDataPlaceHolder()) as $key) {
$v = $this[$key];
if ($v instanceof RecordContainer) {
return false;
}
}
return true;
} | [
"public",
"function",
"anythingButRecord",
"(",
")",
"{",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"getDataPlaceHolder",
"(",
")",
")",
"as",
"$",
"key",
")",
"{",
"$",
"v",
"=",
"$",
"this",
"[",
"$",
"key",
"]",
";",
"if",
"(",
"$",
"v",
"instanceof",
"RecordContainer",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Whether the collection contains anything but a RecordContainer object.
@return boolean | [
"Whether",
"the",
"collection",
"contains",
"anything",
"but",
"a",
"RecordContainer",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/OperandsCollection.php#L358-L368 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/OperandsCollection.php | OperandsCollection.sameBaseType | public function sameBaseType()
{
$operandsCount = count($this);
if ($operandsCount > 0 && !$this->containsNull()) {
// take the first value of the collection as a referer.
$refValue = $this[0];
$refType = RuntimeUtils::inferBaseType($refValue);
for ($i = 1; $i < $operandsCount; $i++) {
$value = $this[$i];
$testType = RuntimeUtils::inferBaseType($value);
if ($testType !== $refType) {
return false;
}
}
// In any other case, return true.
return true;
} else {
return false;
}
} | php | public function sameBaseType()
{
$operandsCount = count($this);
if ($operandsCount > 0 && !$this->containsNull()) {
// take the first value of the collection as a referer.
$refValue = $this[0];
$refType = RuntimeUtils::inferBaseType($refValue);
for ($i = 1; $i < $operandsCount; $i++) {
$value = $this[$i];
$testType = RuntimeUtils::inferBaseType($value);
if ($testType !== $refType) {
return false;
}
}
// In any other case, return true.
return true;
} else {
return false;
}
} | [
"public",
"function",
"sameBaseType",
"(",
")",
"{",
"$",
"operandsCount",
"=",
"count",
"(",
"$",
"this",
")",
";",
"if",
"(",
"$",
"operandsCount",
">",
"0",
"&&",
"!",
"$",
"this",
"->",
"containsNull",
"(",
")",
")",
"{",
"// take the first value of the collection as a referer.",
"$",
"refValue",
"=",
"$",
"this",
"[",
"0",
"]",
";",
"$",
"refType",
"=",
"RuntimeUtils",
"::",
"inferBaseType",
"(",
"$",
"refValue",
")",
";",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<",
"$",
"operandsCount",
";",
"$",
"i",
"++",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"[",
"$",
"i",
"]",
";",
"$",
"testType",
"=",
"RuntimeUtils",
"::",
"inferBaseType",
"(",
"$",
"value",
")",
";",
"if",
"(",
"$",
"testType",
"!==",
"$",
"refType",
")",
"{",
"return",
"false",
";",
"}",
"}",
"// In any other case, return true.",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Whether the collection is composed of values with the same baseType.
* If any of the values has not the same baseType than other values in the collection, false is returned.
* If the OperandsCollection is an empty collection, false is returned.
* If the OperandsCollection contains a value considered to be null, false is returned.
* If the OperandsCollection is composed exclusively by non-null RecordContainer objects, true is returned.
@return boolean | [
"Whether",
"the",
"collection",
"is",
"composed",
"of",
"values",
"with",
"the",
"same",
"baseType",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/OperandsCollection.php#L380-L403 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/OperandsCollection.php | OperandsCollection.sameCardinality | public function sameCardinality()
{
$operandsCount = count($this);
if ($operandsCount > 0 && !$this->containsNull()) {
$refType = RuntimeUtils::inferCardinality($this[0]);
for ($i = 1; $i < $operandsCount; $i++) {
if ($refType !== RuntimeUtils::inferCardinality($this[$i])) {
return false;
}
}
return true;
} else {
return false;
}
} | php | public function sameCardinality()
{
$operandsCount = count($this);
if ($operandsCount > 0 && !$this->containsNull()) {
$refType = RuntimeUtils::inferCardinality($this[0]);
for ($i = 1; $i < $operandsCount; $i++) {
if ($refType !== RuntimeUtils::inferCardinality($this[$i])) {
return false;
}
}
return true;
} else {
return false;
}
} | [
"public",
"function",
"sameCardinality",
"(",
")",
"{",
"$",
"operandsCount",
"=",
"count",
"(",
"$",
"this",
")",
";",
"if",
"(",
"$",
"operandsCount",
">",
"0",
"&&",
"!",
"$",
"this",
"->",
"containsNull",
"(",
")",
")",
"{",
"$",
"refType",
"=",
"RuntimeUtils",
"::",
"inferCardinality",
"(",
"$",
"this",
"[",
"0",
"]",
")",
";",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<",
"$",
"operandsCount",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"$",
"refType",
"!==",
"RuntimeUtils",
"::",
"inferCardinality",
"(",
"$",
"this",
"[",
"$",
"i",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Wether the collection is composed of values with the same cardinality. Please
note that:
* If the OperandsCollection is empty, false is returned.
* If the OperandsCollection contains a NULL value or a NULL container (empty), false is returned
@return boolean | [
"Wether",
"the",
"collection",
"is",
"composed",
"of",
"values",
"with",
"the",
"same",
"cardinality",
".",
"Please",
"note",
"that",
":"
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/OperandsCollection.php#L414-L430 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/OperandsCollection.php | OperandsCollection.exclusivelyPoint | public function exclusivelyPoint()
{
if (count($this) === 0) {
return false;
}
foreach (array_keys($this->getDataPlaceHolder()) as $key) {
$v = $this[$key];
if (($v instanceof MultipleContainer || $v instanceof OrderedContainer) && ($v->isNull() || $v->getBaseType() !== BaseType::POINT)) {
return false;
} elseif (!$v instanceof QtiPoint && !$v instanceof MultipleContainer && !$v instanceof OrderedContainer) {
return false;
}
}
return true;
} | php | public function exclusivelyPoint()
{
if (count($this) === 0) {
return false;
}
foreach (array_keys($this->getDataPlaceHolder()) as $key) {
$v = $this[$key];
if (($v instanceof MultipleContainer || $v instanceof OrderedContainer) && ($v->isNull() || $v->getBaseType() !== BaseType::POINT)) {
return false;
} elseif (!$v instanceof QtiPoint && !$v instanceof MultipleContainer && !$v instanceof OrderedContainer) {
return false;
}
}
return true;
} | [
"public",
"function",
"exclusivelyPoint",
"(",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
")",
"===",
"0",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"getDataPlaceHolder",
"(",
")",
")",
"as",
"$",
"key",
")",
"{",
"$",
"v",
"=",
"$",
"this",
"[",
"$",
"key",
"]",
";",
"if",
"(",
"(",
"$",
"v",
"instanceof",
"MultipleContainer",
"||",
"$",
"v",
"instanceof",
"OrderedContainer",
")",
"&&",
"(",
"$",
"v",
"->",
"isNull",
"(",
")",
"||",
"$",
"v",
"->",
"getBaseType",
"(",
")",
"!==",
"BaseType",
"::",
"POINT",
")",
")",
"{",
"return",
"false",
";",
"}",
"elseif",
"(",
"!",
"$",
"v",
"instanceof",
"QtiPoint",
"&&",
"!",
"$",
"v",
"instanceof",
"MultipleContainer",
"&&",
"!",
"$",
"v",
"instanceof",
"OrderedContainer",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Wheter the collection of operands is composed exclusively of Point objects or Container objects
with a point baseType.
If the collection of operands contains something other than a Point object or a null Container object
with baseType point, false is returned.
@return boolean | [
"Wheter",
"the",
"collection",
"of",
"operands",
"is",
"composed",
"exclusively",
"of",
"Point",
"objects",
"or",
"Container",
"objects",
"with",
"a",
"point",
"baseType",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/OperandsCollection.php#L441-L457 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/OperandsCollection.php | OperandsCollection.exclusivelyDuration | public function exclusivelyDuration()
{
if (count($this) === 0) {
return false;
}
foreach (array_keys($this->getDataPlaceHolder()) as $key) {
$v = $this[$key];
if (($v instanceof MultipleContainer || $v instanceof OrderedContainer) && ($v->isNull() || $v->getBaseType() !== BaseType::DURATION)) {
return false;
} elseif (!$v instanceof QtiDuration && !$v instanceof MultipleContainer && !$v instanceof OrderedContainer) {
return false;
}
}
return true;
} | php | public function exclusivelyDuration()
{
if (count($this) === 0) {
return false;
}
foreach (array_keys($this->getDataPlaceHolder()) as $key) {
$v = $this[$key];
if (($v instanceof MultipleContainer || $v instanceof OrderedContainer) && ($v->isNull() || $v->getBaseType() !== BaseType::DURATION)) {
return false;
} elseif (!$v instanceof QtiDuration && !$v instanceof MultipleContainer && !$v instanceof OrderedContainer) {
return false;
}
}
return true;
} | [
"public",
"function",
"exclusivelyDuration",
"(",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
")",
"===",
"0",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"getDataPlaceHolder",
"(",
")",
")",
"as",
"$",
"key",
")",
"{",
"$",
"v",
"=",
"$",
"this",
"[",
"$",
"key",
"]",
";",
"if",
"(",
"(",
"$",
"v",
"instanceof",
"MultipleContainer",
"||",
"$",
"v",
"instanceof",
"OrderedContainer",
")",
"&&",
"(",
"$",
"v",
"->",
"isNull",
"(",
")",
"||",
"$",
"v",
"->",
"getBaseType",
"(",
")",
"!==",
"BaseType",
"::",
"DURATION",
")",
")",
"{",
"return",
"false",
";",
"}",
"elseif",
"(",
"!",
"$",
"v",
"instanceof",
"QtiDuration",
"&&",
"!",
"$",
"v",
"instanceof",
"MultipleContainer",
"&&",
"!",
"$",
"v",
"instanceof",
"OrderedContainer",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Wheter the collection of operands is composed exclusively of Duration objects or Container objects
with a duration baseType.
If the collection of operands contains something other than a Duration object or a null Container object
with baseType duration, false is returned.
@return boolean | [
"Wheter",
"the",
"collection",
"of",
"operands",
"is",
"composed",
"exclusively",
"of",
"Duration",
"objects",
"or",
"Container",
"objects",
"with",
"a",
"duration",
"baseType",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/OperandsCollection.php#L468-L484 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/FieldValueProcessor.php | FieldValueProcessor.process | public function process()
{
$operands = $this->getOperands();
if ($operands->exclusivelyRecord() === false) {
$msg = "The FieldValue operator only accepts operands with a cardinality of record.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
$fieldIdentifier = $this->getExpression()->getFieldIdentifier();
return $operands[0][$fieldIdentifier];
} | php | public function process()
{
$operands = $this->getOperands();
if ($operands->exclusivelyRecord() === false) {
$msg = "The FieldValue operator only accepts operands with a cardinality of record.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
$fieldIdentifier = $this->getExpression()->getFieldIdentifier();
return $operands[0][$fieldIdentifier];
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"operands",
"=",
"$",
"this",
"->",
"getOperands",
"(",
")",
";",
"if",
"(",
"$",
"operands",
"->",
"exclusivelyRecord",
"(",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The FieldValue operator only accepts operands with a cardinality of record.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_CARDINALITY",
")",
";",
"}",
"$",
"fieldIdentifier",
"=",
"$",
"this",
"->",
"getExpression",
"(",
")",
"->",
"getFieldIdentifier",
"(",
")",
";",
"return",
"$",
"operands",
"[",
"0",
"]",
"[",
"$",
"fieldIdentifier",
"]",
";",
"}"
] | Process the FieldValue object.
@return mixed|null A QTI Runtime compliant value or null if there is no field with that identifier.
@throws \qtism\runtime\expressions\operators\OperatorProcessingException | [
"Process",
"the",
"FieldValue",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/FieldValueProcessor.php#L49-L61 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/NumberSelectedProcessor.php | NumberSelectedProcessor.process | public function process()
{
$testSession = $this->getState();
$itemSubset = $this->getItemSubset();
$numberSelected = 0;
foreach ($itemSubset as $item) {
$itemSessions = $testSession->getAssessmentItemSessions($item->getIdentifier());
if ($itemSessions !== false) {
foreach ($itemSessions as $itemSession) {
if ($itemSession->isSelected() === true) {
$numberSelected++;
}
}
}
}
return new QtiInteger($numberSelected);
} | php | public function process()
{
$testSession = $this->getState();
$itemSubset = $this->getItemSubset();
$numberSelected = 0;
foreach ($itemSubset as $item) {
$itemSessions = $testSession->getAssessmentItemSessions($item->getIdentifier());
if ($itemSessions !== false) {
foreach ($itemSessions as $itemSession) {
if ($itemSession->isSelected() === true) {
$numberSelected++;
}
}
}
}
return new QtiInteger($numberSelected);
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"testSession",
"=",
"$",
"this",
"->",
"getState",
"(",
")",
";",
"$",
"itemSubset",
"=",
"$",
"this",
"->",
"getItemSubset",
"(",
")",
";",
"$",
"numberSelected",
"=",
"0",
";",
"foreach",
"(",
"$",
"itemSubset",
"as",
"$",
"item",
")",
"{",
"$",
"itemSessions",
"=",
"$",
"testSession",
"->",
"getAssessmentItemSessions",
"(",
"$",
"item",
"->",
"getIdentifier",
"(",
")",
")",
";",
"if",
"(",
"$",
"itemSessions",
"!==",
"false",
")",
"{",
"foreach",
"(",
"$",
"itemSessions",
"as",
"$",
"itemSession",
")",
"{",
"if",
"(",
"$",
"itemSession",
"->",
"isSelected",
"(",
")",
"===",
"true",
")",
"{",
"$",
"numberSelected",
"++",
";",
"}",
"}",
"}",
"}",
"return",
"new",
"QtiInteger",
"(",
"$",
"numberSelected",
")",
";",
"}"
] | Process the related NumberSelected expression.
@return integer The number of items in the given sub-set that have been selected for presentation to the candidate.
@throws \qtism\runtime\expressions\ExpressionProcessingException | [
"Process",
"the",
"related",
"NumberSelected",
"expression",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/NumberSelectedProcessor.php#L52-L71 |
oat-sa/qti-sdk | src/qtism/data/expressions/ItemSubset.php | ItemSubset.setSectionIdentifier | public function setSectionIdentifier($sectionIdentifier)
{
if (Format::isIdentifier($sectionIdentifier) || empty($sectionIdentifier)) {
$this->sectionIdentifier = $sectionIdentifier;
} else {
$msg = "'${sectionIndentifier}' is not a valid QTI Identifier.";
throw new InvalidArgumentException($msg);
}
} | php | public function setSectionIdentifier($sectionIdentifier)
{
if (Format::isIdentifier($sectionIdentifier) || empty($sectionIdentifier)) {
$this->sectionIdentifier = $sectionIdentifier;
} else {
$msg = "'${sectionIndentifier}' is not a valid QTI Identifier.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setSectionIdentifier",
"(",
"$",
"sectionIdentifier",
")",
"{",
"if",
"(",
"Format",
"::",
"isIdentifier",
"(",
"$",
"sectionIdentifier",
")",
"||",
"empty",
"(",
"$",
"sectionIdentifier",
")",
")",
"{",
"$",
"this",
"->",
"sectionIdentifier",
"=",
"$",
"sectionIdentifier",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"'${sectionIndentifier}' is not a valid QTI Identifier.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the assessment section identifier to match.
@param string $sectionIdentifier A QTI Identifier.
@throws \InvalidArgumentException If $sectionIdentifier is not a valid QTI Identifier. | [
"Set",
"the",
"assessment",
"section",
"identifier",
"to",
"match",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/expressions/ItemSubset.php#L88-L96 |
oat-sa/qti-sdk | src/qtism/data/content/xhtml/tables/TableCell.php | TableCell.setScope | public function setScope($scope)
{
if (in_array($scope, TableCellScope::asArray(), true) === true || $scope === -1) {
$this->scope = $scope;
} else {
$msg = "The 'scope' argument must be a value from the TableCellScope enumeration, '" . $scope . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setScope($scope)
{
if (in_array($scope, TableCellScope::asArray(), true) === true || $scope === -1) {
$this->scope = $scope;
} else {
$msg = "The 'scope' argument must be a value from the TableCellScope enumeration, '" . $scope . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setScope",
"(",
"$",
"scope",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"scope",
",",
"TableCellScope",
"::",
"asArray",
"(",
")",
",",
"true",
")",
"===",
"true",
"||",
"$",
"scope",
"===",
"-",
"1",
")",
"{",
"$",
"this",
"->",
"scope",
"=",
"$",
"scope",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'scope' argument must be a value from the TableCellScope enumeration, '\"",
".",
"$",
"scope",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the scope attribute.
@param integer $scope A value from the TableCellScope enumeration or -1 if no scope is defined.
@throws \InvalidArgumentException If $scope is not a value from the TableCellScope enumeration nor -1. | [
"Set",
"the",
"scope",
"attribute",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/xhtml/tables/TableCell.php#L154-L162 |
oat-sa/qti-sdk | src/qtism/data/content/xhtml/tables/TableCell.php | TableCell.setAbbr | public function setAbbr($abbr)
{
if (is_string($abbr) === true) {
$this->abbr = $abbr;
} else {
$msg = "The 'abbr' attribute must be a string, '" . gettype($abbr) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setAbbr($abbr)
{
if (is_string($abbr) === true) {
$this->abbr = $abbr;
} else {
$msg = "The 'abbr' attribute must be a string, '" . gettype($abbr) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setAbbr",
"(",
"$",
"abbr",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"abbr",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"abbr",
"=",
"$",
"abbr",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'abbr' attribute must be a string, '\"",
".",
"gettype",
"(",
"$",
"abbr",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the value of the abbr attribute.
@param string $attr A string or an empty string if no abbr is defined.
@throws \InvalidArgumentException If $bbr is not a string. | [
"Set",
"the",
"value",
"of",
"the",
"abbr",
"attribute",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/xhtml/tables/TableCell.php#L190-L198 |
oat-sa/qti-sdk | src/qtism/data/content/xhtml/tables/TableCell.php | TableCell.setAxis | public function setAxis($axis)
{
if (is_string($axis) === true) {
$this->axis = $axis;
} else {
$msg = "The 'axis' argument must be a string, '" . gettype($axis) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setAxis($axis)
{
if (is_string($axis) === true) {
$this->axis = $axis;
} else {
$msg = "The 'axis' argument must be a string, '" . gettype($axis) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setAxis",
"(",
"$",
"axis",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"axis",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"axis",
"=",
"$",
"axis",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'axis' argument must be a string, '\"",
".",
"gettype",
"(",
"$",
"axis",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the value of the axis attribute.
@param string $axis A string. Give an empty string if no axis is indicated.
@throws \InvalidArgumentException If $axis is not a string. | [
"Set",
"the",
"value",
"of",
"the",
"axis",
"attribute",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/xhtml/tables/TableCell.php#L226-L234 |
oat-sa/qti-sdk | src/qtism/data/content/xhtml/tables/TableCell.php | TableCell.setRowspan | public function setRowspan($rowspan)
{
if (is_int($rowspan) === true) {
$this->rowspan = $rowspan;
} else {
$msg = "The 'rowspan' argument must be an integer, '" . gettype($rowspan) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setRowspan($rowspan)
{
if (is_int($rowspan) === true) {
$this->rowspan = $rowspan;
} else {
$msg = "The 'rowspan' argument must be an integer, '" . gettype($rowspan) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setRowspan",
"(",
"$",
"rowspan",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"rowspan",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"rowspan",
"=",
"$",
"rowspan",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'rowspan' argument must be an integer, '\"",
".",
"gettype",
"(",
"$",
"rowspan",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the value of the rowspan attribute. Give a negative value if
no rowspan attribute is set.
@param integer $rowspan
@throws \InvalidArgumentException If $rowspan is not an integer. | [
"Set",
"the",
"value",
"of",
"the",
"rowspan",
"attribute",
".",
"Give",
"a",
"negative",
"value",
"if",
"no",
"rowspan",
"attribute",
"is",
"set",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/xhtml/tables/TableCell.php#L263-L271 |
oat-sa/qti-sdk | src/qtism/data/content/xhtml/tables/TableCell.php | TableCell.setColspan | public function setColspan($colspan)
{
if (is_int($colspan) === true) {
$this->colspan = $colspan;
} else {
$msg = "The 'colspan' argument must be an integer, '" . gettype($colspan) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setColspan($colspan)
{
if (is_int($colspan) === true) {
$this->colspan = $colspan;
} else {
$msg = "The 'colspan' argument must be an integer, '" . gettype($colspan) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setColspan",
"(",
"$",
"colspan",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"colspan",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"colspan",
"=",
"$",
"colspan",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'colspan' argument must be an integer, '\"",
".",
"gettype",
"(",
"$",
"colspan",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the colspan attribute. Give a negative integer to indicate that
no colspan is set.
@param integer $colspan An integer.
@throws \InvalidArgumentException If $colspan is not an integer. | [
"Set",
"the",
"colspan",
"attribute",
".",
"Give",
"a",
"negative",
"integer",
"to",
"indicate",
"that",
"no",
"colspan",
"is",
"set",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/xhtml/tables/TableCell.php#L301-L309 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/NumberPresentedMarshaller.php | NumberPresentedMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
$baseComponent = parent::unmarshall($element);
$object = new NumberPresented();
$object->setSectionIdentifier($baseComponent->getSectionIdentifier());
$object->setIncludeCategories($baseComponent->getIncludeCategories());
$object->setExcludeCategories($baseComponent->getExcludeCategories());
return $object;
} | php | protected function unmarshall(DOMElement $element)
{
$baseComponent = parent::unmarshall($element);
$object = new NumberPresented();
$object->setSectionIdentifier($baseComponent->getSectionIdentifier());
$object->setIncludeCategories($baseComponent->getIncludeCategories());
$object->setExcludeCategories($baseComponent->getExcludeCategories());
return $object;
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"$",
"baseComponent",
"=",
"parent",
"::",
"unmarshall",
"(",
"$",
"element",
")",
";",
"$",
"object",
"=",
"new",
"NumberPresented",
"(",
")",
";",
"$",
"object",
"->",
"setSectionIdentifier",
"(",
"$",
"baseComponent",
"->",
"getSectionIdentifier",
"(",
")",
")",
";",
"$",
"object",
"->",
"setIncludeCategories",
"(",
"$",
"baseComponent",
"->",
"getIncludeCategories",
"(",
")",
")",
";",
"$",
"object",
"->",
"setExcludeCategories",
"(",
"$",
"baseComponent",
"->",
"getExcludeCategories",
"(",
")",
")",
";",
"return",
"$",
"object",
";",
"}"
] | Marshall an numberPresented QTI element in its NumberPresented object equivalent.
@param \DOMElement A DOMElement object.
@return \qtism\data\QtiComponent The corresponding NumberPresented object. | [
"Marshall",
"an",
"numberPresented",
"QTI",
"element",
"in",
"its",
"NumberPresented",
"object",
"equivalent",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/NumberPresentedMarshaller.php#L56-L65 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/PositionObjectStageMarshaller.php | PositionObjectStageMarshaller.marshall | protected function marshall(QtiComponent $component)
{
$element = $this->createElement($component);
$object = $component->getObject();
$element->appendChild($this->getMarshallerFactory()->createMarshaller($object)->marshall($object));
foreach ($component->getPositionObjectInteractions() as $interaction) {
$element->appendChild($this->getMarshallerFactory()->createMarshaller($interaction)->marshall($interaction));
}
return $element;
} | php | protected function marshall(QtiComponent $component)
{
$element = $this->createElement($component);
$object = $component->getObject();
$element->appendChild($this->getMarshallerFactory()->createMarshaller($object)->marshall($object));
foreach ($component->getPositionObjectInteractions() as $interaction) {
$element->appendChild($this->getMarshallerFactory()->createMarshaller($interaction)->marshall($interaction));
}
return $element;
} | [
"protected",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"$",
"element",
"=",
"$",
"this",
"->",
"createElement",
"(",
"$",
"component",
")",
";",
"$",
"object",
"=",
"$",
"component",
"->",
"getObject",
"(",
")",
";",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"object",
")",
"->",
"marshall",
"(",
"$",
"object",
")",
")",
";",
"foreach",
"(",
"$",
"component",
"->",
"getPositionObjectInteractions",
"(",
")",
"as",
"$",
"interaction",
")",
"{",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"interaction",
")",
"->",
"marshall",
"(",
"$",
"interaction",
")",
")",
";",
"}",
"return",
"$",
"element",
";",
"}"
] | Marshall an PositionObjectStage object into a DOMElement object.
@param \qtism\data\QtiComponent $component A PositionObjectStage object.
@return \DOMElement The according DOMElement object.
@throws \qtism\data\storage\xml\marshalling\MarshallingException | [
"Marshall",
"an",
"PositionObjectStage",
"object",
"into",
"a",
"DOMElement",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/PositionObjectStageMarshaller.php#L45-L56 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/PositionObjectStageMarshaller.php | PositionObjectStageMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
$objectElts = $this->getChildElementsByTagName($element, 'object');
if (count($objectElts) > 0) {
$object = $this->getMarshallerFactory()->createMarshaller($objectElts[0])->unmarshall($objectElts[0]);
$positionObjectInteractionElts = $this->getChildElementsByTagName($element, 'positionObjectInteraction');
if (count($positionObjectInteractionElts) > 0) {
$positionObjectInteractions = new PositionObjectInteractionCollection();
foreach ($positionObjectInteractionElts as $interactionElt) {
$positionObjectInteractions[] = $this->getMarshallerFactory()->createMarshaller($interactionElt)->unmarshall($interactionElt);
}
return new PositionObjectStage($object, $positionObjectInteractions);
} else {
$msg = "A 'positionObjectStage' element must contain at least one 'positionObjectInteraction' element, none given.";
throw new UnmarshallingException($msg, $element);
}
} else {
$msg = "A 'positionObjectStage' element must contain exactly one 'object' element, none given.";
throw new UnmarshallingException($msg, $element);
}
} | php | protected function unmarshall(DOMElement $element)
{
$objectElts = $this->getChildElementsByTagName($element, 'object');
if (count($objectElts) > 0) {
$object = $this->getMarshallerFactory()->createMarshaller($objectElts[0])->unmarshall($objectElts[0]);
$positionObjectInteractionElts = $this->getChildElementsByTagName($element, 'positionObjectInteraction');
if (count($positionObjectInteractionElts) > 0) {
$positionObjectInteractions = new PositionObjectInteractionCollection();
foreach ($positionObjectInteractionElts as $interactionElt) {
$positionObjectInteractions[] = $this->getMarshallerFactory()->createMarshaller($interactionElt)->unmarshall($interactionElt);
}
return new PositionObjectStage($object, $positionObjectInteractions);
} else {
$msg = "A 'positionObjectStage' element must contain at least one 'positionObjectInteraction' element, none given.";
throw new UnmarshallingException($msg, $element);
}
} else {
$msg = "A 'positionObjectStage' element must contain exactly one 'object' element, none given.";
throw new UnmarshallingException($msg, $element);
}
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"$",
"objectElts",
"=",
"$",
"this",
"->",
"getChildElementsByTagName",
"(",
"$",
"element",
",",
"'object'",
")",
";",
"if",
"(",
"count",
"(",
"$",
"objectElts",
")",
">",
"0",
")",
"{",
"$",
"object",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"objectElts",
"[",
"0",
"]",
")",
"->",
"unmarshall",
"(",
"$",
"objectElts",
"[",
"0",
"]",
")",
";",
"$",
"positionObjectInteractionElts",
"=",
"$",
"this",
"->",
"getChildElementsByTagName",
"(",
"$",
"element",
",",
"'positionObjectInteraction'",
")",
";",
"if",
"(",
"count",
"(",
"$",
"positionObjectInteractionElts",
")",
">",
"0",
")",
"{",
"$",
"positionObjectInteractions",
"=",
"new",
"PositionObjectInteractionCollection",
"(",
")",
";",
"foreach",
"(",
"$",
"positionObjectInteractionElts",
"as",
"$",
"interactionElt",
")",
"{",
"$",
"positionObjectInteractions",
"[",
"]",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"interactionElt",
")",
"->",
"unmarshall",
"(",
"$",
"interactionElt",
")",
";",
"}",
"return",
"new",
"PositionObjectStage",
"(",
"$",
"object",
",",
"$",
"positionObjectInteractions",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"A 'positionObjectStage' element must contain at least one 'positionObjectInteraction' element, none given.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"A 'positionObjectStage' element must contain exactly one 'object' element, none given.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}"
] | Unmarshall a DOMElement object corresponding to an positionObjectStage element.
@param \DOMElement $element A DOMElement object.
@return \qtism\data\QtiComponent A PositionObjectStage object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException | [
"Unmarshall",
"a",
"DOMElement",
"object",
"corresponding",
"to",
"an",
"positionObjectStage",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/PositionObjectStageMarshaller.php#L65-L90 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/RecursiveMarshaller.php | RecursiveMarshaller.emptyFinal | protected function emptyFinal($count)
{
$returnValue = array();
while ($count > 0) {
$returnValue[] = array_pop($this->final);
$count--;
}
return array_reverse($returnValue);
} | php | protected function emptyFinal($count)
{
$returnValue = array();
while ($count > 0) {
$returnValue[] = array_pop($this->final);
$count--;
}
return array_reverse($returnValue);
} | [
"protected",
"function",
"emptyFinal",
"(",
"$",
"count",
")",
"{",
"$",
"returnValue",
"=",
"array",
"(",
")",
";",
"while",
"(",
"$",
"count",
">",
"0",
")",
"{",
"$",
"returnValue",
"[",
"]",
"=",
"array_pop",
"(",
"$",
"this",
"->",
"final",
")",
";",
"$",
"count",
"--",
";",
"}",
"return",
"array_reverse",
"(",
"$",
"returnValue",
")",
";",
"}"
] | Empty the final stack to get the objects inside.
@return array The content of the final stack. | [
"Empty",
"the",
"final",
"stack",
"to",
"get",
"the",
"objects",
"inside",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/RecursiveMarshaller.php#L161-L171 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/RecursiveMarshaller.php | RecursiveMarshaller.marshall | protected function marshall(QtiComponent $component)
{
// Reset.
$this->resetTrail();
$this->resetFinal();
$this->resetMark();
$this->resetProcessed();
$this->pushTrail($component);
while ($this->countTrail() > 0) {
$node = $this->popTrail();
if (!$node instanceof DOMElement && !$this->isMarked($node) && !$this->isComponentFinal($node)) {
// Hierarchical node, 1st pass.
$this->mark($node);
$this->pushTrail($node); // repush for a further pass.
$children = array_reverse($this->getChildrenComponents($node)); // next nodes to explore.
foreach ($children as $c) {
$this->pushTrail($c);
}
} elseif ($this->isMarked($node)) {
// Push the result on the trail.
$finals = $this->emptyFinal(count($this->getChildrenComponents($node)));
$marshaller = $this->getMarshallerFactory()->createMarshaller($node);
$element = $marshaller->marshallChildrenKnown($node, $finals);
$this->pushProcessed($element);
if ($node === $component) {
// This is our second pass on the root element, the process is finished.
return $element;
} else {
$this->pushTrail($element);
}
} else {
// It's a leaf!
if ($node instanceof DOMElement) {
$this->pushFinal($node);
} else {
$marshaller = $this->getMarshallerFactory()->createMarshaller($node);
$processed = $marshaller->marshall($node);
$this->pushFinal($processed);
$this->pushProcessed($processed);
}
}
}
} | php | protected function marshall(QtiComponent $component)
{
// Reset.
$this->resetTrail();
$this->resetFinal();
$this->resetMark();
$this->resetProcessed();
$this->pushTrail($component);
while ($this->countTrail() > 0) {
$node = $this->popTrail();
if (!$node instanceof DOMElement && !$this->isMarked($node) && !$this->isComponentFinal($node)) {
// Hierarchical node, 1st pass.
$this->mark($node);
$this->pushTrail($node); // repush for a further pass.
$children = array_reverse($this->getChildrenComponents($node)); // next nodes to explore.
foreach ($children as $c) {
$this->pushTrail($c);
}
} elseif ($this->isMarked($node)) {
// Push the result on the trail.
$finals = $this->emptyFinal(count($this->getChildrenComponents($node)));
$marshaller = $this->getMarshallerFactory()->createMarshaller($node);
$element = $marshaller->marshallChildrenKnown($node, $finals);
$this->pushProcessed($element);
if ($node === $component) {
// This is our second pass on the root element, the process is finished.
return $element;
} else {
$this->pushTrail($element);
}
} else {
// It's a leaf!
if ($node instanceof DOMElement) {
$this->pushFinal($node);
} else {
$marshaller = $this->getMarshallerFactory()->createMarshaller($node);
$processed = $marshaller->marshall($node);
$this->pushFinal($processed);
$this->pushProcessed($processed);
}
}
}
} | [
"protected",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"// Reset.",
"$",
"this",
"->",
"resetTrail",
"(",
")",
";",
"$",
"this",
"->",
"resetFinal",
"(",
")",
";",
"$",
"this",
"->",
"resetMark",
"(",
")",
";",
"$",
"this",
"->",
"resetProcessed",
"(",
")",
";",
"$",
"this",
"->",
"pushTrail",
"(",
"$",
"component",
")",
";",
"while",
"(",
"$",
"this",
"->",
"countTrail",
"(",
")",
">",
"0",
")",
"{",
"$",
"node",
"=",
"$",
"this",
"->",
"popTrail",
"(",
")",
";",
"if",
"(",
"!",
"$",
"node",
"instanceof",
"DOMElement",
"&&",
"!",
"$",
"this",
"->",
"isMarked",
"(",
"$",
"node",
")",
"&&",
"!",
"$",
"this",
"->",
"isComponentFinal",
"(",
"$",
"node",
")",
")",
"{",
"// Hierarchical node, 1st pass.",
"$",
"this",
"->",
"mark",
"(",
"$",
"node",
")",
";",
"$",
"this",
"->",
"pushTrail",
"(",
"$",
"node",
")",
";",
"// repush for a further pass.",
"$",
"children",
"=",
"array_reverse",
"(",
"$",
"this",
"->",
"getChildrenComponents",
"(",
"$",
"node",
")",
")",
";",
"// next nodes to explore.",
"foreach",
"(",
"$",
"children",
"as",
"$",
"c",
")",
"{",
"$",
"this",
"->",
"pushTrail",
"(",
"$",
"c",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"this",
"->",
"isMarked",
"(",
"$",
"node",
")",
")",
"{",
"// Push the result on the trail.",
"$",
"finals",
"=",
"$",
"this",
"->",
"emptyFinal",
"(",
"count",
"(",
"$",
"this",
"->",
"getChildrenComponents",
"(",
"$",
"node",
")",
")",
")",
";",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"node",
")",
";",
"$",
"element",
"=",
"$",
"marshaller",
"->",
"marshallChildrenKnown",
"(",
"$",
"node",
",",
"$",
"finals",
")",
";",
"$",
"this",
"->",
"pushProcessed",
"(",
"$",
"element",
")",
";",
"if",
"(",
"$",
"node",
"===",
"$",
"component",
")",
"{",
"// This is our second pass on the root element, the process is finished.",
"return",
"$",
"element",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"pushTrail",
"(",
"$",
"element",
")",
";",
"}",
"}",
"else",
"{",
"// It's a leaf!",
"if",
"(",
"$",
"node",
"instanceof",
"DOMElement",
")",
"{",
"$",
"this",
"->",
"pushFinal",
"(",
"$",
"node",
")",
";",
"}",
"else",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"node",
")",
";",
"$",
"processed",
"=",
"$",
"marshaller",
"->",
"marshall",
"(",
"$",
"node",
")",
";",
"$",
"this",
"->",
"pushFinal",
"(",
"$",
"processed",
")",
";",
"$",
"this",
"->",
"pushProcessed",
"(",
"$",
"processed",
")",
";",
"}",
"}",
"}",
"}"
] | Marshall a QtiComponent that might contain instances of the same class as itself.
@param \qtism\data\QtiComponent $component The QtiComponent object to marshall.
@return \DOMElement A DOMElement corresponding to the QtiComponent to marshall.
@throws \qtism\data\storage\xml\marshalling\MarshallingException If an error occurs during the marshalling process. | [
"Marshall",
"a",
"QtiComponent",
"that",
"might",
"contain",
"instances",
"of",
"the",
"same",
"class",
"as",
"itself",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/RecursiveMarshaller.php#L217-L265 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/RecursiveMarshaller.php | RecursiveMarshaller.unmarshall | protected function unmarshall(DOMElement $element, QtiComponent $rootComponent = null)
{
// Reset.
$this->resetTrail();
$this->resetFinal();
$this->resetMark();
$this->resetProcessed();
$this->pushTrail($element);
// Begin the traversing of the n-ary tree... as a graph!
while ($this->countTrail() > 0) {
$node = $this->popTrail();
if (!$node instanceof QtiComponent && !$this->isMarked($node) && !$this->isElementFinal($node)) {
// Hierarchical node, first pass.
$this->mark($node);
$this->pushTrail($node); // repush for a second pass.
$children = array_reverse($this->getChildrenElements($node)); // further exploration.
foreach ($children as $c) {
$this->pushTrail($c);
}
} elseif ($this->isMarked($node)) {
// Hierarchical node, second pass.
// Push the result on the trail.
$finals = $this->emptyFinal(count($this->getChildrenElements($node)));
$componentCollection = $this->createCollection($node);
foreach ($finals as $f) {
$componentCollection[] = $f;
}
$marshaller = $this->getMarshallerFactory()->createMarshaller($node);
// Root node?
if ($node === $element && !empty($rootComponent)) {
$component = $marshaller->unmarshallChildrenKnown($node, $componentCollection, $rootComponent);
} else {
if ($marshaller instanceof RecursiveMarshaller) {
$component = $marshaller->unmarshallChildrenKnown($node, $componentCollection);
} else {
$component = $marshaller->unmarshall($node);
}
}
$this->pushProcessed($component);
// Root node ?
if ($node === $element) {
// Second pass on the root element, we can return.
return $component;
} else {
$this->pushTrail($component);
}
} else {
// Leaf node.
if ($node instanceof QtiComponent) {
$this->pushFinal($node);
} else {
if ($node instanceof DOMText) {
$node = self::getDOMCradle()->createElement('textRun', preg_replace('/&(?!\w+;)/', '&', $node->wholeText));
}
// Process it and make its a final element to be used by hierarchical nodes.
$marshaller = $this->getMarshallerFactory()->createMarshaller($node);
$processed = $marshaller->unmarshall($node);
$this->pushFinal($processed);
$this->pushProcessed($processed);
}
}
}
} | php | protected function unmarshall(DOMElement $element, QtiComponent $rootComponent = null)
{
// Reset.
$this->resetTrail();
$this->resetFinal();
$this->resetMark();
$this->resetProcessed();
$this->pushTrail($element);
// Begin the traversing of the n-ary tree... as a graph!
while ($this->countTrail() > 0) {
$node = $this->popTrail();
if (!$node instanceof QtiComponent && !$this->isMarked($node) && !$this->isElementFinal($node)) {
// Hierarchical node, first pass.
$this->mark($node);
$this->pushTrail($node); // repush for a second pass.
$children = array_reverse($this->getChildrenElements($node)); // further exploration.
foreach ($children as $c) {
$this->pushTrail($c);
}
} elseif ($this->isMarked($node)) {
// Hierarchical node, second pass.
// Push the result on the trail.
$finals = $this->emptyFinal(count($this->getChildrenElements($node)));
$componentCollection = $this->createCollection($node);
foreach ($finals as $f) {
$componentCollection[] = $f;
}
$marshaller = $this->getMarshallerFactory()->createMarshaller($node);
// Root node?
if ($node === $element && !empty($rootComponent)) {
$component = $marshaller->unmarshallChildrenKnown($node, $componentCollection, $rootComponent);
} else {
if ($marshaller instanceof RecursiveMarshaller) {
$component = $marshaller->unmarshallChildrenKnown($node, $componentCollection);
} else {
$component = $marshaller->unmarshall($node);
}
}
$this->pushProcessed($component);
// Root node ?
if ($node === $element) {
// Second pass on the root element, we can return.
return $component;
} else {
$this->pushTrail($component);
}
} else {
// Leaf node.
if ($node instanceof QtiComponent) {
$this->pushFinal($node);
} else {
if ($node instanceof DOMText) {
$node = self::getDOMCradle()->createElement('textRun', preg_replace('/&(?!\w+;)/', '&', $node->wholeText));
}
// Process it and make its a final element to be used by hierarchical nodes.
$marshaller = $this->getMarshallerFactory()->createMarshaller($node);
$processed = $marshaller->unmarshall($node);
$this->pushFinal($processed);
$this->pushProcessed($processed);
}
}
}
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
",",
"QtiComponent",
"$",
"rootComponent",
"=",
"null",
")",
"{",
"// Reset.",
"$",
"this",
"->",
"resetTrail",
"(",
")",
";",
"$",
"this",
"->",
"resetFinal",
"(",
")",
";",
"$",
"this",
"->",
"resetMark",
"(",
")",
";",
"$",
"this",
"->",
"resetProcessed",
"(",
")",
";",
"$",
"this",
"->",
"pushTrail",
"(",
"$",
"element",
")",
";",
"// Begin the traversing of the n-ary tree... as a graph!",
"while",
"(",
"$",
"this",
"->",
"countTrail",
"(",
")",
">",
"0",
")",
"{",
"$",
"node",
"=",
"$",
"this",
"->",
"popTrail",
"(",
")",
";",
"if",
"(",
"!",
"$",
"node",
"instanceof",
"QtiComponent",
"&&",
"!",
"$",
"this",
"->",
"isMarked",
"(",
"$",
"node",
")",
"&&",
"!",
"$",
"this",
"->",
"isElementFinal",
"(",
"$",
"node",
")",
")",
"{",
"// Hierarchical node, first pass.",
"$",
"this",
"->",
"mark",
"(",
"$",
"node",
")",
";",
"$",
"this",
"->",
"pushTrail",
"(",
"$",
"node",
")",
";",
"// repush for a second pass.",
"$",
"children",
"=",
"array_reverse",
"(",
"$",
"this",
"->",
"getChildrenElements",
"(",
"$",
"node",
")",
")",
";",
"// further exploration.",
"foreach",
"(",
"$",
"children",
"as",
"$",
"c",
")",
"{",
"$",
"this",
"->",
"pushTrail",
"(",
"$",
"c",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"this",
"->",
"isMarked",
"(",
"$",
"node",
")",
")",
"{",
"// Hierarchical node, second pass.",
"// Push the result on the trail.",
"$",
"finals",
"=",
"$",
"this",
"->",
"emptyFinal",
"(",
"count",
"(",
"$",
"this",
"->",
"getChildrenElements",
"(",
"$",
"node",
")",
")",
")",
";",
"$",
"componentCollection",
"=",
"$",
"this",
"->",
"createCollection",
"(",
"$",
"node",
")",
";",
"foreach",
"(",
"$",
"finals",
"as",
"$",
"f",
")",
"{",
"$",
"componentCollection",
"[",
"]",
"=",
"$",
"f",
";",
"}",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"node",
")",
";",
"// Root node?",
"if",
"(",
"$",
"node",
"===",
"$",
"element",
"&&",
"!",
"empty",
"(",
"$",
"rootComponent",
")",
")",
"{",
"$",
"component",
"=",
"$",
"marshaller",
"->",
"unmarshallChildrenKnown",
"(",
"$",
"node",
",",
"$",
"componentCollection",
",",
"$",
"rootComponent",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"marshaller",
"instanceof",
"RecursiveMarshaller",
")",
"{",
"$",
"component",
"=",
"$",
"marshaller",
"->",
"unmarshallChildrenKnown",
"(",
"$",
"node",
",",
"$",
"componentCollection",
")",
";",
"}",
"else",
"{",
"$",
"component",
"=",
"$",
"marshaller",
"->",
"unmarshall",
"(",
"$",
"node",
")",
";",
"}",
"}",
"$",
"this",
"->",
"pushProcessed",
"(",
"$",
"component",
")",
";",
"// Root node ?",
"if",
"(",
"$",
"node",
"===",
"$",
"element",
")",
"{",
"// Second pass on the root element, we can return.",
"return",
"$",
"component",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"pushTrail",
"(",
"$",
"component",
")",
";",
"}",
"}",
"else",
"{",
"// Leaf node.",
"if",
"(",
"$",
"node",
"instanceof",
"QtiComponent",
")",
"{",
"$",
"this",
"->",
"pushFinal",
"(",
"$",
"node",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"node",
"instanceof",
"DOMText",
")",
"{",
"$",
"node",
"=",
"self",
"::",
"getDOMCradle",
"(",
")",
"->",
"createElement",
"(",
"'textRun'",
",",
"preg_replace",
"(",
"'/&(?!\\w+;)/'",
",",
"'&'",
",",
"$",
"node",
"->",
"wholeText",
")",
")",
";",
"}",
"// Process it and make its a final element to be used by hierarchical nodes.",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"node",
")",
";",
"$",
"processed",
"=",
"$",
"marshaller",
"->",
"unmarshall",
"(",
"$",
"node",
")",
";",
"$",
"this",
"->",
"pushFinal",
"(",
"$",
"processed",
")",
";",
"$",
"this",
"->",
"pushProcessed",
"(",
"$",
"processed",
")",
";",
"}",
"}",
"}",
"}"
] | Unmarshall a DOMElement that might contain elements of the same QTI class as itself.
@param \DOMElement $element The DOMElement object to unmarshall.
@param \qtism\data\QtiComponent $rootComponent An optional already instantiated QtiComponent to use as the root component.
@return \qtism\data\QtiComponent A QtiComponent object corresponding to the DOMElement to unmarshall. | [
"Unmarshall",
"a",
"DOMElement",
"that",
"might",
"contain",
"elements",
"of",
"the",
"same",
"QTI",
"class",
"as",
"itself",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/RecursiveMarshaller.php#L274-L347 |
oat-sa/qti-sdk | src/qtism/runtime/rules/RuleEngine.php | RuleEngine.setComponent | public function setComponent(QtiComponent $rule)
{
if ($rule instanceof Rule) {
parent::setComponent($rule);
} else {
$msg = "The RuleEngine class only accepts to execute Rule objects.";
throw new InvalidArgumentException($msg);
}
} | php | public function setComponent(QtiComponent $rule)
{
if ($rule instanceof Rule) {
parent::setComponent($rule);
} else {
$msg = "The RuleEngine class only accepts to execute Rule objects.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setComponent",
"(",
"QtiComponent",
"$",
"rule",
")",
"{",
"if",
"(",
"$",
"rule",
"instanceof",
"Rule",
")",
"{",
"parent",
"::",
"setComponent",
"(",
"$",
"rule",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The RuleEngine class only accepts to execute Rule objects.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the Rule object to be executed by the engine.
@param \qtism\data\QtiComponent $rule A Rule object to be executed.
@throws \InvalidArgumentException If $rule is not a Rule object. | [
"Set",
"the",
"Rule",
"object",
"to",
"be",
"executed",
"by",
"the",
"engine",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rules/RuleEngine.php#L68-L76 |
oat-sa/qti-sdk | src/qtism/runtime/rules/RuleEngine.php | RuleEngine.process | public function process()
{
$rule = $this->getComponent();
$context = $this->getContext();
$processor = $this->getRuleProcessorFactory()->createProcessor($rule);
$processor->setState($context);
$processor->process();
$this->trace($rule->getQtiClassName());
} | php | public function process()
{
$rule = $this->getComponent();
$context = $this->getContext();
$processor = $this->getRuleProcessorFactory()->createProcessor($rule);
$processor->setState($context);
$processor->process();
$this->trace($rule->getQtiClassName());
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"rule",
"=",
"$",
"this",
"->",
"getComponent",
"(",
")",
";",
"$",
"context",
"=",
"$",
"this",
"->",
"getContext",
"(",
")",
";",
"$",
"processor",
"=",
"$",
"this",
"->",
"getRuleProcessorFactory",
"(",
")",
"->",
"createProcessor",
"(",
"$",
"rule",
")",
";",
"$",
"processor",
"->",
"setState",
"(",
"$",
"context",
")",
";",
"$",
"processor",
"->",
"process",
"(",
")",
";",
"$",
"this",
"->",
"trace",
"(",
"$",
"rule",
"->",
"getQtiClassName",
"(",
")",
")",
";",
"}"
] | Execute the current Rule object.
@throws \qtism\runtime\rules\RuleProcessingException | [
"Execute",
"the",
"current",
"Rule",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rules/RuleEngine.php#L103-L113 |
oat-sa/qti-sdk | src/qtism/data/content/BodyElement.php | BodyElement.setId | public function setId($id = '')
{
if (is_string($id) && (empty($id) === true || Format::isIdentifier($id, false) === true)) {
$this->id = $id;
} else {
$msg = "The 'id' argument of a body element must be a valid identifier or an empty string";
throw new InvalidArgumentException($msg);
}
} | php | public function setId($id = '')
{
if (is_string($id) && (empty($id) === true || Format::isIdentifier($id, false) === true)) {
$this->id = $id;
} else {
$msg = "The 'id' argument of a body element must be a valid identifier or an empty string";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setId",
"(",
"$",
"id",
"=",
"''",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"id",
")",
"&&",
"(",
"empty",
"(",
"$",
"id",
")",
"===",
"true",
"||",
"Format",
"::",
"isIdentifier",
"(",
"$",
"id",
",",
"false",
")",
"===",
"true",
")",
")",
"{",
"$",
"this",
"->",
"id",
"=",
"$",
"id",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'id' argument of a body element must be a valid identifier or an empty string\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the unique identifier of the body element.
@param string $id A QTI Identifier.
@throws \InvalidArgumentException If $id is not a valid QTI identifier. | [
"Set",
"the",
"unique",
"identifier",
"of",
"the",
"body",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/BodyElement.php#L129-L137 |
oat-sa/qti-sdk | src/qtism/data/content/BodyElement.php | BodyElement.setClass | public function setClass($class = '')
{
if (is_string($class) && (empty($class) === true || Format::isClass($class) === true)) {
$class = trim($class);
$this->class = $class;
} else {
$msg = "The 'class' argument must be a valid class name, '" . $class . "' given";
throw new InvalidArgumentException($msg);
}
} | php | public function setClass($class = '')
{
if (is_string($class) && (empty($class) === true || Format::isClass($class) === true)) {
$class = trim($class);
$this->class = $class;
} else {
$msg = "The 'class' argument must be a valid class name, '" . $class . "' given";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setClass",
"(",
"$",
"class",
"=",
"''",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"class",
")",
"&&",
"(",
"empty",
"(",
"$",
"class",
")",
"===",
"true",
"||",
"Format",
"::",
"isClass",
"(",
"$",
"class",
")",
"===",
"true",
")",
")",
"{",
"$",
"class",
"=",
"trim",
"(",
"$",
"class",
")",
";",
"$",
"this",
"->",
"class",
"=",
"$",
"class",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'class' argument must be a valid class name, '\"",
".",
"$",
"class",
".",
"\"' given\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the classes assigned to the body element.
@param string $class One or more class names separated by spaces.
@throws \InvalidArgumentException If $class does not represent valid class name(s). | [
"Set",
"the",
"classes",
"assigned",
"to",
"the",
"body",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/BodyElement.php#L165-L174 |
oat-sa/qti-sdk | src/qtism/data/content/BodyElement.php | BodyElement.setDir | public function setDir($dir)
{
if (in_array($dir, Direction::asArray(), true) === true) {
$this->dir = $dir;
} else {
$msg = "The 'dir' argument must be a value from the Direction enumeration.";
throw new InvalidArgumentException($msg);
}
} | php | public function setDir($dir)
{
if (in_array($dir, Direction::asArray(), true) === true) {
$this->dir = $dir;
} else {
$msg = "The 'dir' argument must be a value from the Direction enumeration.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setDir",
"(",
"$",
"dir",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"dir",
",",
"Direction",
"::",
"asArray",
"(",
")",
",",
"true",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"dir",
"=",
"$",
"dir",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'dir' argument must be a value from the Direction enumeration.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the direction in which body elements must be displayed.
@param integer $dir A value from the Direction enumeration.
@throws InvalidArgumentException If $dir is not a value from the Direction enumeration. | [
"Set",
"the",
"direction",
"in",
"which",
"body",
"elements",
"must",
"be",
"displayed",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/BodyElement.php#L258-L266 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/OutcomeMinimumMarshaller.php | OutcomeMinimumMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
$baseComponent = parent::unmarshall($element);
if (($outcomeIdentifier = $this->getDOMElementAttributeAs($element, 'outcomeIdentifier')) !== null) {
$object = new OutcomeMinimum($outcomeIdentifier);
$object->setSectionIdentifier($baseComponent->getSectionIdentifier());
$object->setIncludeCategories($baseComponent->getIncludeCategories());
$object->setExcludeCategories($baseComponent->getExcludeCategories());
if (($weightIdentifier = $this->getDOMElementAttributeAs($element, 'weightIdentifier')) !== null) {
$object->setWeightIdentifier($weightIdentifier);
}
return $object;
} else {
$msg = "The mandatory attribute 'outcomeIdentifier' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} | php | protected function unmarshall(DOMElement $element)
{
$baseComponent = parent::unmarshall($element);
if (($outcomeIdentifier = $this->getDOMElementAttributeAs($element, 'outcomeIdentifier')) !== null) {
$object = new OutcomeMinimum($outcomeIdentifier);
$object->setSectionIdentifier($baseComponent->getSectionIdentifier());
$object->setIncludeCategories($baseComponent->getIncludeCategories());
$object->setExcludeCategories($baseComponent->getExcludeCategories());
if (($weightIdentifier = $this->getDOMElementAttributeAs($element, 'weightIdentifier')) !== null) {
$object->setWeightIdentifier($weightIdentifier);
}
return $object;
} else {
$msg = "The mandatory attribute 'outcomeIdentifier' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"$",
"baseComponent",
"=",
"parent",
"::",
"unmarshall",
"(",
"$",
"element",
")",
";",
"if",
"(",
"(",
"$",
"outcomeIdentifier",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'outcomeIdentifier'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"object",
"=",
"new",
"OutcomeMinimum",
"(",
"$",
"outcomeIdentifier",
")",
";",
"$",
"object",
"->",
"setSectionIdentifier",
"(",
"$",
"baseComponent",
"->",
"getSectionIdentifier",
"(",
")",
")",
";",
"$",
"object",
"->",
"setIncludeCategories",
"(",
"$",
"baseComponent",
"->",
"getIncludeCategories",
"(",
")",
")",
";",
"$",
"object",
"->",
"setExcludeCategories",
"(",
"$",
"baseComponent",
"->",
"getExcludeCategories",
"(",
")",
")",
";",
"if",
"(",
"(",
"$",
"weightIdentifier",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'weightIdentifier'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"object",
"->",
"setWeightIdentifier",
"(",
"$",
"weightIdentifier",
")",
";",
"}",
"return",
"$",
"object",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory attribute 'outcomeIdentifier' is missing from element '\"",
".",
"$",
"element",
"->",
"localName",
".",
"\"'.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}"
] | Marshall a outcomeMinimum QTI element in its OutcomeMinimum object equivalent.
@param \DOMElement A DOMElement object.
@return \qtism\data\QtiComponent The corresponding OutcomeMinimum object. | [
"Marshall",
"a",
"outcomeMinimum",
"QTI",
"element",
"in",
"its",
"OutcomeMinimum",
"object",
"equivalent",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/OutcomeMinimumMarshaller.php#L62-L81 |
oat-sa/qti-sdk | src/qtism/data/state/Mapping.php | Mapping.setLowerBound | public function setLowerBound($lowerBound)
{
if (is_float($lowerBound) || is_double($lowerBound) || (is_bool($lowerBound) && $lowerBound === false)) {
$this->lowerBound = $lowerBound;
} else {
$msg = "The 'lowerBound' attribute must be a float or false, '" . gettype($lowerBound) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setLowerBound($lowerBound)
{
if (is_float($lowerBound) || is_double($lowerBound) || (is_bool($lowerBound) && $lowerBound === false)) {
$this->lowerBound = $lowerBound;
} else {
$msg = "The 'lowerBound' attribute must be a float or false, '" . gettype($lowerBound) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setLowerBound",
"(",
"$",
"lowerBound",
")",
"{",
"if",
"(",
"is_float",
"(",
"$",
"lowerBound",
")",
"||",
"is_double",
"(",
"$",
"lowerBound",
")",
"||",
"(",
"is_bool",
"(",
"$",
"lowerBound",
")",
"&&",
"$",
"lowerBound",
"===",
"false",
")",
")",
"{",
"$",
"this",
"->",
"lowerBound",
"=",
"$",
"lowerBound",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'lowerBound' attribute must be a float or false, '\"",
".",
"gettype",
"(",
"$",
"lowerBound",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the lower bound.
@param boolean|float $lowerBound A float or false if not lower bound.
@throws \InvalidArgumentException If $lowerBound is not a float nor false. | [
"Set",
"the",
"lower",
"bound",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/state/Mapping.php#L111-L119 |
oat-sa/qti-sdk | src/qtism/data/state/Mapping.php | Mapping.setDefaultValue | public function setDefaultValue($defaultValue)
{
if (is_numeric($defaultValue)) {
$this->defaultValue = $defaultValue;
} else {
$msg = "The 'defaultValue' argument must be a numeric value, '" . gettype($defaultValue) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setDefaultValue($defaultValue)
{
if (is_numeric($defaultValue)) {
$this->defaultValue = $defaultValue;
} else {
$msg = "The 'defaultValue' argument must be a numeric value, '" . gettype($defaultValue) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setDefaultValue",
"(",
"$",
"defaultValue",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"defaultValue",
")",
")",
"{",
"$",
"this",
"->",
"defaultValue",
"=",
"$",
"defaultValue",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'defaultValue' argument must be a numeric value, '\"",
".",
"gettype",
"(",
"$",
"defaultValue",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the default value of the Mapping.
@param float $defaultValue A float value.
@throws \InvalidArgumentException If $defaultValue is not a float value. | [
"Set",
"the",
"default",
"value",
"of",
"the",
"Mapping",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/state/Mapping.php#L183-L191 |
oat-sa/qti-sdk | src/qtism/data/state/Mapping.php | Mapping.setMapEntries | public function setMapEntries(MapEntryCollection $mapEntries)
{
if (count($mapEntries) > 0) {
$this->mapEntries = $mapEntries;
} else {
$msg = "A Mapping object must contain at least one MapEntry object, none given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setMapEntries(MapEntryCollection $mapEntries)
{
if (count($mapEntries) > 0) {
$this->mapEntries = $mapEntries;
} else {
$msg = "A Mapping object must contain at least one MapEntry object, none given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setMapEntries",
"(",
"MapEntryCollection",
"$",
"mapEntries",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"mapEntries",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"mapEntries",
"=",
"$",
"mapEntries",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"A Mapping object must contain at least one MapEntry object, none given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the collection of MapEntry objects which compose the Mapping.
@param \qtism\data\state\MapEntryCollection $mapEntries A collection of MapEntry objects with at least one item.
@throws \InvalidArgumentException If $mapEnties is an empty collection. | [
"Set",
"the",
"collection",
"of",
"MapEntry",
"objects",
"which",
"compose",
"the",
"Mapping",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/state/Mapping.php#L209-L217 |
oat-sa/qti-sdk | src/qtism/data/state/CorrectResponse.php | CorrectResponse.setValues | public function setValues(ValueCollection $values)
{
if (count($values) > 0) {
$this->values = $values;
} else {
$msg = "Values must contain at lease one Value.";
throw new InvalidArgumentException($msg);
}
} | php | public function setValues(ValueCollection $values)
{
if (count($values) > 0) {
$this->values = $values;
} else {
$msg = "Values must contain at lease one Value.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setValues",
"(",
"ValueCollection",
"$",
"values",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"values",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"values",
"=",
"$",
"values",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"Values must contain at lease one Value.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the intrinsic values of the CorrectResponse.
@param \qtism\data\state\ValueCollection $values A collection of Value objects containing at least one Value object.
@throws \InvalidArgumentException If $values does not contain at least one Value object. | [
"Set",
"the",
"intrinsic",
"values",
"of",
"the",
"CorrectResponse",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/state/CorrectResponse.php#L115-L123 |
oat-sa/qti-sdk | src/qtism/runtime/rules/SetCorrectResponseProcessor.php | SetCorrectResponseProcessor.process | public function process()
{
$rule = $this->getRule();
$state = $this->getState();
$variableIdentifier = $rule->getIdentifier();
$var = $state->getVariable($variableIdentifier);
if (is_null($var) === true) {
$msg = "No variable with identifier '${variableIdentifier}' to be set in the current state.";
throw new RuleProcessingException($msg, $this, RuleProcessingException::NONEXISTENT_VARIABLE);
} elseif (!$var instanceof ResponseVariable) {
$msg = "The variable to set '${variableIdentifier}' is not an instance of 'ResponseVariable'.";
throw new RuleProcessingException($msg, $this, RuleProcessingException::WRONG_VARIABLE_TYPE);
}
try {
$expressionEngine = new ExpressionEngine($rule->getExpression(), $state);
$val = $expressionEngine->process();
$var->setCorrectResponse($val);
} catch (InvalidArgumentException $e) {
$varBaseType = (BaseType::getNameByConstant($var->getBaseType()) === false) ? 'noBaseType' : BaseType::getNameByConstant($var->getBaseType());
$varCardinality = (Cardinality::getNameByConstant($var->getCardinality()));
// The affected value does not match the baseType of the variable $var.
$msg = "Unable to set value ${val} to variable '${variableIdentifier}' (cardinality = ${varCardinality}, baseType = ${varBaseType}).";
throw new RuleProcessingException($msg, $this, RuleProcessingException::WRONG_VARIABLE_BASETYPE, $e);
} catch (ExpressionProcessingException $e) {
$msg = "An error occured while processing the expression bound with the 'SetCorrectResponse' rule.";
throw new RuleProcessingException($msg, $this, RuleProcessingException::RUNTIME_ERROR, $e);
}
} | php | public function process()
{
$rule = $this->getRule();
$state = $this->getState();
$variableIdentifier = $rule->getIdentifier();
$var = $state->getVariable($variableIdentifier);
if (is_null($var) === true) {
$msg = "No variable with identifier '${variableIdentifier}' to be set in the current state.";
throw new RuleProcessingException($msg, $this, RuleProcessingException::NONEXISTENT_VARIABLE);
} elseif (!$var instanceof ResponseVariable) {
$msg = "The variable to set '${variableIdentifier}' is not an instance of 'ResponseVariable'.";
throw new RuleProcessingException($msg, $this, RuleProcessingException::WRONG_VARIABLE_TYPE);
}
try {
$expressionEngine = new ExpressionEngine($rule->getExpression(), $state);
$val = $expressionEngine->process();
$var->setCorrectResponse($val);
} catch (InvalidArgumentException $e) {
$varBaseType = (BaseType::getNameByConstant($var->getBaseType()) === false) ? 'noBaseType' : BaseType::getNameByConstant($var->getBaseType());
$varCardinality = (Cardinality::getNameByConstant($var->getCardinality()));
// The affected value does not match the baseType of the variable $var.
$msg = "Unable to set value ${val} to variable '${variableIdentifier}' (cardinality = ${varCardinality}, baseType = ${varBaseType}).";
throw new RuleProcessingException($msg, $this, RuleProcessingException::WRONG_VARIABLE_BASETYPE, $e);
} catch (ExpressionProcessingException $e) {
$msg = "An error occured while processing the expression bound with the 'SetCorrectResponse' rule.";
throw new RuleProcessingException($msg, $this, RuleProcessingException::RUNTIME_ERROR, $e);
}
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"rule",
"=",
"$",
"this",
"->",
"getRule",
"(",
")",
";",
"$",
"state",
"=",
"$",
"this",
"->",
"getState",
"(",
")",
";",
"$",
"variableIdentifier",
"=",
"$",
"rule",
"->",
"getIdentifier",
"(",
")",
";",
"$",
"var",
"=",
"$",
"state",
"->",
"getVariable",
"(",
"$",
"variableIdentifier",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"var",
")",
"===",
"true",
")",
"{",
"$",
"msg",
"=",
"\"No variable with identifier '${variableIdentifier}' to be set in the current state.\"",
";",
"throw",
"new",
"RuleProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"RuleProcessingException",
"::",
"NONEXISTENT_VARIABLE",
")",
";",
"}",
"elseif",
"(",
"!",
"$",
"var",
"instanceof",
"ResponseVariable",
")",
"{",
"$",
"msg",
"=",
"\"The variable to set '${variableIdentifier}' is not an instance of 'ResponseVariable'.\"",
";",
"throw",
"new",
"RuleProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"RuleProcessingException",
"::",
"WRONG_VARIABLE_TYPE",
")",
";",
"}",
"try",
"{",
"$",
"expressionEngine",
"=",
"new",
"ExpressionEngine",
"(",
"$",
"rule",
"->",
"getExpression",
"(",
")",
",",
"$",
"state",
")",
";",
"$",
"val",
"=",
"$",
"expressionEngine",
"->",
"process",
"(",
")",
";",
"$",
"var",
"->",
"setCorrectResponse",
"(",
"$",
"val",
")",
";",
"}",
"catch",
"(",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"$",
"varBaseType",
"=",
"(",
"BaseType",
"::",
"getNameByConstant",
"(",
"$",
"var",
"->",
"getBaseType",
"(",
")",
")",
"===",
"false",
")",
"?",
"'noBaseType'",
":",
"BaseType",
"::",
"getNameByConstant",
"(",
"$",
"var",
"->",
"getBaseType",
"(",
")",
")",
";",
"$",
"varCardinality",
"=",
"(",
"Cardinality",
"::",
"getNameByConstant",
"(",
"$",
"var",
"->",
"getCardinality",
"(",
")",
")",
")",
";",
"// The affected value does not match the baseType of the variable $var.",
"$",
"msg",
"=",
"\"Unable to set value ${val} to variable '${variableIdentifier}' (cardinality = ${varCardinality}, baseType = ${varBaseType}).\"",
";",
"throw",
"new",
"RuleProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"RuleProcessingException",
"::",
"WRONG_VARIABLE_BASETYPE",
",",
"$",
"e",
")",
";",
"}",
"catch",
"(",
"ExpressionProcessingException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while processing the expression bound with the 'SetCorrectResponse' rule.\"",
";",
"throw",
"new",
"RuleProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"RuleProcessingException",
"::",
"RUNTIME_ERROR",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Apply the current SetCorrectResponse rule on the current state.
A RuleProcessingException will be thrown if:
* No variable corresponds to the given identifier in the current state.
* The target variable is not a ResponseVariable.
* The baseType and/or cardinality of the value to be set does not correspond to the baseType and/or cardinality of the target variable.
* An error occurs while processing the expression representing the value to be set.
@throws \qtism\runtime\rules\RuleProcessingException | [
"Apply",
"the",
"current",
"SetCorrectResponse",
"rule",
"on",
"the",
"current",
"state",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rules/SetCorrectResponseProcessor.php#L55-L85 |
oat-sa/qti-sdk | src/qtism/runtime/processing/ResponseProcessingEngine.php | ResponseProcessingEngine.setComponent | public function setComponent(QtiComponent $responseProcessing)
{
if ($responseProcessing instanceof ResponseProcessing) {
parent::setComponent($responseProcessing);
} else {
$msg = "The ResponseProcessingEngine class only accepts ResponseProcessing objects to be executed.";
throw new InvalidArgumentException($msg);
}
} | php | public function setComponent(QtiComponent $responseProcessing)
{
if ($responseProcessing instanceof ResponseProcessing) {
parent::setComponent($responseProcessing);
} else {
$msg = "The ResponseProcessingEngine class only accepts ResponseProcessing objects to be executed.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setComponent",
"(",
"QtiComponent",
"$",
"responseProcessing",
")",
"{",
"if",
"(",
"$",
"responseProcessing",
"instanceof",
"ResponseProcessing",
")",
"{",
"parent",
"::",
"setComponent",
"(",
"$",
"responseProcessing",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The ResponseProcessingEngine class only accepts ResponseProcessing objects to be executed.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the ResponseProcessing object to be executed.
@param \qtism\data\QtiComponent $responseProcessing A ResponseProcessing object.
@throws \InvalidArgumentException If $responseProcessing is not a ResponseProcessing object. | [
"Set",
"the",
"ResponseProcessing",
"object",
"to",
"be",
"executed",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/processing/ResponseProcessingEngine.php#L81-L89 |
oat-sa/qti-sdk | src/qtism/runtime/processing/ResponseProcessingEngine.php | ResponseProcessingEngine.addTemplateMapping | public function addTemplateMapping($uri, $url)
{
if (gettype($uri) !== 'string') {
$msg = "The uri argument must be a string, '" . gettype($uri) . "' given.";
throw new InvalidArgumentException($msg);
}
if (gettype($url) !== 'string') {
$msg = "The url argument must be a string, '" . gettype($uri) . "' given.";
throw new InvalidArgumentException($msg);
}
$templateMapping = &$this->getTemplateMapping();
$templateMapping[$uri] = $url;
} | php | public function addTemplateMapping($uri, $url)
{
if (gettype($uri) !== 'string') {
$msg = "The uri argument must be a string, '" . gettype($uri) . "' given.";
throw new InvalidArgumentException($msg);
}
if (gettype($url) !== 'string') {
$msg = "The url argument must be a string, '" . gettype($uri) . "' given.";
throw new InvalidArgumentException($msg);
}
$templateMapping = &$this->getTemplateMapping();
$templateMapping[$uri] = $url;
} | [
"public",
"function",
"addTemplateMapping",
"(",
"$",
"uri",
",",
"$",
"url",
")",
"{",
"if",
"(",
"gettype",
"(",
"$",
"uri",
")",
"!==",
"'string'",
")",
"{",
"$",
"msg",
"=",
"\"The uri argument must be a string, '\"",
".",
"gettype",
"(",
"$",
"uri",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"if",
"(",
"gettype",
"(",
"$",
"url",
")",
"!==",
"'string'",
")",
"{",
"$",
"msg",
"=",
"\"The url argument must be a string, '\"",
".",
"gettype",
"(",
"$",
"uri",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"$",
"templateMapping",
"=",
"&",
"$",
"this",
"->",
"getTemplateMapping",
"(",
")",
";",
"$",
"templateMapping",
"[",
"$",
"uri",
"]",
"=",
"$",
"url",
";",
"}"
] | Add a template mapping.
@param string $uri The template URI (Uniform Resource Identifier).
@param string $url The actual template URL, i.e. where to find the file containing the template markup.
@throws \InvalidArgumentException If $uri or $url are not strings. | [
"Add",
"a",
"template",
"mapping",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/processing/ResponseProcessingEngine.php#L98-L112 |
oat-sa/qti-sdk | src/qtism/runtime/processing/ResponseProcessingEngine.php | ResponseProcessingEngine.removeTemplateMapping | public function removeTemplateMapping($uri)
{
if (gettype($uri) !== 'string') {
$msg = "The uri argument must be a string, '" . gettype($uri) . "' given.";
throw new InvalidArgumentException($msg);
}
$templateMapping = &$this->getTemplateMapping();
if (isset($templateMapping[$uri]) === true) {
unset($templateMapping[$uri]);
}
} | php | public function removeTemplateMapping($uri)
{
if (gettype($uri) !== 'string') {
$msg = "The uri argument must be a string, '" . gettype($uri) . "' given.";
throw new InvalidArgumentException($msg);
}
$templateMapping = &$this->getTemplateMapping();
if (isset($templateMapping[$uri]) === true) {
unset($templateMapping[$uri]);
}
} | [
"public",
"function",
"removeTemplateMapping",
"(",
"$",
"uri",
")",
"{",
"if",
"(",
"gettype",
"(",
"$",
"uri",
")",
"!==",
"'string'",
")",
"{",
"$",
"msg",
"=",
"\"The uri argument must be a string, '\"",
".",
"gettype",
"(",
"$",
"uri",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"$",
"templateMapping",
"=",
"&",
"$",
"this",
"->",
"getTemplateMapping",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"templateMapping",
"[",
"$",
"uri",
"]",
")",
"===",
"true",
")",
"{",
"unset",
"(",
"$",
"templateMapping",
"[",
"$",
"uri",
"]",
")",
";",
"}",
"}"
] | Remove a template mapping for a given $uri. If no template mapping
is found for $uri, nothing happens.
@param string $uri The $uri you want to remove the mapping.
@throws \InvalidArgumentException If $uri is not a string. | [
"Remove",
"a",
"template",
"mapping",
"for",
"a",
"given",
"$uri",
".",
"If",
"no",
"template",
"mapping",
"is",
"found",
"for",
"$uri",
"nothing",
"happens",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/processing/ResponseProcessingEngine.php#L121-L133 |
oat-sa/qti-sdk | src/qtism/runtime/processing/ResponseProcessingEngine.php | ResponseProcessingEngine.process | public function process()
{
// @todo Figure out how to provide a way to the ResponseProcessingEngine to know the folder where to seek for templateLocation, which is a relative URI.
$responseProcessing = $this->getComponent();
$template = $responseProcessing->getTemplate();
$templateLocation = $responseProcessing->getTemplateLocation();
if (count($responseProcessing->getResponseRules()) > 0) {
// Always prefer the embedded rules.
$rules = $responseProcessing->getResponseRules();
} else {
$finalTemplateFile = '';
if (empty($template) === false) {
// try to locate the template file thanks to the given mapping.
$mapping = $this->getTemplateMapping();
if (isset($mapping[$template])) {
$finalTemplateFile = $mapping[$template];
}
}
if (empty($finalTemplateFile) === true && empty($templateLocation) === false) {
// The template could not be resolved using the mapping.
// Try to use template location.
if (@is_readable($templateLocation) === true) {
$finalTemplateFile = $templateLocation;
}
}
if (empty($finalTemplateFile) === true) {
$msg = "The template file could not be found: template='${template}', templateLocation='${templateLocation}'.";
throw new ResponseProcessingException($msg, $this, ResponseProcessingException::TEMPLATE_NOT_FOUND);
}
// Open the file and retrieve the rules.
$this->trace("loading response processing template '${finalTemplateFile}'");
$php = new PhpDocument();
$php->load($finalTemplateFile);
$rules = $php->getDocumentComponent()->getResponseRules();
$this->trace(count($rules) . " responseRule(s) extracted from the response processing template");
}
try {
foreach ($rules as $rule) {
$engine = new RuleEngine($rule, $this->getContext());
$engine->process();
$this->trace($rule->getQtiClassName() . ' executed');
}
} catch (RuleProcessingException $e) {
if ($e->getCode() !== RuleProcessingException::EXIT_RESPONSE) {
throw $e;
} else {
$this->trace('Termination of response processing.');
}
}
} | php | public function process()
{
// @todo Figure out how to provide a way to the ResponseProcessingEngine to know the folder where to seek for templateLocation, which is a relative URI.
$responseProcessing = $this->getComponent();
$template = $responseProcessing->getTemplate();
$templateLocation = $responseProcessing->getTemplateLocation();
if (count($responseProcessing->getResponseRules()) > 0) {
// Always prefer the embedded rules.
$rules = $responseProcessing->getResponseRules();
} else {
$finalTemplateFile = '';
if (empty($template) === false) {
// try to locate the template file thanks to the given mapping.
$mapping = $this->getTemplateMapping();
if (isset($mapping[$template])) {
$finalTemplateFile = $mapping[$template];
}
}
if (empty($finalTemplateFile) === true && empty($templateLocation) === false) {
// The template could not be resolved using the mapping.
// Try to use template location.
if (@is_readable($templateLocation) === true) {
$finalTemplateFile = $templateLocation;
}
}
if (empty($finalTemplateFile) === true) {
$msg = "The template file could not be found: template='${template}', templateLocation='${templateLocation}'.";
throw new ResponseProcessingException($msg, $this, ResponseProcessingException::TEMPLATE_NOT_FOUND);
}
// Open the file and retrieve the rules.
$this->trace("loading response processing template '${finalTemplateFile}'");
$php = new PhpDocument();
$php->load($finalTemplateFile);
$rules = $php->getDocumentComponent()->getResponseRules();
$this->trace(count($rules) . " responseRule(s) extracted from the response processing template");
}
try {
foreach ($rules as $rule) {
$engine = new RuleEngine($rule, $this->getContext());
$engine->process();
$this->trace($rule->getQtiClassName() . ' executed');
}
} catch (RuleProcessingException $e) {
if ($e->getCode() !== RuleProcessingException::EXIT_RESPONSE) {
throw $e;
} else {
$this->trace('Termination of response processing.');
}
}
} | [
"public",
"function",
"process",
"(",
")",
"{",
"// @todo Figure out how to provide a way to the ResponseProcessingEngine to know the folder where to seek for templateLocation, which is a relative URI.",
"$",
"responseProcessing",
"=",
"$",
"this",
"->",
"getComponent",
"(",
")",
";",
"$",
"template",
"=",
"$",
"responseProcessing",
"->",
"getTemplate",
"(",
")",
";",
"$",
"templateLocation",
"=",
"$",
"responseProcessing",
"->",
"getTemplateLocation",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"responseProcessing",
"->",
"getResponseRules",
"(",
")",
")",
">",
"0",
")",
"{",
"// Always prefer the embedded rules.",
"$",
"rules",
"=",
"$",
"responseProcessing",
"->",
"getResponseRules",
"(",
")",
";",
"}",
"else",
"{",
"$",
"finalTemplateFile",
"=",
"''",
";",
"if",
"(",
"empty",
"(",
"$",
"template",
")",
"===",
"false",
")",
"{",
"// try to locate the template file thanks to the given mapping.",
"$",
"mapping",
"=",
"$",
"this",
"->",
"getTemplateMapping",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"mapping",
"[",
"$",
"template",
"]",
")",
")",
"{",
"$",
"finalTemplateFile",
"=",
"$",
"mapping",
"[",
"$",
"template",
"]",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"finalTemplateFile",
")",
"===",
"true",
"&&",
"empty",
"(",
"$",
"templateLocation",
")",
"===",
"false",
")",
"{",
"// The template could not be resolved using the mapping.",
"// Try to use template location.",
"if",
"(",
"@",
"is_readable",
"(",
"$",
"templateLocation",
")",
"===",
"true",
")",
"{",
"$",
"finalTemplateFile",
"=",
"$",
"templateLocation",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"finalTemplateFile",
")",
"===",
"true",
")",
"{",
"$",
"msg",
"=",
"\"The template file could not be found: template='${template}', templateLocation='${templateLocation}'.\"",
";",
"throw",
"new",
"ResponseProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"ResponseProcessingException",
"::",
"TEMPLATE_NOT_FOUND",
")",
";",
"}",
"// Open the file and retrieve the rules.",
"$",
"this",
"->",
"trace",
"(",
"\"loading response processing template '${finalTemplateFile}'\"",
")",
";",
"$",
"php",
"=",
"new",
"PhpDocument",
"(",
")",
";",
"$",
"php",
"->",
"load",
"(",
"$",
"finalTemplateFile",
")",
";",
"$",
"rules",
"=",
"$",
"php",
"->",
"getDocumentComponent",
"(",
")",
"->",
"getResponseRules",
"(",
")",
";",
"$",
"this",
"->",
"trace",
"(",
"count",
"(",
"$",
"rules",
")",
".",
"\" responseRule(s) extracted from the response processing template\"",
")",
";",
"}",
"try",
"{",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"rule",
")",
"{",
"$",
"engine",
"=",
"new",
"RuleEngine",
"(",
"$",
"rule",
",",
"$",
"this",
"->",
"getContext",
"(",
")",
")",
";",
"$",
"engine",
"->",
"process",
"(",
")",
";",
"$",
"this",
"->",
"trace",
"(",
"$",
"rule",
"->",
"getQtiClassName",
"(",
")",
".",
"' executed'",
")",
";",
"}",
"}",
"catch",
"(",
"RuleProcessingException",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"e",
"->",
"getCode",
"(",
")",
"!==",
"RuleProcessingException",
"::",
"EXIT_RESPONSE",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"trace",
"(",
"'Termination of response processing.'",
")",
";",
"}",
"}",
"}"
] | Execute the ResponseProcessing according to the current context.
The following sub-types of ProcessingException may be thrown:
* RuleProcessingException: If a ResponseRule in the ResponseProcessing produces an error OR if the ExitResponse rule is invoked. In this last case, a specific exception code will be produced to deal with the situation accordingly.
* ExpressionProcessingException: If an Expression within a ResponseRule produces an error.
* ResponseProcessingException: If there is a problem with the response processing template processing bound to the ResponseProcessing.
@throws \qtism\runtime\common\ProcessingException | [
"Execute",
"the",
"ResponseProcessing",
"according",
"to",
"the",
"current",
"context",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/processing/ResponseProcessingEngine.php#L155-L210 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/MediaInteractionMarshaller.php | MediaInteractionMarshaller.marshall | protected function marshall(QtiComponent $component)
{
$element = $this->createElement($component);
$this->fillElement($element, $component);
$this->setDOMElementAttribute($element, 'responseIdentifier', $component->getResponseIdentifier());
$this->setDOMElementAttribute($element, 'autostart', $component->mustAutostart());
if ($component->hasPrompt() === true) {
$element->appendChild($this->getMarshallerFactory()->createMarshaller($component->getPrompt())->marshall($component->getPrompt()));
}
$element->appendChild($this->getMarshallerFactory()->createMarshaller($component->getObject())->marshall($component->getObject()));
if ($component->getMinPlays() !== 0) {
$this->setDOMElementAttribute($element, 'minPlays', $component->getMinPlays());
}
if ($component->getMaxPlays() !== 0) {
$this->setDOMElementAttribute($element, 'maxPlays', $component->getMaxPlays());
}
if ($component->mustLoop() === true) {
$this->setDOMElementAttribute($element, 'loop', true);
}
if ($component->hasXmlBase() === true) {
self::setXmlBase($element, $component->getXmlBase());
}
return $element;
} | php | protected function marshall(QtiComponent $component)
{
$element = $this->createElement($component);
$this->fillElement($element, $component);
$this->setDOMElementAttribute($element, 'responseIdentifier', $component->getResponseIdentifier());
$this->setDOMElementAttribute($element, 'autostart', $component->mustAutostart());
if ($component->hasPrompt() === true) {
$element->appendChild($this->getMarshallerFactory()->createMarshaller($component->getPrompt())->marshall($component->getPrompt()));
}
$element->appendChild($this->getMarshallerFactory()->createMarshaller($component->getObject())->marshall($component->getObject()));
if ($component->getMinPlays() !== 0) {
$this->setDOMElementAttribute($element, 'minPlays', $component->getMinPlays());
}
if ($component->getMaxPlays() !== 0) {
$this->setDOMElementAttribute($element, 'maxPlays', $component->getMaxPlays());
}
if ($component->mustLoop() === true) {
$this->setDOMElementAttribute($element, 'loop', true);
}
if ($component->hasXmlBase() === true) {
self::setXmlBase($element, $component->getXmlBase());
}
return $element;
} | [
"protected",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"$",
"element",
"=",
"$",
"this",
"->",
"createElement",
"(",
"$",
"component",
")",
";",
"$",
"this",
"->",
"fillElement",
"(",
"$",
"element",
",",
"$",
"component",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'responseIdentifier'",
",",
"$",
"component",
"->",
"getResponseIdentifier",
"(",
")",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'autostart'",
",",
"$",
"component",
"->",
"mustAutostart",
"(",
")",
")",
";",
"if",
"(",
"$",
"component",
"->",
"hasPrompt",
"(",
")",
"===",
"true",
")",
"{",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"component",
"->",
"getPrompt",
"(",
")",
")",
"->",
"marshall",
"(",
"$",
"component",
"->",
"getPrompt",
"(",
")",
")",
")",
";",
"}",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"component",
"->",
"getObject",
"(",
")",
")",
"->",
"marshall",
"(",
"$",
"component",
"->",
"getObject",
"(",
")",
")",
")",
";",
"if",
"(",
"$",
"component",
"->",
"getMinPlays",
"(",
")",
"!==",
"0",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'minPlays'",
",",
"$",
"component",
"->",
"getMinPlays",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"component",
"->",
"getMaxPlays",
"(",
")",
"!==",
"0",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'maxPlays'",
",",
"$",
"component",
"->",
"getMaxPlays",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"component",
"->",
"mustLoop",
"(",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'loop'",
",",
"true",
")",
";",
"}",
"if",
"(",
"$",
"component",
"->",
"hasXmlBase",
"(",
")",
"===",
"true",
")",
"{",
"self",
"::",
"setXmlBase",
"(",
"$",
"element",
",",
"$",
"component",
"->",
"getXmlBase",
"(",
")",
")",
";",
"}",
"return",
"$",
"element",
";",
"}"
] | Marshall a MediaInteraction object into a DOMElement object.
@param \qtism\data\QtiComponent $component A MediaInteraction object.
@return \DOMElement The according DOMElement object.
@throws \qtism\data\storage\xml\marshalling\MarshallingException | [
"Marshall",
"a",
"MediaInteraction",
"object",
"into",
"a",
"DOMElement",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/MediaInteractionMarshaller.php#L44-L74 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/MediaInteractionMarshaller.php | MediaInteractionMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
if (($responseIdentifier = $this->getDOMElementAttributeAs($element, 'responseIdentifier')) !== null) {
if (($autostart = $this->getDOMElementAttributeAs($element, 'autostart', 'boolean')) !== null) {
$objectElts = $this->getChildElementsByTagName($element, 'object');
if (count($objectElts) > 0) {
$objectElt = $objectElts[0];
$object = $this->getMarshallerFactory()->createMarshaller($objectElt)->unmarshall($objectElt);
$component = new MediaInteraction($responseIdentifier, $autostart, $object);
$promptElts = $this->getChildElementsByTagName($element, 'prompt');
if (count($promptElts) > 0) {
$promptElt = $promptElts[0];
$prompt = $this->getMarshallerFactory()->createMarshaller($promptElt)->unmarshall($promptElt);
$component->setPrompt($prompt);
}
if (($minPlays = $this->getDOMElementAttributeAs($element, 'minPlays', 'integer')) !== null) {
$component->setMinPlays($minPlays);
}
if (($maxPlays = $this->getDOMElementAttributeAs($element, 'maxPlays', 'integer')) !== null) {
$component->setMaxPlays($maxPlays);
}
if (($loop = $this->getDOMElementAttributeAs($element, 'loop', 'boolean')) !== null) {
$component->setLoop($loop);
}
if (($xmlBase = self::getXmlBase($element)) !== false) {
$component->setXmlBase($xmlBase);
}
$this->fillBodyElement($component, $element);
return $component;
} else {
$msg = "A 'mediaInteraction' element must contain exactly one 'object' element, none given.";
throw new UnmarshallingException($msg, $element);
}
} else {
$msg = "The mandatory 'autostart' attribute is missing from the 'mediaInteraction' element.";
throw new UnmarshallingException($msg, $element);
}
} else {
$msg = "The mandatory 'responseIdentifier' attribute is missing from the 'mediaInteraction' element.";
throw new UnmarshallingException($msg, $element);
}
} | php | protected function unmarshall(DOMElement $element)
{
if (($responseIdentifier = $this->getDOMElementAttributeAs($element, 'responseIdentifier')) !== null) {
if (($autostart = $this->getDOMElementAttributeAs($element, 'autostart', 'boolean')) !== null) {
$objectElts = $this->getChildElementsByTagName($element, 'object');
if (count($objectElts) > 0) {
$objectElt = $objectElts[0];
$object = $this->getMarshallerFactory()->createMarshaller($objectElt)->unmarshall($objectElt);
$component = new MediaInteraction($responseIdentifier, $autostart, $object);
$promptElts = $this->getChildElementsByTagName($element, 'prompt');
if (count($promptElts) > 0) {
$promptElt = $promptElts[0];
$prompt = $this->getMarshallerFactory()->createMarshaller($promptElt)->unmarshall($promptElt);
$component->setPrompt($prompt);
}
if (($minPlays = $this->getDOMElementAttributeAs($element, 'minPlays', 'integer')) !== null) {
$component->setMinPlays($minPlays);
}
if (($maxPlays = $this->getDOMElementAttributeAs($element, 'maxPlays', 'integer')) !== null) {
$component->setMaxPlays($maxPlays);
}
if (($loop = $this->getDOMElementAttributeAs($element, 'loop', 'boolean')) !== null) {
$component->setLoop($loop);
}
if (($xmlBase = self::getXmlBase($element)) !== false) {
$component->setXmlBase($xmlBase);
}
$this->fillBodyElement($component, $element);
return $component;
} else {
$msg = "A 'mediaInteraction' element must contain exactly one 'object' element, none given.";
throw new UnmarshallingException($msg, $element);
}
} else {
$msg = "The mandatory 'autostart' attribute is missing from the 'mediaInteraction' element.";
throw new UnmarshallingException($msg, $element);
}
} else {
$msg = "The mandatory 'responseIdentifier' attribute is missing from the 'mediaInteraction' element.";
throw new UnmarshallingException($msg, $element);
}
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"if",
"(",
"(",
"$",
"responseIdentifier",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'responseIdentifier'",
")",
")",
"!==",
"null",
")",
"{",
"if",
"(",
"(",
"$",
"autostart",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'autostart'",
",",
"'boolean'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"objectElts",
"=",
"$",
"this",
"->",
"getChildElementsByTagName",
"(",
"$",
"element",
",",
"'object'",
")",
";",
"if",
"(",
"count",
"(",
"$",
"objectElts",
")",
">",
"0",
")",
"{",
"$",
"objectElt",
"=",
"$",
"objectElts",
"[",
"0",
"]",
";",
"$",
"object",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"objectElt",
")",
"->",
"unmarshall",
"(",
"$",
"objectElt",
")",
";",
"$",
"component",
"=",
"new",
"MediaInteraction",
"(",
"$",
"responseIdentifier",
",",
"$",
"autostart",
",",
"$",
"object",
")",
";",
"$",
"promptElts",
"=",
"$",
"this",
"->",
"getChildElementsByTagName",
"(",
"$",
"element",
",",
"'prompt'",
")",
";",
"if",
"(",
"count",
"(",
"$",
"promptElts",
")",
">",
"0",
")",
"{",
"$",
"promptElt",
"=",
"$",
"promptElts",
"[",
"0",
"]",
";",
"$",
"prompt",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"promptElt",
")",
"->",
"unmarshall",
"(",
"$",
"promptElt",
")",
";",
"$",
"component",
"->",
"setPrompt",
"(",
"$",
"prompt",
")",
";",
"}",
"if",
"(",
"(",
"$",
"minPlays",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'minPlays'",
",",
"'integer'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"component",
"->",
"setMinPlays",
"(",
"$",
"minPlays",
")",
";",
"}",
"if",
"(",
"(",
"$",
"maxPlays",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'maxPlays'",
",",
"'integer'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"component",
"->",
"setMaxPlays",
"(",
"$",
"maxPlays",
")",
";",
"}",
"if",
"(",
"(",
"$",
"loop",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'loop'",
",",
"'boolean'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"component",
"->",
"setLoop",
"(",
"$",
"loop",
")",
";",
"}",
"if",
"(",
"(",
"$",
"xmlBase",
"=",
"self",
"::",
"getXmlBase",
"(",
"$",
"element",
")",
")",
"!==",
"false",
")",
"{",
"$",
"component",
"->",
"setXmlBase",
"(",
"$",
"xmlBase",
")",
";",
"}",
"$",
"this",
"->",
"fillBodyElement",
"(",
"$",
"component",
",",
"$",
"element",
")",
";",
"return",
"$",
"component",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"A 'mediaInteraction' element must contain exactly one 'object' element, none given.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory 'autostart' attribute is missing from the 'mediaInteraction' element.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory 'responseIdentifier' attribute is missing from the 'mediaInteraction' element.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}"
] | Unmarshall a DOMElement object corresponding to a MediaInteraction element.
@param \DOMElement $element A DOMElement object.
@return \qtism\data\QtiComponent A MediaInteraction object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException | [
"Unmarshall",
"a",
"DOMElement",
"object",
"corresponding",
"to",
"a",
"MediaInteraction",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/MediaInteractionMarshaller.php#L83-L134 |
oat-sa/qti-sdk | src/qtism/data/content/interactions/HotspotInteraction.php | HotspotInteraction.setMinChoices | public function setMinChoices($minChoices)
{
if (is_int($minChoices) === true && $minChoices >= 0) {
$this->minChoices = $minChoices;
} else {
$msg = "The 'minChoices' argument must be a positive integer, '" . gettype($minChoices) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setMinChoices($minChoices)
{
if (is_int($minChoices) === true && $minChoices >= 0) {
$this->minChoices = $minChoices;
} else {
$msg = "The 'minChoices' argument must be a positive integer, '" . gettype($minChoices) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setMinChoices",
"(",
"$",
"minChoices",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"minChoices",
")",
"===",
"true",
"&&",
"$",
"minChoices",
">=",
"0",
")",
"{",
"$",
"this",
"->",
"minChoices",
"=",
"$",
"minChoices",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'minChoices' argument must be a positive integer, '\"",
".",
"gettype",
"(",
"$",
"minChoices",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the minimum number of choices that the candidate is allowed to
select.
@param integer $minChoices A positive (>= 0) integer.
@throws \InvalidArgumentException If $minChoices is not a positive integer. | [
"Set",
"the",
"minimum",
"number",
"of",
"choices",
"that",
"the",
"candidate",
"is",
"allowed",
"to",
"select",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/interactions/HotspotInteraction.php#L140-L148 |
oat-sa/qti-sdk | src/qtism/common/datatypes/QtiPoint.php | QtiPoint.setX | public function setX($x)
{
if (is_int($x)) {
$this->x = $x;
} else {
$msg = "The X argument must be an integer value, '" . gettype($x) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setX($x)
{
if (is_int($x)) {
$this->x = $x;
} else {
$msg = "The X argument must be an integer value, '" . gettype($x) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setX",
"(",
"$",
"x",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"x",
")",
")",
"{",
"$",
"this",
"->",
"x",
"=",
"$",
"x",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The X argument must be an integer value, '\"",
".",
"gettype",
"(",
"$",
"x",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the position on the x-axis.
@param int $x A position on the x-axis.
@throws \InvalidArgumentException If $x is nto an integer value. | [
"Set",
"the",
"position",
"on",
"the",
"x",
"-",
"axis",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/datatypes/QtiPoint.php#L76-L84 |
oat-sa/qti-sdk | src/qtism/common/datatypes/QtiPoint.php | QtiPoint.setY | public function setY($y)
{
if (is_int($y)) {
$this->y = $y;
} else {
$msg = "The Y argument must be an integer value, '" . gettype($x) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setY($y)
{
if (is_int($y)) {
$this->y = $y;
} else {
$msg = "The Y argument must be an integer value, '" . gettype($x) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setY",
"(",
"$",
"y",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"y",
")",
")",
"{",
"$",
"this",
"->",
"y",
"=",
"$",
"y",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The Y argument must be an integer value, '\"",
".",
"gettype",
"(",
"$",
"x",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the position on y-axis.
@param int $y A position on the y-axis.
@throws \InvalidArgumentException If $y is not an integer value. | [
"Set",
"the",
"position",
"on",
"y",
"-",
"axis",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/datatypes/QtiPoint.php#L102-L110 |
oat-sa/qti-sdk | src/qtism/common/datatypes/QtiPoint.php | QtiPoint.equals | public function equals($obj)
{
return (gettype($obj) === 'object' &&
$obj instanceof self &&
$obj->getX() === $this->getX() &&
$obj->getY() === $this->getY());
} | php | public function equals($obj)
{
return (gettype($obj) === 'object' &&
$obj instanceof self &&
$obj->getX() === $this->getX() &&
$obj->getY() === $this->getY());
} | [
"public",
"function",
"equals",
"(",
"$",
"obj",
")",
"{",
"return",
"(",
"gettype",
"(",
"$",
"obj",
")",
"===",
"'object'",
"&&",
"$",
"obj",
"instanceof",
"self",
"&&",
"$",
"obj",
"->",
"getX",
"(",
")",
"===",
"$",
"this",
"->",
"getX",
"(",
")",
"&&",
"$",
"obj",
"->",
"getY",
"(",
")",
"===",
"$",
"this",
"->",
"getY",
"(",
")",
")",
";",
"}"
] | Wheter a given $obj is equal to $this Point object. Two Point objects
are considered to be the same if they have the same coordinates.
@param mixed $obj An object.
@return boolean Whether or not the equality is established. | [
"Wheter",
"a",
"given",
"$obj",
"is",
"equal",
"to",
"$this",
"Point",
"object",
".",
"Two",
"Point",
"objects",
"are",
"considered",
"to",
"be",
"the",
"same",
"if",
"they",
"have",
"the",
"same",
"coordinates",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/datatypes/QtiPoint.php#L129-L135 |
oat-sa/qti-sdk | src/qtism/runtime/rendering/qtipl/expressions/operators/InsideQtiPLRenderer.php | InsideQtiPLRenderer.render | public function render($something)
{
$renderer = new QtiPLRenderer($this->getCRO());
$attributes = [];
$attributes['shape'] = "\"" . QtiShape::getNameByConstant($something->getShape()) . "\"";
$attributes['coords'] = $something->getCoords();
return $something->getQtiClassName() . $renderer->writeAttributes($attributes)
. $renderer->writeChildElements($something->getExpressions());
} | php | public function render($something)
{
$renderer = new QtiPLRenderer($this->getCRO());
$attributes = [];
$attributes['shape'] = "\"" . QtiShape::getNameByConstant($something->getShape()) . "\"";
$attributes['coords'] = $something->getCoords();
return $something->getQtiClassName() . $renderer->writeAttributes($attributes)
. $renderer->writeChildElements($something->getExpressions());
} | [
"public",
"function",
"render",
"(",
"$",
"something",
")",
"{",
"$",
"renderer",
"=",
"new",
"QtiPLRenderer",
"(",
"$",
"this",
"->",
"getCRO",
"(",
")",
")",
";",
"$",
"attributes",
"=",
"[",
"]",
";",
"$",
"attributes",
"[",
"'shape'",
"]",
"=",
"\"\\\"\"",
".",
"QtiShape",
"::",
"getNameByConstant",
"(",
"$",
"something",
"->",
"getShape",
"(",
")",
")",
".",
"\"\\\"\"",
";",
"$",
"attributes",
"[",
"'coords'",
"]",
"=",
"$",
"something",
"->",
"getCoords",
"(",
")",
";",
"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/InsideQtiPLRenderer.php#L47-L56 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/MapEntryMarshaller.php | MapEntryMarshaller.setBaseType | protected function setBaseType($baseType)
{
if (in_array($baseType, BaseType::asArray())) {
$this->baseType = $baseType;
} else {
$msg = 'The baseType argument must be a valid QTI baseType value from the BaseType enumeration.';
throw new InvalidArgumentException($msg);
}
} | php | protected function setBaseType($baseType)
{
if (in_array($baseType, BaseType::asArray())) {
$this->baseType = $baseType;
} else {
$msg = 'The baseType argument must be a valid QTI baseType value from the BaseType enumeration.';
throw new InvalidArgumentException($msg);
}
} | [
"protected",
"function",
"setBaseType",
"(",
"$",
"baseType",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"baseType",
",",
"BaseType",
"::",
"asArray",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"baseType",
"=",
"$",
"baseType",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"'The baseType argument must be a valid QTI baseType value from the BaseType enumeration.'",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set a baseType to this marshaller implementation in order
to force the datatype used for the unserialization of the
'mapKey' attribute.
@param int $baseType A baseType from the BaseType enumeration.
@throws \InvalidArgumentException If $baseType is not a value from the BaseType enumeration. | [
"Set",
"a",
"baseType",
"to",
"this",
"marshaller",
"implementation",
"in",
"order",
"to",
"force",
"the",
"datatype",
"used",
"for",
"the",
"unserialization",
"of",
"the",
"mapKey",
"attribute",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/MapEntryMarshaller.php#L57-L65 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/MapEntryMarshaller.php | MapEntryMarshaller.marshall | protected function marshall(QtiComponent $component)
{
$element = static::getDOMCradle()->createElement($component->getQtiClassName());
$this->setDOMElementAttribute($element, 'mapKey', $component->getMapKey());
$this->setDOMElementAttribute($element, 'mappedValue', $component->getMappedValue());
if (Version::compare($this->getVersion(), '2.0.0', '>') === true) {
$this->setDOMElementAttribute($element, 'caseSensitive', $component->isCaseSensitive());
}
return $element;
} | php | protected function marshall(QtiComponent $component)
{
$element = static::getDOMCradle()->createElement($component->getQtiClassName());
$this->setDOMElementAttribute($element, 'mapKey', $component->getMapKey());
$this->setDOMElementAttribute($element, 'mappedValue', $component->getMappedValue());
if (Version::compare($this->getVersion(), '2.0.0', '>') === true) {
$this->setDOMElementAttribute($element, 'caseSensitive', $component->isCaseSensitive());
}
return $element;
} | [
"protected",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"$",
"element",
"=",
"static",
"::",
"getDOMCradle",
"(",
")",
"->",
"createElement",
"(",
"$",
"component",
"->",
"getQtiClassName",
"(",
")",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'mapKey'",
",",
"$",
"component",
"->",
"getMapKey",
"(",
")",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'mappedValue'",
",",
"$",
"component",
"->",
"getMappedValue",
"(",
")",
")",
";",
"if",
"(",
"Version",
"::",
"compare",
"(",
"$",
"this",
"->",
"getVersion",
"(",
")",
",",
"'2.0.0'",
",",
"'>'",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'caseSensitive'",
",",
"$",
"component",
"->",
"isCaseSensitive",
"(",
")",
")",
";",
"}",
"return",
"$",
"element",
";",
"}"
] | Marshall a MapEntry object into a DOMElement object.
@param \qtism\data\QtiComponent $component A MapEntry object.
@return \DOMElement The according DOMElement object. | [
"Marshall",
"a",
"MapEntry",
"object",
"into",
"a",
"DOMElement",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/MapEntryMarshaller.php#L97-L109 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/MapEntryMarshaller.php | MapEntryMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
try {
$mapKey = $this->getDOMElementAttributeAs($element, 'mapKey');
$mapKey = Utils::stringToDatatype($mapKey, $this->getBaseType());
if (($mappedValue = $this->getDOMElementAttributeAs($element, 'mappedValue', 'float')) !== null) {
$object = new MapEntry($mapKey, $mappedValue);
if (Version::compare($this->getVersion(), '2.0.0', '>') && ($caseSensitive = $this->getDOMElementAttributeAs($element, 'caseSensitive', 'boolean')) !== null) {
$object->setCaseSensitive($caseSensitive);
}
return $object;
} else {
$msg = "The mandatory 'mappedValue' attribute is missing from element '" . $element->nodeName . "'.";
throw new UnmarshallingException($msg, $element);
}
} catch (UnexpectedValueException $e) {
$msg = "The value '${mapKey}' of the 'mapKey' attribute could not be converted to a '" . BaseType::getNameByConstant($this->getBaseType()) . "' value.";
throw new UnmarshallingException($msg, $element, $e);
}
} | php | protected function unmarshall(DOMElement $element)
{
try {
$mapKey = $this->getDOMElementAttributeAs($element, 'mapKey');
$mapKey = Utils::stringToDatatype($mapKey, $this->getBaseType());
if (($mappedValue = $this->getDOMElementAttributeAs($element, 'mappedValue', 'float')) !== null) {
$object = new MapEntry($mapKey, $mappedValue);
if (Version::compare($this->getVersion(), '2.0.0', '>') && ($caseSensitive = $this->getDOMElementAttributeAs($element, 'caseSensitive', 'boolean')) !== null) {
$object->setCaseSensitive($caseSensitive);
}
return $object;
} else {
$msg = "The mandatory 'mappedValue' attribute is missing from element '" . $element->nodeName . "'.";
throw new UnmarshallingException($msg, $element);
}
} catch (UnexpectedValueException $e) {
$msg = "The value '${mapKey}' of the 'mapKey' attribute could not be converted to a '" . BaseType::getNameByConstant($this->getBaseType()) . "' value.";
throw new UnmarshallingException($msg, $element, $e);
}
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"try",
"{",
"$",
"mapKey",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'mapKey'",
")",
";",
"$",
"mapKey",
"=",
"Utils",
"::",
"stringToDatatype",
"(",
"$",
"mapKey",
",",
"$",
"this",
"->",
"getBaseType",
"(",
")",
")",
";",
"if",
"(",
"(",
"$",
"mappedValue",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'mappedValue'",
",",
"'float'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"object",
"=",
"new",
"MapEntry",
"(",
"$",
"mapKey",
",",
"$",
"mappedValue",
")",
";",
"if",
"(",
"Version",
"::",
"compare",
"(",
"$",
"this",
"->",
"getVersion",
"(",
")",
",",
"'2.0.0'",
",",
"'>'",
")",
"&&",
"(",
"$",
"caseSensitive",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'caseSensitive'",
",",
"'boolean'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"object",
"->",
"setCaseSensitive",
"(",
"$",
"caseSensitive",
")",
";",
"}",
"return",
"$",
"object",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory 'mappedValue' attribute is missing from element '\"",
".",
"$",
"element",
"->",
"nodeName",
".",
"\"'.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}",
"catch",
"(",
"UnexpectedValueException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"The value '${mapKey}' of the 'mapKey' attribute could not be converted to a '\"",
".",
"BaseType",
"::",
"getNameByConstant",
"(",
"$",
"this",
"->",
"getBaseType",
"(",
")",
")",
".",
"\"' value.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Unmarshall a DOMElement object corresponding to a QTI mapEntry element.
@param \DOMElement $element A DOMElement object.
@return \qtism\data\QtiComponent A MapEntry object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException | [
"Unmarshall",
"a",
"DOMElement",
"object",
"corresponding",
"to",
"a",
"QTI",
"mapEntry",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/MapEntryMarshaller.php#L118-L141 |
oat-sa/qti-sdk | src/qtism/data/state/InterpolationTableEntry.php | InterpolationTableEntry.setSourceValue | public function setSourceValue($sourceValue)
{
if (is_float($sourceValue)) {
$this->sourceValue = $sourceValue;
} else {
$msg = "SourceValue must be a float value, '" . gettype($sourceValue) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setSourceValue($sourceValue)
{
if (is_float($sourceValue)) {
$this->sourceValue = $sourceValue;
} else {
$msg = "SourceValue must be a float value, '" . gettype($sourceValue) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setSourceValue",
"(",
"$",
"sourceValue",
")",
"{",
"if",
"(",
"is_float",
"(",
"$",
"sourceValue",
")",
")",
"{",
"$",
"this",
"->",
"sourceValue",
"=",
"$",
"sourceValue",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"SourceValue must be a float value, '\"",
".",
"gettype",
"(",
"$",
"sourceValue",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the lower bound for the source value to match this entry.
@param float $sourceValue A float value.
@throws \InvalidArgumentException If $sourceValue is not a float. | [
"Set",
"the",
"lower",
"bound",
"for",
"the",
"source",
"value",
"to",
"match",
"this",
"entry",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/state/InterpolationTableEntry.php#L100-L108 |
oat-sa/qti-sdk | src/qtism/data/state/InterpolationTableEntry.php | InterpolationTableEntry.setIncludeBoundary | public function setIncludeBoundary($includeBoundary)
{
if (is_bool($includeBoundary)) {
$this->includeBoundary = $includeBoundary;
} else {
$msg = "IncludeBoudary must be a boolean value, '" . gettype($includeBoundary) . "' given";
throw new InvalidArgumentException($msg);
}
} | php | public function setIncludeBoundary($includeBoundary)
{
if (is_bool($includeBoundary)) {
$this->includeBoundary = $includeBoundary;
} else {
$msg = "IncludeBoudary must be a boolean value, '" . gettype($includeBoundary) . "' given";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setIncludeBoundary",
"(",
"$",
"includeBoundary",
")",
"{",
"if",
"(",
"is_bool",
"(",
"$",
"includeBoundary",
")",
")",
"{",
"$",
"this",
"->",
"includeBoundary",
"=",
"$",
"includeBoundary",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"IncludeBoudary must be a boolean value, '\"",
".",
"gettype",
"(",
"$",
"includeBoundary",
")",
".",
"\"' given\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set if an exact match of the sourceValue attribute matches this entry.
@param boolean $includeBoundary A boolean value.
@throws \InvalidArgumentException If $includeBoundary is not a boolean. | [
"Set",
"if",
"an",
"exact",
"match",
"of",
"the",
"sourceValue",
"attribute",
"matches",
"this",
"entry",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/state/InterpolationTableEntry.php#L136-L144 |
oat-sa/qti-sdk | src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php | QtiBinaryStreamAccess.readVariableValue | public function readVariableValue(Variable $variable, $valueType = self::RW_VALUE)
{
switch ($valueType) {
case self::RW_DEFAULTVALUE:
$setterToCall = 'setDefaultValue';
break;
case self::RW_CORRECTRESPONSE:
$setterToCall = 'setCorrectResponse';
break;
default:
$setterToCall = 'setValue';
break;
}
try {
$isNull = $this->readBoolean();
if ($isNull === true) {
// Nothing more to be read.
call_user_func(array($variable, $setterToCall), null);
return;
}
$count = ($this->readBoolean() === true) ? 1 : $this->readShort();
$cardinality = $variable->getCardinality();
$baseType = $variable->getBaseType();
if ($cardinality === Cardinality::RECORD) {
// Deal with records.
$values = new RecordContainer();
for ($i = 0; $i < $count; $i++) {
$isNull = $this->readBoolean();
$val = $this->readRecordField($isNull);
$values[$val[0]] = $val[1];
}
call_user_func(array($variable, $setterToCall), $values);
} else {
$toCall = 'read' . ucfirst(BaseType::getNameByConstant($baseType));
if ($cardinality === Cardinality::SINGLE) {
// Deal with a single value.
$runtimeValue = Utils::valueToRuntime(call_user_func(array($this, $toCall)), $baseType);
call_user_func(array($variable, $setterToCall), $runtimeValue);
} else {
// Deal with multiple values.
$values = ($cardinality === Cardinality::MULTIPLE) ? new MultipleContainer($baseType) : new OrderedContainer($baseType);
for ($i = 0; $i < $count; $i++) {
$isNull = $this->readBoolean();
$values[] = ($isNull === true) ? null : Utils::valueToRuntime(call_user_func(array($this, $toCall)), $baseType);
}
call_user_func(array($variable, $setterToCall), $values);
}
}
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while reading a Variable value.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::VARIABLE, $e);
} catch (InvalidArgumentException $e) {
$msg = "Datatype mismatch for variable '" . $variable->getIdentifier() . "'.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::VARIABLE, $e);
}
} | php | public function readVariableValue(Variable $variable, $valueType = self::RW_VALUE)
{
switch ($valueType) {
case self::RW_DEFAULTVALUE:
$setterToCall = 'setDefaultValue';
break;
case self::RW_CORRECTRESPONSE:
$setterToCall = 'setCorrectResponse';
break;
default:
$setterToCall = 'setValue';
break;
}
try {
$isNull = $this->readBoolean();
if ($isNull === true) {
// Nothing more to be read.
call_user_func(array($variable, $setterToCall), null);
return;
}
$count = ($this->readBoolean() === true) ? 1 : $this->readShort();
$cardinality = $variable->getCardinality();
$baseType = $variable->getBaseType();
if ($cardinality === Cardinality::RECORD) {
// Deal with records.
$values = new RecordContainer();
for ($i = 0; $i < $count; $i++) {
$isNull = $this->readBoolean();
$val = $this->readRecordField($isNull);
$values[$val[0]] = $val[1];
}
call_user_func(array($variable, $setterToCall), $values);
} else {
$toCall = 'read' . ucfirst(BaseType::getNameByConstant($baseType));
if ($cardinality === Cardinality::SINGLE) {
// Deal with a single value.
$runtimeValue = Utils::valueToRuntime(call_user_func(array($this, $toCall)), $baseType);
call_user_func(array($variable, $setterToCall), $runtimeValue);
} else {
// Deal with multiple values.
$values = ($cardinality === Cardinality::MULTIPLE) ? new MultipleContainer($baseType) : new OrderedContainer($baseType);
for ($i = 0; $i < $count; $i++) {
$isNull = $this->readBoolean();
$values[] = ($isNull === true) ? null : Utils::valueToRuntime(call_user_func(array($this, $toCall)), $baseType);
}
call_user_func(array($variable, $setterToCall), $values);
}
}
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while reading a Variable value.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::VARIABLE, $e);
} catch (InvalidArgumentException $e) {
$msg = "Datatype mismatch for variable '" . $variable->getIdentifier() . "'.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::VARIABLE, $e);
}
} | [
"public",
"function",
"readVariableValue",
"(",
"Variable",
"$",
"variable",
",",
"$",
"valueType",
"=",
"self",
"::",
"RW_VALUE",
")",
"{",
"switch",
"(",
"$",
"valueType",
")",
"{",
"case",
"self",
"::",
"RW_DEFAULTVALUE",
":",
"$",
"setterToCall",
"=",
"'setDefaultValue'",
";",
"break",
";",
"case",
"self",
"::",
"RW_CORRECTRESPONSE",
":",
"$",
"setterToCall",
"=",
"'setCorrectResponse'",
";",
"break",
";",
"default",
":",
"$",
"setterToCall",
"=",
"'setValue'",
";",
"break",
";",
"}",
"try",
"{",
"$",
"isNull",
"=",
"$",
"this",
"->",
"readBoolean",
"(",
")",
";",
"if",
"(",
"$",
"isNull",
"===",
"true",
")",
"{",
"// Nothing more to be read.",
"call_user_func",
"(",
"array",
"(",
"$",
"variable",
",",
"$",
"setterToCall",
")",
",",
"null",
")",
";",
"return",
";",
"}",
"$",
"count",
"=",
"(",
"$",
"this",
"->",
"readBoolean",
"(",
")",
"===",
"true",
")",
"?",
"1",
":",
"$",
"this",
"->",
"readShort",
"(",
")",
";",
"$",
"cardinality",
"=",
"$",
"variable",
"->",
"getCardinality",
"(",
")",
";",
"$",
"baseType",
"=",
"$",
"variable",
"->",
"getBaseType",
"(",
")",
";",
"if",
"(",
"$",
"cardinality",
"===",
"Cardinality",
"::",
"RECORD",
")",
"{",
"// Deal with records.",
"$",
"values",
"=",
"new",
"RecordContainer",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"count",
";",
"$",
"i",
"++",
")",
"{",
"$",
"isNull",
"=",
"$",
"this",
"->",
"readBoolean",
"(",
")",
";",
"$",
"val",
"=",
"$",
"this",
"->",
"readRecordField",
"(",
"$",
"isNull",
")",
";",
"$",
"values",
"[",
"$",
"val",
"[",
"0",
"]",
"]",
"=",
"$",
"val",
"[",
"1",
"]",
";",
"}",
"call_user_func",
"(",
"array",
"(",
"$",
"variable",
",",
"$",
"setterToCall",
")",
",",
"$",
"values",
")",
";",
"}",
"else",
"{",
"$",
"toCall",
"=",
"'read'",
".",
"ucfirst",
"(",
"BaseType",
"::",
"getNameByConstant",
"(",
"$",
"baseType",
")",
")",
";",
"if",
"(",
"$",
"cardinality",
"===",
"Cardinality",
"::",
"SINGLE",
")",
"{",
"// Deal with a single value.",
"$",
"runtimeValue",
"=",
"Utils",
"::",
"valueToRuntime",
"(",
"call_user_func",
"(",
"array",
"(",
"$",
"this",
",",
"$",
"toCall",
")",
")",
",",
"$",
"baseType",
")",
";",
"call_user_func",
"(",
"array",
"(",
"$",
"variable",
",",
"$",
"setterToCall",
")",
",",
"$",
"runtimeValue",
")",
";",
"}",
"else",
"{",
"// Deal with multiple values.",
"$",
"values",
"=",
"(",
"$",
"cardinality",
"===",
"Cardinality",
"::",
"MULTIPLE",
")",
"?",
"new",
"MultipleContainer",
"(",
"$",
"baseType",
")",
":",
"new",
"OrderedContainer",
"(",
"$",
"baseType",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"count",
";",
"$",
"i",
"++",
")",
"{",
"$",
"isNull",
"=",
"$",
"this",
"->",
"readBoolean",
"(",
")",
";",
"$",
"values",
"[",
"]",
"=",
"(",
"$",
"isNull",
"===",
"true",
")",
"?",
"null",
":",
"Utils",
"::",
"valueToRuntime",
"(",
"call_user_func",
"(",
"array",
"(",
"$",
"this",
",",
"$",
"toCall",
")",
")",
",",
"$",
"baseType",
")",
";",
"}",
"call_user_func",
"(",
"array",
"(",
"$",
"variable",
",",
"$",
"setterToCall",
")",
",",
"$",
"values",
")",
";",
"}",
"}",
"}",
"catch",
"(",
"BinaryStreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while reading a Variable value.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"VARIABLE",
",",
"$",
"e",
")",
";",
"}",
"catch",
"(",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"Datatype mismatch for variable '\"",
".",
"$",
"variable",
"->",
"getIdentifier",
"(",
")",
".",
"\"'.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"VARIABLE",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Read and fill the Variable $variable with its value contained
in the current stream.
@param \qtism\runtime\common\Variable $variable A QTI Runtime Variable object.
@param integer The kind of value to be read (self::RW_VALUE | self::RW_DEFAULTVALUE | self::RW_CORRECTRESPONSE)
@throws \qtism\common\storage\BinaryStreamAccessException If an error occurs at the binary level. | [
"Read",
"and",
"fill",
"the",
"Variable",
"$variable",
"with",
"its",
"value",
"contained",
"in",
"the",
"current",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php#L127-L193 |
oat-sa/qti-sdk | src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php | QtiBinaryStreamAccess.writeVariableValue | public function writeVariableValue(Variable $variable, $valueType = self::RW_VALUE)
{
switch ($valueType) {
case self::RW_DEFAULTVALUE:
$getterToCall = 'getDefaultValue';
break;
case self::RW_CORRECTRESPONSE:
$getterToCall = 'getCorrectResponse';
break;
default:
$getterToCall = 'getValue';
}
try {
$value = call_user_func(array($variable, $getterToCall));
$cardinality = $variable->getCardinality();
$baseType = $variable->getBaseType();
if (is_null($value) === true) {
$this->writeBoolean(true);
return;
}
// Non-null value.
$this->writeBoolean(false);
if ($cardinality === Cardinality::RECORD) {
// is-scalar
$this->writeBoolean(false);
// count
$this->writeShort(count($value));
// content
foreach ($value as $k => $v) {
$this->writeRecordField(array($k, $v), is_null($v));
}
} else {
$toCall = 'write' . ucfirst(BaseType::getNameByConstant($baseType));
if ($cardinality === Cardinality::SINGLE) {
// is-scalar
$this->writeBoolean(true);
// content
$this->$toCall(($value instanceof QtiScalar) ? $value->getValue() : $value);
} else {
// is-scalar
$this->writeBoolean(false);
// count
$this->writeShort(count($value));
// MULTIPLE or ORDERED
foreach ($value as $v) {
if (is_null($v) === false) {
$this->writeBoolean(false);
$this->$toCall(($v instanceof QtiScalar) ? $v->getValue() : $v);
} else {
$this->writeBoolean(true);
}
}
}
}
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while writing a Variable value.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::VARIABLE, $e);
}
} | php | public function writeVariableValue(Variable $variable, $valueType = self::RW_VALUE)
{
switch ($valueType) {
case self::RW_DEFAULTVALUE:
$getterToCall = 'getDefaultValue';
break;
case self::RW_CORRECTRESPONSE:
$getterToCall = 'getCorrectResponse';
break;
default:
$getterToCall = 'getValue';
}
try {
$value = call_user_func(array($variable, $getterToCall));
$cardinality = $variable->getCardinality();
$baseType = $variable->getBaseType();
if (is_null($value) === true) {
$this->writeBoolean(true);
return;
}
// Non-null value.
$this->writeBoolean(false);
if ($cardinality === Cardinality::RECORD) {
// is-scalar
$this->writeBoolean(false);
// count
$this->writeShort(count($value));
// content
foreach ($value as $k => $v) {
$this->writeRecordField(array($k, $v), is_null($v));
}
} else {
$toCall = 'write' . ucfirst(BaseType::getNameByConstant($baseType));
if ($cardinality === Cardinality::SINGLE) {
// is-scalar
$this->writeBoolean(true);
// content
$this->$toCall(($value instanceof QtiScalar) ? $value->getValue() : $value);
} else {
// is-scalar
$this->writeBoolean(false);
// count
$this->writeShort(count($value));
// MULTIPLE or ORDERED
foreach ($value as $v) {
if (is_null($v) === false) {
$this->writeBoolean(false);
$this->$toCall(($v instanceof QtiScalar) ? $v->getValue() : $v);
} else {
$this->writeBoolean(true);
}
}
}
}
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while writing a Variable value.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::VARIABLE, $e);
}
} | [
"public",
"function",
"writeVariableValue",
"(",
"Variable",
"$",
"variable",
",",
"$",
"valueType",
"=",
"self",
"::",
"RW_VALUE",
")",
"{",
"switch",
"(",
"$",
"valueType",
")",
"{",
"case",
"self",
"::",
"RW_DEFAULTVALUE",
":",
"$",
"getterToCall",
"=",
"'getDefaultValue'",
";",
"break",
";",
"case",
"self",
"::",
"RW_CORRECTRESPONSE",
":",
"$",
"getterToCall",
"=",
"'getCorrectResponse'",
";",
"break",
";",
"default",
":",
"$",
"getterToCall",
"=",
"'getValue'",
";",
"}",
"try",
"{",
"$",
"value",
"=",
"call_user_func",
"(",
"array",
"(",
"$",
"variable",
",",
"$",
"getterToCall",
")",
")",
";",
"$",
"cardinality",
"=",
"$",
"variable",
"->",
"getCardinality",
"(",
")",
";",
"$",
"baseType",
"=",
"$",
"variable",
"->",
"getBaseType",
"(",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"writeBoolean",
"(",
"true",
")",
";",
"return",
";",
"}",
"// Non-null value.",
"$",
"this",
"->",
"writeBoolean",
"(",
"false",
")",
";",
"if",
"(",
"$",
"cardinality",
"===",
"Cardinality",
"::",
"RECORD",
")",
"{",
"// is-scalar",
"$",
"this",
"->",
"writeBoolean",
"(",
"false",
")",
";",
"// count",
"$",
"this",
"->",
"writeShort",
"(",
"count",
"(",
"$",
"value",
")",
")",
";",
"// content",
"foreach",
"(",
"$",
"value",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"this",
"->",
"writeRecordField",
"(",
"array",
"(",
"$",
"k",
",",
"$",
"v",
")",
",",
"is_null",
"(",
"$",
"v",
")",
")",
";",
"}",
"}",
"else",
"{",
"$",
"toCall",
"=",
"'write'",
".",
"ucfirst",
"(",
"BaseType",
"::",
"getNameByConstant",
"(",
"$",
"baseType",
")",
")",
";",
"if",
"(",
"$",
"cardinality",
"===",
"Cardinality",
"::",
"SINGLE",
")",
"{",
"// is-scalar",
"$",
"this",
"->",
"writeBoolean",
"(",
"true",
")",
";",
"// content",
"$",
"this",
"->",
"$",
"toCall",
"(",
"(",
"$",
"value",
"instanceof",
"QtiScalar",
")",
"?",
"$",
"value",
"->",
"getValue",
"(",
")",
":",
"$",
"value",
")",
";",
"}",
"else",
"{",
"// is-scalar",
"$",
"this",
"->",
"writeBoolean",
"(",
"false",
")",
";",
"// count",
"$",
"this",
"->",
"writeShort",
"(",
"count",
"(",
"$",
"value",
")",
")",
";",
"// MULTIPLE or ORDERED",
"foreach",
"(",
"$",
"value",
"as",
"$",
"v",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"v",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"writeBoolean",
"(",
"false",
")",
";",
"$",
"this",
"->",
"$",
"toCall",
"(",
"(",
"$",
"v",
"instanceof",
"QtiScalar",
")",
"?",
"$",
"v",
"->",
"getValue",
"(",
")",
":",
"$",
"v",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"writeBoolean",
"(",
"true",
")",
";",
"}",
"}",
"}",
"}",
"}",
"catch",
"(",
"BinaryStreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while writing a Variable value.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"VARIABLE",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Write the value of $variable in the current binary stream.
@param \qtism\runtime\common\Variable $variable A QTI Runtime Variable object.
@throws \qtism\runtime\storage\binary\QtiBinaryStreamAccessException | [
"Write",
"the",
"value",
"of",
"$variable",
"in",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php#L201-L272 |
oat-sa/qti-sdk | src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php | QtiBinaryStreamAccess.readRecordField | public function readRecordField($isNull = false)
{
try {
$key = $this->readString();
if ($isNull === false) {
$baseType = $this->readTinyInt();
$toCall = 'read' . ucfirst(BaseType::getNameByConstant($baseType));
$value = Utils::valueToRuntime(call_user_func(array($this, $toCall)), $baseType);
} else {
$value = null;
}
return array($key, $value);
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while reading a Record Field.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::RECORDFIELD, $e);
}
} | php | public function readRecordField($isNull = false)
{
try {
$key = $this->readString();
if ($isNull === false) {
$baseType = $this->readTinyInt();
$toCall = 'read' . ucfirst(BaseType::getNameByConstant($baseType));
$value = Utils::valueToRuntime(call_user_func(array($this, $toCall)), $baseType);
} else {
$value = null;
}
return array($key, $value);
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while reading a Record Field.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::RECORDFIELD, $e);
}
} | [
"public",
"function",
"readRecordField",
"(",
"$",
"isNull",
"=",
"false",
")",
"{",
"try",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"readString",
"(",
")",
";",
"if",
"(",
"$",
"isNull",
"===",
"false",
")",
"{",
"$",
"baseType",
"=",
"$",
"this",
"->",
"readTinyInt",
"(",
")",
";",
"$",
"toCall",
"=",
"'read'",
".",
"ucfirst",
"(",
"BaseType",
"::",
"getNameByConstant",
"(",
"$",
"baseType",
")",
")",
";",
"$",
"value",
"=",
"Utils",
"::",
"valueToRuntime",
"(",
"call_user_func",
"(",
"array",
"(",
"$",
"this",
",",
"$",
"toCall",
")",
")",
",",
"$",
"baseType",
")",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"null",
";",
"}",
"return",
"array",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"catch",
"(",
"BinaryStreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while reading a Record Field.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"RECORDFIELD",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Read a record field value from the current binary stream. A record field is
composed of a key string and a value.
@return array An array where the value at index 0 is the key string and index 1 is the value.
@throws \qtism\runtime\storage\binary\QtiBinaryStreamAccessException | [
"Read",
"a",
"record",
"field",
"value",
"from",
"the",
"current",
"binary",
"stream",
".",
"A",
"record",
"field",
"is",
"composed",
"of",
"a",
"key",
"string",
"and",
"a",
"value",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php#L281-L300 |
oat-sa/qti-sdk | src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php | QtiBinaryStreamAccess.writeRecordField | public function writeRecordField(array $recordField, $isNull = false)
{
try {
$this->writeBoolean($isNull);
$key = $recordField[0];
$this->writeString($key);
if ($isNull === false) {
$value = $recordField[1];
$baseType = Utils::inferBaseType($value);
$this->writeTinyInt($baseType);
$toCall = 'write' . ucfirst(BaseType::getNameByConstant($baseType));
call_user_func(array($this, $toCall), ($value instanceof QtiScalar) ? $value->getValue() : $value);
}
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while writing a Record Field.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::RECORDFIELD);
}
} | php | public function writeRecordField(array $recordField, $isNull = false)
{
try {
$this->writeBoolean($isNull);
$key = $recordField[0];
$this->writeString($key);
if ($isNull === false) {
$value = $recordField[1];
$baseType = Utils::inferBaseType($value);
$this->writeTinyInt($baseType);
$toCall = 'write' . ucfirst(BaseType::getNameByConstant($baseType));
call_user_func(array($this, $toCall), ($value instanceof QtiScalar) ? $value->getValue() : $value);
}
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while writing a Record Field.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::RECORDFIELD);
}
} | [
"public",
"function",
"writeRecordField",
"(",
"array",
"$",
"recordField",
",",
"$",
"isNull",
"=",
"false",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"writeBoolean",
"(",
"$",
"isNull",
")",
";",
"$",
"key",
"=",
"$",
"recordField",
"[",
"0",
"]",
";",
"$",
"this",
"->",
"writeString",
"(",
"$",
"key",
")",
";",
"if",
"(",
"$",
"isNull",
"===",
"false",
")",
"{",
"$",
"value",
"=",
"$",
"recordField",
"[",
"1",
"]",
";",
"$",
"baseType",
"=",
"Utils",
"::",
"inferBaseType",
"(",
"$",
"value",
")",
";",
"$",
"this",
"->",
"writeTinyInt",
"(",
"$",
"baseType",
")",
";",
"$",
"toCall",
"=",
"'write'",
".",
"ucfirst",
"(",
"BaseType",
"::",
"getNameByConstant",
"(",
"$",
"baseType",
")",
")",
";",
"call_user_func",
"(",
"array",
"(",
"$",
"this",
",",
"$",
"toCall",
")",
",",
"(",
"$",
"value",
"instanceof",
"QtiScalar",
")",
"?",
"$",
"value",
"->",
"getValue",
"(",
")",
":",
"$",
"value",
")",
";",
"}",
"}",
"catch",
"(",
"BinaryStreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while writing a Record Field.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"RECORDFIELD",
")",
";",
"}",
"}"
] | Write a record field value in the current binary stream. A record field is composed of a key string and a value.
@param array $recordField An array where index 0 is the key string, and the index 1 is the value.
@throws \qtism\runtime\storage\binary\QtiBinaryStreamAccessException | [
"Write",
"a",
"record",
"field",
"value",
"in",
"the",
"current",
"binary",
"stream",
".",
"A",
"record",
"field",
"is",
"composed",
"of",
"a",
"key",
"string",
"and",
"a",
"value",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php#L308-L328 |
oat-sa/qti-sdk | src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php | QtiBinaryStreamAccess.readIdentifier | public function readIdentifier()
{
try {
return $this->readString();
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while reading an identifier.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::IDENTIFIER, $e);
}
} | php | public function readIdentifier()
{
try {
return $this->readString();
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while reading an identifier.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::IDENTIFIER, $e);
}
} | [
"public",
"function",
"readIdentifier",
"(",
")",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"readString",
"(",
")",
";",
"}",
"catch",
"(",
"BinaryStreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while reading an identifier.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"IDENTIFIER",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Read an identifier from the current binary stream.
@throws \qtism\runtime\storage\binary\QtiBinaryStreamAccessException
@return string An identifier. | [
"Read",
"an",
"identifier",
"from",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php#L336-L344 |
oat-sa/qti-sdk | src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php | QtiBinaryStreamAccess.writeIdentifier | public function writeIdentifier($identifier)
{
try {
$this->writeString($identifier);
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while writing an identifier.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::IDENTIFIER, $e);
}
} | php | public function writeIdentifier($identifier)
{
try {
$this->writeString($identifier);
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while writing an identifier.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::IDENTIFIER, $e);
}
} | [
"public",
"function",
"writeIdentifier",
"(",
"$",
"identifier",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"writeString",
"(",
"$",
"identifier",
")",
";",
"}",
"catch",
"(",
"BinaryStreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while writing an identifier.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"IDENTIFIER",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Write an identifier in the current binary stream.
@param string $identifier A QTI Identifier.
@throws \qtism\runtime\storage\binary\QtiBinaryStreamAccessException | [
"Write",
"an",
"identifier",
"in",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php#L352-L360 |
oat-sa/qti-sdk | src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php | QtiBinaryStreamAccess.readPoint | public function readPoint()
{
try {
return new QtiPoint($this->readShort(), $this->readShort());
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while reading a point.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::POINT, $e);
}
} | php | public function readPoint()
{
try {
return new QtiPoint($this->readShort(), $this->readShort());
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while reading a point.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::POINT, $e);
}
} | [
"public",
"function",
"readPoint",
"(",
")",
"{",
"try",
"{",
"return",
"new",
"QtiPoint",
"(",
"$",
"this",
"->",
"readShort",
"(",
")",
",",
"$",
"this",
"->",
"readShort",
"(",
")",
")",
";",
"}",
"catch",
"(",
"BinaryStreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while reading a point.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"POINT",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Read a Point from the current binary stream.
@throws \qtism\runtime\storage\binary\QtiBinaryStreamAccessException
@return \qtism\common\datatypes\Point A Point object. | [
"Read",
"a",
"Point",
"from",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php#L368-L376 |
oat-sa/qti-sdk | src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php | QtiBinaryStreamAccess.writePoint | public function writePoint(QtiPoint $point)
{
try {
$this->writeShort($point->getX());
$this->writeShort($point->getY());
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while writing a point.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::POINT, $e);
}
} | php | public function writePoint(QtiPoint $point)
{
try {
$this->writeShort($point->getX());
$this->writeShort($point->getY());
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while writing a point.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::POINT, $e);
}
} | [
"public",
"function",
"writePoint",
"(",
"QtiPoint",
"$",
"point",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"writeShort",
"(",
"$",
"point",
"->",
"getX",
"(",
")",
")",
";",
"$",
"this",
"->",
"writeShort",
"(",
"$",
"point",
"->",
"getY",
"(",
")",
")",
";",
"}",
"catch",
"(",
"BinaryStreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while writing a point.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"POINT",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Write a Point in the current binary stream.
@param \qtism\common\datatypes\Point $point A Point object.
@throws \qtism\runtime\storage\binary\QtiBinaryStreamAccessException | [
"Write",
"a",
"Point",
"in",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php#L384-L393 |
oat-sa/qti-sdk | src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php | QtiBinaryStreamAccess.readPair | public function readPair()
{
try {
return new QtiPair($this->readString(), $this->readString());
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while reading a pair.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::PAIR, $e);
}
} | php | public function readPair()
{
try {
return new QtiPair($this->readString(), $this->readString());
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while reading a pair.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::PAIR, $e);
}
} | [
"public",
"function",
"readPair",
"(",
")",
"{",
"try",
"{",
"return",
"new",
"QtiPair",
"(",
"$",
"this",
"->",
"readString",
"(",
")",
",",
"$",
"this",
"->",
"readString",
"(",
")",
")",
";",
"}",
"catch",
"(",
"BinaryStreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while reading a pair.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"PAIR",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Read a Pair from the current binary stream.
@throws \qtism\runtime\storage\binary\QtiBinaryStreamAccessException
@return \qtism\common\datatypes\Pair A Pair object. | [
"Read",
"a",
"Pair",
"from",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php#L401-L409 |
oat-sa/qti-sdk | src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php | QtiBinaryStreamAccess.writePair | public function writePair(QtiPair $pair)
{
try {
$this->writeString($pair->getFirst());
$this->writeString($pair->getSecond());
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while writing a pair.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::PAIR, $e);
}
} | php | public function writePair(QtiPair $pair)
{
try {
$this->writeString($pair->getFirst());
$this->writeString($pair->getSecond());
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while writing a pair.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::PAIR, $e);
}
} | [
"public",
"function",
"writePair",
"(",
"QtiPair",
"$",
"pair",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"writeString",
"(",
"$",
"pair",
"->",
"getFirst",
"(",
")",
")",
";",
"$",
"this",
"->",
"writeString",
"(",
"$",
"pair",
"->",
"getSecond",
"(",
")",
")",
";",
"}",
"catch",
"(",
"BinaryStreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while writing a pair.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"PAIR",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Write a Pair in the current binary stream.
@param \qtism\common\datatypes\Pair $pair A Pair object.
@throws \qtism\runtime\storage\binary\QtiBinaryStreamAccessException | [
"Write",
"a",
"Pair",
"in",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php#L417-L426 |
oat-sa/qti-sdk | src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php | QtiBinaryStreamAccess.readDirectedPair | public function readDirectedPair()
{
try {
return new QtiDirectedPair($this->readString(), $this->readString());
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while reading a directedPair.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::DIRECTEDPAIR, $e);
}
} | php | public function readDirectedPair()
{
try {
return new QtiDirectedPair($this->readString(), $this->readString());
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while reading a directedPair.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::DIRECTEDPAIR, $e);
}
} | [
"public",
"function",
"readDirectedPair",
"(",
")",
"{",
"try",
"{",
"return",
"new",
"QtiDirectedPair",
"(",
"$",
"this",
"->",
"readString",
"(",
")",
",",
"$",
"this",
"->",
"readString",
"(",
")",
")",
";",
"}",
"catch",
"(",
"BinaryStreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while reading a directedPair.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"DIRECTEDPAIR",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Read a DirectedPair from the current binary stream.
@throws \qtism\runtime\storage\binary\QtiBinaryStreamAccessException
@return \qtism\common\datatypes\DirectedPair A DirectedPair object. | [
"Read",
"a",
"DirectedPair",
"from",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php#L434-L442 |
oat-sa/qti-sdk | src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php | QtiBinaryStreamAccess.writeDirectedPair | public function writeDirectedPair(QtiDirectedPair $directedPair)
{
try {
$this->writeString($directedPair->getFirst());
$this->writeString($directedPair->getSecond());
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while writing a directedPair.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::DIRECTEDPAIR, $e);
}
} | php | public function writeDirectedPair(QtiDirectedPair $directedPair)
{
try {
$this->writeString($directedPair->getFirst());
$this->writeString($directedPair->getSecond());
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while writing a directedPair.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::DIRECTEDPAIR, $e);
}
} | [
"public",
"function",
"writeDirectedPair",
"(",
"QtiDirectedPair",
"$",
"directedPair",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"writeString",
"(",
"$",
"directedPair",
"->",
"getFirst",
"(",
")",
")",
";",
"$",
"this",
"->",
"writeString",
"(",
"$",
"directedPair",
"->",
"getSecond",
"(",
")",
")",
";",
"}",
"catch",
"(",
"BinaryStreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while writing a directedPair.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"DIRECTEDPAIR",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Write a DirectedPair in the current binary stream.
@param \qtism\common\datatypes\DirectedPair $directedPair A DirectedPair object.
@throws \qtism\runtime\storage\binary\QtiBinaryStreamAccessException | [
"Write",
"a",
"DirectedPair",
"in",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php#L450-L459 |
oat-sa/qti-sdk | src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php | QtiBinaryStreamAccess.readShufflingGroup | public function readShufflingGroup()
{
try {
$identifiers = new IdentifierCollection();
$fixedIdentifiers = new IdentifierCollection();
$identifiersCount = $this->readTinyInt();
for ($i = 0; $i < $identifiersCount; $i++) {
$identifiers[] = $this->readString();
}
$shufflingGroup = new ShufflingGroup($identifiers);
$fixedIdentifiersCount = $this->readTinyInt();
for ($i = 0; $i < $fixedIdentifiersCount; $i++) {
$fixedIdentifiers[] = $this->readString();
}
$shufflingGroup->setFixedIdentifiers($fixedIdentifiers);
return $shufflingGroup;
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while reading a shufflingGroup.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::SHUFFLING_GROUP, $e);
}
} | php | public function readShufflingGroup()
{
try {
$identifiers = new IdentifierCollection();
$fixedIdentifiers = new IdentifierCollection();
$identifiersCount = $this->readTinyInt();
for ($i = 0; $i < $identifiersCount; $i++) {
$identifiers[] = $this->readString();
}
$shufflingGroup = new ShufflingGroup($identifiers);
$fixedIdentifiersCount = $this->readTinyInt();
for ($i = 0; $i < $fixedIdentifiersCount; $i++) {
$fixedIdentifiers[] = $this->readString();
}
$shufflingGroup->setFixedIdentifiers($fixedIdentifiers);
return $shufflingGroup;
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while reading a shufflingGroup.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::SHUFFLING_GROUP, $e);
}
} | [
"public",
"function",
"readShufflingGroup",
"(",
")",
"{",
"try",
"{",
"$",
"identifiers",
"=",
"new",
"IdentifierCollection",
"(",
")",
";",
"$",
"fixedIdentifiers",
"=",
"new",
"IdentifierCollection",
"(",
")",
";",
"$",
"identifiersCount",
"=",
"$",
"this",
"->",
"readTinyInt",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"identifiersCount",
";",
"$",
"i",
"++",
")",
"{",
"$",
"identifiers",
"[",
"]",
"=",
"$",
"this",
"->",
"readString",
"(",
")",
";",
"}",
"$",
"shufflingGroup",
"=",
"new",
"ShufflingGroup",
"(",
"$",
"identifiers",
")",
";",
"$",
"fixedIdentifiersCount",
"=",
"$",
"this",
"->",
"readTinyInt",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"fixedIdentifiersCount",
";",
"$",
"i",
"++",
")",
"{",
"$",
"fixedIdentifiers",
"[",
"]",
"=",
"$",
"this",
"->",
"readString",
"(",
")",
";",
"}",
"$",
"shufflingGroup",
"->",
"setFixedIdentifiers",
"(",
"$",
"fixedIdentifiers",
")",
";",
"return",
"$",
"shufflingGroup",
";",
"}",
"catch",
"(",
"BinaryStreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while reading a shufflingGroup.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"SHUFFLING_GROUP",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Read a ShufflingGroup from the current binary stream.
@throws QtiBinaryStreamAccessException
@return \qtism\data\state\ShufflingGroup | [
"Read",
"a",
"ShufflingGroup",
"from",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php#L467-L494 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.