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/ExtendedTextInteraction.php | ExtendedTextInteraction.setFormat | public function setFormat($format)
{
if (in_array($format, TextFormat::asArray()) === true) {
$this->format = $format;
} else {
$msg = "The 'format' argument must be a value from the TextFormat enumeration, '" . gettype($format) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setFormat($format)
{
if (in_array($format, TextFormat::asArray()) === true) {
$this->format = $format;
} else {
$msg = "The 'format' argument must be a value from the TextFormat enumeration, '" . gettype($format) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setFormat",
"(",
"$",
"format",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"format",
",",
"TextFormat",
"::",
"asArray",
"(",
")",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"format",
"=",
"$",
"format",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'format' argument must be a value from the TextFormat enumeration, '\"",
".",
"gettype",
"(",
"$",
"format",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the format of the text entered by the candidate.
@param integer $format A value from the TextFormat enumeration.
@throws \InvalidArgumentException If $format is not a value from the TextFormat enumeration. | [
"Set",
"the",
"format",
"of",
"the",
"text",
"entered",
"by",
"the",
"candidate",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/interactions/ExtendedTextInteraction.php#L472-L480 |
oat-sa/qti-sdk | src/qtism/data/rules/ResponseElse.php | ResponseElse.setOutcomeRules | public function setOutcomeRules(ResponseRuleCollection $responseRules)
{
if (count($responseRules) > 0) {
$this->responseRules = $responseRules;
} else {
$msg = "A ResponseElse object must be bound to at least one ResponseRule object.";
throw new InvalidArgumentException($msg);
}
} | php | public function setOutcomeRules(ResponseRuleCollection $responseRules)
{
if (count($responseRules) > 0) {
$this->responseRules = $responseRules;
} else {
$msg = "A ResponseElse object must be bound to at least one ResponseRule object.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setOutcomeRules",
"(",
"ResponseRuleCollection",
"$",
"responseRules",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"responseRules",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"responseRules",
"=",
"$",
"responseRules",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"A ResponseElse object must be bound to at least one ResponseRule object.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the ResponseRule objects to be evaluated.
@param \qtism\data\rules\ResponseRuleCollection $responseRules A collection of ResponseRule objects.
@throws \InvalidArgumentException If $responseRules is an empty collection. | [
"Set",
"the",
"ResponseRule",
"objects",
"to",
"be",
"evaluated",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/rules/ResponseElse.php#L72-L80 |
oat-sa/qti-sdk | src/qtism/data/content/interactions/GapMatchInteraction.php | GapMatchInteraction.setGapChoices | public function setGapChoices(GapChoiceCollection $gapChoices)
{
if (count($gapChoices) > 0) {
$this->gapChoices = $gapChoices;
} else {
$msg = "A GapMatchInteraction object must be composed of at least one GapChoice object, none given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setGapChoices(GapChoiceCollection $gapChoices)
{
if (count($gapChoices) > 0) {
$this->gapChoices = $gapChoices;
} else {
$msg = "A GapMatchInteraction object must be composed of at least one GapChoice object, none given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setGapChoices",
"(",
"GapChoiceCollection",
"$",
"gapChoices",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"gapChoices",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"gapChoices",
"=",
"$",
"gapChoices",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"A GapMatchInteraction object must be composed of at least one GapChoice object, none given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the collection of choices for filling the gaps.
@param \qtism\data\content\interactions\GapChoiceCollection $gapChoices A collection of at least one GapChoice object.
@throws \InvalidArgumentException If $gapChoices is empty. | [
"Set",
"the",
"collection",
"of",
"choices",
"for",
"filling",
"the",
"gaps",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/interactions/GapMatchInteraction.php#L139-L147 |
oat-sa/qti-sdk | src/qtism/runtime/rules/AbstractConditionProcessor.php | AbstractConditionProcessor.pushTrail | public function pushTrail($components)
{
$trail = &$this->getTrail();
if ($components instanceof QtiComponent) {
array_push($trail, $components);
} else {
$i = count($components);
// collection
while ($i >= 1) {
$i--;
array_push($trail, $components[$i]);
}
}
} | php | public function pushTrail($components)
{
$trail = &$this->getTrail();
if ($components instanceof QtiComponent) {
array_push($trail, $components);
} else {
$i = count($components);
// collection
while ($i >= 1) {
$i--;
array_push($trail, $components[$i]);
}
}
} | [
"public",
"function",
"pushTrail",
"(",
"$",
"components",
")",
"{",
"$",
"trail",
"=",
"&",
"$",
"this",
"->",
"getTrail",
"(",
")",
";",
"if",
"(",
"$",
"components",
"instanceof",
"QtiComponent",
")",
"{",
"array_push",
"(",
"$",
"trail",
",",
"$",
"components",
")",
";",
"}",
"else",
"{",
"$",
"i",
"=",
"count",
"(",
"$",
"components",
")",
";",
"// collection",
"while",
"(",
"$",
"i",
">=",
"1",
")",
"{",
"$",
"i",
"--",
";",
"array_push",
"(",
"$",
"trail",
",",
"$",
"components",
"[",
"$",
"i",
"]",
")",
";",
"}",
"}",
"}"
] | Push some Rule objects on the trail stack.
@param \qtism\data\QtiComponentCollection|\qtism\data\QtiComponent $components A collection of Rule objects. | [
"Push",
"some",
"Rule",
"objects",
"on",
"the",
"trail",
"stack",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rules/AbstractConditionProcessor.php#L102-L116 |
oat-sa/qti-sdk | src/qtism/runtime/rules/AbstractConditionProcessor.php | AbstractConditionProcessor.process | public function process()
{
$state = $this->getState();
$this->pushTrail($this->getRule());
$className = ucfirst($this->getQtiNature());
$nsClass = 'qtism\\data\\rules\\' . $className . 'Condition';
$ruleGetter = "get${className}Rules";
$statementGetter = "get${className}"; // + 'If'|'ElseIf'|'Else'
while (count($this->getTrail()) > 0) {
$rule = $this->popTrail();
if (get_class($rule) === $nsClass) {
// Let's try for if.
$ifStatement = call_user_func(array($rule, $statementGetter . 'If'));
$ifExpression = $ifStatement->getExpression();
$exprEngine = new ExpressionEngine($ifExpression, $state);
$value = $exprEngine->process();
if ($value !== null && $value->getValue() === true) {
// Follow the if.
$this->pushTrail(call_user_func(array($ifStatement, $ruleGetter)));
} else {
// Let's try for else ifs.
$followElseIf = false;
$elseIfStatements = call_user_func(array($rule, $statementGetter . 'ElseIfs'));
foreach ($elseIfStatements as $elseIfStatement) {
$elseIfExpression = $elseIfStatement->getExpression();
$exprEngine->setComponent($elseIfExpression);
$value = $exprEngine->process();
if ($value !== null && $value->getValue() === true) {
// Follow the current else if.
$this->pushTrail(call_user_func(array($elseIfStatement, $ruleGetter)));
$followElseIf = true;
break;
}
}
$elseStatement = call_user_func(array($rule, $statementGetter . 'Else'));
if ($followElseIf === false && is_null($elseStatement) === false) {
// No else if followed, the last resort is the else.
$this->pushTrail(call_user_func(array($elseStatement, $ruleGetter)));
}
}
} else {
// $rule is another Rule than OutcomeCondition/ResponseCondition.
$processor = $this->getRuleProcessorFactory()->createProcessor($rule);
$processor->setState($state);
$processor->process();
}
}
} | php | public function process()
{
$state = $this->getState();
$this->pushTrail($this->getRule());
$className = ucfirst($this->getQtiNature());
$nsClass = 'qtism\\data\\rules\\' . $className . 'Condition';
$ruleGetter = "get${className}Rules";
$statementGetter = "get${className}"; // + 'If'|'ElseIf'|'Else'
while (count($this->getTrail()) > 0) {
$rule = $this->popTrail();
if (get_class($rule) === $nsClass) {
// Let's try for if.
$ifStatement = call_user_func(array($rule, $statementGetter . 'If'));
$ifExpression = $ifStatement->getExpression();
$exprEngine = new ExpressionEngine($ifExpression, $state);
$value = $exprEngine->process();
if ($value !== null && $value->getValue() === true) {
// Follow the if.
$this->pushTrail(call_user_func(array($ifStatement, $ruleGetter)));
} else {
// Let's try for else ifs.
$followElseIf = false;
$elseIfStatements = call_user_func(array($rule, $statementGetter . 'ElseIfs'));
foreach ($elseIfStatements as $elseIfStatement) {
$elseIfExpression = $elseIfStatement->getExpression();
$exprEngine->setComponent($elseIfExpression);
$value = $exprEngine->process();
if ($value !== null && $value->getValue() === true) {
// Follow the current else if.
$this->pushTrail(call_user_func(array($elseIfStatement, $ruleGetter)));
$followElseIf = true;
break;
}
}
$elseStatement = call_user_func(array($rule, $statementGetter . 'Else'));
if ($followElseIf === false && is_null($elseStatement) === false) {
// No else if followed, the last resort is the else.
$this->pushTrail(call_user_func(array($elseStatement, $ruleGetter)));
}
}
} else {
// $rule is another Rule than OutcomeCondition/ResponseCondition.
$processor = $this->getRuleProcessorFactory()->createProcessor($rule);
$processor->setState($state);
$processor->process();
}
}
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"state",
"=",
"$",
"this",
"->",
"getState",
"(",
")",
";",
"$",
"this",
"->",
"pushTrail",
"(",
"$",
"this",
"->",
"getRule",
"(",
")",
")",
";",
"$",
"className",
"=",
"ucfirst",
"(",
"$",
"this",
"->",
"getQtiNature",
"(",
")",
")",
";",
"$",
"nsClass",
"=",
"'qtism\\\\data\\\\rules\\\\'",
".",
"$",
"className",
".",
"'Condition'",
";",
"$",
"ruleGetter",
"=",
"\"get${className}Rules\"",
";",
"$",
"statementGetter",
"=",
"\"get${className}\"",
";",
"// + 'If'|'ElseIf'|'Else'",
"while",
"(",
"count",
"(",
"$",
"this",
"->",
"getTrail",
"(",
")",
")",
">",
"0",
")",
"{",
"$",
"rule",
"=",
"$",
"this",
"->",
"popTrail",
"(",
")",
";",
"if",
"(",
"get_class",
"(",
"$",
"rule",
")",
"===",
"$",
"nsClass",
")",
"{",
"// Let's try for if.",
"$",
"ifStatement",
"=",
"call_user_func",
"(",
"array",
"(",
"$",
"rule",
",",
"$",
"statementGetter",
".",
"'If'",
")",
")",
";",
"$",
"ifExpression",
"=",
"$",
"ifStatement",
"->",
"getExpression",
"(",
")",
";",
"$",
"exprEngine",
"=",
"new",
"ExpressionEngine",
"(",
"$",
"ifExpression",
",",
"$",
"state",
")",
";",
"$",
"value",
"=",
"$",
"exprEngine",
"->",
"process",
"(",
")",
";",
"if",
"(",
"$",
"value",
"!==",
"null",
"&&",
"$",
"value",
"->",
"getValue",
"(",
")",
"===",
"true",
")",
"{",
"// Follow the if.",
"$",
"this",
"->",
"pushTrail",
"(",
"call_user_func",
"(",
"array",
"(",
"$",
"ifStatement",
",",
"$",
"ruleGetter",
")",
")",
")",
";",
"}",
"else",
"{",
"// Let's try for else ifs.",
"$",
"followElseIf",
"=",
"false",
";",
"$",
"elseIfStatements",
"=",
"call_user_func",
"(",
"array",
"(",
"$",
"rule",
",",
"$",
"statementGetter",
".",
"'ElseIfs'",
")",
")",
";",
"foreach",
"(",
"$",
"elseIfStatements",
"as",
"$",
"elseIfStatement",
")",
"{",
"$",
"elseIfExpression",
"=",
"$",
"elseIfStatement",
"->",
"getExpression",
"(",
")",
";",
"$",
"exprEngine",
"->",
"setComponent",
"(",
"$",
"elseIfExpression",
")",
";",
"$",
"value",
"=",
"$",
"exprEngine",
"->",
"process",
"(",
")",
";",
"if",
"(",
"$",
"value",
"!==",
"null",
"&&",
"$",
"value",
"->",
"getValue",
"(",
")",
"===",
"true",
")",
"{",
"// Follow the current else if.",
"$",
"this",
"->",
"pushTrail",
"(",
"call_user_func",
"(",
"array",
"(",
"$",
"elseIfStatement",
",",
"$",
"ruleGetter",
")",
")",
")",
";",
"$",
"followElseIf",
"=",
"true",
";",
"break",
";",
"}",
"}",
"$",
"elseStatement",
"=",
"call_user_func",
"(",
"array",
"(",
"$",
"rule",
",",
"$",
"statementGetter",
".",
"'Else'",
")",
")",
";",
"if",
"(",
"$",
"followElseIf",
"===",
"false",
"&&",
"is_null",
"(",
"$",
"elseStatement",
")",
"===",
"false",
")",
"{",
"// No else if followed, the last resort is the else.",
"$",
"this",
"->",
"pushTrail",
"(",
"call_user_func",
"(",
"array",
"(",
"$",
"elseStatement",
",",
"$",
"ruleGetter",
")",
")",
")",
";",
"}",
"}",
"}",
"else",
"{",
"// $rule is another Rule than OutcomeCondition/ResponseCondition.",
"$",
"processor",
"=",
"$",
"this",
"->",
"getRuleProcessorFactory",
"(",
")",
"->",
"createProcessor",
"(",
"$",
"rule",
")",
";",
"$",
"processor",
"->",
"setState",
"(",
"$",
"state",
")",
";",
"$",
"processor",
"->",
"process",
"(",
")",
";",
"}",
"}",
"}"
] | Process the OutcomeCondition/ResponseCondition according to the current state.
@throws \qtism\runtime\rules\RuleProcessingException | [
"Process",
"the",
"OutcomeCondition",
"/",
"ResponseCondition",
"according",
"to",
"the",
"current",
"state",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rules/AbstractConditionProcessor.php#L155-L212 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/BaseValueMarshaller.php | BaseValueMarshaller.marshall | protected function marshall(QtiComponent $component)
{
$element = static::getDOMCradle()->createElement($component->getQtiClassName());
$this->setDOMElementAttribute($element, 'baseType', BaseType::getNameByConstant($component->getBaseType()));
self::setDOMElementValue($element, $component->getValue());
return $element;
} | php | protected function marshall(QtiComponent $component)
{
$element = static::getDOMCradle()->createElement($component->getQtiClassName());
$this->setDOMElementAttribute($element, 'baseType', BaseType::getNameByConstant($component->getBaseType()));
self::setDOMElementValue($element, $component->getValue());
return $element;
} | [
"protected",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"$",
"element",
"=",
"static",
"::",
"getDOMCradle",
"(",
")",
"->",
"createElement",
"(",
"$",
"component",
"->",
"getQtiClassName",
"(",
")",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'baseType'",
",",
"BaseType",
"::",
"getNameByConstant",
"(",
"$",
"component",
"->",
"getBaseType",
"(",
")",
")",
")",
";",
"self",
"::",
"setDOMElementValue",
"(",
"$",
"element",
",",
"$",
"component",
"->",
"getValue",
"(",
")",
")",
";",
"return",
"$",
"element",
";",
"}"
] | Marshall a BaseValue object into a DOMElement object.
@param \qtism\data\QtiComponent $component A BaseValue object.
@return \DOMElement The according DOMElement object. | [
"Marshall",
"a",
"BaseValue",
"object",
"into",
"a",
"DOMElement",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/BaseValueMarshaller.php#L45-L53 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/BaseValueMarshaller.php | BaseValueMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
if (($baseType = $this->getDOMElementAttributeAs($element, 'baseType', 'string')) !== null) {
$value = $element->nodeValue;
$baseTypeCst = BaseType::getConstantByName($baseType);
// A little bit of cleaning...
if ($baseTypeCst !== BaseType::STRING) {
$value = trim($value);
}
$object = new BaseValue($baseTypeCst, Utils::stringToDatatype($value, $baseTypeCst));
return $object;
} else {
$msg = "The mandatory attribute 'baseType' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} | php | protected function unmarshall(DOMElement $element)
{
if (($baseType = $this->getDOMElementAttributeAs($element, 'baseType', 'string')) !== null) {
$value = $element->nodeValue;
$baseTypeCst = BaseType::getConstantByName($baseType);
// A little bit of cleaning...
if ($baseTypeCst !== BaseType::STRING) {
$value = trim($value);
}
$object = new BaseValue($baseTypeCst, Utils::stringToDatatype($value, $baseTypeCst));
return $object;
} else {
$msg = "The mandatory attribute 'baseType' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"if",
"(",
"(",
"$",
"baseType",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'baseType'",
",",
"'string'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"value",
"=",
"$",
"element",
"->",
"nodeValue",
";",
"$",
"baseTypeCst",
"=",
"BaseType",
"::",
"getConstantByName",
"(",
"$",
"baseType",
")",
";",
"// A little bit of cleaning...",
"if",
"(",
"$",
"baseTypeCst",
"!==",
"BaseType",
"::",
"STRING",
")",
"{",
"$",
"value",
"=",
"trim",
"(",
"$",
"value",
")",
";",
"}",
"$",
"object",
"=",
"new",
"BaseValue",
"(",
"$",
"baseTypeCst",
",",
"Utils",
"::",
"stringToDatatype",
"(",
"$",
"value",
",",
"$",
"baseTypeCst",
")",
")",
";",
"return",
"$",
"object",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory attribute 'baseType' is missing from element '\"",
".",
"$",
"element",
"->",
"localName",
".",
"\"'.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}"
] | Unmarshall a DOMElement object corresponding to a QTI baseValue element.
@param \DOMElement $element A DOMElement object.
@return \qtism\data\QtiComponent A BaseValue object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException | [
"Unmarshall",
"a",
"DOMElement",
"object",
"corresponding",
"to",
"a",
"QTI",
"baseValue",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/BaseValueMarshaller.php#L62-L81 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/IsNullProcessor.php | IsNullProcessor.process | public function process()
{
$operands = $this->getOperands();
$expression = $this->getExpression();
return new QtiBoolean($operands->containsNull());
} | php | public function process()
{
$operands = $this->getOperands();
$expression = $this->getExpression();
return new QtiBoolean($operands->containsNull());
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"operands",
"=",
"$",
"this",
"->",
"getOperands",
"(",
")",
";",
"$",
"expression",
"=",
"$",
"this",
"->",
"getExpression",
"(",
")",
";",
"return",
"new",
"QtiBoolean",
"(",
"$",
"operands",
"->",
"containsNull",
"(",
")",
")",
";",
"}"
] | Process the IsNullExpression object from the QTI Data Model.
@return boolean Whether the sub-expression is considered to be NULL.
@throws \qtism\runtime\expressions\operators\OperatorProcessingException If something goes wrong. | [
"Process",
"the",
"IsNullExpression",
"object",
"from",
"the",
"QTI",
"Data",
"Model",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/IsNullProcessor.php#L52-L58 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/VariableDeclarationMarshaller.php | VariableDeclarationMarshaller.marshall | protected function marshall(QtiComponent $component)
{
$element = static::getDOMCradle()->createElement($component->getQtiClassName());
$this->setDOMElementAttribute($element, 'identifier', $component->getIdentifier());
$this->setDOMElementAttribute($element, 'cardinality', Cardinality::getNameByConstant($component->getCardinality()));
if ($component->getBaseType() != -1) {
$this->setDOMElementAttribute($element, 'baseType', BaseType::getNameByConstant($component->getBaseType()));
}
// deal with default value.
if ($component->getDefaultValue() != null) {
$defaultValue = $component->getDefaultValue();
$defaultValueMarshaller = $this->getMarshallerFactory()->createMarshaller($defaultValue, array($component->getBaseType()));
$element->appendChild($defaultValueMarshaller->marshall($defaultValue));
}
return $element;
} | php | protected function marshall(QtiComponent $component)
{
$element = static::getDOMCradle()->createElement($component->getQtiClassName());
$this->setDOMElementAttribute($element, 'identifier', $component->getIdentifier());
$this->setDOMElementAttribute($element, 'cardinality', Cardinality::getNameByConstant($component->getCardinality()));
if ($component->getBaseType() != -1) {
$this->setDOMElementAttribute($element, 'baseType', BaseType::getNameByConstant($component->getBaseType()));
}
// deal with default value.
if ($component->getDefaultValue() != null) {
$defaultValue = $component->getDefaultValue();
$defaultValueMarshaller = $this->getMarshallerFactory()->createMarshaller($defaultValue, array($component->getBaseType()));
$element->appendChild($defaultValueMarshaller->marshall($defaultValue));
}
return $element;
} | [
"protected",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"$",
"element",
"=",
"static",
"::",
"getDOMCradle",
"(",
")",
"->",
"createElement",
"(",
"$",
"component",
"->",
"getQtiClassName",
"(",
")",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'identifier'",
",",
"$",
"component",
"->",
"getIdentifier",
"(",
")",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'cardinality'",
",",
"Cardinality",
"::",
"getNameByConstant",
"(",
"$",
"component",
"->",
"getCardinality",
"(",
")",
")",
")",
";",
"if",
"(",
"$",
"component",
"->",
"getBaseType",
"(",
")",
"!=",
"-",
"1",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'baseType'",
",",
"BaseType",
"::",
"getNameByConstant",
"(",
"$",
"component",
"->",
"getBaseType",
"(",
")",
")",
")",
";",
"}",
"// deal with default value.",
"if",
"(",
"$",
"component",
"->",
"getDefaultValue",
"(",
")",
"!=",
"null",
")",
"{",
"$",
"defaultValue",
"=",
"$",
"component",
"->",
"getDefaultValue",
"(",
")",
";",
"$",
"defaultValueMarshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"defaultValue",
",",
"array",
"(",
"$",
"component",
"->",
"getBaseType",
"(",
")",
")",
")",
";",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"defaultValueMarshaller",
"->",
"marshall",
"(",
"$",
"defaultValue",
")",
")",
";",
"}",
"return",
"$",
"element",
";",
"}"
] | Marshall a VariableDeclaration object into a DOMElement object.
@param \qtism\data\QtiComponent $component An OutcomeDeclaration object.
@return \DOMElement The according DOMElement object. | [
"Marshall",
"a",
"VariableDeclaration",
"object",
"into",
"a",
"DOMElement",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/VariableDeclarationMarshaller.php#L46-L65 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/VariableDeclarationMarshaller.php | VariableDeclarationMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
try {
// identifier is a mandatory value for the variableDeclaration element.
if (($identifier = $this->getDOMElementAttributeAs($element, 'identifier')) !== null) {
// cardinality is a mandatory value too.
if (($cardinality = $this->getDOMElementAttributeAs($element, 'cardinality')) !== null) {
$object = new VariableDeclaration($identifier, -1, Cardinality::getConstantByName($cardinality));
// deal with baseType.
$baseType = $this->getDOMElementAttributeAs($element, 'baseType');
if (!empty($baseType)) {
$object->setBaseType(BaseType::getConstantByName($baseType));
}
// set up optional default value.
$defaultValueElements = $element->getElementsByTagName('defaultValue');
if ($defaultValueElements->length == 1) {
$defaultValueElement = $defaultValueElements->item(0);
$defaultValueMarshaller = $this->getMarshallerFactory()->createMarshaller($defaultValueElements->item(0), array($object->getBaseType()));
$object->setDefaultValue($defaultValueMarshaller->unmarshall($defaultValueElement));
}
return $object;
} else {
$msg = "The mandatory attribute 'cardinality' 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);
}
} catch (InvalidArgumentException $e) {
$msg = "An unexpected error occured while unmarshalling the variableDeclaration.";
throw new UnmarshallingException($msg, $element, $e);
}
} | php | protected function unmarshall(DOMElement $element)
{
try {
// identifier is a mandatory value for the variableDeclaration element.
if (($identifier = $this->getDOMElementAttributeAs($element, 'identifier')) !== null) {
// cardinality is a mandatory value too.
if (($cardinality = $this->getDOMElementAttributeAs($element, 'cardinality')) !== null) {
$object = new VariableDeclaration($identifier, -1, Cardinality::getConstantByName($cardinality));
// deal with baseType.
$baseType = $this->getDOMElementAttributeAs($element, 'baseType');
if (!empty($baseType)) {
$object->setBaseType(BaseType::getConstantByName($baseType));
}
// set up optional default value.
$defaultValueElements = $element->getElementsByTagName('defaultValue');
if ($defaultValueElements->length == 1) {
$defaultValueElement = $defaultValueElements->item(0);
$defaultValueMarshaller = $this->getMarshallerFactory()->createMarshaller($defaultValueElements->item(0), array($object->getBaseType()));
$object->setDefaultValue($defaultValueMarshaller->unmarshall($defaultValueElement));
}
return $object;
} else {
$msg = "The mandatory attribute 'cardinality' 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);
}
} catch (InvalidArgumentException $e) {
$msg = "An unexpected error occured while unmarshalling the variableDeclaration.";
throw new UnmarshallingException($msg, $element, $e);
}
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"try",
"{",
"// identifier is a mandatory value for the variableDeclaration element.",
"if",
"(",
"(",
"$",
"identifier",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'identifier'",
")",
")",
"!==",
"null",
")",
"{",
"// cardinality is a mandatory value too.",
"if",
"(",
"(",
"$",
"cardinality",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'cardinality'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"object",
"=",
"new",
"VariableDeclaration",
"(",
"$",
"identifier",
",",
"-",
"1",
",",
"Cardinality",
"::",
"getConstantByName",
"(",
"$",
"cardinality",
")",
")",
";",
"// deal with baseType.",
"$",
"baseType",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'baseType'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"baseType",
")",
")",
"{",
"$",
"object",
"->",
"setBaseType",
"(",
"BaseType",
"::",
"getConstantByName",
"(",
"$",
"baseType",
")",
")",
";",
"}",
"// set up optional default value.",
"$",
"defaultValueElements",
"=",
"$",
"element",
"->",
"getElementsByTagName",
"(",
"'defaultValue'",
")",
";",
"if",
"(",
"$",
"defaultValueElements",
"->",
"length",
"==",
"1",
")",
"{",
"$",
"defaultValueElement",
"=",
"$",
"defaultValueElements",
"->",
"item",
"(",
"0",
")",
";",
"$",
"defaultValueMarshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"defaultValueElements",
"->",
"item",
"(",
"0",
")",
",",
"array",
"(",
"$",
"object",
"->",
"getBaseType",
"(",
")",
")",
")",
";",
"$",
"object",
"->",
"setDefaultValue",
"(",
"$",
"defaultValueMarshaller",
"->",
"unmarshall",
"(",
"$",
"defaultValueElement",
")",
")",
";",
"}",
"return",
"$",
"object",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory attribute 'cardinality' 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",
")",
";",
"}",
"}",
"catch",
"(",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An unexpected error occured while unmarshalling the variableDeclaration.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Unmarshall a DOMElement object corresponding to a QTI variableDeclaration element.
@param \DOMElement $element A DOMElement object.
@return \qtism\data\QtiComponent A VariableDeclaration object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException | [
"Unmarshall",
"a",
"DOMElement",
"object",
"corresponding",
"to",
"a",
"QTI",
"variableDeclaration",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/VariableDeclarationMarshaller.php#L74-L112 |
oat-sa/qti-sdk | src/qtism/data/storage/php/marshalling/PhpQtiDatatypeMarshaller.php | PhpQtiDatatypeMarshaller.marshall | public function marshall()
{
$toMarshall = $this->getToMarshall();
try {
if ($toMarshall instanceof QtiCoords) {
$this->marshallCoords();
return;
} elseif ($toMarshall instanceof QtiPair) {
$this->marshallPair();
return;
} elseif ($toMarshall instanceof QtiDuration) {
$this->marshallDuration();
return;
} elseif ($toMarshall instanceof QtiPoint) {
$this->marshallPoint();
return;
} else if ($toMarshall instanceof QtiIdentifier) {
$this->marshallIdentifier();
return;
}
} catch (PhpMarshallingException $e) {
$msg = "An error occured while marshalling a QtiDatatype object.";
throw new PhpMarshallingException($msg, PhpMarshallingException::RUNTIME, $e);
}
$className = get_class($toMarshall);
$msg = "Cannot deal with QtiDatatype '${className}'.";
throw new PhpMarshallingException($msg, PhpMarshallingException::RUNTIME);
} | php | public function marshall()
{
$toMarshall = $this->getToMarshall();
try {
if ($toMarshall instanceof QtiCoords) {
$this->marshallCoords();
return;
} elseif ($toMarshall instanceof QtiPair) {
$this->marshallPair();
return;
} elseif ($toMarshall instanceof QtiDuration) {
$this->marshallDuration();
return;
} elseif ($toMarshall instanceof QtiPoint) {
$this->marshallPoint();
return;
} else if ($toMarshall instanceof QtiIdentifier) {
$this->marshallIdentifier();
return;
}
} catch (PhpMarshallingException $e) {
$msg = "An error occured while marshalling a QtiDatatype object.";
throw new PhpMarshallingException($msg, PhpMarshallingException::RUNTIME, $e);
}
$className = get_class($toMarshall);
$msg = "Cannot deal with QtiDatatype '${className}'.";
throw new PhpMarshallingException($msg, PhpMarshallingException::RUNTIME);
} | [
"public",
"function",
"marshall",
"(",
")",
"{",
"$",
"toMarshall",
"=",
"$",
"this",
"->",
"getToMarshall",
"(",
")",
";",
"try",
"{",
"if",
"(",
"$",
"toMarshall",
"instanceof",
"QtiCoords",
")",
"{",
"$",
"this",
"->",
"marshallCoords",
"(",
")",
";",
"return",
";",
"}",
"elseif",
"(",
"$",
"toMarshall",
"instanceof",
"QtiPair",
")",
"{",
"$",
"this",
"->",
"marshallPair",
"(",
")",
";",
"return",
";",
"}",
"elseif",
"(",
"$",
"toMarshall",
"instanceof",
"QtiDuration",
")",
"{",
"$",
"this",
"->",
"marshallDuration",
"(",
")",
";",
"return",
";",
"}",
"elseif",
"(",
"$",
"toMarshall",
"instanceof",
"QtiPoint",
")",
"{",
"$",
"this",
"->",
"marshallPoint",
"(",
")",
";",
"return",
";",
"}",
"else",
"if",
"(",
"$",
"toMarshall",
"instanceof",
"QtiIdentifier",
")",
"{",
"$",
"this",
"->",
"marshallIdentifier",
"(",
")",
";",
"return",
";",
"}",
"}",
"catch",
"(",
"PhpMarshallingException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while marshalling a QtiDatatype object.\"",
";",
"throw",
"new",
"PhpMarshallingException",
"(",
"$",
"msg",
",",
"PhpMarshallingException",
"::",
"RUNTIME",
",",
"$",
"e",
")",
";",
"}",
"$",
"className",
"=",
"get_class",
"(",
"$",
"toMarshall",
")",
";",
"$",
"msg",
"=",
"\"Cannot deal with QtiDatatype '${className}'.\"",
";",
"throw",
"new",
"PhpMarshallingException",
"(",
"$",
"msg",
",",
"PhpMarshallingException",
"::",
"RUNTIME",
")",
";",
"}"
] | Marshall a QtiDatatype object into PHP source code.
@throws \qtism\data\storage\php\marshalling\PhpMarshallingException If an error occurs during marshalling. | [
"Marshall",
"a",
"QtiDatatype",
"object",
"into",
"PHP",
"source",
"code",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/php/marshalling/PhpQtiDatatypeMarshaller.php#L50-L84 |
oat-sa/qti-sdk | src/qtism/data/storage/php/marshalling/PhpQtiDatatypeMarshaller.php | PhpQtiDatatypeMarshaller.marshallCoords | protected function marshallCoords()
{
// Retrieve the coordinates array.
$coords = $this->getToMarshall();
$array = $coords->getArrayCopy();
// Retrieve the shape.
$shape = $coords->getShape();
// -- Actual marshalling.
$ctx = $this->getContext();
$access = $ctx->getStreamAccess();
// Marshall the $array.
$args = new PhpArgumentCollection();
foreach ($array as $a) {
$args[] = new PhpArgument($a);
}
try {
$arrayVarName = $ctx->generateVariableName($array);
$access->writeVariable($arrayVarName);
$access->writeEquals($ctx->mustFormatOutput());
$access->writeFunctionCall('array', $args);
$access->writeSemicolon($ctx->mustFormatOutput());
// Marshall the Coords object.
$coordsArgs = new PhpArgumentCollection(array(new PhpArgument($coords->getShape()), new PhpArgument(new PhpVariable($arrayVarName))));
$varName = $ctx->generateVariableName($coords);
$access->writeVariable($varName);
$access->writeEquals($ctx->mustFormatOutput());
$access->writeInstantiation(get_class($coords), $coordsArgs);
$access->writeSemicolon($ctx->mustFormatOutput());
$ctx->pushOnVariableStack($varName);
} catch (StreamAccessException $e) {
$msg = "An error occured while marshalling a Coords object into the PHP source code stream.";
throw new PhpMarshallingException($msg, PhpMarshallingException::STREAM, $e);
}
} | php | protected function marshallCoords()
{
// Retrieve the coordinates array.
$coords = $this->getToMarshall();
$array = $coords->getArrayCopy();
// Retrieve the shape.
$shape = $coords->getShape();
// -- Actual marshalling.
$ctx = $this->getContext();
$access = $ctx->getStreamAccess();
// Marshall the $array.
$args = new PhpArgumentCollection();
foreach ($array as $a) {
$args[] = new PhpArgument($a);
}
try {
$arrayVarName = $ctx->generateVariableName($array);
$access->writeVariable($arrayVarName);
$access->writeEquals($ctx->mustFormatOutput());
$access->writeFunctionCall('array', $args);
$access->writeSemicolon($ctx->mustFormatOutput());
// Marshall the Coords object.
$coordsArgs = new PhpArgumentCollection(array(new PhpArgument($coords->getShape()), new PhpArgument(new PhpVariable($arrayVarName))));
$varName = $ctx->generateVariableName($coords);
$access->writeVariable($varName);
$access->writeEquals($ctx->mustFormatOutput());
$access->writeInstantiation(get_class($coords), $coordsArgs);
$access->writeSemicolon($ctx->mustFormatOutput());
$ctx->pushOnVariableStack($varName);
} catch (StreamAccessException $e) {
$msg = "An error occured while marshalling a Coords object into the PHP source code stream.";
throw new PhpMarshallingException($msg, PhpMarshallingException::STREAM, $e);
}
} | [
"protected",
"function",
"marshallCoords",
"(",
")",
"{",
"// Retrieve the coordinates array.",
"$",
"coords",
"=",
"$",
"this",
"->",
"getToMarshall",
"(",
")",
";",
"$",
"array",
"=",
"$",
"coords",
"->",
"getArrayCopy",
"(",
")",
";",
"// Retrieve the shape.",
"$",
"shape",
"=",
"$",
"coords",
"->",
"getShape",
"(",
")",
";",
"// -- Actual marshalling.",
"$",
"ctx",
"=",
"$",
"this",
"->",
"getContext",
"(",
")",
";",
"$",
"access",
"=",
"$",
"ctx",
"->",
"getStreamAccess",
"(",
")",
";",
"// Marshall the $array.",
"$",
"args",
"=",
"new",
"PhpArgumentCollection",
"(",
")",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"a",
")",
"{",
"$",
"args",
"[",
"]",
"=",
"new",
"PhpArgument",
"(",
"$",
"a",
")",
";",
"}",
"try",
"{",
"$",
"arrayVarName",
"=",
"$",
"ctx",
"->",
"generateVariableName",
"(",
"$",
"array",
")",
";",
"$",
"access",
"->",
"writeVariable",
"(",
"$",
"arrayVarName",
")",
";",
"$",
"access",
"->",
"writeEquals",
"(",
"$",
"ctx",
"->",
"mustFormatOutput",
"(",
")",
")",
";",
"$",
"access",
"->",
"writeFunctionCall",
"(",
"'array'",
",",
"$",
"args",
")",
";",
"$",
"access",
"->",
"writeSemicolon",
"(",
"$",
"ctx",
"->",
"mustFormatOutput",
"(",
")",
")",
";",
"// Marshall the Coords object.",
"$",
"coordsArgs",
"=",
"new",
"PhpArgumentCollection",
"(",
"array",
"(",
"new",
"PhpArgument",
"(",
"$",
"coords",
"->",
"getShape",
"(",
")",
")",
",",
"new",
"PhpArgument",
"(",
"new",
"PhpVariable",
"(",
"$",
"arrayVarName",
")",
")",
")",
")",
";",
"$",
"varName",
"=",
"$",
"ctx",
"->",
"generateVariableName",
"(",
"$",
"coords",
")",
";",
"$",
"access",
"->",
"writeVariable",
"(",
"$",
"varName",
")",
";",
"$",
"access",
"->",
"writeEquals",
"(",
"$",
"ctx",
"->",
"mustFormatOutput",
"(",
")",
")",
";",
"$",
"access",
"->",
"writeInstantiation",
"(",
"get_class",
"(",
"$",
"coords",
")",
",",
"$",
"coordsArgs",
")",
";",
"$",
"access",
"->",
"writeSemicolon",
"(",
"$",
"ctx",
"->",
"mustFormatOutput",
"(",
")",
")",
";",
"$",
"ctx",
"->",
"pushOnVariableStack",
"(",
"$",
"varName",
")",
";",
"}",
"catch",
"(",
"StreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while marshalling a Coords object into the PHP source code stream.\"",
";",
"throw",
"new",
"PhpMarshallingException",
"(",
"$",
"msg",
",",
"PhpMarshallingException",
"::",
"STREAM",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Marshall a Coords QTI datatype object.
@throws \qtism\data\storage\php\marshalling\PhpMarshallingException | [
"Marshall",
"a",
"Coords",
"QTI",
"datatype",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/php/marshalling/PhpQtiDatatypeMarshaller.php#L101-L140 |
oat-sa/qti-sdk | src/qtism/data/storage/php/marshalling/PhpQtiDatatypeMarshaller.php | PhpQtiDatatypeMarshaller.marshallPair | protected function marshallPair()
{
$pair = $this->getToMarshall();
$ctx = $this->getContext();
$access = $ctx->getStreamAccess();
try {
$varName = $ctx->generateVariableName($pair);
$access->writeVariable($varName);
$access->writeEquals($ctx->mustFormatOutput());
$args = new PhpArgumentCollection(array(new PhpArgument($pair->getFirst()), new PhpArgument($pair->getSecond())));
$access->writeInstantiation(get_class($pair), $args);
$access->writeSemicolon($ctx->mustFormatOutput());
$ctx->pushOnVariableStack($varName);
} catch (StreamAccessException $e) {
$msg = "An error occured while marshalling a Pair/DirectedPair object into the PHP source code stream.";
throw new PhpMarshallingException($msg, PhpMarshallingException::STREAM, $e);
}
} | php | protected function marshallPair()
{
$pair = $this->getToMarshall();
$ctx = $this->getContext();
$access = $ctx->getStreamAccess();
try {
$varName = $ctx->generateVariableName($pair);
$access->writeVariable($varName);
$access->writeEquals($ctx->mustFormatOutput());
$args = new PhpArgumentCollection(array(new PhpArgument($pair->getFirst()), new PhpArgument($pair->getSecond())));
$access->writeInstantiation(get_class($pair), $args);
$access->writeSemicolon($ctx->mustFormatOutput());
$ctx->pushOnVariableStack($varName);
} catch (StreamAccessException $e) {
$msg = "An error occured while marshalling a Pair/DirectedPair object into the PHP source code stream.";
throw new PhpMarshallingException($msg, PhpMarshallingException::STREAM, $e);
}
} | [
"protected",
"function",
"marshallPair",
"(",
")",
"{",
"$",
"pair",
"=",
"$",
"this",
"->",
"getToMarshall",
"(",
")",
";",
"$",
"ctx",
"=",
"$",
"this",
"->",
"getContext",
"(",
")",
";",
"$",
"access",
"=",
"$",
"ctx",
"->",
"getStreamAccess",
"(",
")",
";",
"try",
"{",
"$",
"varName",
"=",
"$",
"ctx",
"->",
"generateVariableName",
"(",
"$",
"pair",
")",
";",
"$",
"access",
"->",
"writeVariable",
"(",
"$",
"varName",
")",
";",
"$",
"access",
"->",
"writeEquals",
"(",
"$",
"ctx",
"->",
"mustFormatOutput",
"(",
")",
")",
";",
"$",
"args",
"=",
"new",
"PhpArgumentCollection",
"(",
"array",
"(",
"new",
"PhpArgument",
"(",
"$",
"pair",
"->",
"getFirst",
"(",
")",
")",
",",
"new",
"PhpArgument",
"(",
"$",
"pair",
"->",
"getSecond",
"(",
")",
")",
")",
")",
";",
"$",
"access",
"->",
"writeInstantiation",
"(",
"get_class",
"(",
"$",
"pair",
")",
",",
"$",
"args",
")",
";",
"$",
"access",
"->",
"writeSemicolon",
"(",
"$",
"ctx",
"->",
"mustFormatOutput",
"(",
")",
")",
";",
"$",
"ctx",
"->",
"pushOnVariableStack",
"(",
"$",
"varName",
")",
";",
"}",
"catch",
"(",
"StreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while marshalling a Pair/DirectedPair object into the PHP source code stream.\"",
";",
"throw",
"new",
"PhpMarshallingException",
"(",
"$",
"msg",
",",
"PhpMarshallingException",
"::",
"STREAM",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Marshall a Pair QTI datatype object.
@throws \qtism\data\storage\php\marshalling\PhpMarshallingException | [
"Marshall",
"a",
"Pair",
"QTI",
"datatype",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/php/marshalling/PhpQtiDatatypeMarshaller.php#L147-L166 |
oat-sa/qti-sdk | src/qtism/data/storage/php/marshalling/PhpQtiDatatypeMarshaller.php | PhpQtiDatatypeMarshaller.marshallDuration | protected function marshallDuration()
{
$duration = $this->getToMarshall();
$ctx = $this->getContext();
$access = $ctx->getStreamAccess();
try {
$varName = $ctx->generateVariableName($duration);
$access->writeVariable($varName);
$access->writeEquals($ctx->mustFormatOutput());
$args = new PhpArgumentCollection(array(new PhpArgument($duration->__toString())));
$access->writeInstantiation(get_class($duration), $args);
$access->writeSemiColon($ctx->mustFormatOutput());
$ctx->pushOnVariableStack($varName);
} catch (StreamAccessException $e) {
$msg = "An error occured while marshalling a Duration object into the PHP source code stream.";
throw new PhpMarshallingException($msg, PhpMarshallingException::STREAM, $e);
}
} | php | protected function marshallDuration()
{
$duration = $this->getToMarshall();
$ctx = $this->getContext();
$access = $ctx->getStreamAccess();
try {
$varName = $ctx->generateVariableName($duration);
$access->writeVariable($varName);
$access->writeEquals($ctx->mustFormatOutput());
$args = new PhpArgumentCollection(array(new PhpArgument($duration->__toString())));
$access->writeInstantiation(get_class($duration), $args);
$access->writeSemiColon($ctx->mustFormatOutput());
$ctx->pushOnVariableStack($varName);
} catch (StreamAccessException $e) {
$msg = "An error occured while marshalling a Duration object into the PHP source code stream.";
throw new PhpMarshallingException($msg, PhpMarshallingException::STREAM, $e);
}
} | [
"protected",
"function",
"marshallDuration",
"(",
")",
"{",
"$",
"duration",
"=",
"$",
"this",
"->",
"getToMarshall",
"(",
")",
";",
"$",
"ctx",
"=",
"$",
"this",
"->",
"getContext",
"(",
")",
";",
"$",
"access",
"=",
"$",
"ctx",
"->",
"getStreamAccess",
"(",
")",
";",
"try",
"{",
"$",
"varName",
"=",
"$",
"ctx",
"->",
"generateVariableName",
"(",
"$",
"duration",
")",
";",
"$",
"access",
"->",
"writeVariable",
"(",
"$",
"varName",
")",
";",
"$",
"access",
"->",
"writeEquals",
"(",
"$",
"ctx",
"->",
"mustFormatOutput",
"(",
")",
")",
";",
"$",
"args",
"=",
"new",
"PhpArgumentCollection",
"(",
"array",
"(",
"new",
"PhpArgument",
"(",
"$",
"duration",
"->",
"__toString",
"(",
")",
")",
")",
")",
";",
"$",
"access",
"->",
"writeInstantiation",
"(",
"get_class",
"(",
"$",
"duration",
")",
",",
"$",
"args",
")",
";",
"$",
"access",
"->",
"writeSemiColon",
"(",
"$",
"ctx",
"->",
"mustFormatOutput",
"(",
")",
")",
";",
"$",
"ctx",
"->",
"pushOnVariableStack",
"(",
"$",
"varName",
")",
";",
"}",
"catch",
"(",
"StreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while marshalling a Duration object into the PHP source code stream.\"",
";",
"throw",
"new",
"PhpMarshallingException",
"(",
"$",
"msg",
",",
"PhpMarshallingException",
"::",
"STREAM",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Marshall a Duration QTI datatype object.
@throws \qtism\data\storage\php\marshalling\PhpMarshallingException | [
"Marshall",
"a",
"Duration",
"QTI",
"datatype",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/php/marshalling/PhpQtiDatatypeMarshaller.php#L173-L192 |
oat-sa/qti-sdk | src/qtism/data/storage/php/marshalling/PhpQtiDatatypeMarshaller.php | PhpQtiDatatypeMarshaller.marshallIdentifier | protected function marshallIdentifier()
{
$identifier = $this->getToMarshall();
$ctx = $this->getContext();
$access = $ctx->getStreamAccess();
try {
$varName = $ctx->generateVariableName($identifier);
$access->writeVariable($varName);
$access->writeEquals($ctx->mustFormatOutput());
$args = new PhpArgumentCollection(array(new PhpArgument($identifier->getValue())));
$access->writeInstantiation(get_class($identifier), $args);
$access->writeSemicolon($ctx->mustFormatOutput());
$ctx->pushOnVariableStack($varName);
} catch (StreamAccessException $e) {
$msg = "An error occured while marshalling an Identifier object into the PHP source code stream.";
throw new PhpMarshallingException($msg, PhpMarshallingException::STREAM, $e);
}
} | php | protected function marshallIdentifier()
{
$identifier = $this->getToMarshall();
$ctx = $this->getContext();
$access = $ctx->getStreamAccess();
try {
$varName = $ctx->generateVariableName($identifier);
$access->writeVariable($varName);
$access->writeEquals($ctx->mustFormatOutput());
$args = new PhpArgumentCollection(array(new PhpArgument($identifier->getValue())));
$access->writeInstantiation(get_class($identifier), $args);
$access->writeSemicolon($ctx->mustFormatOutput());
$ctx->pushOnVariableStack($varName);
} catch (StreamAccessException $e) {
$msg = "An error occured while marshalling an Identifier object into the PHP source code stream.";
throw new PhpMarshallingException($msg, PhpMarshallingException::STREAM, $e);
}
} | [
"protected",
"function",
"marshallIdentifier",
"(",
")",
"{",
"$",
"identifier",
"=",
"$",
"this",
"->",
"getToMarshall",
"(",
")",
";",
"$",
"ctx",
"=",
"$",
"this",
"->",
"getContext",
"(",
")",
";",
"$",
"access",
"=",
"$",
"ctx",
"->",
"getStreamAccess",
"(",
")",
";",
"try",
"{",
"$",
"varName",
"=",
"$",
"ctx",
"->",
"generateVariableName",
"(",
"$",
"identifier",
")",
";",
"$",
"access",
"->",
"writeVariable",
"(",
"$",
"varName",
")",
";",
"$",
"access",
"->",
"writeEquals",
"(",
"$",
"ctx",
"->",
"mustFormatOutput",
"(",
")",
")",
";",
"$",
"args",
"=",
"new",
"PhpArgumentCollection",
"(",
"array",
"(",
"new",
"PhpArgument",
"(",
"$",
"identifier",
"->",
"getValue",
"(",
")",
")",
")",
")",
";",
"$",
"access",
"->",
"writeInstantiation",
"(",
"get_class",
"(",
"$",
"identifier",
")",
",",
"$",
"args",
")",
";",
"$",
"access",
"->",
"writeSemicolon",
"(",
"$",
"ctx",
"->",
"mustFormatOutput",
"(",
")",
")",
";",
"$",
"ctx",
"->",
"pushOnVariableStack",
"(",
"$",
"varName",
")",
";",
"}",
"catch",
"(",
"StreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while marshalling an Identifier object into the PHP source code stream.\"",
";",
"throw",
"new",
"PhpMarshallingException",
"(",
"$",
"msg",
",",
"PhpMarshallingException",
"::",
"STREAM",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Marshall an Identifier QTI datatype object.
@throws \qtism\data\storage\php\marshalling\PhpMarshallingException | [
"Marshall",
"an",
"Identifier",
"QTI",
"datatype",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/php/marshalling/PhpQtiDatatypeMarshaller.php#L199-L218 |
oat-sa/qti-sdk | src/qtism/data/storage/php/marshalling/PhpQtiDatatypeMarshaller.php | PhpQtiDatatypeMarshaller.marshallPoint | protected function marshallPoint()
{
$point = $this->getToMarshall();
$ctx = $this->getContext();
$access = $ctx->getStreamAccess();
try {
$varName = $ctx->generateVariableName($point);
$access->writeVariable($varName);
$access->writeEquals($ctx->mustFormatOutput());
$args = new PhpArgumentCollection(array(new PhpArgument($point->getX()), new PhpArgument($point->getY())));
$access->writeInstantiation(get_class($point), $args);
$access->writeSemicolon($ctx->mustFormatOutput());
$ctx->pushOnVariableStack($varName);
} catch (StreamAccessException $e) {
$msg = "An error occured while marshalling a Point object into the PHP source code stream.";
throw new PhpMarshallingException($msg, PhpMarshallingException::STREAM, $e);
}
} | php | protected function marshallPoint()
{
$point = $this->getToMarshall();
$ctx = $this->getContext();
$access = $ctx->getStreamAccess();
try {
$varName = $ctx->generateVariableName($point);
$access->writeVariable($varName);
$access->writeEquals($ctx->mustFormatOutput());
$args = new PhpArgumentCollection(array(new PhpArgument($point->getX()), new PhpArgument($point->getY())));
$access->writeInstantiation(get_class($point), $args);
$access->writeSemicolon($ctx->mustFormatOutput());
$ctx->pushOnVariableStack($varName);
} catch (StreamAccessException $e) {
$msg = "An error occured while marshalling a Point object into the PHP source code stream.";
throw new PhpMarshallingException($msg, PhpMarshallingException::STREAM, $e);
}
} | [
"protected",
"function",
"marshallPoint",
"(",
")",
"{",
"$",
"point",
"=",
"$",
"this",
"->",
"getToMarshall",
"(",
")",
";",
"$",
"ctx",
"=",
"$",
"this",
"->",
"getContext",
"(",
")",
";",
"$",
"access",
"=",
"$",
"ctx",
"->",
"getStreamAccess",
"(",
")",
";",
"try",
"{",
"$",
"varName",
"=",
"$",
"ctx",
"->",
"generateVariableName",
"(",
"$",
"point",
")",
";",
"$",
"access",
"->",
"writeVariable",
"(",
"$",
"varName",
")",
";",
"$",
"access",
"->",
"writeEquals",
"(",
"$",
"ctx",
"->",
"mustFormatOutput",
"(",
")",
")",
";",
"$",
"args",
"=",
"new",
"PhpArgumentCollection",
"(",
"array",
"(",
"new",
"PhpArgument",
"(",
"$",
"point",
"->",
"getX",
"(",
")",
")",
",",
"new",
"PhpArgument",
"(",
"$",
"point",
"->",
"getY",
"(",
")",
")",
")",
")",
";",
"$",
"access",
"->",
"writeInstantiation",
"(",
"get_class",
"(",
"$",
"point",
")",
",",
"$",
"args",
")",
";",
"$",
"access",
"->",
"writeSemicolon",
"(",
"$",
"ctx",
"->",
"mustFormatOutput",
"(",
")",
")",
";",
"$",
"ctx",
"->",
"pushOnVariableStack",
"(",
"$",
"varName",
")",
";",
"}",
"catch",
"(",
"StreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while marshalling a Point object into the PHP source code stream.\"",
";",
"throw",
"new",
"PhpMarshallingException",
"(",
"$",
"msg",
",",
"PhpMarshallingException",
"::",
"STREAM",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Marshall a Point QTI datatype object.
@throws \qtism\data\storage\php\marshalling\PhpMarshallingException | [
"Marshall",
"a",
"Point",
"QTI",
"datatype",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/php/marshalling/PhpQtiDatatypeMarshaller.php#L225-L244 |
oat-sa/qti-sdk | src/qtism/data/rules/Selection.php | Selection.setSelect | public function setSelect($select)
{
if (is_int($select)) {
$this->select = $select;
} else {
$msg = "Select must be an integer, '" . gettype($select) . "' given.";
}
} | php | public function setSelect($select)
{
if (is_int($select)) {
$this->select = $select;
} else {
$msg = "Select must be an integer, '" . gettype($select) . "' given.";
}
} | [
"public",
"function",
"setSelect",
"(",
"$",
"select",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"select",
")",
")",
"{",
"$",
"this",
"->",
"select",
"=",
"$",
"select",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"Select must be an integer, '\"",
".",
"gettype",
"(",
"$",
"select",
")",
".",
"\"' given.\"",
";",
"}",
"}"
] | Set the number of child elements to be selected.
@param integer $select An integer.
@throws \InvalidArgumentException If $select is not an integer. | [
"Set",
"the",
"number",
"of",
"child",
"elements",
"to",
"be",
"selected",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/rules/Selection.php#L104-L111 |
oat-sa/qti-sdk | src/qtism/data/rules/Selection.php | Selection.setWithReplacement | public function setWithReplacement($withReplacement)
{
if (is_bool($withReplacement)) {
$this->withReplacement = $withReplacement;
} else {
$msg = "WithReplacement must be a boolean, '" . gettype($withReplacement) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setWithReplacement($withReplacement)
{
if (is_bool($withReplacement)) {
$this->withReplacement = $withReplacement;
} else {
$msg = "WithReplacement must be a boolean, '" . gettype($withReplacement) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setWithReplacement",
"(",
"$",
"withReplacement",
")",
"{",
"if",
"(",
"is_bool",
"(",
"$",
"withReplacement",
")",
")",
"{",
"$",
"this",
"->",
"withReplacement",
"=",
"$",
"withReplacement",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"WithReplacement must be a boolean, '\"",
".",
"gettype",
"(",
"$",
"withReplacement",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set if the selection of items must be with or without replacements.
@param boolean $withReplacement true if it must be with replacements, false otherwise.
@throws \InvalidArgumentException If $withReplacement is not a boolean. | [
"Set",
"if",
"the",
"selection",
"of",
"items",
"must",
"be",
"with",
"or",
"without",
"replacements",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/rules/Selection.php#L129-L137 |
oat-sa/qti-sdk | src/qtism/data/rules/Selection.php | Selection.setXmlString | public function setXmlString($xmlString)
{
$this->xmlString = $xmlString;
if ($this->externalComponent !== null) {
$this->getExternalComponent()->setXmlString($xmlString);
}
} | php | public function setXmlString($xmlString)
{
$this->xmlString = $xmlString;
if ($this->externalComponent !== null) {
$this->getExternalComponent()->setXmlString($xmlString);
}
} | [
"public",
"function",
"setXmlString",
"(",
"$",
"xmlString",
")",
"{",
"$",
"this",
"->",
"xmlString",
"=",
"$",
"xmlString",
";",
"if",
"(",
"$",
"this",
"->",
"externalComponent",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"getExternalComponent",
"(",
")",
"->",
"setXmlString",
"(",
"$",
"xmlString",
")",
";",
"}",
"}"
] | Set the xml string content of the selection itself and its content.
@param string $xmlString | [
"Set",
"the",
"xml",
"string",
"content",
"of",
"the",
"selection",
"itself",
"and",
"its",
"content",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/rules/Selection.php#L144-L151 |
oat-sa/qti-sdk | src/qtism/runtime/rendering/qtipl/rules/RuleQtiPLRenderer.php | RuleQtiPLRenderer.render | public function render($something)
{
$renderer = new QtiPLRenderer($this->getCRO());
return $something->getQtiClassName() . $renderer->writeChildElement($something->getExpression());
} | php | public function render($something)
{
$renderer = new QtiPLRenderer($this->getCRO());
return $something->getQtiClassName() . $renderer->writeChildElement($something->getExpression());
} | [
"public",
"function",
"render",
"(",
"$",
"something",
")",
"{",
"$",
"renderer",
"=",
"new",
"QtiPLRenderer",
"(",
"$",
"this",
"->",
"getCRO",
"(",
")",
")",
";",
"return",
"$",
"something",
"->",
"getQtiClassName",
"(",
")",
".",
"$",
"renderer",
"->",
"writeChildElement",
"(",
"$",
"something",
"->",
"getExpression",
"(",
")",
")",
";",
"}"
] | Render a QtiComponent object into another constitution.
@param mixed $something Something to render into another consitution.
@return mixed The rendered component into another constitution.
@throws \qtism\runtime\rendering\RenderingException If something goes wrong while rendering the component. | [
"Render",
"a",
"QtiComponent",
"object",
"into",
"another",
"constitution",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/qtipl/rules/RuleQtiPLRenderer.php#L46-L50 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/PreConditionMarshaller.php | PreConditionMarshaller.marshall | protected function marshall(QtiComponent $component)
{
$element = static::getDOMCradle()->createElement($component->getQtiClassName());
$marshaller = $this->getMarshallerFactory()->createMarshaller($component->getExpression());
$element->appendChild($marshaller->marshall($component->getExpression()));
return $element;
} | php | protected function marshall(QtiComponent $component)
{
$element = static::getDOMCradle()->createElement($component->getQtiClassName());
$marshaller = $this->getMarshallerFactory()->createMarshaller($component->getExpression());
$element->appendChild($marshaller->marshall($component->getExpression()));
return $element;
} | [
"protected",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"$",
"element",
"=",
"static",
"::",
"getDOMCradle",
"(",
")",
"->",
"createElement",
"(",
"$",
"component",
"->",
"getQtiClassName",
"(",
")",
")",
";",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"component",
"->",
"getExpression",
"(",
")",
")",
";",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"marshaller",
"->",
"marshall",
"(",
"$",
"component",
"->",
"getExpression",
"(",
")",
")",
")",
";",
"return",
"$",
"element",
";",
"}"
] | Marshall a PreCondition object into a DOMElement object.
@param \qtism\data\QtiComponent $component A PreCondition object.
@return \DOMElement The according DOMElement object. | [
"Marshall",
"a",
"PreCondition",
"object",
"into",
"a",
"DOMElement",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/PreConditionMarshaller.php#L43-L51 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/PreConditionMarshaller.php | PreConditionMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
$expressionElt = self::getFirstChildElement($element);
if ($expressionElt !== false) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($expressionElt);
$object = new PreCondition($marshaller->unmarshall($expressionElt));
return $object;
} else {
$msg = "The mandatory 'expression' child element is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} | php | protected function unmarshall(DOMElement $element)
{
$expressionElt = self::getFirstChildElement($element);
if ($expressionElt !== false) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($expressionElt);
$object = new PreCondition($marshaller->unmarshall($expressionElt));
return $object;
} else {
$msg = "The mandatory 'expression' child element is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"$",
"expressionElt",
"=",
"self",
"::",
"getFirstChildElement",
"(",
"$",
"element",
")",
";",
"if",
"(",
"$",
"expressionElt",
"!==",
"false",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"expressionElt",
")",
";",
"$",
"object",
"=",
"new",
"PreCondition",
"(",
"$",
"marshaller",
"->",
"unmarshall",
"(",
"$",
"expressionElt",
")",
")",
";",
"return",
"$",
"object",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory 'expression' child element is missing from element '\"",
".",
"$",
"element",
"->",
"localName",
".",
"\"'.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}"
] | Unmarshall a DOMElement object corresponding to a QTI preCondition element.
@param \DOMElement $element A DOMElement object.
@return \qtism\data\QtiComponent A Precondition object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException If $element does not contain any QTI expression element. | [
"Unmarshall",
"a",
"DOMElement",
"object",
"corresponding",
"to",
"a",
"QTI",
"preCondition",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/PreConditionMarshaller.php#L60-L73 |
oat-sa/qti-sdk | src/qtism/data/processing/ResponseProcessing.php | ResponseProcessing.setTemplate | public function setTemplate($template)
{
if (Format::isUri($template) === true || (gettype($template) === 'string' && empty($template) === true)) {
$this->template = $template;
} else {
$msg = "The given template '${template}' is not a valid URI.";
throw new InvalidArgumentException($msg);
}
} | php | public function setTemplate($template)
{
if (Format::isUri($template) === true || (gettype($template) === 'string' && empty($template) === true)) {
$this->template = $template;
} else {
$msg = "The given template '${template}' is not a valid URI.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setTemplate",
"(",
"$",
"template",
")",
"{",
"if",
"(",
"Format",
"::",
"isUri",
"(",
"$",
"template",
")",
"===",
"true",
"||",
"(",
"gettype",
"(",
"$",
"template",
")",
"===",
"'string'",
"&&",
"empty",
"(",
"$",
"template",
")",
"===",
"true",
")",
")",
"{",
"$",
"this",
"->",
"template",
"=",
"$",
"template",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The given template '${template}' is not a valid URI.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the optional response processing template. An empty string ('') indicates
there is no template description.
@param string $template The URI of the template.
@throws \InvalidArgumentException If $template is not a valid URI nor an empty string. | [
"Set",
"the",
"optional",
"response",
"processing",
"template",
".",
"An",
"empty",
"string",
"(",
")",
"indicates",
"there",
"is",
"no",
"template",
"description",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/processing/ResponseProcessing.php#L145-L153 |
oat-sa/qti-sdk | src/qtism/data/processing/ResponseProcessing.php | ResponseProcessing.setTemplateLocation | public function setTemplateLocation($templateLocation)
{
if (Format::isUri($templateLocation) === true || (gettype($templateLocation) === 'string' && empty($templateLocation) === true)) {
$this->templateLocation = $templateLocation;
} else {
$msg = "The given templateLocation '${templateLocation}' is not a valid URI.";
throw new InvalidArgumentException($msg);
}
} | php | public function setTemplateLocation($templateLocation)
{
if (Format::isUri($templateLocation) === true || (gettype($templateLocation) === 'string' && empty($templateLocation) === true)) {
$this->templateLocation = $templateLocation;
} else {
$msg = "The given templateLocation '${templateLocation}' is not a valid URI.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setTemplateLocation",
"(",
"$",
"templateLocation",
")",
"{",
"if",
"(",
"Format",
"::",
"isUri",
"(",
"$",
"templateLocation",
")",
"===",
"true",
"||",
"(",
"gettype",
"(",
"$",
"templateLocation",
")",
"===",
"'string'",
"&&",
"empty",
"(",
"$",
"templateLocation",
")",
"===",
"true",
")",
")",
"{",
"$",
"this",
"->",
"templateLocation",
"=",
"$",
"templateLocation",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The given templateLocation '${templateLocation}' is not a valid URI.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the optional response processing template location. An empty string ('') indicates
there is no template location description.
@param string $templateLocaton The URI of the template location.
@throws \InvalidArgumentException If $templateLocation is not a valid URI nor an empty string. | [
"Set",
"the",
"optional",
"response",
"processing",
"template",
"location",
".",
"An",
"empty",
"string",
"(",
")",
"indicates",
"there",
"is",
"no",
"template",
"location",
"description",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/processing/ResponseProcessing.php#L183-L191 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/MatchTableMarshaller.php | MatchTableMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
$matchTableEntryElements = $element->getElementsByTagName('matchTableEntry');
if ($matchTableEntryElements->length > 0) {
$matchTableEntries = new MatchTableEntryCollection();
for ($i = 0; $i < $matchTableEntryElements->length; $i++) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($matchTableEntryElements->item($i), array($this->getBaseType()));
$matchTableEntries[] = $marshaller->unmarshall($matchTableEntryElements->item($i));
}
$object = new MatchTable($matchTableEntries);
if (($defaultValue = $this->getDOMElementAttributeAs($element, 'defaultValue')) !== null) {
try {
$defaultValue = Utils::stringToDatatype($defaultValue, $this->getBaseType());
$object->setDefaultValue($defaultValue);
} catch (InvalidArgumentException $e) {
$strType = BaseType::getNameByConstant($this->getBaseType());
$msg = "Unable to transform '$defaultValue' in a ${strType}.";
throw new UnmarshallingException($msg, $element, $e);
}
}
return $object;
} else {
$msg = "A QTI matchTable element must contain at least one matchTableEntry element.";
throw new UnmarshallingException($msg, $element);
}
} | php | protected function unmarshall(DOMElement $element)
{
$matchTableEntryElements = $element->getElementsByTagName('matchTableEntry');
if ($matchTableEntryElements->length > 0) {
$matchTableEntries = new MatchTableEntryCollection();
for ($i = 0; $i < $matchTableEntryElements->length; $i++) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($matchTableEntryElements->item($i), array($this->getBaseType()));
$matchTableEntries[] = $marshaller->unmarshall($matchTableEntryElements->item($i));
}
$object = new MatchTable($matchTableEntries);
if (($defaultValue = $this->getDOMElementAttributeAs($element, 'defaultValue')) !== null) {
try {
$defaultValue = Utils::stringToDatatype($defaultValue, $this->getBaseType());
$object->setDefaultValue($defaultValue);
} catch (InvalidArgumentException $e) {
$strType = BaseType::getNameByConstant($this->getBaseType());
$msg = "Unable to transform '$defaultValue' in a ${strType}.";
throw new UnmarshallingException($msg, $element, $e);
}
}
return $object;
} else {
$msg = "A QTI matchTable element must contain at least one matchTableEntry element.";
throw new UnmarshallingException($msg, $element);
}
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"$",
"matchTableEntryElements",
"=",
"$",
"element",
"->",
"getElementsByTagName",
"(",
"'matchTableEntry'",
")",
";",
"if",
"(",
"$",
"matchTableEntryElements",
"->",
"length",
">",
"0",
")",
"{",
"$",
"matchTableEntries",
"=",
"new",
"MatchTableEntryCollection",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"matchTableEntryElements",
"->",
"length",
";",
"$",
"i",
"++",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"matchTableEntryElements",
"->",
"item",
"(",
"$",
"i",
")",
",",
"array",
"(",
"$",
"this",
"->",
"getBaseType",
"(",
")",
")",
")",
";",
"$",
"matchTableEntries",
"[",
"]",
"=",
"$",
"marshaller",
"->",
"unmarshall",
"(",
"$",
"matchTableEntryElements",
"->",
"item",
"(",
"$",
"i",
")",
")",
";",
"}",
"$",
"object",
"=",
"new",
"MatchTable",
"(",
"$",
"matchTableEntries",
")",
";",
"if",
"(",
"(",
"$",
"defaultValue",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'defaultValue'",
")",
")",
"!==",
"null",
")",
"{",
"try",
"{",
"$",
"defaultValue",
"=",
"Utils",
"::",
"stringToDatatype",
"(",
"$",
"defaultValue",
",",
"$",
"this",
"->",
"getBaseType",
"(",
")",
")",
";",
"$",
"object",
"->",
"setDefaultValue",
"(",
"$",
"defaultValue",
")",
";",
"}",
"catch",
"(",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"$",
"strType",
"=",
"BaseType",
"::",
"getNameByConstant",
"(",
"$",
"this",
"->",
"getBaseType",
"(",
")",
")",
";",
"$",
"msg",
"=",
"\"Unable to transform '$defaultValue' in a ${strType}.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
",",
"$",
"e",
")",
";",
"}",
"}",
"return",
"$",
"object",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"A QTI matchTable element must contain at least one matchTableEntry element.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}"
] | Unmarshall a DOMElement object corresponding to a QTI MatchTable element.
@param \DOMElement $element A DOMElement object.
@return \qtism\data\QtiComponent A MatchTable object.
@throws \UnmarshallingException If the $element to unmarshall has no matchTableEntry children. | [
"Unmarshall",
"a",
"DOMElement",
"object",
"corresponding",
"to",
"a",
"QTI",
"MatchTable",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/MatchTableMarshaller.php#L119-L148 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/ProductProcessor.php | ProductProcessor.process | public function process()
{
$operands = $this->getOperands();
if ($operands->containsNull() === true) {
return null;
} elseif ($operands->anythingButRecord() === false) {
$msg = "The Product operator only accepts operands with a single, multiple or ordered cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
} elseif ($operands->exclusivelyNumeric() === false) {
$msg = "The Product operator only accepts operands with integer or float baseType.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
}
$returnValue = 1;
foreach ($this->getOperands() as $operand) {
if ($operand instanceof QtiScalar) {
$returnValue *= $operand->getValue();
} else {
foreach ($operand as $val) {
$returnValue *= $val->getValue();
}
}
}
return (is_int($returnValue)) ? new QtiInteger($returnValue) : new QtiFloat($returnValue);
} | php | public function process()
{
$operands = $this->getOperands();
if ($operands->containsNull() === true) {
return null;
} elseif ($operands->anythingButRecord() === false) {
$msg = "The Product operator only accepts operands with a single, multiple or ordered cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
} elseif ($operands->exclusivelyNumeric() === false) {
$msg = "The Product operator only accepts operands with integer or float baseType.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
}
$returnValue = 1;
foreach ($this->getOperands() as $operand) {
if ($operand instanceof QtiScalar) {
$returnValue *= $operand->getValue();
} else {
foreach ($operand as $val) {
$returnValue *= $val->getValue();
}
}
}
return (is_int($returnValue)) ? new QtiInteger($returnValue) : new QtiFloat($returnValue);
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"operands",
"=",
"$",
"this",
"->",
"getOperands",
"(",
")",
";",
"if",
"(",
"$",
"operands",
"->",
"containsNull",
"(",
")",
"===",
"true",
")",
"{",
"return",
"null",
";",
"}",
"elseif",
"(",
"$",
"operands",
"->",
"anythingButRecord",
"(",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The Product operator only accepts operands with a single, multiple or ordered cardinality.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_CARDINALITY",
")",
";",
"}",
"elseif",
"(",
"$",
"operands",
"->",
"exclusivelyNumeric",
"(",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The Product operator only accepts operands with integer or float baseType.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_BASETYPE",
")",
";",
"}",
"$",
"returnValue",
"=",
"1",
";",
"foreach",
"(",
"$",
"this",
"->",
"getOperands",
"(",
")",
"as",
"$",
"operand",
")",
"{",
"if",
"(",
"$",
"operand",
"instanceof",
"QtiScalar",
")",
"{",
"$",
"returnValue",
"*=",
"$",
"operand",
"->",
"getValue",
"(",
")",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"operand",
"as",
"$",
"val",
")",
"{",
"$",
"returnValue",
"*=",
"$",
"val",
"->",
"getValue",
"(",
")",
";",
"}",
"}",
"}",
"return",
"(",
"is_int",
"(",
"$",
"returnValue",
")",
")",
"?",
"new",
"QtiInteger",
"(",
"$",
"returnValue",
")",
":",
"new",
"QtiFloat",
"(",
"$",
"returnValue",
")",
";",
"}"
] | Process the Product operator.
@throws \qtism\runtime\expressions\operators\OperatorProcessingException If invalid operands are given. | [
"Process",
"the",
"Product",
"operator",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/ProductProcessor.php#L53-L80 |
oat-sa/qti-sdk | src/qtism/runtime/processing/PrintedVariableEngine.php | PrintedVariableEngine.setComponent | public function setComponent(QtiComponent $printedVariable)
{
if ($printedVariable instanceof PrintedVariable) {
parent::setComponent($printedVariable);
} else {
$msg = "The PrintedVariableEngine class only accepts PrintedVariable objects to be executed.";
throw new InvalidArgumentException($msg);
}
} | php | public function setComponent(QtiComponent $printedVariable)
{
if ($printedVariable instanceof PrintedVariable) {
parent::setComponent($printedVariable);
} else {
$msg = "The PrintedVariableEngine class only accepts PrintedVariable objects to be executed.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setComponent",
"(",
"QtiComponent",
"$",
"printedVariable",
")",
"{",
"if",
"(",
"$",
"printedVariable",
"instanceof",
"PrintedVariable",
")",
"{",
"parent",
"::",
"setComponent",
"(",
"$",
"printedVariable",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The PrintedVariableEngine class only accepts PrintedVariable objects to be executed.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the PrintedVariable object to be executed by the engine depending
on the current context.
@param \qtism\data\QtiComponent $printedVariable A PrintedVariable object.
@throws \InvalidArgumentException If $printedVariable is not a PrintedVariable object. | [
"Set",
"the",
"PrintedVariable",
"object",
"to",
"be",
"executed",
"by",
"the",
"engine",
"depending",
"on",
"the",
"current",
"context",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/processing/PrintedVariableEngine.php#L92-L100 |
oat-sa/qti-sdk | src/qtism/runtime/processing/PrintedVariableEngine.php | PrintedVariableEngine.process | public function process()
{
$printedVariable = $this->getComponent();
$identifier = $printedVariable->getIdentifier();
$state = $this->getContext();
if ($state[$identifier] === null) {
return '';
}
$variable = $state->getVariable($identifier);
$value = $variable->getValue();
if ($value === null || $value === '' || ($value instanceof Container && $value->isNull() === true)) {
return '';
}
if ($variable->getCardinality() === Cardinality::SINGLE) {
return $this->processValue($variable->getBaseType(), $value);
} elseif ($variable->getCardinality() === Cardinality::ORDERED) {
$index = $printedVariable->getIndex();
// $index might be a variable reference.
if (is_string($index) === true && $state[$index] !== null) {
$refIndex = $state[$index];
if ($refIndex instanceof QtiInteger) {
// $index references an integer, that's correct.
$index = $refIndex->getValue();
} else {
// $index references something else than an integer.
// This is not correct. We consider then we have
// no index given.
$index = -1;
}
}
if (is_int($index) && $index >= 0 && isset($value[$index])) {
return $this->processValue($variable->getBaseType(), $value[$index]);
} else {
// Display all values.
return $this->processOrderedMultiple($variable);
}
} elseif ($variable->getCardinality() === Cardinality::MULTIPLE) {
// Display all values.
return $this->processOrderedMultiple($variable);
} else {
// This is a record.
$field = $printedVariable->getField();
if (empty($field) === false && isset($value[$field])) {
$v = $value[$field];
return $this->processValue(Utils::inferBaseType($v), $v);
} else {
// Display all values.
return $this->processRecord($variable);
}
}
} | php | public function process()
{
$printedVariable = $this->getComponent();
$identifier = $printedVariable->getIdentifier();
$state = $this->getContext();
if ($state[$identifier] === null) {
return '';
}
$variable = $state->getVariable($identifier);
$value = $variable->getValue();
if ($value === null || $value === '' || ($value instanceof Container && $value->isNull() === true)) {
return '';
}
if ($variable->getCardinality() === Cardinality::SINGLE) {
return $this->processValue($variable->getBaseType(), $value);
} elseif ($variable->getCardinality() === Cardinality::ORDERED) {
$index = $printedVariable->getIndex();
// $index might be a variable reference.
if (is_string($index) === true && $state[$index] !== null) {
$refIndex = $state[$index];
if ($refIndex instanceof QtiInteger) {
// $index references an integer, that's correct.
$index = $refIndex->getValue();
} else {
// $index references something else than an integer.
// This is not correct. We consider then we have
// no index given.
$index = -1;
}
}
if (is_int($index) && $index >= 0 && isset($value[$index])) {
return $this->processValue($variable->getBaseType(), $value[$index]);
} else {
// Display all values.
return $this->processOrderedMultiple($variable);
}
} elseif ($variable->getCardinality() === Cardinality::MULTIPLE) {
// Display all values.
return $this->processOrderedMultiple($variable);
} else {
// This is a record.
$field = $printedVariable->getField();
if (empty($field) === false && isset($value[$field])) {
$v = $value[$field];
return $this->processValue(Utils::inferBaseType($v), $v);
} else {
// Display all values.
return $this->processRecord($variable);
}
}
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"printedVariable",
"=",
"$",
"this",
"->",
"getComponent",
"(",
")",
";",
"$",
"identifier",
"=",
"$",
"printedVariable",
"->",
"getIdentifier",
"(",
")",
";",
"$",
"state",
"=",
"$",
"this",
"->",
"getContext",
"(",
")",
";",
"if",
"(",
"$",
"state",
"[",
"$",
"identifier",
"]",
"===",
"null",
")",
"{",
"return",
"''",
";",
"}",
"$",
"variable",
"=",
"$",
"state",
"->",
"getVariable",
"(",
"$",
"identifier",
")",
";",
"$",
"value",
"=",
"$",
"variable",
"->",
"getValue",
"(",
")",
";",
"if",
"(",
"$",
"value",
"===",
"null",
"||",
"$",
"value",
"===",
"''",
"||",
"(",
"$",
"value",
"instanceof",
"Container",
"&&",
"$",
"value",
"->",
"isNull",
"(",
")",
"===",
"true",
")",
")",
"{",
"return",
"''",
";",
"}",
"if",
"(",
"$",
"variable",
"->",
"getCardinality",
"(",
")",
"===",
"Cardinality",
"::",
"SINGLE",
")",
"{",
"return",
"$",
"this",
"->",
"processValue",
"(",
"$",
"variable",
"->",
"getBaseType",
"(",
")",
",",
"$",
"value",
")",
";",
"}",
"elseif",
"(",
"$",
"variable",
"->",
"getCardinality",
"(",
")",
"===",
"Cardinality",
"::",
"ORDERED",
")",
"{",
"$",
"index",
"=",
"$",
"printedVariable",
"->",
"getIndex",
"(",
")",
";",
"// $index might be a variable reference.",
"if",
"(",
"is_string",
"(",
"$",
"index",
")",
"===",
"true",
"&&",
"$",
"state",
"[",
"$",
"index",
"]",
"!==",
"null",
")",
"{",
"$",
"refIndex",
"=",
"$",
"state",
"[",
"$",
"index",
"]",
";",
"if",
"(",
"$",
"refIndex",
"instanceof",
"QtiInteger",
")",
"{",
"// $index references an integer, that's correct.",
"$",
"index",
"=",
"$",
"refIndex",
"->",
"getValue",
"(",
")",
";",
"}",
"else",
"{",
"// $index references something else than an integer.",
"// This is not correct. We consider then we have",
"// no index given.",
"$",
"index",
"=",
"-",
"1",
";",
"}",
"}",
"if",
"(",
"is_int",
"(",
"$",
"index",
")",
"&&",
"$",
"index",
">=",
"0",
"&&",
"isset",
"(",
"$",
"value",
"[",
"$",
"index",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"processValue",
"(",
"$",
"variable",
"->",
"getBaseType",
"(",
")",
",",
"$",
"value",
"[",
"$",
"index",
"]",
")",
";",
"}",
"else",
"{",
"// Display all values.",
"return",
"$",
"this",
"->",
"processOrderedMultiple",
"(",
"$",
"variable",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"variable",
"->",
"getCardinality",
"(",
")",
"===",
"Cardinality",
"::",
"MULTIPLE",
")",
"{",
"// Display all values.",
"return",
"$",
"this",
"->",
"processOrderedMultiple",
"(",
"$",
"variable",
")",
";",
"}",
"else",
"{",
"// This is a record.",
"$",
"field",
"=",
"$",
"printedVariable",
"->",
"getField",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"field",
")",
"===",
"false",
"&&",
"isset",
"(",
"$",
"value",
"[",
"$",
"field",
"]",
")",
")",
"{",
"$",
"v",
"=",
"$",
"value",
"[",
"$",
"field",
"]",
";",
"return",
"$",
"this",
"->",
"processValue",
"(",
"Utils",
"::",
"inferBaseType",
"(",
"$",
"v",
")",
",",
"$",
"v",
")",
";",
"}",
"else",
"{",
"// Display all values.",
"return",
"$",
"this",
"->",
"processRecord",
"(",
"$",
"variable",
")",
";",
"}",
"}",
"}"
] | Processes the encapsulated PrintedVariable object into a formatted
string, depending on the PrintedVariable object and the current context.
* If the value to format is an OrderedContainer, and no 'index' attribue value is given, the whole container is displayed.
* If no specific precision is given for a float display, the precision will be by default 6.
@return \qtism\data\content\TextRun A processed PrintedVariable as a TextRun object or the NULL value if the variable's value is NULL.
@throws \qtism\runtime\processing\PrintedVariableProcessingException If an error occurs while processing the PrintedVariable object into a TextRun object. | [
"Processes",
"the",
"encapsulated",
"PrintedVariable",
"object",
"into",
"a",
"formatted",
"string",
"depending",
"on",
"the",
"PrintedVariable",
"object",
"and",
"the",
"current",
"context",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/processing/PrintedVariableEngine.php#L112-L171 |
oat-sa/qti-sdk | src/qtism/runtime/processing/PrintedVariableEngine.php | PrintedVariableEngine.processOrderedMultiple | private function processOrderedMultiple(Variable $variable)
{
$processedValues = array();
$baseType = $variable->getBaseType();
foreach ($variable->getValue() as $v) {
$processedValues[] = $this->processValue($baseType, $v);
}
return implode($this->getComponent()->getDelimiter(), $processedValues);
} | php | private function processOrderedMultiple(Variable $variable)
{
$processedValues = array();
$baseType = $variable->getBaseType();
foreach ($variable->getValue() as $v) {
$processedValues[] = $this->processValue($baseType, $v);
}
return implode($this->getComponent()->getDelimiter(), $processedValues);
} | [
"private",
"function",
"processOrderedMultiple",
"(",
"Variable",
"$",
"variable",
")",
"{",
"$",
"processedValues",
"=",
"array",
"(",
")",
";",
"$",
"baseType",
"=",
"$",
"variable",
"->",
"getBaseType",
"(",
")",
";",
"foreach",
"(",
"$",
"variable",
"->",
"getValue",
"(",
")",
"as",
"$",
"v",
")",
"{",
"$",
"processedValues",
"[",
"]",
"=",
"$",
"this",
"->",
"processValue",
"(",
"$",
"baseType",
",",
"$",
"v",
")",
";",
"}",
"return",
"implode",
"(",
"$",
"this",
"->",
"getComponent",
"(",
")",
"->",
"getDelimiter",
"(",
")",
",",
"$",
"processedValues",
")",
";",
"}"
] | Processes all values of an ordered/multiple container and merge
them into a single string.
@param \qtism\runtime\common\Variable $variable The ordered/multiple container Variable to process.
@return string All the values delimited by printedVariable->delimiter. | [
"Processes",
"all",
"values",
"of",
"an",
"ordered",
"/",
"multiple",
"container",
"and",
"merge",
"them",
"into",
"a",
"single",
"string",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/processing/PrintedVariableEngine.php#L180-L190 |
oat-sa/qti-sdk | src/qtism/runtime/processing/PrintedVariableEngine.php | PrintedVariableEngine.processRecord | private function processRecord(Variable $variable)
{
$processedValues = array();
$baseType = $variable->getBaseType();
$mappingIndicator = $this->getComponent()->getMappingIndicator();
foreach ($variable->getValue() as $k => $v) {
$processedValues[] = "${k}${mappingIndicator}" . $this->processValue(Utils::inferBaseType($v), $v);
}
return implode($this->getComponent()->getDelimiter(), $processedValues);
} | php | private function processRecord(Variable $variable)
{
$processedValues = array();
$baseType = $variable->getBaseType();
$mappingIndicator = $this->getComponent()->getMappingIndicator();
foreach ($variable->getValue() as $k => $v) {
$processedValues[] = "${k}${mappingIndicator}" . $this->processValue(Utils::inferBaseType($v), $v);
}
return implode($this->getComponent()->getDelimiter(), $processedValues);
} | [
"private",
"function",
"processRecord",
"(",
"Variable",
"$",
"variable",
")",
"{",
"$",
"processedValues",
"=",
"array",
"(",
")",
";",
"$",
"baseType",
"=",
"$",
"variable",
"->",
"getBaseType",
"(",
")",
";",
"$",
"mappingIndicator",
"=",
"$",
"this",
"->",
"getComponent",
"(",
")",
"->",
"getMappingIndicator",
"(",
")",
";",
"foreach",
"(",
"$",
"variable",
"->",
"getValue",
"(",
")",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"processedValues",
"[",
"]",
"=",
"\"${k}${mappingIndicator}\"",
".",
"$",
"this",
"->",
"processValue",
"(",
"Utils",
"::",
"inferBaseType",
"(",
"$",
"v",
")",
",",
"$",
"v",
")",
";",
"}",
"return",
"implode",
"(",
"$",
"this",
"->",
"getComponent",
"(",
")",
"->",
"getDelimiter",
"(",
")",
",",
"$",
"processedValues",
")",
";",
"}"
] | Processes all values of a record container and merge them into
a single string.
@param \qtism\runtime\common\RecordContainer $variable The record to process.
@return string All the key/values delimited by printedVariable->delimiter. Indicator between keys and values is defined by printedVariable->mappingIndicator. | [
"Processes",
"all",
"values",
"of",
"a",
"record",
"container",
"and",
"merge",
"them",
"into",
"a",
"single",
"string",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/processing/PrintedVariableEngine.php#L199-L210 |
oat-sa/qti-sdk | src/qtism/runtime/processing/PrintedVariableEngine.php | PrintedVariableEngine.processValue | private function processValue($baseType, $value)
{
$printedVariable = $this->getComponent();
if ($value === null) {
return 'null';
}
if ($baseType === BaseType::INT_OR_IDENTIFIER) {
$baseType = (is_int($value) === true) ? BaseType::INTEGER : BaseType::STRING;
} elseif ($baseType === BaseType::IDENTIFIER || $baseType === BaseType::URI) {
$baseType = BaseType::STRING;
} elseif ($baseType === BaseType::FILE) {
// @todo support baseType::FILE in PrintedVariable.
$msg = "The 'file' BaseType is not supported yet by PrintedVariableEngine implementation.";
throw new PrintedVariableProcessingException($msg, $this, PrintedVariableProcessingException::RUNTIME_ERROR);
}
if ($baseType === BaseType::STRING) {
return $value->getValue();
} elseif ($baseType === BaseType::INTEGER || $baseType === BaseType::FLOAT) {
$format = $printedVariable->getFormat();
if (empty($format) === false) {
$format = Format::printfFormatIsoToPhp($format);
return sprintf($format, $value->getValue());
} elseif ($baseType === BaseType::FLOAT && $printedVariable->mustPowerForm() === true) {
return Format::scale10($value->getValue(), 'x');
} elseif ($baseType === BaseType::FLOAT) {
return sprintf('%e', $value->getValue());
} else {
// integer to string
return '' . $value->getValue();
}
} elseif ($baseType === BaseType::DURATION) {
return '' . $value->getSeconds(true);
} elseif ($baseType === BaseType::BOOLEAN) {
return ($value->getValue() === true) ? 'true' : 'false';
} elseif ($baseType === BaseType::POINT || $baseType === BaseType::PAIR || $baseType === BaseType::DIRECTED_PAIR) {
return $value->__toString();
} else {
$msg = "Unknown value type.";
throw new PrintedVariableProcessingException($msg, $this, PrintedVariableProcessingException::RUNTIME_ERROR);
}
} | php | private function processValue($baseType, $value)
{
$printedVariable = $this->getComponent();
if ($value === null) {
return 'null';
}
if ($baseType === BaseType::INT_OR_IDENTIFIER) {
$baseType = (is_int($value) === true) ? BaseType::INTEGER : BaseType::STRING;
} elseif ($baseType === BaseType::IDENTIFIER || $baseType === BaseType::URI) {
$baseType = BaseType::STRING;
} elseif ($baseType === BaseType::FILE) {
// @todo support baseType::FILE in PrintedVariable.
$msg = "The 'file' BaseType is not supported yet by PrintedVariableEngine implementation.";
throw new PrintedVariableProcessingException($msg, $this, PrintedVariableProcessingException::RUNTIME_ERROR);
}
if ($baseType === BaseType::STRING) {
return $value->getValue();
} elseif ($baseType === BaseType::INTEGER || $baseType === BaseType::FLOAT) {
$format = $printedVariable->getFormat();
if (empty($format) === false) {
$format = Format::printfFormatIsoToPhp($format);
return sprintf($format, $value->getValue());
} elseif ($baseType === BaseType::FLOAT && $printedVariable->mustPowerForm() === true) {
return Format::scale10($value->getValue(), 'x');
} elseif ($baseType === BaseType::FLOAT) {
return sprintf('%e', $value->getValue());
} else {
// integer to string
return '' . $value->getValue();
}
} elseif ($baseType === BaseType::DURATION) {
return '' . $value->getSeconds(true);
} elseif ($baseType === BaseType::BOOLEAN) {
return ($value->getValue() === true) ? 'true' : 'false';
} elseif ($baseType === BaseType::POINT || $baseType === BaseType::PAIR || $baseType === BaseType::DIRECTED_PAIR) {
return $value->__toString();
} else {
$msg = "Unknown value type.";
throw new PrintedVariableProcessingException($msg, $this, PrintedVariableProcessingException::RUNTIME_ERROR);
}
} | [
"private",
"function",
"processValue",
"(",
"$",
"baseType",
",",
"$",
"value",
")",
"{",
"$",
"printedVariable",
"=",
"$",
"this",
"->",
"getComponent",
"(",
")",
";",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"'null'",
";",
"}",
"if",
"(",
"$",
"baseType",
"===",
"BaseType",
"::",
"INT_OR_IDENTIFIER",
")",
"{",
"$",
"baseType",
"=",
"(",
"is_int",
"(",
"$",
"value",
")",
"===",
"true",
")",
"?",
"BaseType",
"::",
"INTEGER",
":",
"BaseType",
"::",
"STRING",
";",
"}",
"elseif",
"(",
"$",
"baseType",
"===",
"BaseType",
"::",
"IDENTIFIER",
"||",
"$",
"baseType",
"===",
"BaseType",
"::",
"URI",
")",
"{",
"$",
"baseType",
"=",
"BaseType",
"::",
"STRING",
";",
"}",
"elseif",
"(",
"$",
"baseType",
"===",
"BaseType",
"::",
"FILE",
")",
"{",
"// @todo support baseType::FILE in PrintedVariable.",
"$",
"msg",
"=",
"\"The 'file' BaseType is not supported yet by PrintedVariableEngine implementation.\"",
";",
"throw",
"new",
"PrintedVariableProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"PrintedVariableProcessingException",
"::",
"RUNTIME_ERROR",
")",
";",
"}",
"if",
"(",
"$",
"baseType",
"===",
"BaseType",
"::",
"STRING",
")",
"{",
"return",
"$",
"value",
"->",
"getValue",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"baseType",
"===",
"BaseType",
"::",
"INTEGER",
"||",
"$",
"baseType",
"===",
"BaseType",
"::",
"FLOAT",
")",
"{",
"$",
"format",
"=",
"$",
"printedVariable",
"->",
"getFormat",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"format",
")",
"===",
"false",
")",
"{",
"$",
"format",
"=",
"Format",
"::",
"printfFormatIsoToPhp",
"(",
"$",
"format",
")",
";",
"return",
"sprintf",
"(",
"$",
"format",
",",
"$",
"value",
"->",
"getValue",
"(",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"baseType",
"===",
"BaseType",
"::",
"FLOAT",
"&&",
"$",
"printedVariable",
"->",
"mustPowerForm",
"(",
")",
"===",
"true",
")",
"{",
"return",
"Format",
"::",
"scale10",
"(",
"$",
"value",
"->",
"getValue",
"(",
")",
",",
"'x'",
")",
";",
"}",
"elseif",
"(",
"$",
"baseType",
"===",
"BaseType",
"::",
"FLOAT",
")",
"{",
"return",
"sprintf",
"(",
"'%e'",
",",
"$",
"value",
"->",
"getValue",
"(",
")",
")",
";",
"}",
"else",
"{",
"// integer to string",
"return",
"''",
".",
"$",
"value",
"->",
"getValue",
"(",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"baseType",
"===",
"BaseType",
"::",
"DURATION",
")",
"{",
"return",
"''",
".",
"$",
"value",
"->",
"getSeconds",
"(",
"true",
")",
";",
"}",
"elseif",
"(",
"$",
"baseType",
"===",
"BaseType",
"::",
"BOOLEAN",
")",
"{",
"return",
"(",
"$",
"value",
"->",
"getValue",
"(",
")",
"===",
"true",
")",
"?",
"'true'",
":",
"'false'",
";",
"}",
"elseif",
"(",
"$",
"baseType",
"===",
"BaseType",
"::",
"POINT",
"||",
"$",
"baseType",
"===",
"BaseType",
"::",
"PAIR",
"||",
"$",
"baseType",
"===",
"BaseType",
"::",
"DIRECTED_PAIR",
")",
"{",
"return",
"$",
"value",
"->",
"__toString",
"(",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"Unknown value type.\"",
";",
"throw",
"new",
"PrintedVariableProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"PrintedVariableProcessingException",
"::",
"RUNTIME_ERROR",
")",
";",
"}",
"}"
] | Process a $value depending on its $baseType.
@param integer $baseType The baseType of the value to process.
@param mixed $value A QTI Runtime compliant value.
@throws \qtism\runtime\processing\PrintedVariableProcessingException If the baseType is unknown.
@return string | [
"Process",
"a",
"$value",
"depending",
"on",
"its",
"$baseType",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/processing/PrintedVariableEngine.php#L220-L265 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/TablePartMarshaller.php | TablePartMarshaller.marshall | protected function marshall(QtiComponent $component)
{
$element = self::getDOMCradle()->createElement($component->getQtiClassName());
foreach ($component->getContent() as $tr) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($tr);
$element->appendChild($marshaller->marshall($tr));
}
$this->fillElement($element, $component);
return $element;
} | php | protected function marshall(QtiComponent $component)
{
$element = self::getDOMCradle()->createElement($component->getQtiClassName());
foreach ($component->getContent() as $tr) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($tr);
$element->appendChild($marshaller->marshall($tr));
}
$this->fillElement($element, $component);
return $element;
} | [
"protected",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"$",
"element",
"=",
"self",
"::",
"getDOMCradle",
"(",
")",
"->",
"createElement",
"(",
"$",
"component",
"->",
"getQtiClassName",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"component",
"->",
"getContent",
"(",
")",
"as",
"$",
"tr",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"tr",
")",
";",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"marshaller",
"->",
"marshall",
"(",
"$",
"tr",
")",
")",
";",
"}",
"$",
"this",
"->",
"fillElement",
"(",
"$",
"element",
",",
"$",
"component",
")",
";",
"return",
"$",
"element",
";",
"}"
] | Marshall a Tbody/Thead/Tfoot object into a DOMElement object.
@param \qtism\data\QtiComponent $component A TBody/Thead/Tfoot object.
@return \DOMElement The according DOMElement object.
@throws \qtism\data\storage\xml\marshalling\MarshallingException | [
"Marshall",
"a",
"Tbody",
"/",
"Thead",
"/",
"Tfoot",
"object",
"into",
"a",
"DOMElement",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/TablePartMarshaller.php#L44-L56 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/TablePartMarshaller.php | TablePartMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
$trs = new TrCollection();
foreach ($this->getChildElementsByTagName($element, 'tr') as $trElt) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($trElt);
$trs[] = $marshaller->unmarshall($trElt);
}
if (count($trs) === 0) {
$msg = "A '" . $element->localName . "' element must contain at least one 'tr' element.";
throw new UnmarshallingException($msg, $element);
}
$class = "qtism\\data\\content\\xhtml\\tables\\" . ucfirst($element->localName);
$component = new $class($trs);
$this->fillBodyElement($component, $element);
return $component;
} | php | protected function unmarshall(DOMElement $element)
{
$trs = new TrCollection();
foreach ($this->getChildElementsByTagName($element, 'tr') as $trElt) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($trElt);
$trs[] = $marshaller->unmarshall($trElt);
}
if (count($trs) === 0) {
$msg = "A '" . $element->localName . "' element must contain at least one 'tr' element.";
throw new UnmarshallingException($msg, $element);
}
$class = "qtism\\data\\content\\xhtml\\tables\\" . ucfirst($element->localName);
$component = new $class($trs);
$this->fillBodyElement($component, $element);
return $component;
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"$",
"trs",
"=",
"new",
"TrCollection",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getChildElementsByTagName",
"(",
"$",
"element",
",",
"'tr'",
")",
"as",
"$",
"trElt",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"trElt",
")",
";",
"$",
"trs",
"[",
"]",
"=",
"$",
"marshaller",
"->",
"unmarshall",
"(",
"$",
"trElt",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"trs",
")",
"===",
"0",
")",
"{",
"$",
"msg",
"=",
"\"A '\"",
".",
"$",
"element",
"->",
"localName",
".",
"\"' element must contain at least one 'tr' element.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"$",
"class",
"=",
"\"qtism\\\\data\\\\content\\\\xhtml\\\\tables\\\\\"",
".",
"ucfirst",
"(",
"$",
"element",
"->",
"localName",
")",
";",
"$",
"component",
"=",
"new",
"$",
"class",
"(",
"$",
"trs",
")",
";",
"$",
"this",
"->",
"fillBodyElement",
"(",
"$",
"component",
",",
"$",
"element",
")",
";",
"return",
"$",
"component",
";",
"}"
] | Unmarshall a DOMElement object corresponding to an XHTML tbody/thead/tfoot element.
@param \DOMElement $element A DOMElement object.
@return \qtism\data\QtiComponent A Tbody/Thead/Tfoot object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException | [
"Unmarshall",
"a",
"DOMElement",
"object",
"corresponding",
"to",
"an",
"XHTML",
"tbody",
"/",
"thead",
"/",
"tfoot",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/TablePartMarshaller.php#L65-L85 |
oat-sa/qti-sdk | src/qtism/data/expressions/OutcomeMaximum.php | OutcomeMaximum.setOutcomeIdentifier | public function setOutcomeIdentifier($outcomeIdentifier)
{
if (Format::isIdentifier($outcomeIdentifier)) {
$this->outcomeIdentifier = $outcomeIdentifier;
} else {
$msg = "'${outcomeIdentifier}' is not a valid QTI Identifier.";
throw new InvalidArgumentException($msg);
}
} | php | public function setOutcomeIdentifier($outcomeIdentifier)
{
if (Format::isIdentifier($outcomeIdentifier)) {
$this->outcomeIdentifier = $outcomeIdentifier;
} else {
$msg = "'${outcomeIdentifier}' is not a valid QTI Identifier.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setOutcomeIdentifier",
"(",
"$",
"outcomeIdentifier",
")",
"{",
"if",
"(",
"Format",
"::",
"isIdentifier",
"(",
"$",
"outcomeIdentifier",
")",
")",
"{",
"$",
"this",
"->",
"outcomeIdentifier",
"=",
"$",
"outcomeIdentifier",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"'${outcomeIdentifier}' is not a valid QTI Identifier.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the outcome identifier.
@param string $outcomeIdentifier A QTI Identifier.
@throws \InvalidArgumentException If $outcomeIdentifier is not a valid QTI Identifier. | [
"Set",
"the",
"outcome",
"identifier",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/expressions/OutcomeMaximum.php#L83-L91 |
oat-sa/qti-sdk | src/qtism/data/expressions/OutcomeMaximum.php | OutcomeMaximum.setWeightIdentifier | public function setWeightIdentifier($weightIdentifier)
{
if (Format::isIdentifier($weightIdentifier) || $weightIdentifier == '') {
$this->weightIdentifier = $weightIdentifier;
} else {
$msg = "'${weightIdentifier}' is not a valid QTI Identifier.";
throw new InvalidArgumentException($msg);
}
} | php | public function setWeightIdentifier($weightIdentifier)
{
if (Format::isIdentifier($weightIdentifier) || $weightIdentifier == '') {
$this->weightIdentifier = $weightIdentifier;
} else {
$msg = "'${weightIdentifier}' is not a valid QTI Identifier.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setWeightIdentifier",
"(",
"$",
"weightIdentifier",
")",
"{",
"if",
"(",
"Format",
"::",
"isIdentifier",
"(",
"$",
"weightIdentifier",
")",
"||",
"$",
"weightIdentifier",
"==",
"''",
")",
"{",
"$",
"this",
"->",
"weightIdentifier",
"=",
"$",
"weightIdentifier",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"'${weightIdentifier}' is not a valid QTI Identifier.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the weight identifier. Can be '' (empty string) if no weight specified.
@param string $weightIdentifier A QTI Identifier or '' (empty string) if not specified.
@throws \InvalidArgumentException If $weightIdentifier is not a valid QTI Identifier nor '' (empty string). | [
"Set",
"the",
"weight",
"identifier",
".",
"Can",
"be",
"(",
"empty",
"string",
")",
"if",
"no",
"weight",
"specified",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/expressions/OutcomeMaximum.php#L109-L117 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/RubricBlockMarshaller.php | RubricBlockMarshaller.marshall | protected function marshall(QtiComponent $component)
{
$element = $this->createElement($component);
$arrayViews = array();
foreach ($component->getViews() as $view) {
$key = array_search($view, View::asArray());
// replace '_' by the space char.
$arrayViews[] = strtolower(str_replace("\xf2", "\x20", $key));
}
if (count($arrayViews) > 0) {
$this->setDOMElementAttribute($element, 'view', implode("\x20", $arrayViews));
}
if ($component->getUse() != '') {
$this->setDOMElementAttribute($element, 'use', $component->getUse());
}
if ($component->hasXmlBase() === true) {
static::setXmlBase($element, $component->getXmlBase());
}
foreach ($component->getContent() as $block) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($block);
$element->appendChild($marshaller->marshall($block));
}
foreach ($component->getStylesheets() as $stylesheet) {
$stylesheetMarshaller = $this->getMarshallerFactory()->createMarshaller($stylesheet);
$element->appendChild($stylesheetMarshaller->marshall($stylesheet));
}
$this->fillElement($element, $component);
return $element;
} | php | protected function marshall(QtiComponent $component)
{
$element = $this->createElement($component);
$arrayViews = array();
foreach ($component->getViews() as $view) {
$key = array_search($view, View::asArray());
// replace '_' by the space char.
$arrayViews[] = strtolower(str_replace("\xf2", "\x20", $key));
}
if (count($arrayViews) > 0) {
$this->setDOMElementAttribute($element, 'view', implode("\x20", $arrayViews));
}
if ($component->getUse() != '') {
$this->setDOMElementAttribute($element, 'use', $component->getUse());
}
if ($component->hasXmlBase() === true) {
static::setXmlBase($element, $component->getXmlBase());
}
foreach ($component->getContent() as $block) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($block);
$element->appendChild($marshaller->marshall($block));
}
foreach ($component->getStylesheets() as $stylesheet) {
$stylesheetMarshaller = $this->getMarshallerFactory()->createMarshaller($stylesheet);
$element->appendChild($stylesheetMarshaller->marshall($stylesheet));
}
$this->fillElement($element, $component);
return $element;
} | [
"protected",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"$",
"element",
"=",
"$",
"this",
"->",
"createElement",
"(",
"$",
"component",
")",
";",
"$",
"arrayViews",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"component",
"->",
"getViews",
"(",
")",
"as",
"$",
"view",
")",
"{",
"$",
"key",
"=",
"array_search",
"(",
"$",
"view",
",",
"View",
"::",
"asArray",
"(",
")",
")",
";",
"// replace '_' by the space char.",
"$",
"arrayViews",
"[",
"]",
"=",
"strtolower",
"(",
"str_replace",
"(",
"\"\\xf2\"",
",",
"\"\\x20\"",
",",
"$",
"key",
")",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"arrayViews",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'view'",
",",
"implode",
"(",
"\"\\x20\"",
",",
"$",
"arrayViews",
")",
")",
";",
"}",
"if",
"(",
"$",
"component",
"->",
"getUse",
"(",
")",
"!=",
"''",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'use'",
",",
"$",
"component",
"->",
"getUse",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"component",
"->",
"hasXmlBase",
"(",
")",
"===",
"true",
")",
"{",
"static",
"::",
"setXmlBase",
"(",
"$",
"element",
",",
"$",
"component",
"->",
"getXmlBase",
"(",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"component",
"->",
"getContent",
"(",
")",
"as",
"$",
"block",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"block",
")",
";",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"marshaller",
"->",
"marshall",
"(",
"$",
"block",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"component",
"->",
"getStylesheets",
"(",
")",
"as",
"$",
"stylesheet",
")",
"{",
"$",
"stylesheetMarshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"stylesheet",
")",
";",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"stylesheetMarshaller",
"->",
"marshall",
"(",
"$",
"stylesheet",
")",
")",
";",
"}",
"$",
"this",
"->",
"fillElement",
"(",
"$",
"element",
",",
"$",
"component",
")",
";",
"return",
"$",
"element",
";",
"}"
] | Marshall a RubricBlock object into a DOMElement object.
@param \qtism\data\QtiComponent $component A RubricBlock object.
@return \DOMElement The according DOMElement object. | [
"Marshall",
"a",
"RubricBlock",
"object",
"into",
"a",
"DOMElement",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/RubricBlockMarshaller.php#L51-L87 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/RubricBlockMarshaller.php | RubricBlockMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
// First we retrieve the mandatory views.
if (($value = $this->getDOMElementAttributeAs($element, 'view', 'string')) !== null) {
$viewsArray = explode("\x20", $value);
$viewsCollection = new ViewCollection();
$ref = View::asArray();
foreach ($viewsArray as $viewString) {
$key = strtoupper(str_replace("\xf2", "\x20", $viewString));
if (array_key_exists($key, $ref)) {
$viewsCollection[] = $ref[$key];
}
}
$object = new RubricBlock($viewsCollection);
if (($value = $this->getDOMElementAttributeAs($element, 'use', 'string')) !== null) {
$object->setUse($value);
}
if (($xmlBase = static::getXmlBase($element)) !== false) {
$object->setXmlBase($xmlBase);
}
$stylesheets = new StylesheetCollection();
$content = new FlowStaticCollection();
foreach ($this->getChildElementsByTagName($element, 'apipAccessibility', true, true) as $elt) {
if ($elt instanceof DOMText) {
$elt = self::getDOMCradle()->createElement('textRun', $elt->wholeText);
}
$marshaller = $this->getMarshallerFactory()->createMarshaller($elt);
$cpt = $marshaller->unmarshall($elt);
if ($cpt instanceof Stylesheet) {
$stylesheets[] = $cpt;
} elseif ($cpt instanceof FlowStatic && !in_array($cpt->getQtiClassName(), array('hottext', 'feedbackBlock', 'feedbackInline', 'rubricBlock', 'infoControl'))) {
$content[] = $cpt;
} else {
$msg = "The 'rubricBlock' cannot contain '" . $cpt->getQtiClassName() . "' elements.";
throw new UnmarshallingException($msg, $element);
}
}
$object->setStylesheets($stylesheets);
$object->setContent($content);
$this->fillBodyElement($object, $element);
return $object;
} else {
$msg = "The mandatory attribute 'views' is missing.";
throw new UnmarshallingException($msg, $element);
}
} | php | protected function unmarshall(DOMElement $element)
{
// First we retrieve the mandatory views.
if (($value = $this->getDOMElementAttributeAs($element, 'view', 'string')) !== null) {
$viewsArray = explode("\x20", $value);
$viewsCollection = new ViewCollection();
$ref = View::asArray();
foreach ($viewsArray as $viewString) {
$key = strtoupper(str_replace("\xf2", "\x20", $viewString));
if (array_key_exists($key, $ref)) {
$viewsCollection[] = $ref[$key];
}
}
$object = new RubricBlock($viewsCollection);
if (($value = $this->getDOMElementAttributeAs($element, 'use', 'string')) !== null) {
$object->setUse($value);
}
if (($xmlBase = static::getXmlBase($element)) !== false) {
$object->setXmlBase($xmlBase);
}
$stylesheets = new StylesheetCollection();
$content = new FlowStaticCollection();
foreach ($this->getChildElementsByTagName($element, 'apipAccessibility', true, true) as $elt) {
if ($elt instanceof DOMText) {
$elt = self::getDOMCradle()->createElement('textRun', $elt->wholeText);
}
$marshaller = $this->getMarshallerFactory()->createMarshaller($elt);
$cpt = $marshaller->unmarshall($elt);
if ($cpt instanceof Stylesheet) {
$stylesheets[] = $cpt;
} elseif ($cpt instanceof FlowStatic && !in_array($cpt->getQtiClassName(), array('hottext', 'feedbackBlock', 'feedbackInline', 'rubricBlock', 'infoControl'))) {
$content[] = $cpt;
} else {
$msg = "The 'rubricBlock' cannot contain '" . $cpt->getQtiClassName() . "' elements.";
throw new UnmarshallingException($msg, $element);
}
}
$object->setStylesheets($stylesheets);
$object->setContent($content);
$this->fillBodyElement($object, $element);
return $object;
} else {
$msg = "The mandatory attribute 'views' is missing.";
throw new UnmarshallingException($msg, $element);
}
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"// First we retrieve the mandatory views.",
"if",
"(",
"(",
"$",
"value",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'view'",
",",
"'string'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"viewsArray",
"=",
"explode",
"(",
"\"\\x20\"",
",",
"$",
"value",
")",
";",
"$",
"viewsCollection",
"=",
"new",
"ViewCollection",
"(",
")",
";",
"$",
"ref",
"=",
"View",
"::",
"asArray",
"(",
")",
";",
"foreach",
"(",
"$",
"viewsArray",
"as",
"$",
"viewString",
")",
"{",
"$",
"key",
"=",
"strtoupper",
"(",
"str_replace",
"(",
"\"\\xf2\"",
",",
"\"\\x20\"",
",",
"$",
"viewString",
")",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"ref",
")",
")",
"{",
"$",
"viewsCollection",
"[",
"]",
"=",
"$",
"ref",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"$",
"object",
"=",
"new",
"RubricBlock",
"(",
"$",
"viewsCollection",
")",
";",
"if",
"(",
"(",
"$",
"value",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'use'",
",",
"'string'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"object",
"->",
"setUse",
"(",
"$",
"value",
")",
";",
"}",
"if",
"(",
"(",
"$",
"xmlBase",
"=",
"static",
"::",
"getXmlBase",
"(",
"$",
"element",
")",
")",
"!==",
"false",
")",
"{",
"$",
"object",
"->",
"setXmlBase",
"(",
"$",
"xmlBase",
")",
";",
"}",
"$",
"stylesheets",
"=",
"new",
"StylesheetCollection",
"(",
")",
";",
"$",
"content",
"=",
"new",
"FlowStaticCollection",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getChildElementsByTagName",
"(",
"$",
"element",
",",
"'apipAccessibility'",
",",
"true",
",",
"true",
")",
"as",
"$",
"elt",
")",
"{",
"if",
"(",
"$",
"elt",
"instanceof",
"DOMText",
")",
"{",
"$",
"elt",
"=",
"self",
"::",
"getDOMCradle",
"(",
")",
"->",
"createElement",
"(",
"'textRun'",
",",
"$",
"elt",
"->",
"wholeText",
")",
";",
"}",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"elt",
")",
";",
"$",
"cpt",
"=",
"$",
"marshaller",
"->",
"unmarshall",
"(",
"$",
"elt",
")",
";",
"if",
"(",
"$",
"cpt",
"instanceof",
"Stylesheet",
")",
"{",
"$",
"stylesheets",
"[",
"]",
"=",
"$",
"cpt",
";",
"}",
"elseif",
"(",
"$",
"cpt",
"instanceof",
"FlowStatic",
"&&",
"!",
"in_array",
"(",
"$",
"cpt",
"->",
"getQtiClassName",
"(",
")",
",",
"array",
"(",
"'hottext'",
",",
"'feedbackBlock'",
",",
"'feedbackInline'",
",",
"'rubricBlock'",
",",
"'infoControl'",
")",
")",
")",
"{",
"$",
"content",
"[",
"]",
"=",
"$",
"cpt",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'rubricBlock' cannot contain '\"",
".",
"$",
"cpt",
"->",
"getQtiClassName",
"(",
")",
".",
"\"' elements.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}",
"$",
"object",
"->",
"setStylesheets",
"(",
"$",
"stylesheets",
")",
";",
"$",
"object",
"->",
"setContent",
"(",
"$",
"content",
")",
";",
"$",
"this",
"->",
"fillBodyElement",
"(",
"$",
"object",
",",
"$",
"element",
")",
";",
"return",
"$",
"object",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory attribute 'views' is missing.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}"
] | Unmarshall a DOMElement object corresponding to a QTI rubrickBlock element.
@param \DOMElement $element A DOMElement object.
@return \qtism\data\content\RubricBlock A RubricBlock object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException If the mandatory attribute 'href' is missing from $element. | [
"Unmarshall",
"a",
"DOMElement",
"object",
"corresponding",
"to",
"a",
"QTI",
"rubrickBlock",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/RubricBlockMarshaller.php#L96-L153 |
oat-sa/qti-sdk | src/qtism/data/storage/php/marshalling/PhpMarshallingContext.php | PhpMarshallingContext.pushOnVariableStack | public function pushOnVariableStack($values)
{
if (is_array($values) === false) {
$values = array($values);
}
foreach ($values as $value) {
if (is_string($value) === false) {
$msg = "The pushOnVariableStack method only accepts non-empty string values.";
throw new InvalidArgumentException($msg);
}
$this->getVariableStack()->push($value);
}
} | php | public function pushOnVariableStack($values)
{
if (is_array($values) === false) {
$values = array($values);
}
foreach ($values as $value) {
if (is_string($value) === false) {
$msg = "The pushOnVariableStack method only accepts non-empty string values.";
throw new InvalidArgumentException($msg);
}
$this->getVariableStack()->push($value);
}
} | [
"public",
"function",
"pushOnVariableStack",
"(",
"$",
"values",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"values",
")",
"===",
"false",
")",
"{",
"$",
"values",
"=",
"array",
"(",
"$",
"values",
")",
";",
"}",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The pushOnVariableStack method only accepts non-empty string values.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"$",
"this",
"->",
"getVariableStack",
"(",
")",
"->",
"push",
"(",
"$",
"value",
")",
";",
"}",
"}"
] | Push some value(s) on the variable names stack.
@param string|array $values A string or an array of strings to be pushed on the variable names stack.
@throws \InvalidArgumentException If $value or an item of $value is not a non-empty string. | [
"Push",
"some",
"value",
"(",
"s",
")",
"on",
"the",
"variable",
"names",
"stack",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/php/marshalling/PhpMarshallingContext.php#L201-L215 |
oat-sa/qti-sdk | src/qtism/data/storage/php/marshalling/PhpMarshallingContext.php | PhpMarshallingContext.popFromVariableStack | public function popFromVariableStack($quantity = 1)
{
$quantity = intval($quantity);
if ($quantity < 1) {
$msg = "The 'quantity' argument must be >= 1, '${quantity}' given.";
throw new InvalidArgumentException($msg);
}
$stack = $this->getVariableStack();
$stackCount = count($stack);
if ($stackCount < $quantity) {
$msg = "The number of elements in the variable names stack (${stackCount}) is lower than the requested quantity (${quantity}).";
throw new RuntimeException($msg);
}
$values = array();
for ($i = 0; $i < $quantity; $i++) {
$values[] = $stack->pop();
}
return array_reverse($values);
} | php | public function popFromVariableStack($quantity = 1)
{
$quantity = intval($quantity);
if ($quantity < 1) {
$msg = "The 'quantity' argument must be >= 1, '${quantity}' given.";
throw new InvalidArgumentException($msg);
}
$stack = $this->getVariableStack();
$stackCount = count($stack);
if ($stackCount < $quantity) {
$msg = "The number of elements in the variable names stack (${stackCount}) is lower than the requested quantity (${quantity}).";
throw new RuntimeException($msg);
}
$values = array();
for ($i = 0; $i < $quantity; $i++) {
$values[] = $stack->pop();
}
return array_reverse($values);
} | [
"public",
"function",
"popFromVariableStack",
"(",
"$",
"quantity",
"=",
"1",
")",
"{",
"$",
"quantity",
"=",
"intval",
"(",
"$",
"quantity",
")",
";",
"if",
"(",
"$",
"quantity",
"<",
"1",
")",
"{",
"$",
"msg",
"=",
"\"The 'quantity' argument must be >= 1, '${quantity}' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"$",
"stack",
"=",
"$",
"this",
"->",
"getVariableStack",
"(",
")",
";",
"$",
"stackCount",
"=",
"count",
"(",
"$",
"stack",
")",
";",
"if",
"(",
"$",
"stackCount",
"<",
"$",
"quantity",
")",
"{",
"$",
"msg",
"=",
"\"The number of elements in the variable names stack (${stackCount}) is lower than the requested quantity (${quantity}).\"",
";",
"throw",
"new",
"RuntimeException",
"(",
"$",
"msg",
")",
";",
"}",
"$",
"values",
"=",
"array",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"quantity",
";",
"$",
"i",
"++",
")",
"{",
"$",
"values",
"[",
"]",
"=",
"$",
"stack",
"->",
"pop",
"(",
")",
";",
"}",
"return",
"array_reverse",
"(",
"$",
"values",
")",
";",
"}"
] | Pop a given $quantity of values from the variable names stack.
@param integer $quantity
@return array An array of strings.
@throws \RuntimeException If the the quantity of elements in the stack before popping is less than $quantity.
@throws \InvalidArgumentException If $quantity < 1. | [
"Pop",
"a",
"given",
"$quantity",
"of",
"values",
"from",
"the",
"variable",
"names",
"stack",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/php/marshalling/PhpMarshallingContext.php#L225-L247 |
oat-sa/qti-sdk | src/qtism/data/storage/php/marshalling/PhpMarshallingContext.php | PhpMarshallingContext.generateVariableName | public function generateVariableName($value)
{
$occurence = 0;
if (is_object($value) === true) {
$counter = $this->getObjectCount();
$className = get_class($value);
if (isset($counter[$className]) === false) {
$occurence = 0;
$counter[$className] = $occurence;
} else {
$occurence = $counter[$className];
}
$counter[$className] += 1;
$this->setObjectCount($counter);
} else {
if (is_null($value) === true) {
$type = 'null';
} else {
$type = gettype($value);
}
$counter = $this->getDatatypeCount();
$occurence = $counter[$type];
$counter[$type] += 1;
$this->setDatatypeCount($counter);
}
return PhpMarshallingUtils::variableName($value, $occurence);
} | php | public function generateVariableName($value)
{
$occurence = 0;
if (is_object($value) === true) {
$counter = $this->getObjectCount();
$className = get_class($value);
if (isset($counter[$className]) === false) {
$occurence = 0;
$counter[$className] = $occurence;
} else {
$occurence = $counter[$className];
}
$counter[$className] += 1;
$this->setObjectCount($counter);
} else {
if (is_null($value) === true) {
$type = 'null';
} else {
$type = gettype($value);
}
$counter = $this->getDatatypeCount();
$occurence = $counter[$type];
$counter[$type] += 1;
$this->setDatatypeCount($counter);
}
return PhpMarshallingUtils::variableName($value, $occurence);
} | [
"public",
"function",
"generateVariableName",
"(",
"$",
"value",
")",
"{",
"$",
"occurence",
"=",
"0",
";",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
"===",
"true",
")",
"{",
"$",
"counter",
"=",
"$",
"this",
"->",
"getObjectCount",
"(",
")",
";",
"$",
"className",
"=",
"get_class",
"(",
"$",
"value",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"counter",
"[",
"$",
"className",
"]",
")",
"===",
"false",
")",
"{",
"$",
"occurence",
"=",
"0",
";",
"$",
"counter",
"[",
"$",
"className",
"]",
"=",
"$",
"occurence",
";",
"}",
"else",
"{",
"$",
"occurence",
"=",
"$",
"counter",
"[",
"$",
"className",
"]",
";",
"}",
"$",
"counter",
"[",
"$",
"className",
"]",
"+=",
"1",
";",
"$",
"this",
"->",
"setObjectCount",
"(",
"$",
"counter",
")",
";",
"}",
"else",
"{",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
"===",
"true",
")",
"{",
"$",
"type",
"=",
"'null'",
";",
"}",
"else",
"{",
"$",
"type",
"=",
"gettype",
"(",
"$",
"value",
")",
";",
"}",
"$",
"counter",
"=",
"$",
"this",
"->",
"getDatatypeCount",
"(",
")",
";",
"$",
"occurence",
"=",
"$",
"counter",
"[",
"$",
"type",
"]",
";",
"$",
"counter",
"[",
"$",
"type",
"]",
"+=",
"1",
";",
"$",
"this",
"->",
"setDatatypeCount",
"(",
"$",
"counter",
")",
";",
"}",
"return",
"PhpMarshallingUtils",
"::",
"variableName",
"(",
"$",
"value",
",",
"$",
"occurence",
")",
";",
"}"
] | Generates a suitable variable name to be used for a given value.
@param mixed $value A value.
@return string A variable name without the leading dollar sign ('$'). | [
"Generates",
"a",
"suitable",
"variable",
"name",
"to",
"be",
"used",
"for",
"a",
"given",
"value",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/php/marshalling/PhpMarshallingContext.php#L255-L287 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/ShufflingGroupMarshaller.php | ShufflingGroupMarshaller.marshall | protected function marshall(QtiComponent $component)
{
$element = static::getDOMCradle()->createElement($component->getQtiClassName());
$this->setDOMElementAttribute($element, 'identifiers', implode("\x20", $component->getIdentifiers()->getArrayCopy()));
$fixedIdentifiers = $component->getFixedIdentifiers();
if (count($fixedIdentifiers) > 0) {
$this->setDOMElementAttribute($element, 'fixedIdentifiers', implode("\x20", $component->getFixedIdentifiers()->getArrayCopy()));
}
return $element;
} | php | protected function marshall(QtiComponent $component)
{
$element = static::getDOMCradle()->createElement($component->getQtiClassName());
$this->setDOMElementAttribute($element, 'identifiers', implode("\x20", $component->getIdentifiers()->getArrayCopy()));
$fixedIdentifiers = $component->getFixedIdentifiers();
if (count($fixedIdentifiers) > 0) {
$this->setDOMElementAttribute($element, 'fixedIdentifiers', implode("\x20", $component->getFixedIdentifiers()->getArrayCopy()));
}
return $element;
} | [
"protected",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"$",
"element",
"=",
"static",
"::",
"getDOMCradle",
"(",
")",
"->",
"createElement",
"(",
"$",
"component",
"->",
"getQtiClassName",
"(",
")",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'identifiers'",
",",
"implode",
"(",
"\"\\x20\"",
",",
"$",
"component",
"->",
"getIdentifiers",
"(",
")",
"->",
"getArrayCopy",
"(",
")",
")",
")",
";",
"$",
"fixedIdentifiers",
"=",
"$",
"component",
"->",
"getFixedIdentifiers",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"fixedIdentifiers",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'fixedIdentifiers'",
",",
"implode",
"(",
"\"\\x20\"",
",",
"$",
"component",
"->",
"getFixedIdentifiers",
"(",
")",
"->",
"getArrayCopy",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"element",
";",
"}"
] | Marshall a ShufflingGroup object into a DOMElement object.
@param \qtism\data\QtiComponent $component A ShufflingGroup object.
@return \DOMElement The according DOMElement object. | [
"Marshall",
"a",
"ShufflingGroup",
"object",
"into",
"a",
"DOMElement",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/ShufflingGroupMarshaller.php#L44-L55 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/ShufflingGroupMarshaller.php | ShufflingGroupMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
if (($identifiers = $this->getDOMElementAttributeAs($element, 'identifiers')) !== null) {
$identifiers = explode("\x20", $identifiers);
$component = new ShufflingGroup(new IdentifierCollection($identifiers));
if (($fixedIdentifiers = $this->getDOMElementAttributeAs($element, 'fixedIdentifiers')) !== null) {
$fixedIdentifiers = explode("\x20", $fixedIdentifiers);
$component->setFixedIdentifiers(new IdentifierCollection($fixedIdentifiers));
}
return $component;
} else {
$msg = "The mandatory attribute 'identifiers' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} | php | protected function unmarshall(DOMElement $element)
{
if (($identifiers = $this->getDOMElementAttributeAs($element, 'identifiers')) !== null) {
$identifiers = explode("\x20", $identifiers);
$component = new ShufflingGroup(new IdentifierCollection($identifiers));
if (($fixedIdentifiers = $this->getDOMElementAttributeAs($element, 'fixedIdentifiers')) !== null) {
$fixedIdentifiers = explode("\x20", $fixedIdentifiers);
$component->setFixedIdentifiers(new IdentifierCollection($fixedIdentifiers));
}
return $component;
} else {
$msg = "The mandatory attribute 'identifiers' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"if",
"(",
"(",
"$",
"identifiers",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'identifiers'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"identifiers",
"=",
"explode",
"(",
"\"\\x20\"",
",",
"$",
"identifiers",
")",
";",
"$",
"component",
"=",
"new",
"ShufflingGroup",
"(",
"new",
"IdentifierCollection",
"(",
"$",
"identifiers",
")",
")",
";",
"if",
"(",
"(",
"$",
"fixedIdentifiers",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'fixedIdentifiers'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"fixedIdentifiers",
"=",
"explode",
"(",
"\"\\x20\"",
",",
"$",
"fixedIdentifiers",
")",
";",
"$",
"component",
"->",
"setFixedIdentifiers",
"(",
"new",
"IdentifierCollection",
"(",
"$",
"fixedIdentifiers",
")",
")",
";",
"}",
"return",
"$",
"component",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory attribute 'identifiers' is missing from element '\"",
".",
"$",
"element",
"->",
"localName",
".",
"\"'.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}"
] | Unmarshall a DOMElement object corresponding to a QTI ShufflingGroup element.
@param \DOMElement $element A DOMElement object.
@return \qtism\data\QtiComponent A ShufflingGroup object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException | [
"Unmarshall",
"a",
"DOMElement",
"object",
"corresponding",
"to",
"a",
"QTI",
"ShufflingGroup",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/ShufflingGroupMarshaller.php#L64-L80 |
oat-sa/qti-sdk | src/qtism/runtime/common/MultipleContainer.php | MultipleContainer.createFromDataModel | public static function createFromDataModel(ValueCollection $valueCollection, $baseType = BaseType::INTEGER)
{
$container = new static($baseType);
foreach ($valueCollection as $value) {
$container[] = RuntimeUtils::valueToRuntime($value->getValue(), $value->getBaseType());
}
return $container;
} | php | public static function createFromDataModel(ValueCollection $valueCollection, $baseType = BaseType::INTEGER)
{
$container = new static($baseType);
foreach ($valueCollection as $value) {
$container[] = RuntimeUtils::valueToRuntime($value->getValue(), $value->getBaseType());
}
return $container;
} | [
"public",
"static",
"function",
"createFromDataModel",
"(",
"ValueCollection",
"$",
"valueCollection",
",",
"$",
"baseType",
"=",
"BaseType",
"::",
"INTEGER",
")",
"{",
"$",
"container",
"=",
"new",
"static",
"(",
"$",
"baseType",
")",
";",
"foreach",
"(",
"$",
"valueCollection",
"as",
"$",
"value",
")",
"{",
"$",
"container",
"[",
"]",
"=",
"RuntimeUtils",
"::",
"valueToRuntime",
"(",
"$",
"value",
"->",
"getValue",
"(",
")",
",",
"$",
"value",
"->",
"getBaseType",
"(",
")",
")",
";",
"}",
"return",
"$",
"container",
";",
"}"
] | Create a MultipleContainer object from a Data Model ValueCollection object.
@param \qtism\data\state\ValueCollection $valueCollection A collection of qtism\data\state\Value objects.
@param integer $baseType A value from the BaseType enumeration.
@return \qtism\runtime\common\MultipleContainer A MultipleContainer object populated with the values found in $valueCollection.
@throws \InvalidArgumentException If a value from $valueCollection is not compliant with the QTI Runtime Model or the container type. | [
"Create",
"a",
"MultipleContainer",
"object",
"from",
"a",
"Data",
"Model",
"ValueCollection",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/common/MultipleContainer.php#L113-L121 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/VariableMappingMarshaller.php | VariableMappingMarshaller.marshall | protected function marshall(QtiComponent $component)
{
$element = static::getDOMCradle()->createElement($component->getQtiClassName());
$this->setDOMElementAttribute($element, 'sourceIdentifier', $component->getSource());
$this->setDOMElementAttribute($element, 'targetIdentifier', $component->getTarget());
return $element;
} | php | protected function marshall(QtiComponent $component)
{
$element = static::getDOMCradle()->createElement($component->getQtiClassName());
$this->setDOMElementAttribute($element, 'sourceIdentifier', $component->getSource());
$this->setDOMElementAttribute($element, 'targetIdentifier', $component->getTarget());
return $element;
} | [
"protected",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"$",
"element",
"=",
"static",
"::",
"getDOMCradle",
"(",
")",
"->",
"createElement",
"(",
"$",
"component",
"->",
"getQtiClassName",
"(",
")",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'sourceIdentifier'",
",",
"$",
"component",
"->",
"getSource",
"(",
")",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'targetIdentifier'",
",",
"$",
"component",
"->",
"getTarget",
"(",
")",
")",
";",
"return",
"$",
"element",
";",
"}"
] | Marshall a VariableMapping object into a DOMElement object.
@param \qtism\data\QtiComponent $component A VariableMapping object.
@return \DOMElement The according DOMElement object. | [
"Marshall",
"a",
"VariableMapping",
"object",
"into",
"a",
"DOMElement",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/VariableMappingMarshaller.php#L44-L52 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/VariableMappingMarshaller.php | VariableMappingMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
if (($source = $this->getDOMElementAttributeAs($element, 'sourceIdentifier', 'string')) !== null) {
if (($target = $this->getDOMElementAttributeAs($element, 'targetIdentifier', 'string')) !== null) {
try {
$object = new VariableMapping($source, $target);
return $object;
} catch (InvalidArgumentException $e) {
$msg = "'targetIdentifier or/and 'sourceIdentifier' are not valid QTI Identifiers.";
throw new UnmarshallingException($msg, $element, $e);
}
} else {
$msg = "The mandatory attribute 'targetIdentifier' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} else {
$msg = "The mandatory attribute 'sourceIdentifier' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} | php | protected function unmarshall(DOMElement $element)
{
if (($source = $this->getDOMElementAttributeAs($element, 'sourceIdentifier', 'string')) !== null) {
if (($target = $this->getDOMElementAttributeAs($element, 'targetIdentifier', 'string')) !== null) {
try {
$object = new VariableMapping($source, $target);
return $object;
} catch (InvalidArgumentException $e) {
$msg = "'targetIdentifier or/and 'sourceIdentifier' are not valid QTI Identifiers.";
throw new UnmarshallingException($msg, $element, $e);
}
} else {
$msg = "The mandatory attribute 'targetIdentifier' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} else {
$msg = "The mandatory attribute 'sourceIdentifier' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"if",
"(",
"(",
"$",
"source",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'sourceIdentifier'",
",",
"'string'",
")",
")",
"!==",
"null",
")",
"{",
"if",
"(",
"(",
"$",
"target",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'targetIdentifier'",
",",
"'string'",
")",
")",
"!==",
"null",
")",
"{",
"try",
"{",
"$",
"object",
"=",
"new",
"VariableMapping",
"(",
"$",
"source",
",",
"$",
"target",
")",
";",
"return",
"$",
"object",
";",
"}",
"catch",
"(",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"'targetIdentifier or/and 'sourceIdentifier' are not valid QTI Identifiers.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
",",
"$",
"e",
")",
";",
"}",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory attribute 'targetIdentifier' is missing from element '\"",
".",
"$",
"element",
"->",
"localName",
".",
"\"'.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory attribute 'sourceIdentifier' is missing from element '\"",
".",
"$",
"element",
"->",
"localName",
".",
"\"'.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}"
] | Unmarshall a DOMElement object corresponding to a QTI variableMapping element.
@param \DOMElement $element A DOMElement object.
@return \qtism\data\QtiComponent A VariableMapping object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException If the mandatory attributes 'sourceIdentifier' or 'targetIdentifier' are missing from $element or are invalid. | [
"Unmarshall",
"a",
"DOMElement",
"object",
"corresponding",
"to",
"a",
"QTI",
"variableMapping",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/VariableMappingMarshaller.php#L61-L81 |
oat-sa/qti-sdk | src/qtism/data/storage/php/marshalling/PhpMarshaller.php | PhpMarshaller.setToMarshall | public function setToMarshall($toMarshall)
{
if ($this->isMarshallable($toMarshall) === false) {
$msg = "The value to marshall cannot be managed by this implementation.";
throw new InvalidArgumentException($msg);
}
$this->toMarshall = $toMarshall;
} | php | public function setToMarshall($toMarshall)
{
if ($this->isMarshallable($toMarshall) === false) {
$msg = "The value to marshall cannot be managed by this implementation.";
throw new InvalidArgumentException($msg);
}
$this->toMarshall = $toMarshall;
} | [
"public",
"function",
"setToMarshall",
"(",
"$",
"toMarshall",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isMarshallable",
"(",
"$",
"toMarshall",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The value to marshall cannot be managed by this implementation.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"$",
"this",
"->",
"toMarshall",
"=",
"$",
"toMarshall",
";",
"}"
] | Set the value that has to be marshalled.
@param mixed $toMarshall The value to be marshalled.
@throws \InvalidArgumentException If the value $toMarshall cannot be managed by this implementation. | [
"Set",
"the",
"value",
"that",
"has",
"to",
"be",
"marshalled",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/php/marshalling/PhpMarshaller.php#L68-L76 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/RubricBlockRefMarshaller.php | RubricBlockRefMarshaller.marshall | public function marshall(QtiComponent $component)
{
$element = self::getDOMCradle()->createElement('rubricBlockRef');
$this->setDOMElementAttribute($element, 'identifier', $component->getIdentifier());
$this->setDOMElementAttribute($element, 'href', $component->getHref());
return $element;
} | php | public function marshall(QtiComponent $component)
{
$element = self::getDOMCradle()->createElement('rubricBlockRef');
$this->setDOMElementAttribute($element, 'identifier', $component->getIdentifier());
$this->setDOMElementAttribute($element, 'href', $component->getHref());
return $element;
} | [
"public",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"$",
"element",
"=",
"self",
"::",
"getDOMCradle",
"(",
")",
"->",
"createElement",
"(",
"'rubricBlockRef'",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'identifier'",
",",
"$",
"component",
"->",
"getIdentifier",
"(",
")",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'href'",
",",
"$",
"component",
"->",
"getHref",
"(",
")",
")",
";",
"return",
"$",
"element",
";",
"}"
] | Marshall a RubricBlockRef object to its XML counterpart.
@param \qtism\data\QtiComponent $component
@return \DOMElement | [
"Marshall",
"a",
"RubricBlockRef",
"object",
"to",
"its",
"XML",
"counterpart",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/RubricBlockRefMarshaller.php#L43-L50 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/RubricBlockRefMarshaller.php | RubricBlockRefMarshaller.unmarshall | public function unmarshall(DOMElement $element)
{
if (($identifier = $this->getDOMElementAttributeAs($element, 'identifier')) !== null) {
if (($href = $this->getDOMElementAttributeAs($element, 'href')) !== null) {
return new RubricBlockRef($identifier, $href);
} else {
$msg = "The mandatory 'href' attribute is missing from element 'rubricBlockRef'.";
throw new UnmarshallingException($msg, $element);
}
} else {
$msg = "The mandatory 'identifier' attribute is missing from element 'rubricBlockRef'.";
throw new UnmarshallingException($msg, $element);
}
} | php | public function unmarshall(DOMElement $element)
{
if (($identifier = $this->getDOMElementAttributeAs($element, 'identifier')) !== null) {
if (($href = $this->getDOMElementAttributeAs($element, 'href')) !== null) {
return new RubricBlockRef($identifier, $href);
} else {
$msg = "The mandatory 'href' attribute is missing from element 'rubricBlockRef'.";
throw new UnmarshallingException($msg, $element);
}
} else {
$msg = "The mandatory 'identifier' attribute is missing from element 'rubricBlockRef'.";
throw new UnmarshallingException($msg, $element);
}
} | [
"public",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"if",
"(",
"(",
"$",
"identifier",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'identifier'",
")",
")",
"!==",
"null",
")",
"{",
"if",
"(",
"(",
"$",
"href",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'href'",
")",
")",
"!==",
"null",
")",
"{",
"return",
"new",
"RubricBlockRef",
"(",
"$",
"identifier",
",",
"$",
"href",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory 'href' attribute is missing from element 'rubricBlockRef'.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory 'identifier' attribute is missing from element 'rubricBlockRef'.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}"
] | Unmarshall a DOMElement to its RubricBlockRef data model representation.
@param \DOMElement $element
@return \qtism\data\QtiComponent A RubricBlockRef object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException If the 'identifier' or 'href' attribute is missing from the XML definition. | [
"Unmarshall",
"a",
"DOMElement",
"to",
"its",
"RubricBlockRef",
"data",
"model",
"representation",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/RubricBlockRefMarshaller.php#L59-L73 |
oat-sa/qti-sdk | src/qtism/common/beans/Bean.php | Bean.getGetter | public function getGetter($property)
{
if (is_string($property) === true) {
$propertyName = $property;
} elseif ($property instanceof BeanProperty) {
$propertyName = $property->getName();
} else {
$msg = "The 'property' argument must be a string or a BeanProperty object.";
throw new InvalidArgumentException($msg);
}
if ($this->hasProperty($propertyName) === false) {
$msg = "The bean has no '${propertyName}' property.";
throw new BeanException($msg, BeanException::NO_METHOD);
}
if (($getterName = $this->hasGetter($propertyName)) === false) {
$msg = "The bean has no public getter for a '${propertyName}' property.";
throw new BeanException($msg, BeanException::NO_METHOD);
}
return new BeanMethod($this->getClass()->getName(), $getterName);
} | php | public function getGetter($property)
{
if (is_string($property) === true) {
$propertyName = $property;
} elseif ($property instanceof BeanProperty) {
$propertyName = $property->getName();
} else {
$msg = "The 'property' argument must be a string or a BeanProperty object.";
throw new InvalidArgumentException($msg);
}
if ($this->hasProperty($propertyName) === false) {
$msg = "The bean has no '${propertyName}' property.";
throw new BeanException($msg, BeanException::NO_METHOD);
}
if (($getterName = $this->hasGetter($propertyName)) === false) {
$msg = "The bean has no public getter for a '${propertyName}' property.";
throw new BeanException($msg, BeanException::NO_METHOD);
}
return new BeanMethod($this->getClass()->getName(), $getterName);
} | [
"public",
"function",
"getGetter",
"(",
"$",
"property",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"property",
")",
"===",
"true",
")",
"{",
"$",
"propertyName",
"=",
"$",
"property",
";",
"}",
"elseif",
"(",
"$",
"property",
"instanceof",
"BeanProperty",
")",
"{",
"$",
"propertyName",
"=",
"$",
"property",
"->",
"getName",
"(",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'property' argument must be a string or a BeanProperty object.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"hasProperty",
"(",
"$",
"propertyName",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The bean has no '${propertyName}' property.\"",
";",
"throw",
"new",
"BeanException",
"(",
"$",
"msg",
",",
"BeanException",
"::",
"NO_METHOD",
")",
";",
"}",
"if",
"(",
"(",
"$",
"getterName",
"=",
"$",
"this",
"->",
"hasGetter",
"(",
"$",
"propertyName",
")",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The bean has no public getter for a '${propertyName}' property.\"",
";",
"throw",
"new",
"BeanException",
"(",
"$",
"msg",
",",
"BeanException",
"::",
"NO_METHOD",
")",
";",
"}",
"return",
"new",
"BeanMethod",
"(",
"$",
"this",
"->",
"getClass",
"(",
")",
"->",
"getName",
"(",
")",
",",
"$",
"getterName",
")",
";",
"}"
] | Get the getter related to the property with name $propertyName.
@param string|qtism\common\beans\BeanProperty $property The name of the property/the BeanProperty object the getter is related to.
@return \qtism\common\beans\BeanMethod A BeanMethod object.
@throws \qtism\common\beans\BeanException If no such valid bean property or getter exists for the bean.
@throws \InvalidArgumentException If $property is not a string nor a Bean | [
"Get",
"the",
"getter",
"related",
"to",
"the",
"property",
"with",
"name",
"$propertyName",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/beans/Bean.php#L111-L133 |
oat-sa/qti-sdk | src/qtism/common/beans/Bean.php | Bean.hasGetter | public function hasGetter($property)
{
if (is_string($property) === true) {
$propertyName = $property;
} elseif ($property instanceof BeanProperty) {
$propertyName = $property->getName();
} else {
$msg = "The 'property' argument must be a string or a BeanProperty object.";
throw new InvalidArgumentException($msg);
}
$getterNames = self::getPossibleGetterNames($propertyName);
$hasGetter = false;
foreach ($getterNames as $possibleGetterName) {
if ($this->getClass()->hasMethod($possibleGetterName) === true && $this->hasProperty($propertyName) === true) {
if ($this->getClass()->getMethod($possibleGetterName)->isPublic()) {
$hasGetter = $possibleGetterName;
break;
}
}
}
return $hasGetter;
} | php | public function hasGetter($property)
{
if (is_string($property) === true) {
$propertyName = $property;
} elseif ($property instanceof BeanProperty) {
$propertyName = $property->getName();
} else {
$msg = "The 'property' argument must be a string or a BeanProperty object.";
throw new InvalidArgumentException($msg);
}
$getterNames = self::getPossibleGetterNames($propertyName);
$hasGetter = false;
foreach ($getterNames as $possibleGetterName) {
if ($this->getClass()->hasMethod($possibleGetterName) === true && $this->hasProperty($propertyName) === true) {
if ($this->getClass()->getMethod($possibleGetterName)->isPublic()) {
$hasGetter = $possibleGetterName;
break;
}
}
}
return $hasGetter;
} | [
"public",
"function",
"hasGetter",
"(",
"$",
"property",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"property",
")",
"===",
"true",
")",
"{",
"$",
"propertyName",
"=",
"$",
"property",
";",
"}",
"elseif",
"(",
"$",
"property",
"instanceof",
"BeanProperty",
")",
"{",
"$",
"propertyName",
"=",
"$",
"property",
"->",
"getName",
"(",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'property' argument must be a string or a BeanProperty object.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"$",
"getterNames",
"=",
"self",
"::",
"getPossibleGetterNames",
"(",
"$",
"propertyName",
")",
";",
"$",
"hasGetter",
"=",
"false",
";",
"foreach",
"(",
"$",
"getterNames",
"as",
"$",
"possibleGetterName",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getClass",
"(",
")",
"->",
"hasMethod",
"(",
"$",
"possibleGetterName",
")",
"===",
"true",
"&&",
"$",
"this",
"->",
"hasProperty",
"(",
"$",
"propertyName",
")",
"===",
"true",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getClass",
"(",
")",
"->",
"getMethod",
"(",
"$",
"possibleGetterName",
")",
"->",
"isPublic",
"(",
")",
")",
"{",
"$",
"hasGetter",
"=",
"$",
"possibleGetterName",
";",
"break",
";",
"}",
"}",
"}",
"return",
"$",
"hasGetter",
";",
"}"
] | Whether the bean has a valid getter for a property with name $propertyName.
A getter is considered to be valid if:
* Its name is 'get' + ucfirst($propertyName).
* Its visibility is public.
* A valid bean property exists for $propertyName.
@param string|qtism\common\beans\BeanProperty $property The name of the property/the BeanProperty the getter is related to.
@return false|string False if not found or the final chosen name for the getter.
@throws \InvalidArgumentException If $property is not a string nor a BeanProperty object. | [
"Whether",
"the",
"bean",
"has",
"a",
"valid",
"getter",
"for",
"a",
"property",
"with",
"name",
"$propertyName",
".",
"A",
"getter",
"is",
"considered",
"to",
"be",
"valid",
"if",
":"
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/beans/Bean.php#L147-L171 |
oat-sa/qti-sdk | src/qtism/common/beans/Bean.php | Bean.getGetters | public function getGetters($excludeConstructor = false)
{
$methods = new BeanMethodCollection();
foreach ($this->getProperties() as $prop) {
if (($getterName = $this->hasGetter($prop->getName())) !== false) {
if ($excludeConstructor === false || $this->hasConstructorParameter($prop->getName()) === false) {
$methods[] = new BeanMethod($this->getClass()->getName(), $getterName);
}
}
}
return $methods;
} | php | public function getGetters($excludeConstructor = false)
{
$methods = new BeanMethodCollection();
foreach ($this->getProperties() as $prop) {
if (($getterName = $this->hasGetter($prop->getName())) !== false) {
if ($excludeConstructor === false || $this->hasConstructorParameter($prop->getName()) === false) {
$methods[] = new BeanMethod($this->getClass()->getName(), $getterName);
}
}
}
return $methods;
} | [
"public",
"function",
"getGetters",
"(",
"$",
"excludeConstructor",
"=",
"false",
")",
"{",
"$",
"methods",
"=",
"new",
"BeanMethodCollection",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getProperties",
"(",
")",
"as",
"$",
"prop",
")",
"{",
"if",
"(",
"(",
"$",
"getterName",
"=",
"$",
"this",
"->",
"hasGetter",
"(",
"$",
"prop",
"->",
"getName",
"(",
")",
")",
")",
"!==",
"false",
")",
"{",
"if",
"(",
"$",
"excludeConstructor",
"===",
"false",
"||",
"$",
"this",
"->",
"hasConstructorParameter",
"(",
"$",
"prop",
"->",
"getName",
"(",
")",
")",
"===",
"false",
")",
"{",
"$",
"methods",
"[",
"]",
"=",
"new",
"BeanMethod",
"(",
"$",
"this",
"->",
"getClass",
"(",
")",
"->",
"getName",
"(",
")",
",",
"$",
"getterName",
")",
";",
"}",
"}",
"}",
"return",
"$",
"methods",
";",
"}"
] | Get the valid bean getters of the bean.
@return \qtism\common\beans\BeanMethodCollection A collection of BeanMethod objects. | [
"Get",
"the",
"valid",
"bean",
"getters",
"of",
"the",
"bean",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/beans/Bean.php#L178-L192 |
oat-sa/qti-sdk | src/qtism/common/beans/Bean.php | Bean.getSetter | public function getSetter($property)
{
if (is_string($property) === true) {
$propertyName = $property;
} elseif ($property instanceof BeanProperty) {
$propertyName = $property->getName();
} else {
$msg = "The 'property' argument must be a string or a BeanProperty object.";
throw new InvalidArgumentException($msg);
}
if ($this->hasProperty($propertyName) === false) {
$msg = "The bean has no '${propertyName}' property.";
throw new BeanException($msg, BeanException::NO_METHOD);
}
if ($this->hasSetter($propertyName) === false) {
$msg = "The bean has no public setter for a '${propertyName}' property.";
throw new BeanException($msg, BeanException::NO_METHOD);
}
return new BeanMethod($this->getClass()->getName(), 'set' . ucfirst($propertyName));
} | php | public function getSetter($property)
{
if (is_string($property) === true) {
$propertyName = $property;
} elseif ($property instanceof BeanProperty) {
$propertyName = $property->getName();
} else {
$msg = "The 'property' argument must be a string or a BeanProperty object.";
throw new InvalidArgumentException($msg);
}
if ($this->hasProperty($propertyName) === false) {
$msg = "The bean has no '${propertyName}' property.";
throw new BeanException($msg, BeanException::NO_METHOD);
}
if ($this->hasSetter($propertyName) === false) {
$msg = "The bean has no public setter for a '${propertyName}' property.";
throw new BeanException($msg, BeanException::NO_METHOD);
}
return new BeanMethod($this->getClass()->getName(), 'set' . ucfirst($propertyName));
} | [
"public",
"function",
"getSetter",
"(",
"$",
"property",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"property",
")",
"===",
"true",
")",
"{",
"$",
"propertyName",
"=",
"$",
"property",
";",
"}",
"elseif",
"(",
"$",
"property",
"instanceof",
"BeanProperty",
")",
"{",
"$",
"propertyName",
"=",
"$",
"property",
"->",
"getName",
"(",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'property' argument must be a string or a BeanProperty object.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"hasProperty",
"(",
"$",
"propertyName",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The bean has no '${propertyName}' property.\"",
";",
"throw",
"new",
"BeanException",
"(",
"$",
"msg",
",",
"BeanException",
"::",
"NO_METHOD",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"hasSetter",
"(",
"$",
"propertyName",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The bean has no public setter for a '${propertyName}' property.\"",
";",
"throw",
"new",
"BeanException",
"(",
"$",
"msg",
",",
"BeanException",
"::",
"NO_METHOD",
")",
";",
"}",
"return",
"new",
"BeanMethod",
"(",
"$",
"this",
"->",
"getClass",
"(",
")",
"->",
"getName",
"(",
")",
",",
"'set'",
".",
"ucfirst",
"(",
"$",
"propertyName",
")",
")",
";",
"}"
] | Get the setter related to the property with name $propertyName.
@param string|BeanProperty $property The name of the property/The BeanProperty object the setter is related to.
@return \qtism\common\beans\BeanMethod A BeanMethod object.
@throws \qtism\common\beans\BeanException If no such valid bean property or setter exists for the bean.
@throws \InvalidArgumentException If $property is not a string nor a BeanProperty object. | [
"Get",
"the",
"setter",
"related",
"to",
"the",
"property",
"with",
"name",
"$propertyName",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/beans/Bean.php#L202-L224 |
oat-sa/qti-sdk | src/qtism/common/beans/Bean.php | Bean.hasSetter | public function hasSetter($property)
{
if (is_string($property) === true) {
$propertyName = $property;
} elseif ($property instanceof BeanProperty) {
$propertyName = $property->getName();
} else {
$msg = "The 'property' argument must be a string or a BeanProperty object.";
throw new InvalidArgumentException($msg);
}
$setterName = 'set' . ucfirst($propertyName);
$hasSetter = false;
if ($this->getClass()->hasMethod($setterName) === true && $this->hasProperty($propertyName) === true) {
$hasSetter = $this->getClass()->getMethod($setterName)->isPublic();
}
return $hasSetter;
} | php | public function hasSetter($property)
{
if (is_string($property) === true) {
$propertyName = $property;
} elseif ($property instanceof BeanProperty) {
$propertyName = $property->getName();
} else {
$msg = "The 'property' argument must be a string or a BeanProperty object.";
throw new InvalidArgumentException($msg);
}
$setterName = 'set' . ucfirst($propertyName);
$hasSetter = false;
if ($this->getClass()->hasMethod($setterName) === true && $this->hasProperty($propertyName) === true) {
$hasSetter = $this->getClass()->getMethod($setterName)->isPublic();
}
return $hasSetter;
} | [
"public",
"function",
"hasSetter",
"(",
"$",
"property",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"property",
")",
"===",
"true",
")",
"{",
"$",
"propertyName",
"=",
"$",
"property",
";",
"}",
"elseif",
"(",
"$",
"property",
"instanceof",
"BeanProperty",
")",
"{",
"$",
"propertyName",
"=",
"$",
"property",
"->",
"getName",
"(",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'property' argument must be a string or a BeanProperty object.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"$",
"setterName",
"=",
"'set'",
".",
"ucfirst",
"(",
"$",
"propertyName",
")",
";",
"$",
"hasSetter",
"=",
"false",
";",
"if",
"(",
"$",
"this",
"->",
"getClass",
"(",
")",
"->",
"hasMethod",
"(",
"$",
"setterName",
")",
"===",
"true",
"&&",
"$",
"this",
"->",
"hasProperty",
"(",
"$",
"propertyName",
")",
"===",
"true",
")",
"{",
"$",
"hasSetter",
"=",
"$",
"this",
"->",
"getClass",
"(",
")",
"->",
"getMethod",
"(",
"$",
"setterName",
")",
"->",
"isPublic",
"(",
")",
";",
"}",
"return",
"$",
"hasSetter",
";",
"}"
] | Whether the bean has a valid setter for a property with name $propertyName.
A setter is considered to be valid if:
* Its name is 'set' + ucfirst($propertyName).
* Its visibility is public.
* A valid bean property exists for $propertyName.
@param string|\qtism\common\beans\BeanProperty $property The name of the property/the BeanProperty object related to the setter to be checked.
@return boolean | [
"Whether",
"the",
"bean",
"has",
"a",
"valid",
"setter",
"for",
"a",
"property",
"with",
"name",
"$propertyName",
".",
"A",
"setter",
"is",
"considered",
"to",
"be",
"valid",
"if",
":"
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/beans/Bean.php#L237-L256 |
oat-sa/qti-sdk | src/qtism/common/beans/Bean.php | Bean.getSetters | public function getSetters($excludeConstructor = false)
{
$methods = new BeanMethodCollection();
foreach ($this->getProperties() as $prop) {
if ($this->hasSetter($prop->getName()) === true) {
if ($excludeConstructor === false || $this->hasConstructorParameter($prop->getName()) === false) {
$methods[] = new BeanMethod($this->getClass()->getName(), 'set' . ucfirst($prop->getName()));
}
}
}
return $methods;
} | php | public function getSetters($excludeConstructor = false)
{
$methods = new BeanMethodCollection();
foreach ($this->getProperties() as $prop) {
if ($this->hasSetter($prop->getName()) === true) {
if ($excludeConstructor === false || $this->hasConstructorParameter($prop->getName()) === false) {
$methods[] = new BeanMethod($this->getClass()->getName(), 'set' . ucfirst($prop->getName()));
}
}
}
return $methods;
} | [
"public",
"function",
"getSetters",
"(",
"$",
"excludeConstructor",
"=",
"false",
")",
"{",
"$",
"methods",
"=",
"new",
"BeanMethodCollection",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getProperties",
"(",
")",
"as",
"$",
"prop",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasSetter",
"(",
"$",
"prop",
"->",
"getName",
"(",
")",
")",
"===",
"true",
")",
"{",
"if",
"(",
"$",
"excludeConstructor",
"===",
"false",
"||",
"$",
"this",
"->",
"hasConstructorParameter",
"(",
"$",
"prop",
"->",
"getName",
"(",
")",
")",
"===",
"false",
")",
"{",
"$",
"methods",
"[",
"]",
"=",
"new",
"BeanMethod",
"(",
"$",
"this",
"->",
"getClass",
"(",
")",
"->",
"getName",
"(",
")",
",",
"'set'",
".",
"ucfirst",
"(",
"$",
"prop",
"->",
"getName",
"(",
")",
")",
")",
";",
"}",
"}",
"}",
"return",
"$",
"methods",
";",
"}"
] | Get the valid setters of this bean.
@return \qtism\common\beans\BeanMethodCollection A collection of BeanMethod objects. | [
"Get",
"the",
"valid",
"setters",
"of",
"this",
"bean",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/beans/Bean.php#L263-L277 |
oat-sa/qti-sdk | src/qtism/common/beans/Bean.php | Bean.getProperty | public function getProperty($propertyName)
{
$className = $className = $this->getClass()->getName();
if ($this->hasProperty($propertyName) === true) {
try {
return new BeanProperty($className, $propertyName);
} catch (BeanException $e) {
$msg = "The bean property with name '${propertyName}' in class '${className}' could not be retrieved.";
throw new BeanException($msg, BeanException::NO_PROPERTY, $e);
}
} else {
$msg = "No bean property with name '${propertyName}' in class '${className}'.";
throw new BeanException($msg, BeanException::NO_PROPERTY);
}
} | php | public function getProperty($propertyName)
{
$className = $className = $this->getClass()->getName();
if ($this->hasProperty($propertyName) === true) {
try {
return new BeanProperty($className, $propertyName);
} catch (BeanException $e) {
$msg = "The bean property with name '${propertyName}' in class '${className}' could not be retrieved.";
throw new BeanException($msg, BeanException::NO_PROPERTY, $e);
}
} else {
$msg = "No bean property with name '${propertyName}' in class '${className}'.";
throw new BeanException($msg, BeanException::NO_PROPERTY);
}
} | [
"public",
"function",
"getProperty",
"(",
"$",
"propertyName",
")",
"{",
"$",
"className",
"=",
"$",
"className",
"=",
"$",
"this",
"->",
"getClass",
"(",
")",
"->",
"getName",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hasProperty",
"(",
"$",
"propertyName",
")",
"===",
"true",
")",
"{",
"try",
"{",
"return",
"new",
"BeanProperty",
"(",
"$",
"className",
",",
"$",
"propertyName",
")",
";",
"}",
"catch",
"(",
"BeanException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"The bean property with name '${propertyName}' in class '${className}' could not be retrieved.\"",
";",
"throw",
"new",
"BeanException",
"(",
"$",
"msg",
",",
"BeanException",
"::",
"NO_PROPERTY",
",",
"$",
"e",
")",
";",
"}",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"No bean property with name '${propertyName}' in class '${className}'.\"",
";",
"throw",
"new",
"BeanException",
"(",
"$",
"msg",
",",
"BeanException",
"::",
"NO_PROPERTY",
")",
";",
"}",
"}"
] | Get a bean property with name $propertyName.
@param string $propertyName The name of the bean property.
@return \qtism\common\beans\BeanProperty A BeanProperty object. | [
"Get",
"a",
"bean",
"property",
"with",
"name",
"$propertyName",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/beans/Bean.php#L300-L316 |
oat-sa/qti-sdk | src/qtism/common/beans/Bean.php | Bean.getProperties | public function getProperties()
{
$properties = new BeanPropertyCollection();
// Properties already taken into account accross the hierarchy.
$registeredProperties = array();
$target = $this->getClass();
while ($target) {
foreach ($target->getProperties() as $prop) {
$propName = $prop->getName();
if ($this->isPropertyAnnotated($propName) === true && in_array($propName, $registeredProperties) === false) {
$properties[] = new BeanProperty($target->getName(), $propName);
$registeredProperties[] = $propName;
}
}
$target = $target->getParentClass();
}
return $properties;
} | php | public function getProperties()
{
$properties = new BeanPropertyCollection();
// Properties already taken into account accross the hierarchy.
$registeredProperties = array();
$target = $this->getClass();
while ($target) {
foreach ($target->getProperties() as $prop) {
$propName = $prop->getName();
if ($this->isPropertyAnnotated($propName) === true && in_array($propName, $registeredProperties) === false) {
$properties[] = new BeanProperty($target->getName(), $propName);
$registeredProperties[] = $propName;
}
}
$target = $target->getParentClass();
}
return $properties;
} | [
"public",
"function",
"getProperties",
"(",
")",
"{",
"$",
"properties",
"=",
"new",
"BeanPropertyCollection",
"(",
")",
";",
"// Properties already taken into account accross the hierarchy.",
"$",
"registeredProperties",
"=",
"array",
"(",
")",
";",
"$",
"target",
"=",
"$",
"this",
"->",
"getClass",
"(",
")",
";",
"while",
"(",
"$",
"target",
")",
"{",
"foreach",
"(",
"$",
"target",
"->",
"getProperties",
"(",
")",
"as",
"$",
"prop",
")",
"{",
"$",
"propName",
"=",
"$",
"prop",
"->",
"getName",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isPropertyAnnotated",
"(",
"$",
"propName",
")",
"===",
"true",
"&&",
"in_array",
"(",
"$",
"propName",
",",
"$",
"registeredProperties",
")",
"===",
"false",
")",
"{",
"$",
"properties",
"[",
"]",
"=",
"new",
"BeanProperty",
"(",
"$",
"target",
"->",
"getName",
"(",
")",
",",
"$",
"propName",
")",
";",
"$",
"registeredProperties",
"[",
"]",
"=",
"$",
"propName",
";",
"}",
"}",
"$",
"target",
"=",
"$",
"target",
"->",
"getParentClass",
"(",
")",
";",
"}",
"return",
"$",
"properties",
";",
"}"
] | Get the bean properties. Only valid annotated bean properties will be returned.
@return \qtism\common\beans\BeanPropertyCollection A collection of BeanProperty objects ordered by apparition in source code. | [
"Get",
"the",
"bean",
"properties",
".",
"Only",
"valid",
"annotated",
"bean",
"properties",
"will",
"be",
"returned",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/beans/Bean.php#L323-L347 |
oat-sa/qti-sdk | src/qtism/common/beans/Bean.php | Bean.getConstructorGetters | public function getConstructorGetters()
{
$getters = new BeanMethodCollection();
foreach ($this->getConstructorParameters() as $param) {
$getters[] = $this->getGetter($param->getName());
}
return $getters;
} | php | public function getConstructorGetters()
{
$getters = new BeanMethodCollection();
foreach ($this->getConstructorParameters() as $param) {
$getters[] = $this->getGetter($param->getName());
}
return $getters;
} | [
"public",
"function",
"getConstructorGetters",
"(",
")",
"{",
"$",
"getters",
"=",
"new",
"BeanMethodCollection",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getConstructorParameters",
"(",
")",
"as",
"$",
"param",
")",
"{",
"$",
"getters",
"[",
"]",
"=",
"$",
"this",
"->",
"getGetter",
"(",
"$",
"param",
"->",
"getName",
"(",
")",
")",
";",
"}",
"return",
"$",
"getters",
";",
"}"
] | Get the bean getters related to the parameters of the bean's constructor.
@return \qtism\common\beans\BeanMethodCollection A collection of BeanMethod objects. | [
"Get",
"the",
"bean",
"getters",
"related",
"to",
"the",
"parameters",
"of",
"the",
"bean",
"s",
"constructor",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/beans/Bean.php#L354-L363 |
oat-sa/qti-sdk | src/qtism/common/beans/Bean.php | Bean.getConstructorSetters | public function getConstructorSetters()
{
$setters = new BeanMethodCollection();
foreach ($this->getConstructorParameters() as $param) {
$setters[] = $this->getSetter($param->getName());
}
return $setters;
} | php | public function getConstructorSetters()
{
$setters = new BeanMethodCollection();
foreach ($this->getConstructorParameters() as $param) {
$setters[] = $this->getSetter($param->getName());
}
return $setters;
} | [
"public",
"function",
"getConstructorSetters",
"(",
")",
"{",
"$",
"setters",
"=",
"new",
"BeanMethodCollection",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getConstructorParameters",
"(",
")",
"as",
"$",
"param",
")",
"{",
"$",
"setters",
"[",
"]",
"=",
"$",
"this",
"->",
"getSetter",
"(",
"$",
"param",
"->",
"getName",
"(",
")",
")",
";",
"}",
"return",
"$",
"setters",
";",
"}"
] | Get the bean setters related to the parameters of the bean's constructor.
@return \qtism\common\beans\BeanMethodCollection A collection of BeanMethod objects. | [
"Get",
"the",
"bean",
"setters",
"related",
"to",
"the",
"parameters",
"of",
"the",
"bean",
"s",
"constructor",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/beans/Bean.php#L370-L379 |
oat-sa/qti-sdk | src/qtism/common/beans/Bean.php | Bean.getConstructorParameters | public function getConstructorParameters()
{
$parameters = new BeanParameterCollection();
if (($ctor = $this->getClass()->getConstructor()) !== null) {
foreach ($ctor->getParameters() as $param) {
if ($this->hasProperty($param->getName()) === true) {
$parameters[] = new BeanParameter($this->getClass()->getName(), '__construct', $param->getName());
}
}
}
return $parameters;
} | php | public function getConstructorParameters()
{
$parameters = new BeanParameterCollection();
if (($ctor = $this->getClass()->getConstructor()) !== null) {
foreach ($ctor->getParameters() as $param) {
if ($this->hasProperty($param->getName()) === true) {
$parameters[] = new BeanParameter($this->getClass()->getName(), '__construct', $param->getName());
}
}
}
return $parameters;
} | [
"public",
"function",
"getConstructorParameters",
"(",
")",
"{",
"$",
"parameters",
"=",
"new",
"BeanParameterCollection",
"(",
")",
";",
"if",
"(",
"(",
"$",
"ctor",
"=",
"$",
"this",
"->",
"getClass",
"(",
")",
"->",
"getConstructor",
"(",
")",
")",
"!==",
"null",
")",
"{",
"foreach",
"(",
"$",
"ctor",
"->",
"getParameters",
"(",
")",
"as",
"$",
"param",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasProperty",
"(",
"$",
"param",
"->",
"getName",
"(",
")",
")",
"===",
"true",
")",
"{",
"$",
"parameters",
"[",
"]",
"=",
"new",
"BeanParameter",
"(",
"$",
"this",
"->",
"getClass",
"(",
")",
"->",
"getName",
"(",
")",
",",
"'__construct'",
",",
"$",
"param",
"->",
"getName",
"(",
")",
")",
";",
"}",
"}",
"}",
"return",
"$",
"parameters",
";",
"}"
] | Get the constructor parameters of the bean. Only parameters that have the same name
than a valid bean property will be returned.
@return \qtism\common\beans\BeanParameterCollection A collection of BeanParameter objects. | [
"Get",
"the",
"constructor",
"parameters",
"of",
"the",
"bean",
".",
"Only",
"parameters",
"that",
"have",
"the",
"same",
"name",
"than",
"a",
"valid",
"bean",
"property",
"will",
"be",
"returned",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/beans/Bean.php#L387-L401 |
oat-sa/qti-sdk | src/qtism/common/beans/Bean.php | Bean.hasConstructorParameter | public function hasConstructorParameter($parameterName)
{
$hasConstructorParameter = false;
if (($ctor = $this->getClass()->getConstructor()) !== null) {
foreach ($ctor->getParameters() as $param) {
if ($param->getName() === $parameterName && $this->hasProperty($param->getName()) === true) {
$hasConstructorParameter = true;
break;
}
}
}
return $hasConstructorParameter;
} | php | public function hasConstructorParameter($parameterName)
{
$hasConstructorParameter = false;
if (($ctor = $this->getClass()->getConstructor()) !== null) {
foreach ($ctor->getParameters() as $param) {
if ($param->getName() === $parameterName && $this->hasProperty($param->getName()) === true) {
$hasConstructorParameter = true;
break;
}
}
}
return $hasConstructorParameter;
} | [
"public",
"function",
"hasConstructorParameter",
"(",
"$",
"parameterName",
")",
"{",
"$",
"hasConstructorParameter",
"=",
"false",
";",
"if",
"(",
"(",
"$",
"ctor",
"=",
"$",
"this",
"->",
"getClass",
"(",
")",
"->",
"getConstructor",
"(",
")",
")",
"!==",
"null",
")",
"{",
"foreach",
"(",
"$",
"ctor",
"->",
"getParameters",
"(",
")",
"as",
"$",
"param",
")",
"{",
"if",
"(",
"$",
"param",
"->",
"getName",
"(",
")",
"===",
"$",
"parameterName",
"&&",
"$",
"this",
"->",
"hasProperty",
"(",
"$",
"param",
"->",
"getName",
"(",
")",
")",
"===",
"true",
")",
"{",
"$",
"hasConstructorParameter",
"=",
"true",
";",
"break",
";",
"}",
"}",
"}",
"return",
"$",
"hasConstructorParameter",
";",
"}"
] | Whether the bean has a constructor parameter $parameterName which is related
to a valid bean property.
@param string $parameterName The name of the parameter.
@return boolean | [
"Whether",
"the",
"bean",
"has",
"a",
"constructor",
"parameter",
"$parameterName",
"which",
"is",
"related",
"to",
"a",
"valid",
"bean",
"property",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/beans/Bean.php#L410-L425 |
oat-sa/qti-sdk | src/qtism/common/beans/Bean.php | Bean.isPropertyAnnotated | protected function isPropertyAnnotated($propertyName)
{
$target = $this->getClass();
$isAnnotated = false;
while ($target) {
if ($target->hasProperty($propertyName)) {
$comment = $target->getProperty($propertyName)->getDocComment();
if (empty($comment) === false) {
$isAnnotated = mb_strpos($comment, self::ANNOTATION_PROPERTY, 0, 'UTF-8') !== false;
if ($isAnnotated === true) {
break;
}
}
}
$target = $target->getParentClass();
}
return $isAnnotated;
} | php | protected function isPropertyAnnotated($propertyName)
{
$target = $this->getClass();
$isAnnotated = false;
while ($target) {
if ($target->hasProperty($propertyName)) {
$comment = $target->getProperty($propertyName)->getDocComment();
if (empty($comment) === false) {
$isAnnotated = mb_strpos($comment, self::ANNOTATION_PROPERTY, 0, 'UTF-8') !== false;
if ($isAnnotated === true) {
break;
}
}
}
$target = $target->getParentClass();
}
return $isAnnotated;
} | [
"protected",
"function",
"isPropertyAnnotated",
"(",
"$",
"propertyName",
")",
"{",
"$",
"target",
"=",
"$",
"this",
"->",
"getClass",
"(",
")",
";",
"$",
"isAnnotated",
"=",
"false",
";",
"while",
"(",
"$",
"target",
")",
"{",
"if",
"(",
"$",
"target",
"->",
"hasProperty",
"(",
"$",
"propertyName",
")",
")",
"{",
"$",
"comment",
"=",
"$",
"target",
"->",
"getProperty",
"(",
"$",
"propertyName",
")",
"->",
"getDocComment",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"comment",
")",
"===",
"false",
")",
"{",
"$",
"isAnnotated",
"=",
"mb_strpos",
"(",
"$",
"comment",
",",
"self",
"::",
"ANNOTATION_PROPERTY",
",",
"0",
",",
"'UTF-8'",
")",
"!==",
"false",
";",
"if",
"(",
"$",
"isAnnotated",
"===",
"true",
")",
"{",
"break",
";",
"}",
"}",
"}",
"$",
"target",
"=",
"$",
"target",
"->",
"getParentClass",
"(",
")",
";",
"}",
"return",
"$",
"isAnnotated",
";",
"}"
] | Whether a given property is annotated with the appropriate bean annotation.
@param string $propertyName The name of the property.
@return boolean | [
"Whether",
"a",
"given",
"property",
"is",
"annotated",
"with",
"the",
"appropriate",
"bean",
"annotation",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/beans/Bean.php#L433-L456 |
oat-sa/qti-sdk | src/qtism/common/beans/Bean.php | Bean.validateStrictBean | protected function validateStrictBean()
{
/*
* 1st rule to respect:
* All the constructor's parameters must be bound
* to a valid annotated property, and the appropriate
* getter and setter. (This implies the bean has a constructor)
*/
if ($this->getClass()->hasMethod('__construct') === true) {
$params = $this->getClass()->getMethod('__construct')->getParameters();
$class = $this->getClass()->getName();
foreach ($params as $param) {
$name = $param->getName();
if ($this->hasProperty($name) === false) {
$msg = "The constructor parameter '${name}' of class '${class}' has no related bean property.";
throw new BeanException($msg, BeanException::NO_PROPERTY);
} elseif ($this->hasGetter($name) === false) {
$msg = "The constructor parameter '${name}' of class '${class}' has no related bean getter.";
throw new BeanException($msg, BeanException::NO_METHOD);
} elseif ($this->hasSetter($name) === false) {
$msg = "The construct parameter '${name}' of class '${class}' has no related bean setter.";
throw new BeanException($msg, BeanException::NO_METHOD);
}
}
}
/*
* 2nd rule to respect is that any property annotated as a bean property
* must have the appropriate getter and setter.
*/
foreach ($this->getClass()->getProperties() as $prop) {
$name = $prop->getName();
if ($this->hasProperty($name) === true) {
// Annotated property found.
if ($this->hasGetter($name) === false) {
$msg = "The bean property '${name}' has no related bean getter.";
throw new BeanException($msg, BeanException::NO_METHOD);
} elseif ($this->hasSetter($name) === false) {
$msg = "The bean property '${name}' has no related bean setter.";
throw new BeanException($msg, BeanException::NO_METHOD);
}
}
}
} | php | protected function validateStrictBean()
{
/*
* 1st rule to respect:
* All the constructor's parameters must be bound
* to a valid annotated property, and the appropriate
* getter and setter. (This implies the bean has a constructor)
*/
if ($this->getClass()->hasMethod('__construct') === true) {
$params = $this->getClass()->getMethod('__construct')->getParameters();
$class = $this->getClass()->getName();
foreach ($params as $param) {
$name = $param->getName();
if ($this->hasProperty($name) === false) {
$msg = "The constructor parameter '${name}' of class '${class}' has no related bean property.";
throw new BeanException($msg, BeanException::NO_PROPERTY);
} elseif ($this->hasGetter($name) === false) {
$msg = "The constructor parameter '${name}' of class '${class}' has no related bean getter.";
throw new BeanException($msg, BeanException::NO_METHOD);
} elseif ($this->hasSetter($name) === false) {
$msg = "The construct parameter '${name}' of class '${class}' has no related bean setter.";
throw new BeanException($msg, BeanException::NO_METHOD);
}
}
}
/*
* 2nd rule to respect is that any property annotated as a bean property
* must have the appropriate getter and setter.
*/
foreach ($this->getClass()->getProperties() as $prop) {
$name = $prop->getName();
if ($this->hasProperty($name) === true) {
// Annotated property found.
if ($this->hasGetter($name) === false) {
$msg = "The bean property '${name}' has no related bean getter.";
throw new BeanException($msg, BeanException::NO_METHOD);
} elseif ($this->hasSetter($name) === false) {
$msg = "The bean property '${name}' has no related bean setter.";
throw new BeanException($msg, BeanException::NO_METHOD);
}
}
}
} | [
"protected",
"function",
"validateStrictBean",
"(",
")",
"{",
"/*\n * 1st rule to respect:\n * All the constructor's parameters must be bound\n * to a valid annotated property, and the appropriate\n * getter and setter. (This implies the bean has a constructor)\n */",
"if",
"(",
"$",
"this",
"->",
"getClass",
"(",
")",
"->",
"hasMethod",
"(",
"'__construct'",
")",
"===",
"true",
")",
"{",
"$",
"params",
"=",
"$",
"this",
"->",
"getClass",
"(",
")",
"->",
"getMethod",
"(",
"'__construct'",
")",
"->",
"getParameters",
"(",
")",
";",
"$",
"class",
"=",
"$",
"this",
"->",
"getClass",
"(",
")",
"->",
"getName",
"(",
")",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"param",
")",
"{",
"$",
"name",
"=",
"$",
"param",
"->",
"getName",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hasProperty",
"(",
"$",
"name",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The constructor parameter '${name}' of class '${class}' has no related bean property.\"",
";",
"throw",
"new",
"BeanException",
"(",
"$",
"msg",
",",
"BeanException",
"::",
"NO_PROPERTY",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"hasGetter",
"(",
"$",
"name",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The constructor parameter '${name}' of class '${class}' has no related bean getter.\"",
";",
"throw",
"new",
"BeanException",
"(",
"$",
"msg",
",",
"BeanException",
"::",
"NO_METHOD",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"hasSetter",
"(",
"$",
"name",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The construct parameter '${name}' of class '${class}' has no related bean setter.\"",
";",
"throw",
"new",
"BeanException",
"(",
"$",
"msg",
",",
"BeanException",
"::",
"NO_METHOD",
")",
";",
"}",
"}",
"}",
"/*\n * 2nd rule to respect is that any property annotated as a bean property\n * must have the appropriate getter and setter.\n */",
"foreach",
"(",
"$",
"this",
"->",
"getClass",
"(",
")",
"->",
"getProperties",
"(",
")",
"as",
"$",
"prop",
")",
"{",
"$",
"name",
"=",
"$",
"prop",
"->",
"getName",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hasProperty",
"(",
"$",
"name",
")",
"===",
"true",
")",
"{",
"// Annotated property found.",
"if",
"(",
"$",
"this",
"->",
"hasGetter",
"(",
"$",
"name",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The bean property '${name}' has no related bean getter.\"",
";",
"throw",
"new",
"BeanException",
"(",
"$",
"msg",
",",
"BeanException",
"::",
"NO_METHOD",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"hasSetter",
"(",
"$",
"name",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The bean property '${name}' has no related bean setter.\"",
";",
"throw",
"new",
"BeanException",
"(",
"$",
"msg",
",",
"BeanException",
"::",
"NO_METHOD",
")",
";",
"}",
"}",
"}",
"}"
] | Contains the internal logic of bean validation. Throws exceptions
to know why it's not a valid bean.
@throws \qtism\common\beans\BeanException | [
"Contains",
"the",
"internal",
"logic",
"of",
"bean",
"validation",
".",
"Throws",
"exceptions",
"to",
"know",
"why",
"it",
"s",
"not",
"a",
"valid",
"bean",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/beans/Bean.php#L464-L510 |
oat-sa/qti-sdk | src/qtism/runtime/rendering/qtipl/expressions/operators/StringMatchQtiPLRenderer.php | StringMatchQtiPLRenderer.render | public function render($something)
{
$renderer = new QtiPLRenderer($this->getCRO());
$attributes = [];
$attributes['caseSensitive'] = strtolower(var_export($something->isCaseSensitive(), true));
if ($something->mustSubstring()) {
$attributes['substring'] = "true";
}
return $something->getQtiClassName() . $renderer->writeAttributes($attributes)
. $renderer->writeChildElements($something->getExpressions());
} | php | public function render($something)
{
$renderer = new QtiPLRenderer($this->getCRO());
$attributes = [];
$attributes['caseSensitive'] = strtolower(var_export($something->isCaseSensitive(), true));
if ($something->mustSubstring()) {
$attributes['substring'] = "true";
}
return $something->getQtiClassName() . $renderer->writeAttributes($attributes)
. $renderer->writeChildElements($something->getExpressions());
} | [
"public",
"function",
"render",
"(",
"$",
"something",
")",
"{",
"$",
"renderer",
"=",
"new",
"QtiPLRenderer",
"(",
"$",
"this",
"->",
"getCRO",
"(",
")",
")",
";",
"$",
"attributes",
"=",
"[",
"]",
";",
"$",
"attributes",
"[",
"'caseSensitive'",
"]",
"=",
"strtolower",
"(",
"var_export",
"(",
"$",
"something",
"->",
"isCaseSensitive",
"(",
")",
",",
"true",
")",
")",
";",
"if",
"(",
"$",
"something",
"->",
"mustSubstring",
"(",
")",
")",
"{",
"$",
"attributes",
"[",
"'substring'",
"]",
"=",
"\"true\"",
";",
"}",
"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/StringMatchQtiPLRenderer.php#L46-L58 |
oat-sa/qti-sdk | src/qtism/common/datatypes/QtiPair.php | QtiPair.setFirst | public function setFirst($first)
{
if (Format::isIdentifier($first)) {
$this->first = $first;
} else {
$msg = "'${first}' is an invalid QTI identifier.";
throw new InvalidArgumentException($msg);
}
} | php | public function setFirst($first)
{
if (Format::isIdentifier($first)) {
$this->first = $first;
} else {
$msg = "'${first}' is an invalid QTI identifier.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setFirst",
"(",
"$",
"first",
")",
"{",
"if",
"(",
"Format",
"::",
"isIdentifier",
"(",
"$",
"first",
")",
")",
"{",
"$",
"this",
"->",
"first",
"=",
"$",
"first",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"'${first}' is an invalid QTI identifier.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the first identifier of the pair.
@param string $first A QTI Identifier.
@throws \InvalidArgumentException If $first is an invalid QTI Identifier. | [
"Set",
"the",
"first",
"identifier",
"of",
"the",
"pair",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/datatypes/QtiPair.php#L75-L83 |
oat-sa/qti-sdk | src/qtism/common/datatypes/QtiPair.php | QtiPair.setSecond | public function setSecond($second)
{
if (Format::isIdentifier($second)) {
$this->second = $second;
} else {
$msg = "'${second}' is an invalid QTI identifier.";
throw new InvalidArgumentException($msg);
}
} | php | public function setSecond($second)
{
if (Format::isIdentifier($second)) {
$this->second = $second;
} else {
$msg = "'${second}' is an invalid QTI identifier.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setSecond",
"(",
"$",
"second",
")",
"{",
"if",
"(",
"Format",
"::",
"isIdentifier",
"(",
"$",
"second",
")",
")",
"{",
"$",
"this",
"->",
"second",
"=",
"$",
"second",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"'${second}' is an invalid QTI identifier.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the second identifier of the pair.
@param string $second A QTI Identifier.
@throws \InvalidArgumentException If $identifier is not a valid QTI Identifier. | [
"Set",
"the",
"second",
"identifier",
"of",
"the",
"pair",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/datatypes/QtiPair.php#L101-L109 |
oat-sa/qti-sdk | src/qtism/common/datatypes/QtiPair.php | QtiPair.equals | public function equals($obj)
{
if (gettype($obj) === 'object' && $obj instanceof self) {
$a = array($this->getFirst(), $this->getSecond());
$b = array($obj->getFirst(), $obj->getSecond());
return in_array($b[0], $a) && in_array($b[1], $a);
}
return false;
} | php | public function equals($obj)
{
if (gettype($obj) === 'object' && $obj instanceof self) {
$a = array($this->getFirst(), $this->getSecond());
$b = array($obj->getFirst(), $obj->getSecond());
return in_array($b[0], $a) && in_array($b[1], $a);
}
return false;
} | [
"public",
"function",
"equals",
"(",
"$",
"obj",
")",
"{",
"if",
"(",
"gettype",
"(",
"$",
"obj",
")",
"===",
"'object'",
"&&",
"$",
"obj",
"instanceof",
"self",
")",
"{",
"$",
"a",
"=",
"array",
"(",
"$",
"this",
"->",
"getFirst",
"(",
")",
",",
"$",
"this",
"->",
"getSecond",
"(",
")",
")",
";",
"$",
"b",
"=",
"array",
"(",
"$",
"obj",
"->",
"getFirst",
"(",
")",
",",
"$",
"obj",
"->",
"getSecond",
"(",
")",
")",
";",
"return",
"in_array",
"(",
"$",
"b",
"[",
"0",
"]",
",",
"$",
"a",
")",
"&&",
"in_array",
"(",
"$",
"b",
"[",
"1",
"]",
",",
"$",
"a",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Whether a given $obj is equal to this Pair. Two Pair objects
are considered to be identical if the first and second values
of $obj are the same as the ones of $obj.
@param mixed $obj A value to compare.
@return boolean Whether or not the equality could be established. | [
"Whether",
"a",
"given",
"$obj",
"is",
"equal",
"to",
"this",
"Pair",
".",
"Two",
"Pair",
"objects",
"are",
"considered",
"to",
"be",
"identical",
"if",
"the",
"first",
"and",
"second",
"values",
"of",
"$obj",
"are",
"the",
"same",
"as",
"the",
"ones",
"of",
"$obj",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/datatypes/QtiPair.php#L139-L149 |
oat-sa/qti-sdk | src/qtism/common/datatypes/files/FileSystemFileManager.php | FileSystemFileManager.createFromFile | public function createFromFile($path, $mimeType, $filename = '')
{
$destination = $this->buildDestination();
try {
return FileSystemFile::createFromExistingFile($path, $destination, $mimeType, $filename);
} catch (RuntimeException $e) {
$msg = "An error occured while creating a QTI FileSystemFile object.";
throw new FileManagerException($msg, 0, $e);
}
} | php | public function createFromFile($path, $mimeType, $filename = '')
{
$destination = $this->buildDestination();
try {
return FileSystemFile::createFromExistingFile($path, $destination, $mimeType, $filename);
} catch (RuntimeException $e) {
$msg = "An error occured while creating a QTI FileSystemFile object.";
throw new FileManagerException($msg, 0, $e);
}
} | [
"public",
"function",
"createFromFile",
"(",
"$",
"path",
",",
"$",
"mimeType",
",",
"$",
"filename",
"=",
"''",
")",
"{",
"$",
"destination",
"=",
"$",
"this",
"->",
"buildDestination",
"(",
")",
";",
"try",
"{",
"return",
"FileSystemFile",
"::",
"createFromExistingFile",
"(",
"$",
"path",
",",
"$",
"destination",
",",
"$",
"mimeType",
",",
"$",
"filename",
")",
";",
"}",
"catch",
"(",
"RuntimeException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while creating a QTI FileSystemFile object.\"",
";",
"throw",
"new",
"FileManagerException",
"(",
"$",
"msg",
",",
"0",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Create a FileSystemFile object from an existing
file on the file system.
@param string $path The canonical path to the file.
@param string $mimeType The mime-type of the file (if you want to force it).
@param string $filename The file name of the file (if you want to force it).
@throws \qtism\common\datatypes\files\FileManagerException
@return \qtism\common\datatypes\files\FileSystemFile | [
"Create",
"a",
"FileSystemFile",
"object",
"from",
"an",
"existing",
"file",
"on",
"the",
"file",
"system",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/datatypes/files/FileSystemFileManager.php#L75-L85 |
oat-sa/qti-sdk | src/qtism/common/datatypes/files/FileSystemFileManager.php | FileSystemFileManager.createFromData | public function createFromData($data, $mimeType, $filename = '')
{
$destination = $this->buildDestination();
try {
return FileSystemFile::createFromData($data, $destination, $mimeType, $filename);
} catch (RuntimeException $e) {
$msg = "An error occured while creating a QTI FileSystemFile object.";
throw new FileManagerException($msg, 0, $e);
}
} | php | public function createFromData($data, $mimeType, $filename = '')
{
$destination = $this->buildDestination();
try {
return FileSystemFile::createFromData($data, $destination, $mimeType, $filename);
} catch (RuntimeException $e) {
$msg = "An error occured while creating a QTI FileSystemFile object.";
throw new FileManagerException($msg, 0, $e);
}
} | [
"public",
"function",
"createFromData",
"(",
"$",
"data",
",",
"$",
"mimeType",
",",
"$",
"filename",
"=",
"''",
")",
"{",
"$",
"destination",
"=",
"$",
"this",
"->",
"buildDestination",
"(",
")",
";",
"try",
"{",
"return",
"FileSystemFile",
"::",
"createFromData",
"(",
"$",
"data",
",",
"$",
"destination",
",",
"$",
"mimeType",
",",
"$",
"filename",
")",
";",
"}",
"catch",
"(",
"RuntimeException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while creating a QTI FileSystemFile object.\"",
";",
"throw",
"new",
"FileManagerException",
"(",
"$",
"msg",
",",
"0",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Create a FileSystemFile from existing data on the file system.
@param string $data The binary data of the FileSystemFile object to be created.
@param string $mimeType A mime-type.
@param string $filename A file name e.g. "myfile.txt".
@throws \qtism\common\datatypes\files\FileManagerException
@return \qtism\common\datatypes\files\FileSystemFile | [
"Create",
"a",
"FileSystemFile",
"from",
"existing",
"data",
"on",
"the",
"file",
"system",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/datatypes/files/FileSystemFileManager.php#L96-L106 |
oat-sa/qti-sdk | src/qtism/common/datatypes/files/FileSystemFileManager.php | FileSystemFileManager.retrieve | public function retrieve($identifier)
{
try {
return FileSystemFile::retrieveFile($identifier);
} catch (RuntimeException $e) {
$msg = "An error occured while retrieving a QTI FileSystemFile object.";
throw new FileManagerException($msg, 0, $e);
}
} | php | public function retrieve($identifier)
{
try {
return FileSystemFile::retrieveFile($identifier);
} catch (RuntimeException $e) {
$msg = "An error occured while retrieving a QTI FileSystemFile object.";
throw new FileManagerException($msg, 0, $e);
}
} | [
"public",
"function",
"retrieve",
"(",
"$",
"identifier",
")",
"{",
"try",
"{",
"return",
"FileSystemFile",
"::",
"retrieveFile",
"(",
"$",
"identifier",
")",
";",
"}",
"catch",
"(",
"RuntimeException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while retrieving a QTI FileSystemFile object.\"",
";",
"throw",
"new",
"FileManagerException",
"(",
"$",
"msg",
",",
"0",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Retrieve a FileSystemFile object from its unique identifier.
@param string identifier
@throws \qtism\common\datatypes\files\FileManagerException
@return \qtism\common\datatypes\files\FileSystemFile | [
"Retrieve",
"a",
"FileSystemFile",
"object",
"from",
"its",
"unique",
"identifier",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/datatypes/files/FileSystemFileManager.php#L115-L123 |
oat-sa/qti-sdk | src/qtism/common/datatypes/files/FileSystemFileManager.php | FileSystemFileManager.delete | public function delete(QtiFile $file)
{
$deletion = @unlink($file->getPath());
if ($deletion === false) {
$msg = "The File System File located at '" . $file->getPath() . "' could not be deleted gracefully.";
throw new FileManagerException($msg);
}
} | php | public function delete(QtiFile $file)
{
$deletion = @unlink($file->getPath());
if ($deletion === false) {
$msg = "The File System File located at '" . $file->getPath() . "' could not be deleted gracefully.";
throw new FileManagerException($msg);
}
} | [
"public",
"function",
"delete",
"(",
"QtiFile",
"$",
"file",
")",
"{",
"$",
"deletion",
"=",
"@",
"unlink",
"(",
"$",
"file",
"->",
"getPath",
"(",
")",
")",
";",
"if",
"(",
"$",
"deletion",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The File System File located at '\"",
".",
"$",
"file",
"->",
"getPath",
"(",
")",
".",
"\"' could not be deleted gracefully.\"",
";",
"throw",
"new",
"FileManagerException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Delete a FileSystemFile object from the persistence.
@throws \qtism\common\datatypes\files\FileManagerException | [
"Delete",
"a",
"FileSystemFile",
"object",
"from",
"the",
"persistence",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/datatypes/files/FileSystemFileManager.php#L130-L137 |
oat-sa/qti-sdk | src/qtism/data/expressions/MathConstant.php | MathConstant.setName | public function setName($name)
{
if (in_array($name, MathEnumeration::asArray())) {
$this->name = $name;
} else {
$msg = "${name} is not a valid QTI Math constant.";
throw new InvalidArgumentException($msg);
}
} | php | public function setName($name)
{
if (in_array($name, MathEnumeration::asArray())) {
$this->name = $name;
} else {
$msg = "${name} is not a valid QTI Math constant.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setName",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"name",
",",
"MathEnumeration",
"::",
"asArray",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"name",
"=",
"$",
"name",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"${name} is not a valid QTI Math constant.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the name of the math constant.
@param string $name The name of the math constant.
@throws \InvalidArgumentException If $name is not a valid QTI math constant name. | [
"Set",
"the",
"name",
"of",
"the",
"math",
"constant",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/expressions/MathConstant.php#L71-L79 |
oat-sa/qti-sdk | src/qtism/data/state/InterpolationTable.php | InterpolationTable.setInterpolationTableEntries | public function setInterpolationTableEntries(InterpolationTableEntryCollection $interpolationTableEntries)
{
if (count($interpolationTableEntries) > 0) {
$this->interpolationTableEntries = $interpolationTableEntries;
} else {
$msg = "An InterpolationTable object must contain at least one InterpolationTableEntry object.";
throw new InvalidArgumentException($msg);
}
} | php | public function setInterpolationTableEntries(InterpolationTableEntryCollection $interpolationTableEntries)
{
if (count($interpolationTableEntries) > 0) {
$this->interpolationTableEntries = $interpolationTableEntries;
} else {
$msg = "An InterpolationTable object must contain at least one InterpolationTableEntry object.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setInterpolationTableEntries",
"(",
"InterpolationTableEntryCollection",
"$",
"interpolationTableEntries",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"interpolationTableEntries",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"interpolationTableEntries",
"=",
"$",
"interpolationTableEntries",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"An InterpolationTable object must contain at least one InterpolationTableEntry object.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the InterpolationTableEntry objects contained by the current InterpolationTable.
@param \qtism\data\state\InterpolationTableEntryCollection $interpolationTableEntries A collection of InterpolationTableEntry objects.
@throws \InvalidArgumentException If $interpolationTableEntries is an empty collection. | [
"Set",
"the",
"InterpolationTableEntry",
"objects",
"contained",
"by",
"the",
"current",
"InterpolationTable",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/state/InterpolationTable.php#L81-L89 |
oat-sa/qti-sdk | src/qtism/runtime/processing/PrintedVariableProcessingException.php | PrintedVariableProcessingException.setSource | public function setSource(Processable $source)
{
if ($source instanceof PrintedVariableEngine) {
parent::setSource($source);
} else {
$msg = "PrintedVariableProcessingException::setSource only accepts PrintedVariableEngine objects.";
throw new InvalidArgumentException($msg);
}
} | php | public function setSource(Processable $source)
{
if ($source instanceof PrintedVariableEngine) {
parent::setSource($source);
} else {
$msg = "PrintedVariableProcessingException::setSource only accepts PrintedVariableEngine objects.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setSource",
"(",
"Processable",
"$",
"source",
")",
"{",
"if",
"(",
"$",
"source",
"instanceof",
"PrintedVariableEngine",
")",
"{",
"parent",
"::",
"setSource",
"(",
"$",
"source",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"PrintedVariableProcessingException::setSource only accepts PrintedVariableEngine objects.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the source of the error.
@param \qtism\runtime\common\Processable $source The source of the error.
@throws \InvalidArgumentException If $source is not a PrintedVariableEngine object. | [
"Set",
"the",
"source",
"of",
"the",
"error",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/processing/PrintedVariableProcessingException.php#L44-L52 |
oat-sa/qti-sdk | src/qtism/common/enums/BaseType.php | BaseType.getConstantByName | public static function getConstantByName($name)
{
switch (trim(strtolower($name))) {
case 'identifier':
return self::IDENTIFIER;
break;
case 'boolean':
return self::BOOLEAN;
break;
case 'integer':
return self::INTEGER;
break;
case 'float':
return self::FLOAT;
break;
case 'string':
return self::STRING;
break;
case 'point':
return self::POINT;
break;
case 'pair':
return self::PAIR;
break;
case 'directedpair':
return self::DIRECTED_PAIR;
break;
case 'duration':
return self::DURATION;
break;
case 'file':
return self::FILE;
break;
case 'uri':
return self::URI;
break;
case 'intoridentifier':
return self::INT_OR_IDENTIFIER;
break;
case 'coords':
return self::COORDS;
break;
default:
return false;
break;
}
} | php | public static function getConstantByName($name)
{
switch (trim(strtolower($name))) {
case 'identifier':
return self::IDENTIFIER;
break;
case 'boolean':
return self::BOOLEAN;
break;
case 'integer':
return self::INTEGER;
break;
case 'float':
return self::FLOAT;
break;
case 'string':
return self::STRING;
break;
case 'point':
return self::POINT;
break;
case 'pair':
return self::PAIR;
break;
case 'directedpair':
return self::DIRECTED_PAIR;
break;
case 'duration':
return self::DURATION;
break;
case 'file':
return self::FILE;
break;
case 'uri':
return self::URI;
break;
case 'intoridentifier':
return self::INT_OR_IDENTIFIER;
break;
case 'coords':
return self::COORDS;
break;
default:
return false;
break;
}
} | [
"public",
"static",
"function",
"getConstantByName",
"(",
"$",
"name",
")",
"{",
"switch",
"(",
"trim",
"(",
"strtolower",
"(",
"$",
"name",
")",
")",
")",
"{",
"case",
"'identifier'",
":",
"return",
"self",
"::",
"IDENTIFIER",
";",
"break",
";",
"case",
"'boolean'",
":",
"return",
"self",
"::",
"BOOLEAN",
";",
"break",
";",
"case",
"'integer'",
":",
"return",
"self",
"::",
"INTEGER",
";",
"break",
";",
"case",
"'float'",
":",
"return",
"self",
"::",
"FLOAT",
";",
"break",
";",
"case",
"'string'",
":",
"return",
"self",
"::",
"STRING",
";",
"break",
";",
"case",
"'point'",
":",
"return",
"self",
"::",
"POINT",
";",
"break",
";",
"case",
"'pair'",
":",
"return",
"self",
"::",
"PAIR",
";",
"break",
";",
"case",
"'directedpair'",
":",
"return",
"self",
"::",
"DIRECTED_PAIR",
";",
"break",
";",
"case",
"'duration'",
":",
"return",
"self",
"::",
"DURATION",
";",
"break",
";",
"case",
"'file'",
":",
"return",
"self",
"::",
"FILE",
";",
"break",
";",
"case",
"'uri'",
":",
"return",
"self",
"::",
"URI",
";",
"break",
";",
"case",
"'intoridentifier'",
":",
"return",
"self",
"::",
"INT_OR_IDENTIFIER",
";",
"break",
";",
"case",
"'coords'",
":",
"return",
"self",
"::",
"COORDS",
";",
"break",
";",
"default",
":",
"return",
"false",
";",
"break",
";",
"}",
"}"
] | Get a constant value from the BaseType enumeration by baseType name.
* 'identifier' -> BaseType::IDENTIFIER
* 'boolean' -> BaseType::BOOLEAN
* 'integer' -> BaseType::INTEGER
* 'float' -> BaseType::FLOAT
* 'string' -> BaseType::STRING
* 'point' -> BaseType::POINT
* 'pair' -> BaseType::PAIR
* 'directedPair' -> BaseType::DIRECTED_PAIR
* 'duration' -> BaseType::DURATION
* 'file' -> BaseType::FILE
* 'uri' -> BaseType::URI
* 'intOrIdentifier' -> BaseType::INT_OR_IDENTIFIER
* extra 'coords' -> BaseType::COORDS
@param string $name The baseType name.
@return integer|boolean The related enumeration value or false if the name could not be resolved. | [
"Get",
"a",
"constant",
"value",
"from",
"the",
"BaseType",
"enumeration",
"by",
"baseType",
"name",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/enums/BaseType.php#L214-L273 |
oat-sa/qti-sdk | src/qtism/common/enums/BaseType.php | BaseType.getNameByConstant | public static function getNameByConstant($constant)
{
switch ($constant) {
case self::IDENTIFIER:
return 'identifier';
break;
case self::BOOLEAN:
return 'boolean';
break;
case self::INTEGER:
return 'integer';
break;
case self::FLOAT:
return 'float';
break;
case self::STRING:
return 'string';
break;
case self::POINT:
return 'point';
break;
case self::PAIR:
return 'pair';
break;
case self::DIRECTED_PAIR:
return 'directedPair';
break;
case self::DURATION:
return 'duration';
break;
case self::FILE:
return 'file';
break;
case self::URI:
return 'uri';
break;
case self::INT_OR_IDENTIFIER:
return 'intOrIdentifier';
break;
case self::COORDS:
return 'coords';
break;
default:
return false;
break;
}
} | php | public static function getNameByConstant($constant)
{
switch ($constant) {
case self::IDENTIFIER:
return 'identifier';
break;
case self::BOOLEAN:
return 'boolean';
break;
case self::INTEGER:
return 'integer';
break;
case self::FLOAT:
return 'float';
break;
case self::STRING:
return 'string';
break;
case self::POINT:
return 'point';
break;
case self::PAIR:
return 'pair';
break;
case self::DIRECTED_PAIR:
return 'directedPair';
break;
case self::DURATION:
return 'duration';
break;
case self::FILE:
return 'file';
break;
case self::URI:
return 'uri';
break;
case self::INT_OR_IDENTIFIER:
return 'intOrIdentifier';
break;
case self::COORDS:
return 'coords';
break;
default:
return false;
break;
}
} | [
"public",
"static",
"function",
"getNameByConstant",
"(",
"$",
"constant",
")",
"{",
"switch",
"(",
"$",
"constant",
")",
"{",
"case",
"self",
"::",
"IDENTIFIER",
":",
"return",
"'identifier'",
";",
"break",
";",
"case",
"self",
"::",
"BOOLEAN",
":",
"return",
"'boolean'",
";",
"break",
";",
"case",
"self",
"::",
"INTEGER",
":",
"return",
"'integer'",
";",
"break",
";",
"case",
"self",
"::",
"FLOAT",
":",
"return",
"'float'",
";",
"break",
";",
"case",
"self",
"::",
"STRING",
":",
"return",
"'string'",
";",
"break",
";",
"case",
"self",
"::",
"POINT",
":",
"return",
"'point'",
";",
"break",
";",
"case",
"self",
"::",
"PAIR",
":",
"return",
"'pair'",
";",
"break",
";",
"case",
"self",
"::",
"DIRECTED_PAIR",
":",
"return",
"'directedPair'",
";",
"break",
";",
"case",
"self",
"::",
"DURATION",
":",
"return",
"'duration'",
";",
"break",
";",
"case",
"self",
"::",
"FILE",
":",
"return",
"'file'",
";",
"break",
";",
"case",
"self",
"::",
"URI",
":",
"return",
"'uri'",
";",
"break",
";",
"case",
"self",
"::",
"INT_OR_IDENTIFIER",
":",
"return",
"'intOrIdentifier'",
";",
"break",
";",
"case",
"self",
"::",
"COORDS",
":",
"return",
"'coords'",
";",
"break",
";",
"default",
":",
"return",
"false",
";",
"break",
";",
"}",
"}"
] | Get the QTI name of a BaseType.
@param int $constant A constant value from the BaseType enumeration.
@return string|boolean The QTI name or false if not match. | [
"Get",
"the",
"QTI",
"name",
"of",
"a",
"BaseType",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/enums/BaseType.php#L281-L340 |
oat-sa/qti-sdk | src/qtism/common/beans/BeanProperty.php | BeanProperty.setProperty | protected function setProperty(ReflectionProperty $property)
{
if (mb_strpos($property->getDocComment(), Bean::ANNOTATION_PROPERTY, 0, 'UTF-8') !== false) {
$this->property = $property;
} else {
$msg = "The property must be annotated with '@qtism-bean-property'.";
throw new BeanException($msg, BeanException::NO_ANNOTATION);
}
} | php | protected function setProperty(ReflectionProperty $property)
{
if (mb_strpos($property->getDocComment(), Bean::ANNOTATION_PROPERTY, 0, 'UTF-8') !== false) {
$this->property = $property;
} else {
$msg = "The property must be annotated with '@qtism-bean-property'.";
throw new BeanException($msg, BeanException::NO_ANNOTATION);
}
} | [
"protected",
"function",
"setProperty",
"(",
"ReflectionProperty",
"$",
"property",
")",
"{",
"if",
"(",
"mb_strpos",
"(",
"$",
"property",
"->",
"getDocComment",
"(",
")",
",",
"Bean",
"::",
"ANNOTATION_PROPERTY",
",",
"0",
",",
"'UTF-8'",
")",
"!==",
"false",
")",
"{",
"$",
"this",
"->",
"property",
"=",
"$",
"property",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The property must be annotated with '@qtism-bean-property'.\"",
";",
"throw",
"new",
"BeanException",
"(",
"$",
"msg",
",",
"BeanException",
"::",
"NO_ANNOTATION",
")",
";",
"}",
"}"
] | Set the wrapped ReflectionProperty object.
@param \ReflectionProperty $property A ReflectionProperty object.
@throws \qtism\common\beans\BeanException If the given $property is not annotated with @qtism-bean-property. | [
"Set",
"the",
"wrapped",
"ReflectionProperty",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/beans/BeanProperty.php#L80-L88 |
oat-sa/qti-sdk | src/qtism/runtime/rendering/markup/Utils.php | Utils.printVariable | public static function printVariable(State $context, $identifier, $format = '', $powerForm = false, $base = 10, $index = -1, $delimiter = ';', $field = '', $mappingIndicator = '=')
{
try {
$printedVariable = new PrintedVariable($identifier);
$printedVariable->setFormat($format);
$printedVariable->setPowerForm($powerForm);
$printedVariable->setBase($base);
$printedVariable->setIndex($index);
$printedVariable->setDelimiter($delimiter);
$printedVariable->setField($field);
$printedVariable->setMappingIndicator($mappingIndicator);
$engine = new PrintedVariableEngine($printedVariable);
$engine->setContext($context);
return $engine->process();
} catch (Exception $e) {
$previous = $e->getMessage();
return "qtism\\runtime\\rendering\\markup\\Utils::printVariable() method threw an unexpected exception:\n${previous}.";
}
} | php | public static function printVariable(State $context, $identifier, $format = '', $powerForm = false, $base = 10, $index = -1, $delimiter = ';', $field = '', $mappingIndicator = '=')
{
try {
$printedVariable = new PrintedVariable($identifier);
$printedVariable->setFormat($format);
$printedVariable->setPowerForm($powerForm);
$printedVariable->setBase($base);
$printedVariable->setIndex($index);
$printedVariable->setDelimiter($delimiter);
$printedVariable->setField($field);
$printedVariable->setMappingIndicator($mappingIndicator);
$engine = new PrintedVariableEngine($printedVariable);
$engine->setContext($context);
return $engine->process();
} catch (Exception $e) {
$previous = $e->getMessage();
return "qtism\\runtime\\rendering\\markup\\Utils::printVariable() method threw an unexpected exception:\n${previous}.";
}
} | [
"public",
"static",
"function",
"printVariable",
"(",
"State",
"$",
"context",
",",
"$",
"identifier",
",",
"$",
"format",
"=",
"''",
",",
"$",
"powerForm",
"=",
"false",
",",
"$",
"base",
"=",
"10",
",",
"$",
"index",
"=",
"-",
"1",
",",
"$",
"delimiter",
"=",
"';'",
",",
"$",
"field",
"=",
"''",
",",
"$",
"mappingIndicator",
"=",
"'='",
")",
"{",
"try",
"{",
"$",
"printedVariable",
"=",
"new",
"PrintedVariable",
"(",
"$",
"identifier",
")",
";",
"$",
"printedVariable",
"->",
"setFormat",
"(",
"$",
"format",
")",
";",
"$",
"printedVariable",
"->",
"setPowerForm",
"(",
"$",
"powerForm",
")",
";",
"$",
"printedVariable",
"->",
"setBase",
"(",
"$",
"base",
")",
";",
"$",
"printedVariable",
"->",
"setIndex",
"(",
"$",
"index",
")",
";",
"$",
"printedVariable",
"->",
"setDelimiter",
"(",
"$",
"delimiter",
")",
";",
"$",
"printedVariable",
"->",
"setField",
"(",
"$",
"field",
")",
";",
"$",
"printedVariable",
"->",
"setMappingIndicator",
"(",
"$",
"mappingIndicator",
")",
";",
"$",
"engine",
"=",
"new",
"PrintedVariableEngine",
"(",
"$",
"printedVariable",
")",
";",
"$",
"engine",
"->",
"setContext",
"(",
"$",
"context",
")",
";",
"return",
"$",
"engine",
"->",
"process",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"previous",
"=",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"return",
"\"qtism\\\\runtime\\\\rendering\\\\markup\\\\Utils::printVariable() method threw an unexpected exception:\\n${previous}.\"",
";",
"}",
"}"
] | Helper method to be used in QTI template oriented rendering to produce the final
value of a qti:printedVariable component.
If an error occurs while printing the variable, the return value will contain the error message.
@param State $context A State object from where values will be retrieved prior to formatting, depending on the $identifier argument.
@param string $identifier The identifier of the variable to be printed.
@param string $format The ISO 9899 format string (see printf).
@param boolean $powerForm Render float values in 'e' or 'E' format.
@param integer|string $base The number base to use when formatting integer variables (can be a variable reference).
@param integer|string $index The index to use when displaying ordered cardinality variables (can be a variable reference).
@param integer $delimiter The delimiter to use between values when displaying ordered, multiple, or record cardinality variables.
@param string $field The field specifier to use when displaying variables of record cardinality.
@param string $mappingIndicator The mapping indicator to use between field name and field value when displaying record cardinality variables.
@return string The formatted variable or an error message. | [
"Helper",
"method",
"to",
"be",
"used",
"in",
"QTI",
"template",
"oriented",
"rendering",
"to",
"produce",
"the",
"final",
"value",
"of",
"a",
"qti",
":",
"printedVariable",
"component",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/markup/Utils.php#L58-L79 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/ResponseValidityConstraintMarshaller.php | ResponseValidityConstraintMarshaller.marshall | public function marshall(QtiComponent $component)
{
$element = self::getDOMCradle()->createElement('responseValidityConstraint');
$this->setDOMElementAttribute($element, 'responseIdentifier', $component->getResponseIdentifier());
$this->setDOMElementAttribute($element, 'minConstraint', $component->getMinConstraint());
$this->setDOMElementAttribute($element, 'maxConstraint', $component->getMaxConstraint());
if (($patternMask = $component->getPatternMask()) !== '') {
$this->setDOMElementAttribute($element, 'patternMask', $patternMask);
}
foreach ($component->getAssociationValidityConstraints() as $associationValidityConstraint) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($associationValidityConstraint);
$element->appendChild($marshaller->marshall($associationValidityConstraint));
}
return $element;
} | php | public function marshall(QtiComponent $component)
{
$element = self::getDOMCradle()->createElement('responseValidityConstraint');
$this->setDOMElementAttribute($element, 'responseIdentifier', $component->getResponseIdentifier());
$this->setDOMElementAttribute($element, 'minConstraint', $component->getMinConstraint());
$this->setDOMElementAttribute($element, 'maxConstraint', $component->getMaxConstraint());
if (($patternMask = $component->getPatternMask()) !== '') {
$this->setDOMElementAttribute($element, 'patternMask', $patternMask);
}
foreach ($component->getAssociationValidityConstraints() as $associationValidityConstraint) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($associationValidityConstraint);
$element->appendChild($marshaller->marshall($associationValidityConstraint));
}
return $element;
} | [
"public",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"$",
"element",
"=",
"self",
"::",
"getDOMCradle",
"(",
")",
"->",
"createElement",
"(",
"'responseValidityConstraint'",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'responseIdentifier'",
",",
"$",
"component",
"->",
"getResponseIdentifier",
"(",
")",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'minConstraint'",
",",
"$",
"component",
"->",
"getMinConstraint",
"(",
")",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'maxConstraint'",
",",
"$",
"component",
"->",
"getMaxConstraint",
"(",
")",
")",
";",
"if",
"(",
"(",
"$",
"patternMask",
"=",
"$",
"component",
"->",
"getPatternMask",
"(",
")",
")",
"!==",
"''",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'patternMask'",
",",
"$",
"patternMask",
")",
";",
"}",
"foreach",
"(",
"$",
"component",
"->",
"getAssociationValidityConstraints",
"(",
")",
"as",
"$",
"associationValidityConstraint",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"associationValidityConstraint",
")",
";",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"marshaller",
"->",
"marshall",
"(",
"$",
"associationValidityConstraint",
")",
")",
";",
"}",
"return",
"$",
"element",
";",
"}"
] | Marshall a ResponseValidityConstraint object to its XML counterpart.
@param \qtism\data\QtiComponent $component
@return \DOMElement | [
"Marshall",
"a",
"ResponseValidityConstraint",
"object",
"to",
"its",
"XML",
"counterpart",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/ResponseValidityConstraintMarshaller.php#L45-L62 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/ResponseValidityConstraintMarshaller.php | ResponseValidityConstraintMarshaller.unmarshall | public function unmarshall(DOMElement $element)
{
if (($responseIdentifier = $this->getDOMElementAttributeAs($element, 'responseIdentifier')) !== null) {
if (($minConstraint = $this->getDOMElementAttributeAs($element, 'minConstraint', 'integer')) !== null) {
if (($maxConstraint = $this->getDOMElementAttributeAs($element, 'maxConstraint', 'integer')) !== null) {
if (($patternMask = $this->getDOMElementAttributeAs($element, 'patternMask')) === null) {
$patternMask = '';
}
try {
$component = new ResponseValidityConstraint($responseIdentifier, $minConstraint, $maxConstraint, $patternMask);
// Find child associationValidityConstraint elements if any.
$associationValidityConstraintElts = $this->getChildElementsByTagName($element, 'associationValidityConstraint');
foreach ($associationValidityConstraintElts as $associationValidityConstraintElt) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($associationValidityConstraintElt);
$component->addAssociationValidityConstraint($marshaller->unmarshall($associationValidityConstraintElt));
}
return $component;
} catch (InvalidArgumentException $e) {
throw new UnmarshallingException(
"An error occured while unmarshalling a 'responseValidityConstraint'. See chained exceptions for more information.",
$element,
$e
);
}
} else {
throw new UnmarshallingException(
"The mandatory 'maxConstraint' attribute is missing from element 'responseValididtyConstraint'.",
$element
);
}
} else {
throw new UnmarshallingException(
"The mandatory 'minConstraint' attribute is missing from element 'responseValididtyConstraint'.",
$element
);
}
} else {
throw new UnmarshallingException(
"The mandatory 'responseIdentifier' attribute is missing from element 'responseValididtyConstraint'.",
$element
);
}
} | php | public function unmarshall(DOMElement $element)
{
if (($responseIdentifier = $this->getDOMElementAttributeAs($element, 'responseIdentifier')) !== null) {
if (($minConstraint = $this->getDOMElementAttributeAs($element, 'minConstraint', 'integer')) !== null) {
if (($maxConstraint = $this->getDOMElementAttributeAs($element, 'maxConstraint', 'integer')) !== null) {
if (($patternMask = $this->getDOMElementAttributeAs($element, 'patternMask')) === null) {
$patternMask = '';
}
try {
$component = new ResponseValidityConstraint($responseIdentifier, $minConstraint, $maxConstraint, $patternMask);
// Find child associationValidityConstraint elements if any.
$associationValidityConstraintElts = $this->getChildElementsByTagName($element, 'associationValidityConstraint');
foreach ($associationValidityConstraintElts as $associationValidityConstraintElt) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($associationValidityConstraintElt);
$component->addAssociationValidityConstraint($marshaller->unmarshall($associationValidityConstraintElt));
}
return $component;
} catch (InvalidArgumentException $e) {
throw new UnmarshallingException(
"An error occured while unmarshalling a 'responseValidityConstraint'. See chained exceptions for more information.",
$element,
$e
);
}
} else {
throw new UnmarshallingException(
"The mandatory 'maxConstraint' attribute is missing from element 'responseValididtyConstraint'.",
$element
);
}
} else {
throw new UnmarshallingException(
"The mandatory 'minConstraint' attribute is missing from element 'responseValididtyConstraint'.",
$element
);
}
} else {
throw new UnmarshallingException(
"The mandatory 'responseIdentifier' attribute is missing from element 'responseValididtyConstraint'.",
$element
);
}
} | [
"public",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"if",
"(",
"(",
"$",
"responseIdentifier",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'responseIdentifier'",
")",
")",
"!==",
"null",
")",
"{",
"if",
"(",
"(",
"$",
"minConstraint",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'minConstraint'",
",",
"'integer'",
")",
")",
"!==",
"null",
")",
"{",
"if",
"(",
"(",
"$",
"maxConstraint",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'maxConstraint'",
",",
"'integer'",
")",
")",
"!==",
"null",
")",
"{",
"if",
"(",
"(",
"$",
"patternMask",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'patternMask'",
")",
")",
"===",
"null",
")",
"{",
"$",
"patternMask",
"=",
"''",
";",
"}",
"try",
"{",
"$",
"component",
"=",
"new",
"ResponseValidityConstraint",
"(",
"$",
"responseIdentifier",
",",
"$",
"minConstraint",
",",
"$",
"maxConstraint",
",",
"$",
"patternMask",
")",
";",
"// Find child associationValidityConstraint elements if any.",
"$",
"associationValidityConstraintElts",
"=",
"$",
"this",
"->",
"getChildElementsByTagName",
"(",
"$",
"element",
",",
"'associationValidityConstraint'",
")",
";",
"foreach",
"(",
"$",
"associationValidityConstraintElts",
"as",
"$",
"associationValidityConstraintElt",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"associationValidityConstraintElt",
")",
";",
"$",
"component",
"->",
"addAssociationValidityConstraint",
"(",
"$",
"marshaller",
"->",
"unmarshall",
"(",
"$",
"associationValidityConstraintElt",
")",
")",
";",
"}",
"return",
"$",
"component",
";",
"}",
"catch",
"(",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"throw",
"new",
"UnmarshallingException",
"(",
"\"An error occured while unmarshalling a 'responseValidityConstraint'. See chained exceptions for more information.\"",
",",
"$",
"element",
",",
"$",
"e",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"UnmarshallingException",
"(",
"\"The mandatory 'maxConstraint' attribute is missing from element 'responseValididtyConstraint'.\"",
",",
"$",
"element",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"UnmarshallingException",
"(",
"\"The mandatory 'minConstraint' attribute is missing from element 'responseValididtyConstraint'.\"",
",",
"$",
"element",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"UnmarshallingException",
"(",
"\"The mandatory 'responseIdentifier' attribute is missing from element 'responseValididtyConstraint'.\"",
",",
"$",
"element",
")",
";",
"}",
"}"
] | Unmarshall a DOMElement to its ResponseValidityConstraint data model representation.
@param \DOMElement $element
@return \qtism\data\QtiComponent A ResponseValidityConstraint object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException | [
"Unmarshall",
"a",
"DOMElement",
"to",
"its",
"ResponseValidityConstraint",
"data",
"model",
"representation",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/ResponseValidityConstraintMarshaller.php#L71-L120 |
oat-sa/qti-sdk | src/qtism/runtime/rules/SetValueProcessor.php | SetValueProcessor.process | public function process()
{
$state = $this->getState();
$rule = $this->getRule();
$identifier = $rule->getIdentifier();
$var = $state->getVariable($identifier);
if (is_null($var) === true) {
$msg = "No variable with identifier '${identifier}' to be set in the current state.";
throw new RuleProcessingException($msg, $this, RuleProcessingException::NONEXISTENT_VARIABLE);
} elseif (Reflection::isInstanceOf($var, $this->getVariableType()) === false) {
$msg = "The variable to set '${identifier}' is not an instance of '" . $this->getVariableType() . "'.";
throw new RuleProcessingException($msg, $this, RuleProcessingException::WRONG_VARIABLE_TYPE);
}
// Process the expression.
// Its result will be the value to set to the target variable.
try {
$expressionEngine = new ExpressionEngine($rule->getExpression(), $state);
$val = $expressionEngine->process();
} catch (ExpressionProcessingException $e) {
$msg = "An error occured while processing the expression bound with the '" . Reflection::shortClassName($rule) . "' rule.";
throw new RuleProcessingException($msg, $this, RuleProcessingException::RUNTIME_ERROR, $e);
}
// The variable exists, its new value is processed.
try {
// juggle a little bit (int -> float, float -> int)
if ($val !== null && $var->getCardinality() === Cardinality::SINGLE) {
$baseType = $var->getBaseType();
// If we are trying to put a container in a scalar, let's make some changes...
if (($val->getCardinality() === Cardinality::MULTIPLE || $val->getCardinality() === Cardinality::ORDERED) && count($val) > 0) {
$val = $val[0];
}
if ($baseType === BaseType::INTEGER && $val instanceof QtiFloat) {
$val = new QtiInteger(intval($val->getValue()));
} elseif ($baseType === BaseType::FLOAT && $val instanceof QtiInteger) {
$val = new QtiFloat(floatval($val->getValue()));
}
}
$var->setValue($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 '${identifier}' (cardinality = ${varCardinality}, baseType = ${varBaseType}).";
throw new RuleProcessingException($msg, $this, RuleProcessingException::WRONG_VARIABLE_BASETYPE, $e);
}
} | php | public function process()
{
$state = $this->getState();
$rule = $this->getRule();
$identifier = $rule->getIdentifier();
$var = $state->getVariable($identifier);
if (is_null($var) === true) {
$msg = "No variable with identifier '${identifier}' to be set in the current state.";
throw new RuleProcessingException($msg, $this, RuleProcessingException::NONEXISTENT_VARIABLE);
} elseif (Reflection::isInstanceOf($var, $this->getVariableType()) === false) {
$msg = "The variable to set '${identifier}' is not an instance of '" . $this->getVariableType() . "'.";
throw new RuleProcessingException($msg, $this, RuleProcessingException::WRONG_VARIABLE_TYPE);
}
// Process the expression.
// Its result will be the value to set to the target variable.
try {
$expressionEngine = new ExpressionEngine($rule->getExpression(), $state);
$val = $expressionEngine->process();
} catch (ExpressionProcessingException $e) {
$msg = "An error occured while processing the expression bound with the '" . Reflection::shortClassName($rule) . "' rule.";
throw new RuleProcessingException($msg, $this, RuleProcessingException::RUNTIME_ERROR, $e);
}
// The variable exists, its new value is processed.
try {
// juggle a little bit (int -> float, float -> int)
if ($val !== null && $var->getCardinality() === Cardinality::SINGLE) {
$baseType = $var->getBaseType();
// If we are trying to put a container in a scalar, let's make some changes...
if (($val->getCardinality() === Cardinality::MULTIPLE || $val->getCardinality() === Cardinality::ORDERED) && count($val) > 0) {
$val = $val[0];
}
if ($baseType === BaseType::INTEGER && $val instanceof QtiFloat) {
$val = new QtiInteger(intval($val->getValue()));
} elseif ($baseType === BaseType::FLOAT && $val instanceof QtiInteger) {
$val = new QtiFloat(floatval($val->getValue()));
}
}
$var->setValue($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 '${identifier}' (cardinality = ${varCardinality}, baseType = ${varBaseType}).";
throw new RuleProcessingException($msg, $this, RuleProcessingException::WRONG_VARIABLE_BASETYPE, $e);
}
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"state",
"=",
"$",
"this",
"->",
"getState",
"(",
")",
";",
"$",
"rule",
"=",
"$",
"this",
"->",
"getRule",
"(",
")",
";",
"$",
"identifier",
"=",
"$",
"rule",
"->",
"getIdentifier",
"(",
")",
";",
"$",
"var",
"=",
"$",
"state",
"->",
"getVariable",
"(",
"$",
"identifier",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"var",
")",
"===",
"true",
")",
"{",
"$",
"msg",
"=",
"\"No variable with identifier '${identifier}' to be set in the current state.\"",
";",
"throw",
"new",
"RuleProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"RuleProcessingException",
"::",
"NONEXISTENT_VARIABLE",
")",
";",
"}",
"elseif",
"(",
"Reflection",
"::",
"isInstanceOf",
"(",
"$",
"var",
",",
"$",
"this",
"->",
"getVariableType",
"(",
")",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The variable to set '${identifier}' is not an instance of '\"",
".",
"$",
"this",
"->",
"getVariableType",
"(",
")",
".",
"\"'.\"",
";",
"throw",
"new",
"RuleProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"RuleProcessingException",
"::",
"WRONG_VARIABLE_TYPE",
")",
";",
"}",
"// Process the expression.",
"// Its result will be the value to set to the target variable.",
"try",
"{",
"$",
"expressionEngine",
"=",
"new",
"ExpressionEngine",
"(",
"$",
"rule",
"->",
"getExpression",
"(",
")",
",",
"$",
"state",
")",
";",
"$",
"val",
"=",
"$",
"expressionEngine",
"->",
"process",
"(",
")",
";",
"}",
"catch",
"(",
"ExpressionProcessingException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while processing the expression bound with the '\"",
".",
"Reflection",
"::",
"shortClassName",
"(",
"$",
"rule",
")",
".",
"\"' rule.\"",
";",
"throw",
"new",
"RuleProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"RuleProcessingException",
"::",
"RUNTIME_ERROR",
",",
"$",
"e",
")",
";",
"}",
"// The variable exists, its new value is processed.",
"try",
"{",
"// juggle a little bit (int -> float, float -> int)",
"if",
"(",
"$",
"val",
"!==",
"null",
"&&",
"$",
"var",
"->",
"getCardinality",
"(",
")",
"===",
"Cardinality",
"::",
"SINGLE",
")",
"{",
"$",
"baseType",
"=",
"$",
"var",
"->",
"getBaseType",
"(",
")",
";",
"// If we are trying to put a container in a scalar, let's make some changes...",
"if",
"(",
"(",
"$",
"val",
"->",
"getCardinality",
"(",
")",
"===",
"Cardinality",
"::",
"MULTIPLE",
"||",
"$",
"val",
"->",
"getCardinality",
"(",
")",
"===",
"Cardinality",
"::",
"ORDERED",
")",
"&&",
"count",
"(",
"$",
"val",
")",
">",
"0",
")",
"{",
"$",
"val",
"=",
"$",
"val",
"[",
"0",
"]",
";",
"}",
"if",
"(",
"$",
"baseType",
"===",
"BaseType",
"::",
"INTEGER",
"&&",
"$",
"val",
"instanceof",
"QtiFloat",
")",
"{",
"$",
"val",
"=",
"new",
"QtiInteger",
"(",
"intval",
"(",
"$",
"val",
"->",
"getValue",
"(",
")",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"baseType",
"===",
"BaseType",
"::",
"FLOAT",
"&&",
"$",
"val",
"instanceof",
"QtiInteger",
")",
"{",
"$",
"val",
"=",
"new",
"QtiFloat",
"(",
"floatval",
"(",
"$",
"val",
"->",
"getValue",
"(",
")",
")",
")",
";",
"}",
"}",
"$",
"var",
"->",
"setValue",
"(",
"$",
"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 '${identifier}' (cardinality = ${varCardinality}, baseType = ${varBaseType}).\"",
";",
"throw",
"new",
"RuleProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"RuleProcessingException",
"::",
"WRONG_VARIABLE_BASETYPE",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Process the setOutcomeValue/setTemplateValue rule.
A RuleProcessingException will be thrown if:
* The variable does not exist.
* The requested variable is not an OutcomeVariable/TemplateVariable.
* The variable's baseType does not match the baseType of the affected value.
* An error occurs while processing the related expression.
@throws \qtism\runtime\rules\RuleProcessingException If one of the error described above arise. | [
"Process",
"the",
"setOutcomeValue",
"/",
"setTemplateValue",
"rule",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rules/SetValueProcessor.php#L55-L106 |
oat-sa/qti-sdk | src/qtism/runtime/pci/json/Unmarshaller.php | Unmarshaller.unmarshall | public function unmarshall($json)
{
if (is_string($json) === true) {
$tmpJson = @json_decode($json, true);
if ($tmpJson === null) {
// An error occured while decoding.
$msg = "An error occured while decoding the following JSON data '" . mb_substr($json, 0, 30, 'UTF-8') . "...'.";
$code = UnmarshallingException::JSON_DECODE;
throw new UnmarshallingException($msg, $code);
}
$json = $tmpJson;
}
if (is_array($json) === false || count($json) === 0) {
$msg = "The '" . get_class($this) . "::unmarshall' method only accepts a JSON string or a non-empty array as argument, '";
if (is_object($json) === true) {
$msg .= get_class($json);
} else {
$msg .= gettype($json);
}
$msg .= "' given.";
$code = UnmarshallingException::NOT_SUPPORTED;
throw new UnmarshallingException($msg, $code);
}
if (Arrays::isAssoc($json) === false) {
$msg = "The '" . get_class($this) . "::unmarshall' does not accepts non-associative arrays.";
$code = UnmarshallingException::NOT_SUPPORTED;
throw new UnmarshallingException($msg, $code);
}
// Check whether or not $json is a state (no 'base' nor 'list' keys found),
// a base, a list or a record.
$keys = array_keys($json);
if (in_array('base', $keys) === true) {
// This is a base.
return $this->unmarshallUnit($json);
} elseif (in_array('list', $keys) === true) {
$keys = array_keys($json['list']);
if (isset($keys[0]) === false) {
$msg = "No baseType provided for list.";
throw new UnmarshallingException($msg, UnmarshallingException::NOT_PCI);
}
$baseType = BaseType::getConstantByName($keys[0]);
if ($baseType === false) {
$msg = "Unknown QTI baseType '" . $keys[0] . "'.";
$code = UnmarshallingException::NOT_PCI;
throw new UnmarshallingException($msg, $code);
}
$returnValue = new MultipleContainer($baseType);
// This is a list.
foreach ($json['list'][$keys[0]] as $v) {
if ($v === null) {
$returnValue[] = $this->unmarshallUnit(array('base' => $v));
} else {
$returnValue[] = $this->unmarshallUnit(array('base' => array($keys[0] => $v)));
}
}
return $returnValue;
} elseif (in_array('record' , $keys) === true) {
// This is a record.
$returnValue = new RecordContainer();
if (count($json['record']) === 0) {
return $returnValue;
}
foreach ($json['record'] as $v) {
if (isset($v['name']) === false) {
$msg = "No 'name' key found in record field.";
$code = UnmarshallingException::NOT_PCI;
throw new UnmarshallingException($msg, $code);
}
if (isset($v['base']) === true || (array_key_exists('base', $v) && $v['base'] === null)) {
$unit = array('base' => $v['base']);
} else {
// No value found, let's go for a null value.
$unit = array('base' => null);
}
$returnValue[$v['name']] = $this->unmarshallUnit($unit);
}
return $returnValue;
} else {
// This is a state.
$state = array();
foreach ($json as $k => $j) {
$state[$k] = $this->unmarshall($j);
}
return $state;
}
} | php | public function unmarshall($json)
{
if (is_string($json) === true) {
$tmpJson = @json_decode($json, true);
if ($tmpJson === null) {
// An error occured while decoding.
$msg = "An error occured while decoding the following JSON data '" . mb_substr($json, 0, 30, 'UTF-8') . "...'.";
$code = UnmarshallingException::JSON_DECODE;
throw new UnmarshallingException($msg, $code);
}
$json = $tmpJson;
}
if (is_array($json) === false || count($json) === 0) {
$msg = "The '" . get_class($this) . "::unmarshall' method only accepts a JSON string or a non-empty array as argument, '";
if (is_object($json) === true) {
$msg .= get_class($json);
} else {
$msg .= gettype($json);
}
$msg .= "' given.";
$code = UnmarshallingException::NOT_SUPPORTED;
throw new UnmarshallingException($msg, $code);
}
if (Arrays::isAssoc($json) === false) {
$msg = "The '" . get_class($this) . "::unmarshall' does not accepts non-associative arrays.";
$code = UnmarshallingException::NOT_SUPPORTED;
throw new UnmarshallingException($msg, $code);
}
// Check whether or not $json is a state (no 'base' nor 'list' keys found),
// a base, a list or a record.
$keys = array_keys($json);
if (in_array('base', $keys) === true) {
// This is a base.
return $this->unmarshallUnit($json);
} elseif (in_array('list', $keys) === true) {
$keys = array_keys($json['list']);
if (isset($keys[0]) === false) {
$msg = "No baseType provided for list.";
throw new UnmarshallingException($msg, UnmarshallingException::NOT_PCI);
}
$baseType = BaseType::getConstantByName($keys[0]);
if ($baseType === false) {
$msg = "Unknown QTI baseType '" . $keys[0] . "'.";
$code = UnmarshallingException::NOT_PCI;
throw new UnmarshallingException($msg, $code);
}
$returnValue = new MultipleContainer($baseType);
// This is a list.
foreach ($json['list'][$keys[0]] as $v) {
if ($v === null) {
$returnValue[] = $this->unmarshallUnit(array('base' => $v));
} else {
$returnValue[] = $this->unmarshallUnit(array('base' => array($keys[0] => $v)));
}
}
return $returnValue;
} elseif (in_array('record' , $keys) === true) {
// This is a record.
$returnValue = new RecordContainer();
if (count($json['record']) === 0) {
return $returnValue;
}
foreach ($json['record'] as $v) {
if (isset($v['name']) === false) {
$msg = "No 'name' key found in record field.";
$code = UnmarshallingException::NOT_PCI;
throw new UnmarshallingException($msg, $code);
}
if (isset($v['base']) === true || (array_key_exists('base', $v) && $v['base'] === null)) {
$unit = array('base' => $v['base']);
} else {
// No value found, let's go for a null value.
$unit = array('base' => null);
}
$returnValue[$v['name']] = $this->unmarshallUnit($unit);
}
return $returnValue;
} else {
// This is a state.
$state = array();
foreach ($json as $k => $j) {
$state[$k] = $this->unmarshall($j);
}
return $state;
}
} | [
"public",
"function",
"unmarshall",
"(",
"$",
"json",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"json",
")",
"===",
"true",
")",
"{",
"$",
"tmpJson",
"=",
"@",
"json_decode",
"(",
"$",
"json",
",",
"true",
")",
";",
"if",
"(",
"$",
"tmpJson",
"===",
"null",
")",
"{",
"// An error occured while decoding.",
"$",
"msg",
"=",
"\"An error occured while decoding the following JSON data '\"",
".",
"mb_substr",
"(",
"$",
"json",
",",
"0",
",",
"30",
",",
"'UTF-8'",
")",
".",
"\"...'.\"",
";",
"$",
"code",
"=",
"UnmarshallingException",
"::",
"JSON_DECODE",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"code",
")",
";",
"}",
"$",
"json",
"=",
"$",
"tmpJson",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"json",
")",
"===",
"false",
"||",
"count",
"(",
"$",
"json",
")",
"===",
"0",
")",
"{",
"$",
"msg",
"=",
"\"The '\"",
".",
"get_class",
"(",
"$",
"this",
")",
".",
"\"::unmarshall' method only accepts a JSON string or a non-empty array as argument, '\"",
";",
"if",
"(",
"is_object",
"(",
"$",
"json",
")",
"===",
"true",
")",
"{",
"$",
"msg",
".=",
"get_class",
"(",
"$",
"json",
")",
";",
"}",
"else",
"{",
"$",
"msg",
".=",
"gettype",
"(",
"$",
"json",
")",
";",
"}",
"$",
"msg",
".=",
"\"' given.\"",
";",
"$",
"code",
"=",
"UnmarshallingException",
"::",
"NOT_SUPPORTED",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"code",
")",
";",
"}",
"if",
"(",
"Arrays",
"::",
"isAssoc",
"(",
"$",
"json",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The '\"",
".",
"get_class",
"(",
"$",
"this",
")",
".",
"\"::unmarshall' does not accepts non-associative arrays.\"",
";",
"$",
"code",
"=",
"UnmarshallingException",
"::",
"NOT_SUPPORTED",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"code",
")",
";",
"}",
"// Check whether or not $json is a state (no 'base' nor 'list' keys found),",
"// a base, a list or a record.",
"$",
"keys",
"=",
"array_keys",
"(",
"$",
"json",
")",
";",
"if",
"(",
"in_array",
"(",
"'base'",
",",
"$",
"keys",
")",
"===",
"true",
")",
"{",
"// This is a base.",
"return",
"$",
"this",
"->",
"unmarshallUnit",
"(",
"$",
"json",
")",
";",
"}",
"elseif",
"(",
"in_array",
"(",
"'list'",
",",
"$",
"keys",
")",
"===",
"true",
")",
"{",
"$",
"keys",
"=",
"array_keys",
"(",
"$",
"json",
"[",
"'list'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"keys",
"[",
"0",
"]",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"No baseType provided for list.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"UnmarshallingException",
"::",
"NOT_PCI",
")",
";",
"}",
"$",
"baseType",
"=",
"BaseType",
"::",
"getConstantByName",
"(",
"$",
"keys",
"[",
"0",
"]",
")",
";",
"if",
"(",
"$",
"baseType",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"Unknown QTI baseType '\"",
".",
"$",
"keys",
"[",
"0",
"]",
".",
"\"'.\"",
";",
"$",
"code",
"=",
"UnmarshallingException",
"::",
"NOT_PCI",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"code",
")",
";",
"}",
"$",
"returnValue",
"=",
"new",
"MultipleContainer",
"(",
"$",
"baseType",
")",
";",
"// This is a list.",
"foreach",
"(",
"$",
"json",
"[",
"'list'",
"]",
"[",
"$",
"keys",
"[",
"0",
"]",
"]",
"as",
"$",
"v",
")",
"{",
"if",
"(",
"$",
"v",
"===",
"null",
")",
"{",
"$",
"returnValue",
"[",
"]",
"=",
"$",
"this",
"->",
"unmarshallUnit",
"(",
"array",
"(",
"'base'",
"=>",
"$",
"v",
")",
")",
";",
"}",
"else",
"{",
"$",
"returnValue",
"[",
"]",
"=",
"$",
"this",
"->",
"unmarshallUnit",
"(",
"array",
"(",
"'base'",
"=>",
"array",
"(",
"$",
"keys",
"[",
"0",
"]",
"=>",
"$",
"v",
")",
")",
")",
";",
"}",
"}",
"return",
"$",
"returnValue",
";",
"}",
"elseif",
"(",
"in_array",
"(",
"'record'",
",",
"$",
"keys",
")",
"===",
"true",
")",
"{",
"// This is a record.",
"$",
"returnValue",
"=",
"new",
"RecordContainer",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"json",
"[",
"'record'",
"]",
")",
"===",
"0",
")",
"{",
"return",
"$",
"returnValue",
";",
"}",
"foreach",
"(",
"$",
"json",
"[",
"'record'",
"]",
"as",
"$",
"v",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"v",
"[",
"'name'",
"]",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"No 'name' key found in record field.\"",
";",
"$",
"code",
"=",
"UnmarshallingException",
"::",
"NOT_PCI",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"code",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"v",
"[",
"'base'",
"]",
")",
"===",
"true",
"||",
"(",
"array_key_exists",
"(",
"'base'",
",",
"$",
"v",
")",
"&&",
"$",
"v",
"[",
"'base'",
"]",
"===",
"null",
")",
")",
"{",
"$",
"unit",
"=",
"array",
"(",
"'base'",
"=>",
"$",
"v",
"[",
"'base'",
"]",
")",
";",
"}",
"else",
"{",
"// No value found, let's go for a null value.",
"$",
"unit",
"=",
"array",
"(",
"'base'",
"=>",
"null",
")",
";",
"}",
"$",
"returnValue",
"[",
"$",
"v",
"[",
"'name'",
"]",
"]",
"=",
"$",
"this",
"->",
"unmarshallUnit",
"(",
"$",
"unit",
")",
";",
"}",
"return",
"$",
"returnValue",
";",
"}",
"else",
"{",
"// This is a state.",
"$",
"state",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"json",
"as",
"$",
"k",
"=>",
"$",
"j",
")",
"{",
"$",
"state",
"[",
"$",
"k",
"]",
"=",
"$",
"this",
"->",
"unmarshall",
"(",
"$",
"j",
")",
";",
"}",
"return",
"$",
"state",
";",
"}",
"}"
] | Transform a PCI JSON representation of QTI data into the QTISM runtime model.
@param string|array $json The json data to be transformed.
@throws \qtism\runtime\pci\json\UnmarshallingException If an error occurs while processing $json.
@return null|qtism\common\datatypes\QtiDataType|array | [
"Transform",
"a",
"PCI",
"JSON",
"representation",
"of",
"QTI",
"data",
"into",
"the",
"QTISM",
"runtime",
"model",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/pci/json/Unmarshaller.php#L108-L213 |
oat-sa/qti-sdk | src/qtism/runtime/pci/json/Unmarshaller.php | Unmarshaller.unmarshallUnit | protected function unmarshallUnit(array $unit)
{
if (isset($unit['base'])) {
// Primitive base type.
try {
$keys = array_keys($unit['base']);
switch ($keys[0]) {
case 'boolean':
return $this->unmarshallBoolean($unit);
break;
case 'integer':
return $this->unmarshallInteger($unit);
break;
case 'float':
return $this->unmarshallFloat($unit);
break;
case 'string':
return $this->unmarshallString($unit);
break;
case 'point':
return $this->unmarshallPoint($unit);
break;
case 'pair':
return $this->unmarshallPair($unit);
break;
case 'directedPair':
return $this->unmarshallDirectedPair($unit);
break;
case 'duration':
return $this->unmarshallDuration($unit);
break;
case 'file':
return $this->unmarshallFile($unit);
break;
case 'uri':
return $this->unmarshallUri($unit);
break;
case 'intOrIdentifier':
return $this->unmarshallIntOrIdentifier($unit);
break;
case 'identifier':
return $this->unmarshallIdentifier($unit);
break;
default:
throw new UnmarshallingException("Unknown QTI baseType '" . $keys[0] . "'");
break;
}
} catch (InvalidArgumentException $e) {
$msg = "A value does not satisfy its baseType.";
throw new UnmarshallingException($msg, UnmarshallingException::NOT_PCI, $e);
}
} elseif ($unit['base'] === null) {
return null;
}
} | php | protected function unmarshallUnit(array $unit)
{
if (isset($unit['base'])) {
// Primitive base type.
try {
$keys = array_keys($unit['base']);
switch ($keys[0]) {
case 'boolean':
return $this->unmarshallBoolean($unit);
break;
case 'integer':
return $this->unmarshallInteger($unit);
break;
case 'float':
return $this->unmarshallFloat($unit);
break;
case 'string':
return $this->unmarshallString($unit);
break;
case 'point':
return $this->unmarshallPoint($unit);
break;
case 'pair':
return $this->unmarshallPair($unit);
break;
case 'directedPair':
return $this->unmarshallDirectedPair($unit);
break;
case 'duration':
return $this->unmarshallDuration($unit);
break;
case 'file':
return $this->unmarshallFile($unit);
break;
case 'uri':
return $this->unmarshallUri($unit);
break;
case 'intOrIdentifier':
return $this->unmarshallIntOrIdentifier($unit);
break;
case 'identifier':
return $this->unmarshallIdentifier($unit);
break;
default:
throw new UnmarshallingException("Unknown QTI baseType '" . $keys[0] . "'");
break;
}
} catch (InvalidArgumentException $e) {
$msg = "A value does not satisfy its baseType.";
throw new UnmarshallingException($msg, UnmarshallingException::NOT_PCI, $e);
}
} elseif ($unit['base'] === null) {
return null;
}
} | [
"protected",
"function",
"unmarshallUnit",
"(",
"array",
"$",
"unit",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"unit",
"[",
"'base'",
"]",
")",
")",
"{",
"// Primitive base type.",
"try",
"{",
"$",
"keys",
"=",
"array_keys",
"(",
"$",
"unit",
"[",
"'base'",
"]",
")",
";",
"switch",
"(",
"$",
"keys",
"[",
"0",
"]",
")",
"{",
"case",
"'boolean'",
":",
"return",
"$",
"this",
"->",
"unmarshallBoolean",
"(",
"$",
"unit",
")",
";",
"break",
";",
"case",
"'integer'",
":",
"return",
"$",
"this",
"->",
"unmarshallInteger",
"(",
"$",
"unit",
")",
";",
"break",
";",
"case",
"'float'",
":",
"return",
"$",
"this",
"->",
"unmarshallFloat",
"(",
"$",
"unit",
")",
";",
"break",
";",
"case",
"'string'",
":",
"return",
"$",
"this",
"->",
"unmarshallString",
"(",
"$",
"unit",
")",
";",
"break",
";",
"case",
"'point'",
":",
"return",
"$",
"this",
"->",
"unmarshallPoint",
"(",
"$",
"unit",
")",
";",
"break",
";",
"case",
"'pair'",
":",
"return",
"$",
"this",
"->",
"unmarshallPair",
"(",
"$",
"unit",
")",
";",
"break",
";",
"case",
"'directedPair'",
":",
"return",
"$",
"this",
"->",
"unmarshallDirectedPair",
"(",
"$",
"unit",
")",
";",
"break",
";",
"case",
"'duration'",
":",
"return",
"$",
"this",
"->",
"unmarshallDuration",
"(",
"$",
"unit",
")",
";",
"break",
";",
"case",
"'file'",
":",
"return",
"$",
"this",
"->",
"unmarshallFile",
"(",
"$",
"unit",
")",
";",
"break",
";",
"case",
"'uri'",
":",
"return",
"$",
"this",
"->",
"unmarshallUri",
"(",
"$",
"unit",
")",
";",
"break",
";",
"case",
"'intOrIdentifier'",
":",
"return",
"$",
"this",
"->",
"unmarshallIntOrIdentifier",
"(",
"$",
"unit",
")",
";",
"break",
";",
"case",
"'identifier'",
":",
"return",
"$",
"this",
"->",
"unmarshallIdentifier",
"(",
"$",
"unit",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"UnmarshallingException",
"(",
"\"Unknown QTI baseType '\"",
".",
"$",
"keys",
"[",
"0",
"]",
".",
"\"'\"",
")",
";",
"break",
";",
"}",
"}",
"catch",
"(",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"A value does not satisfy its baseType.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"UnmarshallingException",
"::",
"NOT_PCI",
",",
"$",
"e",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"unit",
"[",
"'base'",
"]",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"}"
] | Unmarshall a unit of data into QTISM runtime model.
@param array $unit
@throws \qtism\runtime\pci\json\UnmarshallingException
@return null|qtism\common\datatypes\QtiDatatype | [
"Unmarshall",
"a",
"unit",
"of",
"data",
"into",
"QTISM",
"runtime",
"model",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/pci/json/Unmarshaller.php#L222-L289 |
oat-sa/qti-sdk | src/qtism/runtime/pci/json/Unmarshaller.php | Unmarshaller.unmarshallFloat | protected function unmarshallFloat(array $unit)
{
$val = $unit['base']['float'];
if (is_int($val) === true) {
$val = floatval($val);
}
return new QtiFloat($val);
} | php | protected function unmarshallFloat(array $unit)
{
$val = $unit['base']['float'];
if (is_int($val) === true) {
$val = floatval($val);
}
return new QtiFloat($val);
} | [
"protected",
"function",
"unmarshallFloat",
"(",
"array",
"$",
"unit",
")",
"{",
"$",
"val",
"=",
"$",
"unit",
"[",
"'base'",
"]",
"[",
"'float'",
"]",
";",
"if",
"(",
"is_int",
"(",
"$",
"val",
")",
"===",
"true",
")",
"{",
"$",
"val",
"=",
"floatval",
"(",
"$",
"val",
")",
";",
"}",
"return",
"new",
"QtiFloat",
"(",
"$",
"val",
")",
";",
"}"
] | Unmarshall a float JSON PCI representation.
@param array $unit
@return \qtism\common\datatypes\Float | [
"Unmarshall",
"a",
"float",
"JSON",
"PCI",
"representation",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/pci/json/Unmarshaller.php#L319-L328 |
oat-sa/qti-sdk | src/qtism/runtime/pci/json/Unmarshaller.php | Unmarshaller.unmarshallFile | protected function unmarshallFile(array $unit)
{
$filename = (empty($unit['base']['file']['name']) === true) ? '' : $unit['base']['file']['name'];
return $this->getFileManager()->createFromData(base64_decode($unit['base']['file']['data']), $unit['base']['file']['mime'], $filename);
} | php | protected function unmarshallFile(array $unit)
{
$filename = (empty($unit['base']['file']['name']) === true) ? '' : $unit['base']['file']['name'];
return $this->getFileManager()->createFromData(base64_decode($unit['base']['file']['data']), $unit['base']['file']['mime'], $filename);
} | [
"protected",
"function",
"unmarshallFile",
"(",
"array",
"$",
"unit",
")",
"{",
"$",
"filename",
"=",
"(",
"empty",
"(",
"$",
"unit",
"[",
"'base'",
"]",
"[",
"'file'",
"]",
"[",
"'name'",
"]",
")",
"===",
"true",
")",
"?",
"''",
":",
"$",
"unit",
"[",
"'base'",
"]",
"[",
"'file'",
"]",
"[",
"'name'",
"]",
";",
"return",
"$",
"this",
"->",
"getFileManager",
"(",
")",
"->",
"createFromData",
"(",
"base64_decode",
"(",
"$",
"unit",
"[",
"'base'",
"]",
"[",
"'file'",
"]",
"[",
"'data'",
"]",
")",
",",
"$",
"unit",
"[",
"'base'",
"]",
"[",
"'file'",
"]",
"[",
"'mime'",
"]",
",",
"$",
"filename",
")",
";",
"}"
] | Unmarshall a duration JSON PCI representation.
@param array $unit
@return \qtism\common\datatypes\File | [
"Unmarshall",
"a",
"duration",
"JSON",
"PCI",
"representation",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/pci/json/Unmarshaller.php#L391-L396 |
oat-sa/qti-sdk | src/qtism/runtime/rendering/qtipl/expressions/operators/NotQtiPLRenderer.php | NotQtiPLRenderer.render | public function render($something)
{
$renderer = new QtiPLRenderer($this->getCRO());
$orenderer = new OperatorQtiPLRenderer($this->getCRO());
$needsparenthesis0 = array_key_exists($something->getExpressions()[0]->getQtiClassName(),
$orenderer->getSignAsOperatorMap())
&& $something->getExpressions()[0]->getExpressions()->count() == 2;
if ($needsparenthesis0) {
return $this->signAsOperator . $renderer->writeChildElements($something->getExpressions());
}
else {
return $this->signAsOperator . $renderer->render($something->getExpressions()[0]);
}
} | php | public function render($something)
{
$renderer = new QtiPLRenderer($this->getCRO());
$orenderer = new OperatorQtiPLRenderer($this->getCRO());
$needsparenthesis0 = array_key_exists($something->getExpressions()[0]->getQtiClassName(),
$orenderer->getSignAsOperatorMap())
&& $something->getExpressions()[0]->getExpressions()->count() == 2;
if ($needsparenthesis0) {
return $this->signAsOperator . $renderer->writeChildElements($something->getExpressions());
}
else {
return $this->signAsOperator . $renderer->render($something->getExpressions()[0]);
}
} | [
"public",
"function",
"render",
"(",
"$",
"something",
")",
"{",
"$",
"renderer",
"=",
"new",
"QtiPLRenderer",
"(",
"$",
"this",
"->",
"getCRO",
"(",
")",
")",
";",
"$",
"orenderer",
"=",
"new",
"OperatorQtiPLRenderer",
"(",
"$",
"this",
"->",
"getCRO",
"(",
")",
")",
";",
"$",
"needsparenthesis0",
"=",
"array_key_exists",
"(",
"$",
"something",
"->",
"getExpressions",
"(",
")",
"[",
"0",
"]",
"->",
"getQtiClassName",
"(",
")",
",",
"$",
"orenderer",
"->",
"getSignAsOperatorMap",
"(",
")",
")",
"&&",
"$",
"something",
"->",
"getExpressions",
"(",
")",
"[",
"0",
"]",
"->",
"getExpressions",
"(",
")",
"->",
"count",
"(",
")",
"==",
"2",
";",
"if",
"(",
"$",
"needsparenthesis0",
")",
"{",
"return",
"$",
"this",
"->",
"signAsOperator",
".",
"$",
"renderer",
"->",
"writeChildElements",
"(",
"$",
"something",
"->",
"getExpressions",
"(",
")",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"signAsOperator",
".",
"$",
"renderer",
"->",
"render",
"(",
"$",
"something",
"->",
"getExpressions",
"(",
")",
"[",
"0",
"]",
")",
";",
"}",
"}"
] | 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/NotQtiPLRenderer.php#L48-L63 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/PatternMatchMarshaller.php | PatternMatchMarshaller.unmarshallChildrenKnown | protected function unmarshallChildrenKnown(DOMElement $element, QtiComponentCollection $children)
{
if (($pattern = $this->getDOMElementAttributeAs($element, 'pattern')) !== null) {
$object = new PatternMatch($children, $pattern);
return $object;
} else {
$msg = "The mandatory attribute 'pattern' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} | php | protected function unmarshallChildrenKnown(DOMElement $element, QtiComponentCollection $children)
{
if (($pattern = $this->getDOMElementAttributeAs($element, 'pattern')) !== null) {
$object = new PatternMatch($children, $pattern);
return $object;
} else {
$msg = "The mandatory attribute 'pattern' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} | [
"protected",
"function",
"unmarshallChildrenKnown",
"(",
"DOMElement",
"$",
"element",
",",
"QtiComponentCollection",
"$",
"children",
")",
"{",
"if",
"(",
"(",
"$",
"pattern",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'pattern'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"object",
"=",
"new",
"PatternMatch",
"(",
"$",
"children",
",",
"$",
"pattern",
")",
";",
"return",
"$",
"object",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory attribute 'pattern' is missing from element '\"",
".",
"$",
"element",
"->",
"localName",
".",
"\"'.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}"
] | Unmarshall a QTI patternMatch operator element into an PatternMatch object.
@param \DOMElement The patternMatch element to unmarshall.
@param \qtism\data\QtiComponentCollection A collection containing the child Expression objects composing the Operator.
@return \qtism\data\QtiComponent A PatternMatch object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException | [
"Unmarshall",
"a",
"QTI",
"patternMatch",
"operator",
"element",
"into",
"an",
"PatternMatch",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/PatternMatchMarshaller.php#L66-L77 |
oat-sa/qti-sdk | src/qtism/data/content/xhtml/ObjectElement.php | ObjectElement.setData | public function setData($data)
{
if ((is_string($data) === true && $data === '') || Format::isUri($data) === true) {
$this->data = $data;
} else {
$msg = "The 'data' argument must be a URI or an empty string, '" . gettype($data) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setData($data)
{
if ((is_string($data) === true && $data === '') || Format::isUri($data) === true) {
$this->data = $data;
} else {
$msg = "The 'data' argument must be a URI or an empty string, '" . gettype($data) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setData",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"(",
"is_string",
"(",
"$",
"data",
")",
"===",
"true",
"&&",
"$",
"data",
"===",
"''",
")",
"||",
"Format",
"::",
"isUri",
"(",
"$",
"data",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"data",
"=",
"$",
"data",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'data' argument must be a URI or an empty string, '\"",
".",
"gettype",
"(",
"$",
"data",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the URI for locating the data of the object.
@param string $data The URI for locating the data of the object.
@throws \InvalidArgumentException If $data is not a URI. | [
"Set",
"the",
"URI",
"for",
"locating",
"the",
"data",
"of",
"the",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/xhtml/ObjectElement.php#L114-L122 |
oat-sa/qti-sdk | src/qtism/data/content/xhtml/ObjectElement.php | ObjectElement.setWidth | public function setWidth($width)
{
if (is_int($width) === true) {
$this->width = $width;
} else {
$msg = "The 'width' argument must be an integer, '" . gettype($width) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setWidth($width)
{
if (is_int($width) === true) {
$this->width = $width;
} else {
$msg = "The 'width' argument must be an integer, '" . gettype($width) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setWidth",
"(",
"$",
"width",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"width",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"width",
"=",
"$",
"width",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'width' argument must be an integer, '\"",
".",
"gettype",
"(",
"$",
"width",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the width of the object.
A negative value describes that no width is provided.
@param integer $width A width.
@throws \InvalidArgumentException | [
"Set",
"the",
"width",
"of",
"the",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/xhtml/ObjectElement.php#L168-L176 |
oat-sa/qti-sdk | src/qtism/data/content/xhtml/ObjectElement.php | ObjectElement.setHeight | public function setHeight($height)
{
if (is_int($height) === true) {
$this->height = $height;
} else {
$msg = "The 'height' argument must be an integer, '" . gettype($height) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setHeight($height)
{
if (is_int($height) === true) {
$this->height = $height;
} else {
$msg = "The 'height' argument must be an integer, '" . gettype($height) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setHeight",
"(",
"$",
"height",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"height",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"height",
"=",
"$",
"height",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'height' argument must be an integer, '\"",
".",
"gettype",
"(",
"$",
"height",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the height of the object.
A negative value describes that no height is provided.
@param integer $height A height.
@throws \InvalidArgumentException If $height is not an integer value. | [
"Set",
"the",
"height",
"of",
"the",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/xhtml/ObjectElement.php#L208-L216 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/ModalFeedbackRuleMarshaller.php | ModalFeedbackRuleMarshaller.marshall | public function marshall(QtiComponent $component)
{
$element = self::getDOMCradle()->createElement('modalFeedbackRule');
$this->setDOMElementAttribute($element, 'outcomeIdentifier', $component->getOutcomeIdentifier());
$this->setDOMElementAttribute($element, 'showHide', ShowHide::getNameByConstant($component->getShowHide()));
$this->setDOMElementAttribute($element, 'identifier', $component->getIdentifier());
if ($component->hasTitle() === true) {
$this->setDOMElementAttribute($element, 'title', $component->getTitle());
}
return $element;
} | php | public function marshall(QtiComponent $component)
{
$element = self::getDOMCradle()->createElement('modalFeedbackRule');
$this->setDOMElementAttribute($element, 'outcomeIdentifier', $component->getOutcomeIdentifier());
$this->setDOMElementAttribute($element, 'showHide', ShowHide::getNameByConstant($component->getShowHide()));
$this->setDOMElementAttribute($element, 'identifier', $component->getIdentifier());
if ($component->hasTitle() === true) {
$this->setDOMElementAttribute($element, 'title', $component->getTitle());
}
return $element;
} | [
"public",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"$",
"element",
"=",
"self",
"::",
"getDOMCradle",
"(",
")",
"->",
"createElement",
"(",
"'modalFeedbackRule'",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'outcomeIdentifier'",
",",
"$",
"component",
"->",
"getOutcomeIdentifier",
"(",
")",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'showHide'",
",",
"ShowHide",
"::",
"getNameByConstant",
"(",
"$",
"component",
"->",
"getShowHide",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'identifier'",
",",
"$",
"component",
"->",
"getIdentifier",
"(",
")",
")",
";",
"if",
"(",
"$",
"component",
"->",
"hasTitle",
"(",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'title'",
",",
"$",
"component",
"->",
"getTitle",
"(",
")",
")",
";",
"}",
"return",
"$",
"element",
";",
"}"
] | Marshall a ModalFeedbackRule object to its XML counterpart.
@param \qtism\data\QtiComponent $component
@return \DOMElement | [
"Marshall",
"a",
"ModalFeedbackRule",
"object",
"to",
"its",
"XML",
"counterpart",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/ModalFeedbackRuleMarshaller.php#L44-L56 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/ModalFeedbackRuleMarshaller.php | ModalFeedbackRuleMarshaller.unmarshall | public function unmarshall(DOMElement $element)
{
if (($identifier = $this->getDOMElementAttributeAs($element, 'identifier')) !== null) {
if (($outcomeIdentifier = $this->getDOMElementAttributeAs($element, 'outcomeIdentifier')) !== null) {
if (($showHide = $this->getDOMElementAttributeAs($element, 'showHide', 'string')) !== null) {
$showHide = ShowHide::getConstantByName($showHide);
$component = new ModalFeedbackRule($outcomeIdentifier, $showHide, $identifier);
if (($title = $this->getDOMElementAttributeAs($element, 'title')) !== null) {
$component->setTitle($title);
}
return $component;
} else {
$msg = "The mandatory 'showHide' attribute is missing from element 'modalFeedbackRule'.";
throw new UnmarshallingException($msg, $element);
}
} else {
$msg = "The mandatory 'outcomeIdentifier' attribute is missing from element 'modalFeedbackRule'.";
throw new UnmarshallingException($msg, $element);
}
} else {
$msg = "The mandatory 'identifier' attribute is missing from element 'modalFeedbackRule'.";
throw new UnmarshallingException($msg, $element);
}
} | php | public function unmarshall(DOMElement $element)
{
if (($identifier = $this->getDOMElementAttributeAs($element, 'identifier')) !== null) {
if (($outcomeIdentifier = $this->getDOMElementAttributeAs($element, 'outcomeIdentifier')) !== null) {
if (($showHide = $this->getDOMElementAttributeAs($element, 'showHide', 'string')) !== null) {
$showHide = ShowHide::getConstantByName($showHide);
$component = new ModalFeedbackRule($outcomeIdentifier, $showHide, $identifier);
if (($title = $this->getDOMElementAttributeAs($element, 'title')) !== null) {
$component->setTitle($title);
}
return $component;
} else {
$msg = "The mandatory 'showHide' attribute is missing from element 'modalFeedbackRule'.";
throw new UnmarshallingException($msg, $element);
}
} else {
$msg = "The mandatory 'outcomeIdentifier' attribute is missing from element 'modalFeedbackRule'.";
throw new UnmarshallingException($msg, $element);
}
} else {
$msg = "The mandatory 'identifier' attribute is missing from element 'modalFeedbackRule'.";
throw new UnmarshallingException($msg, $element);
}
} | [
"public",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"if",
"(",
"(",
"$",
"identifier",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'identifier'",
")",
")",
"!==",
"null",
")",
"{",
"if",
"(",
"(",
"$",
"outcomeIdentifier",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'outcomeIdentifier'",
")",
")",
"!==",
"null",
")",
"{",
"if",
"(",
"(",
"$",
"showHide",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'showHide'",
",",
"'string'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"showHide",
"=",
"ShowHide",
"::",
"getConstantByName",
"(",
"$",
"showHide",
")",
";",
"$",
"component",
"=",
"new",
"ModalFeedbackRule",
"(",
"$",
"outcomeIdentifier",
",",
"$",
"showHide",
",",
"$",
"identifier",
")",
";",
"if",
"(",
"(",
"$",
"title",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'title'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"component",
"->",
"setTitle",
"(",
"$",
"title",
")",
";",
"}",
"return",
"$",
"component",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory 'showHide' attribute is missing from element 'modalFeedbackRule'.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory 'outcomeIdentifier' attribute is missing from element 'modalFeedbackRule'.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory 'identifier' attribute is missing from element 'modalFeedbackRule'.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}"
] | Unmarshall a DOMElement to its ModalFeedbackRule data model representation.
@param \DOMElement $element
@return \qtism\data\QtiComponent A ModalFeedbackRule object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException If the 'identifier', 'outcomeIdentifier', 'showHide', or attribute is missing from the XML definition. | [
"Unmarshall",
"a",
"DOMElement",
"to",
"its",
"ModalFeedbackRule",
"data",
"model",
"representation",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/ModalFeedbackRuleMarshaller.php#L65-L96 |
oat-sa/qti-sdk | src/qtism/data/state/MapEntry.php | MapEntry.setMappedValue | public function setMappedValue($mappedValue)
{
if (is_float($mappedValue) || is_double($mappedValue)) {
$this->mappedValue = $mappedValue;
} else {
$msg = "The attribute 'mappedValue' must be a float value, '" . gettype($mappedValue) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setMappedValue($mappedValue)
{
if (is_float($mappedValue) || is_double($mappedValue)) {
$this->mappedValue = $mappedValue;
} else {
$msg = "The attribute 'mappedValue' must be a float value, '" . gettype($mappedValue) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setMappedValue",
"(",
"$",
"mappedValue",
")",
"{",
"if",
"(",
"is_float",
"(",
"$",
"mappedValue",
")",
"||",
"is_double",
"(",
"$",
"mappedValue",
")",
")",
"{",
"$",
"this",
"->",
"mappedValue",
"=",
"$",
"mappedValue",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The attribute 'mappedValue' must be a float value, '\"",
".",
"gettype",
"(",
"$",
"mappedValue",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the mapped value.
@param float $mappedValue A mapped value.
@throws \InvalidArgumentException If $mappedValue is not a float value. | [
"Set",
"the",
"mapped",
"value",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/state/MapEntry.php#L114-L122 |
oat-sa/qti-sdk | src/qtism/data/state/MapEntry.php | MapEntry.setCaseSensitive | public function setCaseSensitive($caseSensitive)
{
if (is_bool($caseSensitive)) {
$this->caseSensitive = $caseSensitive;
} else {
$msg = "The attribute 'caseSensitive' must be a boolean value, '" . gettype($caseSensitive) . "'.";
throw new InvalidArgumentException($msg);
}
} | php | public function setCaseSensitive($caseSensitive)
{
if (is_bool($caseSensitive)) {
$this->caseSensitive = $caseSensitive;
} else {
$msg = "The attribute 'caseSensitive' must be a boolean value, '" . gettype($caseSensitive) . "'.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setCaseSensitive",
"(",
"$",
"caseSensitive",
")",
"{",
"if",
"(",
"is_bool",
"(",
"$",
"caseSensitive",
")",
")",
"{",
"$",
"this",
"->",
"caseSensitive",
"=",
"$",
"caseSensitive",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The attribute 'caseSensitive' must be a boolean value, '\"",
".",
"gettype",
"(",
"$",
"caseSensitive",
")",
".",
"\"'.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set whether the mapEntry string is matched case sensitively.
@param boolean $caseSensitive
@throws \InvalidArgumentException If $caseSensitive is not a boolean value. | [
"Set",
"whether",
"the",
"mapEntry",
"string",
"is",
"matched",
"case",
"sensitively",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/state/MapEntry.php#L140-L148 |
oat-sa/qti-sdk | src/qtism/data/content/interactions/SelectPointInteraction.php | SelectPointInteraction.setMaxChoices | public function setMaxChoices($maxChoices)
{
if (is_int($maxChoices) === true && $maxChoices >= 0) {
$this->maxChoices = $maxChoices;
} else {
$msg = "The 'maxChoices' argument must be a positive (>= 0) integer, '" . gettype($maxChoices) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setMaxChoices($maxChoices)
{
if (is_int($maxChoices) === true && $maxChoices >= 0) {
$this->maxChoices = $maxChoices;
} else {
$msg = "The 'maxChoices' argument must be a positive (>= 0) integer, '" . gettype($maxChoices) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setMaxChoices",
"(",
"$",
"maxChoices",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"maxChoices",
")",
"===",
"true",
"&&",
"$",
"maxChoices",
">=",
"0",
")",
"{",
"$",
"this",
"->",
"maxChoices",
"=",
"$",
"maxChoices",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'maxChoices' argument must be a positive (>= 0) integer, '\"",
".",
"gettype",
"(",
"$",
"maxChoices",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the maximum number of points that the candidate is allowed to select.
@param integer $maxChoices A positive (>= 0) integer.
@throws \InvalidArgumentException If $maxChoices is not a positive integer. | [
"Set",
"the",
"maximum",
"number",
"of",
"points",
"that",
"the",
"candidate",
"is",
"allowed",
"to",
"select",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/interactions/SelectPointInteraction.php#L108-L116 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/TemplateProcessingMarshaller.php | TemplateProcessingMarshaller.marshall | protected function marshall(QtiComponent $component)
{
$element = self::getDOMCradle()->createElement('templateProcessing');
foreach ($component->getTemplateRules() as $templateRule) {
$element->appendChild($this->getMarshallerFactory()->createMarshaller($templateRule)->marshall($templateRule));
}
return $element;
} | php | protected function marshall(QtiComponent $component)
{
$element = self::getDOMCradle()->createElement('templateProcessing');
foreach ($component->getTemplateRules() as $templateRule) {
$element->appendChild($this->getMarshallerFactory()->createMarshaller($templateRule)->marshall($templateRule));
}
return $element;
} | [
"protected",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"$",
"element",
"=",
"self",
"::",
"getDOMCradle",
"(",
")",
"->",
"createElement",
"(",
"'templateProcessing'",
")",
";",
"foreach",
"(",
"$",
"component",
"->",
"getTemplateRules",
"(",
")",
"as",
"$",
"templateRule",
")",
"{",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"templateRule",
")",
"->",
"marshall",
"(",
"$",
"templateRule",
")",
")",
";",
"}",
"return",
"$",
"element",
";",
"}"
] | Marshall a TemplateProcessing object into a DOMElement object.
@param \qtism\data\QtiComponent $component A TemplateProcessing object.
@return \DOMElement The according DOMElement object.
@throws \qtism\data\storage\xml\marshalling\MarshallingException | [
"Marshall",
"a",
"TemplateProcessing",
"object",
"into",
"a",
"DOMElement",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/TemplateProcessingMarshaller.php#L46-L55 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/TemplateProcessingMarshaller.php | TemplateProcessingMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
$childrenTagNames = array('exitTemplate', 'setCorrectResponse', 'setDefaultValue', 'setTemplateValue', 'templateCondition', 'templateConstraint');
$templateRuleElts = $this->getChildElementsByTagName($element, $childrenTagNames);
$templateRules = new TemplateRuleCollection();
foreach ($templateRuleElts as $templateRuleElt) {
$templateRules[] = $this->getMarshallerFactory()->createMarshaller($templateRuleElt)->unmarshall($templateRuleElt);
}
try {
return new TemplateProcessing($templateRules);
} catch (InvalidArgumentException $e) {
$msg = "A 'templateProcessing' element must contain at least one 'templateRule' element, none given.";
throw new UnmarshallingException($msg, $element, $e);
}
} | php | protected function unmarshall(DOMElement $element)
{
$childrenTagNames = array('exitTemplate', 'setCorrectResponse', 'setDefaultValue', 'setTemplateValue', 'templateCondition', 'templateConstraint');
$templateRuleElts = $this->getChildElementsByTagName($element, $childrenTagNames);
$templateRules = new TemplateRuleCollection();
foreach ($templateRuleElts as $templateRuleElt) {
$templateRules[] = $this->getMarshallerFactory()->createMarshaller($templateRuleElt)->unmarshall($templateRuleElt);
}
try {
return new TemplateProcessing($templateRules);
} catch (InvalidArgumentException $e) {
$msg = "A 'templateProcessing' element must contain at least one 'templateRule' element, none given.";
throw new UnmarshallingException($msg, $element, $e);
}
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"$",
"childrenTagNames",
"=",
"array",
"(",
"'exitTemplate'",
",",
"'setCorrectResponse'",
",",
"'setDefaultValue'",
",",
"'setTemplateValue'",
",",
"'templateCondition'",
",",
"'templateConstraint'",
")",
";",
"$",
"templateRuleElts",
"=",
"$",
"this",
"->",
"getChildElementsByTagName",
"(",
"$",
"element",
",",
"$",
"childrenTagNames",
")",
";",
"$",
"templateRules",
"=",
"new",
"TemplateRuleCollection",
"(",
")",
";",
"foreach",
"(",
"$",
"templateRuleElts",
"as",
"$",
"templateRuleElt",
")",
"{",
"$",
"templateRules",
"[",
"]",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"templateRuleElt",
")",
"->",
"unmarshall",
"(",
"$",
"templateRuleElt",
")",
";",
"}",
"try",
"{",
"return",
"new",
"TemplateProcessing",
"(",
"$",
"templateRules",
")",
";",
"}",
"catch",
"(",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"A 'templateProcessing' element must contain at least one 'templateRule' element, none given.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Unmarshall a DOMElement object corresponding to a QTI templateProcessing element.
@param \DOMElement $element A DOMElement object.
@return \qtism\data\QtiComponent A TemplateProcessing object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException | [
"Unmarshall",
"a",
"DOMElement",
"object",
"corresponding",
"to",
"a",
"QTI",
"templateProcessing",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/TemplateProcessingMarshaller.php#L64-L80 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/ContainerSizeProcessor.php | ContainerSizeProcessor.process | public function process()
{
$operands = $this->getOperands();
if ($operands->containsNull() === true) {
return new QtiInteger(0);
}
if ($operands->exclusivelyMultipleOrOrdered() === false) {
$msg = "The ContainerSize operator only accepts operands with a multiple or ordered cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
return new QtiInteger(count($operands[0]));
} | php | public function process()
{
$operands = $this->getOperands();
if ($operands->containsNull() === true) {
return new QtiInteger(0);
}
if ($operands->exclusivelyMultipleOrOrdered() === false) {
$msg = "The ContainerSize operator only accepts operands with a multiple or ordered cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
return new QtiInteger(count($operands[0]));
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"operands",
"=",
"$",
"this",
"->",
"getOperands",
"(",
")",
";",
"if",
"(",
"$",
"operands",
"->",
"containsNull",
"(",
")",
"===",
"true",
")",
"{",
"return",
"new",
"QtiInteger",
"(",
"0",
")",
";",
"}",
"if",
"(",
"$",
"operands",
"->",
"exclusivelyMultipleOrOrdered",
"(",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The ContainerSize operator only accepts operands with a multiple or ordered cardinality.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_CARDINALITY",
")",
";",
"}",
"return",
"new",
"QtiInteger",
"(",
"count",
"(",
"$",
"operands",
"[",
"0",
"]",
")",
")",
";",
"}"
] | Process the current expression.
@return integer|null The size of the container or null if it contains NULL.
@throws \qtism\runtime\expressions\operators\OperatorProcessingException | [
"Process",
"the",
"current",
"expression",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/ContainerSizeProcessor.php#L51-L65 |
oat-sa/qti-sdk | src/qtism/data/expressions/operators/MathOperator.php | MathOperator.setName | public function setName($name)
{
if (in_array($name, MathFunctions::asArray())) {
$this->name = $name;
} else {
$msg = "The name attribute must be a value from the MathFunctions enumeration, '" . $name . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setName($name)
{
if (in_array($name, MathFunctions::asArray())) {
$this->name = $name;
} else {
$msg = "The name attribute must be a value from the MathFunctions enumeration, '" . $name . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setName",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"name",
",",
"MathFunctions",
"::",
"asArray",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"name",
"=",
"$",
"name",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The name attribute must be a value from the MathFunctions enumeration, '\"",
".",
"$",
"name",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the name of the math function to use.
@param integer $name A value from the MathFunctions enumeration.
@throws \InvalidArgumentException If $name is not a value from the MathFunctions enumeration. | [
"Set",
"the",
"name",
"of",
"the",
"math",
"function",
"to",
"use",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/expressions/operators/MathOperator.php#L113-L121 |
oat-sa/qti-sdk | src/qtism/data/QtiDocument.php | QtiDocument.setVersion | public function setVersion($version)
{
if (Version::isKnown($version) === true) {
$this->version = Version::appendPatchVersion($version);
} else {
$msg = "Version '{$version}' is not a known QTI version. Known versions are '" . implode(', ', Version::knownVersions()) . "'";
throw new InvalidArgumentException($msg);
}
} | php | public function setVersion($version)
{
if (Version::isKnown($version) === true) {
$this->version = Version::appendPatchVersion($version);
} else {
$msg = "Version '{$version}' is not a known QTI version. Known versions are '" . implode(', ', Version::knownVersions()) . "'";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setVersion",
"(",
"$",
"version",
")",
"{",
"if",
"(",
"Version",
"::",
"isKnown",
"(",
"$",
"version",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"version",
"=",
"Version",
"::",
"appendPatchVersion",
"(",
"$",
"version",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"Version '{$version}' is not a known QTI version. Known versions are '\"",
".",
"implode",
"(",
"', '",
",",
"Version",
"::",
"knownVersions",
"(",
")",
")",
".",
"\"'\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the QTI $version in use for this document.
@param string $version A QTI version number e.g. '2.1.1'.
@throws \InvalidArgumentException If $version is unknown regarding existing QTI versions. | [
"Set",
"the",
"QTI",
"$version",
"in",
"use",
"for",
"this",
"document",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/QtiDocument.php#L63-L71 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/ContentMarshaller.php | ContentMarshaller.lookupClass | protected function lookupClass(DOMElement $element)
{
$localName = $element->localName;
if ($this->isWebComponentFriendly() === true && preg_match('/^qti-/', $localName) === 1) {
$localName = XmlUtils::qtiFriendlyName($localName);
}
$lookup = $this->getLookupClasses();
$class = ucfirst($localName);
foreach ($lookup as $l) {
$fqClass = $l . "\\" . $class;
if (class_exists($fqClass) === true) {
return $fqClass;
}
$fqClass = $fqClass . 'Element';
if (class_exists($fqClass) === true) {
return $fqClass;
}
}
$msg = "No class could be found for tag with name '" . $localName . "'.";
throw new UnmarshallingException($msg, $element);
} | php | protected function lookupClass(DOMElement $element)
{
$localName = $element->localName;
if ($this->isWebComponentFriendly() === true && preg_match('/^qti-/', $localName) === 1) {
$localName = XmlUtils::qtiFriendlyName($localName);
}
$lookup = $this->getLookupClasses();
$class = ucfirst($localName);
foreach ($lookup as $l) {
$fqClass = $l . "\\" . $class;
if (class_exists($fqClass) === true) {
return $fqClass;
}
$fqClass = $fqClass . 'Element';
if (class_exists($fqClass) === true) {
return $fqClass;
}
}
$msg = "No class could be found for tag with name '" . $localName . "'.";
throw new UnmarshallingException($msg, $element);
} | [
"protected",
"function",
"lookupClass",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"$",
"localName",
"=",
"$",
"element",
"->",
"localName",
";",
"if",
"(",
"$",
"this",
"->",
"isWebComponentFriendly",
"(",
")",
"===",
"true",
"&&",
"preg_match",
"(",
"'/^qti-/'",
",",
"$",
"localName",
")",
"===",
"1",
")",
"{",
"$",
"localName",
"=",
"XmlUtils",
"::",
"qtiFriendlyName",
"(",
"$",
"localName",
")",
";",
"}",
"$",
"lookup",
"=",
"$",
"this",
"->",
"getLookupClasses",
"(",
")",
";",
"$",
"class",
"=",
"ucfirst",
"(",
"$",
"localName",
")",
";",
"foreach",
"(",
"$",
"lookup",
"as",
"$",
"l",
")",
"{",
"$",
"fqClass",
"=",
"$",
"l",
".",
"\"\\\\\"",
".",
"$",
"class",
";",
"if",
"(",
"class_exists",
"(",
"$",
"fqClass",
")",
"===",
"true",
")",
"{",
"return",
"$",
"fqClass",
";",
"}",
"$",
"fqClass",
"=",
"$",
"fqClass",
".",
"'Element'",
";",
"if",
"(",
"class_exists",
"(",
"$",
"fqClass",
")",
"===",
"true",
")",
"{",
"return",
"$",
"fqClass",
";",
"}",
"}",
"$",
"msg",
"=",
"\"No class could be found for tag with name '\"",
".",
"$",
"localName",
".",
"\"'.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}"
] | Get the related PHP class name of a given $element.
@param \DOMElement $element The element you want to know the data model PHP class.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException If no class can be found for $element.
@return string A fully qualified class name. | [
"Get",
"the",
"related",
"PHP",
"class",
"name",
"of",
"a",
"given",
"$element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/ContentMarshaller.php#L305-L330 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.