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/runtime/common/OutcomeVariable.php | OutcomeVariable.setNormalMaximum | public function setNormalMaximum($normalMaximum)
{
if ((is_bool($normalMaximum) && $normalMaximum === false) || is_float($normalMaximum) || is_double($normalMaximum)) {
$this->normalMaximum = $normalMaximum;
} else {
$msg = "The normalMaximum argument must be a floating point value or false, '" . gettype($normalMaximum) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setNormalMaximum($normalMaximum)
{
if ((is_bool($normalMaximum) && $normalMaximum === false) || is_float($normalMaximum) || is_double($normalMaximum)) {
$this->normalMaximum = $normalMaximum;
} else {
$msg = "The normalMaximum argument must be a floating point value or false, '" . gettype($normalMaximum) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setNormalMaximum",
"(",
"$",
"normalMaximum",
")",
"{",
"if",
"(",
"(",
"is_bool",
"(",
"$",
"normalMaximum",
")",
"&&",
"$",
"normalMaximum",
"===",
"false",
")",
"||",
"is_float",
"(",
"$",
"normalMaximum",
")",
"||",
"is_double",
"(",
"$",
"normalMaximum",
")",
")",
"{",
"$",
"this",
"->",
"normalMaximum",
"=",
"$",
"normalMaximum",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The normalMaximum argument must be a floating point value or false, '\"",
".",
"gettype",
"(",
"$",
"normalMaximum",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the normal maximum.
@param floatboolean $normalMaximum The normal maximum or false if not defined.
@throws \InvalidArgumentException If $normalMaximum is not false nor a floating point value. | [
"Set",
"the",
"normal",
"maximum",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/common/OutcomeVariable.php#L121-L129 |
oat-sa/qti-sdk | src/qtism/runtime/common/OutcomeVariable.php | OutcomeVariable.setNormalMinimum | public function setNormalMinimum($normalMinimum)
{
if ((is_bool($normalMinimum) && $normalMinimum === false) || is_float($normalMinimum) || is_double($normalMinimum)) {
$this->normalMinimum = $normalMinimum;
} else {
$msg = "The normalMinimum argument must be a floating point value or false, '" . gettype($normalMinimum) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setNormalMinimum($normalMinimum)
{
if ((is_bool($normalMinimum) && $normalMinimum === false) || is_float($normalMinimum) || is_double($normalMinimum)) {
$this->normalMinimum = $normalMinimum;
} else {
$msg = "The normalMinimum argument must be a floating point value or false, '" . gettype($normalMinimum) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setNormalMinimum",
"(",
"$",
"normalMinimum",
")",
"{",
"if",
"(",
"(",
"is_bool",
"(",
"$",
"normalMinimum",
")",
"&&",
"$",
"normalMinimum",
"===",
"false",
")",
"||",
"is_float",
"(",
"$",
"normalMinimum",
")",
"||",
"is_double",
"(",
"$",
"normalMinimum",
")",
")",
"{",
"$",
"this",
"->",
"normalMinimum",
"=",
"$",
"normalMinimum",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The normalMinimum argument must be a floating point value or false, '\"",
".",
"gettype",
"(",
"$",
"normalMinimum",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the normal minimum.
@param float|boolean $normalMinimum The normal minimum or false if not defined.
@throws \InvalidArgumentException If $normalMinimum is not false nor a floating point value. | [
"Set",
"the",
"normal",
"minimum",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/common/OutcomeVariable.php#L147-L155 |
oat-sa/qti-sdk | src/qtism/runtime/common/OutcomeVariable.php | OutcomeVariable.setMasteryValue | public function setMasteryValue($masteryValue)
{
if ((is_bool($masteryValue) && $masteryValue === false) || is_float($masteryValue) || is_double($masteryValue)) {
$this->masteryValue = $masteryValue;
} else {
$msg = "The masteryValue argument must be a floating point value or false, '" . gettype($masteryValue) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setMasteryValue($masteryValue)
{
if ((is_bool($masteryValue) && $masteryValue === false) || is_float($masteryValue) || is_double($masteryValue)) {
$this->masteryValue = $masteryValue;
} else {
$msg = "The masteryValue argument must be a floating point value or false, '" . gettype($masteryValue) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setMasteryValue",
"(",
"$",
"masteryValue",
")",
"{",
"if",
"(",
"(",
"is_bool",
"(",
"$",
"masteryValue",
")",
"&&",
"$",
"masteryValue",
"===",
"false",
")",
"||",
"is_float",
"(",
"$",
"masteryValue",
")",
"||",
"is_double",
"(",
"$",
"masteryValue",
")",
")",
"{",
"$",
"this",
"->",
"masteryValue",
"=",
"$",
"masteryValue",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The masteryValue argument must be a floating point value or false, '\"",
".",
"gettype",
"(",
"$",
"masteryValue",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the mastery value.
@param float|double|boolean $masteryValue A floating point value or false if not defined.
@throws \InvalidArgumentException If $masteryValue is not a floating point value nor false. | [
"Set",
"the",
"mastery",
"value",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/common/OutcomeVariable.php#L173-L181 |
oat-sa/qti-sdk | src/qtism/runtime/common/OutcomeVariable.php | OutcomeVariable.createFromDataModel | public static function createFromDataModel(VariableDeclaration $variableDeclaration)
{
$variable = parent::createFromDataModel($variableDeclaration);
if ($variableDeclaration instanceof OutcomeDeclaration) {
$variable->setViews($variableDeclaration->getViews());
$variable->setNormalMaximum($variableDeclaration->getNormalMaximum());
$variable->setNormalMinimum($variableDeclaration->getNormalMinimum());
$variable->setMasteryValue($variableDeclaration->getMasteryValue());
$variable->setLookupTable($variableDeclaration->getLookupTable());
return $variable;
} else {
$msg = "OutcomeVariable::createFromDataModel only accept 'qtism\\data\\state\\OutcomeDeclaration' objects, '" . get_class($variableDeclaration) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public static function createFromDataModel(VariableDeclaration $variableDeclaration)
{
$variable = parent::createFromDataModel($variableDeclaration);
if ($variableDeclaration instanceof OutcomeDeclaration) {
$variable->setViews($variableDeclaration->getViews());
$variable->setNormalMaximum($variableDeclaration->getNormalMaximum());
$variable->setNormalMinimum($variableDeclaration->getNormalMinimum());
$variable->setMasteryValue($variableDeclaration->getMasteryValue());
$variable->setLookupTable($variableDeclaration->getLookupTable());
return $variable;
} else {
$msg = "OutcomeVariable::createFromDataModel only accept 'qtism\\data\\state\\OutcomeDeclaration' objects, '" . get_class($variableDeclaration) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"static",
"function",
"createFromDataModel",
"(",
"VariableDeclaration",
"$",
"variableDeclaration",
")",
"{",
"$",
"variable",
"=",
"parent",
"::",
"createFromDataModel",
"(",
"$",
"variableDeclaration",
")",
";",
"if",
"(",
"$",
"variableDeclaration",
"instanceof",
"OutcomeDeclaration",
")",
"{",
"$",
"variable",
"->",
"setViews",
"(",
"$",
"variableDeclaration",
"->",
"getViews",
"(",
")",
")",
";",
"$",
"variable",
"->",
"setNormalMaximum",
"(",
"$",
"variableDeclaration",
"->",
"getNormalMaximum",
"(",
")",
")",
";",
"$",
"variable",
"->",
"setNormalMinimum",
"(",
"$",
"variableDeclaration",
"->",
"getNormalMinimum",
"(",
")",
")",
";",
"$",
"variable",
"->",
"setMasteryValue",
"(",
"$",
"variableDeclaration",
"->",
"getMasteryValue",
"(",
")",
")",
";",
"$",
"variable",
"->",
"setLookupTable",
"(",
"$",
"variableDeclaration",
"->",
"getLookupTable",
"(",
")",
")",
";",
"return",
"$",
"variable",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"OutcomeVariable::createFromDataModel only accept 'qtism\\\\data\\\\state\\\\OutcomeDeclaration' objects, '\"",
".",
"get_class",
"(",
"$",
"variableDeclaration",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Create an OutcomeVariable object from a data model VariableDeclaration object.
@param \qtism\data\state\VariableDeclaration $variableDeclaration
@throws \InvalidArgumentException
@return \qtism\runtime\common\OutcomeVariable | [
"Create",
"an",
"OutcomeVariable",
"object",
"from",
"a",
"data",
"model",
"VariableDeclaration",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/common/OutcomeVariable.php#L220-L237 |
oat-sa/qti-sdk | src/qtism/runtime/common/OutcomeVariable.php | OutcomeVariable.applyDefaultValue | public function applyDefaultValue()
{
parent::applyDefaultValue();
if (is_null($this->getDefaultValue()) === true && $this->getCardinality() === Cardinality::SINGLE) {
if ($this->getBaseType() === BaseType::INTEGER) {
$this->setValue(new QtiInteger(0));
} elseif ($this->getBaseType() === BaseType::FLOAT) {
$this->setValue(new QtiFloat(0.0));
}
}
} | php | public function applyDefaultValue()
{
parent::applyDefaultValue();
if (is_null($this->getDefaultValue()) === true && $this->getCardinality() === Cardinality::SINGLE) {
if ($this->getBaseType() === BaseType::INTEGER) {
$this->setValue(new QtiInteger(0));
} elseif ($this->getBaseType() === BaseType::FLOAT) {
$this->setValue(new QtiFloat(0.0));
}
}
} | [
"public",
"function",
"applyDefaultValue",
"(",
")",
"{",
"parent",
"::",
"applyDefaultValue",
"(",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"getDefaultValue",
"(",
")",
")",
"===",
"true",
"&&",
"$",
"this",
"->",
"getCardinality",
"(",
")",
"===",
"Cardinality",
"::",
"SINGLE",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getBaseType",
"(",
")",
"===",
"BaseType",
"::",
"INTEGER",
")",
"{",
"$",
"this",
"->",
"setValue",
"(",
"new",
"QtiInteger",
"(",
"0",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"getBaseType",
"(",
")",
"===",
"BaseType",
"::",
"FLOAT",
")",
"{",
"$",
"this",
"->",
"setValue",
"(",
"new",
"QtiFloat",
"(",
"0.0",
")",
")",
";",
"}",
"}",
"}"
] | Apply the default value to the OutcomeVariable.
If no default value is described, and the cardinality is single and the baseType
is integer or float, the value of the variable becomes 0. | [
"Apply",
"the",
"default",
"value",
"to",
"the",
"OutcomeVariable",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/common/OutcomeVariable.php#L246-L257 |
oat-sa/qti-sdk | src/qtism/data/content/interactions/PositionObjectInteraction.php | PositionObjectInteraction.setMinChoices | public function setMinChoices($minChoices)
{
if (is_int($minChoices) && $minChoices >= 0) {
if (($maxChoices = $this->getMaxChoices()) > 0 && $minChoices > $maxChoices) {
$msg = "The 'minChoices' argument must be less than or equal to the limits imposed by 'maxChoices'.";
throw new InvalidArgumentException($msg);
}
$this->minChoices = $minChoices;
} else {
$msg = "The 'minChoices' argument must be a strictly positive (> 0) integer or a negative integer, '" . gettype($minChoices) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setMinChoices($minChoices)
{
if (is_int($minChoices) && $minChoices >= 0) {
if (($maxChoices = $this->getMaxChoices()) > 0 && $minChoices > $maxChoices) {
$msg = "The 'minChoices' argument must be less than or equal to the limits imposed by 'maxChoices'.";
throw new InvalidArgumentException($msg);
}
$this->minChoices = $minChoices;
} else {
$msg = "The 'minChoices' argument must be a strictly positive (> 0) integer or a negative integer, '" . gettype($minChoices) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setMinChoices",
"(",
"$",
"minChoices",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"minChoices",
")",
"&&",
"$",
"minChoices",
">=",
"0",
")",
"{",
"if",
"(",
"(",
"$",
"maxChoices",
"=",
"$",
"this",
"->",
"getMaxChoices",
"(",
")",
")",
">",
"0",
"&&",
"$",
"minChoices",
">",
"$",
"maxChoices",
")",
"{",
"$",
"msg",
"=",
"\"The 'minChoices' argument must be less than or equal to the limits imposed by 'maxChoices'.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"$",
"this",
"->",
"minChoices",
"=",
"$",
"minChoices",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'minChoices' argument must be a strictly positive (> 0) integer or a negative integer, '\"",
".",
"gettype",
"(",
"$",
"minChoices",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the minimum number of positions that the image must be placed to form a valid response
to the interaction.
@param integer $minChoices A strictly positive (> 0) integer that respects the limits imposed by 'maxChoices' or a negative integer to specify there is no 'minChoices'.
@throws \InvalidArgumentException If $minChoices is not a strictly positive integer of if it does not respect the limits imposed by 'maxChoices'. | [
"Set",
"the",
"minimum",
"number",
"of",
"positions",
"that",
"the",
"image",
"must",
"be",
"placed",
"to",
"form",
"a",
"valid",
"response",
"to",
"the",
"interaction",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/interactions/PositionObjectInteraction.php#L183-L197 |
oat-sa/qti-sdk | src/qtism/runtime/rendering/qtipl/expressions/BaseValueQtiPLRenderer.php | BaseValueQtiPLRenderer.render | public function render($something)
{
switch ($something->getBaseType()) {
case 0: // IDENTIFIER
return "'" . $something->getValue() . "'";
case 1: // BOOLEAN
return strtolower(var_export($something->getValue(), true));
case 2: // INTEGER
return $something->getValue();
case 3: // FLOAT
return $something->getValue();
case 4: // STRING
return "\"" . $something->getValue() . "\"";
case 10: // URI
return "`" . $something->getValue() . "`";
default:
return strtolower(BaseType::getNameByConstant($something->getBaseType())) . "(" .
$something->getValue() . ")";
}
} | php | public function render($something)
{
switch ($something->getBaseType()) {
case 0: // IDENTIFIER
return "'" . $something->getValue() . "'";
case 1: // BOOLEAN
return strtolower(var_export($something->getValue(), true));
case 2: // INTEGER
return $something->getValue();
case 3: // FLOAT
return $something->getValue();
case 4: // STRING
return "\"" . $something->getValue() . "\"";
case 10: // URI
return "`" . $something->getValue() . "`";
default:
return strtolower(BaseType::getNameByConstant($something->getBaseType())) . "(" .
$something->getValue() . ")";
}
} | [
"public",
"function",
"render",
"(",
"$",
"something",
")",
"{",
"switch",
"(",
"$",
"something",
"->",
"getBaseType",
"(",
")",
")",
"{",
"case",
"0",
":",
"// IDENTIFIER",
"return",
"\"'\"",
".",
"$",
"something",
"->",
"getValue",
"(",
")",
".",
"\"'\"",
";",
"case",
"1",
":",
"// BOOLEAN",
"return",
"strtolower",
"(",
"var_export",
"(",
"$",
"something",
"->",
"getValue",
"(",
")",
",",
"true",
")",
")",
";",
"case",
"2",
":",
"// INTEGER",
"return",
"$",
"something",
"->",
"getValue",
"(",
")",
";",
"case",
"3",
":",
"// FLOAT",
"return",
"$",
"something",
"->",
"getValue",
"(",
")",
";",
"case",
"4",
":",
"// STRING",
"return",
"\"\\\"\"",
".",
"$",
"something",
"->",
"getValue",
"(",
")",
".",
"\"\\\"\"",
";",
"case",
"10",
":",
"// URI",
"return",
"\"`\"",
".",
"$",
"something",
"->",
"getValue",
"(",
")",
".",
"\"`\"",
";",
"default",
":",
"return",
"strtolower",
"(",
"BaseType",
"::",
"getNameByConstant",
"(",
"$",
"something",
"->",
"getBaseType",
"(",
")",
")",
")",
".",
"\"(\"",
".",
"$",
"something",
"->",
"getValue",
"(",
")",
".",
"\")\"",
";",
"}",
"}"
] | 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/BaseValueQtiPLRenderer.php#L45-L64 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/NotProcessor.php | NotProcessor.process | public function process()
{
$operands = $this->getOperands();
if ($operands->containsNull()) {
return null;
}
if ($operands->exclusivelySingle() === false) {
$msg = "The Not Expression only accept operands with single cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
if ($operands->exclusivelyBoolean() === false) {
$msg = "The Not Expression only accept operands with boolean baseType.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
}
$operand = $operands[0];
return new QtiBoolean(!$operand->getValue());
} | php | public function process()
{
$operands = $this->getOperands();
if ($operands->containsNull()) {
return null;
}
if ($operands->exclusivelySingle() === false) {
$msg = "The Not Expression only accept operands with single cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
if ($operands->exclusivelyBoolean() === false) {
$msg = "The Not Expression only accept operands with boolean baseType.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
}
$operand = $operands[0];
return new QtiBoolean(!$operand->getValue());
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"operands",
"=",
"$",
"this",
"->",
"getOperands",
"(",
")",
";",
"if",
"(",
"$",
"operands",
"->",
"containsNull",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"operands",
"->",
"exclusivelySingle",
"(",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The Not Expression only accept operands with single cardinality.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_CARDINALITY",
")",
";",
"}",
"if",
"(",
"$",
"operands",
"->",
"exclusivelyBoolean",
"(",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The Not Expression only accept operands with boolean baseType.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_BASETYPE",
")",
";",
"}",
"$",
"operand",
"=",
"$",
"operands",
"[",
"0",
"]",
";",
"return",
"new",
"QtiBoolean",
"(",
"!",
"$",
"operand",
"->",
"getValue",
"(",
")",
")",
";",
"}"
] | Returns the logical negation of the sub-expressions.
@return boolean
@throws \qtism\runtime\expressions\operators\OperatorProcessingException | [
"Returns",
"the",
"logical",
"negation",
"of",
"the",
"sub",
"-",
"expressions",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/NotProcessor.php#L51-L72 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/SubstringProcessor.php | SubstringProcessor.process | public function process()
{
$operands = $this->getOperands();
if ($operands->containsNull() === true) {
return null;
}
if ($operands->exclusivelySingle() === false) {
$msg = "The Substring operator only accepts operands with a single cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
if ($operands->exclusivelyString() === false) {
$msg = "The Substring operator only accepts operands with a string baseType.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
}
$operand1 = $operands[0];
$operand2 = $operands[1];
$call = ($this->getExpression()->isCaseSensitive() === true) ? 'mb_strpos' : 'mb_stripos';
return new QtiBoolean($call($operand2->getValue(), $operand1->getValue(), 0, 'UTF-8') !== false);
} | php | public function process()
{
$operands = $this->getOperands();
if ($operands->containsNull() === true) {
return null;
}
if ($operands->exclusivelySingle() === false) {
$msg = "The Substring operator only accepts operands with a single cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
if ($operands->exclusivelyString() === false) {
$msg = "The Substring operator only accepts operands with a string baseType.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
}
$operand1 = $operands[0];
$operand2 = $operands[1];
$call = ($this->getExpression()->isCaseSensitive() === true) ? 'mb_strpos' : 'mb_stripos';
return new QtiBoolean($call($operand2->getValue(), $operand1->getValue(), 0, 'UTF-8') !== false);
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"operands",
"=",
"$",
"this",
"->",
"getOperands",
"(",
")",
";",
"if",
"(",
"$",
"operands",
"->",
"containsNull",
"(",
")",
"===",
"true",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"operands",
"->",
"exclusivelySingle",
"(",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The Substring operator only accepts operands with a single cardinality.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_CARDINALITY",
")",
";",
"}",
"if",
"(",
"$",
"operands",
"->",
"exclusivelyString",
"(",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The Substring operator only accepts operands with a string baseType.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_BASETYPE",
")",
";",
"}",
"$",
"operand1",
"=",
"$",
"operands",
"[",
"0",
"]",
";",
"$",
"operand2",
"=",
"$",
"operands",
"[",
"1",
"]",
";",
"$",
"call",
"=",
"(",
"$",
"this",
"->",
"getExpression",
"(",
")",
"->",
"isCaseSensitive",
"(",
")",
"===",
"true",
")",
"?",
"'mb_strpos'",
":",
"'mb_stripos'",
";",
"return",
"new",
"QtiBoolean",
"(",
"$",
"call",
"(",
"$",
"operand2",
"->",
"getValue",
"(",
")",
",",
"$",
"operand1",
"->",
"getValue",
"(",
")",
",",
"0",
",",
"'UTF-8'",
")",
"!==",
"false",
")",
";",
"}"
] | Process the Substring operator.
@return boolean|null Whether the first sub-expression is a substring of the second sub-expression or NULL if either sub-expression is NULL.
@throws \qtism\runtime\expressions\operators\OperatorProcessingException | [
"Process",
"the",
"Substring",
"operator",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/SubstringProcessor.php#L52-L76 |
oat-sa/qti-sdk | src/qtism/runtime/rules/RuleProcessorFactory.php | RuleProcessorFactory.createProcessor | public function createProcessor(QtiComponent $rule)
{
$qtiClassName = ucfirst($rule->getQtiClassName());
$nsPackage = 'qtism\\runtime\\rules\\';
$className = $nsPackage . $qtiClassName . 'Processor';
if (class_exists($className) === true) {
return new $className($rule);
}
$msg = "The QTI rule class '${qtiClassName}' has no dedicated RuleProcessor class.";
throw new RuntimeException($msg);
} | php | public function createProcessor(QtiComponent $rule)
{
$qtiClassName = ucfirst($rule->getQtiClassName());
$nsPackage = 'qtism\\runtime\\rules\\';
$className = $nsPackage . $qtiClassName . 'Processor';
if (class_exists($className) === true) {
return new $className($rule);
}
$msg = "The QTI rule class '${qtiClassName}' has no dedicated RuleProcessor class.";
throw new RuntimeException($msg);
} | [
"public",
"function",
"createProcessor",
"(",
"QtiComponent",
"$",
"rule",
")",
"{",
"$",
"qtiClassName",
"=",
"ucfirst",
"(",
"$",
"rule",
"->",
"getQtiClassName",
"(",
")",
")",
";",
"$",
"nsPackage",
"=",
"'qtism\\\\runtime\\\\rules\\\\'",
";",
"$",
"className",
"=",
"$",
"nsPackage",
".",
"$",
"qtiClassName",
".",
"'Processor'",
";",
"if",
"(",
"class_exists",
"(",
"$",
"className",
")",
"===",
"true",
")",
"{",
"return",
"new",
"$",
"className",
"(",
"$",
"rule",
")",
";",
"}",
"$",
"msg",
"=",
"\"The QTI rule class '${qtiClassName}' has no dedicated RuleProcessor class.\"",
";",
"throw",
"new",
"RuntimeException",
"(",
"$",
"msg",
")",
";",
"}"
] | Create the RuleProcessor object able to process the given $rule.
@param \qtism\data\QtiComponent $rule A Rule object you want to get the related processor.
@return \qtism\runtime\common\Processable The related RuleProcessor object.
@throws \RuntimeException If no RuleProcessor can be found for the given $rule. | [
"Create",
"the",
"RuleProcessor",
"object",
"able",
"to",
"process",
"the",
"given",
"$rule",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rules/RuleProcessorFactory.php#L57-L69 |
oat-sa/qti-sdk | src/qtism/runtime/rendering/qtipl/QtiPLRenderer.php | QtiPLRenderer.render | public function render($something)
{
if (array_key_exists($something->getQtiClassName(), $this->registry)) {
return $this->registry[$something->getQtiClassName()]->render($something);
} else if (in_array($something->getQtiClassName(), operators\OperatorQtiPLRenderer::getOperatorClassNames())) {
return $this->registry['operator']->render($something);
} else {
return $this->getDefaultRendering($something);
}
} | php | public function render($something)
{
if (array_key_exists($something->getQtiClassName(), $this->registry)) {
return $this->registry[$something->getQtiClassName()]->render($something);
} else if (in_array($something->getQtiClassName(), operators\OperatorQtiPLRenderer::getOperatorClassNames())) {
return $this->registry['operator']->render($something);
} else {
return $this->getDefaultRendering($something);
}
} | [
"public",
"function",
"render",
"(",
"$",
"something",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"something",
"->",
"getQtiClassName",
"(",
")",
",",
"$",
"this",
"->",
"registry",
")",
")",
"{",
"return",
"$",
"this",
"->",
"registry",
"[",
"$",
"something",
"->",
"getQtiClassName",
"(",
")",
"]",
"->",
"render",
"(",
"$",
"something",
")",
";",
"}",
"else",
"if",
"(",
"in_array",
"(",
"$",
"something",
"->",
"getQtiClassName",
"(",
")",
",",
"operators",
"\\",
"OperatorQtiPLRenderer",
"::",
"getOperatorClassNames",
"(",
")",
")",
")",
"{",
"return",
"$",
"this",
"->",
"registry",
"[",
"'operator'",
"]",
"->",
"render",
"(",
"$",
"something",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"getDefaultRendering",
"(",
"$",
"something",
")",
";",
"}",
"}"
] | 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/QtiPLRenderer.php#L141-L150 |
oat-sa/qti-sdk | src/qtism/common/datatypes/QtiScalar.php | QtiScalar.equals | public function equals($obj)
{
if ($obj instanceof QtiScalar) {
return $obj->getValue() === $this->getValue();
} else {
return $this->getValue() === $obj;
}
} | php | public function equals($obj)
{
if ($obj instanceof QtiScalar) {
return $obj->getValue() === $this->getValue();
} else {
return $this->getValue() === $obj;
}
} | [
"public",
"function",
"equals",
"(",
"$",
"obj",
")",
"{",
"if",
"(",
"$",
"obj",
"instanceof",
"QtiScalar",
")",
"{",
"return",
"$",
"obj",
"->",
"getValue",
"(",
")",
"===",
"$",
"this",
"->",
"getValue",
"(",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"getValue",
"(",
")",
"===",
"$",
"obj",
";",
"}",
"}"
] | Wheter or not $this is equal to $obj. Two Scalar
objects are considered to be identical if their intrinsic
values are strictly (===) equal.
@return boolean | [
"Wheter",
"or",
"not",
"$this",
"is",
"equal",
"to",
"$obj",
".",
"Two",
"Scalar",
"objects",
"are",
"considered",
"to",
"be",
"identical",
"if",
"their",
"intrinsic",
"values",
"are",
"strictly",
"(",
"===",
")",
"equal",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/datatypes/QtiScalar.php#L89-L96 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/ItemSubsetProcessor.php | ItemSubsetProcessor.getMappedVariableIdentifier | protected static function getMappedVariableIdentifier(AssessmentItemRef $assessmentItemRef, $targetIdentifier)
{
// return false if no mapping found.
$sourceIdentifier = $targetIdentifier;
foreach ($assessmentItemRef->getVariableMappings() as $variableMapping) {
if ($variableMapping->getTarget() === $targetIdentifier) {
$sourceIdentifier = $variableMapping->getSource();
break;
} elseif ($variableMapping->getSource() === $targetIdentifier) {
// Conflict.
$sourceIdentifier = false;
}
}
return $sourceIdentifier;
} | php | protected static function getMappedVariableIdentifier(AssessmentItemRef $assessmentItemRef, $targetIdentifier)
{
// return false if no mapping found.
$sourceIdentifier = $targetIdentifier;
foreach ($assessmentItemRef->getVariableMappings() as $variableMapping) {
if ($variableMapping->getTarget() === $targetIdentifier) {
$sourceIdentifier = $variableMapping->getSource();
break;
} elseif ($variableMapping->getSource() === $targetIdentifier) {
// Conflict.
$sourceIdentifier = false;
}
}
return $sourceIdentifier;
} | [
"protected",
"static",
"function",
"getMappedVariableIdentifier",
"(",
"AssessmentItemRef",
"$",
"assessmentItemRef",
",",
"$",
"targetIdentifier",
")",
"{",
"// return false if no mapping found.",
"$",
"sourceIdentifier",
"=",
"$",
"targetIdentifier",
";",
"foreach",
"(",
"$",
"assessmentItemRef",
"->",
"getVariableMappings",
"(",
")",
"as",
"$",
"variableMapping",
")",
"{",
"if",
"(",
"$",
"variableMapping",
"->",
"getTarget",
"(",
")",
"===",
"$",
"targetIdentifier",
")",
"{",
"$",
"sourceIdentifier",
"=",
"$",
"variableMapping",
"->",
"getSource",
"(",
")",
";",
"break",
";",
"}",
"elseif",
"(",
"$",
"variableMapping",
"->",
"getSource",
"(",
")",
"===",
"$",
"targetIdentifier",
")",
"{",
"// Conflict.",
"$",
"sourceIdentifier",
"=",
"false",
";",
"}",
"}",
"return",
"$",
"sourceIdentifier",
";",
"}"
] | Convenience method that returns the mapped variable identifier from $targetIdentifier.
@param \qtism\data\AssessmentItemRef $assessmentItemRef An AssessmentItemRef object where variable mappings can be found.
@param string $targetIdentifier A targetIdentifier to be replaced by a sourceIdentifier.
@return string|false The mapped identifier or $targetIdentifier if no mapping could be established. | [
"Convenience",
"method",
"that",
"returns",
"the",
"mapped",
"variable",
"identifier",
"from",
"$targetIdentifier",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/ItemSubsetProcessor.php#L108-L124 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/ItemSubsetProcessor.php | ItemSubsetProcessor.getItemSubset | protected function getItemSubset()
{
$sectionIdentifier = $this->getSectionIdentifier();
$includeCategories = $this->getIncludeCategories();
$excludeCategories = $this->getExcludeCategories();
return $this->getState()->getItemSubset($sectionIdentifier, $includeCategories, $excludeCategories);
} | php | protected function getItemSubset()
{
$sectionIdentifier = $this->getSectionIdentifier();
$includeCategories = $this->getIncludeCategories();
$excludeCategories = $this->getExcludeCategories();
return $this->getState()->getItemSubset($sectionIdentifier, $includeCategories, $excludeCategories);
} | [
"protected",
"function",
"getItemSubset",
"(",
")",
"{",
"$",
"sectionIdentifier",
"=",
"$",
"this",
"->",
"getSectionIdentifier",
"(",
")",
";",
"$",
"includeCategories",
"=",
"$",
"this",
"->",
"getIncludeCategories",
"(",
")",
";",
"$",
"excludeCategories",
"=",
"$",
"this",
"->",
"getExcludeCategories",
"(",
")",
";",
"return",
"$",
"this",
"->",
"getState",
"(",
")",
"->",
"getItemSubset",
"(",
"$",
"sectionIdentifier",
",",
"$",
"includeCategories",
",",
"$",
"excludeCategories",
")",
";",
"}"
] | A convenience method enabling you to get the item subset corresponding to the ItemSubset expression to be processed.
@return \qtism\data\AssessmentItemRefCollection A collection of AssessmentItemRef object that match the criteria expressed by the ItemSubset expression to be processed. | [
"A",
"convenience",
"method",
"enabling",
"you",
"to",
"get",
"the",
"item",
"subset",
"corresponding",
"to",
"the",
"ItemSubset",
"expression",
"to",
"be",
"processed",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/ItemSubsetProcessor.php#L131-L138 |
oat-sa/qti-sdk | src/qtism/data/expressions/RandomFloat.php | RandomFloat.setMin | public function setMin($min)
{
if (is_numeric($min) || Format::isVariableRef($min)) {
$this->min = $min;
} else {
$msg = "'Min' must be a numeric value or a variableRef, '" . gettype($min) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setMin($min)
{
if (is_numeric($min) || Format::isVariableRef($min)) {
$this->min = $min;
} else {
$msg = "'Min' must be a numeric value or a variableRef, '" . gettype($min) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setMin",
"(",
"$",
"min",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"min",
")",
"||",
"Format",
"::",
"isVariableRef",
"(",
"$",
"min",
")",
")",
"{",
"$",
"this",
"->",
"min",
"=",
"$",
"min",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"'Min' must be a numeric value or a variableRef, '\"",
".",
"gettype",
"(",
"$",
"min",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the min attribute value.
@param number|string $min A float value, int value or a variableRef.
@throws \InvalidArgumentException If $min is not a numeric value nor a variableRef. | [
"Set",
"the",
"min",
"attribute",
"value",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/expressions/RandomFloat.php#L82-L90 |
oat-sa/qti-sdk | src/qtism/data/expressions/RandomFloat.php | RandomFloat.setMax | public function setMax($max)
{
if (is_numeric($max) || Format::isVariableRef($max)) {
$this->max = $max;
} else {
$msg = "'Max must be a numeric value or a variableRef, '" . gettype($max) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setMax($max)
{
if (is_numeric($max) || Format::isVariableRef($max)) {
$this->max = $max;
} else {
$msg = "'Max must be a numeric value or a variableRef, '" . gettype($max) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setMax",
"(",
"$",
"max",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"max",
")",
"||",
"Format",
"::",
"isVariableRef",
"(",
"$",
"max",
")",
")",
"{",
"$",
"this",
"->",
"max",
"=",
"$",
"max",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"'Max must be a numeric value or a variableRef, '\"",
".",
"gettype",
"(",
"$",
"max",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the max attribute.
@param number|string $max A numeric value or a variableRef.
@throws \InvalidArgumentException If $max is not a numeric value nor a variableRef. | [
"Set",
"the",
"max",
"attribute",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/expressions/RandomFloat.php#L108-L116 |
oat-sa/qti-sdk | src/qtism/data/expressions/operators/CustomOperator.php | CustomOperator.setDefinition | public function setDefinition($definition)
{
if (is_string($definition) === true) {
$this->definition = $definition;
} else {
$msg = "The 'definition' argument must be a string, '" . gettype($class) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setDefinition($definition)
{
if (is_string($definition) === true) {
$this->definition = $definition;
} else {
$msg = "The 'definition' argument must be a string, '" . gettype($class) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setDefinition",
"(",
"$",
"definition",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"definition",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"definition",
"=",
"$",
"definition",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'definition' argument must be a string, '\"",
".",
"gettype",
"(",
"$",
"class",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the URI that identifies the definition of the custom operator
in the global namespace. An empty value means there is no value set for the definition attribute.
@param string $definition A URI or an empty string.
@throws \InvalidArgumentException If $definition is not a string. | [
"Set",
"the",
"URI",
"that",
"identifies",
"the",
"definition",
"of",
"the",
"custom",
"operator",
"in",
"the",
"global",
"namespace",
".",
"An",
"empty",
"value",
"means",
"there",
"is",
"no",
"value",
"set",
"for",
"the",
"definition",
"attribute",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/expressions/operators/CustomOperator.php#L140-L148 |
oat-sa/qti-sdk | src/qtism/data/state/AssociationValidityConstraint.php | AssociationValidityConstraint.setIdentifier | public function setIdentifier($identifier)
{
if (is_string($identifier) === false || empty($identifier) === true) {
throw new InvalidArgumentException(
"The 'identifier' argument must be a non-empty string."
);
}
$this->identifier = $identifier;
} | php | public function setIdentifier($identifier)
{
if (is_string($identifier) === false || empty($identifier) === true) {
throw new InvalidArgumentException(
"The 'identifier' argument must be a non-empty string."
);
}
$this->identifier = $identifier;
} | [
"public",
"function",
"setIdentifier",
"(",
"$",
"identifier",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"identifier",
")",
"===",
"false",
"||",
"empty",
"(",
"$",
"identifier",
")",
"===",
"true",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"The 'identifier' argument must be a non-empty string.\"",
")",
";",
"}",
"$",
"this",
"->",
"identifier",
"=",
"$",
"identifier",
";",
"}"
] | Set the identifier on which the validity constraint applies to.
@param integer $identifier
@throws \InvalidArgumentException If $identifier is an empty string. | [
"Set",
"the",
"identifier",
"on",
"which",
"the",
"validity",
"constraint",
"applies",
"to",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/state/AssociationValidityConstraint.php#L87-L96 |
oat-sa/qti-sdk | src/qtism/data/state/AssociationValidityConstraint.php | AssociationValidityConstraint.setMinConstraint | public function setMinConstraint($minConstraint)
{
if (is_int($minConstraint) === false || $minConstraint < 0) {
throw new InvalidArgumentException(
"The 'minConstraint' argument must be a non negative (>= 0) integer."
);
}
$this->minConstraint = $minConstraint;
} | php | public function setMinConstraint($minConstraint)
{
if (is_int($minConstraint) === false || $minConstraint < 0) {
throw new InvalidArgumentException(
"The 'minConstraint' argument must be a non negative (>= 0) integer."
);
}
$this->minConstraint = $minConstraint;
} | [
"public",
"function",
"setMinConstraint",
"(",
"$",
"minConstraint",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"minConstraint",
")",
"===",
"false",
"||",
"$",
"minConstraint",
"<",
"0",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"The 'minConstraint' argument must be a non negative (>= 0) integer.\"",
")",
";",
"}",
"$",
"this",
"->",
"minConstraint",
"=",
"$",
"minConstraint",
";",
"}"
] | Set the minimum number of times $identifier may be found in a Response Variable.
@param integer $minConstraint A non negative integer (>= 0) integer value.
@throws \InvalidArgumentException If $minConstraint is not a non negative (>= 0) integer value. | [
"Set",
"the",
"minimum",
"number",
"of",
"times",
"$identifier",
"may",
"be",
"found",
"in",
"a",
"Response",
"Variable",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/state/AssociationValidityConstraint.php#L114-L123 |
oat-sa/qti-sdk | src/qtism/data/state/AssociationValidityConstraint.php | AssociationValidityConstraint.setMaxConstraint | public function setMaxConstraint($maxConstraint)
{
if (is_int($maxConstraint) === false) {
throw new InvalidArgumentException(
"The 'maxConstraint' argument must be an integer."
);
} else if ($maxConstraint < 0) {
throw new InvalidArgumentException(
"The 'maxConstraint' argument must be a non negative (>= 0) integer."
);
} elseif ($maxConstraint !== 0 && $maxConstraint < ($minConstraint = $this->getMinConstraint())) {
throw new InvalidArgumentException(
"The 'maxConstraint' argument must be greather or equal to than the 'minConstraint' in place."
);
}
$this->maxConstraint = $maxConstraint;
} | php | public function setMaxConstraint($maxConstraint)
{
if (is_int($maxConstraint) === false) {
throw new InvalidArgumentException(
"The 'maxConstraint' argument must be an integer."
);
} else if ($maxConstraint < 0) {
throw new InvalidArgumentException(
"The 'maxConstraint' argument must be a non negative (>= 0) integer."
);
} elseif ($maxConstraint !== 0 && $maxConstraint < ($minConstraint = $this->getMinConstraint())) {
throw new InvalidArgumentException(
"The 'maxConstraint' argument must be greather or equal to than the 'minConstraint' in place."
);
}
$this->maxConstraint = $maxConstraint;
} | [
"public",
"function",
"setMaxConstraint",
"(",
"$",
"maxConstraint",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"maxConstraint",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"The 'maxConstraint' argument must be an integer.\"",
")",
";",
"}",
"else",
"if",
"(",
"$",
"maxConstraint",
"<",
"0",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"The 'maxConstraint' argument must be a non negative (>= 0) integer.\"",
")",
";",
"}",
"elseif",
"(",
"$",
"maxConstraint",
"!==",
"0",
"&&",
"$",
"maxConstraint",
"<",
"(",
"$",
"minConstraint",
"=",
"$",
"this",
"->",
"getMinConstraint",
"(",
")",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"The 'maxConstraint' argument must be greather or equal to than the 'minConstraint' in place.\"",
")",
";",
"}",
"$",
"this",
"->",
"maxConstraint",
"=",
"$",
"maxConstraint",
";",
"}"
] | Set the maximum number of times $identifier may be found in a Response Variable.
Please note that 0 indicates no constraint.
@param integer $maxConstraint An integer value which is greater than the 'minConstraint' in place.
@throws \InvalidArgumentException If $maxConstraint is not an integer greater or equal to the 'minConstraint' in place. | [
"Set",
"the",
"maximum",
"number",
"of",
"times",
"$identifier",
"may",
"be",
"found",
"in",
"a",
"Response",
"Variable",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/state/AssociationValidityConstraint.php#L143-L160 |
oat-sa/qti-sdk | src/qtism/runtime/rendering/markup/xhtml/Utils.php | Utils.shuffle | static public function shuffle(DOMNode $node, ShufflableCollection $shufflables)
{
$shufflableIndexes = array();
$elements = array();
// 1. Detect what are the components that must
// be shuffles within the fragment ($shufflableIndexes).
//
// 2. Store the related DOMElements into a
// more suitable way ($elements).
foreach ($shufflables as $k => $s) {
$i = 0;
while ($i < $node->childNodes->length) {
$n = $node->childNodes->item($i);
$i++;
if ($n->nodeType === XML_ELEMENT_NODE && self::hasClass($n, 'qti-' . $s->getQtiClassName()) === true && !in_array($n, $elements, true)) {
$elements[] = $n;
if ($s->isFixed() === false) {
$shufflableIndexes[] = $k;
}
break;
}
}
}
// Swap two elements together N times where N is the number of shufflable components.
$count = count($shufflableIndexes);
$max = $count - 1;
for ($i = 0; $i < $count; $i++) {
$r1 = mt_rand(0, $max);
$r2 = mt_rand(0, $max);
if ($r1 !== $r2) {
// Do only if swapping is 'useful'...
$placeholder1 = $node->ownerDocument->createElement('placeholder1');
$placeholder2 = $node->ownerDocument->createElement('placeholder2');
$statements1 = self::extractStatements($elements[$shufflableIndexes[$r1]]);
$statements2 = self::extractStatements($elements[$shufflableIndexes[$r2]]);
$node->replaceChild($placeholder1, $elements[$shufflableIndexes[$r1]]);
$node->replaceChild($placeholder2, $elements[$shufflableIndexes[$r2]]);
$placeholder1 = $node->replaceChild($elements[$shufflableIndexes[$r2]], $placeholder1);
$placeholder2 = $node->replaceChild($elements[$shufflableIndexes[$r1]], $placeholder2);
if (empty($statements1) === false && empty($statements2) === false) {
for ($i = 0; $i < 2; $i++) {
$node->removeChild($statements1[$i]);
$node->replaceChild($statements1[$i], $statements2[$i]);
}
$node->insertBefore($statements2[0], $elements[$shufflableIndexes[$r2]]);
$elements[$shufflableIndexes[$r2]]->parentNode->insertBefore($statements2[1], $elements[$shufflableIndexes[$r2]]->nextSibling);
} else if (empty($statements1) === false && empty($statements2) === true) {
$node->removeChild($statements1[0]);
$node->removeChild($statements1[1]);
$node->insertBefore($statements1[0], $elements[$shufflableIndexes[$r1]]);
$elements[$shufflableIndexes[$r1]]->parentNode->insertBefore($statements1[1], $elements[$shufflableIndexes[$r1]]->nextSibling);
} else if (empty($statements2) === false && empty($statements1) === true) {
$node->removeChild($statements2[0]);
$node->removeChild($statements2[1]);
$node->insertBefore($statements2[0], $elements[$shufflableIndexes[$r2]]);
$elements[$shufflableIndexes[$r2]]->parentNode->insertBefore($statements2[1], $elements[$shufflableIndexes[$r2]]->nextSibling);
}
unset($placeholder1);
unset($placeholder2);
}
}
} | php | static public function shuffle(DOMNode $node, ShufflableCollection $shufflables)
{
$shufflableIndexes = array();
$elements = array();
// 1. Detect what are the components that must
// be shuffles within the fragment ($shufflableIndexes).
//
// 2. Store the related DOMElements into a
// more suitable way ($elements).
foreach ($shufflables as $k => $s) {
$i = 0;
while ($i < $node->childNodes->length) {
$n = $node->childNodes->item($i);
$i++;
if ($n->nodeType === XML_ELEMENT_NODE && self::hasClass($n, 'qti-' . $s->getQtiClassName()) === true && !in_array($n, $elements, true)) {
$elements[] = $n;
if ($s->isFixed() === false) {
$shufflableIndexes[] = $k;
}
break;
}
}
}
// Swap two elements together N times where N is the number of shufflable components.
$count = count($shufflableIndexes);
$max = $count - 1;
for ($i = 0; $i < $count; $i++) {
$r1 = mt_rand(0, $max);
$r2 = mt_rand(0, $max);
if ($r1 !== $r2) {
// Do only if swapping is 'useful'...
$placeholder1 = $node->ownerDocument->createElement('placeholder1');
$placeholder2 = $node->ownerDocument->createElement('placeholder2');
$statements1 = self::extractStatements($elements[$shufflableIndexes[$r1]]);
$statements2 = self::extractStatements($elements[$shufflableIndexes[$r2]]);
$node->replaceChild($placeholder1, $elements[$shufflableIndexes[$r1]]);
$node->replaceChild($placeholder2, $elements[$shufflableIndexes[$r2]]);
$placeholder1 = $node->replaceChild($elements[$shufflableIndexes[$r2]], $placeholder1);
$placeholder2 = $node->replaceChild($elements[$shufflableIndexes[$r1]], $placeholder2);
if (empty($statements1) === false && empty($statements2) === false) {
for ($i = 0; $i < 2; $i++) {
$node->removeChild($statements1[$i]);
$node->replaceChild($statements1[$i], $statements2[$i]);
}
$node->insertBefore($statements2[0], $elements[$shufflableIndexes[$r2]]);
$elements[$shufflableIndexes[$r2]]->parentNode->insertBefore($statements2[1], $elements[$shufflableIndexes[$r2]]->nextSibling);
} else if (empty($statements1) === false && empty($statements2) === true) {
$node->removeChild($statements1[0]);
$node->removeChild($statements1[1]);
$node->insertBefore($statements1[0], $elements[$shufflableIndexes[$r1]]);
$elements[$shufflableIndexes[$r1]]->parentNode->insertBefore($statements1[1], $elements[$shufflableIndexes[$r1]]->nextSibling);
} else if (empty($statements2) === false && empty($statements1) === true) {
$node->removeChild($statements2[0]);
$node->removeChild($statements2[1]);
$node->insertBefore($statements2[0], $elements[$shufflableIndexes[$r2]]);
$elements[$shufflableIndexes[$r2]]->parentNode->insertBefore($statements2[1], $elements[$shufflableIndexes[$r2]]->nextSibling);
}
unset($placeholder1);
unset($placeholder2);
}
}
} | [
"static",
"public",
"function",
"shuffle",
"(",
"DOMNode",
"$",
"node",
",",
"ShufflableCollection",
"$",
"shufflables",
")",
"{",
"$",
"shufflableIndexes",
"=",
"array",
"(",
")",
";",
"$",
"elements",
"=",
"array",
"(",
")",
";",
"// 1. Detect what are the components that must",
"// be shuffles within the fragment ($shufflableIndexes).",
"//",
"// 2. Store the related DOMElements into a",
"// more suitable way ($elements).",
"foreach",
"(",
"$",
"shufflables",
"as",
"$",
"k",
"=>",
"$",
"s",
")",
"{",
"$",
"i",
"=",
"0",
";",
"while",
"(",
"$",
"i",
"<",
"$",
"node",
"->",
"childNodes",
"->",
"length",
")",
"{",
"$",
"n",
"=",
"$",
"node",
"->",
"childNodes",
"->",
"item",
"(",
"$",
"i",
")",
";",
"$",
"i",
"++",
";",
"if",
"(",
"$",
"n",
"->",
"nodeType",
"===",
"XML_ELEMENT_NODE",
"&&",
"self",
"::",
"hasClass",
"(",
"$",
"n",
",",
"'qti-'",
".",
"$",
"s",
"->",
"getQtiClassName",
"(",
")",
")",
"===",
"true",
"&&",
"!",
"in_array",
"(",
"$",
"n",
",",
"$",
"elements",
",",
"true",
")",
")",
"{",
"$",
"elements",
"[",
"]",
"=",
"$",
"n",
";",
"if",
"(",
"$",
"s",
"->",
"isFixed",
"(",
")",
"===",
"false",
")",
"{",
"$",
"shufflableIndexes",
"[",
"]",
"=",
"$",
"k",
";",
"}",
"break",
";",
"}",
"}",
"}",
"// Swap two elements together N times where N is the number of shufflable components.",
"$",
"count",
"=",
"count",
"(",
"$",
"shufflableIndexes",
")",
";",
"$",
"max",
"=",
"$",
"count",
"-",
"1",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"count",
";",
"$",
"i",
"++",
")",
"{",
"$",
"r1",
"=",
"mt_rand",
"(",
"0",
",",
"$",
"max",
")",
";",
"$",
"r2",
"=",
"mt_rand",
"(",
"0",
",",
"$",
"max",
")",
";",
"if",
"(",
"$",
"r1",
"!==",
"$",
"r2",
")",
"{",
"// Do only if swapping is 'useful'...",
"$",
"placeholder1",
"=",
"$",
"node",
"->",
"ownerDocument",
"->",
"createElement",
"(",
"'placeholder1'",
")",
";",
"$",
"placeholder2",
"=",
"$",
"node",
"->",
"ownerDocument",
"->",
"createElement",
"(",
"'placeholder2'",
")",
";",
"$",
"statements1",
"=",
"self",
"::",
"extractStatements",
"(",
"$",
"elements",
"[",
"$",
"shufflableIndexes",
"[",
"$",
"r1",
"]",
"]",
")",
";",
"$",
"statements2",
"=",
"self",
"::",
"extractStatements",
"(",
"$",
"elements",
"[",
"$",
"shufflableIndexes",
"[",
"$",
"r2",
"]",
"]",
")",
";",
"$",
"node",
"->",
"replaceChild",
"(",
"$",
"placeholder1",
",",
"$",
"elements",
"[",
"$",
"shufflableIndexes",
"[",
"$",
"r1",
"]",
"]",
")",
";",
"$",
"node",
"->",
"replaceChild",
"(",
"$",
"placeholder2",
",",
"$",
"elements",
"[",
"$",
"shufflableIndexes",
"[",
"$",
"r2",
"]",
"]",
")",
";",
"$",
"placeholder1",
"=",
"$",
"node",
"->",
"replaceChild",
"(",
"$",
"elements",
"[",
"$",
"shufflableIndexes",
"[",
"$",
"r2",
"]",
"]",
",",
"$",
"placeholder1",
")",
";",
"$",
"placeholder2",
"=",
"$",
"node",
"->",
"replaceChild",
"(",
"$",
"elements",
"[",
"$",
"shufflableIndexes",
"[",
"$",
"r1",
"]",
"]",
",",
"$",
"placeholder2",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"statements1",
")",
"===",
"false",
"&&",
"empty",
"(",
"$",
"statements2",
")",
"===",
"false",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"2",
";",
"$",
"i",
"++",
")",
"{",
"$",
"node",
"->",
"removeChild",
"(",
"$",
"statements1",
"[",
"$",
"i",
"]",
")",
";",
"$",
"node",
"->",
"replaceChild",
"(",
"$",
"statements1",
"[",
"$",
"i",
"]",
",",
"$",
"statements2",
"[",
"$",
"i",
"]",
")",
";",
"}",
"$",
"node",
"->",
"insertBefore",
"(",
"$",
"statements2",
"[",
"0",
"]",
",",
"$",
"elements",
"[",
"$",
"shufflableIndexes",
"[",
"$",
"r2",
"]",
"]",
")",
";",
"$",
"elements",
"[",
"$",
"shufflableIndexes",
"[",
"$",
"r2",
"]",
"]",
"->",
"parentNode",
"->",
"insertBefore",
"(",
"$",
"statements2",
"[",
"1",
"]",
",",
"$",
"elements",
"[",
"$",
"shufflableIndexes",
"[",
"$",
"r2",
"]",
"]",
"->",
"nextSibling",
")",
";",
"}",
"else",
"if",
"(",
"empty",
"(",
"$",
"statements1",
")",
"===",
"false",
"&&",
"empty",
"(",
"$",
"statements2",
")",
"===",
"true",
")",
"{",
"$",
"node",
"->",
"removeChild",
"(",
"$",
"statements1",
"[",
"0",
"]",
")",
";",
"$",
"node",
"->",
"removeChild",
"(",
"$",
"statements1",
"[",
"1",
"]",
")",
";",
"$",
"node",
"->",
"insertBefore",
"(",
"$",
"statements1",
"[",
"0",
"]",
",",
"$",
"elements",
"[",
"$",
"shufflableIndexes",
"[",
"$",
"r1",
"]",
"]",
")",
";",
"$",
"elements",
"[",
"$",
"shufflableIndexes",
"[",
"$",
"r1",
"]",
"]",
"->",
"parentNode",
"->",
"insertBefore",
"(",
"$",
"statements1",
"[",
"1",
"]",
",",
"$",
"elements",
"[",
"$",
"shufflableIndexes",
"[",
"$",
"r1",
"]",
"]",
"->",
"nextSibling",
")",
";",
"}",
"else",
"if",
"(",
"empty",
"(",
"$",
"statements2",
")",
"===",
"false",
"&&",
"empty",
"(",
"$",
"statements1",
")",
"===",
"true",
")",
"{",
"$",
"node",
"->",
"removeChild",
"(",
"$",
"statements2",
"[",
"0",
"]",
")",
";",
"$",
"node",
"->",
"removeChild",
"(",
"$",
"statements2",
"[",
"1",
"]",
")",
";",
"$",
"node",
"->",
"insertBefore",
"(",
"$",
"statements2",
"[",
"0",
"]",
",",
"$",
"elements",
"[",
"$",
"shufflableIndexes",
"[",
"$",
"r2",
"]",
"]",
")",
";",
"$",
"elements",
"[",
"$",
"shufflableIndexes",
"[",
"$",
"r2",
"]",
"]",
"->",
"parentNode",
"->",
"insertBefore",
"(",
"$",
"statements2",
"[",
"1",
"]",
",",
"$",
"elements",
"[",
"$",
"shufflableIndexes",
"[",
"$",
"r2",
"]",
"]",
"->",
"nextSibling",
")",
";",
"}",
"unset",
"(",
"$",
"placeholder1",
")",
";",
"unset",
"(",
"$",
"placeholder2",
")",
";",
"}",
"}",
"}"
] | Shuffle the elements related to $shufflables components within a given $node.
@param \DOMNode $node The DOM Node where corresponding $shufflables must be shuffled.
@param \qtism\data\ShufflableCollection $shufflables A collection of Shufflable objects. | [
"Shuffle",
"the",
"elements",
"related",
"to",
"$shufflables",
"components",
"within",
"a",
"given",
"$node",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/markup/xhtml/Utils.php#L48-L124 |
oat-sa/qti-sdk | src/qtism/runtime/rendering/markup/xhtml/Utils.php | Utils.hasClass | static public function hasClass(DOMElement $node, $class)
{
if (is_array($class) === false) {
$class = array($class);
}
$attr = explode("\x20", $node->getAttribute('class'));
foreach ($class as $c) {
if (in_array($c, $attr) === false) {
return false;
}
}
return true;
} | php | static public function hasClass(DOMElement $node, $class)
{
if (is_array($class) === false) {
$class = array($class);
}
$attr = explode("\x20", $node->getAttribute('class'));
foreach ($class as $c) {
if (in_array($c, $attr) === false) {
return false;
}
}
return true;
} | [
"static",
"public",
"function",
"hasClass",
"(",
"DOMElement",
"$",
"node",
",",
"$",
"class",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"class",
")",
"===",
"false",
")",
"{",
"$",
"class",
"=",
"array",
"(",
"$",
"class",
")",
";",
"}",
"$",
"attr",
"=",
"explode",
"(",
"\"\\x20\"",
",",
"$",
"node",
"->",
"getAttribute",
"(",
"'class'",
")",
")",
";",
"foreach",
"(",
"$",
"class",
"as",
"$",
"c",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"c",
",",
"$",
"attr",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Whether or not a given $node element has the given CSS $class(es).
@param \DOMElement $node
@param string|array $class A class or an array of CSS classes.
@return boolean | [
"Whether",
"or",
"not",
"a",
"given",
"$node",
"element",
"has",
"the",
"given",
"CSS",
"$class",
"(",
"es",
")",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/markup/xhtml/Utils.php#L133-L148 |
oat-sa/qti-sdk | src/qtism/runtime/rendering/markup/xhtml/Utils.php | Utils.extractStatements | static public function extractStatements(DOMElement $node, $type = self::EXTRACT_IF)
{
$statements = array();
$extract = array(
'qtism-if',
'qtism-endif'
);
if ($type === self::EXTRACT_INCLUDE) {
$extract = array(
'qtism-include',
'qtism-endinclude'
);
}
$sibling = $node->previousSibling;
while ($sibling && $sibling->nodeType === XML_COMMENT_NODE) {
if (strpos(trim($sibling->data), $extract[0]) === 0) {
$statements[] = $sibling;
break;
}
$sibling = $sibling->previousSibling;
}
if (empty($statements) === false) {
$sibling = $node->nextSibling;
while ($sibling && $sibling->nodeType === XML_COMMENT_NODE) {
if (strpos(trim($sibling->data), $extract[1]) === 0) {
$statements[] = $sibling;
return $statements;
}
$sibling = $sibling->nextSibling;
}
}
return array();
} | php | static public function extractStatements(DOMElement $node, $type = self::EXTRACT_IF)
{
$statements = array();
$extract = array(
'qtism-if',
'qtism-endif'
);
if ($type === self::EXTRACT_INCLUDE) {
$extract = array(
'qtism-include',
'qtism-endinclude'
);
}
$sibling = $node->previousSibling;
while ($sibling && $sibling->nodeType === XML_COMMENT_NODE) {
if (strpos(trim($sibling->data), $extract[0]) === 0) {
$statements[] = $sibling;
break;
}
$sibling = $sibling->previousSibling;
}
if (empty($statements) === false) {
$sibling = $node->nextSibling;
while ($sibling && $sibling->nodeType === XML_COMMENT_NODE) {
if (strpos(trim($sibling->data), $extract[1]) === 0) {
$statements[] = $sibling;
return $statements;
}
$sibling = $sibling->nextSibling;
}
}
return array();
} | [
"static",
"public",
"function",
"extractStatements",
"(",
"DOMElement",
"$",
"node",
",",
"$",
"type",
"=",
"self",
"::",
"EXTRACT_IF",
")",
"{",
"$",
"statements",
"=",
"array",
"(",
")",
";",
"$",
"extract",
"=",
"array",
"(",
"'qtism-if'",
",",
"'qtism-endif'",
")",
";",
"if",
"(",
"$",
"type",
"===",
"self",
"::",
"EXTRACT_INCLUDE",
")",
"{",
"$",
"extract",
"=",
"array",
"(",
"'qtism-include'",
",",
"'qtism-endinclude'",
")",
";",
"}",
"$",
"sibling",
"=",
"$",
"node",
"->",
"previousSibling",
";",
"while",
"(",
"$",
"sibling",
"&&",
"$",
"sibling",
"->",
"nodeType",
"===",
"XML_COMMENT_NODE",
")",
"{",
"if",
"(",
"strpos",
"(",
"trim",
"(",
"$",
"sibling",
"->",
"data",
")",
",",
"$",
"extract",
"[",
"0",
"]",
")",
"===",
"0",
")",
"{",
"$",
"statements",
"[",
"]",
"=",
"$",
"sibling",
";",
"break",
";",
"}",
"$",
"sibling",
"=",
"$",
"sibling",
"->",
"previousSibling",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"statements",
")",
"===",
"false",
")",
"{",
"$",
"sibling",
"=",
"$",
"node",
"->",
"nextSibling",
";",
"while",
"(",
"$",
"sibling",
"&&",
"$",
"sibling",
"->",
"nodeType",
"===",
"XML_COMMENT_NODE",
")",
"{",
"if",
"(",
"strpos",
"(",
"trim",
"(",
"$",
"sibling",
"->",
"data",
")",
",",
"$",
"extract",
"[",
"1",
"]",
")",
"===",
"0",
")",
"{",
"$",
"statements",
"[",
"]",
"=",
"$",
"sibling",
";",
"return",
"$",
"statements",
";",
"}",
"$",
"sibling",
"=",
"$",
"sibling",
"->",
"nextSibling",
";",
"}",
"}",
"return",
"array",
"(",
")",
";",
"}"
] | Extract qtism-if/qtism-endif statements around a given $node.
@param DOMElement $node
@return array An array of DOMComment objects. | [
"Extract",
"qtism",
"-",
"if",
"/",
"qtism",
"-",
"endif",
"statements",
"around",
"a",
"given",
"$node",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/markup/xhtml/Utils.php#L156-L193 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/MatchTableEntryMarshaller.php | MatchTableEntryMarshaller.marshall | protected function marshall(QtiComponent $component)
{
$element = static::getDOMCradle()->createElement($component->getQtiClassName());
$this->setDOMElementAttribute($element, 'sourceValue', $component->getSourceValue());
$this->setDOMElementAttribute($element, 'targetValue', $component->getTargetValue());
return $element;
} | php | protected function marshall(QtiComponent $component)
{
$element = static::getDOMCradle()->createElement($component->getQtiClassName());
$this->setDOMElementAttribute($element, 'sourceValue', $component->getSourceValue());
$this->setDOMElementAttribute($element, 'targetValue', $component->getTargetValue());
return $element;
} | [
"protected",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"$",
"element",
"=",
"static",
"::",
"getDOMCradle",
"(",
")",
"->",
"createElement",
"(",
"$",
"component",
"->",
"getQtiClassName",
"(",
")",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'sourceValue'",
",",
"$",
"component",
"->",
"getSourceValue",
"(",
")",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'targetValue'",
",",
"$",
"component",
"->",
"getTargetValue",
"(",
")",
")",
";",
"return",
"$",
"element",
";",
"}"
] | Marshall a MatchTableEntry object into a DOMElement object.
@param \qtism\data\QtiComponent $component A MatchTableEntry object.
@return \DOMElement The according DOMElement object. | [
"Marshall",
"a",
"MatchTableEntry",
"object",
"into",
"a",
"DOMElement",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/MatchTableEntryMarshaller.php#L98-L106 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/MatchTableEntryMarshaller.php | MatchTableEntryMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
if (($sourceValue = $this->getDOMElementAttributeAs($element, 'sourceValue', 'integer')) !== null) {
if (($targetValue = $this->getDOMElementAttributeAs($element, 'targetValue', 'string')) !== null) {
$object = new MatchTableEntry($sourceValue, Utils::stringToDatatype($targetValue, $this->getBaseType()), $this->getBaseType());
return $object;
} else {
$msg = "The mandatory attribute 'targetValue' is missing.";
throw new InvalidArgumentException($msg, $element);
}
} else {
$msg = "The mandatory attribute 'sourceValue' is missing.";
throw new UnmarshallingException($msg, $element);
}
} | php | protected function unmarshall(DOMElement $element)
{
if (($sourceValue = $this->getDOMElementAttributeAs($element, 'sourceValue', 'integer')) !== null) {
if (($targetValue = $this->getDOMElementAttributeAs($element, 'targetValue', 'string')) !== null) {
$object = new MatchTableEntry($sourceValue, Utils::stringToDatatype($targetValue, $this->getBaseType()), $this->getBaseType());
return $object;
} else {
$msg = "The mandatory attribute 'targetValue' is missing.";
throw new InvalidArgumentException($msg, $element);
}
} else {
$msg = "The mandatory attribute 'sourceValue' is missing.";
throw new UnmarshallingException($msg, $element);
}
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"if",
"(",
"(",
"$",
"sourceValue",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'sourceValue'",
",",
"'integer'",
")",
")",
"!==",
"null",
")",
"{",
"if",
"(",
"(",
"$",
"targetValue",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'targetValue'",
",",
"'string'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"object",
"=",
"new",
"MatchTableEntry",
"(",
"$",
"sourceValue",
",",
"Utils",
"::",
"stringToDatatype",
"(",
"$",
"targetValue",
",",
"$",
"this",
"->",
"getBaseType",
"(",
")",
")",
",",
"$",
"this",
"->",
"getBaseType",
"(",
")",
")",
";",
"return",
"$",
"object",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory attribute 'targetValue' is missing.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory attribute 'sourceValue' is missing.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}"
] | Unmarshall a DOMElement object corresponding to a QTI MatchTableEntry element.
@param \DOMElement $element A DOMElement object.
@return \qtism\data\QtiComponent A MatchTableEntry object.
@throws \UnmarshallingException If the mandatory attributes 'sourceValue' or 'targetValue' are missing from $element. | [
"Unmarshall",
"a",
"DOMElement",
"object",
"corresponding",
"to",
"a",
"QTI",
"MatchTableEntry",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/MatchTableEntryMarshaller.php#L115-L131 |
oat-sa/qti-sdk | src/qtism/runtime/rules/RuleProcessingException.php | RuleProcessingException.setSource | public function setSource(Processable $source)
{
if ($source instanceof RuleProcessor) {
parent::setSource($source);
} else {
$msg = "RuleProcessingException::setSource only accept RuleProcessor objects.";
throw new InvalidArgumentException($msg);
}
} | php | public function setSource(Processable $source)
{
if ($source instanceof RuleProcessor) {
parent::setSource($source);
} else {
$msg = "RuleProcessingException::setSource only accept RuleProcessor objects.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setSource",
"(",
"Processable",
"$",
"source",
")",
"{",
"if",
"(",
"$",
"source",
"instanceof",
"RuleProcessor",
")",
"{",
"parent",
"::",
"setSource",
"(",
"$",
"source",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"RuleProcessingException::setSource only accept RuleProcessor 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 an ExpressionProcessor object. | [
"Set",
"the",
"source",
"of",
"the",
"error",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rules/RuleProcessingException.php#L75-L83 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/Utils.php | Utils.gcd | static public function gcd($a, $b)
{
$a = abs($a);
$b = abs($b);
$k = max($a, $b);
$m = min($a, $b);
while ($m !== 0) {
$r = $k % $m;
$k = $m;
$m = $r;
}
return $k;
} | php | static public function gcd($a, $b)
{
$a = abs($a);
$b = abs($b);
$k = max($a, $b);
$m = min($a, $b);
while ($m !== 0) {
$r = $k % $m;
$k = $m;
$m = $r;
}
return $k;
} | [
"static",
"public",
"function",
"gcd",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"$",
"a",
"=",
"abs",
"(",
"$",
"a",
")",
";",
"$",
"b",
"=",
"abs",
"(",
"$",
"b",
")",
";",
"$",
"k",
"=",
"max",
"(",
"$",
"a",
",",
"$",
"b",
")",
";",
"$",
"m",
"=",
"min",
"(",
"$",
"a",
",",
"$",
"b",
")",
";",
"while",
"(",
"$",
"m",
"!==",
"0",
")",
"{",
"$",
"r",
"=",
"$",
"k",
"%",
"$",
"m",
";",
"$",
"k",
"=",
"$",
"m",
";",
"$",
"m",
"=",
"$",
"r",
";",
"}",
"return",
"$",
"k",
";",
"}"
] | Compute the GCD (Greatest Common Divider) of $a and $b.
If either $a or $b is negative, its absolute value will be used
instead.
@param integer $a A positive integer
@param integer $b A positive integer
@return integer The GCD of $a and $b. | [
"Compute",
"the",
"GCD",
"(",
"Greatest",
"Common",
"Divider",
")",
"of",
"$a",
"and",
"$b",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/Utils.php#L46-L61 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/Utils.php | Utils.lcm | static public function lcm($a, $b)
{
$a = abs($a);
$b = abs($b);
if ($a === 0 || $b === 0) {
return 0;
}
$a = $a / self::gcd($a, $b);
return $a * $b;
} | php | static public function lcm($a, $b)
{
$a = abs($a);
$b = abs($b);
if ($a === 0 || $b === 0) {
return 0;
}
$a = $a / self::gcd($a, $b);
return $a * $b;
} | [
"static",
"public",
"function",
"lcm",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"$",
"a",
"=",
"abs",
"(",
"$",
"a",
")",
";",
"$",
"b",
"=",
"abs",
"(",
"$",
"b",
")",
";",
"if",
"(",
"$",
"a",
"===",
"0",
"||",
"$",
"b",
"===",
"0",
")",
"{",
"return",
"0",
";",
"}",
"$",
"a",
"=",
"$",
"a",
"/",
"self",
"::",
"gcd",
"(",
"$",
"a",
",",
"$",
"b",
")",
";",
"return",
"$",
"a",
"*",
"$",
"b",
";",
"}"
] | Compute LCM (Least Common Multiple) of $a and $b.
@param integer $a
@param integer $b
@return integer the LCM of $a and $b. | [
"Compute",
"LCM",
"(",
"Least",
"Common",
"Multiple",
")",
"of",
"$a",
"and",
"$b",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/Utils.php#L70-L82 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/Utils.php | Utils.mean | static public function mean(array $sample)
{
$count = count($sample);
if ($count === 0) {
return false;
}
$sum = 0;
foreach ($sample as $s) {
$sType = gettype($s);
if ($sType !== 'integer' && $sType !== 'double') {
// only deal with numeric values.
return false;
}
$sum += $s;
}
return $sum / $count;
} | php | static public function mean(array $sample)
{
$count = count($sample);
if ($count === 0) {
return false;
}
$sum = 0;
foreach ($sample as $s) {
$sType = gettype($s);
if ($sType !== 'integer' && $sType !== 'double') {
// only deal with numeric values.
return false;
}
$sum += $s;
}
return $sum / $count;
} | [
"static",
"public",
"function",
"mean",
"(",
"array",
"$",
"sample",
")",
"{",
"$",
"count",
"=",
"count",
"(",
"$",
"sample",
")",
";",
"if",
"(",
"$",
"count",
"===",
"0",
")",
"{",
"return",
"false",
";",
"}",
"$",
"sum",
"=",
"0",
";",
"foreach",
"(",
"$",
"sample",
"as",
"$",
"s",
")",
"{",
"$",
"sType",
"=",
"gettype",
"(",
"$",
"s",
")",
";",
"if",
"(",
"$",
"sType",
"!==",
"'integer'",
"&&",
"$",
"sType",
"!==",
"'double'",
")",
"{",
"// only deal with numeric values.",
"return",
"false",
";",
"}",
"$",
"sum",
"+=",
"$",
"s",
";",
"}",
"return",
"$",
"sum",
"/",
"$",
"count",
";",
"}"
] | Compute the arithmetic mean of $sample.
@param array An array of numeric values.
@return false|number The arithmetic mean of $sample or false if any of the values of $sample is not numeric or if $sample is empty. | [
"Compute",
"the",
"arithmetic",
"mean",
"of",
"$sample",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/Utils.php#L90-L110 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/Utils.php | Utils.variance | static public function variance(array $sample, $correction = true)
{
$mean = static::mean($sample);
if ($mean === false) {
return false;
}
// We are sure that
// 1. $sample is not empty.
// 2. $sample contains only numeric values.
$count = count($sample);
if ($correction === true && $count <= 1) {
return false;
}
// because self::mean returns false if $sample is empty
// or if it contains non-numeric values, we do not have to
// check that fact anymore.
$sum = 0;
foreach ($sample as $s) {
$sum += pow($s - $mean, 2);
}
$d = ($correction === true) ? $count - 1 : $count;
return $sum / $d;
} | php | static public function variance(array $sample, $correction = true)
{
$mean = static::mean($sample);
if ($mean === false) {
return false;
}
// We are sure that
// 1. $sample is not empty.
// 2. $sample contains only numeric values.
$count = count($sample);
if ($correction === true && $count <= 1) {
return false;
}
// because self::mean returns false if $sample is empty
// or if it contains non-numeric values, we do not have to
// check that fact anymore.
$sum = 0;
foreach ($sample as $s) {
$sum += pow($s - $mean, 2);
}
$d = ($correction === true) ? $count - 1 : $count;
return $sum / $d;
} | [
"static",
"public",
"function",
"variance",
"(",
"array",
"$",
"sample",
",",
"$",
"correction",
"=",
"true",
")",
"{",
"$",
"mean",
"=",
"static",
"::",
"mean",
"(",
"$",
"sample",
")",
";",
"if",
"(",
"$",
"mean",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"// We are sure that",
"// 1. $sample is not empty.",
"// 2. $sample contains only numeric values.",
"$",
"count",
"=",
"count",
"(",
"$",
"sample",
")",
";",
"if",
"(",
"$",
"correction",
"===",
"true",
"&&",
"$",
"count",
"<=",
"1",
")",
"{",
"return",
"false",
";",
"}",
"// because self::mean returns false if $sample is empty",
"// or if it contains non-numeric values, we do not have to",
"// check that fact anymore.",
"$",
"sum",
"=",
"0",
";",
"foreach",
"(",
"$",
"sample",
"as",
"$",
"s",
")",
"{",
"$",
"sum",
"+=",
"pow",
"(",
"$",
"s",
"-",
"$",
"mean",
",",
"2",
")",
";",
"}",
"$",
"d",
"=",
"(",
"$",
"correction",
"===",
"true",
")",
"?",
"$",
"count",
"-",
"1",
":",
"$",
"count",
";",
"return",
"$",
"sum",
"/",
"$",
"d",
";",
"}"
] | Compute the variance of $sample.
* To compute the population variance: $sample is considered as a population if $correction equals false.
* To compute the sample variance: $sample is considered as sample if $correction equals true.
IMPORTANT:
If $correction is true, $sample must contain more than 1 value, otherwise this method
returns false.
@param array $sample An array of numeric values.
@param boolean $correction (optional) Apply the Bessel's correction on the computed variance.
@return false|number The variance of $sample or false if $sample is empty or contains non-numeric values.
@link http://en.wikipedia.org/wiki/Variance#Population_variance_and_sample_variance | [
"Compute",
"the",
"variance",
"of",
"$sample",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/Utils.php#L127-L155 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/Utils.php | Utils.standardDeviation | static public function standardDeviation(array $sample, $correction = true)
{
$sampleVariance = static::variance($sample, $correction);
if ($sampleVariance === false) {
// non numeric values found in $sample or empty $sample or $correction applied
// but count($sample) <= 1.
return false;
}
return sqrt($sampleVariance);
} | php | static public function standardDeviation(array $sample, $correction = true)
{
$sampleVariance = static::variance($sample, $correction);
if ($sampleVariance === false) {
// non numeric values found in $sample or empty $sample or $correction applied
// but count($sample) <= 1.
return false;
}
return sqrt($sampleVariance);
} | [
"static",
"public",
"function",
"standardDeviation",
"(",
"array",
"$",
"sample",
",",
"$",
"correction",
"=",
"true",
")",
"{",
"$",
"sampleVariance",
"=",
"static",
"::",
"variance",
"(",
"$",
"sample",
",",
"$",
"correction",
")",
";",
"if",
"(",
"$",
"sampleVariance",
"===",
"false",
")",
"{",
"// non numeric values found in $sample or empty $sample or $correction applied",
"// but count($sample) <= 1.",
"return",
"false",
";",
"}",
"return",
"sqrt",
"(",
"$",
"sampleVariance",
")",
";",
"}"
] | Compute the standard deviation of $sample.
* To compute the population standard deviation: $sample is considered as a population if $correction equals false.
* To compute the sample standard deviation: $sample is considered as sample if $correction equals true.
IMPORTANT:
If $correction is true, $sample must contain more than 1 value, otherwise this method
returns false.
@param array $sample An array of numeric values.
@param boolean $correction (optional) Whether to apply Bessel's correction.
@return false|number The standard deviation of $sample or false if $sample is empty or contains non-numeric values.
@link http://en.wikipedia.org/wiki/Variance#Population_variance_and_sample_variance | [
"Compute",
"the",
"standard",
"deviation",
"of",
"$sample",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/Utils.php#L172-L183 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/Utils.php | Utils.getPrecedingBackslashesCount | static public function getPrecedingBackslashesCount($string, $offset)
{
$count = 0;
if ($offset < strlen($string)) {
for ($i = $offset; $i > 0; $i--) {
if ($string[$i - 1] === '\\') {
$count++;
} else {
break;
}
}
}
return $count;
} | php | static public function getPrecedingBackslashesCount($string, $offset)
{
$count = 0;
if ($offset < strlen($string)) {
for ($i = $offset; $i > 0; $i--) {
if ($string[$i - 1] === '\\') {
$count++;
} else {
break;
}
}
}
return $count;
} | [
"static",
"public",
"function",
"getPrecedingBackslashesCount",
"(",
"$",
"string",
",",
"$",
"offset",
")",
"{",
"$",
"count",
"=",
"0",
";",
"if",
"(",
"$",
"offset",
"<",
"strlen",
"(",
"$",
"string",
")",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"$",
"offset",
";",
"$",
"i",
">",
"0",
";",
"$",
"i",
"--",
")",
"{",
"if",
"(",
"$",
"string",
"[",
"$",
"i",
"-",
"1",
"]",
"===",
"'\\\\'",
")",
"{",
"$",
"count",
"++",
";",
"}",
"else",
"{",
"break",
";",
"}",
"}",
"}",
"return",
"$",
"count",
";",
"}"
] | Get the amout of backslash (\) characters in $string that precede $offset.
@param string $string
@param integer $offset
@return integer | [
"Get",
"the",
"amout",
"of",
"backslash",
"(",
"\\",
")",
"characters",
"in",
"$string",
"that",
"precede",
"$offset",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/Utils.php#L203-L218 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/Utils.php | Utils.escapeSymbols | static public function escapeSymbols($string, $symbols)
{
if (!is_array($symbols)) {
$symbols = array($symbols);
}
$len = mb_strlen($string, 'UTF-8');
$returnValue = '';
for ($i = 0; $i < $len; $i++) {
$char = mb_substr($string, $i, 1); // get a multi-byte char.
if (in_array($char, $symbols) === true) {
// Check escaping.
// If the amount of preceding backslashes is odd, it is escaped.
// If the amount of preceding backslashes is even, it is not escaped.
if (static::getPrecedingBackslashesCount($string, $i) % 2 === 0) {
// It is not escaped, so ecape it.
$returnValue .= '\\';
}
}
$returnValue .= $char;
}
return $returnValue;
} | php | static public function escapeSymbols($string, $symbols)
{
if (!is_array($symbols)) {
$symbols = array($symbols);
}
$len = mb_strlen($string, 'UTF-8');
$returnValue = '';
for ($i = 0; $i < $len; $i++) {
$char = mb_substr($string, $i, 1); // get a multi-byte char.
if (in_array($char, $symbols) === true) {
// Check escaping.
// If the amount of preceding backslashes is odd, it is escaped.
// If the amount of preceding backslashes is even, it is not escaped.
if (static::getPrecedingBackslashesCount($string, $i) % 2 === 0) {
// It is not escaped, so ecape it.
$returnValue .= '\\';
}
}
$returnValue .= $char;
}
return $returnValue;
} | [
"static",
"public",
"function",
"escapeSymbols",
"(",
"$",
"string",
",",
"$",
"symbols",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"symbols",
")",
")",
"{",
"$",
"symbols",
"=",
"array",
"(",
"$",
"symbols",
")",
";",
"}",
"$",
"len",
"=",
"mb_strlen",
"(",
"$",
"string",
",",
"'UTF-8'",
")",
";",
"$",
"returnValue",
"=",
"''",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"len",
";",
"$",
"i",
"++",
")",
"{",
"$",
"char",
"=",
"mb_substr",
"(",
"$",
"string",
",",
"$",
"i",
",",
"1",
")",
";",
"// get a multi-byte char.",
"if",
"(",
"in_array",
"(",
"$",
"char",
",",
"$",
"symbols",
")",
"===",
"true",
")",
"{",
"// Check escaping.",
"// If the amount of preceding backslashes is odd, it is escaped.",
"// If the amount of preceding backslashes is even, it is not escaped.",
"if",
"(",
"static",
"::",
"getPrecedingBackslashesCount",
"(",
"$",
"string",
",",
"$",
"i",
")",
"%",
"2",
"===",
"0",
")",
"{",
"// It is not escaped, so ecape it.",
"$",
"returnValue",
".=",
"'\\\\'",
";",
"}",
"}",
"$",
"returnValue",
".=",
"$",
"char",
";",
"}",
"return",
"$",
"returnValue",
";",
"}"
] | Escape with a backslash (\) the $symbols in $string.
@param string $string
@param array|string $symbols An array of symbols or a single symbol.
@return string The escaped string. | [
"Escape",
"with",
"a",
"backslash",
"(",
"\\",
")",
"the",
"$symbols",
"in",
"$string",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/Utils.php#L227-L253 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/Utils.php | Utils.customOperatorClassToPhpClass | static public function customOperatorClassToPhpClass($class)
{
if (is_string($class) === false) {
return false;
} elseif (Format::isIdentifier($class, false) === false) {
return false;
}
$class = strval($class);
$tokens = explode('.', $class);
$tokenCount = count($tokens);
if ($tokenCount <= 1) {
return false;
}
// ucfirst on last token (i.e. The actual class name)
$lastPosition = $tokenCount - 1;
$lastToken = ucfirst($tokens[$lastPosition]);
$tokens[$lastPosition] = $lastToken;
return implode("\\", $tokens);
} | php | static public function customOperatorClassToPhpClass($class)
{
if (is_string($class) === false) {
return false;
} elseif (Format::isIdentifier($class, false) === false) {
return false;
}
$class = strval($class);
$tokens = explode('.', $class);
$tokenCount = count($tokens);
if ($tokenCount <= 1) {
return false;
}
// ucfirst on last token (i.e. The actual class name)
$lastPosition = $tokenCount - 1;
$lastToken = ucfirst($tokens[$lastPosition]);
$tokens[$lastPosition] = $lastToken;
return implode("\\", $tokens);
} | [
"static",
"public",
"function",
"customOperatorClassToPhpClass",
"(",
"$",
"class",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"class",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"elseif",
"(",
"Format",
"::",
"isIdentifier",
"(",
"$",
"class",
",",
"false",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"$",
"class",
"=",
"strval",
"(",
"$",
"class",
")",
";",
"$",
"tokens",
"=",
"explode",
"(",
"'.'",
",",
"$",
"class",
")",
";",
"$",
"tokenCount",
"=",
"count",
"(",
"$",
"tokens",
")",
";",
"if",
"(",
"$",
"tokenCount",
"<=",
"1",
")",
"{",
"return",
"false",
";",
"}",
"// ucfirst on last token (i.e. The actual class name)",
"$",
"lastPosition",
"=",
"$",
"tokenCount",
"-",
"1",
";",
"$",
"lastToken",
"=",
"ucfirst",
"(",
"$",
"tokens",
"[",
"$",
"lastPosition",
"]",
")",
";",
"$",
"tokens",
"[",
"$",
"lastPosition",
"]",
"=",
"$",
"lastToken",
";",
"return",
"implode",
"(",
"\"\\\\\"",
",",
"$",
"tokens",
")",
";",
"}"
] | Transform a custom operator class e.g. 'org.qtism.custom.explode' into a PHP
fully qualified class name e.g. 'org\qtism\custom\Explode'.
@param string $class A custom operator class name where namespace separator is '.' (dot).
@return boolean|string A fully qualified PHP class name corresponding to $class or false if the transformation failed. | [
"Transform",
"a",
"custom",
"operator",
"class",
"e",
".",
"g",
".",
"org",
".",
"qtism",
".",
"custom",
".",
"explode",
"into",
"a",
"PHP",
"fully",
"qualified",
"class",
"name",
"e",
".",
"g",
".",
"org",
"\\",
"qtism",
"\\",
"custom",
"\\",
"Explode",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/Utils.php#L262-L284 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/Utils.php | Utils.lastPregErrorMessage | static public function lastPregErrorMessage()
{
$error = preg_last_error();
$errorType = 'PCRE Engine error';
switch ($error) {
case PREG_BACKTRACK_LIMIT_ERROR:
$errorType = "PCRE Engine backtrack limit exceeded";
break;
case PREG_RECURSION_LIMIT_ERROR:
$errorType = "PCRE Engine recursion limit exceeded";
break;
case PREG_BAD_UTF8_ERROR:case PREG_BAD_UTF8_OFFSET_ERROR:
$errorType = "PCRE Engine malformed UTF-8 error";
break;
}
return $errorType;
} | php | static public function lastPregErrorMessage()
{
$error = preg_last_error();
$errorType = 'PCRE Engine error';
switch ($error) {
case PREG_BACKTRACK_LIMIT_ERROR:
$errorType = "PCRE Engine backtrack limit exceeded";
break;
case PREG_RECURSION_LIMIT_ERROR:
$errorType = "PCRE Engine recursion limit exceeded";
break;
case PREG_BAD_UTF8_ERROR:case PREG_BAD_UTF8_OFFSET_ERROR:
$errorType = "PCRE Engine malformed UTF-8 error";
break;
}
return $errorType;
} | [
"static",
"public",
"function",
"lastPregErrorMessage",
"(",
")",
"{",
"$",
"error",
"=",
"preg_last_error",
"(",
")",
";",
"$",
"errorType",
"=",
"'PCRE Engine error'",
";",
"switch",
"(",
"$",
"error",
")",
"{",
"case",
"PREG_BACKTRACK_LIMIT_ERROR",
":",
"$",
"errorType",
"=",
"\"PCRE Engine backtrack limit exceeded\"",
";",
"break",
";",
"case",
"PREG_RECURSION_LIMIT_ERROR",
":",
"$",
"errorType",
"=",
"\"PCRE Engine recursion limit exceeded\"",
";",
"break",
";",
"case",
"PREG_BAD_UTF8_ERROR",
":",
"case",
"PREG_BAD_UTF8_OFFSET_ERROR",
":",
"$",
"errorType",
"=",
"\"PCRE Engine malformed UTF-8 error\"",
";",
"break",
";",
"}",
"return",
"$",
"errorType",
";",
"}"
] | Get a meaningful message for the last PREG error that occured.
The following PREG error codes are considered by this method:
* PREG_BACKTRACK_LIMIT_ERROR
* PREG_RECURSION_LIMIT_ERROR
* PREG_BAD_UTF8_ERROR
* PREG_BAD_UTF8_OFFSET_ERROR
@return string | [
"Get",
"a",
"meaningful",
"message",
"for",
"the",
"last",
"PREG",
"error",
"that",
"occured",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/Utils.php#L298-L319 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/Utils.php | Utils.prepareXsdPatternForPcre | static public function prepareXsdPatternForPcre($pattern)
{
// XML schema always implicitly anchors the entire regular expression
// because there is no carret (^) nor dollar ($) signs.
// see http://www.regular-expressions.info/xml.html
$pattern = self::escapeSymbols($pattern, array('$', '^'));
$pattern = self::pregAddDelimiter('^' . $pattern . '$');
// XSD regexp always case-sensitive (nothing to do), dot matches white-spaces (use PCRE_DOTALL).
$pattern .= 's';
return $pattern;
} | php | static public function prepareXsdPatternForPcre($pattern)
{
// XML schema always implicitly anchors the entire regular expression
// because there is no carret (^) nor dollar ($) signs.
// see http://www.regular-expressions.info/xml.html
$pattern = self::escapeSymbols($pattern, array('$', '^'));
$pattern = self::pregAddDelimiter('^' . $pattern . '$');
// XSD regexp always case-sensitive (nothing to do), dot matches white-spaces (use PCRE_DOTALL).
$pattern .= 's';
return $pattern;
} | [
"static",
"public",
"function",
"prepareXsdPatternForPcre",
"(",
"$",
"pattern",
")",
"{",
"// XML schema always implicitly anchors the entire regular expression",
"// because there is no carret (^) nor dollar ($) signs.",
"// see http://www.regular-expressions.info/xml.html",
"$",
"pattern",
"=",
"self",
"::",
"escapeSymbols",
"(",
"$",
"pattern",
",",
"array",
"(",
"'$'",
",",
"'^'",
")",
")",
";",
"$",
"pattern",
"=",
"self",
"::",
"pregAddDelimiter",
"(",
"'^'",
".",
"$",
"pattern",
".",
"'$'",
")",
";",
"// XSD regexp always case-sensitive (nothing to do), dot matches white-spaces (use PCRE_DOTALL).",
"$",
"pattern",
".=",
"'s'",
";",
"return",
"$",
"pattern",
";",
"}"
] | Prepare an XSD Regular Expression pattern into a PCRE compliant one.
@return string | [
"Prepare",
"an",
"XSD",
"Regular",
"Expression",
"pattern",
"into",
"a",
"PCRE",
"compliant",
"one",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/Utils.php#L326-L338 |
oat-sa/qti-sdk | src/qtism/cli/Cli.php | Cli.main | public static function main()
{
$cli = new static();
// Initialize arguments from factory method.
$arguments = $cli->setupArguments();
// Add help flag.
$arguments->addFlag(array('help', 'h'), 'Show help screen.');
// Add verbose flag.
$arguments->addFlag(array('verbose', 'v'), 'Verbose mode.');
// Parse arguments and provide to implementation.
$arguments->parse();
$cli->setArguments($arguments);
if ($arguments['help'] === true) {
echo $arguments->getHelpScreen() . "\n\n";
} else {
// Perform arguments check.
$cli->checkArguments();
// Run the CLI Module implementation.
$cli->run();
}
} | php | public static function main()
{
$cli = new static();
// Initialize arguments from factory method.
$arguments = $cli->setupArguments();
// Add help flag.
$arguments->addFlag(array('help', 'h'), 'Show help screen.');
// Add verbose flag.
$arguments->addFlag(array('verbose', 'v'), 'Verbose mode.');
// Parse arguments and provide to implementation.
$arguments->parse();
$cli->setArguments($arguments);
if ($arguments['help'] === true) {
echo $arguments->getHelpScreen() . "\n\n";
} else {
// Perform arguments check.
$cli->checkArguments();
// Run the CLI Module implementation.
$cli->run();
}
} | [
"public",
"static",
"function",
"main",
"(",
")",
"{",
"$",
"cli",
"=",
"new",
"static",
"(",
")",
";",
"// Initialize arguments from factory method.",
"$",
"arguments",
"=",
"$",
"cli",
"->",
"setupArguments",
"(",
")",
";",
"// Add help flag.",
"$",
"arguments",
"->",
"addFlag",
"(",
"array",
"(",
"'help'",
",",
"'h'",
")",
",",
"'Show help screen.'",
")",
";",
"// Add verbose flag.",
"$",
"arguments",
"->",
"addFlag",
"(",
"array",
"(",
"'verbose'",
",",
"'v'",
")",
",",
"'Verbose mode.'",
")",
";",
"// Parse arguments and provide to implementation.",
"$",
"arguments",
"->",
"parse",
"(",
")",
";",
"$",
"cli",
"->",
"setArguments",
"(",
"$",
"arguments",
")",
";",
"if",
"(",
"$",
"arguments",
"[",
"'help'",
"]",
"===",
"true",
")",
"{",
"echo",
"$",
"arguments",
"->",
"getHelpScreen",
"(",
")",
".",
"\"\\n\\n\"",
";",
"}",
"else",
"{",
"// Perform arguments check.",
"$",
"cli",
"->",
"checkArguments",
"(",
")",
";",
"// Run the CLI Module implementation.",
"$",
"cli",
"->",
"run",
"(",
")",
";",
"}",
"}"
] | Main CLI entry point. | [
"Main",
"CLI",
"entry",
"point",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/cli/Cli.php#L87-L113 |
oat-sa/qti-sdk | src/qtism/cli/Cli.php | Cli.success | protected function success($message)
{
if ($this->isVerbose() === true) {
$this->out("%g${message}%n", true);
}
exit(self::EXIT_SUCCESS);
} | php | protected function success($message)
{
if ($this->isVerbose() === true) {
$this->out("%g${message}%n", true);
}
exit(self::EXIT_SUCCESS);
} | [
"protected",
"function",
"success",
"(",
"$",
"message",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isVerbose",
"(",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"out",
"(",
"\"%g${message}%n\"",
",",
"true",
")",
";",
"}",
"exit",
"(",
"self",
"::",
"EXIT_SUCCESS",
")",
";",
"}"
] | Show a success message as a single line in stdout and return a zero POSIX exit status.
This method produces no output if verbose mode is not in force but the exit status
will still be returned.
@param string $message The success message. | [
"Show",
"a",
"success",
"message",
"as",
"a",
"single",
"line",
"in",
"stdout",
"and",
"return",
"a",
"zero",
"POSIX",
"exit",
"status",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/cli/Cli.php#L181-L188 |
oat-sa/qti-sdk | src/qtism/cli/Cli.php | Cli.out | protected function out($data, $newLine = true)
{
CliTools\out($data);
if ($newLine === true) {
CliTools\out("\n");
}
} | php | protected function out($data, $newLine = true)
{
CliTools\out($data);
if ($newLine === true) {
CliTools\out("\n");
}
} | [
"protected",
"function",
"out",
"(",
"$",
"data",
",",
"$",
"newLine",
"=",
"true",
")",
"{",
"CliTools",
"\\",
"out",
"(",
"$",
"data",
")",
";",
"if",
"(",
"$",
"newLine",
"===",
"true",
")",
"{",
"CliTools",
"\\",
"out",
"(",
"\"\\n\"",
")",
";",
"}",
"}"
] | Show raw data in console even if verbose mode is not in force.
@param string $data The data to go in output.
@param boolean $newLine Whether to display a new line after $data. | [
"Show",
"raw",
"data",
"in",
"console",
"even",
"if",
"verbose",
"mode",
"is",
"not",
"in",
"force",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/cli/Cli.php#L240-L247 |
oat-sa/qti-sdk | src/qtism/common/collections/AbstractCollection.php | AbstractCollection.offsetGet | public function offsetGet($offset)
{
return isset($this->dataPlaceHolder[$offset]) ? $this->dataPlaceHolder[$offset] : null;
} | php | public function offsetGet($offset)
{
return isset($this->dataPlaceHolder[$offset]) ? $this->dataPlaceHolder[$offset] : null;
} | [
"public",
"function",
"offsetGet",
"(",
"$",
"offset",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"dataPlaceHolder",
"[",
"$",
"offset",
"]",
")",
"?",
"$",
"this",
"->",
"dataPlaceHolder",
"[",
"$",
"offset",
"]",
":",
"null",
";",
"}"
] | Offset to retrieve. If the $offset does not reference any value, a null
value is returned.
@param mixed $offset The offset to retrieve.
@return mixex The value at specified offset. | [
"Offset",
"to",
"retrieve",
".",
"If",
"the",
"$offset",
"does",
"not",
"reference",
"any",
"value",
"a",
"null",
"value",
"is",
"returned",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/collections/AbstractCollection.php#L160-L163 |
oat-sa/qti-sdk | src/qtism/common/collections/AbstractCollection.php | AbstractCollection.offsetSet | public function offsetSet($offset, $value)
{
$this->checkType($value);
if (is_null($offset)) {
array_push($this->dataPlaceHolder, $value);
} else {
$this->dataPlaceHolder[$offset] = $value;
}
} | php | public function offsetSet($offset, $value)
{
$this->checkType($value);
if (is_null($offset)) {
array_push($this->dataPlaceHolder, $value);
} else {
$this->dataPlaceHolder[$offset] = $value;
}
} | [
"public",
"function",
"offsetSet",
"(",
"$",
"offset",
",",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"checkType",
"(",
"$",
"value",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"offset",
")",
")",
"{",
"array_push",
"(",
"$",
"this",
"->",
"dataPlaceHolder",
",",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"dataPlaceHolder",
"[",
"$",
"offset",
"]",
"=",
"$",
"value",
";",
"}",
"}"
] | Offset to set. If a value is already set for the given $offset, its value
will be overriden with $value.
@param mixed $offset The offset to assign the value to.
@param mixed $value The value to set.
@throws \InvalidArgumentException If $value has not a valid type regarding the implementation. | [
"Offset",
"to",
"set",
".",
"If",
"a",
"value",
"is",
"already",
"set",
"for",
"the",
"given",
"$offset",
"its",
"value",
"will",
"be",
"overriden",
"with",
"$value",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/collections/AbstractCollection.php#L173-L182 |
oat-sa/qti-sdk | src/qtism/common/collections/AbstractCollection.php | AbstractCollection.getArrayCopy | public function getArrayCopy($preserveKeys = false)
{
return ($preserveKeys === true) ? $this->dataPlaceHolder : array_values($this->dataPlaceHolder);
} | php | public function getArrayCopy($preserveKeys = false)
{
return ($preserveKeys === true) ? $this->dataPlaceHolder : array_values($this->dataPlaceHolder);
} | [
"public",
"function",
"getArrayCopy",
"(",
"$",
"preserveKeys",
"=",
"false",
")",
"{",
"return",
"(",
"$",
"preserveKeys",
"===",
"true",
")",
"?",
"$",
"this",
"->",
"dataPlaceHolder",
":",
"array_values",
"(",
"$",
"this",
"->",
"dataPlaceHolder",
")",
";",
"}"
] | Get a copy of the collection as an array. This method is implemented in order
to implement ArrayObject in a near future.
@return array The collection as an array of data. | [
"Get",
"a",
"copy",
"of",
"the",
"collection",
"as",
"an",
"array",
".",
"This",
"method",
"is",
"implemented",
"in",
"order",
"to",
"implement",
"ArrayObject",
"in",
"a",
"near",
"future",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/collections/AbstractCollection.php#L195-L198 |
oat-sa/qti-sdk | src/qtism/common/collections/AbstractCollection.php | AbstractCollection.contains | public function contains($value)
{
foreach (array_keys($this->dataPlaceHolder) as $key) {
$data = $this->dataPlaceHolder[$key];
if ($value === $data || ($data instanceof Comparable && $data->equals($value))) {
return true;
}
}
return false;
} | php | public function contains($value)
{
foreach (array_keys($this->dataPlaceHolder) as $key) {
$data = $this->dataPlaceHolder[$key];
if ($value === $data || ($data instanceof Comparable && $data->equals($value))) {
return true;
}
}
return false;
} | [
"public",
"function",
"contains",
"(",
"$",
"value",
")",
"{",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"dataPlaceHolder",
")",
"as",
"$",
"key",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"dataPlaceHolder",
"[",
"$",
"key",
"]",
";",
"if",
"(",
"$",
"value",
"===",
"$",
"data",
"||",
"(",
"$",
"data",
"instanceof",
"Comparable",
"&&",
"$",
"data",
"->",
"equals",
"(",
"$",
"value",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Whether the collection contains a given $value. The comparison
is strict, using the === operator.
@param mixed $value A value.
@return boolean Whether the collection contains $value. | [
"Whether",
"the",
"collection",
"contains",
"a",
"given",
"$value",
".",
"The",
"comparison",
"is",
"strict",
"using",
"the",
"===",
"operator",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/collections/AbstractCollection.php#L207-L217 |
oat-sa/qti-sdk | src/qtism/common/collections/AbstractCollection.php | AbstractCollection.attach | public function attach($object)
{
$this->checkType($object);
if (gettype($object) !== 'object') {
$msg = "You can only attach 'objects' into an AbstractCollection, '" . gettype($object) . "' given";
throw new InvalidArgumentException($msg);
} elseif (!$this->contains($object)) {
$this->offsetSet(null, $object);
}
} | php | public function attach($object)
{
$this->checkType($object);
if (gettype($object) !== 'object') {
$msg = "You can only attach 'objects' into an AbstractCollection, '" . gettype($object) . "' given";
throw new InvalidArgumentException($msg);
} elseif (!$this->contains($object)) {
$this->offsetSet(null, $object);
}
} | [
"public",
"function",
"attach",
"(",
"$",
"object",
")",
"{",
"$",
"this",
"->",
"checkType",
"(",
"$",
"object",
")",
";",
"if",
"(",
"gettype",
"(",
"$",
"object",
")",
"!==",
"'object'",
")",
"{",
"$",
"msg",
"=",
"\"You can only attach 'objects' into an AbstractCollection, '\"",
".",
"gettype",
"(",
"$",
"object",
")",
".",
"\"' given\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"elseif",
"(",
"!",
"$",
"this",
"->",
"contains",
"(",
"$",
"object",
")",
")",
"{",
"$",
"this",
"->",
"offsetSet",
"(",
"null",
",",
"$",
"object",
")",
";",
"}",
"}"
] | Attach a given $object to the collection.
@param mixed $object An object.
@throws \InvalidArgumentException If $object is not an 'object' type or not compliant with the typing of the collection. | [
"Attach",
"a",
"given",
"$object",
"to",
"the",
"collection",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/collections/AbstractCollection.php#L225-L235 |
oat-sa/qti-sdk | src/qtism/common/collections/AbstractCollection.php | AbstractCollection.detach | public function detach($object)
{
$this->checkType($object);
if (gettype($object) !== 'object') {
$msg = "You can only detach 'objects' into an AbstractCollection, '" . gettype($object) . "' given.";
throw new InvalidArgumentException($msg);
}
foreach (array_keys($this->dataPlaceHolder) as $k) {
if ($this->dataPlaceHolder[$k] === $object) {
$this->offsetUnset($k);
return;
}
}
$msg = "The object you want to detach could not be found in the collection.";
throw new UnexpectedValueException($msg);
} | php | public function detach($object)
{
$this->checkType($object);
if (gettype($object) !== 'object') {
$msg = "You can only detach 'objects' into an AbstractCollection, '" . gettype($object) . "' given.";
throw new InvalidArgumentException($msg);
}
foreach (array_keys($this->dataPlaceHolder) as $k) {
if ($this->dataPlaceHolder[$k] === $object) {
$this->offsetUnset($k);
return;
}
}
$msg = "The object you want to detach could not be found in the collection.";
throw new UnexpectedValueException($msg);
} | [
"public",
"function",
"detach",
"(",
"$",
"object",
")",
"{",
"$",
"this",
"->",
"checkType",
"(",
"$",
"object",
")",
";",
"if",
"(",
"gettype",
"(",
"$",
"object",
")",
"!==",
"'object'",
")",
"{",
"$",
"msg",
"=",
"\"You can only detach 'objects' into an AbstractCollection, '\"",
".",
"gettype",
"(",
"$",
"object",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"dataPlaceHolder",
")",
"as",
"$",
"k",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"dataPlaceHolder",
"[",
"$",
"k",
"]",
"===",
"$",
"object",
")",
"{",
"$",
"this",
"->",
"offsetUnset",
"(",
"$",
"k",
")",
";",
"return",
";",
"}",
"}",
"$",
"msg",
"=",
"\"The object you want to detach could not be found in the collection.\"",
";",
"throw",
"new",
"UnexpectedValueException",
"(",
"$",
"msg",
")",
";",
"}"
] | Detach a given $object from the collection.
@param mixed $object An object.
@throws \InvalidArgumentException If $object is not an 'object' type or not compliant with the typing of the collection.
@throws \UnexpectedValueException If $object cannot be found in the collection. | [
"Detach",
"a",
"given",
"$object",
"from",
"the",
"collection",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/collections/AbstractCollection.php#L244-L263 |
oat-sa/qti-sdk | src/qtism/common/collections/AbstractCollection.php | AbstractCollection.replace | public function replace($object, $replacement)
{
$this->checkType($object);
$this->checkType($replacement);
if (gettype($object) !== 'object') {
$msg = "You can only replace 'objects' into an AbstractCollection, '" . gettype($object) . "' given.";
throw new InvalidArgumentException($msg);
}
if (gettype($replacement) !== 'object') {
$msg = "You can only replace 'objects' into an AbstractCollection, '" . gettype($replacement) . "' given.";
throw new InvalidArgumentException($msg);
}
foreach (array_keys($this->dataPlaceHolder) as $k) {
if ($this->dataPlaceHolder[$k] === $object) {
$this->dataPlaceHolder[$k] = $replacement;
return;
}
}
$msg = "The object you want to replace could not be found.";
throw new UnexpectedValueException($msg);
} | php | public function replace($object, $replacement)
{
$this->checkType($object);
$this->checkType($replacement);
if (gettype($object) !== 'object') {
$msg = "You can only replace 'objects' into an AbstractCollection, '" . gettype($object) . "' given.";
throw new InvalidArgumentException($msg);
}
if (gettype($replacement) !== 'object') {
$msg = "You can only replace 'objects' into an AbstractCollection, '" . gettype($replacement) . "' given.";
throw new InvalidArgumentException($msg);
}
foreach (array_keys($this->dataPlaceHolder) as $k) {
if ($this->dataPlaceHolder[$k] === $object) {
$this->dataPlaceHolder[$k] = $replacement;
return;
}
}
$msg = "The object you want to replace could not be found.";
throw new UnexpectedValueException($msg);
} | [
"public",
"function",
"replace",
"(",
"$",
"object",
",",
"$",
"replacement",
")",
"{",
"$",
"this",
"->",
"checkType",
"(",
"$",
"object",
")",
";",
"$",
"this",
"->",
"checkType",
"(",
"$",
"replacement",
")",
";",
"if",
"(",
"gettype",
"(",
"$",
"object",
")",
"!==",
"'object'",
")",
"{",
"$",
"msg",
"=",
"\"You can only replace 'objects' into an AbstractCollection, '\"",
".",
"gettype",
"(",
"$",
"object",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"if",
"(",
"gettype",
"(",
"$",
"replacement",
")",
"!==",
"'object'",
")",
"{",
"$",
"msg",
"=",
"\"You can only replace 'objects' into an AbstractCollection, '\"",
".",
"gettype",
"(",
"$",
"replacement",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"dataPlaceHolder",
")",
"as",
"$",
"k",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"dataPlaceHolder",
"[",
"$",
"k",
"]",
"===",
"$",
"object",
")",
"{",
"$",
"this",
"->",
"dataPlaceHolder",
"[",
"$",
"k",
"]",
"=",
"$",
"replacement",
";",
"return",
";",
"}",
"}",
"$",
"msg",
"=",
"\"The object you want to replace could not be found.\"",
";",
"throw",
"new",
"UnexpectedValueException",
"(",
"$",
"msg",
")",
";",
"}"
] | Replace an $object in the collection by another $replacement $object.
@param mixed $object An object to be replaced.
@param mixed $replacement An object to be used as a replacement.
@throws \InvalidArgumentException If $object or $replacement are not compliant with the current collection typing.
@throws \UnexpectedValueException If $object is not contained in the collection. | [
"Replace",
"an",
"$object",
"in",
"the",
"collection",
"by",
"another",
"$replacement",
"$object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/collections/AbstractCollection.php#L273-L298 |
oat-sa/qti-sdk | src/qtism/common/collections/AbstractCollection.php | AbstractCollection.remove | public function remove($object)
{
foreach (array_keys($this->dataPlaceHolder) as $k) {
if ($this->dataPlaceHolder[$k] === $object) {
unset($this->dataPlaceHolder[$k]);
return;
}
}
} | php | public function remove($object)
{
foreach (array_keys($this->dataPlaceHolder) as $k) {
if ($this->dataPlaceHolder[$k] === $object) {
unset($this->dataPlaceHolder[$k]);
return;
}
}
} | [
"public",
"function",
"remove",
"(",
"$",
"object",
")",
"{",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"dataPlaceHolder",
")",
"as",
"$",
"k",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"dataPlaceHolder",
"[",
"$",
"k",
"]",
"===",
"$",
"object",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"dataPlaceHolder",
"[",
"$",
"k",
"]",
")",
";",
"return",
";",
"}",
"}",
"}"
] | Remove $object from the collection. If $object is not in the collection,
it remains as it is.
@param mixed $object The object to remove from the collection. | [
"Remove",
"$object",
"from",
"the",
"collection",
".",
"If",
"$object",
"is",
"not",
"in",
"the",
"collection",
"it",
"remains",
"as",
"it",
"is",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/collections/AbstractCollection.php#L306-L315 |
oat-sa/qti-sdk | src/qtism/common/collections/AbstractCollection.php | AbstractCollection.merge | public function merge(AbstractCollection $collection)
{
if (is_subclass_of($collection, get_class($this)) === true || get_class($collection) === get_class($this)) {
$newData = array_merge($this->dataPlaceHolder, $collection->getDataPlaceHolder());
$this->dataPlaceHolder = $newData;
} else {
$msg = "Only collections with compliant types can be merged ";
$msg.= "('" . get_class($this) . "' vs '" . get_class($collection) . "').";
throw new InvalidArgumentException($msg);
}
} | php | public function merge(AbstractCollection $collection)
{
if (is_subclass_of($collection, get_class($this)) === true || get_class($collection) === get_class($this)) {
$newData = array_merge($this->dataPlaceHolder, $collection->getDataPlaceHolder());
$this->dataPlaceHolder = $newData;
} else {
$msg = "Only collections with compliant types can be merged ";
$msg.= "('" . get_class($this) . "' vs '" . get_class($collection) . "').";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"merge",
"(",
"AbstractCollection",
"$",
"collection",
")",
"{",
"if",
"(",
"is_subclass_of",
"(",
"$",
"collection",
",",
"get_class",
"(",
"$",
"this",
")",
")",
"===",
"true",
"||",
"get_class",
"(",
"$",
"collection",
")",
"===",
"get_class",
"(",
"$",
"this",
")",
")",
"{",
"$",
"newData",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"dataPlaceHolder",
",",
"$",
"collection",
"->",
"getDataPlaceHolder",
"(",
")",
")",
";",
"$",
"this",
"->",
"dataPlaceHolder",
"=",
"$",
"newData",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"Only collections with compliant types can be merged \"",
";",
"$",
"msg",
".=",
"\"('\"",
".",
"get_class",
"(",
"$",
"this",
")",
".",
"\"' vs '\"",
".",
"get_class",
"(",
"$",
"collection",
")",
".",
"\"').\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Merge the collection with another one.
@param qtism\common\collections\AbstractCollection $collection
@throws \InvalidArgumentException If $collection is not a subclass of the target of the call. | [
"Merge",
"the",
"collection",
"with",
"another",
"one",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/collections/AbstractCollection.php#L342-L352 |
oat-sa/qti-sdk | src/qtism/common/collections/AbstractCollection.php | AbstractCollection.diff | public function diff(AbstractCollection $collection)
{
if (get_class($this) === get_class($collection)) {
$newData = array_diff($this->dataPlaceHolder, $collection->getDataPlaceHolder());
return new static($newData);
} else {
$msg = "Difference may apply only on two collections of the same type.";
throw new InvalidArgumentException($msg);
}
} | php | public function diff(AbstractCollection $collection)
{
if (get_class($this) === get_class($collection)) {
$newData = array_diff($this->dataPlaceHolder, $collection->getDataPlaceHolder());
return new static($newData);
} else {
$msg = "Difference may apply only on two collections of the same type.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"diff",
"(",
"AbstractCollection",
"$",
"collection",
")",
"{",
"if",
"(",
"get_class",
"(",
"$",
"this",
")",
"===",
"get_class",
"(",
"$",
"collection",
")",
")",
"{",
"$",
"newData",
"=",
"array_diff",
"(",
"$",
"this",
"->",
"dataPlaceHolder",
",",
"$",
"collection",
"->",
"getDataPlaceHolder",
"(",
")",
")",
";",
"return",
"new",
"static",
"(",
"$",
"newData",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"Difference may apply only on two collections of the same type.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Get the difference between this collection and another one.
@param \qtism\common\collections\AbstractCollection $collection
@return \qtism\common\collections\AbstractCollection | [
"Get",
"the",
"difference",
"between",
"this",
"collection",
"and",
"another",
"one",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/collections/AbstractCollection.php#L360-L370 |
oat-sa/qti-sdk | src/qtism/common/collections/AbstractCollection.php | AbstractCollection.intersect | public function intersect(AbstractCollection $collection)
{
if (get_class($this) === get_class($collection)) {
$newData = array_intersect($this->dataPlaceHolder, $collection->getDataPlaceHolder());
return new static($newData);
} else {
$msg = "Intersection may apply only on two collections of the same type.";
throw new InvalidArgumentException($msg);
}
} | php | public function intersect(AbstractCollection $collection)
{
if (get_class($this) === get_class($collection)) {
$newData = array_intersect($this->dataPlaceHolder, $collection->getDataPlaceHolder());
return new static($newData);
} else {
$msg = "Intersection may apply only on two collections of the same type.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"intersect",
"(",
"AbstractCollection",
"$",
"collection",
")",
"{",
"if",
"(",
"get_class",
"(",
"$",
"this",
")",
"===",
"get_class",
"(",
"$",
"collection",
")",
")",
"{",
"$",
"newData",
"=",
"array_intersect",
"(",
"$",
"this",
"->",
"dataPlaceHolder",
",",
"$",
"collection",
"->",
"getDataPlaceHolder",
"(",
")",
")",
";",
"return",
"new",
"static",
"(",
"$",
"newData",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"Intersection may apply only on two collections of the same type.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Get the intersection between this collection and another one.
@param \qtism\common\collections\AbstractCollection $collection
@return \qtism\common\collections\AbstractCollection | [
"Get",
"the",
"intersection",
"between",
"this",
"collection",
"and",
"another",
"one",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/collections/AbstractCollection.php#L378-L388 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/MemberProcessor.php | MemberProcessor.process | public function process()
{
$operands = $this->getOperands();
if ($operands->containsNull() === true) {
return null;
}
if ($operands->sameBaseType() === false) {
$msg = "The Member operator only accepts values with the same baseType.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
}
$operand1 = $operands[0];
$operand2 = $operands[1];
// The first expression must have single cardinality.
if (CommonUtils::inferCardinality($operand1) !== Cardinality::SINGLE) {
$msg = "The first operand of the Member operator must have a single cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
// The second expression must have multiple or ordered cardinality.
$cardinality = CommonUtils::inferCardinality($operand2);
if ($cardinality === Cardinality::SINGLE) {
$operand2 = new MultipleContainer($operand1->getBaseType(), array($operand2));
} elseif ($cardinality !== Cardinality::MULTIPLE && $cardinality !== Cardinality::ORDERED) {
$msg = "The second operand of the Member operator must have a single, multiple or ordered cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
return new QtiBoolean($operand2->contains($operand1));
} | php | public function process()
{
$operands = $this->getOperands();
if ($operands->containsNull() === true) {
return null;
}
if ($operands->sameBaseType() === false) {
$msg = "The Member operator only accepts values with the same baseType.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
}
$operand1 = $operands[0];
$operand2 = $operands[1];
// The first expression must have single cardinality.
if (CommonUtils::inferCardinality($operand1) !== Cardinality::SINGLE) {
$msg = "The first operand of the Member operator must have a single cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
// The second expression must have multiple or ordered cardinality.
$cardinality = CommonUtils::inferCardinality($operand2);
if ($cardinality === Cardinality::SINGLE) {
$operand2 = new MultipleContainer($operand1->getBaseType(), array($operand2));
} elseif ($cardinality !== Cardinality::MULTIPLE && $cardinality !== Cardinality::ORDERED) {
$msg = "The second operand of the Member operator must have a single, multiple or ordered cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
return new QtiBoolean($operand2->contains($operand1));
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"operands",
"=",
"$",
"this",
"->",
"getOperands",
"(",
")",
";",
"if",
"(",
"$",
"operands",
"->",
"containsNull",
"(",
")",
"===",
"true",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"operands",
"->",
"sameBaseType",
"(",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The Member operator only accepts values with the same baseType.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_BASETYPE",
")",
";",
"}",
"$",
"operand1",
"=",
"$",
"operands",
"[",
"0",
"]",
";",
"$",
"operand2",
"=",
"$",
"operands",
"[",
"1",
"]",
";",
"// The first expression must have single cardinality.",
"if",
"(",
"CommonUtils",
"::",
"inferCardinality",
"(",
"$",
"operand1",
")",
"!==",
"Cardinality",
"::",
"SINGLE",
")",
"{",
"$",
"msg",
"=",
"\"The first operand of the Member operator must have a single cardinality.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_CARDINALITY",
")",
";",
"}",
"// The second expression must have multiple or ordered cardinality.",
"$",
"cardinality",
"=",
"CommonUtils",
"::",
"inferCardinality",
"(",
"$",
"operand2",
")",
";",
"if",
"(",
"$",
"cardinality",
"===",
"Cardinality",
"::",
"SINGLE",
")",
"{",
"$",
"operand2",
"=",
"new",
"MultipleContainer",
"(",
"$",
"operand1",
"->",
"getBaseType",
"(",
")",
",",
"array",
"(",
"$",
"operand2",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"cardinality",
"!==",
"Cardinality",
"::",
"MULTIPLE",
"&&",
"$",
"cardinality",
"!==",
"Cardinality",
"::",
"ORDERED",
")",
"{",
"$",
"msg",
"=",
"\"The second operand of the Member operator must have a single, multiple or ordered cardinality.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_CARDINALITY",
")",
";",
"}",
"return",
"new",
"QtiBoolean",
"(",
"$",
"operand2",
"->",
"contains",
"(",
"$",
"operand1",
")",
")",
";",
"}"
] | Process the Member operator.
@return boolean Whether the first operand is contained by the second one as a boolean value, or NULL if any of the sub-expressions are NULL.
@throws \qtism\runtime\expressions\operators\OperatorProcessingException | [
"Process",
"the",
"Member",
"operator",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/MemberProcessor.php#L57-L89 |
oat-sa/qti-sdk | src/qtism/data/content/interactions/MatchInteraction.php | MatchInteraction.setSimpleMatchSets | public function setSimpleMatchSets(SimpleMatchSetCollection $simpleMatchSets)
{
if (count($simpleMatchSets) === 2) {
$this->simpleMatchSets = $simpleMatchSets;
} else {
$msg = "A MatchInteraction object must be composed of exactly two SimpleMatchSet objects.";
throw new InvalidArgumentException($msg);
}
} | php | public function setSimpleMatchSets(SimpleMatchSetCollection $simpleMatchSets)
{
if (count($simpleMatchSets) === 2) {
$this->simpleMatchSets = $simpleMatchSets;
} else {
$msg = "A MatchInteraction object must be composed of exactly two SimpleMatchSet objects.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setSimpleMatchSets",
"(",
"SimpleMatchSetCollection",
"$",
"simpleMatchSets",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"simpleMatchSets",
")",
"===",
"2",
")",
"{",
"$",
"this",
"->",
"simpleMatchSets",
"=",
"$",
"simpleMatchSets",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"A MatchInteraction object must be composed of exactly two SimpleMatchSet objects.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the set of choices. The first defines the source choices and the second one the
targets.
@param \qtism\data\content\interactions\SimpleMatchSetCollection $simpleMatchSets A collection of exactly two SimpleMatchSet objects.
@throws \InvalidArgumentException If $simpleMatchSets does not contain exactly two SimpleMatchSet objects. | [
"Set",
"the",
"set",
"of",
"choices",
".",
"The",
"first",
"defines",
"the",
"source",
"choices",
"and",
"the",
"second",
"one",
"the",
"targets",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/interactions/MatchInteraction.php#L203-L211 |
oat-sa/qti-sdk | src/qtism/data/storage/FileResolver.php | FileResolver.setBasePath | public function setBasePath($basePath = '')
{
if (gettype($basePath) === 'string') {
$this->basePath = $basePath;
} else {
$msg = "The basePath argument must be a valid string, '" . gettype($basePath) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setBasePath($basePath = '')
{
if (gettype($basePath) === 'string') {
$this->basePath = $basePath;
} else {
$msg = "The basePath argument must be a valid string, '" . gettype($basePath) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setBasePath",
"(",
"$",
"basePath",
"=",
"''",
")",
"{",
"if",
"(",
"gettype",
"(",
"$",
"basePath",
")",
"===",
"'string'",
")",
"{",
"$",
"this",
"->",
"basePath",
"=",
"$",
"basePath",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The basePath argument must be a valid string, '\"",
".",
"gettype",
"(",
"$",
"basePath",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the basePath.
@param string $basePath A base path.
@throws \InvalidArgumentException If $basePath is not a string value. | [
"Set",
"the",
"basePath",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/FileResolver.php#L60-L68 |
oat-sa/qti-sdk | src/qtism/data/state/MatchTableEntry.php | MatchTableEntry.setSourceValue | public function setSourceValue($sourceValue)
{
if (is_int($sourceValue)) {
$this->sourceValue = $sourceValue;
} else {
$msg = "SourceValue must be an integer, '" . gettype($sourceValue) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setSourceValue($sourceValue)
{
if (is_int($sourceValue)) {
$this->sourceValue = $sourceValue;
} else {
$msg = "SourceValue must be an integer, '" . gettype($sourceValue) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setSourceValue",
"(",
"$",
"sourceValue",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"sourceValue",
")",
")",
"{",
"$",
"this",
"->",
"sourceValue",
"=",
"$",
"sourceValue",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"SourceValue must be an integer, '\"",
".",
"gettype",
"(",
"$",
"sourceValue",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the source integer that must be matched exactly.
@param integer $sourceValue An integer value.
@throws \InvalidArgumentException If $sourceValue is not an integer. | [
"Set",
"the",
"source",
"integer",
"that",
"must",
"be",
"matched",
"exactly",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/state/MatchTableEntry.php#L86-L94 |
oat-sa/qti-sdk | src/qtism/data/content/TemplateElement.php | TemplateElement.setTemplateIdentifier | public function setTemplateIdentifier($templateIdentifier)
{
if (Format::isIdentifier($templateIdentifier, false) === true) {
$this->templateIdentifier = $templateIdentifier;
} else {
$msg = "The 'templateIdentifier' argument must be a valid QTI identifier, '" . $templateIdentifier . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setTemplateIdentifier($templateIdentifier)
{
if (Format::isIdentifier($templateIdentifier, false) === true) {
$this->templateIdentifier = $templateIdentifier;
} else {
$msg = "The 'templateIdentifier' argument must be a valid QTI identifier, '" . $templateIdentifier . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setTemplateIdentifier",
"(",
"$",
"templateIdentifier",
")",
"{",
"if",
"(",
"Format",
"::",
"isIdentifier",
"(",
"$",
"templateIdentifier",
",",
"false",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"templateIdentifier",
"=",
"$",
"templateIdentifier",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'templateIdentifier' argument must be a valid QTI identifier, '\"",
".",
"$",
"templateIdentifier",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the template variable identifier.
@param string $templateIdentifier A QTI identifier.
@throws \InvalidArgumentException If $templateIdentifier is not a valid QTI identifier. | [
"Set",
"the",
"template",
"variable",
"identifier",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/TemplateElement.php#L89-L97 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/IndexProcessor.php | IndexProcessor.process | public function process()
{
$operands = $this->getOperands();
if ($operands->containsNull()) {
return null;
}
if ($operands->exclusivelyOrdered() === false) {
$msg = "The Index operator only accepts values with a cardinality of ordered.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
$n = $this->getExpression()->getN();
if (gettype($n) === 'string') {
// The value of $n comes from the state.
$state = $this->getState();
if (($index = $state[ProcessingUtils::sanitizeVariableRef($n)]) !== null) {
if ($index instanceof QtiInteger) {
$n = $index->getValue();
} else {
$msg = "The value '${index}' is not an integer. Ordered containers can be only accessed by integers.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_VARIABLE_BASETYPE);
}
} else {
$msg = "Unknown variable reference '${n}'.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::NONEXISTENT_VARIABLE);
}
}
if ($n < 1) {
$msg = "The value of 'n' must be a non-zero postive integer, '${n}' given.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::LOGIC_ERROR);
}
$n = $n - 1; // QTI indexes begin at 1...
if ($n > count($operands[0]) - 1) {
// As per specs, if n exceeds the number of values in the container,
// the result of the index operator is NULL.
return null;
}
return $operands[0][$n];
} | php | public function process()
{
$operands = $this->getOperands();
if ($operands->containsNull()) {
return null;
}
if ($operands->exclusivelyOrdered() === false) {
$msg = "The Index operator only accepts values with a cardinality of ordered.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
$n = $this->getExpression()->getN();
if (gettype($n) === 'string') {
// The value of $n comes from the state.
$state = $this->getState();
if (($index = $state[ProcessingUtils::sanitizeVariableRef($n)]) !== null) {
if ($index instanceof QtiInteger) {
$n = $index->getValue();
} else {
$msg = "The value '${index}' is not an integer. Ordered containers can be only accessed by integers.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_VARIABLE_BASETYPE);
}
} else {
$msg = "Unknown variable reference '${n}'.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::NONEXISTENT_VARIABLE);
}
}
if ($n < 1) {
$msg = "The value of 'n' must be a non-zero postive integer, '${n}' given.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::LOGIC_ERROR);
}
$n = $n - 1; // QTI indexes begin at 1...
if ($n > count($operands[0]) - 1) {
// As per specs, if n exceeds the number of values in the container,
// the result of the index operator is NULL.
return null;
}
return $operands[0][$n];
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"operands",
"=",
"$",
"this",
"->",
"getOperands",
"(",
")",
";",
"if",
"(",
"$",
"operands",
"->",
"containsNull",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"operands",
"->",
"exclusivelyOrdered",
"(",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The Index operator only accepts values with a cardinality of ordered.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_CARDINALITY",
")",
";",
"}",
"$",
"n",
"=",
"$",
"this",
"->",
"getExpression",
"(",
")",
"->",
"getN",
"(",
")",
";",
"if",
"(",
"gettype",
"(",
"$",
"n",
")",
"===",
"'string'",
")",
"{",
"// The value of $n comes from the state.",
"$",
"state",
"=",
"$",
"this",
"->",
"getState",
"(",
")",
";",
"if",
"(",
"(",
"$",
"index",
"=",
"$",
"state",
"[",
"ProcessingUtils",
"::",
"sanitizeVariableRef",
"(",
"$",
"n",
")",
"]",
")",
"!==",
"null",
")",
"{",
"if",
"(",
"$",
"index",
"instanceof",
"QtiInteger",
")",
"{",
"$",
"n",
"=",
"$",
"index",
"->",
"getValue",
"(",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The value '${index}' is not an integer. Ordered containers can be only accessed by integers.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_VARIABLE_BASETYPE",
")",
";",
"}",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"Unknown variable reference '${n}'.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"NONEXISTENT_VARIABLE",
")",
";",
"}",
"}",
"if",
"(",
"$",
"n",
"<",
"1",
")",
"{",
"$",
"msg",
"=",
"\"The value of 'n' must be a non-zero postive integer, '${n}' given.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"LOGIC_ERROR",
")",
";",
"}",
"$",
"n",
"=",
"$",
"n",
"-",
"1",
";",
"// QTI indexes begin at 1...",
"if",
"(",
"$",
"n",
">",
"count",
"(",
"$",
"operands",
"[",
"0",
"]",
")",
"-",
"1",
")",
"{",
"// As per specs, if n exceeds the number of values in the container,",
"// the result of the index operator is NULL.",
"return",
"null",
";",
"}",
"return",
"$",
"operands",
"[",
"0",
"]",
"[",
"$",
"n",
"]",
";",
"}"
] | Process the Index operator.
@return mixed|null A QTIRuntime compliant scalar value. NULL is returned if expression->n exceeds the number of values in the container or the sub-expression is NULL.
@throws \qtism\runtime\expressions\operators\OperatorProcessingException | [
"Process",
"the",
"Index",
"operator",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/IndexProcessor.php#L55-L98 |
oat-sa/qti-sdk | src/qtism/data/storage/php/PhpVariable.php | PhpVariable.setName | public function setName($name)
{
if (is_string($name) === false) {
$msg = "The 'name' argument must be a string value, '" . gettype($name) . "' given.";
throw new InvalidArgumentException($msg);
}
$this->name = $name;
} | php | public function setName($name)
{
if (is_string($name) === false) {
$msg = "The 'name' argument must be a string value, '" . gettype($name) . "' given.";
throw new InvalidArgumentException($msg);
}
$this->name = $name;
} | [
"public",
"function",
"setName",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"name",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The 'name' argument must be a string value, '\"",
".",
"gettype",
"(",
"$",
"name",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"$",
"this",
"->",
"name",
"=",
"$",
"name",
";",
"}"
] | Set the name of the variable.
@param string $name The name of the variable without the leading dollar sign ('$').
@throws InvalidArgumentException If $name is not a string value. | [
"Set",
"the",
"name",
"of",
"the",
"variable",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/php/PhpVariable.php#L59-L67 |
oat-sa/qti-sdk | src/qtism/data/content/ModalFeedbackRule.php | ModalFeedbackRule.setTitle | public function setTitle($title)
{
if (is_string($title) === true) {
$this->title = $title;
} else {
$msg = "The 'title' argument must be a string, '" . gettype($title) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setTitle($title)
{
if (is_string($title) === true) {
$this->title = $title;
} else {
$msg = "The 'title' argument must be a string, '" . gettype($title) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setTitle",
"(",
"$",
"title",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"title",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"title",
"=",
"$",
"title",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'title' argument must be a string, '\"",
".",
"gettype",
"(",
"$",
"title",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the title of the feedback.
An empty string means there is no title.
@param string $title
@throws InvalidArgumentException If $title is not a string. | [
"Set",
"the",
"title",
"of",
"the",
"feedback",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/ModalFeedbackRule.php#L176-L184 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/ColMarshaller.php | ColMarshaller.marshall | protected function marshall(QtiComponent $component)
{
$element = self::getDOMCradle()->createElement('col');
if ($component->getSpan() !== 1) {
$this->setDOMElementAttribute($element, 'span', $component->getSpan());
}
$this->fillElement($element, $component);
return $element;
} | php | protected function marshall(QtiComponent $component)
{
$element = self::getDOMCradle()->createElement('col');
if ($component->getSpan() !== 1) {
$this->setDOMElementAttribute($element, 'span', $component->getSpan());
}
$this->fillElement($element, $component);
return $element;
} | [
"protected",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"$",
"element",
"=",
"self",
"::",
"getDOMCradle",
"(",
")",
"->",
"createElement",
"(",
"'col'",
")",
";",
"if",
"(",
"$",
"component",
"->",
"getSpan",
"(",
")",
"!==",
"1",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'span'",
",",
"$",
"component",
"->",
"getSpan",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"fillElement",
"(",
"$",
"element",
",",
"$",
"component",
")",
";",
"return",
"$",
"element",
";",
"}"
] | Marshall a Col object into a DOMElement object.
@param \QtiComponent $component A Col object.
@return \DOMElement The according DOMElement object.
@throws \qtism\data\storage\xml\marshalling\MarshallingException | [
"Marshall",
"a",
"Col",
"object",
"into",
"a",
"DOMElement",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/ColMarshaller.php#L44-L55 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/ColMarshaller.php | ColMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
$component = new Col();
if (($span = $this->getDOMElementAttributeAs($element, 'span', 'integer')) !== null) {
$component->setSpan($span);
}
$this->fillBodyElement($component, $element);
return $component;
} | php | protected function unmarshall(DOMElement $element)
{
$component = new Col();
if (($span = $this->getDOMElementAttributeAs($element, 'span', 'integer')) !== null) {
$component->setSpan($span);
}
$this->fillBodyElement($component, $element);
return $component;
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"$",
"component",
"=",
"new",
"Col",
"(",
")",
";",
"if",
"(",
"(",
"$",
"span",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'span'",
",",
"'integer'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"component",
"->",
"setSpan",
"(",
"$",
"span",
")",
";",
"}",
"$",
"this",
"->",
"fillBodyElement",
"(",
"$",
"component",
",",
"$",
"element",
")",
";",
"return",
"$",
"component",
";",
"}"
] | Unmarshall a DOMElement object corresponding to an XHTML col element.
@param \DOMElement $element A DOMElement object.
@return \qtism\data\QtiComponent A Col object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException | [
"Unmarshall",
"a",
"DOMElement",
"object",
"corresponding",
"to",
"an",
"XHTML",
"col",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/ColMarshaller.php#L64-L75 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/StatsOperatorProcessor.php | StatsOperatorProcessor.process | public function process()
{
$operands = $this->getOperands();
if ($operands->containsNull() === true) {
return null;
}
if ($operands->exclusivelyMultipleOrOrdered() === false) {
$msg = "The StatsOperator operator only accepts operands with a multiple or ordered cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
if ($operands->exclusivelyNumeric() === false) {
$msg = "The StatsOperator operator only accepts operands with a multiple or ordered cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
}
$qtiFuncName = Statistics::getNameByConstant($this->getExpression()->getName());
$methodName = 'process' . ucfirst($qtiFuncName);
return call_user_func_array(array($this, $methodName), array());
} | php | public function process()
{
$operands = $this->getOperands();
if ($operands->containsNull() === true) {
return null;
}
if ($operands->exclusivelyMultipleOrOrdered() === false) {
$msg = "The StatsOperator operator only accepts operands with a multiple or ordered cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
if ($operands->exclusivelyNumeric() === false) {
$msg = "The StatsOperator operator only accepts operands with a multiple or ordered cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
}
$qtiFuncName = Statistics::getNameByConstant($this->getExpression()->getName());
$methodName = 'process' . ucfirst($qtiFuncName);
return call_user_func_array(array($this, $methodName), array());
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"operands",
"=",
"$",
"this",
"->",
"getOperands",
"(",
")",
";",
"if",
"(",
"$",
"operands",
"->",
"containsNull",
"(",
")",
"===",
"true",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"operands",
"->",
"exclusivelyMultipleOrOrdered",
"(",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The StatsOperator operator only accepts operands with a multiple or ordered cardinality.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_CARDINALITY",
")",
";",
"}",
"if",
"(",
"$",
"operands",
"->",
"exclusivelyNumeric",
"(",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The StatsOperator operator only accepts operands with a multiple or ordered cardinality.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_BASETYPE",
")",
";",
"}",
"$",
"qtiFuncName",
"=",
"Statistics",
"::",
"getNameByConstant",
"(",
"$",
"this",
"->",
"getExpression",
"(",
")",
"->",
"getName",
"(",
")",
")",
";",
"$",
"methodName",
"=",
"'process'",
".",
"ucfirst",
"(",
"$",
"qtiFuncName",
")",
";",
"return",
"call_user_func_array",
"(",
"array",
"(",
"$",
"this",
",",
"$",
"methodName",
")",
",",
"array",
"(",
")",
")",
";",
"}"
] | Process the StatsOperator.
@return float A single float or NULL if the sub-expression or any value contained therein is NULL.
@throws \qtism\runtime\expressions\operators\OperatorProcessingException | [
"Process",
"the",
"StatsOperator",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/StatsOperatorProcessor.php#L67-L89 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/StatsOperatorProcessor.php | StatsOperatorProcessor.filterValues | protected static function filterValues(array $data)
{
$returnValue = array();
foreach ($data as $d) {
if ($d !== null) {
$returnValue[] = $d->getValue();
} else {
$returnValue[] = $d;
}
}
return $returnValue;
} | php | protected static function filterValues(array $data)
{
$returnValue = array();
foreach ($data as $d) {
if ($d !== null) {
$returnValue[] = $d->getValue();
} else {
$returnValue[] = $d;
}
}
return $returnValue;
} | [
"protected",
"static",
"function",
"filterValues",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"returnValue",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"d",
")",
"{",
"if",
"(",
"$",
"d",
"!==",
"null",
")",
"{",
"$",
"returnValue",
"[",
"]",
"=",
"$",
"d",
"->",
"getValue",
"(",
")",
";",
"}",
"else",
"{",
"$",
"returnValue",
"[",
"]",
"=",
"$",
"d",
";",
"}",
"}",
"return",
"$",
"returnValue",
";",
"}"
] | Filter the $data array by transforming
Float and Integer object into PHP runtime values.
@param array $data An array of Float and/or Integer values.
@return array A filtered array with PHP float and integers. | [
"Filter",
"the",
"$data",
"array",
"by",
"transforming",
"Float",
"and",
"Integer",
"object",
"into",
"PHP",
"runtime",
"values",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/StatsOperatorProcessor.php#L168-L180 |
oat-sa/qti-sdk | src/qtism/common/utils/Version.php | Version.compare | static public function compare($version1, $version2, $operator = null)
{
$version1 = trim($version1);
$version2 = trim($version2);
// Because version_compare consider 2.1 < 2.1.0...
$version1 = self::appendPatchVersion($version1);
$version2 = self::appendPatchVersion($version2);
// Check if the versions are known...
$knownVersions = self::knownVersions();
if (self::isKnown($version1) === false) {
$msg = "Version '${version1}' is not a known QTI version. Known versions are '" . implode(', ', $knownVersions) . "'.";
throw new InvalidArgumentException($msg);
} elseif (self::isKnown($version2) === false) {
$msg = "Version '${version2}' is not a known QTI version. Known versions are '" . implode(', ', $knownVersions) . "'.";
throw new InvalidArgumentException($msg);
}
// Check if operator is correct.
$knownOperators = array('<', 'lt', '<=', 'le', '>', 'gt', '>=', 'ge', '==', '=', 'eq', '!=', '<>', 'ne');
if (is_null($operator) === true || in_array($operator, $knownOperators) === true) {
return (is_null($operator) === true) ? version_compare($version1, $version2) : version_compare($version1, $version2, $operator);
} else {
$msg = "Unknown operator '${operator}'. Known operators are '" . implode(', ', $knownOperators) . "'.";
throw new InvalidArgumentException($msg);
}
} | php | static public function compare($version1, $version2, $operator = null)
{
$version1 = trim($version1);
$version2 = trim($version2);
// Because version_compare consider 2.1 < 2.1.0...
$version1 = self::appendPatchVersion($version1);
$version2 = self::appendPatchVersion($version2);
// Check if the versions are known...
$knownVersions = self::knownVersions();
if (self::isKnown($version1) === false) {
$msg = "Version '${version1}' is not a known QTI version. Known versions are '" . implode(', ', $knownVersions) . "'.";
throw new InvalidArgumentException($msg);
} elseif (self::isKnown($version2) === false) {
$msg = "Version '${version2}' is not a known QTI version. Known versions are '" . implode(', ', $knownVersions) . "'.";
throw new InvalidArgumentException($msg);
}
// Check if operator is correct.
$knownOperators = array('<', 'lt', '<=', 'le', '>', 'gt', '>=', 'ge', '==', '=', 'eq', '!=', '<>', 'ne');
if (is_null($operator) === true || in_array($operator, $knownOperators) === true) {
return (is_null($operator) === true) ? version_compare($version1, $version2) : version_compare($version1, $version2, $operator);
} else {
$msg = "Unknown operator '${operator}'. Known operators are '" . implode(', ', $knownOperators) . "'.";
throw new InvalidArgumentException($msg);
}
} | [
"static",
"public",
"function",
"compare",
"(",
"$",
"version1",
",",
"$",
"version2",
",",
"$",
"operator",
"=",
"null",
")",
"{",
"$",
"version1",
"=",
"trim",
"(",
"$",
"version1",
")",
";",
"$",
"version2",
"=",
"trim",
"(",
"$",
"version2",
")",
";",
"// Because version_compare consider 2.1 < 2.1.0...",
"$",
"version1",
"=",
"self",
"::",
"appendPatchVersion",
"(",
"$",
"version1",
")",
";",
"$",
"version2",
"=",
"self",
"::",
"appendPatchVersion",
"(",
"$",
"version2",
")",
";",
"// Check if the versions are known...",
"$",
"knownVersions",
"=",
"self",
"::",
"knownVersions",
"(",
")",
";",
"if",
"(",
"self",
"::",
"isKnown",
"(",
"$",
"version1",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"Version '${version1}' is not a known QTI version. Known versions are '\"",
".",
"implode",
"(",
"', '",
",",
"$",
"knownVersions",
")",
".",
"\"'.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"elseif",
"(",
"self",
"::",
"isKnown",
"(",
"$",
"version2",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"Version '${version2}' is not a known QTI version. Known versions are '\"",
".",
"implode",
"(",
"', '",
",",
"$",
"knownVersions",
")",
".",
"\"'.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"// Check if operator is correct.",
"$",
"knownOperators",
"=",
"array",
"(",
"'<'",
",",
"'lt'",
",",
"'<='",
",",
"'le'",
",",
"'>'",
",",
"'gt'",
",",
"'>='",
",",
"'ge'",
",",
"'=='",
",",
"'='",
",",
"'eq'",
",",
"'!='",
",",
"'<>'",
",",
"'ne'",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"operator",
")",
"===",
"true",
"||",
"in_array",
"(",
"$",
"operator",
",",
"$",
"knownOperators",
")",
"===",
"true",
")",
"{",
"return",
"(",
"is_null",
"(",
"$",
"operator",
")",
"===",
"true",
")",
"?",
"version_compare",
"(",
"$",
"version1",
",",
"$",
"version2",
")",
":",
"version_compare",
"(",
"$",
"version1",
",",
"$",
"version2",
",",
"$",
"operator",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"Unknown operator '${operator}'. Known operators are '\"",
".",
"implode",
"(",
"', '",
",",
"$",
"knownOperators",
")",
".",
"\"'.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Compare two version numbers of QTI, following the rules of Semantic Versioning.
This method provides QTI version comparison. Two versions are compared using an optional operator.
When no $operator is provided, this method returns
* -1 if $version1 is lower than $version2
* 0 if $version1 is equal to $version2
* 1 if $version1 is greater than $version2
In case of using a specific $operator, the method returns true or false depending on
the $operator and versions given. Accepted operators are '<', 'lt', '<=', 'le', '>', 'gt',
'>=', 'ge', '==', '=', 'eq', '!=' and 'ne'.
If an unknown QTI version is given for $version1 or $version2 arguments, or if $operator
is an unknown operator, an InvalidArgumentException is thrown.
Important note: This metod will consider version '2.1' and '2.1.0' equal.
@param string $version1 A version number.
@param string $version2 A version number
@param string $operator An operator.
@throws \InvalidArgumentException
@return mixed
@see http://semver.org Semantic Versioning | [
"Compare",
"two",
"version",
"numbers",
"of",
"QTI",
"following",
"the",
"rules",
"of",
"Semantic",
"Versioning",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/utils/Version.php#L61-L88 |
oat-sa/qti-sdk | src/qtism/common/utils/Version.php | Version.isKnown | static public function isKnown($version)
{
$version = self::appendPatchVersion($version);
return in_array($version, self::knownVersions());
} | php | static public function isKnown($version)
{
$version = self::appendPatchVersion($version);
return in_array($version, self::knownVersions());
} | [
"static",
"public",
"function",
"isKnown",
"(",
"$",
"version",
")",
"{",
"$",
"version",
"=",
"self",
"::",
"appendPatchVersion",
"(",
"$",
"version",
")",
";",
"return",
"in_array",
"(",
"$",
"version",
",",
"self",
"::",
"knownVersions",
"(",
")",
")",
";",
"}"
] | Wether or not a $version containing a major, minor and patch
version is a known QTI version.
@param string $version A version with major, minor and patch version e.g. '2.1.1'.
@return boolean | [
"Wether",
"or",
"not",
"a",
"$version",
"containing",
"a",
"major",
"minor",
"and",
"patch",
"version",
"is",
"a",
"known",
"QTI",
"version",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/utils/Version.php#L97-L101 |
oat-sa/qti-sdk | src/qtism/common/utils/Version.php | Version.appendPatchVersion | static public function appendPatchVersion($version)
{
$shortKnownVersions = array('2.0', '2.1', '2.2');
if (in_array($version, $shortKnownVersions) === true) {
$version = $version . '.0';
}
return $version;
} | php | static public function appendPatchVersion($version)
{
$shortKnownVersions = array('2.0', '2.1', '2.2');
if (in_array($version, $shortKnownVersions) === true) {
$version = $version . '.0';
}
return $version;
} | [
"static",
"public",
"function",
"appendPatchVersion",
"(",
"$",
"version",
")",
"{",
"$",
"shortKnownVersions",
"=",
"array",
"(",
"'2.0'",
",",
"'2.1'",
",",
"'2.2'",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"version",
",",
"$",
"shortKnownVersions",
")",
"===",
"true",
")",
"{",
"$",
"version",
"=",
"$",
"version",
".",
"'.0'",
";",
"}",
"return",
"$",
"version",
";",
"}"
] | Append patch version to $version if $version only contains
major and minor versions.
@param string $version
@return string | [
"Append",
"patch",
"version",
"to",
"$version",
"if",
"$version",
"only",
"contains",
"major",
"and",
"minor",
"versions",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/utils/Version.php#L121-L129 |
oat-sa/qti-sdk | src/qtism/data/AssessmentSection.php | AssessmentSection.setTitle | public function setTitle($title)
{
if (gettype($title) === 'string') {
$this->title = $title;
} else {
$msg = "Title must be a string, '" . gettype($title) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setTitle($title)
{
if (gettype($title) === 'string') {
$this->title = $title;
} else {
$msg = "Title must be a string, '" . gettype($title) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setTitle",
"(",
"$",
"title",
")",
"{",
"if",
"(",
"gettype",
"(",
"$",
"title",
")",
"===",
"'string'",
")",
"{",
"$",
"this",
"->",
"title",
"=",
"$",
"title",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"Title must be a string, '\"",
".",
"gettype",
"(",
"$",
"title",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the title of the Assessment Section.
@param string $title A title.
@throws \InvalidArgumentException If $title is not a string. | [
"Set",
"the",
"title",
"of",
"the",
"Assessment",
"Section",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/AssessmentSection.php#L130-L138 |
oat-sa/qti-sdk | src/qtism/data/AssessmentSection.php | AssessmentSection.setVisible | public function setVisible($visible)
{
if (is_bool($visible)) {
$this->visible = $visible;
} else {
$msg = "Visible must be a boolean, '" . gettype($visible) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setVisible($visible)
{
if (is_bool($visible)) {
$this->visible = $visible;
} else {
$msg = "Visible must be a boolean, '" . gettype($visible) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setVisible",
"(",
"$",
"visible",
")",
"{",
"if",
"(",
"is_bool",
"(",
"$",
"visible",
")",
")",
"{",
"$",
"this",
"->",
"visible",
"=",
"$",
"visible",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"Visible must be a boolean, '\"",
".",
"gettype",
"(",
"$",
"visible",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the visibility of the section.
@param boolean $visible true if it must be visible, false otherwise.
@throws \InvalidArgumentException If $visible is not a boolean. | [
"Set",
"the",
"visibility",
"of",
"the",
"section",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/AssessmentSection.php#L156-L164 |
oat-sa/qti-sdk | src/qtism/data/AssessmentSection.php | AssessmentSection.setKeepTogether | public function setKeepTogether($keepTogether)
{
if (is_bool($keepTogether)) {
$this->keepTogether = $keepTogether;
} else {
$msg = "KeepTogether must be a boolean, '" . gettype($keepTogether) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setKeepTogether($keepTogether)
{
if (is_bool($keepTogether)) {
$this->keepTogether = $keepTogether;
} else {
$msg = "KeepTogether must be a boolean, '" . gettype($keepTogether) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setKeepTogether",
"(",
"$",
"keepTogether",
")",
"{",
"if",
"(",
"is_bool",
"(",
"$",
"keepTogether",
")",
")",
"{",
"$",
"this",
"->",
"keepTogether",
"=",
"$",
"keepTogether",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"KeepTogether must be a boolean, '\"",
".",
"gettype",
"(",
"$",
"keepTogether",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set if the items must be kept together if the section is invisible.
@param boolean $keepTogether true if the items must be kept together, false otherwise.
@throws \InvalidArgumentException If $keepTogether is not a boolean. | [
"Set",
"if",
"the",
"items",
"must",
"be",
"kept",
"together",
"if",
"the",
"section",
"is",
"invisible",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/AssessmentSection.php#L182-L190 |
oat-sa/qti-sdk | src/qtism/runtime/processing/Utils.php | Utils.templateProcessingImpactedVariables | static public function templateProcessingImpactedVariables(TemplateProcessing $templateProcessing)
{
$identifiers = array();
$classNames = array(
'setTemplateValue',
'setCorrectResponse',
'setDefaultValue'
);
$iterator = $templateProcessing->getComponentsByClassName($classNames);
foreach ($iterator as $templateRule) {
$identifiers[] = $templateRule->getIdentifier();
}
return array_unique($identifiers);
} | php | static public function templateProcessingImpactedVariables(TemplateProcessing $templateProcessing)
{
$identifiers = array();
$classNames = array(
'setTemplateValue',
'setCorrectResponse',
'setDefaultValue'
);
$iterator = $templateProcessing->getComponentsByClassName($classNames);
foreach ($iterator as $templateRule) {
$identifiers[] = $templateRule->getIdentifier();
}
return array_unique($identifiers);
} | [
"static",
"public",
"function",
"templateProcessingImpactedVariables",
"(",
"TemplateProcessing",
"$",
"templateProcessing",
")",
"{",
"$",
"identifiers",
"=",
"array",
"(",
")",
";",
"$",
"classNames",
"=",
"array",
"(",
"'setTemplateValue'",
",",
"'setCorrectResponse'",
",",
"'setDefaultValue'",
")",
";",
"$",
"iterator",
"=",
"$",
"templateProcessing",
"->",
"getComponentsByClassName",
"(",
"$",
"classNames",
")",
";",
"foreach",
"(",
"$",
"iterator",
"as",
"$",
"templateRule",
")",
"{",
"$",
"identifiers",
"[",
"]",
"=",
"$",
"templateRule",
"->",
"getIdentifier",
"(",
")",
";",
"}",
"return",
"array_unique",
"(",
"$",
"identifiers",
")",
";",
"}"
] | Obtain a list of the identifiers of variables that might have their values changed by
a templateProcessing description.
A variable is considered to be possibly impacted if:
* It is the target of a setTemplateValue template rule.
* It is the target of a setCorrectResponse template rule.
* It is the target of a setDefaultValue template rule.
@param TemplateProcessing $templateProcessing
@return array A list of QTI identifiers. | [
"Obtain",
"a",
"list",
"of",
"the",
"identifiers",
"of",
"variables",
"that",
"might",
"have",
"their",
"values",
"changed",
"by",
"a",
"templateProcessing",
"description",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/processing/Utils.php#L49-L65 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/RepeatMarshaller.php | RepeatMarshaller.unmarshallChildrenKnown | protected function unmarshallChildrenKnown(DOMElement $element, QtiComponentCollection $children)
{
if (($numberRepeats = $this->getDOMElementAttributeAs($element, 'numberRepeats')) !== null) {
if (Format::isInteger($numberRepeats)) {
$numberRepeats = intval($numberRepeats);
}
$object = new Repeat($children, $numberRepeats);
return $object;
} else {
$msg = "The mandatory attribute 'numberRepeats' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} | php | protected function unmarshallChildrenKnown(DOMElement $element, QtiComponentCollection $children)
{
if (($numberRepeats = $this->getDOMElementAttributeAs($element, 'numberRepeats')) !== null) {
if (Format::isInteger($numberRepeats)) {
$numberRepeats = intval($numberRepeats);
}
$object = new Repeat($children, $numberRepeats);
return $object;
} else {
$msg = "The mandatory attribute 'numberRepeats' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} | [
"protected",
"function",
"unmarshallChildrenKnown",
"(",
"DOMElement",
"$",
"element",
",",
"QtiComponentCollection",
"$",
"children",
")",
"{",
"if",
"(",
"(",
"$",
"numberRepeats",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'numberRepeats'",
")",
")",
"!==",
"null",
")",
"{",
"if",
"(",
"Format",
"::",
"isInteger",
"(",
"$",
"numberRepeats",
")",
")",
"{",
"$",
"numberRepeats",
"=",
"intval",
"(",
"$",
"numberRepeats",
")",
";",
"}",
"$",
"object",
"=",
"new",
"Repeat",
"(",
"$",
"children",
",",
"$",
"numberRepeats",
")",
";",
"return",
"$",
"object",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory attribute 'numberRepeats' is missing from element '\"",
".",
"$",
"element",
"->",
"localName",
".",
"\"'.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}"
] | Unmarshall a QTI repeat operator element into a Repeat object.
@param \DOMElement $element The repeat element to unmarshall.
@param \qtism\data\QtiComponentCollection $children A collection containing the child Expression objects composing the Operator.
@return \qtism\data\QtiComponent A Repeat object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException | [
"Unmarshall",
"a",
"QTI",
"repeat",
"operator",
"element",
"into",
"a",
"Repeat",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/RepeatMarshaller.php#L67-L82 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/OutcomeProcessingMarshaller.php | OutcomeProcessingMarshaller.marshall | protected function marshall(QtiComponent $component)
{
$element = self::getDOMCradle()->createElement($component->getQtiClassName());
foreach ($component->getOutcomeRules() as $outcomeRule) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($outcomeRule);
$element->appendChild($marshaller->marshall($outcomeRule));
}
return $element;
} | php | protected function marshall(QtiComponent $component)
{
$element = self::getDOMCradle()->createElement($component->getQtiClassName());
foreach ($component->getOutcomeRules() as $outcomeRule) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($outcomeRule);
$element->appendChild($marshaller->marshall($outcomeRule));
}
return $element;
} | [
"protected",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"$",
"element",
"=",
"self",
"::",
"getDOMCradle",
"(",
")",
"->",
"createElement",
"(",
"$",
"component",
"->",
"getQtiClassName",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"component",
"->",
"getOutcomeRules",
"(",
")",
"as",
"$",
"outcomeRule",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"outcomeRule",
")",
";",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"marshaller",
"->",
"marshall",
"(",
"$",
"outcomeRule",
")",
")",
";",
"}",
"return",
"$",
"element",
";",
"}"
] | Marshall an OutcomeProcessing object into a DOMElement object.
@param \qtism\data\QtiComponent $component An OutcomeProcessing object.
@return \DOMElement The according DOMElement object.
@throws \qtism\data\storage\xml\marshalling\MarshallingException | [
"Marshall",
"an",
"OutcomeProcessing",
"object",
"into",
"a",
"DOMElement",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/OutcomeProcessingMarshaller.php#L45-L55 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/OutcomeProcessingMarshaller.php | OutcomeProcessingMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
$outcomeRuleElts = self::getChildElements($element);
$outcomeRules = new OutcomeRuleCollection();
for ($i = 0; $i < count($outcomeRuleElts); $i++) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($outcomeRuleElts[$i]);
$outcomeRules[] = $marshaller->unmarshall($outcomeRuleElts[$i]);
}
$object = new OutcomeProcessing($outcomeRules);
return $object;
} | php | protected function unmarshall(DOMElement $element)
{
$outcomeRuleElts = self::getChildElements($element);
$outcomeRules = new OutcomeRuleCollection();
for ($i = 0; $i < count($outcomeRuleElts); $i++) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($outcomeRuleElts[$i]);
$outcomeRules[] = $marshaller->unmarshall($outcomeRuleElts[$i]);
}
$object = new OutcomeProcessing($outcomeRules);
return $object;
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"$",
"outcomeRuleElts",
"=",
"self",
"::",
"getChildElements",
"(",
"$",
"element",
")",
";",
"$",
"outcomeRules",
"=",
"new",
"OutcomeRuleCollection",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"outcomeRuleElts",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"outcomeRuleElts",
"[",
"$",
"i",
"]",
")",
";",
"$",
"outcomeRules",
"[",
"]",
"=",
"$",
"marshaller",
"->",
"unmarshall",
"(",
"$",
"outcomeRuleElts",
"[",
"$",
"i",
"]",
")",
";",
"}",
"$",
"object",
"=",
"new",
"OutcomeProcessing",
"(",
"$",
"outcomeRules",
")",
";",
"return",
"$",
"object",
";",
"}"
] | Unmarshall a DOMElement object corresponding to a QTI outcomeProcessing element.
@param \DOMElement $element A DOMElement object.
@return \qtism\data\QtiComponent An OutcomeProcessing object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException | [
"Unmarshall",
"a",
"DOMElement",
"object",
"corresponding",
"to",
"a",
"QTI",
"outcomeProcessing",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/OutcomeProcessingMarshaller.php#L64-L77 |
oat-sa/qti-sdk | src/qtism/runtime/rendering/css/CssScoper.php | CssScoper.render | public function render($file, $id = '')
{
if (empty($id) === true) {
$id = uniqid();
}
$this->init($id, $file);
$stream = $this->getStream();
while ($stream->eof() === false) {
try {
$char = $stream->read(1);
$this->beforeCharReading($char);
switch ($this->getState()) {
case self::RUNNING:
$this->runningState();
break;
case self::IN_ATRULE:
$this->inAtRuleState();
break;
case self::IN_ATRULESTRING:
$this->inAtRuleStringState();
break;
case self::IN_SELECTOR:
$this->inSelectorState();
break;
case self::IN_CLASSBODY:
$this->inClassbodyState();
break;
case self::IN_MAINCOMMENT:
$this->inMainCommentState();
break;
case self::IN_CLASSSTRING:
$this->inClassStringState();
break;
case self::IN_CLASSCOMMENT:
$this->inClassCommentState();
break;
case self::IN_ATRULEBODY:
$this->inAtRuleBodyState();
break;
}
$this->afterCharReading($char);
} catch (MemoryStreamException $e) {
$stream->close();
$msg = "An unexpected error occured while reading the CSS file '${file}'.";
throw new RenderingException($msg, RenderingException::RUNTIME, $e);
}
}
$stream->close();
return $this->getOutput();
} | php | public function render($file, $id = '')
{
if (empty($id) === true) {
$id = uniqid();
}
$this->init($id, $file);
$stream = $this->getStream();
while ($stream->eof() === false) {
try {
$char = $stream->read(1);
$this->beforeCharReading($char);
switch ($this->getState()) {
case self::RUNNING:
$this->runningState();
break;
case self::IN_ATRULE:
$this->inAtRuleState();
break;
case self::IN_ATRULESTRING:
$this->inAtRuleStringState();
break;
case self::IN_SELECTOR:
$this->inSelectorState();
break;
case self::IN_CLASSBODY:
$this->inClassbodyState();
break;
case self::IN_MAINCOMMENT:
$this->inMainCommentState();
break;
case self::IN_CLASSSTRING:
$this->inClassStringState();
break;
case self::IN_CLASSCOMMENT:
$this->inClassCommentState();
break;
case self::IN_ATRULEBODY:
$this->inAtRuleBodyState();
break;
}
$this->afterCharReading($char);
} catch (MemoryStreamException $e) {
$stream->close();
$msg = "An unexpected error occured while reading the CSS file '${file}'.";
throw new RenderingException($msg, RenderingException::RUNTIME, $e);
}
}
$stream->close();
return $this->getOutput();
} | [
"public",
"function",
"render",
"(",
"$",
"file",
",",
"$",
"id",
"=",
"''",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"id",
")",
"===",
"true",
")",
"{",
"$",
"id",
"=",
"uniqid",
"(",
")",
";",
"}",
"$",
"this",
"->",
"init",
"(",
"$",
"id",
",",
"$",
"file",
")",
";",
"$",
"stream",
"=",
"$",
"this",
"->",
"getStream",
"(",
")",
";",
"while",
"(",
"$",
"stream",
"->",
"eof",
"(",
")",
"===",
"false",
")",
"{",
"try",
"{",
"$",
"char",
"=",
"$",
"stream",
"->",
"read",
"(",
"1",
")",
";",
"$",
"this",
"->",
"beforeCharReading",
"(",
"$",
"char",
")",
";",
"switch",
"(",
"$",
"this",
"->",
"getState",
"(",
")",
")",
"{",
"case",
"self",
"::",
"RUNNING",
":",
"$",
"this",
"->",
"runningState",
"(",
")",
";",
"break",
";",
"case",
"self",
"::",
"IN_ATRULE",
":",
"$",
"this",
"->",
"inAtRuleState",
"(",
")",
";",
"break",
";",
"case",
"self",
"::",
"IN_ATRULESTRING",
":",
"$",
"this",
"->",
"inAtRuleStringState",
"(",
")",
";",
"break",
";",
"case",
"self",
"::",
"IN_SELECTOR",
":",
"$",
"this",
"->",
"inSelectorState",
"(",
")",
";",
"break",
";",
"case",
"self",
"::",
"IN_CLASSBODY",
":",
"$",
"this",
"->",
"inClassbodyState",
"(",
")",
";",
"break",
";",
"case",
"self",
"::",
"IN_MAINCOMMENT",
":",
"$",
"this",
"->",
"inMainCommentState",
"(",
")",
";",
"break",
";",
"case",
"self",
"::",
"IN_CLASSSTRING",
":",
"$",
"this",
"->",
"inClassStringState",
"(",
")",
";",
"break",
";",
"case",
"self",
"::",
"IN_CLASSCOMMENT",
":",
"$",
"this",
"->",
"inClassCommentState",
"(",
")",
";",
"break",
";",
"case",
"self",
"::",
"IN_ATRULEBODY",
":",
"$",
"this",
"->",
"inAtRuleBodyState",
"(",
")",
";",
"break",
";",
"}",
"$",
"this",
"->",
"afterCharReading",
"(",
"$",
"char",
")",
";",
"}",
"catch",
"(",
"MemoryStreamException",
"$",
"e",
")",
"{",
"$",
"stream",
"->",
"close",
"(",
")",
";",
"$",
"msg",
"=",
"\"An unexpected error occured while reading the CSS file '${file}'.\"",
";",
"throw",
"new",
"RenderingException",
"(",
"$",
"msg",
",",
"RenderingException",
"::",
"RUNTIME",
",",
"$",
"e",
")",
";",
"}",
"}",
"$",
"stream",
"->",
"close",
"(",
")",
";",
"return",
"$",
"this",
"->",
"getOutput",
"(",
")",
";",
"}"
] | Rescope the content of a given CSS file.
@param string $file The path to the file that has to be rescoped.
@param string $id The scope identifier. If not given, will be randomly generated.
@return string The rescoped content of $file.
@throws \qtism\runtime\rendering\RenderingException If something goes wrong while rescoping the content. | [
"Rescope",
"the",
"content",
"of",
"a",
"given",
"CSS",
"file",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/css/CssScoper.php#L409-L474 |
oat-sa/qti-sdk | src/qtism/runtime/rendering/css/CssScoper.php | CssScoper.init | protected function init($id, $file)
{
$this->setState(self::RUNNING);
$this->setId($id);
$this->setBuffer(array());
$this->setOutput('');
$this->setPreviousChar(false);
$this->setPreviousSignificantChar(false);
if (($data = @file_get_contents($file)) !== false) {
$stream = new MemoryStream($data);
$stream->open();
$this->setStream($stream);
} else {
throw new RenderingException("The CSS file '${file}' could not be open.", RenderingException::RUNTIME);
}
} | php | protected function init($id, $file)
{
$this->setState(self::RUNNING);
$this->setId($id);
$this->setBuffer(array());
$this->setOutput('');
$this->setPreviousChar(false);
$this->setPreviousSignificantChar(false);
if (($data = @file_get_contents($file)) !== false) {
$stream = new MemoryStream($data);
$stream->open();
$this->setStream($stream);
} else {
throw new RenderingException("The CSS file '${file}' could not be open.", RenderingException::RUNTIME);
}
} | [
"protected",
"function",
"init",
"(",
"$",
"id",
",",
"$",
"file",
")",
"{",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"RUNNING",
")",
";",
"$",
"this",
"->",
"setId",
"(",
"$",
"id",
")",
";",
"$",
"this",
"->",
"setBuffer",
"(",
"array",
"(",
")",
")",
";",
"$",
"this",
"->",
"setOutput",
"(",
"''",
")",
";",
"$",
"this",
"->",
"setPreviousChar",
"(",
"false",
")",
";",
"$",
"this",
"->",
"setPreviousSignificantChar",
"(",
"false",
")",
";",
"if",
"(",
"(",
"$",
"data",
"=",
"@",
"file_get_contents",
"(",
"$",
"file",
")",
")",
"!==",
"false",
")",
"{",
"$",
"stream",
"=",
"new",
"MemoryStream",
"(",
"$",
"data",
")",
";",
"$",
"stream",
"->",
"open",
"(",
")",
";",
"$",
"this",
"->",
"setStream",
"(",
"$",
"stream",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"RenderingException",
"(",
"\"The CSS file '${file}' could not be open.\"",
",",
"RenderingException",
"::",
"RUNTIME",
")",
";",
"}",
"}"
] | Initialize the object to be ready for a new rescoping.
@param string $id The identifier to be used for scoping.
@param string $file The path to the CSS file to be scoped.
@throws \qtism\runtime\rendering\RenderingException | [
"Initialize",
"the",
"object",
"to",
"be",
"ready",
"for",
"a",
"new",
"rescoping",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/css/CssScoper.php#L483-L499 |
oat-sa/qti-sdk | src/qtism/runtime/rendering/css/CssScoper.php | CssScoper.afterCharReading | protected function afterCharReading($char)
{
$this->setPreviousChar($char);
if (self::isWhiteSpace($char) === false) {
$this->setPreviousSignificantChar($char);
}
} | php | protected function afterCharReading($char)
{
$this->setPreviousChar($char);
if (self::isWhiteSpace($char) === false) {
$this->setPreviousSignificantChar($char);
}
} | [
"protected",
"function",
"afterCharReading",
"(",
"$",
"char",
")",
"{",
"$",
"this",
"->",
"setPreviousChar",
"(",
"$",
"char",
")",
";",
"if",
"(",
"self",
"::",
"isWhiteSpace",
"(",
"$",
"char",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"setPreviousSignificantChar",
"(",
"$",
"char",
")",
";",
"}",
"}"
] | Instructions to perform after any character read.
@param string $char | [
"Instructions",
"to",
"perform",
"after",
"any",
"character",
"read",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/css/CssScoper.php#L576-L583 |
oat-sa/qti-sdk | src/qtism/runtime/rendering/css/CssScoper.php | CssScoper.runningState | protected function runningState()
{
$char = $this->getCurrentChar();
if ($char === self::CHAR_AT) {
$this->setState(self::IN_ATRULE);
$this->bufferize($char);
$this->output($char);
} elseif ($char === self::CHAR_STAR && $this->getPreviousChar() === self::CHAR_SLASH) {
$this->setState(self::IN_MAINCOMMENT);
$this->output($char);
} elseif ($char === self::CHAR_SLASH) {
$this->output($char);
} elseif (self::isWhiteSpace($char) === false && $char !== self::CHAR_CLOSINGBRACE) {
$this->bufferize($char);
$this->setState(self::IN_SELECTOR);
} else {
$this->output($char);
}
} | php | protected function runningState()
{
$char = $this->getCurrentChar();
if ($char === self::CHAR_AT) {
$this->setState(self::IN_ATRULE);
$this->bufferize($char);
$this->output($char);
} elseif ($char === self::CHAR_STAR && $this->getPreviousChar() === self::CHAR_SLASH) {
$this->setState(self::IN_MAINCOMMENT);
$this->output($char);
} elseif ($char === self::CHAR_SLASH) {
$this->output($char);
} elseif (self::isWhiteSpace($char) === false && $char !== self::CHAR_CLOSINGBRACE) {
$this->bufferize($char);
$this->setState(self::IN_SELECTOR);
} else {
$this->output($char);
}
} | [
"protected",
"function",
"runningState",
"(",
")",
"{",
"$",
"char",
"=",
"$",
"this",
"->",
"getCurrentChar",
"(",
")",
";",
"if",
"(",
"$",
"char",
"===",
"self",
"::",
"CHAR_AT",
")",
"{",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"IN_ATRULE",
")",
";",
"$",
"this",
"->",
"bufferize",
"(",
"$",
"char",
")",
";",
"$",
"this",
"->",
"output",
"(",
"$",
"char",
")",
";",
"}",
"elseif",
"(",
"$",
"char",
"===",
"self",
"::",
"CHAR_STAR",
"&&",
"$",
"this",
"->",
"getPreviousChar",
"(",
")",
"===",
"self",
"::",
"CHAR_SLASH",
")",
"{",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"IN_MAINCOMMENT",
")",
";",
"$",
"this",
"->",
"output",
"(",
"$",
"char",
")",
";",
"}",
"elseif",
"(",
"$",
"char",
"===",
"self",
"::",
"CHAR_SLASH",
")",
"{",
"$",
"this",
"->",
"output",
"(",
"$",
"char",
")",
";",
"}",
"elseif",
"(",
"self",
"::",
"isWhiteSpace",
"(",
"$",
"char",
")",
"===",
"false",
"&&",
"$",
"char",
"!==",
"self",
"::",
"CHAR_CLOSINGBRACE",
")",
"{",
"$",
"this",
"->",
"bufferize",
"(",
"$",
"char",
")",
";",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"IN_SELECTOR",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"output",
"(",
"$",
"char",
")",
";",
"}",
"}"
] | Instructions to be performed in 'running' state. | [
"Instructions",
"to",
"be",
"performed",
"in",
"running",
"state",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/css/CssScoper.php#L666-L685 |
oat-sa/qti-sdk | src/qtism/runtime/rendering/css/CssScoper.php | CssScoper.inAtRuleState | protected function inAtRuleState()
{
$char = $this->getCurrentChar();
if ($char === self::CHAR_DOUBLEQUOTE) {
$this->setState(self::IN_ATRULESTRING);
} elseif ($char === self::CHAR_TERMINATOR) {
$this->setState(self::RUNNING);
$this->cleanBuffer();
} elseif ($char === self::CHAR_OPENINGBRACE && (($buffer = implode('', $this->getBuffer())) && (strpos($buffer, '@media') !== false || strpos($buffer, '@supports') !== false))) {
$this->setState(self::RUNNING);
$this->cleanBuffer();
} elseif ($char === self::CHAR_OPENINGBRACE) {
$this->setState(self::IN_ATRULEBODY);
$this->cleanBuffer();
$this->bufferize($char);
} else {
$this->bufferize($char);
}
$this->output($char);
} | php | protected function inAtRuleState()
{
$char = $this->getCurrentChar();
if ($char === self::CHAR_DOUBLEQUOTE) {
$this->setState(self::IN_ATRULESTRING);
} elseif ($char === self::CHAR_TERMINATOR) {
$this->setState(self::RUNNING);
$this->cleanBuffer();
} elseif ($char === self::CHAR_OPENINGBRACE && (($buffer = implode('', $this->getBuffer())) && (strpos($buffer, '@media') !== false || strpos($buffer, '@supports') !== false))) {
$this->setState(self::RUNNING);
$this->cleanBuffer();
} elseif ($char === self::CHAR_OPENINGBRACE) {
$this->setState(self::IN_ATRULEBODY);
$this->cleanBuffer();
$this->bufferize($char);
} else {
$this->bufferize($char);
}
$this->output($char);
} | [
"protected",
"function",
"inAtRuleState",
"(",
")",
"{",
"$",
"char",
"=",
"$",
"this",
"->",
"getCurrentChar",
"(",
")",
";",
"if",
"(",
"$",
"char",
"===",
"self",
"::",
"CHAR_DOUBLEQUOTE",
")",
"{",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"IN_ATRULESTRING",
")",
";",
"}",
"elseif",
"(",
"$",
"char",
"===",
"self",
"::",
"CHAR_TERMINATOR",
")",
"{",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"RUNNING",
")",
";",
"$",
"this",
"->",
"cleanBuffer",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"char",
"===",
"self",
"::",
"CHAR_OPENINGBRACE",
"&&",
"(",
"(",
"$",
"buffer",
"=",
"implode",
"(",
"''",
",",
"$",
"this",
"->",
"getBuffer",
"(",
")",
")",
")",
"&&",
"(",
"strpos",
"(",
"$",
"buffer",
",",
"'@media'",
")",
"!==",
"false",
"||",
"strpos",
"(",
"$",
"buffer",
",",
"'@supports'",
")",
"!==",
"false",
")",
")",
")",
"{",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"RUNNING",
")",
";",
"$",
"this",
"->",
"cleanBuffer",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"char",
"===",
"self",
"::",
"CHAR_OPENINGBRACE",
")",
"{",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"IN_ATRULEBODY",
")",
";",
"$",
"this",
"->",
"cleanBuffer",
"(",
")",
";",
"$",
"this",
"->",
"bufferize",
"(",
"$",
"char",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"bufferize",
"(",
"$",
"char",
")",
";",
"}",
"$",
"this",
"->",
"output",
"(",
"$",
"char",
")",
";",
"}"
] | Instructions to be performed in 'atRule' state. | [
"Instructions",
"to",
"be",
"performed",
"in",
"atRule",
"state",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/css/CssScoper.php#L690-L711 |
oat-sa/qti-sdk | src/qtism/runtime/rendering/css/CssScoper.php | CssScoper.inAtRuleStringState | protected function inAtRuleStringState()
{
$char = $this->getCurrentChar();
if ($char === self::CHAR_DOUBLEQUOTE && $this->isEscaping() === false) {
$this->cleanBuffer();
$this->setState(self::IN_ATRULE);
} elseif ($char === self::CHAR_ESCAPE) {
$this->bufferize($char);
} else {
$this->cleanBuffer();
}
$this->output($char);
} | php | protected function inAtRuleStringState()
{
$char = $this->getCurrentChar();
if ($char === self::CHAR_DOUBLEQUOTE && $this->isEscaping() === false) {
$this->cleanBuffer();
$this->setState(self::IN_ATRULE);
} elseif ($char === self::CHAR_ESCAPE) {
$this->bufferize($char);
} else {
$this->cleanBuffer();
}
$this->output($char);
} | [
"protected",
"function",
"inAtRuleStringState",
"(",
")",
"{",
"$",
"char",
"=",
"$",
"this",
"->",
"getCurrentChar",
"(",
")",
";",
"if",
"(",
"$",
"char",
"===",
"self",
"::",
"CHAR_DOUBLEQUOTE",
"&&",
"$",
"this",
"->",
"isEscaping",
"(",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"cleanBuffer",
"(",
")",
";",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"IN_ATRULE",
")",
";",
"}",
"elseif",
"(",
"$",
"char",
"===",
"self",
"::",
"CHAR_ESCAPE",
")",
"{",
"$",
"this",
"->",
"bufferize",
"(",
"$",
"char",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"cleanBuffer",
"(",
")",
";",
"}",
"$",
"this",
"->",
"output",
"(",
"$",
"char",
")",
";",
"}"
] | Instructions to be performed in 'atRuleString' state. | [
"Instructions",
"to",
"be",
"performed",
"in",
"atRuleString",
"state",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/css/CssScoper.php#L716-L730 |
oat-sa/qti-sdk | src/qtism/runtime/rendering/css/CssScoper.php | CssScoper.inAtRuleBodyState | protected function inAtRuleBodyState()
{
$char = $this->getCurrentChar();
if ($char === self::CHAR_CLOSINGBRACE) {
$buffer = implode('', $this->getBuffer());
$openingCount = substr_count($buffer, self::CHAR_OPENINGBRACE);
$closingCount = substr_count($buffer, self::CHAR_CLOSINGBRACE) + 1;
if ($openingCount === $closingCount) {
$this->cleanBuffer();
$this->setState(self::RUNNING);
} else {
$this->bufferize($char);
}
} else {
$this->bufferize($char);
}
$this->output($char);
} | php | protected function inAtRuleBodyState()
{
$char = $this->getCurrentChar();
if ($char === self::CHAR_CLOSINGBRACE) {
$buffer = implode('', $this->getBuffer());
$openingCount = substr_count($buffer, self::CHAR_OPENINGBRACE);
$closingCount = substr_count($buffer, self::CHAR_CLOSINGBRACE) + 1;
if ($openingCount === $closingCount) {
$this->cleanBuffer();
$this->setState(self::RUNNING);
} else {
$this->bufferize($char);
}
} else {
$this->bufferize($char);
}
$this->output($char);
} | [
"protected",
"function",
"inAtRuleBodyState",
"(",
")",
"{",
"$",
"char",
"=",
"$",
"this",
"->",
"getCurrentChar",
"(",
")",
";",
"if",
"(",
"$",
"char",
"===",
"self",
"::",
"CHAR_CLOSINGBRACE",
")",
"{",
"$",
"buffer",
"=",
"implode",
"(",
"''",
",",
"$",
"this",
"->",
"getBuffer",
"(",
")",
")",
";",
"$",
"openingCount",
"=",
"substr_count",
"(",
"$",
"buffer",
",",
"self",
"::",
"CHAR_OPENINGBRACE",
")",
";",
"$",
"closingCount",
"=",
"substr_count",
"(",
"$",
"buffer",
",",
"self",
"::",
"CHAR_CLOSINGBRACE",
")",
"+",
"1",
";",
"if",
"(",
"$",
"openingCount",
"===",
"$",
"closingCount",
")",
"{",
"$",
"this",
"->",
"cleanBuffer",
"(",
")",
";",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"RUNNING",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"bufferize",
"(",
"$",
"char",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"bufferize",
"(",
"$",
"char",
")",
";",
"}",
"$",
"this",
"->",
"output",
"(",
"$",
"char",
")",
";",
"}"
] | Instructions to be performed in 'atRuleBody' state. | [
"Instructions",
"to",
"be",
"performed",
"in",
"atRuleBody",
"state",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/css/CssScoper.php#L735-L755 |
oat-sa/qti-sdk | src/qtism/runtime/rendering/css/CssScoper.php | CssScoper.inSelectorState | protected function inSelectorState()
{
$char = $this->getCurrentChar();
if ($char === self::CHAR_OPENINGBRACE) {
$this->updateSelector();
$this->cleanBuffer();
$this->setState(self::IN_CLASSBODY);
} else {
$this->bufferize($char);
}
} | php | protected function inSelectorState()
{
$char = $this->getCurrentChar();
if ($char === self::CHAR_OPENINGBRACE) {
$this->updateSelector();
$this->cleanBuffer();
$this->setState(self::IN_CLASSBODY);
} else {
$this->bufferize($char);
}
} | [
"protected",
"function",
"inSelectorState",
"(",
")",
"{",
"$",
"char",
"=",
"$",
"this",
"->",
"getCurrentChar",
"(",
")",
";",
"if",
"(",
"$",
"char",
"===",
"self",
"::",
"CHAR_OPENINGBRACE",
")",
"{",
"$",
"this",
"->",
"updateSelector",
"(",
")",
";",
"$",
"this",
"->",
"cleanBuffer",
"(",
")",
";",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"IN_CLASSBODY",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"bufferize",
"(",
"$",
"char",
")",
";",
"}",
"}"
] | Instructions to be performed in 'selector' state. | [
"Instructions",
"to",
"be",
"performed",
"in",
"selector",
"state",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/css/CssScoper.php#L760-L771 |
oat-sa/qti-sdk | src/qtism/runtime/rendering/css/CssScoper.php | CssScoper.inClassBodyState | protected function inClassBodyState()
{
$char = $this->getCurrentChar();
if ($char === self::CHAR_DOUBLEQUOTE) {
$this->setState(self::IN_CLASSSTRING);
} elseif ($char === self::CHAR_CLOSINGBRACE) {
$this->setState(self::RUNNING);
} elseif ($char === self::CHAR_STAR && $this->getPreviousChar() === self::CHAR_SLASH) {
$this->setState(self::IN_CLASSCOMMENT);
}
$this->output($char);
} | php | protected function inClassBodyState()
{
$char = $this->getCurrentChar();
if ($char === self::CHAR_DOUBLEQUOTE) {
$this->setState(self::IN_CLASSSTRING);
} elseif ($char === self::CHAR_CLOSINGBRACE) {
$this->setState(self::RUNNING);
} elseif ($char === self::CHAR_STAR && $this->getPreviousChar() === self::CHAR_SLASH) {
$this->setState(self::IN_CLASSCOMMENT);
}
$this->output($char);
} | [
"protected",
"function",
"inClassBodyState",
"(",
")",
"{",
"$",
"char",
"=",
"$",
"this",
"->",
"getCurrentChar",
"(",
")",
";",
"if",
"(",
"$",
"char",
"===",
"self",
"::",
"CHAR_DOUBLEQUOTE",
")",
"{",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"IN_CLASSSTRING",
")",
";",
"}",
"elseif",
"(",
"$",
"char",
"===",
"self",
"::",
"CHAR_CLOSINGBRACE",
")",
"{",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"RUNNING",
")",
";",
"}",
"elseif",
"(",
"$",
"char",
"===",
"self",
"::",
"CHAR_STAR",
"&&",
"$",
"this",
"->",
"getPreviousChar",
"(",
")",
"===",
"self",
"::",
"CHAR_SLASH",
")",
"{",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"IN_CLASSCOMMENT",
")",
";",
"}",
"$",
"this",
"->",
"output",
"(",
"$",
"char",
")",
";",
"}"
] | Instructions to be performed in 'classBody' state. | [
"Instructions",
"to",
"be",
"performed",
"in",
"classBody",
"state",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/css/CssScoper.php#L776-L789 |
oat-sa/qti-sdk | src/qtism/runtime/rendering/css/CssScoper.php | CssScoper.inMainCommentState | protected function inMainCommentState()
{
$char = $this->getCurrentChar();
if ($char === self::CHAR_SLASH && $this->getPreviousChar() === self::CHAR_STAR) {
$this->setState(self::RUNNING);
}
$this->output($char);
} | php | protected function inMainCommentState()
{
$char = $this->getCurrentChar();
if ($char === self::CHAR_SLASH && $this->getPreviousChar() === self::CHAR_STAR) {
$this->setState(self::RUNNING);
}
$this->output($char);
} | [
"protected",
"function",
"inMainCommentState",
"(",
")",
"{",
"$",
"char",
"=",
"$",
"this",
"->",
"getCurrentChar",
"(",
")",
";",
"if",
"(",
"$",
"char",
"===",
"self",
"::",
"CHAR_SLASH",
"&&",
"$",
"this",
"->",
"getPreviousChar",
"(",
")",
"===",
"self",
"::",
"CHAR_STAR",
")",
"{",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"RUNNING",
")",
";",
"}",
"$",
"this",
"->",
"output",
"(",
"$",
"char",
")",
";",
"}"
] | Instructions to be performed in 'mainComment' state. | [
"Instructions",
"to",
"be",
"performed",
"in",
"mainComment",
"state",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/css/CssScoper.php#L794-L803 |
oat-sa/qti-sdk | src/qtism/runtime/rendering/css/CssScoper.php | CssScoper.inClassCommentState | protected function inClassCommentState()
{
$char = $this->getCurrentChar();
if ($char === self::CHAR_SLASH && $this->getPreviousChar() === self::CHAR_STAR) {
$this->setState(self::IN_CLASSBODY);
}
$this->output($char);
} | php | protected function inClassCommentState()
{
$char = $this->getCurrentChar();
if ($char === self::CHAR_SLASH && $this->getPreviousChar() === self::CHAR_STAR) {
$this->setState(self::IN_CLASSBODY);
}
$this->output($char);
} | [
"protected",
"function",
"inClassCommentState",
"(",
")",
"{",
"$",
"char",
"=",
"$",
"this",
"->",
"getCurrentChar",
"(",
")",
";",
"if",
"(",
"$",
"char",
"===",
"self",
"::",
"CHAR_SLASH",
"&&",
"$",
"this",
"->",
"getPreviousChar",
"(",
")",
"===",
"self",
"::",
"CHAR_STAR",
")",
"{",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"IN_CLASSBODY",
")",
";",
"}",
"$",
"this",
"->",
"output",
"(",
"$",
"char",
")",
";",
"}"
] | Instructions to be performed in 'classComment' state. | [
"Instructions",
"to",
"be",
"performed",
"in",
"classComment",
"state",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/css/CssScoper.php#L808-L817 |
oat-sa/qti-sdk | src/qtism/runtime/rendering/css/CssScoper.php | CssScoper.inClassStringState | protected function inClassStringState()
{
$char = $this->getCurrentChar();
if ($char === self::CHAR_DOUBLEQUOTE && $this->isEscaping() === false) {
$this->cleanBuffer();
$this->setState(self::IN_CLASSBODY);
} elseif ($char === self::CHAR_ESCAPE) {
$this->bufferize($char);
} else {
$this->cleanBuffer();
}
$this->output($char);
} | php | protected function inClassStringState()
{
$char = $this->getCurrentChar();
if ($char === self::CHAR_DOUBLEQUOTE && $this->isEscaping() === false) {
$this->cleanBuffer();
$this->setState(self::IN_CLASSBODY);
} elseif ($char === self::CHAR_ESCAPE) {
$this->bufferize($char);
} else {
$this->cleanBuffer();
}
$this->output($char);
} | [
"protected",
"function",
"inClassStringState",
"(",
")",
"{",
"$",
"char",
"=",
"$",
"this",
"->",
"getCurrentChar",
"(",
")",
";",
"if",
"(",
"$",
"char",
"===",
"self",
"::",
"CHAR_DOUBLEQUOTE",
"&&",
"$",
"this",
"->",
"isEscaping",
"(",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"cleanBuffer",
"(",
")",
";",
"$",
"this",
"->",
"setState",
"(",
"self",
"::",
"IN_CLASSBODY",
")",
";",
"}",
"elseif",
"(",
"$",
"char",
"===",
"self",
"::",
"CHAR_ESCAPE",
")",
"{",
"$",
"this",
"->",
"bufferize",
"(",
"$",
"char",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"cleanBuffer",
"(",
")",
";",
"}",
"$",
"this",
"->",
"output",
"(",
"$",
"char",
")",
";",
"}"
] | Instructions to be performed in 'classString' state. | [
"Instructions",
"to",
"be",
"performed",
"in",
"classString",
"state",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/css/CssScoper.php#L822-L836 |
oat-sa/qti-sdk | src/qtism/runtime/rendering/css/CssScoper.php | CssScoper.isWhiteSpace | private static function isWhiteSpace($char)
{
return $char === self::CHAR_SPACE || $char === self::CHAR_CARRIAGERETURN || $char === self::CHAR_NEWLINE || $char === self::CHAR_TAB || $char === self::CHAR_VERTICALTAB;
} | php | private static function isWhiteSpace($char)
{
return $char === self::CHAR_SPACE || $char === self::CHAR_CARRIAGERETURN || $char === self::CHAR_NEWLINE || $char === self::CHAR_TAB || $char === self::CHAR_VERTICALTAB;
} | [
"private",
"static",
"function",
"isWhiteSpace",
"(",
"$",
"char",
")",
"{",
"return",
"$",
"char",
"===",
"self",
"::",
"CHAR_SPACE",
"||",
"$",
"char",
"===",
"self",
"::",
"CHAR_CARRIAGERETURN",
"||",
"$",
"char",
"===",
"self",
"::",
"CHAR_NEWLINE",
"||",
"$",
"char",
"===",
"self",
"::",
"CHAR_TAB",
"||",
"$",
"char",
"===",
"self",
"::",
"CHAR_VERTICALTAB",
";",
"}"
] | Whether a given $char is considered to be white space.
@param string $char
@return boolean | [
"Whether",
"a",
"given",
"$char",
"is",
"considered",
"to",
"be",
"white",
"space",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/css/CssScoper.php#L844-L847 |
oat-sa/qti-sdk | src/qtism/runtime/rendering/css/CssScoper.php | CssScoper.bufferize | protected function bufferize($char)
{
$buffer = $this->getBuffer();
$buffer[] = $char;
$this->setBuffer($buffer);
} | php | protected function bufferize($char)
{
$buffer = $this->getBuffer();
$buffer[] = $char;
$this->setBuffer($buffer);
} | [
"protected",
"function",
"bufferize",
"(",
"$",
"char",
")",
"{",
"$",
"buffer",
"=",
"$",
"this",
"->",
"getBuffer",
"(",
")",
";",
"$",
"buffer",
"[",
"]",
"=",
"$",
"char",
";",
"$",
"this",
"->",
"setBuffer",
"(",
"$",
"buffer",
")",
";",
"}"
] | Put a given $char in the read buffer.
@param string $char | [
"Put",
"a",
"given",
"$char",
"in",
"the",
"read",
"buffer",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/css/CssScoper.php#L882-L887 |
oat-sa/qti-sdk | src/qtism/runtime/rendering/css/CssScoper.php | CssScoper.output | protected function output($char)
{
$output = $this->getOutput();
$output .= $char;
$this->setOutput($output);
} | php | protected function output($char)
{
$output = $this->getOutput();
$output .= $char;
$this->setOutput($output);
} | [
"protected",
"function",
"output",
"(",
"$",
"char",
")",
"{",
"$",
"output",
"=",
"$",
"this",
"->",
"getOutput",
"(",
")",
";",
"$",
"output",
".=",
"$",
"char",
";",
"$",
"this",
"->",
"setOutput",
"(",
"$",
"output",
")",
";",
"}"
] | Output a given $char as a scoping result.
@param string $char | [
"Output",
"a",
"given",
"$char",
"as",
"a",
"scoping",
"result",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/css/CssScoper.php#L914-L919 |
oat-sa/qti-sdk | src/qtism/runtime/rendering/css/CssScoper.php | CssScoper.updateSelector | protected function updateSelector()
{
$buffer = implode('', $this->getBuffer());
$qtiClassMap = ($this->isWebComponentFriendly()) ? array_merge(self::$qtiClassMapping, self::$wcFriendlyQtiClassMapping) : self::$qtiClassMapping;
if (strpos($buffer, ',') === false) {
// Do not rescope if already scoped!
if (strpos($buffer, '#' . $this->getId()) === false) {
$buffer = ($this->doesMapQtiClasses() === true) ? CssUtils::mapSelector($buffer, $qtiClassMap) : $buffer;
$buffer = ($this->doesMapQtiPseudoClasses() === true) ? CssUtils::mapPseudoClasses($buffer, self::getQtiPseudoClassMapping()) : $buffer;
$this->output('#' . $this->getId() . ' ' . $buffer . '{');
} else {
$buffer = ($this->doesMapQtiPseudoClasses() === true) ? CssUtils::mapPseudoClasses($buffer, self::getQtiPseudoClassMapping()) : $buffer;
$this->output($buffer . '{');
}
} else {
$classes = explode(',', $buffer);
$newClasses = array();
foreach ($classes as $c) {
// Same as above, do not rescope if already scoped...
if (strpos($c, '#' . $this->getId()) === false) {
$c = ($this->doesMapQtiClasses() === true) ? CssUtils::mapSelector($c, $qtiClassMap) : $c;
$newC = '#' . $this->getId() . ' ' . trim($c);
$newC = str_replace(trim($c), $newC, $c);
} else {
$newC = $c;
}
$newClasses[] = $newC;
}
$buffer = implode(',', $newClasses);
$buffer = ($this->doesMapQtiPseudoClasses() === true) ? CssUtils::mapPseudoClasses($buffer, self::getQtiPseudoClassMapping()) : $buffer;
$this->output($buffer . '{');
}
} | php | protected function updateSelector()
{
$buffer = implode('', $this->getBuffer());
$qtiClassMap = ($this->isWebComponentFriendly()) ? array_merge(self::$qtiClassMapping, self::$wcFriendlyQtiClassMapping) : self::$qtiClassMapping;
if (strpos($buffer, ',') === false) {
// Do not rescope if already scoped!
if (strpos($buffer, '#' . $this->getId()) === false) {
$buffer = ($this->doesMapQtiClasses() === true) ? CssUtils::mapSelector($buffer, $qtiClassMap) : $buffer;
$buffer = ($this->doesMapQtiPseudoClasses() === true) ? CssUtils::mapPseudoClasses($buffer, self::getQtiPseudoClassMapping()) : $buffer;
$this->output('#' . $this->getId() . ' ' . $buffer . '{');
} else {
$buffer = ($this->doesMapQtiPseudoClasses() === true) ? CssUtils::mapPseudoClasses($buffer, self::getQtiPseudoClassMapping()) : $buffer;
$this->output($buffer . '{');
}
} else {
$classes = explode(',', $buffer);
$newClasses = array();
foreach ($classes as $c) {
// Same as above, do not rescope if already scoped...
if (strpos($c, '#' . $this->getId()) === false) {
$c = ($this->doesMapQtiClasses() === true) ? CssUtils::mapSelector($c, $qtiClassMap) : $c;
$newC = '#' . $this->getId() . ' ' . trim($c);
$newC = str_replace(trim($c), $newC, $c);
} else {
$newC = $c;
}
$newClasses[] = $newC;
}
$buffer = implode(',', $newClasses);
$buffer = ($this->doesMapQtiPseudoClasses() === true) ? CssUtils::mapPseudoClasses($buffer, self::getQtiPseudoClassMapping()) : $buffer;
$this->output($buffer . '{');
}
} | [
"protected",
"function",
"updateSelector",
"(",
")",
"{",
"$",
"buffer",
"=",
"implode",
"(",
"''",
",",
"$",
"this",
"->",
"getBuffer",
"(",
")",
")",
";",
"$",
"qtiClassMap",
"=",
"(",
"$",
"this",
"->",
"isWebComponentFriendly",
"(",
")",
")",
"?",
"array_merge",
"(",
"self",
"::",
"$",
"qtiClassMapping",
",",
"self",
"::",
"$",
"wcFriendlyQtiClassMapping",
")",
":",
"self",
"::",
"$",
"qtiClassMapping",
";",
"if",
"(",
"strpos",
"(",
"$",
"buffer",
",",
"','",
")",
"===",
"false",
")",
"{",
"// Do not rescope if already scoped!",
"if",
"(",
"strpos",
"(",
"$",
"buffer",
",",
"'#'",
".",
"$",
"this",
"->",
"getId",
"(",
")",
")",
"===",
"false",
")",
"{",
"$",
"buffer",
"=",
"(",
"$",
"this",
"->",
"doesMapQtiClasses",
"(",
")",
"===",
"true",
")",
"?",
"CssUtils",
"::",
"mapSelector",
"(",
"$",
"buffer",
",",
"$",
"qtiClassMap",
")",
":",
"$",
"buffer",
";",
"$",
"buffer",
"=",
"(",
"$",
"this",
"->",
"doesMapQtiPseudoClasses",
"(",
")",
"===",
"true",
")",
"?",
"CssUtils",
"::",
"mapPseudoClasses",
"(",
"$",
"buffer",
",",
"self",
"::",
"getQtiPseudoClassMapping",
"(",
")",
")",
":",
"$",
"buffer",
";",
"$",
"this",
"->",
"output",
"(",
"'#'",
".",
"$",
"this",
"->",
"getId",
"(",
")",
".",
"' '",
".",
"$",
"buffer",
".",
"'{'",
")",
";",
"}",
"else",
"{",
"$",
"buffer",
"=",
"(",
"$",
"this",
"->",
"doesMapQtiPseudoClasses",
"(",
")",
"===",
"true",
")",
"?",
"CssUtils",
"::",
"mapPseudoClasses",
"(",
"$",
"buffer",
",",
"self",
"::",
"getQtiPseudoClassMapping",
"(",
")",
")",
":",
"$",
"buffer",
";",
"$",
"this",
"->",
"output",
"(",
"$",
"buffer",
".",
"'{'",
")",
";",
"}",
"}",
"else",
"{",
"$",
"classes",
"=",
"explode",
"(",
"','",
",",
"$",
"buffer",
")",
";",
"$",
"newClasses",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"classes",
"as",
"$",
"c",
")",
"{",
"// Same as above, do not rescope if already scoped...",
"if",
"(",
"strpos",
"(",
"$",
"c",
",",
"'#'",
".",
"$",
"this",
"->",
"getId",
"(",
")",
")",
"===",
"false",
")",
"{",
"$",
"c",
"=",
"(",
"$",
"this",
"->",
"doesMapQtiClasses",
"(",
")",
"===",
"true",
")",
"?",
"CssUtils",
"::",
"mapSelector",
"(",
"$",
"c",
",",
"$",
"qtiClassMap",
")",
":",
"$",
"c",
";",
"$",
"newC",
"=",
"'#'",
".",
"$",
"this",
"->",
"getId",
"(",
")",
".",
"' '",
".",
"trim",
"(",
"$",
"c",
")",
";",
"$",
"newC",
"=",
"str_replace",
"(",
"trim",
"(",
"$",
"c",
")",
",",
"$",
"newC",
",",
"$",
"c",
")",
";",
"}",
"else",
"{",
"$",
"newC",
"=",
"$",
"c",
";",
"}",
"$",
"newClasses",
"[",
"]",
"=",
"$",
"newC",
";",
"}",
"$",
"buffer",
"=",
"implode",
"(",
"','",
",",
"$",
"newClasses",
")",
";",
"$",
"buffer",
"=",
"(",
"$",
"this",
"->",
"doesMapQtiPseudoClasses",
"(",
")",
"===",
"true",
")",
"?",
"CssUtils",
"::",
"mapPseudoClasses",
"(",
"$",
"buffer",
",",
"self",
"::",
"getQtiPseudoClassMapping",
"(",
")",
")",
":",
"$",
"buffer",
";",
"$",
"this",
"->",
"output",
"(",
"$",
"buffer",
".",
"'{'",
")",
";",
"}",
"}"
] | Update selector implementation.
Update the currently processed CSS selector by prefixing it
with the appropriate id. | [
"Update",
"selector",
"implementation",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/css/CssScoper.php#L943-L981 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/RoundToMarshaller.php | RoundToMarshaller.marshallChildrenKnown | protected function marshallChildrenKnown(QtiComponent $component, array $elements)
{
$element = self::getDOMCradle()->createElement($component->getQtiClassName());
$this->setDOMElementAttribute($element, 'figures', $component->getFigures());
$this->setDOMElementAttribute($element, 'roundingMode', RoundingMode::getNameByConstant($component->getRoundingMode()));
foreach ($elements as $elt) {
$element->appendChild($elt);
}
return $element;
} | php | protected function marshallChildrenKnown(QtiComponent $component, array $elements)
{
$element = self::getDOMCradle()->createElement($component->getQtiClassName());
$this->setDOMElementAttribute($element, 'figures', $component->getFigures());
$this->setDOMElementAttribute($element, 'roundingMode', RoundingMode::getNameByConstant($component->getRoundingMode()));
foreach ($elements as $elt) {
$element->appendChild($elt);
}
return $element;
} | [
"protected",
"function",
"marshallChildrenKnown",
"(",
"QtiComponent",
"$",
"component",
",",
"array",
"$",
"elements",
")",
"{",
"$",
"element",
"=",
"self",
"::",
"getDOMCradle",
"(",
")",
"->",
"createElement",
"(",
"$",
"component",
"->",
"getQtiClassName",
"(",
")",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'figures'",
",",
"$",
"component",
"->",
"getFigures",
"(",
")",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'roundingMode'",
",",
"RoundingMode",
"::",
"getNameByConstant",
"(",
"$",
"component",
"->",
"getRoundingMode",
"(",
")",
")",
")",
";",
"foreach",
"(",
"$",
"elements",
"as",
"$",
"elt",
")",
"{",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"elt",
")",
";",
"}",
"return",
"$",
"element",
";",
"}"
] | Unmarshall a RoundTo object into a QTI roundTo element.
@param \qtism\data\QtiComponent $component The RoundTo object to marshall.
@param array $elements An array of child DOMEelement objects.
@return \DOMElement The marshalled QTI roundTo element. | [
"Unmarshall",
"a",
"RoundTo",
"object",
"into",
"a",
"QTI",
"roundTo",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/RoundToMarshaller.php#L48-L60 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/RoundToMarshaller.php | RoundToMarshaller.unmarshallChildrenKnown | protected function unmarshallChildrenKnown(DOMElement $element, QtiComponentCollection $children)
{
if (($figures = $this->getDOMElementAttributeAs($element, 'figures', 'string')) !== null) {
if (!Format::isVariableRef($figures)) {
$figures = intval($figures);
}
$object = new RoundTo($children, $figures);
if (($roundingMode = $this->getDOMElementAttributeAs($element, 'roundingMode')) !== null) {
$object->setRoundingMode(RoundingMode::getConstantByName($roundingMode));
}
return $object;
} else {
$msg = "The mandatory attribute 'figures' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} | php | protected function unmarshallChildrenKnown(DOMElement $element, QtiComponentCollection $children)
{
if (($figures = $this->getDOMElementAttributeAs($element, 'figures', 'string')) !== null) {
if (!Format::isVariableRef($figures)) {
$figures = intval($figures);
}
$object = new RoundTo($children, $figures);
if (($roundingMode = $this->getDOMElementAttributeAs($element, 'roundingMode')) !== null) {
$object->setRoundingMode(RoundingMode::getConstantByName($roundingMode));
}
return $object;
} else {
$msg = "The mandatory attribute 'figures' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} | [
"protected",
"function",
"unmarshallChildrenKnown",
"(",
"DOMElement",
"$",
"element",
",",
"QtiComponentCollection",
"$",
"children",
")",
"{",
"if",
"(",
"(",
"$",
"figures",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'figures'",
",",
"'string'",
")",
")",
"!==",
"null",
")",
"{",
"if",
"(",
"!",
"Format",
"::",
"isVariableRef",
"(",
"$",
"figures",
")",
")",
"{",
"$",
"figures",
"=",
"intval",
"(",
"$",
"figures",
")",
";",
"}",
"$",
"object",
"=",
"new",
"RoundTo",
"(",
"$",
"children",
",",
"$",
"figures",
")",
";",
"if",
"(",
"(",
"$",
"roundingMode",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'roundingMode'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"object",
"->",
"setRoundingMode",
"(",
"RoundingMode",
"::",
"getConstantByName",
"(",
"$",
"roundingMode",
")",
")",
";",
"}",
"return",
"$",
"object",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory attribute 'figures' is missing from element '\"",
".",
"$",
"element",
"->",
"localName",
".",
"\"'.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}"
] | Unmarshall a QTI roundTo operator element into a RoundTo object.
@param \DOMElement $element The roundTo element to unmarshall.
@param \qtism\data\QtiComponentCollection $children A collection containing the child Expression objects composing the Operator.
@return \qtism\data\QtiComponent A RoundTo object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException | [
"Unmarshall",
"a",
"QTI",
"roundTo",
"operator",
"element",
"into",
"a",
"RoundTo",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/RoundToMarshaller.php#L70-L89 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/RandomIntegerProcessor.php | RandomIntegerProcessor.process | public function process()
{
$expr = $this->getExpression();
$min = $expr->getMin();
$max = $expr->getMax();
$step = $expr->getStep();
$state = $this->getState();
$min = (gettype($min) === 'integer') ? $min : $state[Utils::sanitizeVariableRef($min)]->getValue();
$max = (gettype($max) === 'integer') ? $max : $state[Utils::sanitizeVariableRef($max)]->getValue();
$step = (gettype($step) === 'integer') ? $step : $state[Utils::sanitizeVariableRef($step)]->getValue();
if (gettype($min) === 'integer' && gettype($max) === 'integer' && gettype($step) === 'integer') {
if ($min > $max) {
$msg = "'min':'${min}' is greater than 'max':'${max}'.";
throw new ExpressionProcessingException($msg, $this, ExpressionProcessingException::LOGIC_ERROR);
}
if ($step === 1) {
return new QtiInteger(mt_rand($min, $max));
} else {
$distance = ($min < 0) ? ($max + abs($min)) : ($max - $min);
$mult = mt_rand(0, intval(floor($distance / $step)));
$random = new QtiInteger($min + ($mult * $step));
return $random;
}
} else {
$msg = "At least one of the following variables is not an integer: 'min', 'max', 'step' while processing RandomInteger.";
throw new ExpressionProcessingException($msg, $this, ExpressionProcessingException::WRONG_VARIABLE_BASETYPE);
}
} | php | public function process()
{
$expr = $this->getExpression();
$min = $expr->getMin();
$max = $expr->getMax();
$step = $expr->getStep();
$state = $this->getState();
$min = (gettype($min) === 'integer') ? $min : $state[Utils::sanitizeVariableRef($min)]->getValue();
$max = (gettype($max) === 'integer') ? $max : $state[Utils::sanitizeVariableRef($max)]->getValue();
$step = (gettype($step) === 'integer') ? $step : $state[Utils::sanitizeVariableRef($step)]->getValue();
if (gettype($min) === 'integer' && gettype($max) === 'integer' && gettype($step) === 'integer') {
if ($min > $max) {
$msg = "'min':'${min}' is greater than 'max':'${max}'.";
throw new ExpressionProcessingException($msg, $this, ExpressionProcessingException::LOGIC_ERROR);
}
if ($step === 1) {
return new QtiInteger(mt_rand($min, $max));
} else {
$distance = ($min < 0) ? ($max + abs($min)) : ($max - $min);
$mult = mt_rand(0, intval(floor($distance / $step)));
$random = new QtiInteger($min + ($mult * $step));
return $random;
}
} else {
$msg = "At least one of the following variables is not an integer: 'min', 'max', 'step' while processing RandomInteger.";
throw new ExpressionProcessingException($msg, $this, ExpressionProcessingException::WRONG_VARIABLE_BASETYPE);
}
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"expr",
"=",
"$",
"this",
"->",
"getExpression",
"(",
")",
";",
"$",
"min",
"=",
"$",
"expr",
"->",
"getMin",
"(",
")",
";",
"$",
"max",
"=",
"$",
"expr",
"->",
"getMax",
"(",
")",
";",
"$",
"step",
"=",
"$",
"expr",
"->",
"getStep",
"(",
")",
";",
"$",
"state",
"=",
"$",
"this",
"->",
"getState",
"(",
")",
";",
"$",
"min",
"=",
"(",
"gettype",
"(",
"$",
"min",
")",
"===",
"'integer'",
")",
"?",
"$",
"min",
":",
"$",
"state",
"[",
"Utils",
"::",
"sanitizeVariableRef",
"(",
"$",
"min",
")",
"]",
"->",
"getValue",
"(",
")",
";",
"$",
"max",
"=",
"(",
"gettype",
"(",
"$",
"max",
")",
"===",
"'integer'",
")",
"?",
"$",
"max",
":",
"$",
"state",
"[",
"Utils",
"::",
"sanitizeVariableRef",
"(",
"$",
"max",
")",
"]",
"->",
"getValue",
"(",
")",
";",
"$",
"step",
"=",
"(",
"gettype",
"(",
"$",
"step",
")",
"===",
"'integer'",
")",
"?",
"$",
"step",
":",
"$",
"state",
"[",
"Utils",
"::",
"sanitizeVariableRef",
"(",
"$",
"step",
")",
"]",
"->",
"getValue",
"(",
")",
";",
"if",
"(",
"gettype",
"(",
"$",
"min",
")",
"===",
"'integer'",
"&&",
"gettype",
"(",
"$",
"max",
")",
"===",
"'integer'",
"&&",
"gettype",
"(",
"$",
"step",
")",
"===",
"'integer'",
")",
"{",
"if",
"(",
"$",
"min",
">",
"$",
"max",
")",
"{",
"$",
"msg",
"=",
"\"'min':'${min}' is greater than 'max':'${max}'.\"",
";",
"throw",
"new",
"ExpressionProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"ExpressionProcessingException",
"::",
"LOGIC_ERROR",
")",
";",
"}",
"if",
"(",
"$",
"step",
"===",
"1",
")",
"{",
"return",
"new",
"QtiInteger",
"(",
"mt_rand",
"(",
"$",
"min",
",",
"$",
"max",
")",
")",
";",
"}",
"else",
"{",
"$",
"distance",
"=",
"(",
"$",
"min",
"<",
"0",
")",
"?",
"(",
"$",
"max",
"+",
"abs",
"(",
"$",
"min",
")",
")",
":",
"(",
"$",
"max",
"-",
"$",
"min",
")",
";",
"$",
"mult",
"=",
"mt_rand",
"(",
"0",
",",
"intval",
"(",
"floor",
"(",
"$",
"distance",
"/",
"$",
"step",
")",
")",
")",
";",
"$",
"random",
"=",
"new",
"QtiInteger",
"(",
"$",
"min",
"+",
"(",
"$",
"mult",
"*",
"$",
"step",
")",
")",
";",
"return",
"$",
"random",
";",
"}",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"At least one of the following variables is not an integer: 'min', 'max', 'step' while processing RandomInteger.\"",
";",
"throw",
"new",
"ExpressionProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"ExpressionProcessingException",
"::",
"WRONG_VARIABLE_BASETYPE",
")",
";",
"}",
"}"
] | Process the RandomInteger expression.
* Throws an ExpressionProcessingException if 'min' is greater than 'max'.
* Throws an ExpressionProcessingException if a variable reference is not found in the current state.
* Throws an ExpressionProcessingException if a variable reference's value is not an integer.
@return integer A random integer value.
@throws \qtism\runtime\expressions\ExpressionProcessingException | [
"Process",
"the",
"RandomInteger",
"expression",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/RandomIntegerProcessor.php#L53-L84 |
oat-sa/qti-sdk | src/qtism/data/content/xhtml/tables/Col.php | Col.setSpan | public function setSpan($span)
{
if (is_int($span) === true && $span > 0) {
$this->span = $span;
} else {
$msg = "The 'span' attribute must be a strictly positive (> 0) integer, '" . gettype($span) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setSpan($span)
{
if (is_int($span) === true && $span > 0) {
$this->span = $span;
} else {
$msg = "The 'span' attribute must be a strictly positive (> 0) integer, '" . gettype($span) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setSpan",
"(",
"$",
"span",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"span",
")",
"===",
"true",
"&&",
"$",
"span",
">",
"0",
")",
"{",
"$",
"this",
"->",
"span",
"=",
"$",
"span",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'span' attribute must be a strictly positive (> 0) integer, '\"",
".",
"gettype",
"(",
"$",
"span",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the span attribute.
@param integer $span A strictly positive integer.
@throws \InvalidArgumentException If $span is not a positive integer. | [
"Set",
"the",
"span",
"attribute",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/xhtml/tables/Col.php#L67-L75 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/OperatorProcessorFactory.php | OperatorProcessorFactory.createProcessor | public function createProcessor(QtiComponent $expression, OperandsCollection $operands = null)
{
if ($expression instanceof Operator) {
if (is_null($operands) === true) {
$operands = new OperandsCollection();
}
if ($expression instanceof CustomOperator) {
// QTI custom operator. Try to load an autoloaded class by using
// its class attribute value.
if ($expression->hasClass() === true) {
$className = Utils::customOperatorClassToPhpClass($expression->getClass());
if (class_exists($className) === true) {
return new $className($expression, $operands);
} else {
$msg = "No custom operator implementation found for class '" . $expression->getClass() . "'.";
throw new RuntimeException($msg);
}
} else {
$msg = "Only custom operators with a 'class' attribute value can be processed.";
throw new RuntimeException($msg);
}
} else {
// QTI built-in operator.
$qtiClassName = ucfirst($expression->getQtiClassName());
$nsPackage = 'qtism\\runtime\\expressions\\operators\\';
$className = $nsPackage . $qtiClassName . 'Processor';
return new $className($expression, $operands);
}
} else {
$msg = "The OperatorProcessorFactory only accepts to create processors for Operator objects.";
throw new InvalidArgumentException($msg);
}
} | php | public function createProcessor(QtiComponent $expression, OperandsCollection $operands = null)
{
if ($expression instanceof Operator) {
if (is_null($operands) === true) {
$operands = new OperandsCollection();
}
if ($expression instanceof CustomOperator) {
// QTI custom operator. Try to load an autoloaded class by using
// its class attribute value.
if ($expression->hasClass() === true) {
$className = Utils::customOperatorClassToPhpClass($expression->getClass());
if (class_exists($className) === true) {
return new $className($expression, $operands);
} else {
$msg = "No custom operator implementation found for class '" . $expression->getClass() . "'.";
throw new RuntimeException($msg);
}
} else {
$msg = "Only custom operators with a 'class' attribute value can be processed.";
throw new RuntimeException($msg);
}
} else {
// QTI built-in operator.
$qtiClassName = ucfirst($expression->getQtiClassName());
$nsPackage = 'qtism\\runtime\\expressions\\operators\\';
$className = $nsPackage . $qtiClassName . 'Processor';
return new $className($expression, $operands);
}
} else {
$msg = "The OperatorProcessorFactory only accepts to create processors for Operator objects.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"createProcessor",
"(",
"QtiComponent",
"$",
"expression",
",",
"OperandsCollection",
"$",
"operands",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"expression",
"instanceof",
"Operator",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"operands",
")",
"===",
"true",
")",
"{",
"$",
"operands",
"=",
"new",
"OperandsCollection",
"(",
")",
";",
"}",
"if",
"(",
"$",
"expression",
"instanceof",
"CustomOperator",
")",
"{",
"// QTI custom operator. Try to load an autoloaded class by using",
"// its class attribute value.",
"if",
"(",
"$",
"expression",
"->",
"hasClass",
"(",
")",
"===",
"true",
")",
"{",
"$",
"className",
"=",
"Utils",
"::",
"customOperatorClassToPhpClass",
"(",
"$",
"expression",
"->",
"getClass",
"(",
")",
")",
";",
"if",
"(",
"class_exists",
"(",
"$",
"className",
")",
"===",
"true",
")",
"{",
"return",
"new",
"$",
"className",
"(",
"$",
"expression",
",",
"$",
"operands",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"No custom operator implementation found for class '\"",
".",
"$",
"expression",
"->",
"getClass",
"(",
")",
".",
"\"'.\"",
";",
"throw",
"new",
"RuntimeException",
"(",
"$",
"msg",
")",
";",
"}",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"Only custom operators with a 'class' attribute value can be processed.\"",
";",
"throw",
"new",
"RuntimeException",
"(",
"$",
"msg",
")",
";",
"}",
"}",
"else",
"{",
"// QTI built-in operator.",
"$",
"qtiClassName",
"=",
"ucfirst",
"(",
"$",
"expression",
"->",
"getQtiClassName",
"(",
")",
")",
";",
"$",
"nsPackage",
"=",
"'qtism\\\\runtime\\\\expressions\\\\operators\\\\'",
";",
"$",
"className",
"=",
"$",
"nsPackage",
".",
"$",
"qtiClassName",
".",
"'Processor'",
";",
"return",
"new",
"$",
"className",
"(",
"$",
"expression",
",",
"$",
"operands",
")",
";",
"}",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The OperatorProcessorFactory only accepts to create processors for Operator objects.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Create the OperatorProcessor relevant to the given $expression.
@param \qtism\data\expressions\Expression $expression The Operator object you want to get the processor.
@param \qtism\runtime\expressions\operators\OperandsCollection $operands The operands to be involved in the Operator object.
@return \qtism\runtime\expressions\operators\OperatorProcessor An OperatorProcessor object ready to process $expression.
@throws \qtism\runtime\expressions\operators\OperatorProcessingException If the $operands count is not compliant with the Operator object to be processed.
@throws \InvalidArgumentException If $expression is not an Operator object.
@throws \RuntimeException If no relevant OperatorProcessor is found for the given $expression. | [
"Create",
"the",
"OperatorProcessor",
"relevant",
"to",
"the",
"given",
"$expression",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/OperatorProcessorFactory.php#L61-L97 |
oat-sa/qti-sdk | src/qtism/data/state/OutcomeDeclaration.php | OutcomeDeclaration.setInterpretation | public function setInterpretation($interpretation)
{
if (gettype($interpretation) === 'string') {
$this->interpretation = $interpretation;
} else {
$msg = "Interpretation must be a string, '" . gettype($interpretation) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setInterpretation($interpretation)
{
if (gettype($interpretation) === 'string') {
$this->interpretation = $interpretation;
} else {
$msg = "Interpretation must be a string, '" . gettype($interpretation) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setInterpretation",
"(",
"$",
"interpretation",
")",
"{",
"if",
"(",
"gettype",
"(",
"$",
"interpretation",
")",
"===",
"'string'",
")",
"{",
"$",
"this",
"->",
"interpretation",
"=",
"$",
"interpretation",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"Interpretation must be a string, '\"",
".",
"gettype",
"(",
"$",
"interpretation",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the human interpretation of the outcome variable's value.
@param string $interpretation A string.
@throws \InvalidArgumentException If $interpretation is not a string. | [
"Set",
"the",
"human",
"interpretation",
"of",
"the",
"outcome",
"variable",
"s",
"value",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/state/OutcomeDeclaration.php#L209-L217 |
oat-sa/qti-sdk | src/qtism/data/state/OutcomeDeclaration.php | OutcomeDeclaration.setLongInterpretation | public function setLongInterpretation($longInterpretation)
{
if (gettype($longInterpretation) === 'string') {
$this->longInterpretation = $longInterpretation;
} else {
$msg = "LongInterpretation must be a string, '" . gettype($longInterpretation) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setLongInterpretation($longInterpretation)
{
if (gettype($longInterpretation) === 'string') {
$this->longInterpretation = $longInterpretation;
} else {
$msg = "LongInterpretation must be a string, '" . gettype($longInterpretation) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setLongInterpretation",
"(",
"$",
"longInterpretation",
")",
"{",
"if",
"(",
"gettype",
"(",
"$",
"longInterpretation",
")",
"===",
"'string'",
")",
"{",
"$",
"this",
"->",
"longInterpretation",
"=",
"$",
"longInterpretation",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"LongInterpretation must be a string, '\"",
".",
"gettype",
"(",
"$",
"longInterpretation",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set a link (URI) to an extended interpretation of the outcome variable's value.
@param string $longInterpretation A string.
@throws \InvalidArgumentException If $longInterpretation is not a string. | [
"Set",
"a",
"link",
"(",
"URI",
")",
"to",
"an",
"extended",
"interpretation",
"of",
"the",
"outcome",
"variable",
"s",
"value",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/state/OutcomeDeclaration.php#L235-L243 |
oat-sa/qti-sdk | src/qtism/data/state/OutcomeDeclaration.php | OutcomeDeclaration.setNormalMinimum | public function setNormalMinimum($normalMinimum)
{
if (is_numeric($normalMinimum) || (is_bool($normalMinimum) && $normalMinimum === false)) {
$this->normalMinimum = $normalMinimum;
} else {
$msg = "NormalMinimum must be a number or (boolean) false, '" . gettype($normalMinimum) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setNormalMinimum($normalMinimum)
{
if (is_numeric($normalMinimum) || (is_bool($normalMinimum) && $normalMinimum === false)) {
$this->normalMinimum = $normalMinimum;
} else {
$msg = "NormalMinimum must be a number or (boolean) false, '" . gettype($normalMinimum) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setNormalMinimum",
"(",
"$",
"normalMinimum",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"normalMinimum",
")",
"||",
"(",
"is_bool",
"(",
"$",
"normalMinimum",
")",
"&&",
"$",
"normalMinimum",
"===",
"false",
")",
")",
"{",
"$",
"this",
"->",
"normalMinimum",
"=",
"$",
"normalMinimum",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"NormalMinimum must be a number or (boolean) false, '\"",
".",
"gettype",
"(",
"$",
"normalMinimum",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the normal minimum.
@param boolean|numeric $normalMinimum A numeric value.
@throws \InvalidArgumentException If $normalMinimum is not numeric nor false. | [
"Set",
"the",
"normal",
"minimum",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/state/OutcomeDeclaration.php#L261-L269 |
oat-sa/qti-sdk | src/qtism/data/state/OutcomeDeclaration.php | OutcomeDeclaration.setNormalMaximum | public function setNormalMaximum($normalMaximum)
{
if (is_numeric($normalMaximum) || (is_bool($normalMaximum) && $normalMaximum === false)) {
$this->normalMaximum = $normalMaximum;
} else {
$msg = "NormalMaximum must be a number or (boolean) false, '" . gettype($normalMaximum) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setNormalMaximum($normalMaximum)
{
if (is_numeric($normalMaximum) || (is_bool($normalMaximum) && $normalMaximum === false)) {
$this->normalMaximum = $normalMaximum;
} else {
$msg = "NormalMaximum must be a number or (boolean) false, '" . gettype($normalMaximum) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setNormalMaximum",
"(",
"$",
"normalMaximum",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"normalMaximum",
")",
"||",
"(",
"is_bool",
"(",
"$",
"normalMaximum",
")",
"&&",
"$",
"normalMaximum",
"===",
"false",
")",
")",
"{",
"$",
"this",
"->",
"normalMaximum",
"=",
"$",
"normalMaximum",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"NormalMaximum must be a number or (boolean) false, '\"",
".",
"gettype",
"(",
"$",
"normalMaximum",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the normal maximum.
@param boolean|number $normalMaximum A numeric value.
@throws \InvalidArgumentException If $normalMaximum is not a numeric value nor false. | [
"Set",
"the",
"normal",
"maximum",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/state/OutcomeDeclaration.php#L287-L295 |
oat-sa/qti-sdk | src/qtism/data/state/OutcomeDeclaration.php | OutcomeDeclaration.setMasteryValue | public function setMasteryValue($masteryValue)
{
if (is_numeric($masteryValue) || (is_bool($masteryValue) && $masteryValue === false)) {
$this->masteryValue = $masteryValue;
} else {
$msg = "MasteryValue must be a number or (boolean) false, '" . gettype($masteryValue) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setMasteryValue($masteryValue)
{
if (is_numeric($masteryValue) || (is_bool($masteryValue) && $masteryValue === false)) {
$this->masteryValue = $masteryValue;
} else {
$msg = "MasteryValue must be a number or (boolean) false, '" . gettype($masteryValue) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setMasteryValue",
"(",
"$",
"masteryValue",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"masteryValue",
")",
"||",
"(",
"is_bool",
"(",
"$",
"masteryValue",
")",
"&&",
"$",
"masteryValue",
"===",
"false",
")",
")",
"{",
"$",
"this",
"->",
"masteryValue",
"=",
"$",
"masteryValue",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"MasteryValue must be a number or (boolean) false, '\"",
".",
"gettype",
"(",
"$",
"masteryValue",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the mastery value. Set to false if not specified.
@param boolean|number $masteryValue A numeric value or false.
@throws \InvalidArgumentException If $masteryValue is not numeric nor false. | [
"Set",
"the",
"mastery",
"value",
".",
"Set",
"to",
"false",
"if",
"not",
"specified",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/state/OutcomeDeclaration.php#L313-L321 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/DeleteProcessor.php | DeleteProcessor.process | public function process()
{
$operands = $this->getOperands();
if ($operands->containsNull() === true) {
return null;
}
if ($operands->sameBaseType() === false) {
$msg = "The Delete operator only accepts operands with the same baseType.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
}
$operand1 = $operands[0];
if (RuntimeUtils::inferCardinality($operand1) !== Cardinality::SINGLE) {
$msg = "The first operand of the Delete operator must have the single cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
$operand2 = $operands[1];
$cardinality = RuntimeUtils::inferCardinality($operand2);
if ($cardinality !== Cardinality::MULTIPLE && $cardinality !== Cardinality::ORDERED) {
$msg = "The second operand of the Delete operator must have a cardinality or multiple or ordered.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
$returnedBaseType = RuntimeUtils::inferBaseType($operand1);
$returnValue = ($cardinality === Cardinality::MULTIPLE) ? new MultipleContainer($returnedBaseType) : new OrderedContainer($returnedBaseType);
foreach ($operand2 as $value) {
if ($value === $operand1 || ($operand1 instanceof Comparable && $operand1->equals($value) === true)) {
// This is the same value, it will not be included in the returned value.
continue;
} else {
$returnValue[] = $value;
}
}
return $returnValue;
} | php | public function process()
{
$operands = $this->getOperands();
if ($operands->containsNull() === true) {
return null;
}
if ($operands->sameBaseType() === false) {
$msg = "The Delete operator only accepts operands with the same baseType.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
}
$operand1 = $operands[0];
if (RuntimeUtils::inferCardinality($operand1) !== Cardinality::SINGLE) {
$msg = "The first operand of the Delete operator must have the single cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
$operand2 = $operands[1];
$cardinality = RuntimeUtils::inferCardinality($operand2);
if ($cardinality !== Cardinality::MULTIPLE && $cardinality !== Cardinality::ORDERED) {
$msg = "The second operand of the Delete operator must have a cardinality or multiple or ordered.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
$returnedBaseType = RuntimeUtils::inferBaseType($operand1);
$returnValue = ($cardinality === Cardinality::MULTIPLE) ? new MultipleContainer($returnedBaseType) : new OrderedContainer($returnedBaseType);
foreach ($operand2 as $value) {
if ($value === $operand1 || ($operand1 instanceof Comparable && $operand1->equals($value) === true)) {
// This is the same value, it will not be included in the returned value.
continue;
} else {
$returnValue[] = $value;
}
}
return $returnValue;
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"operands",
"=",
"$",
"this",
"->",
"getOperands",
"(",
")",
";",
"if",
"(",
"$",
"operands",
"->",
"containsNull",
"(",
")",
"===",
"true",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"operands",
"->",
"sameBaseType",
"(",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The Delete operator only accepts operands with the same baseType.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_BASETYPE",
")",
";",
"}",
"$",
"operand1",
"=",
"$",
"operands",
"[",
"0",
"]",
";",
"if",
"(",
"RuntimeUtils",
"::",
"inferCardinality",
"(",
"$",
"operand1",
")",
"!==",
"Cardinality",
"::",
"SINGLE",
")",
"{",
"$",
"msg",
"=",
"\"The first operand of the Delete operator must have the single cardinality.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_CARDINALITY",
")",
";",
"}",
"$",
"operand2",
"=",
"$",
"operands",
"[",
"1",
"]",
";",
"$",
"cardinality",
"=",
"RuntimeUtils",
"::",
"inferCardinality",
"(",
"$",
"operand2",
")",
";",
"if",
"(",
"$",
"cardinality",
"!==",
"Cardinality",
"::",
"MULTIPLE",
"&&",
"$",
"cardinality",
"!==",
"Cardinality",
"::",
"ORDERED",
")",
"{",
"$",
"msg",
"=",
"\"The second operand of the Delete operator must have a cardinality or multiple or ordered.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_CARDINALITY",
")",
";",
"}",
"$",
"returnedBaseType",
"=",
"RuntimeUtils",
"::",
"inferBaseType",
"(",
"$",
"operand1",
")",
";",
"$",
"returnValue",
"=",
"(",
"$",
"cardinality",
"===",
"Cardinality",
"::",
"MULTIPLE",
")",
"?",
"new",
"MultipleContainer",
"(",
"$",
"returnedBaseType",
")",
":",
"new",
"OrderedContainer",
"(",
"$",
"returnedBaseType",
")",
";",
"foreach",
"(",
"$",
"operand2",
"as",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"$",
"operand1",
"||",
"(",
"$",
"operand1",
"instanceof",
"Comparable",
"&&",
"$",
"operand1",
"->",
"equals",
"(",
"$",
"value",
")",
"===",
"true",
")",
")",
"{",
"// This is the same value, it will not be included in the returned value.",
"continue",
";",
"}",
"else",
"{",
"$",
"returnValue",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"returnValue",
";",
"}"
] | Process the Delete operator.
@return \qtism\common\collections\Container A new container derived from the second sub-expression with all instances of the first sub-expression removed, or NULL if either sub-expression is considered to be NULL.
@throws \qtism\runtime\expressions\operators\OperatorProcessingException | [
"Process",
"the",
"Delete",
"operator",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/DeleteProcessor.php#L60-L99 |
oat-sa/qti-sdk | src/qtism/data/content/interactions/GraphicGapMatchInteraction.php | GraphicGapMatchInteraction.setGapImgs | public function setGapImgs(GapImgCollection $gapImgs)
{
if (count($gapImgs) > 0) {
$this->gapImgs = $gapImgs;
} else {
$msg = "A GraphicGapMatch interaction must composed of at least 1 GapImg object, none given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setGapImgs(GapImgCollection $gapImgs)
{
if (count($gapImgs) > 0) {
$this->gapImgs = $gapImgs;
} else {
$msg = "A GraphicGapMatch interaction must composed of at least 1 GapImg object, none given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setGapImgs",
"(",
"GapImgCollection",
"$",
"gapImgs",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"gapImgs",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"gapImgs",
"=",
"$",
"gapImgs",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"A GraphicGapMatch interaction must composed of at least 1 GapImg object, none given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the list of choices for filling the gaps.
@param \qtism\data\content\interactions\GapImgCollection $gapImgs A collection of GapImg objects.
@throws \InvalidArgumentException If $gapImgs is empty. | [
"Set",
"the",
"list",
"of",
"choices",
"for",
"filling",
"the",
"gaps",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/interactions/GraphicGapMatchInteraction.php#L105-L113 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.