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/storage/binary/QtiBinaryStreamAccess.php | QtiBinaryStreamAccess.writeShufflingGroup | public function writeShufflingGroup(ShufflingGroup $shufflingGroup)
{
try {
$identifiers = $shufflingGroup->getIdentifiers();
$this->writeTinyInt(count($identifiers));
foreach ($identifiers as $identifier) {
$this->writeString($identifier);
}
$fixedIdentifiers = $shufflingGroup->getFixedIdentifiers();
$this->writeTinyInt(count($fixedIdentifiers));
foreach ($fixedIdentifiers as $identifier) {
$this->writeString($identifier);
}
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while writing a shufflingGroup.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::SHUFFLING_GROUP, $e);
}
} | php | public function writeShufflingGroup(ShufflingGroup $shufflingGroup)
{
try {
$identifiers = $shufflingGroup->getIdentifiers();
$this->writeTinyInt(count($identifiers));
foreach ($identifiers as $identifier) {
$this->writeString($identifier);
}
$fixedIdentifiers = $shufflingGroup->getFixedIdentifiers();
$this->writeTinyInt(count($fixedIdentifiers));
foreach ($fixedIdentifiers as $identifier) {
$this->writeString($identifier);
}
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while writing a shufflingGroup.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::SHUFFLING_GROUP, $e);
}
} | [
"public",
"function",
"writeShufflingGroup",
"(",
"ShufflingGroup",
"$",
"shufflingGroup",
")",
"{",
"try",
"{",
"$",
"identifiers",
"=",
"$",
"shufflingGroup",
"->",
"getIdentifiers",
"(",
")",
";",
"$",
"this",
"->",
"writeTinyInt",
"(",
"count",
"(",
"$",
"identifiers",
")",
")",
";",
"foreach",
"(",
"$",
"identifiers",
"as",
"$",
"identifier",
")",
"{",
"$",
"this",
"->",
"writeString",
"(",
"$",
"identifier",
")",
";",
"}",
"$",
"fixedIdentifiers",
"=",
"$",
"shufflingGroup",
"->",
"getFixedIdentifiers",
"(",
")",
";",
"$",
"this",
"->",
"writeTinyInt",
"(",
"count",
"(",
"$",
"fixedIdentifiers",
")",
")",
";",
"foreach",
"(",
"$",
"fixedIdentifiers",
"as",
"$",
"identifier",
")",
"{",
"$",
"this",
"->",
"writeString",
"(",
"$",
"identifier",
")",
";",
"}",
"}",
"catch",
"(",
"BinaryStreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while writing a shufflingGroup.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"SHUFFLING_GROUP",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Write a ShufflingGroup in the current binary stream.
@param \qtism\data\state\ShufflingGroup $shufflingGroup
@throws QtiBinaryStreamAccessException | [
"Write",
"a",
"ShufflingGroup",
"in",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php#L502-L520 |
oat-sa/qti-sdk | src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php | QtiBinaryStreamAccess.readShufflingState | public function readShufflingState()
{
try {
$responseIdentifier = $this->readIdentifier();
$shufflingGroupCount = $this->readTinyInt();
$shufflingGroups = new ShufflingGroupCollection();
for ($i = 0; $i < $shufflingGroupCount; $i++) {
$shufflingGroups[] = $this->readShufflingGroup();
}
return new Shuffling($responseIdentifier, $shufflingGroups);
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while reading a shufflingState.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::SHUFFLING_STATE);
}
} | php | public function readShufflingState()
{
try {
$responseIdentifier = $this->readIdentifier();
$shufflingGroupCount = $this->readTinyInt();
$shufflingGroups = new ShufflingGroupCollection();
for ($i = 0; $i < $shufflingGroupCount; $i++) {
$shufflingGroups[] = $this->readShufflingGroup();
}
return new Shuffling($responseIdentifier, $shufflingGroups);
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while reading a shufflingState.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::SHUFFLING_STATE);
}
} | [
"public",
"function",
"readShufflingState",
"(",
")",
"{",
"try",
"{",
"$",
"responseIdentifier",
"=",
"$",
"this",
"->",
"readIdentifier",
"(",
")",
";",
"$",
"shufflingGroupCount",
"=",
"$",
"this",
"->",
"readTinyInt",
"(",
")",
";",
"$",
"shufflingGroups",
"=",
"new",
"ShufflingGroupCollection",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"shufflingGroupCount",
";",
"$",
"i",
"++",
")",
"{",
"$",
"shufflingGroups",
"[",
"]",
"=",
"$",
"this",
"->",
"readShufflingGroup",
"(",
")",
";",
"}",
"return",
"new",
"Shuffling",
"(",
"$",
"responseIdentifier",
",",
"$",
"shufflingGroups",
")",
";",
"}",
"catch",
"(",
"BinaryStreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while reading a shufflingState.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"SHUFFLING_STATE",
")",
";",
"}",
"}"
] | Read a Shuffling object from the current binary stream.
@throws QtiBinaryStreamAccessException
@return \qtism\data\state\Shuffling | [
"Read",
"a",
"Shuffling",
"object",
"from",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php#L528-L545 |
oat-sa/qti-sdk | src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php | QtiBinaryStreamAccess.writeShufflingState | public function writeShufflingState(Shuffling $shufflingState)
{
try {
$this->writeIdentifier($shufflingState->getResponseIdentifier());
$shufflingGroups = $shufflingState->getShufflingGroups();
$this->writeTinyInt(count($shufflingGroups));
foreach ($shufflingGroups as $shufflingGroup) {
$this->writeShufflingGroup($shufflingGroup);
}
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while writing a shufflingState.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::SHUFFLING_STATE, $e);
}
} | php | public function writeShufflingState(Shuffling $shufflingState)
{
try {
$this->writeIdentifier($shufflingState->getResponseIdentifier());
$shufflingGroups = $shufflingState->getShufflingGroups();
$this->writeTinyInt(count($shufflingGroups));
foreach ($shufflingGroups as $shufflingGroup) {
$this->writeShufflingGroup($shufflingGroup);
}
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while writing a shufflingState.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::SHUFFLING_STATE, $e);
}
} | [
"public",
"function",
"writeShufflingState",
"(",
"Shuffling",
"$",
"shufflingState",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"writeIdentifier",
"(",
"$",
"shufflingState",
"->",
"getResponseIdentifier",
"(",
")",
")",
";",
"$",
"shufflingGroups",
"=",
"$",
"shufflingState",
"->",
"getShufflingGroups",
"(",
")",
";",
"$",
"this",
"->",
"writeTinyInt",
"(",
"count",
"(",
"$",
"shufflingGroups",
")",
")",
";",
"foreach",
"(",
"$",
"shufflingGroups",
"as",
"$",
"shufflingGroup",
")",
"{",
"$",
"this",
"->",
"writeShufflingGroup",
"(",
"$",
"shufflingGroup",
")",
";",
"}",
"}",
"catch",
"(",
"BinaryStreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while writing a shufflingState.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"SHUFFLING_STATE",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Write a Shuffling object in the current binary stream.
@param \qtism\data\state\Shuffling $shufflingState
@throws QtiBinaryStreamAccessException | [
"Write",
"a",
"Shuffling",
"object",
"in",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php#L553-L567 |
oat-sa/qti-sdk | src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php | QtiBinaryStreamAccess.readDuration | public function readDuration()
{
try {
return new QtiDuration($this->readString());
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while reading a duration.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::DURATION, $e);
}
} | php | public function readDuration()
{
try {
return new QtiDuration($this->readString());
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while reading a duration.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::DURATION, $e);
}
} | [
"public",
"function",
"readDuration",
"(",
")",
"{",
"try",
"{",
"return",
"new",
"QtiDuration",
"(",
"$",
"this",
"->",
"readString",
"(",
")",
")",
";",
"}",
"catch",
"(",
"BinaryStreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while reading a duration.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"DURATION",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Read a Duration from the current binary stream.
@throws \qtism\runtime\storage\binary\QtiBinaryStreamAccessException
@return \qtism\common\datatypes\Duration A Duration object. | [
"Read",
"a",
"Duration",
"from",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php#L575-L583 |
oat-sa/qti-sdk | src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php | QtiBinaryStreamAccess.writeDuration | public function writeDuration(QtiDuration $duration)
{
try {
$this->writeString($duration->__toString());
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while writing a duration.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::DURATION, $e);
}
} | php | public function writeDuration(QtiDuration $duration)
{
try {
$this->writeString($duration->__toString());
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while writing a duration.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::DURATION, $e);
}
} | [
"public",
"function",
"writeDuration",
"(",
"QtiDuration",
"$",
"duration",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"writeString",
"(",
"$",
"duration",
"->",
"__toString",
"(",
")",
")",
";",
"}",
"catch",
"(",
"BinaryStreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while writing a duration.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"DURATION",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Write a Duration in the current binary stream.
@param \qtism\common\datatypes\Duration $duration A Duration object.
@throws \qtism\runtime\storage\binary\QtiBinaryStreamAccessException | [
"Write",
"a",
"Duration",
"in",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php#L591-L599 |
oat-sa/qti-sdk | src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php | QtiBinaryStreamAccess.readUri | public function readUri()
{
try {
return $this->readString();
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while reading a URI.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::URI, $e);
}
} | php | public function readUri()
{
try {
return $this->readString();
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while reading a URI.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::URI, $e);
}
} | [
"public",
"function",
"readUri",
"(",
")",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"readString",
"(",
")",
";",
"}",
"catch",
"(",
"BinaryStreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while reading a URI.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"URI",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Read a URI (Uniform Resource Identifier) from the current binary stream.
@throws \qtism\runtime\storage\binary\QtiBinaryStreamAccessException
@return string A URI. | [
"Read",
"a",
"URI",
"(",
"Uniform",
"Resource",
"Identifier",
")",
"from",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php#L607-L615 |
oat-sa/qti-sdk | src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php | QtiBinaryStreamAccess.writeUri | public function writeUri($uri)
{
try {
$this->writeString($uri);
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while writing a URI.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::URI, $e);
}
} | php | public function writeUri($uri)
{
try {
$this->writeString($uri);
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while writing a URI.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::URI, $e);
}
} | [
"public",
"function",
"writeUri",
"(",
"$",
"uri",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"writeString",
"(",
"$",
"uri",
")",
";",
"}",
"catch",
"(",
"BinaryStreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while writing a URI.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"URI",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Write a URI (Uniform Resource Identifier) in the current binary stream.
@param string $uri A URI.
@throws \qtism\runtime\storage\binary\QtiBinaryStreamAccessException | [
"Write",
"a",
"URI",
"(",
"Uniform",
"Resource",
"Identifier",
")",
"in",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php#L623-L631 |
oat-sa/qti-sdk | src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php | QtiBinaryStreamAccess.readIntOrIdentifier | public function readIntOrIdentifier()
{
try {
$isInt = $this->readBoolean();
return ($isInt === true) ? $this->readInteger() : $this->readIdentifier();
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while reading an intOrIdentifier.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::INTORIDENTIFIER, $e);
}
} | php | public function readIntOrIdentifier()
{
try {
$isInt = $this->readBoolean();
return ($isInt === true) ? $this->readInteger() : $this->readIdentifier();
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while reading an intOrIdentifier.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::INTORIDENTIFIER, $e);
}
} | [
"public",
"function",
"readIntOrIdentifier",
"(",
")",
"{",
"try",
"{",
"$",
"isInt",
"=",
"$",
"this",
"->",
"readBoolean",
"(",
")",
";",
"return",
"(",
"$",
"isInt",
"===",
"true",
")",
"?",
"$",
"this",
"->",
"readInteger",
"(",
")",
":",
"$",
"this",
"->",
"readIdentifier",
"(",
")",
";",
"}",
"catch",
"(",
"BinaryStreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while reading an intOrIdentifier.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"INTORIDENTIFIER",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Read an intOrIdentifier from the current binary stream.
@return integer|string An integer or a string depending on the nature of the intOrIdentifier datatype. | [
"Read",
"an",
"intOrIdentifier",
"from",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php#L638-L648 |
oat-sa/qti-sdk | src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php | QtiBinaryStreamAccess.writeIntOrIdentifier | public function writeIntOrIdentifier($intOrIdentifier)
{
try {
if (gettype($intOrIdentifier) === 'integer') {
$this->writeBoolean(true);
$this->writeInteger($intOrIdentifier);
} elseif (gettype($intOrIdentifier) === 'string') {
$this->writeBoolean(false);
$this->writeString($intOrIdentifier);
} else {
$msg = "The intOrIdentifier value to be written must be an integer or a string, '" . gettype($intOrIdentifier) . "' given.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::INTORIDENTIFIER);
}
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while writing an intOrIdentifier.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::INTORIDENTIFIER, $e);
}
} | php | public function writeIntOrIdentifier($intOrIdentifier)
{
try {
if (gettype($intOrIdentifier) === 'integer') {
$this->writeBoolean(true);
$this->writeInteger($intOrIdentifier);
} elseif (gettype($intOrIdentifier) === 'string') {
$this->writeBoolean(false);
$this->writeString($intOrIdentifier);
} else {
$msg = "The intOrIdentifier value to be written must be an integer or a string, '" . gettype($intOrIdentifier) . "' given.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::INTORIDENTIFIER);
}
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while writing an intOrIdentifier.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::INTORIDENTIFIER, $e);
}
} | [
"public",
"function",
"writeIntOrIdentifier",
"(",
"$",
"intOrIdentifier",
")",
"{",
"try",
"{",
"if",
"(",
"gettype",
"(",
"$",
"intOrIdentifier",
")",
"===",
"'integer'",
")",
"{",
"$",
"this",
"->",
"writeBoolean",
"(",
"true",
")",
";",
"$",
"this",
"->",
"writeInteger",
"(",
"$",
"intOrIdentifier",
")",
";",
"}",
"elseif",
"(",
"gettype",
"(",
"$",
"intOrIdentifier",
")",
"===",
"'string'",
")",
"{",
"$",
"this",
"->",
"writeBoolean",
"(",
"false",
")",
";",
"$",
"this",
"->",
"writeString",
"(",
"$",
"intOrIdentifier",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The intOrIdentifier value to be written must be an integer or a string, '\"",
".",
"gettype",
"(",
"$",
"intOrIdentifier",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"INTORIDENTIFIER",
")",
";",
"}",
"}",
"catch",
"(",
"BinaryStreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while writing an intOrIdentifier.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"INTORIDENTIFIER",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Write an intOrIdentifier in the current binary stream.
@param integer|string $intOrIdentifier An integer or a string value.
@throws \qtism\runtime\storage\binary\QtiBinaryStreamAccessException | [
"Write",
"an",
"intOrIdentifier",
"in",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php#L656-L673 |
oat-sa/qti-sdk | src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php | QtiBinaryStreamAccess.readAssessmentItemSession | public function readAssessmentItemSession(AbstractSessionManager $manager, AssessmentTestSeeker $seeker)
{
try {
$itemRefPosition = $this->readShort();
$assessmentItemRef = $seeker->seekComponent('assessmentItemRef', $itemRefPosition);
$session = $manager->createAssessmentItemSession($assessmentItemRef);
$session->setAssessmentItem($assessmentItemRef);
$session->setState($this->readTinyInt());
$session->setNavigationMode($this->readTinyInt());
$session->setSubmissionMode($this->readTinyInt());
$session->setAttempting($this->readBoolean());
if ($this->readBoolean() === true) {
$itemSessionControl = $seeker->seekComponent('itemSessionControl', $this->readShort());
$session->setItemSessionControl($itemSessionControl);
}
$session['numAttempts'] = new QtiInteger($this->readTinyInt());
$session['duration'] = $this->readDuration();
$session['completionStatus'] = new QtiIdentifier($this->readString());
if ($this->readBoolean() === true) {
// A time reference is set.
$session->setTimeReference($this->readDateTime());
}
// Read the number of item-specific variables involved in the session.
$varCount = $this->readTinyInt();
for ($i = 0; $i < $varCount; $i++) {
// For each of these variables...
// Detect the nature of the variable
// 0 = outcomeVariable, 1 = responseVariable, 2 = templateVariable
$varNature = $this->readShort();
// Read the position of the associated variableDeclaration
// in the assessment tree.
$varPosition = $this->readShort();
$variable = null;
try {
if ($varNature === 0) {
// outcome
$variable = $seeker->seekComponent('outcomeDeclaration', $varPosition);
$variable = OutcomeVariable::createFromDataModel($variable);
} elseif ($varNature === 1) {
// response
$variable = $seeker->seekComponent('responseDeclaration', $varPosition);
$variable = ResponseVariable::createFromDataModel($variable);
} elseif ($varNature === 2) {
// template
$variable = $seeker->seekComponent('templateDeclaration', $varPosition);
$variable = TemplateVariable::createFromDataModel($variable);
}
} catch (OutOfBoundsException $e) {
$msg = "No variable found at position ${varPosition} in the assessmentTest tree structure.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::ITEM_SESSION, $e);
}
// If we are here, we have our variable. We can read its value(s).
// Do we have a specific default value? A specific correct response?
$hasDefaultValue = $this->readBoolean();
$hasCorrectResponse = $this->readBoolean();
// Read the intrinsic value of the variable.
$this->readVariableValue($variable, self::RW_VALUE);
if ($hasDefaultValue === true) {
$this->readVariableValue($variable, self::RW_DEFAULTVALUE);
}
if ($hasCorrectResponse === true) {
$this->readVariableValue($variable, self::RW_CORRECTRESPONSE);
}
$session->setVariable($variable);
}
// Read shuffling states if any.
$shufflingStateCount = $this->readTinyInt();
$shufflingStates = new ShufflingCollection();
for ($i = 0; $i < $shufflingStateCount; $i++) {
$shufflingStates[] = $this->readShufflingState();
}
$session->setShufflingStates($shufflingStates);
return $session;
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while reading an assessment item session.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::ITEM_SESSION, $e);
} catch (OutOfBoundsException $e) {
$msg = "No assessmentItemRef found at position ${itemRefPosition} in the assessmentTest tree structure.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::ITEM_SESSION, $e);
}
} | php | public function readAssessmentItemSession(AbstractSessionManager $manager, AssessmentTestSeeker $seeker)
{
try {
$itemRefPosition = $this->readShort();
$assessmentItemRef = $seeker->seekComponent('assessmentItemRef', $itemRefPosition);
$session = $manager->createAssessmentItemSession($assessmentItemRef);
$session->setAssessmentItem($assessmentItemRef);
$session->setState($this->readTinyInt());
$session->setNavigationMode($this->readTinyInt());
$session->setSubmissionMode($this->readTinyInt());
$session->setAttempting($this->readBoolean());
if ($this->readBoolean() === true) {
$itemSessionControl = $seeker->seekComponent('itemSessionControl', $this->readShort());
$session->setItemSessionControl($itemSessionControl);
}
$session['numAttempts'] = new QtiInteger($this->readTinyInt());
$session['duration'] = $this->readDuration();
$session['completionStatus'] = new QtiIdentifier($this->readString());
if ($this->readBoolean() === true) {
// A time reference is set.
$session->setTimeReference($this->readDateTime());
}
// Read the number of item-specific variables involved in the session.
$varCount = $this->readTinyInt();
for ($i = 0; $i < $varCount; $i++) {
// For each of these variables...
// Detect the nature of the variable
// 0 = outcomeVariable, 1 = responseVariable, 2 = templateVariable
$varNature = $this->readShort();
// Read the position of the associated variableDeclaration
// in the assessment tree.
$varPosition = $this->readShort();
$variable = null;
try {
if ($varNature === 0) {
// outcome
$variable = $seeker->seekComponent('outcomeDeclaration', $varPosition);
$variable = OutcomeVariable::createFromDataModel($variable);
} elseif ($varNature === 1) {
// response
$variable = $seeker->seekComponent('responseDeclaration', $varPosition);
$variable = ResponseVariable::createFromDataModel($variable);
} elseif ($varNature === 2) {
// template
$variable = $seeker->seekComponent('templateDeclaration', $varPosition);
$variable = TemplateVariable::createFromDataModel($variable);
}
} catch (OutOfBoundsException $e) {
$msg = "No variable found at position ${varPosition} in the assessmentTest tree structure.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::ITEM_SESSION, $e);
}
// If we are here, we have our variable. We can read its value(s).
// Do we have a specific default value? A specific correct response?
$hasDefaultValue = $this->readBoolean();
$hasCorrectResponse = $this->readBoolean();
// Read the intrinsic value of the variable.
$this->readVariableValue($variable, self::RW_VALUE);
if ($hasDefaultValue === true) {
$this->readVariableValue($variable, self::RW_DEFAULTVALUE);
}
if ($hasCorrectResponse === true) {
$this->readVariableValue($variable, self::RW_CORRECTRESPONSE);
}
$session->setVariable($variable);
}
// Read shuffling states if any.
$shufflingStateCount = $this->readTinyInt();
$shufflingStates = new ShufflingCollection();
for ($i = 0; $i < $shufflingStateCount; $i++) {
$shufflingStates[] = $this->readShufflingState();
}
$session->setShufflingStates($shufflingStates);
return $session;
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while reading an assessment item session.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::ITEM_SESSION, $e);
} catch (OutOfBoundsException $e) {
$msg = "No assessmentItemRef found at position ${itemRefPosition} in the assessmentTest tree structure.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::ITEM_SESSION, $e);
}
} | [
"public",
"function",
"readAssessmentItemSession",
"(",
"AbstractSessionManager",
"$",
"manager",
",",
"AssessmentTestSeeker",
"$",
"seeker",
")",
"{",
"try",
"{",
"$",
"itemRefPosition",
"=",
"$",
"this",
"->",
"readShort",
"(",
")",
";",
"$",
"assessmentItemRef",
"=",
"$",
"seeker",
"->",
"seekComponent",
"(",
"'assessmentItemRef'",
",",
"$",
"itemRefPosition",
")",
";",
"$",
"session",
"=",
"$",
"manager",
"->",
"createAssessmentItemSession",
"(",
"$",
"assessmentItemRef",
")",
";",
"$",
"session",
"->",
"setAssessmentItem",
"(",
"$",
"assessmentItemRef",
")",
";",
"$",
"session",
"->",
"setState",
"(",
"$",
"this",
"->",
"readTinyInt",
"(",
")",
")",
";",
"$",
"session",
"->",
"setNavigationMode",
"(",
"$",
"this",
"->",
"readTinyInt",
"(",
")",
")",
";",
"$",
"session",
"->",
"setSubmissionMode",
"(",
"$",
"this",
"->",
"readTinyInt",
"(",
")",
")",
";",
"$",
"session",
"->",
"setAttempting",
"(",
"$",
"this",
"->",
"readBoolean",
"(",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"readBoolean",
"(",
")",
"===",
"true",
")",
"{",
"$",
"itemSessionControl",
"=",
"$",
"seeker",
"->",
"seekComponent",
"(",
"'itemSessionControl'",
",",
"$",
"this",
"->",
"readShort",
"(",
")",
")",
";",
"$",
"session",
"->",
"setItemSessionControl",
"(",
"$",
"itemSessionControl",
")",
";",
"}",
"$",
"session",
"[",
"'numAttempts'",
"]",
"=",
"new",
"QtiInteger",
"(",
"$",
"this",
"->",
"readTinyInt",
"(",
")",
")",
";",
"$",
"session",
"[",
"'duration'",
"]",
"=",
"$",
"this",
"->",
"readDuration",
"(",
")",
";",
"$",
"session",
"[",
"'completionStatus'",
"]",
"=",
"new",
"QtiIdentifier",
"(",
"$",
"this",
"->",
"readString",
"(",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"readBoolean",
"(",
")",
"===",
"true",
")",
"{",
"// A time reference is set.",
"$",
"session",
"->",
"setTimeReference",
"(",
"$",
"this",
"->",
"readDateTime",
"(",
")",
")",
";",
"}",
"// Read the number of item-specific variables involved in the session.",
"$",
"varCount",
"=",
"$",
"this",
"->",
"readTinyInt",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"varCount",
";",
"$",
"i",
"++",
")",
"{",
"// For each of these variables...",
"// Detect the nature of the variable",
"// 0 = outcomeVariable, 1 = responseVariable, 2 = templateVariable",
"$",
"varNature",
"=",
"$",
"this",
"->",
"readShort",
"(",
")",
";",
"// Read the position of the associated variableDeclaration",
"// in the assessment tree.",
"$",
"varPosition",
"=",
"$",
"this",
"->",
"readShort",
"(",
")",
";",
"$",
"variable",
"=",
"null",
";",
"try",
"{",
"if",
"(",
"$",
"varNature",
"===",
"0",
")",
"{",
"// outcome",
"$",
"variable",
"=",
"$",
"seeker",
"->",
"seekComponent",
"(",
"'outcomeDeclaration'",
",",
"$",
"varPosition",
")",
";",
"$",
"variable",
"=",
"OutcomeVariable",
"::",
"createFromDataModel",
"(",
"$",
"variable",
")",
";",
"}",
"elseif",
"(",
"$",
"varNature",
"===",
"1",
")",
"{",
"// response",
"$",
"variable",
"=",
"$",
"seeker",
"->",
"seekComponent",
"(",
"'responseDeclaration'",
",",
"$",
"varPosition",
")",
";",
"$",
"variable",
"=",
"ResponseVariable",
"::",
"createFromDataModel",
"(",
"$",
"variable",
")",
";",
"}",
"elseif",
"(",
"$",
"varNature",
"===",
"2",
")",
"{",
"// template",
"$",
"variable",
"=",
"$",
"seeker",
"->",
"seekComponent",
"(",
"'templateDeclaration'",
",",
"$",
"varPosition",
")",
";",
"$",
"variable",
"=",
"TemplateVariable",
"::",
"createFromDataModel",
"(",
"$",
"variable",
")",
";",
"}",
"}",
"catch",
"(",
"OutOfBoundsException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"No variable found at position ${varPosition} in the assessmentTest tree structure.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"ITEM_SESSION",
",",
"$",
"e",
")",
";",
"}",
"// If we are here, we have our variable. We can read its value(s).",
"// Do we have a specific default value? A specific correct response?",
"$",
"hasDefaultValue",
"=",
"$",
"this",
"->",
"readBoolean",
"(",
")",
";",
"$",
"hasCorrectResponse",
"=",
"$",
"this",
"->",
"readBoolean",
"(",
")",
";",
"// Read the intrinsic value of the variable.",
"$",
"this",
"->",
"readVariableValue",
"(",
"$",
"variable",
",",
"self",
"::",
"RW_VALUE",
")",
";",
"if",
"(",
"$",
"hasDefaultValue",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"readVariableValue",
"(",
"$",
"variable",
",",
"self",
"::",
"RW_DEFAULTVALUE",
")",
";",
"}",
"if",
"(",
"$",
"hasCorrectResponse",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"readVariableValue",
"(",
"$",
"variable",
",",
"self",
"::",
"RW_CORRECTRESPONSE",
")",
";",
"}",
"$",
"session",
"->",
"setVariable",
"(",
"$",
"variable",
")",
";",
"}",
"// Read shuffling states if any.",
"$",
"shufflingStateCount",
"=",
"$",
"this",
"->",
"readTinyInt",
"(",
")",
";",
"$",
"shufflingStates",
"=",
"new",
"ShufflingCollection",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"shufflingStateCount",
";",
"$",
"i",
"++",
")",
"{",
"$",
"shufflingStates",
"[",
"]",
"=",
"$",
"this",
"->",
"readShufflingState",
"(",
")",
";",
"}",
"$",
"session",
"->",
"setShufflingStates",
"(",
"$",
"shufflingStates",
")",
";",
"return",
"$",
"session",
";",
"}",
"catch",
"(",
"BinaryStreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while reading an assessment item session.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"ITEM_SESSION",
",",
"$",
"e",
")",
";",
"}",
"catch",
"(",
"OutOfBoundsException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"No assessmentItemRef found at position ${itemRefPosition} in the assessmentTest tree structure.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"ITEM_SESSION",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Read an AssessmentItemSession from the current binary stream.
@param \qtism\runtime\tests\AbstractSessionManager $manager
@param \qtism\runtime\storage\common\AssessmentTestSeeker $seeker An AssessmentTestSeeker object from where 'assessmentItemRef', 'outcomeDeclaration' and 'responseDeclaration' QTI components will be pulled out.
@throws \qtism\runtime\storage\binary\QtiBinaryStreamAccessException | [
"Read",
"an",
"AssessmentItemSession",
"from",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php#L682-L780 |
oat-sa/qti-sdk | src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php | QtiBinaryStreamAccess.writeAssessmentItemSession | public function writeAssessmentItemSession(AssessmentTestSeeker $seeker, AssessmentItemSession $session)
{
try {
$this->writeShort($seeker->seekPosition($session->getAssessmentItem()));
$this->writeTinyInt($session->getState());
$this->writeTinyInt($session->getNavigationMode());
$this->writeTinyInt($session->getSubmissionMode());
$this->writeBoolean($session->isAttempting());
$isItemSessionControlDefault = $session->getItemSessionControl()->isDefault();
if ($isItemSessionControlDefault === true) {
$this->writeBoolean(false);
} else {
$this->writeBoolean(true);
$this->writeShort($seeker->seekPosition($session->getItemSessionControl()));
}
$this->writeTinyInt($session['numAttempts']->getValue());
$this->writeDuration($session['duration']);
$this->writeString($session['completionStatus']->getValue());
$timeReference = $session->getTimeReference();
if (is_null($timeReference) === true) {
// Describe that we have no time reference for the session.
$this->writeBoolean(false);
} else {
// Describe that we have a time reference for the session.
$this->writeBoolean(true);
// Write the time reference.
$this->writeDateTime($timeReference);
}
// Write the session variables.
// (minus the 3 built-in variables)
$varCount = count($session) - 3;
$this->writeTinyInt($varCount);
$itemOutcomes = $session->getAssessmentItem()->getOutcomeDeclarations();
$itemResponses = $session->getAssessmentItem()->getResponseDeclarations();
$itemTemplates = $session->getAssessmentItem()->getTemplateDeclarations();
foreach ($session->getKeys() as $varId) {
if (in_array($varId, array('numAttempts', 'duration', 'completionStatus')) === false) {
$var = $session->getVariable($varId);
if ($var instanceof OutcomeVariable) {
$variableDeclaration = $itemOutcomes[$varId];
$variable = OutcomeVariable::createFromDataModel($variableDeclaration);
$varNature = 0;
} elseif ($var instanceof ResponseVariable) {
$variableDeclaration = $itemResponses[$varId];
$variable = ResponseVariable::createFromDataModel($variableDeclaration);
$varNature = 1;
} elseif ($var instanceof TemplateVariable) {
$variableDeclaration = $itemTemplates[$varId];
$variable = TemplateVariable::createFromDataModel($variableDeclaration);
$varNature = 2;
}
$this->writeShort($varNature);
$this->writeShort($seeker->seekPosition($variableDeclaration));
// If defaultValue or correct response is different from what's inside
// the variable declaration, just write it.
$hasDefaultValue = !Utils::equals($variable->getDefaultValue(), $var->getDefaultValue());
$hasCorrectResponse = false;
if ($varNature === 1 && !Utils::equals($variable->getCorrectResponse(), $var->getCorrectResponse())) {
$hasCorrectResponse = true;
}
$this->writeBoolean($hasDefaultValue);
$this->writeBoolean($hasCorrectResponse);
$this->writeVariableValue($var, self::RW_VALUE);
if ($hasDefaultValue === true) {
$this->writeVariableValue($var, self::RW_DEFAULTVALUE);
}
if ($hasCorrectResponse === true) {
$this->writeVariableValue($var, self::RW_CORRECTRESPONSE);
}
}
}
// Write shuffling states if any.
$shufflingStates = $session->getShufflingStates();
$this->writeTinyInt(count($shufflingStates));
foreach ($shufflingStates as $shufflingState) {
$this->writeShufflingState($shufflingState);
}
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while writing an assessment item session.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::ITEM_SESSION, $e);
} catch (OutOfBoundsException $e) {
$msg = "No assessmentItemRef found in the assessmentTest tree structure.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::ITEM_SESSION, $e);
}
} | php | public function writeAssessmentItemSession(AssessmentTestSeeker $seeker, AssessmentItemSession $session)
{
try {
$this->writeShort($seeker->seekPosition($session->getAssessmentItem()));
$this->writeTinyInt($session->getState());
$this->writeTinyInt($session->getNavigationMode());
$this->writeTinyInt($session->getSubmissionMode());
$this->writeBoolean($session->isAttempting());
$isItemSessionControlDefault = $session->getItemSessionControl()->isDefault();
if ($isItemSessionControlDefault === true) {
$this->writeBoolean(false);
} else {
$this->writeBoolean(true);
$this->writeShort($seeker->seekPosition($session->getItemSessionControl()));
}
$this->writeTinyInt($session['numAttempts']->getValue());
$this->writeDuration($session['duration']);
$this->writeString($session['completionStatus']->getValue());
$timeReference = $session->getTimeReference();
if (is_null($timeReference) === true) {
// Describe that we have no time reference for the session.
$this->writeBoolean(false);
} else {
// Describe that we have a time reference for the session.
$this->writeBoolean(true);
// Write the time reference.
$this->writeDateTime($timeReference);
}
// Write the session variables.
// (minus the 3 built-in variables)
$varCount = count($session) - 3;
$this->writeTinyInt($varCount);
$itemOutcomes = $session->getAssessmentItem()->getOutcomeDeclarations();
$itemResponses = $session->getAssessmentItem()->getResponseDeclarations();
$itemTemplates = $session->getAssessmentItem()->getTemplateDeclarations();
foreach ($session->getKeys() as $varId) {
if (in_array($varId, array('numAttempts', 'duration', 'completionStatus')) === false) {
$var = $session->getVariable($varId);
if ($var instanceof OutcomeVariable) {
$variableDeclaration = $itemOutcomes[$varId];
$variable = OutcomeVariable::createFromDataModel($variableDeclaration);
$varNature = 0;
} elseif ($var instanceof ResponseVariable) {
$variableDeclaration = $itemResponses[$varId];
$variable = ResponseVariable::createFromDataModel($variableDeclaration);
$varNature = 1;
} elseif ($var instanceof TemplateVariable) {
$variableDeclaration = $itemTemplates[$varId];
$variable = TemplateVariable::createFromDataModel($variableDeclaration);
$varNature = 2;
}
$this->writeShort($varNature);
$this->writeShort($seeker->seekPosition($variableDeclaration));
// If defaultValue or correct response is different from what's inside
// the variable declaration, just write it.
$hasDefaultValue = !Utils::equals($variable->getDefaultValue(), $var->getDefaultValue());
$hasCorrectResponse = false;
if ($varNature === 1 && !Utils::equals($variable->getCorrectResponse(), $var->getCorrectResponse())) {
$hasCorrectResponse = true;
}
$this->writeBoolean($hasDefaultValue);
$this->writeBoolean($hasCorrectResponse);
$this->writeVariableValue($var, self::RW_VALUE);
if ($hasDefaultValue === true) {
$this->writeVariableValue($var, self::RW_DEFAULTVALUE);
}
if ($hasCorrectResponse === true) {
$this->writeVariableValue($var, self::RW_CORRECTRESPONSE);
}
}
}
// Write shuffling states if any.
$shufflingStates = $session->getShufflingStates();
$this->writeTinyInt(count($shufflingStates));
foreach ($shufflingStates as $shufflingState) {
$this->writeShufflingState($shufflingState);
}
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while writing an assessment item session.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::ITEM_SESSION, $e);
} catch (OutOfBoundsException $e) {
$msg = "No assessmentItemRef found in the assessmentTest tree structure.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::ITEM_SESSION, $e);
}
} | [
"public",
"function",
"writeAssessmentItemSession",
"(",
"AssessmentTestSeeker",
"$",
"seeker",
",",
"AssessmentItemSession",
"$",
"session",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"writeShort",
"(",
"$",
"seeker",
"->",
"seekPosition",
"(",
"$",
"session",
"->",
"getAssessmentItem",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"writeTinyInt",
"(",
"$",
"session",
"->",
"getState",
"(",
")",
")",
";",
"$",
"this",
"->",
"writeTinyInt",
"(",
"$",
"session",
"->",
"getNavigationMode",
"(",
")",
")",
";",
"$",
"this",
"->",
"writeTinyInt",
"(",
"$",
"session",
"->",
"getSubmissionMode",
"(",
")",
")",
";",
"$",
"this",
"->",
"writeBoolean",
"(",
"$",
"session",
"->",
"isAttempting",
"(",
")",
")",
";",
"$",
"isItemSessionControlDefault",
"=",
"$",
"session",
"->",
"getItemSessionControl",
"(",
")",
"->",
"isDefault",
"(",
")",
";",
"if",
"(",
"$",
"isItemSessionControlDefault",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"writeBoolean",
"(",
"false",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"writeBoolean",
"(",
"true",
")",
";",
"$",
"this",
"->",
"writeShort",
"(",
"$",
"seeker",
"->",
"seekPosition",
"(",
"$",
"session",
"->",
"getItemSessionControl",
"(",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"writeTinyInt",
"(",
"$",
"session",
"[",
"'numAttempts'",
"]",
"->",
"getValue",
"(",
")",
")",
";",
"$",
"this",
"->",
"writeDuration",
"(",
"$",
"session",
"[",
"'duration'",
"]",
")",
";",
"$",
"this",
"->",
"writeString",
"(",
"$",
"session",
"[",
"'completionStatus'",
"]",
"->",
"getValue",
"(",
")",
")",
";",
"$",
"timeReference",
"=",
"$",
"session",
"->",
"getTimeReference",
"(",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"timeReference",
")",
"===",
"true",
")",
"{",
"// Describe that we have no time reference for the session.",
"$",
"this",
"->",
"writeBoolean",
"(",
"false",
")",
";",
"}",
"else",
"{",
"// Describe that we have a time reference for the session.",
"$",
"this",
"->",
"writeBoolean",
"(",
"true",
")",
";",
"// Write the time reference.",
"$",
"this",
"->",
"writeDateTime",
"(",
"$",
"timeReference",
")",
";",
"}",
"// Write the session variables.",
"// (minus the 3 built-in variables)",
"$",
"varCount",
"=",
"count",
"(",
"$",
"session",
")",
"-",
"3",
";",
"$",
"this",
"->",
"writeTinyInt",
"(",
"$",
"varCount",
")",
";",
"$",
"itemOutcomes",
"=",
"$",
"session",
"->",
"getAssessmentItem",
"(",
")",
"->",
"getOutcomeDeclarations",
"(",
")",
";",
"$",
"itemResponses",
"=",
"$",
"session",
"->",
"getAssessmentItem",
"(",
")",
"->",
"getResponseDeclarations",
"(",
")",
";",
"$",
"itemTemplates",
"=",
"$",
"session",
"->",
"getAssessmentItem",
"(",
")",
"->",
"getTemplateDeclarations",
"(",
")",
";",
"foreach",
"(",
"$",
"session",
"->",
"getKeys",
"(",
")",
"as",
"$",
"varId",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"varId",
",",
"array",
"(",
"'numAttempts'",
",",
"'duration'",
",",
"'completionStatus'",
")",
")",
"===",
"false",
")",
"{",
"$",
"var",
"=",
"$",
"session",
"->",
"getVariable",
"(",
"$",
"varId",
")",
";",
"if",
"(",
"$",
"var",
"instanceof",
"OutcomeVariable",
")",
"{",
"$",
"variableDeclaration",
"=",
"$",
"itemOutcomes",
"[",
"$",
"varId",
"]",
";",
"$",
"variable",
"=",
"OutcomeVariable",
"::",
"createFromDataModel",
"(",
"$",
"variableDeclaration",
")",
";",
"$",
"varNature",
"=",
"0",
";",
"}",
"elseif",
"(",
"$",
"var",
"instanceof",
"ResponseVariable",
")",
"{",
"$",
"variableDeclaration",
"=",
"$",
"itemResponses",
"[",
"$",
"varId",
"]",
";",
"$",
"variable",
"=",
"ResponseVariable",
"::",
"createFromDataModel",
"(",
"$",
"variableDeclaration",
")",
";",
"$",
"varNature",
"=",
"1",
";",
"}",
"elseif",
"(",
"$",
"var",
"instanceof",
"TemplateVariable",
")",
"{",
"$",
"variableDeclaration",
"=",
"$",
"itemTemplates",
"[",
"$",
"varId",
"]",
";",
"$",
"variable",
"=",
"TemplateVariable",
"::",
"createFromDataModel",
"(",
"$",
"variableDeclaration",
")",
";",
"$",
"varNature",
"=",
"2",
";",
"}",
"$",
"this",
"->",
"writeShort",
"(",
"$",
"varNature",
")",
";",
"$",
"this",
"->",
"writeShort",
"(",
"$",
"seeker",
"->",
"seekPosition",
"(",
"$",
"variableDeclaration",
")",
")",
";",
"// If defaultValue or correct response is different from what's inside",
"// the variable declaration, just write it.",
"$",
"hasDefaultValue",
"=",
"!",
"Utils",
"::",
"equals",
"(",
"$",
"variable",
"->",
"getDefaultValue",
"(",
")",
",",
"$",
"var",
"->",
"getDefaultValue",
"(",
")",
")",
";",
"$",
"hasCorrectResponse",
"=",
"false",
";",
"if",
"(",
"$",
"varNature",
"===",
"1",
"&&",
"!",
"Utils",
"::",
"equals",
"(",
"$",
"variable",
"->",
"getCorrectResponse",
"(",
")",
",",
"$",
"var",
"->",
"getCorrectResponse",
"(",
")",
")",
")",
"{",
"$",
"hasCorrectResponse",
"=",
"true",
";",
"}",
"$",
"this",
"->",
"writeBoolean",
"(",
"$",
"hasDefaultValue",
")",
";",
"$",
"this",
"->",
"writeBoolean",
"(",
"$",
"hasCorrectResponse",
")",
";",
"$",
"this",
"->",
"writeVariableValue",
"(",
"$",
"var",
",",
"self",
"::",
"RW_VALUE",
")",
";",
"if",
"(",
"$",
"hasDefaultValue",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"writeVariableValue",
"(",
"$",
"var",
",",
"self",
"::",
"RW_DEFAULTVALUE",
")",
";",
"}",
"if",
"(",
"$",
"hasCorrectResponse",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"writeVariableValue",
"(",
"$",
"var",
",",
"self",
"::",
"RW_CORRECTRESPONSE",
")",
";",
"}",
"}",
"}",
"// Write shuffling states if any.",
"$",
"shufflingStates",
"=",
"$",
"session",
"->",
"getShufflingStates",
"(",
")",
";",
"$",
"this",
"->",
"writeTinyInt",
"(",
"count",
"(",
"$",
"shufflingStates",
")",
")",
";",
"foreach",
"(",
"$",
"shufflingStates",
"as",
"$",
"shufflingState",
")",
"{",
"$",
"this",
"->",
"writeShufflingState",
"(",
"$",
"shufflingState",
")",
";",
"}",
"}",
"catch",
"(",
"BinaryStreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while writing an assessment item session.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"ITEM_SESSION",
",",
"$",
"e",
")",
";",
"}",
"catch",
"(",
"OutOfBoundsException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"No assessmentItemRef found in the assessmentTest tree structure.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"ITEM_SESSION",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Write an AssessmetnItemSession from the current binary stream.
@param \qtism\runtime\storage\common\AssessmentTestSeeker $seeker The AssessmentTestSeeker object from where the position of components will be pulled out.
@param \qtism\runtime\tests\AssessmentItemSession $session An AssessmentItemSession object.
@throws \qtism\runtime\storage\binary\QtiBinaryStreamAccessException | [
"Write",
"an",
"AssessmetnItemSession",
"from",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php#L789-L890 |
oat-sa/qti-sdk | src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php | QtiBinaryStreamAccess.readRouteItem | public function readRouteItem(AssessmentTestSeeker $seeker)
{
try {
$occurence = $this->readTinyInt();
$itemRef = $seeker->seekComponent('assessmentItemRef', $this->readShort());
$testPart = $seeker->seekComponent('testPart', $this->readShort());
$sectionsCount = $this->readTinyInt();
$sections = new AssessmentSectionCollection();
for ($i = 0; $i < $sectionsCount; $i++) {
$sections[] = $seeker->seekComponent('assessmentSection', $this->readShort());
}
$branchRulesCount = $this->readTinyInt();
$branchRules = new BranchRuleCollection();
for ($i = 0; $i < $branchRulesCount; $i++) {
$branchRules[] = $seeker->seekComponent('branchRule', $this->readShort());
}
$preConditionsCount = $this->readTinyInt();
$preConditions = new PreConditionCollection();
for ($i = 0; $i < $preConditionsCount; $i++) {
$preConditions[] = $seeker->seekComponent('preCondition', $this->readShort());
}
$routeItem = new RouteItem($itemRef, $sections, $testPart, $seeker->getAssessmentTest());
$routeItem->setOccurence($occurence);
$routeItem->setBranchRules($branchRules);
$routeItem->setPreConditions($preConditions);
return $routeItem;
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while reading a route item.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::ROUTE_ITEM, $e);
} catch (OutOfBoundsException $e) {
$msg = "A QTI Component was not found in the assessmentTest tree structure.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::ROUTE_ITEM, $e);
}
} | php | public function readRouteItem(AssessmentTestSeeker $seeker)
{
try {
$occurence = $this->readTinyInt();
$itemRef = $seeker->seekComponent('assessmentItemRef', $this->readShort());
$testPart = $seeker->seekComponent('testPart', $this->readShort());
$sectionsCount = $this->readTinyInt();
$sections = new AssessmentSectionCollection();
for ($i = 0; $i < $sectionsCount; $i++) {
$sections[] = $seeker->seekComponent('assessmentSection', $this->readShort());
}
$branchRulesCount = $this->readTinyInt();
$branchRules = new BranchRuleCollection();
for ($i = 0; $i < $branchRulesCount; $i++) {
$branchRules[] = $seeker->seekComponent('branchRule', $this->readShort());
}
$preConditionsCount = $this->readTinyInt();
$preConditions = new PreConditionCollection();
for ($i = 0; $i < $preConditionsCount; $i++) {
$preConditions[] = $seeker->seekComponent('preCondition', $this->readShort());
}
$routeItem = new RouteItem($itemRef, $sections, $testPart, $seeker->getAssessmentTest());
$routeItem->setOccurence($occurence);
$routeItem->setBranchRules($branchRules);
$routeItem->setPreConditions($preConditions);
return $routeItem;
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while reading a route item.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::ROUTE_ITEM, $e);
} catch (OutOfBoundsException $e) {
$msg = "A QTI Component was not found in the assessmentTest tree structure.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::ROUTE_ITEM, $e);
}
} | [
"public",
"function",
"readRouteItem",
"(",
"AssessmentTestSeeker",
"$",
"seeker",
")",
"{",
"try",
"{",
"$",
"occurence",
"=",
"$",
"this",
"->",
"readTinyInt",
"(",
")",
";",
"$",
"itemRef",
"=",
"$",
"seeker",
"->",
"seekComponent",
"(",
"'assessmentItemRef'",
",",
"$",
"this",
"->",
"readShort",
"(",
")",
")",
";",
"$",
"testPart",
"=",
"$",
"seeker",
"->",
"seekComponent",
"(",
"'testPart'",
",",
"$",
"this",
"->",
"readShort",
"(",
")",
")",
";",
"$",
"sectionsCount",
"=",
"$",
"this",
"->",
"readTinyInt",
"(",
")",
";",
"$",
"sections",
"=",
"new",
"AssessmentSectionCollection",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"sectionsCount",
";",
"$",
"i",
"++",
")",
"{",
"$",
"sections",
"[",
"]",
"=",
"$",
"seeker",
"->",
"seekComponent",
"(",
"'assessmentSection'",
",",
"$",
"this",
"->",
"readShort",
"(",
")",
")",
";",
"}",
"$",
"branchRulesCount",
"=",
"$",
"this",
"->",
"readTinyInt",
"(",
")",
";",
"$",
"branchRules",
"=",
"new",
"BranchRuleCollection",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"branchRulesCount",
";",
"$",
"i",
"++",
")",
"{",
"$",
"branchRules",
"[",
"]",
"=",
"$",
"seeker",
"->",
"seekComponent",
"(",
"'branchRule'",
",",
"$",
"this",
"->",
"readShort",
"(",
")",
")",
";",
"}",
"$",
"preConditionsCount",
"=",
"$",
"this",
"->",
"readTinyInt",
"(",
")",
";",
"$",
"preConditions",
"=",
"new",
"PreConditionCollection",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"preConditionsCount",
";",
"$",
"i",
"++",
")",
"{",
"$",
"preConditions",
"[",
"]",
"=",
"$",
"seeker",
"->",
"seekComponent",
"(",
"'preCondition'",
",",
"$",
"this",
"->",
"readShort",
"(",
")",
")",
";",
"}",
"$",
"routeItem",
"=",
"new",
"RouteItem",
"(",
"$",
"itemRef",
",",
"$",
"sections",
",",
"$",
"testPart",
",",
"$",
"seeker",
"->",
"getAssessmentTest",
"(",
")",
")",
";",
"$",
"routeItem",
"->",
"setOccurence",
"(",
"$",
"occurence",
")",
";",
"$",
"routeItem",
"->",
"setBranchRules",
"(",
"$",
"branchRules",
")",
";",
"$",
"routeItem",
"->",
"setPreConditions",
"(",
"$",
"preConditions",
")",
";",
"return",
"$",
"routeItem",
";",
"}",
"catch",
"(",
"BinaryStreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while reading a route item.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"ROUTE_ITEM",
",",
"$",
"e",
")",
";",
"}",
"catch",
"(",
"OutOfBoundsException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"A QTI Component was not found in the assessmentTest tree structure.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"ROUTE_ITEM",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Read a route item from the current binary stream.
@param \qtism\runtime\storage\common\AssessmentTestSeeker $seeker An AssessmentTestSeeker object where components will be pulled out by position.
@throws \qtism\runtime\storage\binary\QtiBinaryStreamAccessException
@return \qtism\runtime\tests\RouteItem | [
"Read",
"a",
"route",
"item",
"from",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php#L899-L940 |
oat-sa/qti-sdk | src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php | QtiBinaryStreamAccess.writeRouteItem | public function writeRouteItem(AssessmentTestSeeker $seeker, RouteItem $routeItem)
{
try {
$this->writeTinyInt($routeItem->getOccurence());
$this->writeShort($seeker->seekPosition($routeItem->getAssessmentItemRef()));
$this->writeShort($seeker->seekPosition($routeItem->getTestPart()));
$assessmentSections = $routeItem->getAssessmentSections();
$this->writeTinyInt(count($assessmentSections));
foreach ($assessmentSections as $assessmentSection) {
$this->writeShort($seeker->seekPosition($assessmentSection));
}
$branchRules = $routeItem->getBranchRules();
$this->writeTinyInt(count($branchRules));
foreach ($branchRules as $branchRule) {
$this->writeShort($seeker->seekPosition($branchRule));
}
$preConditions = $routeItem->getPreConditions();
$this->writeTinyInt(count($preConditions));
foreach ($preConditions as $preCondition) {
$this->writeShort($seeker->seekPosition($preCondition));
}
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while writing a route item.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::ROUTE_ITEM, $e);
} catch (OutOfBoundsException $e) {
$msg = "A QTI Component position was not found in the assessmentTest tree structure.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::ROUTE_ITEM, $e);
}
} | php | public function writeRouteItem(AssessmentTestSeeker $seeker, RouteItem $routeItem)
{
try {
$this->writeTinyInt($routeItem->getOccurence());
$this->writeShort($seeker->seekPosition($routeItem->getAssessmentItemRef()));
$this->writeShort($seeker->seekPosition($routeItem->getTestPart()));
$assessmentSections = $routeItem->getAssessmentSections();
$this->writeTinyInt(count($assessmentSections));
foreach ($assessmentSections as $assessmentSection) {
$this->writeShort($seeker->seekPosition($assessmentSection));
}
$branchRules = $routeItem->getBranchRules();
$this->writeTinyInt(count($branchRules));
foreach ($branchRules as $branchRule) {
$this->writeShort($seeker->seekPosition($branchRule));
}
$preConditions = $routeItem->getPreConditions();
$this->writeTinyInt(count($preConditions));
foreach ($preConditions as $preCondition) {
$this->writeShort($seeker->seekPosition($preCondition));
}
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while writing a route item.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::ROUTE_ITEM, $e);
} catch (OutOfBoundsException $e) {
$msg = "A QTI Component position was not found in the assessmentTest tree structure.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::ROUTE_ITEM, $e);
}
} | [
"public",
"function",
"writeRouteItem",
"(",
"AssessmentTestSeeker",
"$",
"seeker",
",",
"RouteItem",
"$",
"routeItem",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"writeTinyInt",
"(",
"$",
"routeItem",
"->",
"getOccurence",
"(",
")",
")",
";",
"$",
"this",
"->",
"writeShort",
"(",
"$",
"seeker",
"->",
"seekPosition",
"(",
"$",
"routeItem",
"->",
"getAssessmentItemRef",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"writeShort",
"(",
"$",
"seeker",
"->",
"seekPosition",
"(",
"$",
"routeItem",
"->",
"getTestPart",
"(",
")",
")",
")",
";",
"$",
"assessmentSections",
"=",
"$",
"routeItem",
"->",
"getAssessmentSections",
"(",
")",
";",
"$",
"this",
"->",
"writeTinyInt",
"(",
"count",
"(",
"$",
"assessmentSections",
")",
")",
";",
"foreach",
"(",
"$",
"assessmentSections",
"as",
"$",
"assessmentSection",
")",
"{",
"$",
"this",
"->",
"writeShort",
"(",
"$",
"seeker",
"->",
"seekPosition",
"(",
"$",
"assessmentSection",
")",
")",
";",
"}",
"$",
"branchRules",
"=",
"$",
"routeItem",
"->",
"getBranchRules",
"(",
")",
";",
"$",
"this",
"->",
"writeTinyInt",
"(",
"count",
"(",
"$",
"branchRules",
")",
")",
";",
"foreach",
"(",
"$",
"branchRules",
"as",
"$",
"branchRule",
")",
"{",
"$",
"this",
"->",
"writeShort",
"(",
"$",
"seeker",
"->",
"seekPosition",
"(",
"$",
"branchRule",
")",
")",
";",
"}",
"$",
"preConditions",
"=",
"$",
"routeItem",
"->",
"getPreConditions",
"(",
")",
";",
"$",
"this",
"->",
"writeTinyInt",
"(",
"count",
"(",
"$",
"preConditions",
")",
")",
";",
"foreach",
"(",
"$",
"preConditions",
"as",
"$",
"preCondition",
")",
"{",
"$",
"this",
"->",
"writeShort",
"(",
"$",
"seeker",
"->",
"seekPosition",
"(",
"$",
"preCondition",
")",
")",
";",
"}",
"}",
"catch",
"(",
"BinaryStreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while writing a route item.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"ROUTE_ITEM",
",",
"$",
"e",
")",
";",
"}",
"catch",
"(",
"OutOfBoundsException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"A QTI Component position was not found in the assessmentTest tree structure.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"ROUTE_ITEM",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Write a route item in the current binary stream.
@param \qtism\runtime\storage\common\AssessmentTestSeeker $seeker An AssessmentTestSeeker object in order to know tree position for involved QTI Components.
@param \qtism\runtime\tests\RouteItem $routeItem A RouteItem object.
@throws \qtism\runtime\storage\binary\QtiBinaryStreamAccessException | [
"Write",
"a",
"route",
"item",
"in",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php#L949-L984 |
oat-sa/qti-sdk | src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php | QtiBinaryStreamAccess.readPendingResponses | public function readPendingResponses(AssessmentTestSeeker $seeker)
{
try {
// Read the state.
$state = new State();
$varCount = $this->readTinyInt();
for ($i = 0; $i < $varCount; $i++) {
$responseDeclaration = $seeker->seekComponent('responseDeclaration', $this->readShort());
$responseVariable = ResponseVariable::createFromDataModel($responseDeclaration);
$this->readVariableValue($responseVariable);
$state->setVariable($responseVariable);
}
// Read the assessmentItemRef.
$itemRef = $seeker->seekComponent('assessmentItemRef', $this->readShort());
// Read the occurence number.
$occurence = $this->readTinyInt();
return new PendingResponses($state, $itemRef, $occurence);
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while reading some pending responses.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::PENDING_RESPONSES, $e);
} catch (OutOfBoundsException $e) {
$msg = "A QTI component was not found in the assessmentTest tree structure.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::PENDING_RESPONSES, $e);
}
} | php | public function readPendingResponses(AssessmentTestSeeker $seeker)
{
try {
// Read the state.
$state = new State();
$varCount = $this->readTinyInt();
for ($i = 0; $i < $varCount; $i++) {
$responseDeclaration = $seeker->seekComponent('responseDeclaration', $this->readShort());
$responseVariable = ResponseVariable::createFromDataModel($responseDeclaration);
$this->readVariableValue($responseVariable);
$state->setVariable($responseVariable);
}
// Read the assessmentItemRef.
$itemRef = $seeker->seekComponent('assessmentItemRef', $this->readShort());
// Read the occurence number.
$occurence = $this->readTinyInt();
return new PendingResponses($state, $itemRef, $occurence);
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while reading some pending responses.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::PENDING_RESPONSES, $e);
} catch (OutOfBoundsException $e) {
$msg = "A QTI component was not found in the assessmentTest tree structure.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::PENDING_RESPONSES, $e);
}
} | [
"public",
"function",
"readPendingResponses",
"(",
"AssessmentTestSeeker",
"$",
"seeker",
")",
"{",
"try",
"{",
"// Read the state.",
"$",
"state",
"=",
"new",
"State",
"(",
")",
";",
"$",
"varCount",
"=",
"$",
"this",
"->",
"readTinyInt",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"varCount",
";",
"$",
"i",
"++",
")",
"{",
"$",
"responseDeclaration",
"=",
"$",
"seeker",
"->",
"seekComponent",
"(",
"'responseDeclaration'",
",",
"$",
"this",
"->",
"readShort",
"(",
")",
")",
";",
"$",
"responseVariable",
"=",
"ResponseVariable",
"::",
"createFromDataModel",
"(",
"$",
"responseDeclaration",
")",
";",
"$",
"this",
"->",
"readVariableValue",
"(",
"$",
"responseVariable",
")",
";",
"$",
"state",
"->",
"setVariable",
"(",
"$",
"responseVariable",
")",
";",
"}",
"// Read the assessmentItemRef.",
"$",
"itemRef",
"=",
"$",
"seeker",
"->",
"seekComponent",
"(",
"'assessmentItemRef'",
",",
"$",
"this",
"->",
"readShort",
"(",
")",
")",
";",
"// Read the occurence number.",
"$",
"occurence",
"=",
"$",
"this",
"->",
"readTinyInt",
"(",
")",
";",
"return",
"new",
"PendingResponses",
"(",
"$",
"state",
",",
"$",
"itemRef",
",",
"$",
"occurence",
")",
";",
"}",
"catch",
"(",
"BinaryStreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while reading some pending responses.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"PENDING_RESPONSES",
",",
"$",
"e",
")",
";",
"}",
"catch",
"(",
"OutOfBoundsException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"A QTI component was not found in the assessmentTest tree structure.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"PENDING_RESPONSES",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Read a PendingResponse object from the current binary stream.
@param \qtism\runtime\storage\common\AssessmentTestSeeker $seeker An AssessmentTestSeeker object in order to know tree position for involved QTI Components.
@return \qtism\runtime\tests\PendingResponses A PendingResponses object.
@throws \qtism\runtime\storage\binary\QtiBinaryStreamAccessException | [
"Read",
"a",
"PendingResponse",
"object",
"from",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php#L993-L1021 |
oat-sa/qti-sdk | src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php | QtiBinaryStreamAccess.writePendingResponses | public function writePendingResponses(AssessmentTestSeeker $seeker, PendingResponses $pendingResponses)
{
try {
$state = $pendingResponses->getState();
$itemRef = $pendingResponses->getAssessmentItemRef();
$occurence = $pendingResponses->getOccurence();
// Write the state.
$responseDeclarations = $itemRef->getResponseDeclarations();
$varCount = count($state);
$this->writeTinyInt($varCount);
foreach ($state as $responseVariable) {
$respId = $responseVariable->getIdentifier();
if (isset($responseDeclarations[$respId]) === true) {
$this->writeShort($seeker->seekPosition($responseDeclarations[$respId]));
$this->writeVariableValue($responseVariable);
} else {
$msg = "No response variable with identifier '${respId}' found in related assessmentItemRef.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::PENDING_RESPONSES);
}
}
// Write the assessmentItemRef.
$this->writeShort($seeker->seekPosition($itemRef));
// Write the occurence number.
$this->writeTinyInt($occurence);
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while reading some pending responses.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::PENDING_RESPONSES, $e);
} catch (OutOfBoundsException $e) {
$msg = "A QTI component position could not be found in the assessmentTest tree structure.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::PENDING_RESPONSES, $e);
}
} | php | public function writePendingResponses(AssessmentTestSeeker $seeker, PendingResponses $pendingResponses)
{
try {
$state = $pendingResponses->getState();
$itemRef = $pendingResponses->getAssessmentItemRef();
$occurence = $pendingResponses->getOccurence();
// Write the state.
$responseDeclarations = $itemRef->getResponseDeclarations();
$varCount = count($state);
$this->writeTinyInt($varCount);
foreach ($state as $responseVariable) {
$respId = $responseVariable->getIdentifier();
if (isset($responseDeclarations[$respId]) === true) {
$this->writeShort($seeker->seekPosition($responseDeclarations[$respId]));
$this->writeVariableValue($responseVariable);
} else {
$msg = "No response variable with identifier '${respId}' found in related assessmentItemRef.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::PENDING_RESPONSES);
}
}
// Write the assessmentItemRef.
$this->writeShort($seeker->seekPosition($itemRef));
// Write the occurence number.
$this->writeTinyInt($occurence);
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while reading some pending responses.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::PENDING_RESPONSES, $e);
} catch (OutOfBoundsException $e) {
$msg = "A QTI component position could not be found in the assessmentTest tree structure.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::PENDING_RESPONSES, $e);
}
} | [
"public",
"function",
"writePendingResponses",
"(",
"AssessmentTestSeeker",
"$",
"seeker",
",",
"PendingResponses",
"$",
"pendingResponses",
")",
"{",
"try",
"{",
"$",
"state",
"=",
"$",
"pendingResponses",
"->",
"getState",
"(",
")",
";",
"$",
"itemRef",
"=",
"$",
"pendingResponses",
"->",
"getAssessmentItemRef",
"(",
")",
";",
"$",
"occurence",
"=",
"$",
"pendingResponses",
"->",
"getOccurence",
"(",
")",
";",
"// Write the state.",
"$",
"responseDeclarations",
"=",
"$",
"itemRef",
"->",
"getResponseDeclarations",
"(",
")",
";",
"$",
"varCount",
"=",
"count",
"(",
"$",
"state",
")",
";",
"$",
"this",
"->",
"writeTinyInt",
"(",
"$",
"varCount",
")",
";",
"foreach",
"(",
"$",
"state",
"as",
"$",
"responseVariable",
")",
"{",
"$",
"respId",
"=",
"$",
"responseVariable",
"->",
"getIdentifier",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"responseDeclarations",
"[",
"$",
"respId",
"]",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"writeShort",
"(",
"$",
"seeker",
"->",
"seekPosition",
"(",
"$",
"responseDeclarations",
"[",
"$",
"respId",
"]",
")",
")",
";",
"$",
"this",
"->",
"writeVariableValue",
"(",
"$",
"responseVariable",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"No response variable with identifier '${respId}' found in related assessmentItemRef.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"PENDING_RESPONSES",
")",
";",
"}",
"}",
"// Write the assessmentItemRef.",
"$",
"this",
"->",
"writeShort",
"(",
"$",
"seeker",
"->",
"seekPosition",
"(",
"$",
"itemRef",
")",
")",
";",
"// Write the occurence number.",
"$",
"this",
"->",
"writeTinyInt",
"(",
"$",
"occurence",
")",
";",
"}",
"catch",
"(",
"BinaryStreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while reading some pending responses.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"PENDING_RESPONSES",
",",
"$",
"e",
")",
";",
"}",
"catch",
"(",
"OutOfBoundsException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"A QTI component position could not be found in the assessmentTest tree structure.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"PENDING_RESPONSES",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Write a PendingResponses object in the current binary stream.
@param \qtism\runtime\storage\common\AssessmentTestSeeker $seeker An AssessmentTestSeeker object from where positions in the assessmentTest tree will be pulled out.
@param \qtism\runtime\tests\PendingResponses $pendingResponses The read PendingResponses object.
@throws \qtism\runtime\storage\binary\QtiBinaryStreamAccessException | [
"Write",
"a",
"PendingResponses",
"object",
"in",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php#L1030-L1065 |
oat-sa/qti-sdk | src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php | QtiBinaryStreamAccess.writeFile | public function writeFile(QtiFile $file)
{
try {
$this->writeString($file->getIdentifier());
} catch (QtiBinaryStreamAccessException $e) {
$msg = "An error occured while reading a QTI File.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::FILE, $e);
}
} | php | public function writeFile(QtiFile $file)
{
try {
$this->writeString($file->getIdentifier());
} catch (QtiBinaryStreamAccessException $e) {
$msg = "An error occured while reading a QTI File.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::FILE, $e);
}
} | [
"public",
"function",
"writeFile",
"(",
"QtiFile",
"$",
"file",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"writeString",
"(",
"$",
"file",
"->",
"getIdentifier",
"(",
")",
")",
";",
"}",
"catch",
"(",
"QtiBinaryStreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while reading a QTI File.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"FILE",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Write a QtiFile object in the current binary stream.
@param \qtism\common\datatypes\QtiFile $file | [
"Write",
"a",
"QtiFile",
"object",
"in",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php#L1072-L1080 |
oat-sa/qti-sdk | src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php | QtiBinaryStreamAccess.readFile | public function readFile()
{
try {
$id = $this->readString();
return $this->getFileManager()->retrieve($id);
} catch (\Exception $e) {
$msg = "An error occured while writing a QTI File.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::FILE, $e);
}
} | php | public function readFile()
{
try {
$id = $this->readString();
return $this->getFileManager()->retrieve($id);
} catch (\Exception $e) {
$msg = "An error occured while writing a QTI File.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::FILE, $e);
}
} | [
"public",
"function",
"readFile",
"(",
")",
"{",
"try",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"readString",
"(",
")",
";",
"return",
"$",
"this",
"->",
"getFileManager",
"(",
")",
"->",
"retrieve",
"(",
"$",
"id",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while writing a QTI File.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"FILE",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Read a QtiFile object from the current binary stream.
@return \qtism\common\datatypes\QtiFile | [
"Read",
"a",
"QtiFile",
"object",
"from",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php#L1087-L1096 |
oat-sa/qti-sdk | src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php | QtiBinaryStreamAccess.readPath | public function readPath() {
try {
$pathCount = $this->readShort();
$path = array();
for ($i = 0; $i < $pathCount; $i++) {
$path[] = $this->readShort();
}
return $path;
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while reading the path.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::PATH, $e);
}
} | php | public function readPath() {
try {
$pathCount = $this->readShort();
$path = array();
for ($i = 0; $i < $pathCount; $i++) {
$path[] = $this->readShort();
}
return $path;
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while reading the path.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::PATH, $e);
}
} | [
"public",
"function",
"readPath",
"(",
")",
"{",
"try",
"{",
"$",
"pathCount",
"=",
"$",
"this",
"->",
"readShort",
"(",
")",
";",
"$",
"path",
"=",
"array",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"pathCount",
";",
"$",
"i",
"++",
")",
"{",
"$",
"path",
"[",
"]",
"=",
"$",
"this",
"->",
"readShort",
"(",
")",
";",
"}",
"return",
"$",
"path",
";",
"}",
"catch",
"(",
"BinaryStreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while reading the path.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"PATH",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Read the path from the current binary stream.
@return array An array of integer values representing flow positions. | [
"Read",
"the",
"path",
"from",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php#L1103-L1117 |
oat-sa/qti-sdk | src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php | QtiBinaryStreamAccess.writePath | public function writePath(array $path) {
try {
$this->writeShort(count($path));
foreach ($path as $p) {
$this->writeShort($p);
}
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while writing the path.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::PATH, $e);
}
} | php | public function writePath(array $path) {
try {
$this->writeShort(count($path));
foreach ($path as $p) {
$this->writeShort($p);
}
} catch (BinaryStreamAccessException $e) {
$msg = "An error occured while writing the path.";
throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::PATH, $e);
}
} | [
"public",
"function",
"writePath",
"(",
"array",
"$",
"path",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"writeShort",
"(",
"count",
"(",
"$",
"path",
")",
")",
";",
"foreach",
"(",
"$",
"path",
"as",
"$",
"p",
")",
"{",
"$",
"this",
"->",
"writeShort",
"(",
"$",
"p",
")",
";",
"}",
"}",
"catch",
"(",
"BinaryStreamAccessException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while writing the path.\"",
";",
"throw",
"new",
"QtiBinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"QtiBinaryStreamAccessException",
"::",
"PATH",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Write the path in the current binary stream.
@param array $path An array of integer values representing flow positions. | [
"Write",
"the",
"path",
"in",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/storage/binary/QtiBinaryStreamAccess.php#L1124-L1134 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/MappingMarshaller.php | MappingMarshaller.marshall | protected function marshall(QtiComponent $component)
{
$element = static::getDOMCradle()->createElement($component->getQtiClassName());
if ($component->hasLowerBound() === true) {
$this->setDOMElementAttribute($element, 'lowerBound', $component->getLowerBound());
}
if ($component->hasUpperBound() === true) {
$this->setDOMElementAttribute($element, 'upperBound', $component->getUpperBound());
}
$this->setDOMElementAttribute($element, 'defaultValue', $component->getDefaultValue());
foreach ($component->getMapEntries() as $mapEntry) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($mapEntry, array($this->getBaseType()));
$element->appendChild($marshaller->marshall($mapEntry));
}
return $element;
} | php | protected function marshall(QtiComponent $component)
{
$element = static::getDOMCradle()->createElement($component->getQtiClassName());
if ($component->hasLowerBound() === true) {
$this->setDOMElementAttribute($element, 'lowerBound', $component->getLowerBound());
}
if ($component->hasUpperBound() === true) {
$this->setDOMElementAttribute($element, 'upperBound', $component->getUpperBound());
}
$this->setDOMElementAttribute($element, 'defaultValue', $component->getDefaultValue());
foreach ($component->getMapEntries() as $mapEntry) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($mapEntry, array($this->getBaseType()));
$element->appendChild($marshaller->marshall($mapEntry));
}
return $element;
} | [
"protected",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"$",
"element",
"=",
"static",
"::",
"getDOMCradle",
"(",
")",
"->",
"createElement",
"(",
"$",
"component",
"->",
"getQtiClassName",
"(",
")",
")",
";",
"if",
"(",
"$",
"component",
"->",
"hasLowerBound",
"(",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'lowerBound'",
",",
"$",
"component",
"->",
"getLowerBound",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"component",
"->",
"hasUpperBound",
"(",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'upperBound'",
",",
"$",
"component",
"->",
"getUpperBound",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'defaultValue'",
",",
"$",
"component",
"->",
"getDefaultValue",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"component",
"->",
"getMapEntries",
"(",
")",
"as",
"$",
"mapEntry",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"mapEntry",
",",
"array",
"(",
"$",
"this",
"->",
"getBaseType",
"(",
")",
")",
")",
";",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"marshaller",
"->",
"marshall",
"(",
"$",
"mapEntry",
")",
")",
";",
"}",
"return",
"$",
"element",
";",
"}"
] | Marshall a Mapping object into a DOMElement object.
@param \qtism\data\QtiComponent $component A Mapping object.
@return \DOMElement The according DOMElement object. | [
"Marshall",
"a",
"Mapping",
"object",
"into",
"a",
"DOMElement",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/MappingMarshaller.php#L95-L115 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/MappingMarshaller.php | MappingMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
$mapEntriesElts = $this->getChildElementsByTagName($element, 'mapEntry');
$mapEntries = new MapEntryCollection();
foreach ($mapEntriesElts as $mapEntryElt) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($mapEntryElt, array($this->getBaseType()));
$mapEntries[] = $marshaller->unmarshall($mapEntryElt);
}
try {
$object = new Mapping($mapEntries);
if (($defaultValue = $this->getDOMElementAttributeAs($element, 'defaultValue', 'float')) !== null) {
$object->setDefaultValue($defaultValue);
}
if (($lowerBound = $this->getDOMElementAttributeAs($element, 'lowerBound', 'float')) !== null) {
$object->setLowerBound($lowerBound);
}
if (($upperBound = $this->getDOMElementAttributeAs($element, 'upperBound', 'float')) !== null) {
$object->setUpperBound($upperBound);
}
return $object;
} catch (InvalidArgumentException $e) {
$msg = "A 'mapping' element must contain at least one 'mapEntry' element. None found";
throw new UnmarshallingException($msg, $element, $e);
}
} | php | protected function unmarshall(DOMElement $element)
{
$mapEntriesElts = $this->getChildElementsByTagName($element, 'mapEntry');
$mapEntries = new MapEntryCollection();
foreach ($mapEntriesElts as $mapEntryElt) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($mapEntryElt, array($this->getBaseType()));
$mapEntries[] = $marshaller->unmarshall($mapEntryElt);
}
try {
$object = new Mapping($mapEntries);
if (($defaultValue = $this->getDOMElementAttributeAs($element, 'defaultValue', 'float')) !== null) {
$object->setDefaultValue($defaultValue);
}
if (($lowerBound = $this->getDOMElementAttributeAs($element, 'lowerBound', 'float')) !== null) {
$object->setLowerBound($lowerBound);
}
if (($upperBound = $this->getDOMElementAttributeAs($element, 'upperBound', 'float')) !== null) {
$object->setUpperBound($upperBound);
}
return $object;
} catch (InvalidArgumentException $e) {
$msg = "A 'mapping' element must contain at least one 'mapEntry' element. None found";
throw new UnmarshallingException($msg, $element, $e);
}
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"$",
"mapEntriesElts",
"=",
"$",
"this",
"->",
"getChildElementsByTagName",
"(",
"$",
"element",
",",
"'mapEntry'",
")",
";",
"$",
"mapEntries",
"=",
"new",
"MapEntryCollection",
"(",
")",
";",
"foreach",
"(",
"$",
"mapEntriesElts",
"as",
"$",
"mapEntryElt",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"mapEntryElt",
",",
"array",
"(",
"$",
"this",
"->",
"getBaseType",
"(",
")",
")",
")",
";",
"$",
"mapEntries",
"[",
"]",
"=",
"$",
"marshaller",
"->",
"unmarshall",
"(",
"$",
"mapEntryElt",
")",
";",
"}",
"try",
"{",
"$",
"object",
"=",
"new",
"Mapping",
"(",
"$",
"mapEntries",
")",
";",
"if",
"(",
"(",
"$",
"defaultValue",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'defaultValue'",
",",
"'float'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"object",
"->",
"setDefaultValue",
"(",
"$",
"defaultValue",
")",
";",
"}",
"if",
"(",
"(",
"$",
"lowerBound",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'lowerBound'",
",",
"'float'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"object",
"->",
"setLowerBound",
"(",
"$",
"lowerBound",
")",
";",
"}",
"if",
"(",
"(",
"$",
"upperBound",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'upperBound'",
",",
"'float'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"object",
"->",
"setUpperBound",
"(",
"$",
"upperBound",
")",
";",
"}",
"return",
"$",
"object",
";",
"}",
"catch",
"(",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"A 'mapping' element must contain at least one 'mapEntry' element. None found\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Unmarshall a DOMElement object corresponding to a QTI mapping element.
@param \DOMElement $element A DOMElement object.
@return \qtism\data\QtiComponent A Mapping object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException | [
"Unmarshall",
"a",
"DOMElement",
"object",
"corresponding",
"to",
"a",
"QTI",
"mapping",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/MappingMarshaller.php#L124-L154 |
oat-sa/qti-sdk | src/qtism/runtime/common/StackTraceItem.php | StackTraceItem.setTraceMessage | public function setTraceMessage($traceMessage)
{
if (gettype($traceMessage) === 'string') {
$this->traceMessage = $traceMessage;
} else {
$msg = "The traceMessage argument must be a string, '" . gettype($traceMessage) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setTraceMessage($traceMessage)
{
if (gettype($traceMessage) === 'string') {
$this->traceMessage = $traceMessage;
} else {
$msg = "The traceMessage argument must be a string, '" . gettype($traceMessage) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setTraceMessage",
"(",
"$",
"traceMessage",
")",
"{",
"if",
"(",
"gettype",
"(",
"$",
"traceMessage",
")",
"===",
"'string'",
")",
"{",
"$",
"this",
"->",
"traceMessage",
"=",
"$",
"traceMessage",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The traceMessage argument must be a string, '\"",
".",
"gettype",
"(",
"$",
"traceMessage",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Get the message about the traced QtiComponent object.
@param string $traceMessage A human-readable message.
@throws \InvalidArgumentException If $traceMessage is not a string. | [
"Get",
"the",
"message",
"about",
"the",
"traced",
"QtiComponent",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/common/StackTraceItem.php#L103-L111 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/VariableProcessor.php | VariableProcessor.process | public function process()
{
$state = $this->getState();
$variableIdentifier = $this->getExpression()->getIdentifier();
$weightIdentifier = $this->getExpression()->getWeightIdentifier();
$variable = $state->getVariable($variableIdentifier);
if (empty($variable)) {
return null;
}
$variableValue = $state[$variableIdentifier];
if ($variable->isNull()) {
return $variableValue; // Even if empty string, it is considered by QTI as null.
}
// We have a value for this variable, is it weighted?
if ($state instanceof AssessmentTestSession) {
try {
$vIdentifier = new VariableIdentifier($variableIdentifier);
if ($vIdentifier->hasPrefix() === true && empty($weightIdentifier) === false) {
$weight = $state->getWeight($vIdentifier->getPrefix() . '.' . $weightIdentifier);
$baseType = $variableValue->getBaseType();
$cardinality = $variableValue->getCardinality();
// From IMS QTI:
// Weights only apply to item variables with base types integer and float.
// If the item variable is of any other type the weight is ignored.
if (!empty($weight) && ($baseType === BaseType::INTEGER || $baseType === BaseType::FLOAT)) {
if ($cardinality === Cardinality::SINGLE) {
return new QtiFloat($variableValue->getValue() * $weight->getValue());
} elseif ($cardinality === Cardinality::MULTIPLE || $cardinality === Cardinality::ORDERED) {
// variableValue is an object, the weighting should not
// affect the content of the state so a new container is created.
$finalValue = ($cardinality === Cardinality::MULTIPLE) ? new MultipleContainer(BaseType::FLOAT) : new OrderedContainer(BaseType::FLOAT);
for ($i = 0; $i < count($variableValue); $i++) {
if ($variableValue[$i] !== null) {
$finalValue[] = new QtiFloat($variableValue[$i]->getValue() * $weight->getValue()) ;
} else {
$finalValue[] = null;
}
}
return $finalValue;
}
} else {
return $variableValue;
}
} else {
return $variableValue;
}
} catch (InvalidArgumentException $e) {
// Invalid $variableIdentifier.
$msg = "Invalid identifier '${variableIdentifier}' given for variable identifier.";
throw new ExpressionProcessingException($msg, $this, ExpressionProcessingException::NONEXISTENT_VARIABLE, $e);
}
} else {
return $variableValue;
}
} | php | public function process()
{
$state = $this->getState();
$variableIdentifier = $this->getExpression()->getIdentifier();
$weightIdentifier = $this->getExpression()->getWeightIdentifier();
$variable = $state->getVariable($variableIdentifier);
if (empty($variable)) {
return null;
}
$variableValue = $state[$variableIdentifier];
if ($variable->isNull()) {
return $variableValue; // Even if empty string, it is considered by QTI as null.
}
// We have a value for this variable, is it weighted?
if ($state instanceof AssessmentTestSession) {
try {
$vIdentifier = new VariableIdentifier($variableIdentifier);
if ($vIdentifier->hasPrefix() === true && empty($weightIdentifier) === false) {
$weight = $state->getWeight($vIdentifier->getPrefix() . '.' . $weightIdentifier);
$baseType = $variableValue->getBaseType();
$cardinality = $variableValue->getCardinality();
// From IMS QTI:
// Weights only apply to item variables with base types integer and float.
// If the item variable is of any other type the weight is ignored.
if (!empty($weight) && ($baseType === BaseType::INTEGER || $baseType === BaseType::FLOAT)) {
if ($cardinality === Cardinality::SINGLE) {
return new QtiFloat($variableValue->getValue() * $weight->getValue());
} elseif ($cardinality === Cardinality::MULTIPLE || $cardinality === Cardinality::ORDERED) {
// variableValue is an object, the weighting should not
// affect the content of the state so a new container is created.
$finalValue = ($cardinality === Cardinality::MULTIPLE) ? new MultipleContainer(BaseType::FLOAT) : new OrderedContainer(BaseType::FLOAT);
for ($i = 0; $i < count($variableValue); $i++) {
if ($variableValue[$i] !== null) {
$finalValue[] = new QtiFloat($variableValue[$i]->getValue() * $weight->getValue()) ;
} else {
$finalValue[] = null;
}
}
return $finalValue;
}
} else {
return $variableValue;
}
} else {
return $variableValue;
}
} catch (InvalidArgumentException $e) {
// Invalid $variableIdentifier.
$msg = "Invalid identifier '${variableIdentifier}' given for variable identifier.";
throw new ExpressionProcessingException($msg, $this, ExpressionProcessingException::NONEXISTENT_VARIABLE, $e);
}
} else {
return $variableValue;
}
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"state",
"=",
"$",
"this",
"->",
"getState",
"(",
")",
";",
"$",
"variableIdentifier",
"=",
"$",
"this",
"->",
"getExpression",
"(",
")",
"->",
"getIdentifier",
"(",
")",
";",
"$",
"weightIdentifier",
"=",
"$",
"this",
"->",
"getExpression",
"(",
")",
"->",
"getWeightIdentifier",
"(",
")",
";",
"$",
"variable",
"=",
"$",
"state",
"->",
"getVariable",
"(",
"$",
"variableIdentifier",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"variable",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"variableValue",
"=",
"$",
"state",
"[",
"$",
"variableIdentifier",
"]",
";",
"if",
"(",
"$",
"variable",
"->",
"isNull",
"(",
")",
")",
"{",
"return",
"$",
"variableValue",
";",
"// Even if empty string, it is considered by QTI as null.",
"}",
"// We have a value for this variable, is it weighted?",
"if",
"(",
"$",
"state",
"instanceof",
"AssessmentTestSession",
")",
"{",
"try",
"{",
"$",
"vIdentifier",
"=",
"new",
"VariableIdentifier",
"(",
"$",
"variableIdentifier",
")",
";",
"if",
"(",
"$",
"vIdentifier",
"->",
"hasPrefix",
"(",
")",
"===",
"true",
"&&",
"empty",
"(",
"$",
"weightIdentifier",
")",
"===",
"false",
")",
"{",
"$",
"weight",
"=",
"$",
"state",
"->",
"getWeight",
"(",
"$",
"vIdentifier",
"->",
"getPrefix",
"(",
")",
".",
"'.'",
".",
"$",
"weightIdentifier",
")",
";",
"$",
"baseType",
"=",
"$",
"variableValue",
"->",
"getBaseType",
"(",
")",
";",
"$",
"cardinality",
"=",
"$",
"variableValue",
"->",
"getCardinality",
"(",
")",
";",
"// From IMS QTI:",
"// Weights only apply to item variables with base types integer and float.",
"// If the item variable is of any other type the weight is ignored.",
"if",
"(",
"!",
"empty",
"(",
"$",
"weight",
")",
"&&",
"(",
"$",
"baseType",
"===",
"BaseType",
"::",
"INTEGER",
"||",
"$",
"baseType",
"===",
"BaseType",
"::",
"FLOAT",
")",
")",
"{",
"if",
"(",
"$",
"cardinality",
"===",
"Cardinality",
"::",
"SINGLE",
")",
"{",
"return",
"new",
"QtiFloat",
"(",
"$",
"variableValue",
"->",
"getValue",
"(",
")",
"*",
"$",
"weight",
"->",
"getValue",
"(",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"cardinality",
"===",
"Cardinality",
"::",
"MULTIPLE",
"||",
"$",
"cardinality",
"===",
"Cardinality",
"::",
"ORDERED",
")",
"{",
"// variableValue is an object, the weighting should not",
"// affect the content of the state so a new container is created.",
"$",
"finalValue",
"=",
"(",
"$",
"cardinality",
"===",
"Cardinality",
"::",
"MULTIPLE",
")",
"?",
"new",
"MultipleContainer",
"(",
"BaseType",
"::",
"FLOAT",
")",
":",
"new",
"OrderedContainer",
"(",
"BaseType",
"::",
"FLOAT",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"variableValue",
")",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"$",
"variableValue",
"[",
"$",
"i",
"]",
"!==",
"null",
")",
"{",
"$",
"finalValue",
"[",
"]",
"=",
"new",
"QtiFloat",
"(",
"$",
"variableValue",
"[",
"$",
"i",
"]",
"->",
"getValue",
"(",
")",
"*",
"$",
"weight",
"->",
"getValue",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"finalValue",
"[",
"]",
"=",
"null",
";",
"}",
"}",
"return",
"$",
"finalValue",
";",
"}",
"}",
"else",
"{",
"return",
"$",
"variableValue",
";",
"}",
"}",
"else",
"{",
"return",
"$",
"variableValue",
";",
"}",
"}",
"catch",
"(",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"// Invalid $variableIdentifier.",
"$",
"msg",
"=",
"\"Invalid identifier '${variableIdentifier}' given for variable identifier.\"",
";",
"throw",
"new",
"ExpressionProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"ExpressionProcessingException",
"::",
"NONEXISTENT_VARIABLE",
",",
"$",
"e",
")",
";",
"}",
"}",
"else",
"{",
"return",
"$",
"variableValue",
";",
"}",
"}"
] | Process the Variable expression.
* If the requested variable does not exist, NULL is returned.
* In a test context, if the requested weight does not exist, the raw value of the variable is returned.
@returns null|mixed The value of the target variable or NULL if the variable does not exist.
@throws \qtism\runtime\expressions\ExpressionProcessingException | [
"Process",
"the",
"Variable",
"expression",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/VariableProcessor.php#L85-L149 |
oat-sa/qti-sdk | src/qtism/runtime/rendering/qtipl/expressions/operators/OperatorQtiPLRenderer.php | OperatorQtiPLRenderer.render | public function render($something)
{
if (!array_key_exists($something->getQtiClassName(), $this->getSignAsOperatorMap()) ||
$something->getExpressions()->count() != 2) {
return $this->getDefaultRendering($something);
}
else { // With operator sign form
return $this->renderWithSignAsOperator($something);
}
} | php | public function render($something)
{
if (!array_key_exists($something->getQtiClassName(), $this->getSignAsOperatorMap()) ||
$something->getExpressions()->count() != 2) {
return $this->getDefaultRendering($something);
}
else { // With operator sign form
return $this->renderWithSignAsOperator($something);
}
} | [
"public",
"function",
"render",
"(",
"$",
"something",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"something",
"->",
"getQtiClassName",
"(",
")",
",",
"$",
"this",
"->",
"getSignAsOperatorMap",
"(",
")",
")",
"||",
"$",
"something",
"->",
"getExpressions",
"(",
")",
"->",
"count",
"(",
")",
"!=",
"2",
")",
"{",
"return",
"$",
"this",
"->",
"getDefaultRendering",
"(",
"$",
"something",
")",
";",
"}",
"else",
"{",
"// With operator sign form",
"return",
"$",
"this",
"->",
"renderWithSignAsOperator",
"(",
"$",
"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/expressions/operators/OperatorQtiPLRenderer.php#L80-L90 |
oat-sa/qti-sdk | src/qtism/runtime/rendering/qtipl/expressions/operators/OperatorQtiPLRenderer.php | OperatorQtiPLRenderer.getDefaultRendering | public function getDefaultRendering($something) {
$renderer = new QtiPLRenderer($this->getCRO());
return $something->getQtiClassName() . $renderer->writeChildElements($something->getExpressions());
} | php | public function getDefaultRendering($something) {
$renderer = new QtiPLRenderer($this->getCRO());
return $something->getQtiClassName() . $renderer->writeChildElements($something->getExpressions());
} | [
"public",
"function",
"getDefaultRendering",
"(",
"$",
"something",
")",
"{",
"$",
"renderer",
"=",
"new",
"QtiPLRenderer",
"(",
"$",
"this",
"->",
"getCRO",
"(",
")",
")",
";",
"return",
"$",
"something",
"->",
"getQtiClassName",
"(",
")",
".",
"$",
"renderer",
"->",
"writeChildElements",
"(",
"$",
"something",
"->",
"getExpressions",
"(",
")",
")",
";",
"}"
] | Returns the default QtiPL rendering for an Operator.
@param mixed $something Something to render into another consitution.
@return string The default QtiPL rendering for an Operator | [
"Returns",
"the",
"default",
"QtiPL",
"rendering",
"for",
"an",
"Operator",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/qtipl/expressions/operators/OperatorQtiPLRenderer.php#L97-L101 |
oat-sa/qti-sdk | src/qtism/runtime/rendering/qtipl/expressions/operators/OperatorQtiPLRenderer.php | OperatorQtiPLRenderer.renderWithSignAsOperator | private function renderWithSignAsOperator($something)
{
$qtipl = "";
$renderer = new QtiPLRenderer($this->getCRO());
$needsparenthesis0 = array_key_exists($something->getExpressions()[0]->getQtiClassName(), $this->getSignAsOperatorMap())
&& $something->getExpressions()[0]->getExpressions()->count() == 2;
$needsparenthesis1 = array_key_exists($something->getExpressions()[1]->getQtiClassName(), $this->getSignAsOperatorMap())
&& $something->getExpressions()[1]->getExpressions()->count() == 2;
$qtipl .= ($needsparenthesis0) ? $renderer->getOpenChildElement() .
$renderer->render($something->getExpressions()[0]) . $renderer->getCloseChildElement():
$renderer->render($something->getExpressions()[0]);
$qtipl .= " " . $this->getSignAsOperatorMap()[$something->getQtiClassName()] . " ";
$qtipl .= ($needsparenthesis1) ? $renderer->getOpenChildElement() .
$renderer->render($something->getExpressions()[1]) . $renderer->getCloseChildElement():
$renderer->render($something->getExpressions()[1]);
return $qtipl;
} | php | private function renderWithSignAsOperator($something)
{
$qtipl = "";
$renderer = new QtiPLRenderer($this->getCRO());
$needsparenthesis0 = array_key_exists($something->getExpressions()[0]->getQtiClassName(), $this->getSignAsOperatorMap())
&& $something->getExpressions()[0]->getExpressions()->count() == 2;
$needsparenthesis1 = array_key_exists($something->getExpressions()[1]->getQtiClassName(), $this->getSignAsOperatorMap())
&& $something->getExpressions()[1]->getExpressions()->count() == 2;
$qtipl .= ($needsparenthesis0) ? $renderer->getOpenChildElement() .
$renderer->render($something->getExpressions()[0]) . $renderer->getCloseChildElement():
$renderer->render($something->getExpressions()[0]);
$qtipl .= " " . $this->getSignAsOperatorMap()[$something->getQtiClassName()] . " ";
$qtipl .= ($needsparenthesis1) ? $renderer->getOpenChildElement() .
$renderer->render($something->getExpressions()[1]) . $renderer->getCloseChildElement():
$renderer->render($something->getExpressions()[1]);
return $qtipl;
} | [
"private",
"function",
"renderWithSignAsOperator",
"(",
"$",
"something",
")",
"{",
"$",
"qtipl",
"=",
"\"\"",
";",
"$",
"renderer",
"=",
"new",
"QtiPLRenderer",
"(",
"$",
"this",
"->",
"getCRO",
"(",
")",
")",
";",
"$",
"needsparenthesis0",
"=",
"array_key_exists",
"(",
"$",
"something",
"->",
"getExpressions",
"(",
")",
"[",
"0",
"]",
"->",
"getQtiClassName",
"(",
")",
",",
"$",
"this",
"->",
"getSignAsOperatorMap",
"(",
")",
")",
"&&",
"$",
"something",
"->",
"getExpressions",
"(",
")",
"[",
"0",
"]",
"->",
"getExpressions",
"(",
")",
"->",
"count",
"(",
")",
"==",
"2",
";",
"$",
"needsparenthesis1",
"=",
"array_key_exists",
"(",
"$",
"something",
"->",
"getExpressions",
"(",
")",
"[",
"1",
"]",
"->",
"getQtiClassName",
"(",
")",
",",
"$",
"this",
"->",
"getSignAsOperatorMap",
"(",
")",
")",
"&&",
"$",
"something",
"->",
"getExpressions",
"(",
")",
"[",
"1",
"]",
"->",
"getExpressions",
"(",
")",
"->",
"count",
"(",
")",
"==",
"2",
";",
"$",
"qtipl",
".=",
"(",
"$",
"needsparenthesis0",
")",
"?",
"$",
"renderer",
"->",
"getOpenChildElement",
"(",
")",
".",
"$",
"renderer",
"->",
"render",
"(",
"$",
"something",
"->",
"getExpressions",
"(",
")",
"[",
"0",
"]",
")",
".",
"$",
"renderer",
"->",
"getCloseChildElement",
"(",
")",
":",
"$",
"renderer",
"->",
"render",
"(",
"$",
"something",
"->",
"getExpressions",
"(",
")",
"[",
"0",
"]",
")",
";",
"$",
"qtipl",
".=",
"\" \"",
".",
"$",
"this",
"->",
"getSignAsOperatorMap",
"(",
")",
"[",
"$",
"something",
"->",
"getQtiClassName",
"(",
")",
"]",
".",
"\" \"",
";",
"$",
"qtipl",
".=",
"(",
"$",
"needsparenthesis1",
")",
"?",
"$",
"renderer",
"->",
"getOpenChildElement",
"(",
")",
".",
"$",
"renderer",
"->",
"render",
"(",
"$",
"something",
"->",
"getExpressions",
"(",
")",
"[",
"1",
"]",
")",
".",
"$",
"renderer",
"->",
"getCloseChildElement",
"(",
")",
":",
"$",
"renderer",
"->",
"render",
"(",
"$",
"something",
"->",
"getExpressions",
"(",
")",
"[",
"1",
"]",
")",
";",
"return",
"$",
"qtipl",
";",
"}"
] | Returns the default QtiPL rendering for an Operator with a specific sign and
2 sub-expressions.
@param mixed $something Something to render into another consitution.
@return string The default QtiPL rendering for an Operator with a specific sign and
2 sub-expressions | [
"Returns",
"the",
"default",
"QtiPL",
"rendering",
"for",
"an",
"Operator",
"with",
"a",
"specific",
"sign",
"and",
"2",
"sub",
"-",
"expressions",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/qtipl/expressions/operators/OperatorQtiPLRenderer.php#L111-L129 |
oat-sa/qti-sdk | src/qtism/data/state/ResponseValidityConstraint.php | ResponseValidityConstraint.setResponseIdentifier | public function setResponseIdentifier($responseIdentifier)
{
if (is_string($responseIdentifier) === false || empty($responseIdentifier) === true) {
throw new InvalidArgumentException(
"The 'responseIdentifier' argument must be a non-empty string."
);
}
$this->responseIdentifier = $responseIdentifier;
} | php | public function setResponseIdentifier($responseIdentifier)
{
if (is_string($responseIdentifier) === false || empty($responseIdentifier) === true) {
throw new InvalidArgumentException(
"The 'responseIdentifier' argument must be a non-empty string."
);
}
$this->responseIdentifier = $responseIdentifier;
} | [
"public",
"function",
"setResponseIdentifier",
"(",
"$",
"responseIdentifier",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"responseIdentifier",
")",
"===",
"false",
"||",
"empty",
"(",
"$",
"responseIdentifier",
")",
"===",
"true",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"The 'responseIdentifier' argument must be a non-empty string.\"",
")",
";",
"}",
"$",
"this",
"->",
"responseIdentifier",
"=",
"$",
"responseIdentifier",
";",
"}"
] | Set the identifier of the response the validity constraint applies to.
@param integer $responseIdentifier
@throws \InvalidArgumentException If $responseIdentifier is not a non-empty string. | [
"Set",
"the",
"identifier",
"of",
"the",
"response",
"the",
"validity",
"constraint",
"applies",
"to",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/state/ResponseValidityConstraint.php#L101-L110 |
oat-sa/qti-sdk | src/qtism/data/state/ResponseValidityConstraint.php | ResponseValidityConstraint.setPatternMask | public function setPatternMask($patternMask)
{
if (is_string($patternMask) === false) {
throw new InvalidArgumentException(
"The 'patternMask' argument must be a string, '" . gettype($patternMask) . "' given."
);
}
$this->patternMask = $patternMask;
} | php | public function setPatternMask($patternMask)
{
if (is_string($patternMask) === false) {
throw new InvalidArgumentException(
"The 'patternMask' argument must be a string, '" . gettype($patternMask) . "' given."
);
}
$this->patternMask = $patternMask;
} | [
"public",
"function",
"setPatternMask",
"(",
"$",
"patternMask",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"patternMask",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"The 'patternMask' argument must be a string, '\"",
".",
"gettype",
"(",
"$",
"patternMask",
")",
".",
"\"' given.\"",
")",
";",
"}",
"$",
"this",
"->",
"patternMask",
"=",
"$",
"patternMask",
";",
"}"
] | Set the PatternMask for the ResponseValidityConstraint.
Set the XML Schema regular expression representing a constraint to be applied on all string
values contained by the variable described in the $responseÏdentifier variable. Providing an empty
string as the $patternMask means there is no constraint to be applied.
@param string $patternMask An XML Schema regular expression. | [
"Set",
"the",
"PatternMask",
"for",
"the",
"ResponseValidityConstraint",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/state/ResponseValidityConstraint.php#L197-L206 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/TableMarshaller.php | TableMarshaller.marshall | protected function marshall(QtiComponent $component)
{
$element = self::getDOMCradle()->createElement('table');
if ($component->hasSummary() === true) {
$this->setDOMElementAttribute($element, 'summary', $component->getSummary());
}
if ($component->hasXmlBase() === true) {
self::setXmlBase($element, $component->getXmlBase());
}
if ($component->hasCaption() === true) {
$caption = $component->getCaption();
$marshaller = $this->getMarshallerFactory()->createMarshaller($caption);
$element->appendChild($marshaller->marshall($caption));
}
$cols = $component->getCols();
if (count($cols) > 0) {
foreach ($cols as $c) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($c);
$element->appendChild($marshaller->marshall($c));
}
}
$colgroups = $component->getColgroups();
if (count($colgroups) > 0) {
foreach ($colgroups as $c) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($c);
$element->appendChild($marshaller->marshall($c));
}
}
if ($component->hasThead() === true) {
$thead = $component->getThead();
$marshaller = $this->getMarshallerFactory()->createMarshaller($thead);
$element->appendChild($marshaller->marshall($thead));
}
if ($component->hasTfoot() === true) {
$tfoot = $component->getTfoot();
$marshaller = $this->getMarshallerFactory()->createMarshaller($tfoot);
$element->appendChild($marshaller->marshall($tfoot));
}
foreach ($component->getTbodies() as $tbody) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($tbody);
$element->appendChild($marshaller->marshall($tbody));
}
$this->fillElement($element, $component);
return $element;
} | php | protected function marshall(QtiComponent $component)
{
$element = self::getDOMCradle()->createElement('table');
if ($component->hasSummary() === true) {
$this->setDOMElementAttribute($element, 'summary', $component->getSummary());
}
if ($component->hasXmlBase() === true) {
self::setXmlBase($element, $component->getXmlBase());
}
if ($component->hasCaption() === true) {
$caption = $component->getCaption();
$marshaller = $this->getMarshallerFactory()->createMarshaller($caption);
$element->appendChild($marshaller->marshall($caption));
}
$cols = $component->getCols();
if (count($cols) > 0) {
foreach ($cols as $c) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($c);
$element->appendChild($marshaller->marshall($c));
}
}
$colgroups = $component->getColgroups();
if (count($colgroups) > 0) {
foreach ($colgroups as $c) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($c);
$element->appendChild($marshaller->marshall($c));
}
}
if ($component->hasThead() === true) {
$thead = $component->getThead();
$marshaller = $this->getMarshallerFactory()->createMarshaller($thead);
$element->appendChild($marshaller->marshall($thead));
}
if ($component->hasTfoot() === true) {
$tfoot = $component->getTfoot();
$marshaller = $this->getMarshallerFactory()->createMarshaller($tfoot);
$element->appendChild($marshaller->marshall($tfoot));
}
foreach ($component->getTbodies() as $tbody) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($tbody);
$element->appendChild($marshaller->marshall($tbody));
}
$this->fillElement($element, $component);
return $element;
} | [
"protected",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"$",
"element",
"=",
"self",
"::",
"getDOMCradle",
"(",
")",
"->",
"createElement",
"(",
"'table'",
")",
";",
"if",
"(",
"$",
"component",
"->",
"hasSummary",
"(",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'summary'",
",",
"$",
"component",
"->",
"getSummary",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"component",
"->",
"hasXmlBase",
"(",
")",
"===",
"true",
")",
"{",
"self",
"::",
"setXmlBase",
"(",
"$",
"element",
",",
"$",
"component",
"->",
"getXmlBase",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"component",
"->",
"hasCaption",
"(",
")",
"===",
"true",
")",
"{",
"$",
"caption",
"=",
"$",
"component",
"->",
"getCaption",
"(",
")",
";",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"caption",
")",
";",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"marshaller",
"->",
"marshall",
"(",
"$",
"caption",
")",
")",
";",
"}",
"$",
"cols",
"=",
"$",
"component",
"->",
"getCols",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"cols",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"cols",
"as",
"$",
"c",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"c",
")",
";",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"marshaller",
"->",
"marshall",
"(",
"$",
"c",
")",
")",
";",
"}",
"}",
"$",
"colgroups",
"=",
"$",
"component",
"->",
"getColgroups",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"colgroups",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"colgroups",
"as",
"$",
"c",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"c",
")",
";",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"marshaller",
"->",
"marshall",
"(",
"$",
"c",
")",
")",
";",
"}",
"}",
"if",
"(",
"$",
"component",
"->",
"hasThead",
"(",
")",
"===",
"true",
")",
"{",
"$",
"thead",
"=",
"$",
"component",
"->",
"getThead",
"(",
")",
";",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"thead",
")",
";",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"marshaller",
"->",
"marshall",
"(",
"$",
"thead",
")",
")",
";",
"}",
"if",
"(",
"$",
"component",
"->",
"hasTfoot",
"(",
")",
"===",
"true",
")",
"{",
"$",
"tfoot",
"=",
"$",
"component",
"->",
"getTfoot",
"(",
")",
";",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"tfoot",
")",
";",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"marshaller",
"->",
"marshall",
"(",
"$",
"tfoot",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"component",
"->",
"getTbodies",
"(",
")",
"as",
"$",
"tbody",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"tbody",
")",
";",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"marshaller",
"->",
"marshall",
"(",
"$",
"tbody",
")",
")",
";",
"}",
"$",
"this",
"->",
"fillElement",
"(",
"$",
"element",
",",
"$",
"component",
")",
";",
"return",
"$",
"element",
";",
"}"
] | Marshall a Table object into a DOMElement object.
@param \qtism\data\QtiComponent $component A Table object.
@return \DOMElement The according DOMElement object.
@throws \qtism\data\storage\xml\marshalling\MarshallingException | [
"Marshall",
"a",
"Table",
"object",
"into",
"a",
"DOMElement",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/TableMarshaller.php#L47-L101 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/TableMarshaller.php | TableMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
$tbodyElts = $this->getChildElementsByTagName($element, 'tbody');
if (count($tbodyElts) > 0) {
$tbodies = new TbodyCollection();
foreach ($tbodyElts as $tbodyElt) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($tbodyElt);
$tbodies[] = $marshaller->unmarshall($tbodyElt);
}
$component = new Table($tbodies);
if (($summary = $this->getDOMElementAttributeAs($element, 'summary')) !== null) {
$component->setSummary($summary);
}
if (($xmlBase = self::getXmlBase($element)) !== false) {
$component->setXmlBase($xmlBase);
}
$captionElts = $this->getChildElementsByTagName($element, 'caption');
if (count($captionElts) > 0) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($captionElts[0]);
$component->setCaption($marshaller->unmarshall($captionElts[0]));
}
$colElts = $this->getChildElementsByTagName($element, 'col');
if (count($colElts) > 0) {
$cols = new ColCollection();
foreach ($colElts as $c) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($c);
$cols[] = $marshaller->unmarshall($c);
}
$component->setCols($cols);
}
$colgroupElts = $this->getChildElementsByTagName($element, 'colgroup');
if (count($colgroupElts) > 0) {
$colgroups = new ColgroupCollection();
foreach ($colgroupElts as $c) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($c);
$colgroups[] = $marshaller->unmarshall($c);
}
$component->setColgroups($colgroups);
}
$theadElts = $this->getChildElementsByTagName($element, 'thead');
if (count($theadElts) > 0) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($theadElts[0]);
$component->setThead($marshaller->unmarshall($theadElts[0]));
}
$tfootElts = $this->getChildElementsByTagName($element, 'tfoot');
if (count($tfootElts) > 0) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($tfootElts[0]);
$component->setTfoot($marshaller->unmarshall($tfootElts[0]));
}
$this->fillBodyElement($component, $element);
return $component;
} else {
$msg = "A 'table' element must contain at lease one 'tbody' element.";
throw new UnmarshallingException($msg, $element);
}
} | php | protected function unmarshall(DOMElement $element)
{
$tbodyElts = $this->getChildElementsByTagName($element, 'tbody');
if (count($tbodyElts) > 0) {
$tbodies = new TbodyCollection();
foreach ($tbodyElts as $tbodyElt) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($tbodyElt);
$tbodies[] = $marshaller->unmarshall($tbodyElt);
}
$component = new Table($tbodies);
if (($summary = $this->getDOMElementAttributeAs($element, 'summary')) !== null) {
$component->setSummary($summary);
}
if (($xmlBase = self::getXmlBase($element)) !== false) {
$component->setXmlBase($xmlBase);
}
$captionElts = $this->getChildElementsByTagName($element, 'caption');
if (count($captionElts) > 0) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($captionElts[0]);
$component->setCaption($marshaller->unmarshall($captionElts[0]));
}
$colElts = $this->getChildElementsByTagName($element, 'col');
if (count($colElts) > 0) {
$cols = new ColCollection();
foreach ($colElts as $c) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($c);
$cols[] = $marshaller->unmarshall($c);
}
$component->setCols($cols);
}
$colgroupElts = $this->getChildElementsByTagName($element, 'colgroup');
if (count($colgroupElts) > 0) {
$colgroups = new ColgroupCollection();
foreach ($colgroupElts as $c) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($c);
$colgroups[] = $marshaller->unmarshall($c);
}
$component->setColgroups($colgroups);
}
$theadElts = $this->getChildElementsByTagName($element, 'thead');
if (count($theadElts) > 0) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($theadElts[0]);
$component->setThead($marshaller->unmarshall($theadElts[0]));
}
$tfootElts = $this->getChildElementsByTagName($element, 'tfoot');
if (count($tfootElts) > 0) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($tfootElts[0]);
$component->setTfoot($marshaller->unmarshall($tfootElts[0]));
}
$this->fillBodyElement($component, $element);
return $component;
} else {
$msg = "A 'table' element must contain at lease one 'tbody' element.";
throw new UnmarshallingException($msg, $element);
}
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"$",
"tbodyElts",
"=",
"$",
"this",
"->",
"getChildElementsByTagName",
"(",
"$",
"element",
",",
"'tbody'",
")",
";",
"if",
"(",
"count",
"(",
"$",
"tbodyElts",
")",
">",
"0",
")",
"{",
"$",
"tbodies",
"=",
"new",
"TbodyCollection",
"(",
")",
";",
"foreach",
"(",
"$",
"tbodyElts",
"as",
"$",
"tbodyElt",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"tbodyElt",
")",
";",
"$",
"tbodies",
"[",
"]",
"=",
"$",
"marshaller",
"->",
"unmarshall",
"(",
"$",
"tbodyElt",
")",
";",
"}",
"$",
"component",
"=",
"new",
"Table",
"(",
"$",
"tbodies",
")",
";",
"if",
"(",
"(",
"$",
"summary",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'summary'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"component",
"->",
"setSummary",
"(",
"$",
"summary",
")",
";",
"}",
"if",
"(",
"(",
"$",
"xmlBase",
"=",
"self",
"::",
"getXmlBase",
"(",
"$",
"element",
")",
")",
"!==",
"false",
")",
"{",
"$",
"component",
"->",
"setXmlBase",
"(",
"$",
"xmlBase",
")",
";",
"}",
"$",
"captionElts",
"=",
"$",
"this",
"->",
"getChildElementsByTagName",
"(",
"$",
"element",
",",
"'caption'",
")",
";",
"if",
"(",
"count",
"(",
"$",
"captionElts",
")",
">",
"0",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"captionElts",
"[",
"0",
"]",
")",
";",
"$",
"component",
"->",
"setCaption",
"(",
"$",
"marshaller",
"->",
"unmarshall",
"(",
"$",
"captionElts",
"[",
"0",
"]",
")",
")",
";",
"}",
"$",
"colElts",
"=",
"$",
"this",
"->",
"getChildElementsByTagName",
"(",
"$",
"element",
",",
"'col'",
")",
";",
"if",
"(",
"count",
"(",
"$",
"colElts",
")",
">",
"0",
")",
"{",
"$",
"cols",
"=",
"new",
"ColCollection",
"(",
")",
";",
"foreach",
"(",
"$",
"colElts",
"as",
"$",
"c",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"c",
")",
";",
"$",
"cols",
"[",
"]",
"=",
"$",
"marshaller",
"->",
"unmarshall",
"(",
"$",
"c",
")",
";",
"}",
"$",
"component",
"->",
"setCols",
"(",
"$",
"cols",
")",
";",
"}",
"$",
"colgroupElts",
"=",
"$",
"this",
"->",
"getChildElementsByTagName",
"(",
"$",
"element",
",",
"'colgroup'",
")",
";",
"if",
"(",
"count",
"(",
"$",
"colgroupElts",
")",
">",
"0",
")",
"{",
"$",
"colgroups",
"=",
"new",
"ColgroupCollection",
"(",
")",
";",
"foreach",
"(",
"$",
"colgroupElts",
"as",
"$",
"c",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"c",
")",
";",
"$",
"colgroups",
"[",
"]",
"=",
"$",
"marshaller",
"->",
"unmarshall",
"(",
"$",
"c",
")",
";",
"}",
"$",
"component",
"->",
"setColgroups",
"(",
"$",
"colgroups",
")",
";",
"}",
"$",
"theadElts",
"=",
"$",
"this",
"->",
"getChildElementsByTagName",
"(",
"$",
"element",
",",
"'thead'",
")",
";",
"if",
"(",
"count",
"(",
"$",
"theadElts",
")",
">",
"0",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"theadElts",
"[",
"0",
"]",
")",
";",
"$",
"component",
"->",
"setThead",
"(",
"$",
"marshaller",
"->",
"unmarshall",
"(",
"$",
"theadElts",
"[",
"0",
"]",
")",
")",
";",
"}",
"$",
"tfootElts",
"=",
"$",
"this",
"->",
"getChildElementsByTagName",
"(",
"$",
"element",
",",
"'tfoot'",
")",
";",
"if",
"(",
"count",
"(",
"$",
"tfootElts",
")",
">",
"0",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"tfootElts",
"[",
"0",
"]",
")",
";",
"$",
"component",
"->",
"setTfoot",
"(",
"$",
"marshaller",
"->",
"unmarshall",
"(",
"$",
"tfootElts",
"[",
"0",
"]",
")",
")",
";",
"}",
"$",
"this",
"->",
"fillBodyElement",
"(",
"$",
"component",
",",
"$",
"element",
")",
";",
"return",
"$",
"component",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"A 'table' element must contain at lease one 'tbody' element.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}"
] | Unmarshall a DOMElement object corresponding to an XHTML table element.
@param \DOMElement $element A DOMElement object.
@return \qtism\data\QtiComponent A Table object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException | [
"Unmarshall",
"a",
"DOMElement",
"object",
"corresponding",
"to",
"an",
"XHTML",
"table",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/TableMarshaller.php#L110-L178 |
oat-sa/qti-sdk | src/qtism/common/utils/Exception.php | Exception.formatMessage | static public function formatMessage(\Exception $e, $withClassName = true)
{
$returnValue = '';
do {
$className = get_class($e);
$message = $e->getMessage();
$returnValue .= ($withClassName === true) ? "[${className}] ${message}" : $message;
if ($e = $e->getPrevious()) {
$returnValue .= "\nCaused by:\n";
}
} while ($e);
return $returnValue;
} | php | static public function formatMessage(\Exception $e, $withClassName = true)
{
$returnValue = '';
do {
$className = get_class($e);
$message = $e->getMessage();
$returnValue .= ($withClassName === true) ? "[${className}] ${message}" : $message;
if ($e = $e->getPrevious()) {
$returnValue .= "\nCaused by:\n";
}
} while ($e);
return $returnValue;
} | [
"static",
"public",
"function",
"formatMessage",
"(",
"\\",
"Exception",
"$",
"e",
",",
"$",
"withClassName",
"=",
"true",
")",
"{",
"$",
"returnValue",
"=",
"''",
";",
"do",
"{",
"$",
"className",
"=",
"get_class",
"(",
"$",
"e",
")",
";",
"$",
"message",
"=",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"$",
"returnValue",
".=",
"(",
"$",
"withClassName",
"===",
"true",
")",
"?",
"\"[${className}] ${message}\"",
":",
"$",
"message",
";",
"if",
"(",
"$",
"e",
"=",
"$",
"e",
"->",
"getPrevious",
"(",
")",
")",
"{",
"$",
"returnValue",
".=",
"\"\\nCaused by:\\n\"",
";",
"}",
"}",
"while",
"(",
"$",
"e",
")",
";",
"return",
"$",
"returnValue",
";",
"}"
] | Format an Exception message.
This method will format an exception message using the following scheme:
[CLASSNAME] MESSAGE
If the Exception contains previous exceptions, the following scheme will be used:
[CLASSNAME] MESSAGE
Caused by:
[CLASSNAME] MESSAGE
...
@param \Exception $e A PHP Exception object.
@param true $withClassName Whether to show the Exception class name. | [
"Format",
"an",
"Exception",
"message",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/utils/Exception.php#L49-L64 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/ValueMarshaller.php | ValueMarshaller.marshall | protected function marshall(QtiComponent $component)
{
$element = static::getDOMCradle()->createElement($component->getQtiClassName());
$fieldIdentifer = $component->getFieldIdentifier();
$baseType = $component->getBaseType();
self::setDOMElementValue($element, $component->getValue());
if (!empty($fieldIdentifer)) {
$this->setDOMElementAttribute($element, 'fieldIdentifier', $fieldIdentifer);
}
if ($component->isPartOfRecord() && $baseType >= 0) {
$this->setDOMElementAttribute($element, 'baseType', BaseType::getNameByConstant($baseType));
}
return $element;
} | php | protected function marshall(QtiComponent $component)
{
$element = static::getDOMCradle()->createElement($component->getQtiClassName());
$fieldIdentifer = $component->getFieldIdentifier();
$baseType = $component->getBaseType();
self::setDOMElementValue($element, $component->getValue());
if (!empty($fieldIdentifer)) {
$this->setDOMElementAttribute($element, 'fieldIdentifier', $fieldIdentifer);
}
if ($component->isPartOfRecord() && $baseType >= 0) {
$this->setDOMElementAttribute($element, 'baseType', BaseType::getNameByConstant($baseType));
}
return $element;
} | [
"protected",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"$",
"element",
"=",
"static",
"::",
"getDOMCradle",
"(",
")",
"->",
"createElement",
"(",
"$",
"component",
"->",
"getQtiClassName",
"(",
")",
")",
";",
"$",
"fieldIdentifer",
"=",
"$",
"component",
"->",
"getFieldIdentifier",
"(",
")",
";",
"$",
"baseType",
"=",
"$",
"component",
"->",
"getBaseType",
"(",
")",
";",
"self",
"::",
"setDOMElementValue",
"(",
"$",
"element",
",",
"$",
"component",
"->",
"getValue",
"(",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"fieldIdentifer",
")",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'fieldIdentifier'",
",",
"$",
"fieldIdentifer",
")",
";",
"}",
"if",
"(",
"$",
"component",
"->",
"isPartOfRecord",
"(",
")",
"&&",
"$",
"baseType",
">=",
"0",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'baseType'",
",",
"BaseType",
"::",
"getNameByConstant",
"(",
"$",
"baseType",
")",
")",
";",
"}",
"return",
"$",
"element",
";",
"}"
] | Marshall a Value object into a DOMElement object.
@param \qtism\data\QtiComponent $component A Value object.
@return \DOMElement The according DOMElement object. | [
"Marshall",
"a",
"Value",
"object",
"into",
"a",
"DOMElement",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/ValueMarshaller.php#L95-L113 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/ValueMarshaller.php | ValueMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
$object = null;
if (($baseType = $this->getDOMElementAttributeAs($element, 'baseType', 'string')) !== null) {
// baseType attribute is set -> part of a record.
$baseTypeCst = BaseType::getConstantByName($baseType);
if ($baseTypeCst !== false) {
$object = new Value(Utils::stringToDatatype(trim($element->nodeValue), $baseTypeCst), $baseTypeCst);
$object->setPartOfRecord(true);
} else {
$msg = "The 'baseType' attribute value ('${value}') is not a valid QTI baseType in element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} else {
// baseType attribute not set -> not part of a record.
$nodeValue = trim($element->nodeValue);
if ($nodeValue !== '') {
// Try to use the marshaller as parametric to know how to unserialize the value.
if ($this->getBaseType() != -1) {
$object = new Value(Utils::stringToDatatype($nodeValue, $this->getBaseType()), $this->getBaseType());
} else {
// value used as plain string (at your own risks).
$object = new Value($nodeValue);
}
} else {
$msg = "The element '" . $element->localName . "' has no value.";
throw new UnmarshallingException($msg, $element);
}
}
if (($value = $this->getDOMElementAttributeAs($element, 'fieldIdentifier', 'string')) !== null) {
$object->setFieldIdentifier($value);
}
return $object;
} | php | protected function unmarshall(DOMElement $element)
{
$object = null;
if (($baseType = $this->getDOMElementAttributeAs($element, 'baseType', 'string')) !== null) {
// baseType attribute is set -> part of a record.
$baseTypeCst = BaseType::getConstantByName($baseType);
if ($baseTypeCst !== false) {
$object = new Value(Utils::stringToDatatype(trim($element->nodeValue), $baseTypeCst), $baseTypeCst);
$object->setPartOfRecord(true);
} else {
$msg = "The 'baseType' attribute value ('${value}') is not a valid QTI baseType in element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} else {
// baseType attribute not set -> not part of a record.
$nodeValue = trim($element->nodeValue);
if ($nodeValue !== '') {
// Try to use the marshaller as parametric to know how to unserialize the value.
if ($this->getBaseType() != -1) {
$object = new Value(Utils::stringToDatatype($nodeValue, $this->getBaseType()), $this->getBaseType());
} else {
// value used as plain string (at your own risks).
$object = new Value($nodeValue);
}
} else {
$msg = "The element '" . $element->localName . "' has no value.";
throw new UnmarshallingException($msg, $element);
}
}
if (($value = $this->getDOMElementAttributeAs($element, 'fieldIdentifier', 'string')) !== null) {
$object->setFieldIdentifier($value);
}
return $object;
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"$",
"object",
"=",
"null",
";",
"if",
"(",
"(",
"$",
"baseType",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'baseType'",
",",
"'string'",
")",
")",
"!==",
"null",
")",
"{",
"// baseType attribute is set -> part of a record.",
"$",
"baseTypeCst",
"=",
"BaseType",
"::",
"getConstantByName",
"(",
"$",
"baseType",
")",
";",
"if",
"(",
"$",
"baseTypeCst",
"!==",
"false",
")",
"{",
"$",
"object",
"=",
"new",
"Value",
"(",
"Utils",
"::",
"stringToDatatype",
"(",
"trim",
"(",
"$",
"element",
"->",
"nodeValue",
")",
",",
"$",
"baseTypeCst",
")",
",",
"$",
"baseTypeCst",
")",
";",
"$",
"object",
"->",
"setPartOfRecord",
"(",
"true",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'baseType' attribute value ('${value}') is not a valid QTI baseType in element '\"",
".",
"$",
"element",
"->",
"localName",
".",
"\"'.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}",
"else",
"{",
"// baseType attribute not set -> not part of a record.",
"$",
"nodeValue",
"=",
"trim",
"(",
"$",
"element",
"->",
"nodeValue",
")",
";",
"if",
"(",
"$",
"nodeValue",
"!==",
"''",
")",
"{",
"// Try to use the marshaller as parametric to know how to unserialize the value.",
"if",
"(",
"$",
"this",
"->",
"getBaseType",
"(",
")",
"!=",
"-",
"1",
")",
"{",
"$",
"object",
"=",
"new",
"Value",
"(",
"Utils",
"::",
"stringToDatatype",
"(",
"$",
"nodeValue",
",",
"$",
"this",
"->",
"getBaseType",
"(",
")",
")",
",",
"$",
"this",
"->",
"getBaseType",
"(",
")",
")",
";",
"}",
"else",
"{",
"// value used as plain string (at your own risks).",
"$",
"object",
"=",
"new",
"Value",
"(",
"$",
"nodeValue",
")",
";",
"}",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The element '\"",
".",
"$",
"element",
"->",
"localName",
".",
"\"' has no value.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}",
"if",
"(",
"(",
"$",
"value",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'fieldIdentifier'",
",",
"'string'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"object",
"->",
"setFieldIdentifier",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"object",
";",
"}"
] | Unmarshall a DOMElement object corresponding to a QTI Value element.
@param \DOMElement $element A DOMElement object.
@return \qtism\data\QtiComponent A Value object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException If the 'baseType' attribute is not a valid QTI baseType. | [
"Unmarshall",
"a",
"DOMElement",
"object",
"corresponding",
"to",
"a",
"QTI",
"Value",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/ValueMarshaller.php#L122-L159 |
oat-sa/qti-sdk | src/qtism/runtime/storage/binary/AbstractQtiBinaryStorage.php | AbstractQtiBinaryStorage.instantiate | public function instantiate($config = 0, $sessionId = '')
{
// If not provided, generate a session ID.
if (empty($sessionId) === true) {
$sessionId = uniqid('qtism', true);
}
try {
$session = $this->getManager()->createAssessmentTestSession($this->getAssessmentTest(), null, $config);
$session->setSessionId($sessionId);
return $session;
} catch (Exception $e) {
$msg = "An error occured while instantiating the given AssessmentTest.";
throw new StorageException($msg, StorageException::INSTANTIATION, $e);
}
} | php | public function instantiate($config = 0, $sessionId = '')
{
// If not provided, generate a session ID.
if (empty($sessionId) === true) {
$sessionId = uniqid('qtism', true);
}
try {
$session = $this->getManager()->createAssessmentTestSession($this->getAssessmentTest(), null, $config);
$session->setSessionId($sessionId);
return $session;
} catch (Exception $e) {
$msg = "An error occured while instantiating the given AssessmentTest.";
throw new StorageException($msg, StorageException::INSTANTIATION, $e);
}
} | [
"public",
"function",
"instantiate",
"(",
"$",
"config",
"=",
"0",
",",
"$",
"sessionId",
"=",
"''",
")",
"{",
"// If not provided, generate a session ID.",
"if",
"(",
"empty",
"(",
"$",
"sessionId",
")",
"===",
"true",
")",
"{",
"$",
"sessionId",
"=",
"uniqid",
"(",
"'qtism'",
",",
"true",
")",
";",
"}",
"try",
"{",
"$",
"session",
"=",
"$",
"this",
"->",
"getManager",
"(",
")",
"->",
"createAssessmentTestSession",
"(",
"$",
"this",
"->",
"getAssessmentTest",
"(",
")",
",",
"null",
",",
"$",
"config",
")",
";",
"$",
"session",
"->",
"setSessionId",
"(",
"$",
"sessionId",
")",
";",
"return",
"$",
"session",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while instantiating the given AssessmentTest.\"",
";",
"throw",
"new",
"StorageException",
"(",
"$",
"msg",
",",
"StorageException",
"::",
"INSTANTIATION",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Instantiate a new AssessmentTestSession.
@param integer $config (optional) The configuration to be taken into account for the instantiated AssessmentTestSession object.
@param string $sessionId An session ID. If not provided, a new session ID will be generated and given to the AssessmentTestSession.
@return \qtism\runtime\tests\AssessmentTestSession An AssessmentTestSession object. | [
"Instantiate",
"a",
"new",
"AssessmentTestSession",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/storage/binary/AbstractQtiBinaryStorage.php#L96-L112 |
oat-sa/qti-sdk | src/qtism/runtime/storage/binary/AbstractQtiBinaryStorage.php | AbstractQtiBinaryStorage.persist | public function persist(AssessmentTestSession $assessmentTestSession)
{
try {
$stream = new MemoryStream();
$stream->open();
$access = $this->createBinaryStreamAccess($stream);
// -- Deal with intrinsic values of the Test Session.
$access->writeTinyInt($assessmentTestSession->getState());
// Write the current position in the route.
$route = $assessmentTestSession->getRoute();
$access->writeTinyInt($route->getPosition());
// persist time reference.
$timeReference = $assessmentTestSession->getTimeReference();
if (is_null($timeReference) === true) {
$access->writeBoolean(false);
} else {
$access->writeBoolean(true);
$access->writeDateTime($timeReference);
}
// persist visited testPart identifiers.
$visitedTestPartIdentifiers = $assessmentTestSession->getVisitedTestPartIdentifiers();
$access->writeTinyInt(count($visitedTestPartIdentifiers));
foreach ($visitedTestPartIdentifiers as $visitedTestPartIdentifier) {
$access->writeString($visitedTestPartIdentifier);
}
// persist path.
$access->writePath($assessmentTestSession->getPath());
// -- Persist configuration
$access->writeShort($assessmentTestSession->getConfig());
// -- Persist the Route of the AssessmentTestSession and the related item sessions.
$access->writeTinyInt($route->count());
$itemSessionStore = $assessmentTestSession->getAssessmentItemSessionStore();
$pendingResponseStore = $assessmentTestSession->getPendingResponseStore();
$oldRoutePosition = $route->getPosition();
$seeker = $this->getSeeker();
foreach ($route as $routeItem) {
$item = $routeItem->getAssessmentItemRef();
$occurence = $routeItem->getOccurence();
// Deal with RouteItem
$access->writeRouteItem($seeker, $routeItem);
// Deal with ItemSession related to the previously written RouteItem.
try {
$itemSession = $itemSessionStore->getAssessmentItemSession($item, $occurence);
$access->writeBoolean(true);
$access->writeAssessmentItemSession($seeker, $itemSession);
// Deal with last occurence update.
$access->writeBoolean($assessmentTestSession->isLastOccurenceUpdate($item, $occurence));
// Deal with PendingResponses
if (($pendingResponses = $pendingResponseStore->getPendingResponses($item, $occurence)) !== false) {
$access->writeBoolean(true);
$access->writePendingResponses($seeker, $pendingResponses);
} else {
$access->writeBoolean(false);
}
}
catch (OutOfBoundsException $e) {
$access->writeBoolean(false);
// No assessmentItemSession for this route item.
continue;
}
}
$route->setPosition($oldRoutePosition);
// Persist the test-level global scope.
foreach ($assessmentTestSession->getKeys() as $outcomeIdentifier) {
$outcomeVariable = $assessmentTestSession->getVariable($outcomeIdentifier);
$access->writeVariableValue($outcomeVariable);
}
$durationStore = $assessmentTestSession->getDurationStore();
$access->writeShort(count($durationStore));
foreach ($durationStore->getKeys() as $k) {
$access->writeString($k);
$access->writeVariableValue($durationStore->getVariable($k));
}
$this->persistStream($assessmentTestSession, $stream);
$stream->close();
} catch (Exception $e) {
$sessionId = $assessmentTestSession->getSessionId();
$msg = "An error occured while persisting AssessmentTestSession with ID '${sessionId}': " . $e->getMessage();
throw new StorageException($msg, StorageException::PERSISTENCE, $e);
}
} | php | public function persist(AssessmentTestSession $assessmentTestSession)
{
try {
$stream = new MemoryStream();
$stream->open();
$access = $this->createBinaryStreamAccess($stream);
// -- Deal with intrinsic values of the Test Session.
$access->writeTinyInt($assessmentTestSession->getState());
// Write the current position in the route.
$route = $assessmentTestSession->getRoute();
$access->writeTinyInt($route->getPosition());
// persist time reference.
$timeReference = $assessmentTestSession->getTimeReference();
if (is_null($timeReference) === true) {
$access->writeBoolean(false);
} else {
$access->writeBoolean(true);
$access->writeDateTime($timeReference);
}
// persist visited testPart identifiers.
$visitedTestPartIdentifiers = $assessmentTestSession->getVisitedTestPartIdentifiers();
$access->writeTinyInt(count($visitedTestPartIdentifiers));
foreach ($visitedTestPartIdentifiers as $visitedTestPartIdentifier) {
$access->writeString($visitedTestPartIdentifier);
}
// persist path.
$access->writePath($assessmentTestSession->getPath());
// -- Persist configuration
$access->writeShort($assessmentTestSession->getConfig());
// -- Persist the Route of the AssessmentTestSession and the related item sessions.
$access->writeTinyInt($route->count());
$itemSessionStore = $assessmentTestSession->getAssessmentItemSessionStore();
$pendingResponseStore = $assessmentTestSession->getPendingResponseStore();
$oldRoutePosition = $route->getPosition();
$seeker = $this->getSeeker();
foreach ($route as $routeItem) {
$item = $routeItem->getAssessmentItemRef();
$occurence = $routeItem->getOccurence();
// Deal with RouteItem
$access->writeRouteItem($seeker, $routeItem);
// Deal with ItemSession related to the previously written RouteItem.
try {
$itemSession = $itemSessionStore->getAssessmentItemSession($item, $occurence);
$access->writeBoolean(true);
$access->writeAssessmentItemSession($seeker, $itemSession);
// Deal with last occurence update.
$access->writeBoolean($assessmentTestSession->isLastOccurenceUpdate($item, $occurence));
// Deal with PendingResponses
if (($pendingResponses = $pendingResponseStore->getPendingResponses($item, $occurence)) !== false) {
$access->writeBoolean(true);
$access->writePendingResponses($seeker, $pendingResponses);
} else {
$access->writeBoolean(false);
}
}
catch (OutOfBoundsException $e) {
$access->writeBoolean(false);
// No assessmentItemSession for this route item.
continue;
}
}
$route->setPosition($oldRoutePosition);
// Persist the test-level global scope.
foreach ($assessmentTestSession->getKeys() as $outcomeIdentifier) {
$outcomeVariable = $assessmentTestSession->getVariable($outcomeIdentifier);
$access->writeVariableValue($outcomeVariable);
}
$durationStore = $assessmentTestSession->getDurationStore();
$access->writeShort(count($durationStore));
foreach ($durationStore->getKeys() as $k) {
$access->writeString($k);
$access->writeVariableValue($durationStore->getVariable($k));
}
$this->persistStream($assessmentTestSession, $stream);
$stream->close();
} catch (Exception $e) {
$sessionId = $assessmentTestSession->getSessionId();
$msg = "An error occured while persisting AssessmentTestSession with ID '${sessionId}': " . $e->getMessage();
throw new StorageException($msg, StorageException::PERSISTENCE, $e);
}
} | [
"public",
"function",
"persist",
"(",
"AssessmentTestSession",
"$",
"assessmentTestSession",
")",
"{",
"try",
"{",
"$",
"stream",
"=",
"new",
"MemoryStream",
"(",
")",
";",
"$",
"stream",
"->",
"open",
"(",
")",
";",
"$",
"access",
"=",
"$",
"this",
"->",
"createBinaryStreamAccess",
"(",
"$",
"stream",
")",
";",
"// -- Deal with intrinsic values of the Test Session.",
"$",
"access",
"->",
"writeTinyInt",
"(",
"$",
"assessmentTestSession",
"->",
"getState",
"(",
")",
")",
";",
"// Write the current position in the route.",
"$",
"route",
"=",
"$",
"assessmentTestSession",
"->",
"getRoute",
"(",
")",
";",
"$",
"access",
"->",
"writeTinyInt",
"(",
"$",
"route",
"->",
"getPosition",
"(",
")",
")",
";",
"// persist time reference.",
"$",
"timeReference",
"=",
"$",
"assessmentTestSession",
"->",
"getTimeReference",
"(",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"timeReference",
")",
"===",
"true",
")",
"{",
"$",
"access",
"->",
"writeBoolean",
"(",
"false",
")",
";",
"}",
"else",
"{",
"$",
"access",
"->",
"writeBoolean",
"(",
"true",
")",
";",
"$",
"access",
"->",
"writeDateTime",
"(",
"$",
"timeReference",
")",
";",
"}",
"// persist visited testPart identifiers.",
"$",
"visitedTestPartIdentifiers",
"=",
"$",
"assessmentTestSession",
"->",
"getVisitedTestPartIdentifiers",
"(",
")",
";",
"$",
"access",
"->",
"writeTinyInt",
"(",
"count",
"(",
"$",
"visitedTestPartIdentifiers",
")",
")",
";",
"foreach",
"(",
"$",
"visitedTestPartIdentifiers",
"as",
"$",
"visitedTestPartIdentifier",
")",
"{",
"$",
"access",
"->",
"writeString",
"(",
"$",
"visitedTestPartIdentifier",
")",
";",
"}",
"// persist path.",
"$",
"access",
"->",
"writePath",
"(",
"$",
"assessmentTestSession",
"->",
"getPath",
"(",
")",
")",
";",
"// -- Persist configuration",
"$",
"access",
"->",
"writeShort",
"(",
"$",
"assessmentTestSession",
"->",
"getConfig",
"(",
")",
")",
";",
"// -- Persist the Route of the AssessmentTestSession and the related item sessions.",
"$",
"access",
"->",
"writeTinyInt",
"(",
"$",
"route",
"->",
"count",
"(",
")",
")",
";",
"$",
"itemSessionStore",
"=",
"$",
"assessmentTestSession",
"->",
"getAssessmentItemSessionStore",
"(",
")",
";",
"$",
"pendingResponseStore",
"=",
"$",
"assessmentTestSession",
"->",
"getPendingResponseStore",
"(",
")",
";",
"$",
"oldRoutePosition",
"=",
"$",
"route",
"->",
"getPosition",
"(",
")",
";",
"$",
"seeker",
"=",
"$",
"this",
"->",
"getSeeker",
"(",
")",
";",
"foreach",
"(",
"$",
"route",
"as",
"$",
"routeItem",
")",
"{",
"$",
"item",
"=",
"$",
"routeItem",
"->",
"getAssessmentItemRef",
"(",
")",
";",
"$",
"occurence",
"=",
"$",
"routeItem",
"->",
"getOccurence",
"(",
")",
";",
"// Deal with RouteItem",
"$",
"access",
"->",
"writeRouteItem",
"(",
"$",
"seeker",
",",
"$",
"routeItem",
")",
";",
"// Deal with ItemSession related to the previously written RouteItem.",
"try",
"{",
"$",
"itemSession",
"=",
"$",
"itemSessionStore",
"->",
"getAssessmentItemSession",
"(",
"$",
"item",
",",
"$",
"occurence",
")",
";",
"$",
"access",
"->",
"writeBoolean",
"(",
"true",
")",
";",
"$",
"access",
"->",
"writeAssessmentItemSession",
"(",
"$",
"seeker",
",",
"$",
"itemSession",
")",
";",
"// Deal with last occurence update.",
"$",
"access",
"->",
"writeBoolean",
"(",
"$",
"assessmentTestSession",
"->",
"isLastOccurenceUpdate",
"(",
"$",
"item",
",",
"$",
"occurence",
")",
")",
";",
"// Deal with PendingResponses",
"if",
"(",
"(",
"$",
"pendingResponses",
"=",
"$",
"pendingResponseStore",
"->",
"getPendingResponses",
"(",
"$",
"item",
",",
"$",
"occurence",
")",
")",
"!==",
"false",
")",
"{",
"$",
"access",
"->",
"writeBoolean",
"(",
"true",
")",
";",
"$",
"access",
"->",
"writePendingResponses",
"(",
"$",
"seeker",
",",
"$",
"pendingResponses",
")",
";",
"}",
"else",
"{",
"$",
"access",
"->",
"writeBoolean",
"(",
"false",
")",
";",
"}",
"}",
"catch",
"(",
"OutOfBoundsException",
"$",
"e",
")",
"{",
"$",
"access",
"->",
"writeBoolean",
"(",
"false",
")",
";",
"// No assessmentItemSession for this route item.",
"continue",
";",
"}",
"}",
"$",
"route",
"->",
"setPosition",
"(",
"$",
"oldRoutePosition",
")",
";",
"// Persist the test-level global scope.",
"foreach",
"(",
"$",
"assessmentTestSession",
"->",
"getKeys",
"(",
")",
"as",
"$",
"outcomeIdentifier",
")",
"{",
"$",
"outcomeVariable",
"=",
"$",
"assessmentTestSession",
"->",
"getVariable",
"(",
"$",
"outcomeIdentifier",
")",
";",
"$",
"access",
"->",
"writeVariableValue",
"(",
"$",
"outcomeVariable",
")",
";",
"}",
"$",
"durationStore",
"=",
"$",
"assessmentTestSession",
"->",
"getDurationStore",
"(",
")",
";",
"$",
"access",
"->",
"writeShort",
"(",
"count",
"(",
"$",
"durationStore",
")",
")",
";",
"foreach",
"(",
"$",
"durationStore",
"->",
"getKeys",
"(",
")",
"as",
"$",
"k",
")",
"{",
"$",
"access",
"->",
"writeString",
"(",
"$",
"k",
")",
";",
"$",
"access",
"->",
"writeVariableValue",
"(",
"$",
"durationStore",
"->",
"getVariable",
"(",
"$",
"k",
")",
")",
";",
"}",
"$",
"this",
"->",
"persistStream",
"(",
"$",
"assessmentTestSession",
",",
"$",
"stream",
")",
";",
"$",
"stream",
"->",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"sessionId",
"=",
"$",
"assessmentTestSession",
"->",
"getSessionId",
"(",
")",
";",
"$",
"msg",
"=",
"\"An error occured while persisting AssessmentTestSession with ID '${sessionId}': \"",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"throw",
"new",
"StorageException",
"(",
"$",
"msg",
",",
"StorageException",
"::",
"PERSISTENCE",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Persist an AssessmentTestSession into persistent binary data.
@param \qtism\runtime\tests\AssessmentTestSession $assessmentTestSession
@throws \qtism\runtime\storage\common\StorageException | [
"Persist",
"an",
"AssessmentTestSession",
"into",
"persistent",
"binary",
"data",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/storage/binary/AbstractQtiBinaryStorage.php#L120-L219 |
oat-sa/qti-sdk | src/qtism/runtime/storage/binary/AbstractQtiBinaryStorage.php | AbstractQtiBinaryStorage.retrieve | public function retrieve($sessionId)
{
try {
$stream = $this->getRetrievalStream($sessionId);
$stream->open();
$access = $this->createBinaryStreamAccess($stream);
// -- Deal with intrinsic values of the Test Session.
$assessmentTestSessionState = $access->readTinyInt();
$currentPosition = $access->readTinyInt();
if ($access->readBoolean() === true) {
$timeReference = $access->readDateTime();
} else {
$timeReference = null;
}
$visitedTestPartIdentifiers = array();
$visitedTestPartIdentifiersCount = $access->readTinyInt();
for ($i = 0; $i < $visitedTestPartIdentifiersCount; $i++) {
$visitedTestPartIdentifiers[] = $access->readString();
}
$path = $access->readPath();
// -- Session configuration.
$config = $access->readShort();
// Build the route and the item sessions.
$route = new Route();
$lastOccurenceUpdate = new SplObjectStorage();
$itemSessionStore = new AssessmentItemSessionStore();
$pendingResponseStore = new PendingResponseStore();
$routeCount = $access->readTinyInt();
// Create the item session factory that will be used to instantiate
// new item sessions.
$seeker = $this->getSeeker();
for ($i = 0; $i < $routeCount; $i++) {
$routeItem = $access->readRouteItem($seeker);
$route->addRouteItemObject($routeItem);
// An already instantiated session for this route item?
if ($access->readBoolean() === true) {
$itemSession = $access->readAssessmentItemSession($this->getManager(), $seeker);
// last-update
if ($access->readBoolean() === true) {
$lastOccurenceUpdate[$routeItem->getAssessmentItemRef()] = $routeItem->getOccurence();
}
// pending-responses
if ($access->readBoolean() === true) {
$pendingResponseStore->addPendingResponses($access->readPendingResponses($seeker));
}
$itemSessionStore->addAssessmentItemSession($itemSession, $routeItem->getOccurence());
}
}
$route->setPosition($currentPosition);
$manager = $this->getManager();
$assessmentTestSession = $manager->createAssessmentTestSession($this->getAssessmentTest(), $route, $config);
$assessmentTestSession->setAssessmentItemSessionStore($itemSessionStore);
$assessmentTestSession->setSessionId($sessionId);
$assessmentTestSession->setState($assessmentTestSessionState);
$assessmentTestSession->setLastOccurenceUpdate($lastOccurenceUpdate);
$assessmentTestSession->setPendingResponseStore($pendingResponseStore);
$assessmentTestSession->setTimeReference($timeReference);
$assessmentTestSession->setVisitedTestPartIdentifiers($visitedTestPartIdentifiers);
$assessmentTestSession->setPath($path);
// Build the test-level global scope, composed of Outcome Variables.
foreach ($this->getAssessmentTest()->getOutcomeDeclarations() as $outcomeDeclaration) {
$outcomeVariable = OutcomeVariable::createFromDataModel($outcomeDeclaration);
$access->readVariableValue($outcomeVariable);
$assessmentTestSession->setVariable($outcomeVariable);
}
// Build the duration store.
$durationStore = new DurationStore();
$durationCount = $access->readShort();
for ($i = 0; $i < $durationCount; $i++) {
$varName = $access->readString();
$durationVariable = new OutcomeVariable($varName, Cardinality::SINGLE, BaseType::DURATION);
$access->readVariableValue($durationVariable);
$durationStore->setVariable($durationVariable);
}
$assessmentTestSession->setDurationStore($durationStore);
$stream->close();
return $assessmentTestSession;
} catch (Exception $e) {
$msg = "An error occured while retrieving AssessmentTestSession. " . $e->getMessage();
throw new StorageException($msg, StorageException::RETRIEVAL, $e);
}
} | php | public function retrieve($sessionId)
{
try {
$stream = $this->getRetrievalStream($sessionId);
$stream->open();
$access = $this->createBinaryStreamAccess($stream);
// -- Deal with intrinsic values of the Test Session.
$assessmentTestSessionState = $access->readTinyInt();
$currentPosition = $access->readTinyInt();
if ($access->readBoolean() === true) {
$timeReference = $access->readDateTime();
} else {
$timeReference = null;
}
$visitedTestPartIdentifiers = array();
$visitedTestPartIdentifiersCount = $access->readTinyInt();
for ($i = 0; $i < $visitedTestPartIdentifiersCount; $i++) {
$visitedTestPartIdentifiers[] = $access->readString();
}
$path = $access->readPath();
// -- Session configuration.
$config = $access->readShort();
// Build the route and the item sessions.
$route = new Route();
$lastOccurenceUpdate = new SplObjectStorage();
$itemSessionStore = new AssessmentItemSessionStore();
$pendingResponseStore = new PendingResponseStore();
$routeCount = $access->readTinyInt();
// Create the item session factory that will be used to instantiate
// new item sessions.
$seeker = $this->getSeeker();
for ($i = 0; $i < $routeCount; $i++) {
$routeItem = $access->readRouteItem($seeker);
$route->addRouteItemObject($routeItem);
// An already instantiated session for this route item?
if ($access->readBoolean() === true) {
$itemSession = $access->readAssessmentItemSession($this->getManager(), $seeker);
// last-update
if ($access->readBoolean() === true) {
$lastOccurenceUpdate[$routeItem->getAssessmentItemRef()] = $routeItem->getOccurence();
}
// pending-responses
if ($access->readBoolean() === true) {
$pendingResponseStore->addPendingResponses($access->readPendingResponses($seeker));
}
$itemSessionStore->addAssessmentItemSession($itemSession, $routeItem->getOccurence());
}
}
$route->setPosition($currentPosition);
$manager = $this->getManager();
$assessmentTestSession = $manager->createAssessmentTestSession($this->getAssessmentTest(), $route, $config);
$assessmentTestSession->setAssessmentItemSessionStore($itemSessionStore);
$assessmentTestSession->setSessionId($sessionId);
$assessmentTestSession->setState($assessmentTestSessionState);
$assessmentTestSession->setLastOccurenceUpdate($lastOccurenceUpdate);
$assessmentTestSession->setPendingResponseStore($pendingResponseStore);
$assessmentTestSession->setTimeReference($timeReference);
$assessmentTestSession->setVisitedTestPartIdentifiers($visitedTestPartIdentifiers);
$assessmentTestSession->setPath($path);
// Build the test-level global scope, composed of Outcome Variables.
foreach ($this->getAssessmentTest()->getOutcomeDeclarations() as $outcomeDeclaration) {
$outcomeVariable = OutcomeVariable::createFromDataModel($outcomeDeclaration);
$access->readVariableValue($outcomeVariable);
$assessmentTestSession->setVariable($outcomeVariable);
}
// Build the duration store.
$durationStore = new DurationStore();
$durationCount = $access->readShort();
for ($i = 0; $i < $durationCount; $i++) {
$varName = $access->readString();
$durationVariable = new OutcomeVariable($varName, Cardinality::SINGLE, BaseType::DURATION);
$access->readVariableValue($durationVariable);
$durationStore->setVariable($durationVariable);
}
$assessmentTestSession->setDurationStore($durationStore);
$stream->close();
return $assessmentTestSession;
} catch (Exception $e) {
$msg = "An error occured while retrieving AssessmentTestSession. " . $e->getMessage();
throw new StorageException($msg, StorageException::RETRIEVAL, $e);
}
} | [
"public",
"function",
"retrieve",
"(",
"$",
"sessionId",
")",
"{",
"try",
"{",
"$",
"stream",
"=",
"$",
"this",
"->",
"getRetrievalStream",
"(",
"$",
"sessionId",
")",
";",
"$",
"stream",
"->",
"open",
"(",
")",
";",
"$",
"access",
"=",
"$",
"this",
"->",
"createBinaryStreamAccess",
"(",
"$",
"stream",
")",
";",
"// -- Deal with intrinsic values of the Test Session.",
"$",
"assessmentTestSessionState",
"=",
"$",
"access",
"->",
"readTinyInt",
"(",
")",
";",
"$",
"currentPosition",
"=",
"$",
"access",
"->",
"readTinyInt",
"(",
")",
";",
"if",
"(",
"$",
"access",
"->",
"readBoolean",
"(",
")",
"===",
"true",
")",
"{",
"$",
"timeReference",
"=",
"$",
"access",
"->",
"readDateTime",
"(",
")",
";",
"}",
"else",
"{",
"$",
"timeReference",
"=",
"null",
";",
"}",
"$",
"visitedTestPartIdentifiers",
"=",
"array",
"(",
")",
";",
"$",
"visitedTestPartIdentifiersCount",
"=",
"$",
"access",
"->",
"readTinyInt",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"visitedTestPartIdentifiersCount",
";",
"$",
"i",
"++",
")",
"{",
"$",
"visitedTestPartIdentifiers",
"[",
"]",
"=",
"$",
"access",
"->",
"readString",
"(",
")",
";",
"}",
"$",
"path",
"=",
"$",
"access",
"->",
"readPath",
"(",
")",
";",
"// -- Session configuration.",
"$",
"config",
"=",
"$",
"access",
"->",
"readShort",
"(",
")",
";",
"// Build the route and the item sessions.",
"$",
"route",
"=",
"new",
"Route",
"(",
")",
";",
"$",
"lastOccurenceUpdate",
"=",
"new",
"SplObjectStorage",
"(",
")",
";",
"$",
"itemSessionStore",
"=",
"new",
"AssessmentItemSessionStore",
"(",
")",
";",
"$",
"pendingResponseStore",
"=",
"new",
"PendingResponseStore",
"(",
")",
";",
"$",
"routeCount",
"=",
"$",
"access",
"->",
"readTinyInt",
"(",
")",
";",
"// Create the item session factory that will be used to instantiate",
"// new item sessions.",
"$",
"seeker",
"=",
"$",
"this",
"->",
"getSeeker",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"routeCount",
";",
"$",
"i",
"++",
")",
"{",
"$",
"routeItem",
"=",
"$",
"access",
"->",
"readRouteItem",
"(",
"$",
"seeker",
")",
";",
"$",
"route",
"->",
"addRouteItemObject",
"(",
"$",
"routeItem",
")",
";",
"// An already instantiated session for this route item?",
"if",
"(",
"$",
"access",
"->",
"readBoolean",
"(",
")",
"===",
"true",
")",
"{",
"$",
"itemSession",
"=",
"$",
"access",
"->",
"readAssessmentItemSession",
"(",
"$",
"this",
"->",
"getManager",
"(",
")",
",",
"$",
"seeker",
")",
";",
"// last-update",
"if",
"(",
"$",
"access",
"->",
"readBoolean",
"(",
")",
"===",
"true",
")",
"{",
"$",
"lastOccurenceUpdate",
"[",
"$",
"routeItem",
"->",
"getAssessmentItemRef",
"(",
")",
"]",
"=",
"$",
"routeItem",
"->",
"getOccurence",
"(",
")",
";",
"}",
"// pending-responses",
"if",
"(",
"$",
"access",
"->",
"readBoolean",
"(",
")",
"===",
"true",
")",
"{",
"$",
"pendingResponseStore",
"->",
"addPendingResponses",
"(",
"$",
"access",
"->",
"readPendingResponses",
"(",
"$",
"seeker",
")",
")",
";",
"}",
"$",
"itemSessionStore",
"->",
"addAssessmentItemSession",
"(",
"$",
"itemSession",
",",
"$",
"routeItem",
"->",
"getOccurence",
"(",
")",
")",
";",
"}",
"}",
"$",
"route",
"->",
"setPosition",
"(",
"$",
"currentPosition",
")",
";",
"$",
"manager",
"=",
"$",
"this",
"->",
"getManager",
"(",
")",
";",
"$",
"assessmentTestSession",
"=",
"$",
"manager",
"->",
"createAssessmentTestSession",
"(",
"$",
"this",
"->",
"getAssessmentTest",
"(",
")",
",",
"$",
"route",
",",
"$",
"config",
")",
";",
"$",
"assessmentTestSession",
"->",
"setAssessmentItemSessionStore",
"(",
"$",
"itemSessionStore",
")",
";",
"$",
"assessmentTestSession",
"->",
"setSessionId",
"(",
"$",
"sessionId",
")",
";",
"$",
"assessmentTestSession",
"->",
"setState",
"(",
"$",
"assessmentTestSessionState",
")",
";",
"$",
"assessmentTestSession",
"->",
"setLastOccurenceUpdate",
"(",
"$",
"lastOccurenceUpdate",
")",
";",
"$",
"assessmentTestSession",
"->",
"setPendingResponseStore",
"(",
"$",
"pendingResponseStore",
")",
";",
"$",
"assessmentTestSession",
"->",
"setTimeReference",
"(",
"$",
"timeReference",
")",
";",
"$",
"assessmentTestSession",
"->",
"setVisitedTestPartIdentifiers",
"(",
"$",
"visitedTestPartIdentifiers",
")",
";",
"$",
"assessmentTestSession",
"->",
"setPath",
"(",
"$",
"path",
")",
";",
"// Build the test-level global scope, composed of Outcome Variables.",
"foreach",
"(",
"$",
"this",
"->",
"getAssessmentTest",
"(",
")",
"->",
"getOutcomeDeclarations",
"(",
")",
"as",
"$",
"outcomeDeclaration",
")",
"{",
"$",
"outcomeVariable",
"=",
"OutcomeVariable",
"::",
"createFromDataModel",
"(",
"$",
"outcomeDeclaration",
")",
";",
"$",
"access",
"->",
"readVariableValue",
"(",
"$",
"outcomeVariable",
")",
";",
"$",
"assessmentTestSession",
"->",
"setVariable",
"(",
"$",
"outcomeVariable",
")",
";",
"}",
"// Build the duration store.",
"$",
"durationStore",
"=",
"new",
"DurationStore",
"(",
")",
";",
"$",
"durationCount",
"=",
"$",
"access",
"->",
"readShort",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"durationCount",
";",
"$",
"i",
"++",
")",
"{",
"$",
"varName",
"=",
"$",
"access",
"->",
"readString",
"(",
")",
";",
"$",
"durationVariable",
"=",
"new",
"OutcomeVariable",
"(",
"$",
"varName",
",",
"Cardinality",
"::",
"SINGLE",
",",
"BaseType",
"::",
"DURATION",
")",
";",
"$",
"access",
"->",
"readVariableValue",
"(",
"$",
"durationVariable",
")",
";",
"$",
"durationStore",
"->",
"setVariable",
"(",
"$",
"durationVariable",
")",
";",
"}",
"$",
"assessmentTestSession",
"->",
"setDurationStore",
"(",
"$",
"durationStore",
")",
";",
"$",
"stream",
"->",
"close",
"(",
")",
";",
"return",
"$",
"assessmentTestSession",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An error occured while retrieving AssessmentTestSession. \"",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"throw",
"new",
"StorageException",
"(",
"$",
"msg",
",",
"StorageException",
"::",
"RETRIEVAL",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Retrieve an AssessmentTestSession object from storage by $sessionId.
@param string $sessionId
@throws \qtism\runtime\storage\common\StorageException If the AssessmentTestSession could not be retrieved from persistent binary storage. | [
"Retrieve",
"an",
"AssessmentTestSession",
"object",
"from",
"storage",
"by",
"$sessionId",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/storage/binary/AbstractQtiBinaryStorage.php#L227-L328 |
oat-sa/qti-sdk | src/qtism/data/state/VariableMapping.php | VariableMapping.setSource | public function setSource($source)
{
if (Format::isIdentifier($source)) {
$this->source = $source;
} else {
$msg = "'${source}' is not a valid QTI identifier.";
throw new InvalidArgumentException($msg);
}
} | php | public function setSource($source)
{
if (Format::isIdentifier($source)) {
$this->source = $source;
} else {
$msg = "'${source}' is not a valid QTI identifier.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setSource",
"(",
"$",
"source",
")",
"{",
"if",
"(",
"Format",
"::",
"isIdentifier",
"(",
"$",
"source",
")",
")",
"{",
"$",
"this",
"->",
"source",
"=",
"$",
"source",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"'${source}' is not a valid QTI identifier.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the source variable identifier.
@param string $source A valid QTI identifier.
@throws \InvalidArgumentException If $source is not a valid QTI identifier. | [
"Set",
"the",
"source",
"variable",
"identifier",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/state/VariableMapping.php#L88-L96 |
oat-sa/qti-sdk | src/qtism/data/state/VariableMapping.php | VariableMapping.setTarget | public function setTarget($target)
{
if (Format::isIdentifier($target)) {
$this->target = $target;
} else {
$msg = "'${target}' is not a valid QTI identifier.";
throw new InvalidArgumentException($msg);
}
} | php | public function setTarget($target)
{
if (Format::isIdentifier($target)) {
$this->target = $target;
} else {
$msg = "'${target}' is not a valid QTI identifier.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setTarget",
"(",
"$",
"target",
")",
"{",
"if",
"(",
"Format",
"::",
"isIdentifier",
"(",
"$",
"target",
")",
")",
"{",
"$",
"this",
"->",
"target",
"=",
"$",
"target",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"'${target}' is not a valid QTI identifier.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the target variable identifier.
@param string $target A valid QTI identifier.
@throws \InvalidArgumentException If $target is not a valid QTI identifier. | [
"Set",
"the",
"target",
"variable",
"identifier",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/state/VariableMapping.php#L114-L122 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/VariableMarshaller.php | VariableMarshaller.marshall | protected function marshall(QtiComponent $component)
{
$element = static::getDOMCradle()->createElement($component->getQtiClassName());
$this->setDOMElementAttribute($element, 'identifier', $component->getIdentifier());
$weightIdentifier = $component->getWeightIdentifier();
if (!empty($weightIdentifier)) {
$this->setDOMElementAttribute($element, 'weightIdentifier', $weightIdentifier);
}
return $element;
} | php | protected function marshall(QtiComponent $component)
{
$element = static::getDOMCradle()->createElement($component->getQtiClassName());
$this->setDOMElementAttribute($element, 'identifier', $component->getIdentifier());
$weightIdentifier = $component->getWeightIdentifier();
if (!empty($weightIdentifier)) {
$this->setDOMElementAttribute($element, 'weightIdentifier', $weightIdentifier);
}
return $element;
} | [
"protected",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"$",
"element",
"=",
"static",
"::",
"getDOMCradle",
"(",
")",
"->",
"createElement",
"(",
"$",
"component",
"->",
"getQtiClassName",
"(",
")",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'identifier'",
",",
"$",
"component",
"->",
"getIdentifier",
"(",
")",
")",
";",
"$",
"weightIdentifier",
"=",
"$",
"component",
"->",
"getWeightIdentifier",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"weightIdentifier",
")",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'weightIdentifier'",
",",
"$",
"weightIdentifier",
")",
";",
"}",
"return",
"$",
"element",
";",
"}"
] | Marshall a Variable object into a DOMElement object.
@param \qtism\data\QtiComponent $component A Variable object.
@return \DOMElement The according DOMElement object. | [
"Marshall",
"a",
"Variable",
"object",
"into",
"a",
"DOMElement",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/VariableMarshaller.php#L43-L55 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/VariableMarshaller.php | VariableMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
if (($identifier = $this->getDOMElementAttributeAs($element, 'identifier')) !== null) {
$object = new Variable($identifier);
if (($weightIdentifier = $this->getDOMElementAttributeAs($element, 'weightIdentifier')) !== null) {
$object->setWeightIdentifier($weightIdentifier);
}
return $object;
} else {
$msg = "The mandatory attribute 'identifier' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} | php | protected function unmarshall(DOMElement $element)
{
if (($identifier = $this->getDOMElementAttributeAs($element, 'identifier')) !== null) {
$object = new Variable($identifier);
if (($weightIdentifier = $this->getDOMElementAttributeAs($element, 'weightIdentifier')) !== null) {
$object->setWeightIdentifier($weightIdentifier);
}
return $object;
} else {
$msg = "The mandatory attribute 'identifier' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"if",
"(",
"(",
"$",
"identifier",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'identifier'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"object",
"=",
"new",
"Variable",
"(",
"$",
"identifier",
")",
";",
"if",
"(",
"(",
"$",
"weightIdentifier",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'weightIdentifier'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"object",
"->",
"setWeightIdentifier",
"(",
"$",
"weightIdentifier",
")",
";",
"}",
"return",
"$",
"object",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory attribute 'identifier' is missing from element '\"",
".",
"$",
"element",
"->",
"localName",
".",
"\"'.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}"
] | Unmarshall a DOMElement object corresponding to a QTI Variable element.
@param \DOMElement $element A DOMElement object.
@return \qtism\data\QtiComponent A Variable object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException If the mandatory attribute 'identifier' is not set in $element. | [
"Unmarshall",
"a",
"DOMElement",
"object",
"corresponding",
"to",
"a",
"QTI",
"Variable",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/VariableMarshaller.php#L64-L78 |
oat-sa/qti-sdk | src/qtism/runtime/rendering/qtipl/expressions/RandomIntegerQtiPLRenderer.php | RandomIntegerQtiPLRenderer.render | public function render($something)
{
$renderer = new QtiPLRenderer($this->getCRO());
$attributes = [];
$attributes['min'] = $something->getMin();
$attributes['max'] = $something->getMax();
if ($something->getStep() != 1) {
$attributes['step'] = $something->getStep();
}
return $something->getQtiClassName() . $renderer->writeAttributes($attributes)
. $renderer->writeChildElements();
} | php | public function render($something)
{
$renderer = new QtiPLRenderer($this->getCRO());
$attributes = [];
$attributes['min'] = $something->getMin();
$attributes['max'] = $something->getMax();
if ($something->getStep() != 1) {
$attributes['step'] = $something->getStep();
}
return $something->getQtiClassName() . $renderer->writeAttributes($attributes)
. $renderer->writeChildElements();
} | [
"public",
"function",
"render",
"(",
"$",
"something",
")",
"{",
"$",
"renderer",
"=",
"new",
"QtiPLRenderer",
"(",
"$",
"this",
"->",
"getCRO",
"(",
")",
")",
";",
"$",
"attributes",
"=",
"[",
"]",
";",
"$",
"attributes",
"[",
"'min'",
"]",
"=",
"$",
"something",
"->",
"getMin",
"(",
")",
";",
"$",
"attributes",
"[",
"'max'",
"]",
"=",
"$",
"something",
"->",
"getMax",
"(",
")",
";",
"if",
"(",
"$",
"something",
"->",
"getStep",
"(",
")",
"!=",
"1",
")",
"{",
"$",
"attributes",
"[",
"'step'",
"]",
"=",
"$",
"something",
"->",
"getStep",
"(",
")",
";",
"}",
"return",
"$",
"something",
"->",
"getQtiClassName",
"(",
")",
".",
"$",
"renderer",
"->",
"writeAttributes",
"(",
"$",
"attributes",
")",
".",
"$",
"renderer",
"->",
"writeChildElements",
"(",
")",
";",
"}"
] | 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/RandomIntegerQtiPLRenderer.php#L45-L59 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/StylesheetMarshaller.php | StylesheetMarshaller.marshall | protected function marshall(QtiComponent $component)
{
$element = static::getDOMCradle()->createElement($component->getQtiClassName());
$this->setDOMElementAttribute($element, 'href', $component->getHref());
$this->setDOMElementAttribute($element, 'media', $component->getMedia());
$this->setDOMElementAttribute($element, 'type', $component->getType());
if (($title = $component->getTitle()) != '') {
$this->setDOMElementAttribute($element, 'title', $component->getTitle());
}
return $element;
} | php | protected function marshall(QtiComponent $component)
{
$element = static::getDOMCradle()->createElement($component->getQtiClassName());
$this->setDOMElementAttribute($element, 'href', $component->getHref());
$this->setDOMElementAttribute($element, 'media', $component->getMedia());
$this->setDOMElementAttribute($element, 'type', $component->getType());
if (($title = $component->getTitle()) != '') {
$this->setDOMElementAttribute($element, 'title', $component->getTitle());
}
return $element;
} | [
"protected",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"$",
"element",
"=",
"static",
"::",
"getDOMCradle",
"(",
")",
"->",
"createElement",
"(",
"$",
"component",
"->",
"getQtiClassName",
"(",
")",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'href'",
",",
"$",
"component",
"->",
"getHref",
"(",
")",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'media'",
",",
"$",
"component",
"->",
"getMedia",
"(",
")",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'type'",
",",
"$",
"component",
"->",
"getType",
"(",
")",
")",
";",
"if",
"(",
"(",
"$",
"title",
"=",
"$",
"component",
"->",
"getTitle",
"(",
")",
")",
"!=",
"''",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'title'",
",",
"$",
"component",
"->",
"getTitle",
"(",
")",
")",
";",
"}",
"return",
"$",
"element",
";",
"}"
] | Marshall a Stylesheet object into a DOMElement object.
@param \qtism\data\QtiComponent $component A Stylesheet object.
@return \DOMElement The according DOMElement object. | [
"Marshall",
"a",
"Stylesheet",
"object",
"into",
"a",
"DOMElement",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/StylesheetMarshaller.php#L43-L56 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/StylesheetMarshaller.php | StylesheetMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
// href is a mandatory value, retrieve it first.
if (($value = $this->getDOMElementAttributeAs($element, 'href', 'string')) !== null) {
$object = new Stylesheet($value);
if (($value = $this->getDOMElementAttributeAs($element, 'type', 'string')) !== null) {
$object->setType($value);
}
if (($value = $this->getDOMElementAttributeAs($element, 'media', 'string')) !== null) {
$object->setMedia($value);
}
if (($value = $this->getDOMElementAttributeAs($element, 'title', 'string')) !== null) {
$object->setTitle($value);
}
} else {
$msg = "The mandatory attribute 'href' is missing.";
throw new UnmarshallingException($msg, $element);
}
return $object;
} | php | protected function unmarshall(DOMElement $element)
{
// href is a mandatory value, retrieve it first.
if (($value = $this->getDOMElementAttributeAs($element, 'href', 'string')) !== null) {
$object = new Stylesheet($value);
if (($value = $this->getDOMElementAttributeAs($element, 'type', 'string')) !== null) {
$object->setType($value);
}
if (($value = $this->getDOMElementAttributeAs($element, 'media', 'string')) !== null) {
$object->setMedia($value);
}
if (($value = $this->getDOMElementAttributeAs($element, 'title', 'string')) !== null) {
$object->setTitle($value);
}
} else {
$msg = "The mandatory attribute 'href' is missing.";
throw new UnmarshallingException($msg, $element);
}
return $object;
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"// href is a mandatory value, retrieve it first.",
"if",
"(",
"(",
"$",
"value",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'href'",
",",
"'string'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"object",
"=",
"new",
"Stylesheet",
"(",
"$",
"value",
")",
";",
"if",
"(",
"(",
"$",
"value",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'type'",
",",
"'string'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"object",
"->",
"setType",
"(",
"$",
"value",
")",
";",
"}",
"if",
"(",
"(",
"$",
"value",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'media'",
",",
"'string'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"object",
"->",
"setMedia",
"(",
"$",
"value",
")",
";",
"}",
"if",
"(",
"(",
"$",
"value",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'title'",
",",
"'string'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"object",
"->",
"setTitle",
"(",
"$",
"value",
")",
";",
"}",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory attribute 'href' is missing.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"return",
"$",
"object",
";",
"}"
] | Unmarshall a DOMElement object corresponding to a QTI stylesheet element.
@param \DOMElement $element A DOMElement object.
@return \qtism\data\QtiComponent A Stylesheet object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException If the mandatory attribute 'href' is missing from $element. | [
"Unmarshall",
"a",
"DOMElement",
"object",
"corresponding",
"to",
"a",
"QTI",
"stylesheet",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/StylesheetMarshaller.php#L65-L88 |
oat-sa/qti-sdk | src/qtism/data/rules/OutcomeIf.php | OutcomeIf.setOutcomeRules | public function setOutcomeRules(OutcomeRuleCollection $outcomeRules)
{
if (count($outcomeRules) > 0) {
$this->outcomeRules = $outcomeRules;
} else {
$msg = "An OutcomeIf object must be bound to at least one OutcomeRule.";
throw new InvalidArgumentException($msg);
}
} | php | public function setOutcomeRules(OutcomeRuleCollection $outcomeRules)
{
if (count($outcomeRules) > 0) {
$this->outcomeRules = $outcomeRules;
} else {
$msg = "An OutcomeIf object must be bound to at least one OutcomeRule.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setOutcomeRules",
"(",
"OutcomeRuleCollection",
"$",
"outcomeRules",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"outcomeRules",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"outcomeRules",
"=",
"$",
"outcomeRules",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"An OutcomeIf object must be bound to at least one OutcomeRule.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the OutcomeRule objects to be evaluated as sub expressions if the expression
evaluated with the If statement returns true.
@param \qtism\data\rules\OutcomeRuleCollection $outcomeRules A collection of OutcomeRule objects.
@throws \InvalidArgumentException If $outcomeRules is an empty collection. | [
"Set",
"the",
"OutcomeRule",
"objects",
"to",
"be",
"evaluated",
"as",
"sub",
"expressions",
"if",
"the",
"expression",
"evaluated",
"with",
"the",
"If",
"statement",
"returns",
"true",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/rules/OutcomeIf.php#L101-L109 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/DrawingInteractionMarshaller.php | DrawingInteractionMarshaller.marshall | protected function marshall(QtiComponent $component)
{
$element = $this->createElement($component);
$this->fillElement($element, $component);
$this->setDOMElementAttribute($element, 'responseIdentifier', $component->getResponseIdentifier());
if ($component->hasXmlBase() === true) {
self::setXmlBase($element, $component->getXmlBase());
}
if ($component->hasPrompt() === true) {
$element->appendChild($this->getMarshallerFactory()->createMarshaller($component->getPrompt())->marshall($component->getPrompt()));
}
$element->appendChild($this->getMarshallerFactory()->createMarshaller($component->getObject())->marshall($component->getObject()));
return $element;
} | php | protected function marshall(QtiComponent $component)
{
$element = $this->createElement($component);
$this->fillElement($element, $component);
$this->setDOMElementAttribute($element, 'responseIdentifier', $component->getResponseIdentifier());
if ($component->hasXmlBase() === true) {
self::setXmlBase($element, $component->getXmlBase());
}
if ($component->hasPrompt() === true) {
$element->appendChild($this->getMarshallerFactory()->createMarshaller($component->getPrompt())->marshall($component->getPrompt()));
}
$element->appendChild($this->getMarshallerFactory()->createMarshaller($component->getObject())->marshall($component->getObject()));
return $element;
} | [
"protected",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"$",
"element",
"=",
"$",
"this",
"->",
"createElement",
"(",
"$",
"component",
")",
";",
"$",
"this",
"->",
"fillElement",
"(",
"$",
"element",
",",
"$",
"component",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'responseIdentifier'",
",",
"$",
"component",
"->",
"getResponseIdentifier",
"(",
")",
")",
";",
"if",
"(",
"$",
"component",
"->",
"hasXmlBase",
"(",
")",
"===",
"true",
")",
"{",
"self",
"::",
"setXmlBase",
"(",
"$",
"element",
",",
"$",
"component",
"->",
"getXmlBase",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"component",
"->",
"hasPrompt",
"(",
")",
"===",
"true",
")",
"{",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"component",
"->",
"getPrompt",
"(",
")",
")",
"->",
"marshall",
"(",
"$",
"component",
"->",
"getPrompt",
"(",
")",
")",
")",
";",
"}",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"component",
"->",
"getObject",
"(",
")",
")",
"->",
"marshall",
"(",
"$",
"component",
"->",
"getObject",
"(",
")",
")",
")",
";",
"return",
"$",
"element",
";",
"}"
] | Marshall a DrawingInteraction object into a DOMElement object.
@param \qtism\data\QtiComponent $component A DrawingInteraction object.
@return \DOMElement The according DOMElement object.
@throws \qtism\data\storage\xml\marshalling\MarshallingException | [
"Marshall",
"a",
"DrawingInteraction",
"object",
"into",
"a",
"DOMElement",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/DrawingInteractionMarshaller.php#L44-L61 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/DrawingInteractionMarshaller.php | DrawingInteractionMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
if (($responseIdentifier = $this->getDOMElementAttributeAs($element, 'responseIdentifier')) !== null) {
$objectElts = $this->getChildElementsByTagName($element, 'object');
if (count($objectElts) > 0) {
$objectElt = $objectElts[0];
$object = $this->getMarshallerFactory()->createMarshaller($objectElt)->unmarshall($objectElt);
$component = new DrawingInteraction($responseIdentifier, $object);
$promptElts = $this->getChildElementsByTagName($element, 'prompt');
if (count($promptElts) > 0) {
$promptElt = $promptElts[0];
$prompt = $this->getMarshallerFactory()->createMarshaller($promptElt)->unmarshall($promptElt);
$component->setPrompt($prompt);
}
if (($xmlBase = self::getXmlBase($element)) !== false) {
$component->setXmlBase($xmlBase);
}
$this->fillBodyElement($component, $element);
return $component;
} else {
$msg = "A 'drawingInteraction' element must contain exactly one 'object' element, none given.";
throw new UnmarshallingException($msg, $element);
}
} else {
$msg = "The mandatory 'responseIdentifier' attribute is missing from the 'drawingInteraction' element.";
throw new UnmarshallingException($msg, $element);
}
} | php | protected function unmarshall(DOMElement $element)
{
if (($responseIdentifier = $this->getDOMElementAttributeAs($element, 'responseIdentifier')) !== null) {
$objectElts = $this->getChildElementsByTagName($element, 'object');
if (count($objectElts) > 0) {
$objectElt = $objectElts[0];
$object = $this->getMarshallerFactory()->createMarshaller($objectElt)->unmarshall($objectElt);
$component = new DrawingInteraction($responseIdentifier, $object);
$promptElts = $this->getChildElementsByTagName($element, 'prompt');
if (count($promptElts) > 0) {
$promptElt = $promptElts[0];
$prompt = $this->getMarshallerFactory()->createMarshaller($promptElt)->unmarshall($promptElt);
$component->setPrompt($prompt);
}
if (($xmlBase = self::getXmlBase($element)) !== false) {
$component->setXmlBase($xmlBase);
}
$this->fillBodyElement($component, $element);
return $component;
} else {
$msg = "A 'drawingInteraction' element must contain exactly one 'object' element, none given.";
throw new UnmarshallingException($msg, $element);
}
} else {
$msg = "The mandatory 'responseIdentifier' attribute is missing from the 'drawingInteraction' element.";
throw new UnmarshallingException($msg, $element);
}
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"if",
"(",
"(",
"$",
"responseIdentifier",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'responseIdentifier'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"objectElts",
"=",
"$",
"this",
"->",
"getChildElementsByTagName",
"(",
"$",
"element",
",",
"'object'",
")",
";",
"if",
"(",
"count",
"(",
"$",
"objectElts",
")",
">",
"0",
")",
"{",
"$",
"objectElt",
"=",
"$",
"objectElts",
"[",
"0",
"]",
";",
"$",
"object",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"objectElt",
")",
"->",
"unmarshall",
"(",
"$",
"objectElt",
")",
";",
"$",
"component",
"=",
"new",
"DrawingInteraction",
"(",
"$",
"responseIdentifier",
",",
"$",
"object",
")",
";",
"$",
"promptElts",
"=",
"$",
"this",
"->",
"getChildElementsByTagName",
"(",
"$",
"element",
",",
"'prompt'",
")",
";",
"if",
"(",
"count",
"(",
"$",
"promptElts",
")",
">",
"0",
")",
"{",
"$",
"promptElt",
"=",
"$",
"promptElts",
"[",
"0",
"]",
";",
"$",
"prompt",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"promptElt",
")",
"->",
"unmarshall",
"(",
"$",
"promptElt",
")",
";",
"$",
"component",
"->",
"setPrompt",
"(",
"$",
"prompt",
")",
";",
"}",
"if",
"(",
"(",
"$",
"xmlBase",
"=",
"self",
"::",
"getXmlBase",
"(",
"$",
"element",
")",
")",
"!==",
"false",
")",
"{",
"$",
"component",
"->",
"setXmlBase",
"(",
"$",
"xmlBase",
")",
";",
"}",
"$",
"this",
"->",
"fillBodyElement",
"(",
"$",
"component",
",",
"$",
"element",
")",
";",
"return",
"$",
"component",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"A 'drawingInteraction' element must contain exactly one 'object' element, none given.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory 'responseIdentifier' attribute is missing from the 'drawingInteraction' element.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}"
] | Unmarshall a DOMElement object corresponding to a DrawingInteraction element.
@param \DOMElement $element A DOMElement object.
@return \qtism\data\QtiComponent A DrawingInteraction object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException | [
"Unmarshall",
"a",
"DOMElement",
"object",
"corresponding",
"to",
"a",
"DrawingInteraction",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/DrawingInteractionMarshaller.php#L70-L103 |
oat-sa/qti-sdk | src/qtism/runtime/rendering/qtipl/expressions/VariableQtiPLRenderer.php | VariableQtiPLRenderer.render | public function render($something)
{
$renderer = new QtiPLRenderer($this->getCRO());
$attributes = [];
$attributes['identifier'] = "\"" . $something->getIdentifier() . "\"";
if ($something->getWeightIdentifier() != "") {
$attributes['weightIdentifier'] = "\"" . $something->getWeightIdentifier() . "\"";
}
return $something->getQtiClassName() . $renderer->writeAttributes($attributes)
. $renderer->writeChildElements();
} | php | public function render($something)
{
$renderer = new QtiPLRenderer($this->getCRO());
$attributes = [];
$attributes['identifier'] = "\"" . $something->getIdentifier() . "\"";
if ($something->getWeightIdentifier() != "") {
$attributes['weightIdentifier'] = "\"" . $something->getWeightIdentifier() . "\"";
}
return $something->getQtiClassName() . $renderer->writeAttributes($attributes)
. $renderer->writeChildElements();
} | [
"public",
"function",
"render",
"(",
"$",
"something",
")",
"{",
"$",
"renderer",
"=",
"new",
"QtiPLRenderer",
"(",
"$",
"this",
"->",
"getCRO",
"(",
")",
")",
";",
"$",
"attributes",
"=",
"[",
"]",
";",
"$",
"attributes",
"[",
"'identifier'",
"]",
"=",
"\"\\\"\"",
".",
"$",
"something",
"->",
"getIdentifier",
"(",
")",
".",
"\"\\\"\"",
";",
"if",
"(",
"$",
"something",
"->",
"getWeightIdentifier",
"(",
")",
"!=",
"\"\"",
")",
"{",
"$",
"attributes",
"[",
"'weightIdentifier'",
"]",
"=",
"\"\\\"\"",
".",
"$",
"something",
"->",
"getWeightIdentifier",
"(",
")",
".",
"\"\\\"\"",
";",
"}",
"return",
"$",
"something",
"->",
"getQtiClassName",
"(",
")",
".",
"$",
"renderer",
"->",
"writeAttributes",
"(",
"$",
"attributes",
")",
".",
"$",
"renderer",
"->",
"writeChildElements",
"(",
")",
";",
"}"
] | 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/VariableQtiPLRenderer.php#L45-L57 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/CorrectResponseMarshaller.php | CorrectResponseMarshaller.marshall | protected function marshall(QtiComponent $component)
{
$element = static::getDOMCradle()->createElement($component->getQtiClassName());
$interpretation = $component->getInterpretation();
if (!empty($interpretation)) {
$this->setDOMElementAttribute($element, 'interpretation', $interpretation);
}
// A CorrectResponse contains 1..* Value objects
foreach ($component->getValues() as $value) {
$valueMarshaller = $this->getMarshallerFactory()->createMarshaller($value, array($this->getBaseType()));
$valueElement = $valueMarshaller->marshall($value);
$element->appendChild($valueElement);
}
return $element;
} | php | protected function marshall(QtiComponent $component)
{
$element = static::getDOMCradle()->createElement($component->getQtiClassName());
$interpretation = $component->getInterpretation();
if (!empty($interpretation)) {
$this->setDOMElementAttribute($element, 'interpretation', $interpretation);
}
// A CorrectResponse contains 1..* Value objects
foreach ($component->getValues() as $value) {
$valueMarshaller = $this->getMarshallerFactory()->createMarshaller($value, array($this->getBaseType()));
$valueElement = $valueMarshaller->marshall($value);
$element->appendChild($valueElement);
}
return $element;
} | [
"protected",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"$",
"element",
"=",
"static",
"::",
"getDOMCradle",
"(",
")",
"->",
"createElement",
"(",
"$",
"component",
"->",
"getQtiClassName",
"(",
")",
")",
";",
"$",
"interpretation",
"=",
"$",
"component",
"->",
"getInterpretation",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"interpretation",
")",
")",
"{",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'interpretation'",
",",
"$",
"interpretation",
")",
";",
"}",
"// A CorrectResponse contains 1..* Value objects",
"foreach",
"(",
"$",
"component",
"->",
"getValues",
"(",
")",
"as",
"$",
"value",
")",
"{",
"$",
"valueMarshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"value",
",",
"array",
"(",
"$",
"this",
"->",
"getBaseType",
"(",
")",
")",
")",
";",
"$",
"valueElement",
"=",
"$",
"valueMarshaller",
"->",
"marshall",
"(",
"$",
"value",
")",
";",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"valueElement",
")",
";",
"}",
"return",
"$",
"element",
";",
"}"
] | Marshall a CorrectResponse object into a DOMElement object.
@param \qtism\data\QtiComponent $component A CorrectResponse object.
@return \DOMElement The according DOMElement object. | [
"Marshall",
"a",
"CorrectResponse",
"object",
"into",
"a",
"DOMElement",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/CorrectResponseMarshaller.php#L86-L103 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/ResponseDeclarationMarshaller.php | ResponseDeclarationMarshaller.marshall | protected function marshall(QtiComponent $component)
{
$element = parent::marshall($component);
$baseType = $component->getBaseType();
if ($component->getCorrectResponse() !== null) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($component->getCorrectResponse(), array($baseType));
$element->appendChild($marshaller->marshall($component->getCorrectResponse()));
}
if ($component->getMapping() !== null) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($component->getMapping(), array($baseType));
$element->appendChild($marshaller->marshall($component->getMapping()));
}
if ($component->getAreaMapping() !== null) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($component->getAreaMapping());
$element->appendChild($marshaller->marshall($component->getAreaMapping()));
}
return $element;
} | php | protected function marshall(QtiComponent $component)
{
$element = parent::marshall($component);
$baseType = $component->getBaseType();
if ($component->getCorrectResponse() !== null) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($component->getCorrectResponse(), array($baseType));
$element->appendChild($marshaller->marshall($component->getCorrectResponse()));
}
if ($component->getMapping() !== null) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($component->getMapping(), array($baseType));
$element->appendChild($marshaller->marshall($component->getMapping()));
}
if ($component->getAreaMapping() !== null) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($component->getAreaMapping());
$element->appendChild($marshaller->marshall($component->getAreaMapping()));
}
return $element;
} | [
"protected",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"$",
"element",
"=",
"parent",
"::",
"marshall",
"(",
"$",
"component",
")",
";",
"$",
"baseType",
"=",
"$",
"component",
"->",
"getBaseType",
"(",
")",
";",
"if",
"(",
"$",
"component",
"->",
"getCorrectResponse",
"(",
")",
"!==",
"null",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"component",
"->",
"getCorrectResponse",
"(",
")",
",",
"array",
"(",
"$",
"baseType",
")",
")",
";",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"marshaller",
"->",
"marshall",
"(",
"$",
"component",
"->",
"getCorrectResponse",
"(",
")",
")",
")",
";",
"}",
"if",
"(",
"$",
"component",
"->",
"getMapping",
"(",
")",
"!==",
"null",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"component",
"->",
"getMapping",
"(",
")",
",",
"array",
"(",
"$",
"baseType",
")",
")",
";",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"marshaller",
"->",
"marshall",
"(",
"$",
"component",
"->",
"getMapping",
"(",
")",
")",
")",
";",
"}",
"if",
"(",
"$",
"component",
"->",
"getAreaMapping",
"(",
")",
"!==",
"null",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"component",
"->",
"getAreaMapping",
"(",
")",
")",
";",
"$",
"element",
"->",
"appendChild",
"(",
"$",
"marshaller",
"->",
"marshall",
"(",
"$",
"component",
"->",
"getAreaMapping",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"element",
";",
"}"
] | Marshall a ResponseDeclaration object into a DOMElement object.
@param \qtism\data\QtiComponent $component A ResponseDeclaration object.
@return \DOMElement The according DOMElement object. | [
"Marshall",
"a",
"ResponseDeclaration",
"object",
"into",
"a",
"DOMElement",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/ResponseDeclarationMarshaller.php#L44-L65 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/ResponseDeclarationMarshaller.php | ResponseDeclarationMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
try {
$baseComponent = parent::unmarshall($element);
$object = new ResponseDeclaration($baseComponent->getIdentifier());
$object->setBaseType($baseComponent->getBaseType());
$object->setCardinality($baseComponent->getCardinality());
$object->setDefaultValue($baseComponent->getDefaultValue());
$correctResponseElts = $this->getChildElementsByTagName($element, 'correctResponse');
if (count($correctResponseElts) === 1) {
$correctResponseElt = $correctResponseElts[0];
$marshaller = $this->getMarshallerFactory()->createMarshaller($correctResponseElt, array($baseComponent->getBaseType()));
$object->setCorrectResponse($marshaller->unmarshall($correctResponseElt));
}
$mappingElts = $this->getChildElementsByTagName($element, 'mapping');
if (count($mappingElts) === 1) {
$mappingElt = $mappingElts[0];
$marshaller = $this->getMarshallerFactory()->createMarshaller($mappingElt, array($baseComponent->getBaseType()));
$object->setMapping($marshaller->unmarshall($mappingElt));
}
$areaMappingElts = $this->getChildElementsByTagName($element, 'areaMapping');
if (count($areaMappingElts) === 1) {
$areaMappingElt = $areaMappingElts[0];
$marshaller = $this->getMarshallerFactory()->createMarshaller($areaMappingElt);
$object->setAreaMapping($marshaller->unmarshall($areaMappingElt));
}
return $object;
} catch (InvalidArgumentException $e) {
$msg = "An unexpected error occured while unmarshalling the responseDeclaration.";
throw new UnmarshallingException($msg, $element, $e);
}
} | php | protected function unmarshall(DOMElement $element)
{
try {
$baseComponent = parent::unmarshall($element);
$object = new ResponseDeclaration($baseComponent->getIdentifier());
$object->setBaseType($baseComponent->getBaseType());
$object->setCardinality($baseComponent->getCardinality());
$object->setDefaultValue($baseComponent->getDefaultValue());
$correctResponseElts = $this->getChildElementsByTagName($element, 'correctResponse');
if (count($correctResponseElts) === 1) {
$correctResponseElt = $correctResponseElts[0];
$marshaller = $this->getMarshallerFactory()->createMarshaller($correctResponseElt, array($baseComponent->getBaseType()));
$object->setCorrectResponse($marshaller->unmarshall($correctResponseElt));
}
$mappingElts = $this->getChildElementsByTagName($element, 'mapping');
if (count($mappingElts) === 1) {
$mappingElt = $mappingElts[0];
$marshaller = $this->getMarshallerFactory()->createMarshaller($mappingElt, array($baseComponent->getBaseType()));
$object->setMapping($marshaller->unmarshall($mappingElt));
}
$areaMappingElts = $this->getChildElementsByTagName($element, 'areaMapping');
if (count($areaMappingElts) === 1) {
$areaMappingElt = $areaMappingElts[0];
$marshaller = $this->getMarshallerFactory()->createMarshaller($areaMappingElt);
$object->setAreaMapping($marshaller->unmarshall($areaMappingElt));
}
return $object;
} catch (InvalidArgumentException $e) {
$msg = "An unexpected error occured while unmarshalling the responseDeclaration.";
throw new UnmarshallingException($msg, $element, $e);
}
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"try",
"{",
"$",
"baseComponent",
"=",
"parent",
"::",
"unmarshall",
"(",
"$",
"element",
")",
";",
"$",
"object",
"=",
"new",
"ResponseDeclaration",
"(",
"$",
"baseComponent",
"->",
"getIdentifier",
"(",
")",
")",
";",
"$",
"object",
"->",
"setBaseType",
"(",
"$",
"baseComponent",
"->",
"getBaseType",
"(",
")",
")",
";",
"$",
"object",
"->",
"setCardinality",
"(",
"$",
"baseComponent",
"->",
"getCardinality",
"(",
")",
")",
";",
"$",
"object",
"->",
"setDefaultValue",
"(",
"$",
"baseComponent",
"->",
"getDefaultValue",
"(",
")",
")",
";",
"$",
"correctResponseElts",
"=",
"$",
"this",
"->",
"getChildElementsByTagName",
"(",
"$",
"element",
",",
"'correctResponse'",
")",
";",
"if",
"(",
"count",
"(",
"$",
"correctResponseElts",
")",
"===",
"1",
")",
"{",
"$",
"correctResponseElt",
"=",
"$",
"correctResponseElts",
"[",
"0",
"]",
";",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"correctResponseElt",
",",
"array",
"(",
"$",
"baseComponent",
"->",
"getBaseType",
"(",
")",
")",
")",
";",
"$",
"object",
"->",
"setCorrectResponse",
"(",
"$",
"marshaller",
"->",
"unmarshall",
"(",
"$",
"correctResponseElt",
")",
")",
";",
"}",
"$",
"mappingElts",
"=",
"$",
"this",
"->",
"getChildElementsByTagName",
"(",
"$",
"element",
",",
"'mapping'",
")",
";",
"if",
"(",
"count",
"(",
"$",
"mappingElts",
")",
"===",
"1",
")",
"{",
"$",
"mappingElt",
"=",
"$",
"mappingElts",
"[",
"0",
"]",
";",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"mappingElt",
",",
"array",
"(",
"$",
"baseComponent",
"->",
"getBaseType",
"(",
")",
")",
")",
";",
"$",
"object",
"->",
"setMapping",
"(",
"$",
"marshaller",
"->",
"unmarshall",
"(",
"$",
"mappingElt",
")",
")",
";",
"}",
"$",
"areaMappingElts",
"=",
"$",
"this",
"->",
"getChildElementsByTagName",
"(",
"$",
"element",
",",
"'areaMapping'",
")",
";",
"if",
"(",
"count",
"(",
"$",
"areaMappingElts",
")",
"===",
"1",
")",
"{",
"$",
"areaMappingElt",
"=",
"$",
"areaMappingElts",
"[",
"0",
"]",
";",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"areaMappingElt",
")",
";",
"$",
"object",
"->",
"setAreaMapping",
"(",
"$",
"marshaller",
"->",
"unmarshall",
"(",
"$",
"areaMappingElt",
")",
")",
";",
"}",
"return",
"$",
"object",
";",
"}",
"catch",
"(",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"$",
"msg",
"=",
"\"An unexpected error occured while unmarshalling the responseDeclaration.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Unmarshall a DOMElement object corresponding to a QTI responseDeclaration element.
@param \DOMElement $element A DOMElement object.
@return \qtism\data\QtiComponent A ResponseDeclaration object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException | [
"Unmarshall",
"a",
"DOMElement",
"object",
"corresponding",
"to",
"a",
"QTI",
"responseDeclaration",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/ResponseDeclarationMarshaller.php#L74-L109 |
oat-sa/qti-sdk | src/qtism/data/ItemSessionControl.php | ItemSessionControl.setMaxAttempts | public function setMaxAttempts($maxAttempts)
{
if (is_int($maxAttempts)) {
$this->maxAttempts = $maxAttempts;
} else {
$msg = "MaxAttempts must be an integer, '" . gettype($maxAttempts) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setMaxAttempts($maxAttempts)
{
if (is_int($maxAttempts)) {
$this->maxAttempts = $maxAttempts;
} else {
$msg = "MaxAttempts must be an integer, '" . gettype($maxAttempts) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setMaxAttempts",
"(",
"$",
"maxAttempts",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"maxAttempts",
")",
")",
"{",
"$",
"this",
"->",
"maxAttempts",
"=",
"$",
"maxAttempts",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"MaxAttempts must be an integer, '\"",
".",
"gettype",
"(",
"$",
"maxAttempts",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the maximum number of attempts in the given test context.
@param integer $maxAttempts An integer.
@throws \InvalidArgumentException If $maxAttempts is not an integer. | [
"Set",
"the",
"maximum",
"number",
"of",
"attempts",
"in",
"the",
"given",
"test",
"context",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/ItemSessionControl.php#L173-L181 |
oat-sa/qti-sdk | src/qtism/data/ItemSessionControl.php | ItemSessionControl.setShowFeedback | public function setShowFeedback($showFeedback)
{
if (is_bool($showFeedback)) {
$this->showFeedback = $showFeedback;
} else {
$msg = "ShowFeedback must be a boolean, '" . gettype($showFeedback) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setShowFeedback($showFeedback)
{
if (is_bool($showFeedback)) {
$this->showFeedback = $showFeedback;
} else {
$msg = "ShowFeedback must be a boolean, '" . gettype($showFeedback) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setShowFeedback",
"(",
"$",
"showFeedback",
")",
"{",
"if",
"(",
"is_bool",
"(",
"$",
"showFeedback",
")",
")",
"{",
"$",
"this",
"->",
"showFeedback",
"=",
"$",
"showFeedback",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"ShowFeedback must be a boolean, '\"",
".",
"gettype",
"(",
"$",
"showFeedback",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set if feedbacks must be shown in the given test context.
@param boolean $showFeedback true if feedbacks must be shown, otherwise false.
@throws \InvalidArgumentException If $showFeedback is not a boolean value. | [
"Set",
"if",
"feedbacks",
"must",
"be",
"shown",
"in",
"the",
"given",
"test",
"context",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/ItemSessionControl.php#L199-L207 |
oat-sa/qti-sdk | src/qtism/data/ItemSessionControl.php | ItemSessionControl.setAllowReview | public function setAllowReview($allowReview)
{
if (is_bool($allowReview)) {
$this->allowReview = $allowReview;
} else {
$msg = "AllowReview must be a boolean, '" . gettype($allowReview) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setAllowReview($allowReview)
{
if (is_bool($allowReview)) {
$this->allowReview = $allowReview;
} else {
$msg = "AllowReview must be a boolean, '" . gettype($allowReview) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setAllowReview",
"(",
"$",
"allowReview",
")",
"{",
"if",
"(",
"is_bool",
"(",
"$",
"allowReview",
")",
")",
"{",
"$",
"this",
"->",
"allowReview",
"=",
"$",
"allowReview",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"AllowReview must be a boolean, '\"",
".",
"gettype",
"(",
"$",
"allowReview",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set that the candidate is allowed to review item body and given responses
after the last item.
@param boolean $allowReview true if allowed, false if not.
@throws \InvalidArgumentException If $allowReview is not a boolean. | [
"Set",
"that",
"the",
"candidate",
"is",
"allowed",
"to",
"review",
"item",
"body",
"and",
"given",
"responses",
"after",
"the",
"last",
"item",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/ItemSessionControl.php#L226-L234 |
oat-sa/qti-sdk | src/qtism/data/ItemSessionControl.php | ItemSessionControl.setShowSolution | public function setShowSolution($showSolution)
{
if (is_bool($showSolution)) {
$this->showSolution = $showSolution;
} else {
$msg = "ShowSolution must be a boolean, '" . gettype($showSolution) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setShowSolution($showSolution)
{
if (is_bool($showSolution)) {
$this->showSolution = $showSolution;
} else {
$msg = "ShowSolution must be a boolean, '" . gettype($showSolution) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setShowSolution",
"(",
"$",
"showSolution",
")",
"{",
"if",
"(",
"is_bool",
"(",
"$",
"showSolution",
")",
")",
"{",
"$",
"this",
"->",
"showSolution",
"=",
"$",
"showSolution",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"ShowSolution must be a boolean, '\"",
".",
"gettype",
"(",
"$",
"showSolution",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set if the candidate is provided a way to enter the 'solution' state.
@param boolean $showSolution true if he is provided, false if not.
@throws \InvalidArgumentException If $showSolution is not a boolean. | [
"Set",
"if",
"the",
"candidate",
"is",
"provided",
"a",
"way",
"to",
"enter",
"the",
"solution",
"state",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/ItemSessionControl.php#L252-L260 |
oat-sa/qti-sdk | src/qtism/data/ItemSessionControl.php | ItemSessionControl.setAllowComment | public function setAllowComment($allowComment)
{
if (is_bool($allowComment)) {
$this->allowComment = $allowComment;
} else {
$msg = "AllowComment must be a boolean, '" . gettype($allowComment) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setAllowComment($allowComment)
{
if (is_bool($allowComment)) {
$this->allowComment = $allowComment;
} else {
$msg = "AllowComment must be a boolean, '" . gettype($allowComment) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setAllowComment",
"(",
"$",
"allowComment",
")",
"{",
"if",
"(",
"is_bool",
"(",
"$",
"allowComment",
")",
")",
"{",
"$",
"this",
"->",
"allowComment",
"=",
"$",
"allowComment",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"AllowComment must be a boolean, '\"",
".",
"gettype",
"(",
"$",
"allowComment",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set if the candidate is allowed to communicate comments during the session.
@param boolean $allowComment true if allowed, false if not.
@throws \InvalidArgumentException If $allowComment is not a boolean. | [
"Set",
"if",
"the",
"candidate",
"is",
"allowed",
"to",
"communicate",
"comments",
"during",
"the",
"session",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/ItemSessionControl.php#L278-L286 |
oat-sa/qti-sdk | src/qtism/data/ItemSessionControl.php | ItemSessionControl.setAllowSkipping | public function setAllowSkipping($allowSkipping)
{
if (is_bool($allowSkipping)) {
$this->allowSkipping = $allowSkipping;
} else {
$msg = "AllowSkipping must be a boolean, '" . gettype($allowSkipping) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setAllowSkipping($allowSkipping)
{
if (is_bool($allowSkipping)) {
$this->allowSkipping = $allowSkipping;
} else {
$msg = "AllowSkipping must be a boolean, '" . gettype($allowSkipping) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setAllowSkipping",
"(",
"$",
"allowSkipping",
")",
"{",
"if",
"(",
"is_bool",
"(",
"$",
"allowSkipping",
")",
")",
"{",
"$",
"this",
"->",
"allowSkipping",
"=",
"$",
"allowSkipping",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"AllowSkipping must be a boolean, '\"",
".",
"gettype",
"(",
"$",
"allowSkipping",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set if the candidate is allowed to skip items.
Set whether or not the Delivery Engine allows the candidate to skip items.
@param boolean $allowSkipping true if allowed, false otherwise.
@throws \InvalidArgumentException If $allowSkipping is not a valid boolean. | [
"Set",
"if",
"the",
"candidate",
"is",
"allowed",
"to",
"skip",
"items",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/ItemSessionControl.php#L308-L316 |
oat-sa/qti-sdk | src/qtism/data/ItemSessionControl.php | ItemSessionControl.isDefault | public function isDefault()
{
return $this->getMaxAttempts() === 1 &&
$this->mustShowFeedback() === false &&
$this->doesAllowReview() === true &&
$this->mustShowSolution() === false &&
$this->doesAllowComment() === false &&
$this->mustValidateResponses() === false &&
$this->doesAllowSkipping() === true;
} | php | public function isDefault()
{
return $this->getMaxAttempts() === 1 &&
$this->mustShowFeedback() === false &&
$this->doesAllowReview() === true &&
$this->mustShowSolution() === false &&
$this->doesAllowComment() === false &&
$this->mustValidateResponses() === false &&
$this->doesAllowSkipping() === true;
} | [
"public",
"function",
"isDefault",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"getMaxAttempts",
"(",
")",
"===",
"1",
"&&",
"$",
"this",
"->",
"mustShowFeedback",
"(",
")",
"===",
"false",
"&&",
"$",
"this",
"->",
"doesAllowReview",
"(",
")",
"===",
"true",
"&&",
"$",
"this",
"->",
"mustShowSolution",
"(",
")",
"===",
"false",
"&&",
"$",
"this",
"->",
"doesAllowComment",
"(",
")",
"===",
"false",
"&&",
"$",
"this",
"->",
"mustValidateResponses",
"(",
")",
"===",
"false",
"&&",
"$",
"this",
"->",
"doesAllowSkipping",
"(",
")",
"===",
"true",
";",
"}"
] | Is a default Item Session Control?
Whether the values held by the ItemSessionControl are the default ones.
@return boolean | [
"Is",
"a",
"default",
"Item",
"Session",
"Control?"
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/ItemSessionControl.php#L335-L344 |
oat-sa/qti-sdk | src/qtism/data/ItemSessionControl.php | ItemSessionControl.setValidateResponses | public function setValidateResponses($validateResponses)
{
if (is_bool($validateResponses)) {
$this->validateResponses = $validateResponses;
} else {
$msg = "ValidateResponses must be a boolean value, '" . gettype($validateResponses) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setValidateResponses($validateResponses)
{
if (is_bool($validateResponses)) {
$this->validateResponses = $validateResponses;
} else {
$msg = "ValidateResponses must be a boolean value, '" . gettype($validateResponses) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setValidateResponses",
"(",
"$",
"validateResponses",
")",
"{",
"if",
"(",
"is_bool",
"(",
"$",
"validateResponses",
")",
")",
"{",
"$",
"this",
"->",
"validateResponses",
"=",
"$",
"validateResponses",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"ValidateResponses must be a boolean value, '\"",
".",
"gettype",
"(",
"$",
"validateResponses",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set if the responses must be validated.
Set whether or not responses must be validated by the Delivery Engine.
@param boolean $validateResponses true if responses must be validated, false if not.
@throws \InvalidArgumentException If $validateResponses is not a boolean. | [
"Set",
"if",
"the",
"responses",
"must",
"be",
"validated",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/ItemSessionControl.php#L354-L362 |
oat-sa/qti-sdk | src/qtism/runtime/common/RecordContainer.php | RecordContainer.offsetSet | public function offsetSet($offset, $value)
{
if (gettype($offset) === 'string') {
$this->checkType($value);
$placeholder = &$this->getDataPlaceHolder();
$placeholder[$offset] = $value;
} else {
$msg = "The offset of a value in a RecordContainer must be a string.";
throw new RuntimeException($msg);
}
} | php | public function offsetSet($offset, $value)
{
if (gettype($offset) === 'string') {
$this->checkType($value);
$placeholder = &$this->getDataPlaceHolder();
$placeholder[$offset] = $value;
} else {
$msg = "The offset of a value in a RecordContainer must be a string.";
throw new RuntimeException($msg);
}
} | [
"public",
"function",
"offsetSet",
"(",
"$",
"offset",
",",
"$",
"value",
")",
"{",
"if",
"(",
"gettype",
"(",
"$",
"offset",
")",
"===",
"'string'",
")",
"{",
"$",
"this",
"->",
"checkType",
"(",
"$",
"value",
")",
";",
"$",
"placeholder",
"=",
"&",
"$",
"this",
"->",
"getDataPlaceHolder",
"(",
")",
";",
"$",
"placeholder",
"[",
"$",
"offset",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The offset of a value in a RecordContainer must be a string.\"",
";",
"throw",
"new",
"RuntimeException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Overloading of offsetSet that makes sure that the $offset
is a string.
@param string $offset A string offset.
@param mixed $value A value.
@throws \RuntimeException If $offset is not a string. | [
"Overloading",
"of",
"offsetSet",
"that",
"makes",
"sure",
"that",
"the",
"$offset",
"is",
"a",
"string",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/common/RecordContainer.php#L89-L99 |
oat-sa/qti-sdk | src/qtism/runtime/common/RecordContainer.php | RecordContainer.createFromDataModel | public static function createFromDataModel(ValueCollection $valueCollection)
{
$container = new static();
foreach ($valueCollection as $value) {
$fieldIdentifier = $value->getFieldIdentifier();
if (!empty($fieldIdentifier)) {
$container[$value->getFieldIdentifier()] = RuntimeUtils::valueToRuntime($value->getValue(), $value->getBaseType());
} else {
$msg = "Cannot include qtism\\data\\state\\Value '" . $value->getValue() . "' in the RecordContainer ";
$msg .= "because it has no fieldIdentifier specified.";
throw new InvalidArgumentException($msg);
}
}
return $container;
} | php | public static function createFromDataModel(ValueCollection $valueCollection)
{
$container = new static();
foreach ($valueCollection as $value) {
$fieldIdentifier = $value->getFieldIdentifier();
if (!empty($fieldIdentifier)) {
$container[$value->getFieldIdentifier()] = RuntimeUtils::valueToRuntime($value->getValue(), $value->getBaseType());
} else {
$msg = "Cannot include qtism\\data\\state\\Value '" . $value->getValue() . "' in the RecordContainer ";
$msg .= "because it has no fieldIdentifier specified.";
throw new InvalidArgumentException($msg);
}
}
return $container;
} | [
"public",
"static",
"function",
"createFromDataModel",
"(",
"ValueCollection",
"$",
"valueCollection",
")",
"{",
"$",
"container",
"=",
"new",
"static",
"(",
")",
";",
"foreach",
"(",
"$",
"valueCollection",
"as",
"$",
"value",
")",
"{",
"$",
"fieldIdentifier",
"=",
"$",
"value",
"->",
"getFieldIdentifier",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"fieldIdentifier",
")",
")",
"{",
"$",
"container",
"[",
"$",
"value",
"->",
"getFieldIdentifier",
"(",
")",
"]",
"=",
"RuntimeUtils",
"::",
"valueToRuntime",
"(",
"$",
"value",
"->",
"getValue",
"(",
")",
",",
"$",
"value",
"->",
"getBaseType",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"Cannot include qtism\\\\data\\\\state\\\\Value '\"",
".",
"$",
"value",
"->",
"getValue",
"(",
")",
".",
"\"' in the RecordContainer \"",
";",
"$",
"msg",
".=",
"\"because it has no fieldIdentifier specified.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}",
"return",
"$",
"container",
";",
"}"
] | Create a RecordContainer object from a Data Model ValueCollection object.
@param \qtism\data\state\ValueCollection $valueCollection A collection of qtism\data\state\Value objects.
@return \qtism\runtime\common\RecordContainer A Container object populated with the values found in $valueCollection.
@throws \InvalidArgumentException If a value from $valueCollection is not compliant with the QTI Runtime Model or the container type or if a value has no fieldIdentifier. | [
"Create",
"a",
"RecordContainer",
"object",
"from",
"a",
"Data",
"Model",
"ValueCollection",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/common/RecordContainer.php#L108-L124 |
oat-sa/qti-sdk | src/qtism/runtime/rendering/qtipl/expressions/OutcomeMaximumQtiPLRenderer.php | OutcomeMaximumQtiPLRenderer.render | public function render($something)
{
$renderer = new QtiPLRenderer($this->getCRO());
$attributes = [];
if ($something->getSectionIdentifier() != "") {
$attributes['sectionIdentifier'] = "\"" . $something->getSectionIdentifier() . "\"";
}
if ($something->getIncludeCategories() != "") {
$attributes['includeCategory'] = "\"" . $something->getIncludeCategories() . "\"";
}
if ($something->getExcludeCategories() != "") {
$attributes['excludeCategory'] = "\"" . $something->getExcludeCategories() . "\"";
}
$attributes['outcomeIdentifier'] = "\"" . $something->getOutcomeIdentifier() . "\"";
if ($something->getWeightIdentifier() != "") {
$attributes['weightIdentifier'] = "\"" . $something->getWeightIdentifier() . "\"";
}
return $something->getQtiClassName() . $renderer->writeAttributes($attributes)
. $renderer->writeChildElements();
} | php | public function render($something)
{
$renderer = new QtiPLRenderer($this->getCRO());
$attributes = [];
if ($something->getSectionIdentifier() != "") {
$attributes['sectionIdentifier'] = "\"" . $something->getSectionIdentifier() . "\"";
}
if ($something->getIncludeCategories() != "") {
$attributes['includeCategory'] = "\"" . $something->getIncludeCategories() . "\"";
}
if ($something->getExcludeCategories() != "") {
$attributes['excludeCategory'] = "\"" . $something->getExcludeCategories() . "\"";
}
$attributes['outcomeIdentifier'] = "\"" . $something->getOutcomeIdentifier() . "\"";
if ($something->getWeightIdentifier() != "") {
$attributes['weightIdentifier'] = "\"" . $something->getWeightIdentifier() . "\"";
}
return $something->getQtiClassName() . $renderer->writeAttributes($attributes)
. $renderer->writeChildElements();
} | [
"public",
"function",
"render",
"(",
"$",
"something",
")",
"{",
"$",
"renderer",
"=",
"new",
"QtiPLRenderer",
"(",
"$",
"this",
"->",
"getCRO",
"(",
")",
")",
";",
"$",
"attributes",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"something",
"->",
"getSectionIdentifier",
"(",
")",
"!=",
"\"\"",
")",
"{",
"$",
"attributes",
"[",
"'sectionIdentifier'",
"]",
"=",
"\"\\\"\"",
".",
"$",
"something",
"->",
"getSectionIdentifier",
"(",
")",
".",
"\"\\\"\"",
";",
"}",
"if",
"(",
"$",
"something",
"->",
"getIncludeCategories",
"(",
")",
"!=",
"\"\"",
")",
"{",
"$",
"attributes",
"[",
"'includeCategory'",
"]",
"=",
"\"\\\"\"",
".",
"$",
"something",
"->",
"getIncludeCategories",
"(",
")",
".",
"\"\\\"\"",
";",
"}",
"if",
"(",
"$",
"something",
"->",
"getExcludeCategories",
"(",
")",
"!=",
"\"\"",
")",
"{",
"$",
"attributes",
"[",
"'excludeCategory'",
"]",
"=",
"\"\\\"\"",
".",
"$",
"something",
"->",
"getExcludeCategories",
"(",
")",
".",
"\"\\\"\"",
";",
"}",
"$",
"attributes",
"[",
"'outcomeIdentifier'",
"]",
"=",
"\"\\\"\"",
".",
"$",
"something",
"->",
"getOutcomeIdentifier",
"(",
")",
".",
"\"\\\"\"",
";",
"if",
"(",
"$",
"something",
"->",
"getWeightIdentifier",
"(",
")",
"!=",
"\"\"",
")",
"{",
"$",
"attributes",
"[",
"'weightIdentifier'",
"]",
"=",
"\"\\\"\"",
".",
"$",
"something",
"->",
"getWeightIdentifier",
"(",
")",
".",
"\"\\\"\"",
";",
"}",
"return",
"$",
"something",
"->",
"getQtiClassName",
"(",
")",
".",
"$",
"renderer",
"->",
"writeAttributes",
"(",
"$",
"attributes",
")",
".",
"$",
"renderer",
"->",
"writeChildElements",
"(",
")",
";",
"}"
] | 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/OutcomeMaximumQtiPLRenderer.php#L45-L70 |
oat-sa/qti-sdk | src/qtism/data/storage/php/marshalling/PhpArrayMarshaller.php | PhpArrayMarshaller.marshall | public function marshall()
{
$ctx = $this->getContext();
$access = $ctx->getStreamAccess();
$array = $this->getToMarshall();
$args = new PhpArgumentCollection();
foreach ($array as $a) {
if (PhpUtils::isScalar($a) === false) {
$msg = "The PhpArrayMarshaller class only deals with PHP scalar values, object or resource given.";
throw new PhpMarshallingException($msg);
}
$args[] = new PhpArgument($a);
}
$arrayVarName = $ctx->generateVariableName($array);
$access->writeVariable($arrayVarName);
$access->writeEquals($ctx->mustFormatOutput());
$access->writeFunctionCall('array', $args);
$access->writeSemicolon($ctx->mustFormatOutput());
$ctx->pushOnVariableStack($arrayVarName);
} | php | public function marshall()
{
$ctx = $this->getContext();
$access = $ctx->getStreamAccess();
$array = $this->getToMarshall();
$args = new PhpArgumentCollection();
foreach ($array as $a) {
if (PhpUtils::isScalar($a) === false) {
$msg = "The PhpArrayMarshaller class only deals with PHP scalar values, object or resource given.";
throw new PhpMarshallingException($msg);
}
$args[] = new PhpArgument($a);
}
$arrayVarName = $ctx->generateVariableName($array);
$access->writeVariable($arrayVarName);
$access->writeEquals($ctx->mustFormatOutput());
$access->writeFunctionCall('array', $args);
$access->writeSemicolon($ctx->mustFormatOutput());
$ctx->pushOnVariableStack($arrayVarName);
} | [
"public",
"function",
"marshall",
"(",
")",
"{",
"$",
"ctx",
"=",
"$",
"this",
"->",
"getContext",
"(",
")",
";",
"$",
"access",
"=",
"$",
"ctx",
"->",
"getStreamAccess",
"(",
")",
";",
"$",
"array",
"=",
"$",
"this",
"->",
"getToMarshall",
"(",
")",
";",
"$",
"args",
"=",
"new",
"PhpArgumentCollection",
"(",
")",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"a",
")",
"{",
"if",
"(",
"PhpUtils",
"::",
"isScalar",
"(",
"$",
"a",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The PhpArrayMarshaller class only deals with PHP scalar values, object or resource given.\"",
";",
"throw",
"new",
"PhpMarshallingException",
"(",
"$",
"msg",
")",
";",
"}",
"$",
"args",
"[",
"]",
"=",
"new",
"PhpArgument",
"(",
"$",
"a",
")",
";",
"}",
"$",
"arrayVarName",
"=",
"$",
"ctx",
"->",
"generateVariableName",
"(",
"$",
"array",
")",
";",
"$",
"access",
"->",
"writeVariable",
"(",
"$",
"arrayVarName",
")",
";",
"$",
"access",
"->",
"writeEquals",
"(",
"$",
"ctx",
"->",
"mustFormatOutput",
"(",
")",
")",
";",
"$",
"access",
"->",
"writeFunctionCall",
"(",
"'array'",
",",
"$",
"args",
")",
";",
"$",
"access",
"->",
"writeSemicolon",
"(",
"$",
"ctx",
"->",
"mustFormatOutput",
"(",
")",
")",
";",
"$",
"ctx",
"->",
"pushOnVariableStack",
"(",
"$",
"arrayVarName",
")",
";",
"}"
] | Marshall an array into PHP source code.
@throws \qtism\data\storage\php\marshalling\PhpMarshallingException If something wrong happens during marshalling. | [
"Marshall",
"an",
"array",
"into",
"PHP",
"source",
"code",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/php/marshalling/PhpArrayMarshaller.php#L43-L66 |
oat-sa/qti-sdk | src/qtism/common/storage/BinaryStreamAccess.php | BinaryStreamAccess.setStream | protected function setStream(IStream $stream)
{
if ($stream->isOpen() === false) {
$msg = "A BinaryStreamAccess do not accept closed streams to be read.";
throw new BinaryStreamAccessException($msg, $this, StreamAccessException::NOT_OPEN);
}
parent::setStream($stream);
} | php | protected function setStream(IStream $stream)
{
if ($stream->isOpen() === false) {
$msg = "A BinaryStreamAccess do not accept closed streams to be read.";
throw new BinaryStreamAccessException($msg, $this, StreamAccessException::NOT_OPEN);
}
parent::setStream($stream);
} | [
"protected",
"function",
"setStream",
"(",
"IStream",
"$",
"stream",
")",
"{",
"if",
"(",
"$",
"stream",
"->",
"isOpen",
"(",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"A BinaryStreamAccess do not accept closed streams to be read.\"",
";",
"throw",
"new",
"BinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"StreamAccessException",
"::",
"NOT_OPEN",
")",
";",
"}",
"parent",
"::",
"setStream",
"(",
"$",
"stream",
")",
";",
"}"
] | Set the IStream object to be read.
@param \qtism\common\storage\IStream $stream An IStream object.
@throws \qtism\common\storage\StreamAccessException If the $stream is not open yet. | [
"Set",
"the",
"IStream",
"object",
"to",
"be",
"read",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/storage/BinaryStreamAccess.php#L41-L49 |
oat-sa/qti-sdk | src/qtism/common/storage/BinaryStreamAccess.php | BinaryStreamAccess.readTinyInt | public function readTinyInt()
{
try {
$bin = $this->getStream()->read(1);
return ord($bin);
} catch (StreamException $e) {
$this->handleStreamException($e, BinaryStreamAccessException::TINYINT);
}
} | php | public function readTinyInt()
{
try {
$bin = $this->getStream()->read(1);
return ord($bin);
} catch (StreamException $e) {
$this->handleStreamException($e, BinaryStreamAccessException::TINYINT);
}
} | [
"public",
"function",
"readTinyInt",
"(",
")",
"{",
"try",
"{",
"$",
"bin",
"=",
"$",
"this",
"->",
"getStream",
"(",
")",
"->",
"read",
"(",
"1",
")",
";",
"return",
"ord",
"(",
"$",
"bin",
")",
";",
"}",
"catch",
"(",
"StreamException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"handleStreamException",
"(",
"$",
"e",
",",
"BinaryStreamAccessException",
"::",
"TINYINT",
")",
";",
"}",
"}"
] | Read a single byte unsigned integer from the current binary stream.
@throws \qtism\common\storage\BinaryStreamAccessException
@return integer | [
"Read",
"a",
"single",
"byte",
"unsigned",
"integer",
"from",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/storage/BinaryStreamAccess.php#L57-L66 |
oat-sa/qti-sdk | src/qtism/common/storage/BinaryStreamAccess.php | BinaryStreamAccess.writeTinyInt | public function writeTinyInt($tinyInt)
{
try {
$this->getStream()->write(chr($tinyInt));
} catch (StreamException $e) {
$this->handleStreamException($e, BinaryStreamAccessException::TINYINT, false);
}
} | php | public function writeTinyInt($tinyInt)
{
try {
$this->getStream()->write(chr($tinyInt));
} catch (StreamException $e) {
$this->handleStreamException($e, BinaryStreamAccessException::TINYINT, false);
}
} | [
"public",
"function",
"writeTinyInt",
"(",
"$",
"tinyInt",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"getStream",
"(",
")",
"->",
"write",
"(",
"chr",
"(",
"$",
"tinyInt",
")",
")",
";",
"}",
"catch",
"(",
"StreamException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"handleStreamException",
"(",
"$",
"e",
",",
"BinaryStreamAccessException",
"::",
"TINYINT",
",",
"false",
")",
";",
"}",
"}"
] | Write a single byte unsigned integer in the current binary stream.
@param integer $tinyInt
@throws \qtism\common\storage\BinaryStreamAccessException | [
"Write",
"a",
"single",
"byte",
"unsigned",
"integer",
"in",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/storage/BinaryStreamAccess.php#L74-L81 |
oat-sa/qti-sdk | src/qtism/common/storage/BinaryStreamAccess.php | BinaryStreamAccess.readShort | public function readShort()
{
try {
$bin = $this->getStream()->read(2);
return current(unpack('S', $bin));
} catch (StreamException $e) {
$this->handleStreamException($e, BinaryStreamAccessException::SHORT);
}
} | php | public function readShort()
{
try {
$bin = $this->getStream()->read(2);
return current(unpack('S', $bin));
} catch (StreamException $e) {
$this->handleStreamException($e, BinaryStreamAccessException::SHORT);
}
} | [
"public",
"function",
"readShort",
"(",
")",
"{",
"try",
"{",
"$",
"bin",
"=",
"$",
"this",
"->",
"getStream",
"(",
")",
"->",
"read",
"(",
"2",
")",
";",
"return",
"current",
"(",
"unpack",
"(",
"'S'",
",",
"$",
"bin",
")",
")",
";",
"}",
"catch",
"(",
"StreamException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"handleStreamException",
"(",
"$",
"e",
",",
"BinaryStreamAccessException",
"::",
"SHORT",
")",
";",
"}",
"}"
] | Read a 2 bytes unsigned integer from the current binary stream.
@throws \qtism\common\storage\BinaryStreamAccessException
@return integer | [
"Read",
"a",
"2",
"bytes",
"unsigned",
"integer",
"from",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/storage/BinaryStreamAccess.php#L89-L98 |
oat-sa/qti-sdk | src/qtism/common/storage/BinaryStreamAccess.php | BinaryStreamAccess.writeShort | public function writeShort($short)
{
try {
$this->getStream()->write(pack('S', $short));
} catch (StreamException $e) {
$this->handleStreamException($e, BinaryStreamAccessException::SHORT, false);
}
} | php | public function writeShort($short)
{
try {
$this->getStream()->write(pack('S', $short));
} catch (StreamException $e) {
$this->handleStreamException($e, BinaryStreamAccessException::SHORT, false);
}
} | [
"public",
"function",
"writeShort",
"(",
"$",
"short",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"getStream",
"(",
")",
"->",
"write",
"(",
"pack",
"(",
"'S'",
",",
"$",
"short",
")",
")",
";",
"}",
"catch",
"(",
"StreamException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"handleStreamException",
"(",
"$",
"e",
",",
"BinaryStreamAccessException",
"::",
"SHORT",
",",
"false",
")",
";",
"}",
"}"
] | Write a 2 bytes unsigned integer in the current binary stream.
@param integer $short
@throws \qtism\common\storage\BinaryStreamAccessException | [
"Write",
"a",
"2",
"bytes",
"unsigned",
"integer",
"in",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/storage/BinaryStreamAccess.php#L106-L113 |
oat-sa/qti-sdk | src/qtism/common/storage/BinaryStreamAccess.php | BinaryStreamAccess.readInteger | public function readInteger()
{
try {
$bin = $this->getStream()->read(4);
return current(unpack('l', $bin));
} catch (StreamException $e) {
$this->handleStreamException($e, BinaryStreamAccessException::INT);
}
} | php | public function readInteger()
{
try {
$bin = $this->getStream()->read(4);
return current(unpack('l', $bin));
} catch (StreamException $e) {
$this->handleStreamException($e, BinaryStreamAccessException::INT);
}
} | [
"public",
"function",
"readInteger",
"(",
")",
"{",
"try",
"{",
"$",
"bin",
"=",
"$",
"this",
"->",
"getStream",
"(",
")",
"->",
"read",
"(",
"4",
")",
";",
"return",
"current",
"(",
"unpack",
"(",
"'l'",
",",
"$",
"bin",
")",
")",
";",
"}",
"catch",
"(",
"StreamException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"handleStreamException",
"(",
"$",
"e",
",",
"BinaryStreamAccessException",
"::",
"INT",
")",
";",
"}",
"}"
] | Read a 8 bytes signed integer from the current binary stream.
@throws \qtism\common\storage\BinaryStreamAccessException
@return integer | [
"Read",
"a",
"8",
"bytes",
"signed",
"integer",
"from",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/storage/BinaryStreamAccess.php#L121-L130 |
oat-sa/qti-sdk | src/qtism/common/storage/BinaryStreamAccess.php | BinaryStreamAccess.writeInteger | public function writeInteger($int)
{
try {
$this->getStream()->write(pack('l', $int));
} catch (StreamException $e) {
$this->handleStreamException($e, BinaryStreamAccessException::INT, false);
}
} | php | public function writeInteger($int)
{
try {
$this->getStream()->write(pack('l', $int));
} catch (StreamException $e) {
$this->handleStreamException($e, BinaryStreamAccessException::INT, false);
}
} | [
"public",
"function",
"writeInteger",
"(",
"$",
"int",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"getStream",
"(",
")",
"->",
"write",
"(",
"pack",
"(",
"'l'",
",",
"$",
"int",
")",
")",
";",
"}",
"catch",
"(",
"StreamException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"handleStreamException",
"(",
"$",
"e",
",",
"BinaryStreamAccessException",
"::",
"INT",
",",
"false",
")",
";",
"}",
"}"
] | Write a 8 bytes signed integer in the current binary stream.
@param integer $int
@throws \qtism\common\storage\BinaryStreamAccessException | [
"Write",
"a",
"8",
"bytes",
"signed",
"integer",
"in",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/storage/BinaryStreamAccess.php#L138-L145 |
oat-sa/qti-sdk | src/qtism/common/storage/BinaryStreamAccess.php | BinaryStreamAccess.readFloat | public function readFloat()
{
try {
$bin = $this->getStream()->read(8);
return current(unpack('d', $bin));
} catch (StreamException $e) {
$this->handleStreamException($e, BinaryStreamAccessException::FLOAT);
}
} | php | public function readFloat()
{
try {
$bin = $this->getStream()->read(8);
return current(unpack('d', $bin));
} catch (StreamException $e) {
$this->handleStreamException($e, BinaryStreamAccessException::FLOAT);
}
} | [
"public",
"function",
"readFloat",
"(",
")",
"{",
"try",
"{",
"$",
"bin",
"=",
"$",
"this",
"->",
"getStream",
"(",
")",
"->",
"read",
"(",
"8",
")",
";",
"return",
"current",
"(",
"unpack",
"(",
"'d'",
",",
"$",
"bin",
")",
")",
";",
"}",
"catch",
"(",
"StreamException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"handleStreamException",
"(",
"$",
"e",
",",
"BinaryStreamAccessException",
"::",
"FLOAT",
")",
";",
"}",
"}"
] | Read a double precision float from the current binary stream.
@throws \qtism\common\storage\BinaryStreamAccessException
@return integer | [
"Read",
"a",
"double",
"precision",
"float",
"from",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/storage/BinaryStreamAccess.php#L153-L162 |
oat-sa/qti-sdk | src/qtism/common/storage/BinaryStreamAccess.php | BinaryStreamAccess.writeFloat | public function writeFloat($float)
{
try {
$this->getStream()->write(pack('d', $float));
} catch (StreamException $e) {
$this->handleStreamException($e, BinaryStreamAccessException::FLOAT, false);
}
} | php | public function writeFloat($float)
{
try {
$this->getStream()->write(pack('d', $float));
} catch (StreamException $e) {
$this->handleStreamException($e, BinaryStreamAccessException::FLOAT, false);
}
} | [
"public",
"function",
"writeFloat",
"(",
"$",
"float",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"getStream",
"(",
")",
"->",
"write",
"(",
"pack",
"(",
"'d'",
",",
"$",
"float",
")",
")",
";",
"}",
"catch",
"(",
"StreamException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"handleStreamException",
"(",
"$",
"e",
",",
"BinaryStreamAccessException",
"::",
"FLOAT",
",",
"false",
")",
";",
"}",
"}"
] | Write a double precision float in the current binary stream.
@param float $float
@throws \qtism\common\storage\BinaryStreamAccessException | [
"Write",
"a",
"double",
"precision",
"float",
"in",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/storage/BinaryStreamAccess.php#L170-L177 |
oat-sa/qti-sdk | src/qtism/common/storage/BinaryStreamAccess.php | BinaryStreamAccess.readBoolean | public function readBoolean()
{
try {
$int = ord($this->getStream()->read(1));
return ($int === 0) ? false : true;
} catch (StreamException $e) {
$this->handleStreamException($e, BinaryStreamAccessException::BOOLEAN);
}
} | php | public function readBoolean()
{
try {
$int = ord($this->getStream()->read(1));
return ($int === 0) ? false : true;
} catch (StreamException $e) {
$this->handleStreamException($e, BinaryStreamAccessException::BOOLEAN);
}
} | [
"public",
"function",
"readBoolean",
"(",
")",
"{",
"try",
"{",
"$",
"int",
"=",
"ord",
"(",
"$",
"this",
"->",
"getStream",
"(",
")",
"->",
"read",
"(",
"1",
")",
")",
";",
"return",
"(",
"$",
"int",
"===",
"0",
")",
"?",
"false",
":",
"true",
";",
"}",
"catch",
"(",
"StreamException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"handleStreamException",
"(",
"$",
"e",
",",
"BinaryStreamAccessException",
"::",
"BOOLEAN",
")",
";",
"}",
"}"
] | Read a boolean value from the current binary stream.
@throws \qtism\common\storage\BinaryStreamAccessException
@return boolean | [
"Read",
"a",
"boolean",
"value",
"from",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/storage/BinaryStreamAccess.php#L185-L194 |
oat-sa/qti-sdk | src/qtism/common/storage/BinaryStreamAccess.php | BinaryStreamAccess.writeBoolean | public function writeBoolean($boolean)
{
try {
$val = ($boolean === true) ? 1 : 0;
$this->getStream()->write(chr($val));
} catch (StreamException $e) {
$this->handleStreamException($e, BinaryStreamAccessException::FLOAT, false);
}
} | php | public function writeBoolean($boolean)
{
try {
$val = ($boolean === true) ? 1 : 0;
$this->getStream()->write(chr($val));
} catch (StreamException $e) {
$this->handleStreamException($e, BinaryStreamAccessException::FLOAT, false);
}
} | [
"public",
"function",
"writeBoolean",
"(",
"$",
"boolean",
")",
"{",
"try",
"{",
"$",
"val",
"=",
"(",
"$",
"boolean",
"===",
"true",
")",
"?",
"1",
":",
"0",
";",
"$",
"this",
"->",
"getStream",
"(",
")",
"->",
"write",
"(",
"chr",
"(",
"$",
"val",
")",
")",
";",
"}",
"catch",
"(",
"StreamException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"handleStreamException",
"(",
"$",
"e",
",",
"BinaryStreamAccessException",
"::",
"FLOAT",
",",
"false",
")",
";",
"}",
"}"
] | Write a boolean value from the current binary stream.
@param boolean $boolean
@throws \qtism\common\storage\BinaryStreamAccessException | [
"Write",
"a",
"boolean",
"value",
"from",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/storage/BinaryStreamAccess.php#L202-L210 |
oat-sa/qti-sdk | src/qtism/common/storage/BinaryStreamAccess.php | BinaryStreamAccess.readString | public function readString()
{
try {
$binLength = $this->getStream()->read(2);
$length = current(unpack('S', $binLength));
return $this->getStream()->read($length);
} catch (StreamException $e) {
$this->handleStreamException($e, BinaryStreamAccessException::STRING);
}
} | php | public function readString()
{
try {
$binLength = $this->getStream()->read(2);
$length = current(unpack('S', $binLength));
return $this->getStream()->read($length);
} catch (StreamException $e) {
$this->handleStreamException($e, BinaryStreamAccessException::STRING);
}
} | [
"public",
"function",
"readString",
"(",
")",
"{",
"try",
"{",
"$",
"binLength",
"=",
"$",
"this",
"->",
"getStream",
"(",
")",
"->",
"read",
"(",
"2",
")",
";",
"$",
"length",
"=",
"current",
"(",
"unpack",
"(",
"'S'",
",",
"$",
"binLength",
")",
")",
";",
"return",
"$",
"this",
"->",
"getStream",
"(",
")",
"->",
"read",
"(",
"$",
"length",
")",
";",
"}",
"catch",
"(",
"StreamException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"handleStreamException",
"(",
"$",
"e",
",",
"BinaryStreamAccessException",
"::",
"STRING",
")",
";",
"}",
"}"
] | Read a string value from the current binary stream.
@throws \qtism\common\storage\BinaryStreamAccessException
@return string | [
"Read",
"a",
"string",
"value",
"from",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/storage/BinaryStreamAccess.php#L218-L228 |
oat-sa/qti-sdk | src/qtism/common/storage/BinaryStreamAccess.php | BinaryStreamAccess.writeString | public function writeString($string)
{
// $maxLen = 2^16 -1 = max val of unsigned short integer.
$maxLen = 65535;
$len = strlen($string);
if ($len > $maxLen) {
$len = $maxLen;
$string = substr($string, 0, $maxLen);
}
try {
$this->getStream()->write(pack('S', $len) . $string);
} catch (StreamException $e) {
$this->handleStreamException($e, BinaryStreamAccessException::STRING, false);
}
} | php | public function writeString($string)
{
// $maxLen = 2^16 -1 = max val of unsigned short integer.
$maxLen = 65535;
$len = strlen($string);
if ($len > $maxLen) {
$len = $maxLen;
$string = substr($string, 0, $maxLen);
}
try {
$this->getStream()->write(pack('S', $len) . $string);
} catch (StreamException $e) {
$this->handleStreamException($e, BinaryStreamAccessException::STRING, false);
}
} | [
"public",
"function",
"writeString",
"(",
"$",
"string",
")",
"{",
"// $maxLen = 2^16 -1 = max val of unsigned short integer.",
"$",
"maxLen",
"=",
"65535",
";",
"$",
"len",
"=",
"strlen",
"(",
"$",
"string",
")",
";",
"if",
"(",
"$",
"len",
">",
"$",
"maxLen",
")",
"{",
"$",
"len",
"=",
"$",
"maxLen",
";",
"$",
"string",
"=",
"substr",
"(",
"$",
"string",
",",
"0",
",",
"$",
"maxLen",
")",
";",
"}",
"try",
"{",
"$",
"this",
"->",
"getStream",
"(",
")",
"->",
"write",
"(",
"pack",
"(",
"'S'",
",",
"$",
"len",
")",
".",
"$",
"string",
")",
";",
"}",
"catch",
"(",
"StreamException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"handleStreamException",
"(",
"$",
"e",
",",
"BinaryStreamAccessException",
"::",
"STRING",
",",
"false",
")",
";",
"}",
"}"
] | Write a string value from in the current binary string.
@param string $string
@throws \qtism\common\storage\BinaryStreamAccessException | [
"Write",
"a",
"string",
"value",
"from",
"in",
"the",
"current",
"binary",
"string",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/storage/BinaryStreamAccess.php#L236-L252 |
oat-sa/qti-sdk | src/qtism/common/storage/BinaryStreamAccess.php | BinaryStreamAccess.readDateTime | public function readDateTime()
{
try {
$timeStamp = current(unpack('l', $this->getStream()->read(4)));
$date = new DateTime('now', new \DateTimeZone('UTC'));
return $date->setTimestamp($timeStamp);
} catch (StreamException $e) {
$this->handleStreamException($e, BinaryStreamAccessException::DATETIME);
}
} | php | public function readDateTime()
{
try {
$timeStamp = current(unpack('l', $this->getStream()->read(4)));
$date = new DateTime('now', new \DateTimeZone('UTC'));
return $date->setTimestamp($timeStamp);
} catch (StreamException $e) {
$this->handleStreamException($e, BinaryStreamAccessException::DATETIME);
}
} | [
"public",
"function",
"readDateTime",
"(",
")",
"{",
"try",
"{",
"$",
"timeStamp",
"=",
"current",
"(",
"unpack",
"(",
"'l'",
",",
"$",
"this",
"->",
"getStream",
"(",
")",
"->",
"read",
"(",
"4",
")",
")",
")",
";",
"$",
"date",
"=",
"new",
"DateTime",
"(",
"'now'",
",",
"new",
"\\",
"DateTimeZone",
"(",
"'UTC'",
")",
")",
";",
"return",
"$",
"date",
"->",
"setTimestamp",
"(",
"$",
"timeStamp",
")",
";",
"}",
"catch",
"(",
"StreamException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"handleStreamException",
"(",
"$",
"e",
",",
"BinaryStreamAccessException",
"::",
"DATETIME",
")",
";",
"}",
"}"
] | Read a DateTime from the current binary stream.
@return \DateTime A DateTime object.
@throws \qtism\common\storage\BinaryStreamAccessException | [
"Read",
"a",
"DateTime",
"from",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/storage/BinaryStreamAccess.php#L282-L292 |
oat-sa/qti-sdk | src/qtism/common/storage/BinaryStreamAccess.php | BinaryStreamAccess.writeDateTime | public function writeDateTime(DateTime $dateTime)
{
try {
$timeStamp = $dateTime->getTimestamp();
$this->getStream()->write(pack('l', $timeStamp));
} catch (StreamException $e) {
$this->handleStreamException($e, BinaryStreamAccessException::DATETIME, false);
}
} | php | public function writeDateTime(DateTime $dateTime)
{
try {
$timeStamp = $dateTime->getTimestamp();
$this->getStream()->write(pack('l', $timeStamp));
} catch (StreamException $e) {
$this->handleStreamException($e, BinaryStreamAccessException::DATETIME, false);
}
} | [
"public",
"function",
"writeDateTime",
"(",
"DateTime",
"$",
"dateTime",
")",
"{",
"try",
"{",
"$",
"timeStamp",
"=",
"$",
"dateTime",
"->",
"getTimestamp",
"(",
")",
";",
"$",
"this",
"->",
"getStream",
"(",
")",
"->",
"write",
"(",
"pack",
"(",
"'l'",
",",
"$",
"timeStamp",
")",
")",
";",
"}",
"catch",
"(",
"StreamException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"handleStreamException",
"(",
"$",
"e",
",",
"BinaryStreamAccessException",
"::",
"DATETIME",
",",
"false",
")",
";",
"}",
"}"
] | Write a DateTime from the current binary stream.
@param \DateTime $dateTime A DateTime object.
@throws \qtism\common\storage\BinaryStreamAccessException | [
"Write",
"a",
"DateTime",
"from",
"the",
"current",
"binary",
"stream",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/storage/BinaryStreamAccess.php#L300-L308 |
oat-sa/qti-sdk | src/qtism/common/storage/BinaryStreamAccess.php | BinaryStreamAccess.handleStreamException | protected function handleStreamException(StreamException $e, $typeError, $read = true)
{
$strType = 'unknown datatype';
switch ($typeError) {
case BinaryStreamAccessException::BOOLEAN:
$strType = 'boolean';
break;
case BinaryStreamAccessException::BINARY:
$strType = 'binary data';
break;
case BinaryStreamAccessException::FLOAT:
$strType = 'double precision float';
break;
case BinaryStreamAccessException::INT:
$strType = 'integer';
break;
case BinaryStreamAccessException::SHORT:
$strType = 'short integer';
break;
case BinaryStreamAccessException::STRING:
$strType = 'string';
break;
case BinaryStreamAccessException::TINYINT:
$strType = 'tiny integer';
break;
case BinaryStreamAccessException::DATETIME:
$strType = 'datetime';
break;
}
$strAction = ($read === true) ? 'reading' : 'writing';
switch ($e->getCode()) {
case StreamException::NOT_OPEN:
$strAction = ucfirst($strAction);
$msg = "${strAction} a ${strType} from a closed binary stream is not permitted.";
throw new BinaryStreamAccessException($msg, $this, BinaryStreamAccessException::NOT_OPEN, $e);
break;
case StreamException::READ:
$msg = "An error occured while ${strAction} a ${strType}.";
throw new BinaryStreamAccessException($msg, $this, $typeError, $e);
break;
default:
$msg = "An unknown error occured while ${strAction} a ${strType}.";
throw new BinaryStreamAccessException($msg, $this, BinaryStreamAccessException::UNKNOWN, $e);
break;
}
} | php | protected function handleStreamException(StreamException $e, $typeError, $read = true)
{
$strType = 'unknown datatype';
switch ($typeError) {
case BinaryStreamAccessException::BOOLEAN:
$strType = 'boolean';
break;
case BinaryStreamAccessException::BINARY:
$strType = 'binary data';
break;
case BinaryStreamAccessException::FLOAT:
$strType = 'double precision float';
break;
case BinaryStreamAccessException::INT:
$strType = 'integer';
break;
case BinaryStreamAccessException::SHORT:
$strType = 'short integer';
break;
case BinaryStreamAccessException::STRING:
$strType = 'string';
break;
case BinaryStreamAccessException::TINYINT:
$strType = 'tiny integer';
break;
case BinaryStreamAccessException::DATETIME:
$strType = 'datetime';
break;
}
$strAction = ($read === true) ? 'reading' : 'writing';
switch ($e->getCode()) {
case StreamException::NOT_OPEN:
$strAction = ucfirst($strAction);
$msg = "${strAction} a ${strType} from a closed binary stream is not permitted.";
throw new BinaryStreamAccessException($msg, $this, BinaryStreamAccessException::NOT_OPEN, $e);
break;
case StreamException::READ:
$msg = "An error occured while ${strAction} a ${strType}.";
throw new BinaryStreamAccessException($msg, $this, $typeError, $e);
break;
default:
$msg = "An unknown error occured while ${strAction} a ${strType}.";
throw new BinaryStreamAccessException($msg, $this, BinaryStreamAccessException::UNKNOWN, $e);
break;
}
} | [
"protected",
"function",
"handleStreamException",
"(",
"StreamException",
"$",
"e",
",",
"$",
"typeError",
",",
"$",
"read",
"=",
"true",
")",
"{",
"$",
"strType",
"=",
"'unknown datatype'",
";",
"switch",
"(",
"$",
"typeError",
")",
"{",
"case",
"BinaryStreamAccessException",
"::",
"BOOLEAN",
":",
"$",
"strType",
"=",
"'boolean'",
";",
"break",
";",
"case",
"BinaryStreamAccessException",
"::",
"BINARY",
":",
"$",
"strType",
"=",
"'binary data'",
";",
"break",
";",
"case",
"BinaryStreamAccessException",
"::",
"FLOAT",
":",
"$",
"strType",
"=",
"'double precision float'",
";",
"break",
";",
"case",
"BinaryStreamAccessException",
"::",
"INT",
":",
"$",
"strType",
"=",
"'integer'",
";",
"break",
";",
"case",
"BinaryStreamAccessException",
"::",
"SHORT",
":",
"$",
"strType",
"=",
"'short integer'",
";",
"break",
";",
"case",
"BinaryStreamAccessException",
"::",
"STRING",
":",
"$",
"strType",
"=",
"'string'",
";",
"break",
";",
"case",
"BinaryStreamAccessException",
"::",
"TINYINT",
":",
"$",
"strType",
"=",
"'tiny integer'",
";",
"break",
";",
"case",
"BinaryStreamAccessException",
"::",
"DATETIME",
":",
"$",
"strType",
"=",
"'datetime'",
";",
"break",
";",
"}",
"$",
"strAction",
"=",
"(",
"$",
"read",
"===",
"true",
")",
"?",
"'reading'",
":",
"'writing'",
";",
"switch",
"(",
"$",
"e",
"->",
"getCode",
"(",
")",
")",
"{",
"case",
"StreamException",
"::",
"NOT_OPEN",
":",
"$",
"strAction",
"=",
"ucfirst",
"(",
"$",
"strAction",
")",
";",
"$",
"msg",
"=",
"\"${strAction} a ${strType} from a closed binary stream is not permitted.\"",
";",
"throw",
"new",
"BinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"BinaryStreamAccessException",
"::",
"NOT_OPEN",
",",
"$",
"e",
")",
";",
"break",
";",
"case",
"StreamException",
"::",
"READ",
":",
"$",
"msg",
"=",
"\"An error occured while ${strAction} a ${strType}.\"",
";",
"throw",
"new",
"BinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"$",
"typeError",
",",
"$",
"e",
")",
";",
"break",
";",
"default",
":",
"$",
"msg",
"=",
"\"An unknown error occured while ${strAction} a ${strType}.\"",
";",
"throw",
"new",
"BinaryStreamAccessException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"BinaryStreamAccessException",
"::",
"UNKNOWN",
",",
"$",
"e",
")",
";",
"break",
";",
"}",
"}"
] | Handle a StreamException in order to throw the relevant BinaryStreamAccessException.
@param \qtism\common\storage\StreamException $e The StreamException object to deal with.
@param integer $typeError The BinaryStreamAccess exception code to be thrown in case of error.
@param boolean $read Wheter or not the error occured in a reading/writing context.
@throws \qtism\common\storage\BinaryStreamAccessException The resulting BinaryStreamAccessException. | [
"Handle",
"a",
"StreamException",
"in",
"order",
"to",
"throw",
"the",
"relevant",
"BinaryStreamAccessException",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/storage/BinaryStreamAccess.php#L318-L375 |
oat-sa/qti-sdk | src/qtism/data/QtiComponent.php | QtiComponent.getComponentByIdentifier | public function getComponentByIdentifier($identifier, $recursive = true)
{
if (gettype($identifier) !== 'string') {
$msg = "The QtiComponent::getComponentByIdentifier method only accepts a string as its ";
$msg.= "argument. '" . gettype($identifier) . "' given.";
throw new InvalidArgumentException($msg);
}
$toIterate = ($recursive === true) ? $this->getIterator() : $this->getComponents();
foreach ($toIterate as $component) {
if ($component instanceof QtiIdentifiable && $component->getIdentifier() === $identifier) {
return $component;
}
}
return null;
} | php | public function getComponentByIdentifier($identifier, $recursive = true)
{
if (gettype($identifier) !== 'string') {
$msg = "The QtiComponent::getComponentByIdentifier method only accepts a string as its ";
$msg.= "argument. '" . gettype($identifier) . "' given.";
throw new InvalidArgumentException($msg);
}
$toIterate = ($recursive === true) ? $this->getIterator() : $this->getComponents();
foreach ($toIterate as $component) {
if ($component instanceof QtiIdentifiable && $component->getIdentifier() === $identifier) {
return $component;
}
}
return null;
} | [
"public",
"function",
"getComponentByIdentifier",
"(",
"$",
"identifier",
",",
"$",
"recursive",
"=",
"true",
")",
"{",
"if",
"(",
"gettype",
"(",
"$",
"identifier",
")",
"!==",
"'string'",
")",
"{",
"$",
"msg",
"=",
"\"The QtiComponent::getComponentByIdentifier method only accepts a string as its \"",
";",
"$",
"msg",
".=",
"\"argument. '\"",
".",
"gettype",
"(",
"$",
"identifier",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"$",
"toIterate",
"=",
"(",
"$",
"recursive",
"===",
"true",
")",
"?",
"$",
"this",
"->",
"getIterator",
"(",
")",
":",
"$",
"this",
"->",
"getComponents",
"(",
")",
";",
"foreach",
"(",
"$",
"toIterate",
"as",
"$",
"component",
")",
"{",
"if",
"(",
"$",
"component",
"instanceof",
"QtiIdentifiable",
"&&",
"$",
"component",
"->",
"getIdentifier",
"(",
")",
"===",
"$",
"identifier",
")",
"{",
"return",
"$",
"component",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Get a QtiComponent object which is contained by this one on the basis
of a given $identifier.
@param string $identifier The identifier to search for.
@param boolean $recursive Whether to search recursively in contained QtiComponent objects.
@return \qtism\data\QtiComponent|null A QtiComponent object or null if not found.
@throws \InvalidArgumentException If $identifier is not a string. | [
"Get",
"a",
"QtiComponent",
"object",
"which",
"is",
"contained",
"by",
"this",
"one",
"on",
"the",
"basis",
"of",
"a",
"given",
"$identifier",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/QtiComponent.php#L70-L87 |
oat-sa/qti-sdk | src/qtism/data/QtiComponent.php | QtiComponent.getComponentsByClassName | public function getComponentsByClassName($classNames, $recursive = true)
{
if (gettype($classNames) !== 'string' && !is_array($classNames)) {
$msg = "The QtiComponent::getComponentsByClassName method only accepts ";
$msg.= "a string or an array as its main argument, '" . gettype($classNames) . "' given.";
throw new InvalidArgumentException($classNames);
}
if (!is_array($classNames)) {
$classNames = array($classNames);
}
$toIterate = ($recursive === true) ? $this->getIterator() : $this->getComponents();
$foundComponents = new QtiComponentCollection();
foreach ($toIterate as $component) {
if (in_array($component->getQtiClassName(), $classNames)) {
$foundComponents[] = $component;
}
}
return $foundComponents;
} | php | public function getComponentsByClassName($classNames, $recursive = true)
{
if (gettype($classNames) !== 'string' && !is_array($classNames)) {
$msg = "The QtiComponent::getComponentsByClassName method only accepts ";
$msg.= "a string or an array as its main argument, '" . gettype($classNames) . "' given.";
throw new InvalidArgumentException($classNames);
}
if (!is_array($classNames)) {
$classNames = array($classNames);
}
$toIterate = ($recursive === true) ? $this->getIterator() : $this->getComponents();
$foundComponents = new QtiComponentCollection();
foreach ($toIterate as $component) {
if (in_array($component->getQtiClassName(), $classNames)) {
$foundComponents[] = $component;
}
}
return $foundComponents;
} | [
"public",
"function",
"getComponentsByClassName",
"(",
"$",
"classNames",
",",
"$",
"recursive",
"=",
"true",
")",
"{",
"if",
"(",
"gettype",
"(",
"$",
"classNames",
")",
"!==",
"'string'",
"&&",
"!",
"is_array",
"(",
"$",
"classNames",
")",
")",
"{",
"$",
"msg",
"=",
"\"The QtiComponent::getComponentsByClassName method only accepts \"",
";",
"$",
"msg",
".=",
"\"a string or an array as its main argument, '\"",
".",
"gettype",
"(",
"$",
"classNames",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"classNames",
")",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"classNames",
")",
")",
"{",
"$",
"classNames",
"=",
"array",
"(",
"$",
"classNames",
")",
";",
"}",
"$",
"toIterate",
"=",
"(",
"$",
"recursive",
"===",
"true",
")",
"?",
"$",
"this",
"->",
"getIterator",
"(",
")",
":",
"$",
"this",
"->",
"getComponents",
"(",
")",
";",
"$",
"foundComponents",
"=",
"new",
"QtiComponentCollection",
"(",
")",
";",
"foreach",
"(",
"$",
"toIterate",
"as",
"$",
"component",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"component",
"->",
"getQtiClassName",
"(",
")",
",",
"$",
"classNames",
")",
")",
"{",
"$",
"foundComponents",
"[",
"]",
"=",
"$",
"component",
";",
"}",
"}",
"return",
"$",
"foundComponents",
";",
"}"
] | Get QtiComponents object which is contained by this one the basis of
a given QTI className. If nothing found, an empty QtiComponentCollection
object is returned.
Example where we look for all assessmentSection class instances contained
in an assessmentTest.
<code>
$search = $assessmentTest->getComponentByClassName('assessmentSection');
// $search contains a QTIComponentCollection composed of AssessmentSection objects.
</code>
@param array|string An array of strings or a string.
@param boolean $recursive Whether to search recursively in contained QtiComponent objects.
@return \qtism\data\QtiComponentCollection
@throws \InvalidArgumentException If $classNames is not an array nor a string value. | [
"Get",
"QtiComponents",
"object",
"which",
"is",
"contained",
"by",
"this",
"one",
"the",
"basis",
"of",
"a",
"given",
"QTI",
"className",
".",
"If",
"nothing",
"found",
"an",
"empty",
"QtiComponentCollection",
"object",
"is",
"returned",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/QtiComponent.php#L106-L128 |
oat-sa/qti-sdk | src/qtism/data/QtiComponent.php | QtiComponent.getIdentifiableComponents | public function getIdentifiableComponents($recursive = true)
{
$iterator = ($recursive === true) ? $this->getIterator() : $this->getComponents();
$foundComponents = array();
$identifiers = array();
$collision = false;
foreach ($iterator as $component) {
if ($component instanceof QtiIdentifiable) {
$foundComponents[] = $component;
$identifier = $component->getIdentifier();
if (in_array($identifier, $identifiers) === true && $collision === false) {
$collision = true;
}
$identifiers[] = $identifier;
}
}
return ($collision === true) ? new QtiComponentCollection($foundComponents) : new QtiIdentifiableCollection($foundComponents);
} | php | public function getIdentifiableComponents($recursive = true)
{
$iterator = ($recursive === true) ? $this->getIterator() : $this->getComponents();
$foundComponents = array();
$identifiers = array();
$collision = false;
foreach ($iterator as $component) {
if ($component instanceof QtiIdentifiable) {
$foundComponents[] = $component;
$identifier = $component->getIdentifier();
if (in_array($identifier, $identifiers) === true && $collision === false) {
$collision = true;
}
$identifiers[] = $identifier;
}
}
return ($collision === true) ? new QtiComponentCollection($foundComponents) : new QtiIdentifiableCollection($foundComponents);
} | [
"public",
"function",
"getIdentifiableComponents",
"(",
"$",
"recursive",
"=",
"true",
")",
"{",
"$",
"iterator",
"=",
"(",
"$",
"recursive",
"===",
"true",
")",
"?",
"$",
"this",
"->",
"getIterator",
"(",
")",
":",
"$",
"this",
"->",
"getComponents",
"(",
")",
";",
"$",
"foundComponents",
"=",
"array",
"(",
")",
";",
"$",
"identifiers",
"=",
"array",
"(",
")",
";",
"$",
"collision",
"=",
"false",
";",
"foreach",
"(",
"$",
"iterator",
"as",
"$",
"component",
")",
"{",
"if",
"(",
"$",
"component",
"instanceof",
"QtiIdentifiable",
")",
"{",
"$",
"foundComponents",
"[",
"]",
"=",
"$",
"component",
";",
"$",
"identifier",
"=",
"$",
"component",
"->",
"getIdentifier",
"(",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"identifier",
",",
"$",
"identifiers",
")",
"===",
"true",
"&&",
"$",
"collision",
"===",
"false",
")",
"{",
"$",
"collision",
"=",
"true",
";",
"}",
"$",
"identifiers",
"[",
"]",
"=",
"$",
"identifier",
";",
"}",
"}",
"return",
"(",
"$",
"collision",
"===",
"true",
")",
"?",
"new",
"QtiComponentCollection",
"(",
"$",
"foundComponents",
")",
":",
"new",
"QtiIdentifiableCollection",
"(",
"$",
"foundComponents",
")",
";",
"}"
] | Get the QtiIdentifiableComponent object contained by this QtiComponent. Be carefull,
the type of the returned collection depends on the values collected:
* If all the objects found have a unique identifier within the retrieved set, a QtiIdentifiableCollection is returned.
* If an identifier collision occurs within the retrieved set, a QtiComponentCollection is returned.
@param boolean $recursive Whether to search recursively in contained QtiComponent objects.
@return \qtism\data\QtiComponentCollection A QtiIdentifiableCollection or a QtiComponentCollection in case of collision. | [
"Get",
"the",
"QtiIdentifiableComponent",
"object",
"contained",
"by",
"this",
"QtiComponent",
".",
"Be",
"carefull",
"the",
"type",
"of",
"the",
"returned",
"collection",
"depends",
"on",
"the",
"values",
"collected",
":"
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/QtiComponent.php#L140-L161 |
oat-sa/qti-sdk | src/qtism/data/QtiComponent.php | QtiComponent.containsComponentWithClassName | public function containsComponentWithClassName($classNames, $recursive = true) {
if (is_array($classNames) === false) {
$classNames = array($classNames);
}
$iterator = ($recursive === true) ? $this->getIterator($classNames) : $this->getComponents();
foreach ($iterator as $component) {
if (in_array($component->getQtiClassName(), $classNames)) {
return true;
}
}
return false;
} | php | public function containsComponentWithClassName($classNames, $recursive = true) {
if (is_array($classNames) === false) {
$classNames = array($classNames);
}
$iterator = ($recursive === true) ? $this->getIterator($classNames) : $this->getComponents();
foreach ($iterator as $component) {
if (in_array($component->getQtiClassName(), $classNames)) {
return true;
}
}
return false;
} | [
"public",
"function",
"containsComponentWithClassName",
"(",
"$",
"classNames",
",",
"$",
"recursive",
"=",
"true",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"classNames",
")",
"===",
"false",
")",
"{",
"$",
"classNames",
"=",
"array",
"(",
"$",
"classNames",
")",
";",
"}",
"$",
"iterator",
"=",
"(",
"$",
"recursive",
"===",
"true",
")",
"?",
"$",
"this",
"->",
"getIterator",
"(",
"$",
"classNames",
")",
":",
"$",
"this",
"->",
"getComponents",
"(",
")",
";",
"foreach",
"(",
"$",
"iterator",
"as",
"$",
"component",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"component",
"->",
"getQtiClassName",
"(",
")",
",",
"$",
"classNames",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Whether the component contains child components with class $classNames.
@param string|array $classNames
@param boolean $recursive Whether to search recursively in contained QtiComponent objects.
@return boolean | [
"Whether",
"the",
"component",
"contains",
"child",
"components",
"with",
"class",
"$classNames",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/QtiComponent.php#L170-L183 |
oat-sa/qti-sdk | src/qtism/runtime/expressions/operators/IntegerDivideProcessor.php | IntegerDivideProcessor.process | public function process()
{
$operands = $this->getOperands();
if ($operands->containsNull() === true) {
return null;
}
if ($operands->exclusivelySingle() === false) {
$msg = "The IntegerDivide operator only accepts operands with single cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
if ($operands->exclusivelyInteger() === false) {
$msg = "The IntegerDivide operator only accepts operands with baseType integer.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
}
$operand1 = $operands[0];
$operand2 = $operands[1];
if ($operand2->getValue() == 0) {
// division by zero forbidden.
return null;
}
return new QtiInteger(intval(floor($operand1->getValue() / $operand2->getValue())));
} | php | public function process()
{
$operands = $this->getOperands();
if ($operands->containsNull() === true) {
return null;
}
if ($operands->exclusivelySingle() === false) {
$msg = "The IntegerDivide operator only accepts operands with single cardinality.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
}
if ($operands->exclusivelyInteger() === false) {
$msg = "The IntegerDivide operator only accepts operands with baseType integer.";
throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
}
$operand1 = $operands[0];
$operand2 = $operands[1];
if ($operand2->getValue() == 0) {
// division by zero forbidden.
return null;
}
return new QtiInteger(intval(floor($operand1->getValue() / $operand2->getValue())));
} | [
"public",
"function",
"process",
"(",
")",
"{",
"$",
"operands",
"=",
"$",
"this",
"->",
"getOperands",
"(",
")",
";",
"if",
"(",
"$",
"operands",
"->",
"containsNull",
"(",
")",
"===",
"true",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"operands",
"->",
"exclusivelySingle",
"(",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The IntegerDivide operator only accepts operands with single cardinality.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_CARDINALITY",
")",
";",
"}",
"if",
"(",
"$",
"operands",
"->",
"exclusivelyInteger",
"(",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The IntegerDivide operator only accepts operands with baseType integer.\"",
";",
"throw",
"new",
"OperatorProcessingException",
"(",
"$",
"msg",
",",
"$",
"this",
",",
"OperatorProcessingException",
"::",
"WRONG_BASETYPE",
")",
";",
"}",
"$",
"operand1",
"=",
"$",
"operands",
"[",
"0",
"]",
";",
"$",
"operand2",
"=",
"$",
"operands",
"[",
"1",
"]",
";",
"if",
"(",
"$",
"operand2",
"->",
"getValue",
"(",
")",
"==",
"0",
")",
"{",
"// division by zero forbidden.",
"return",
"null",
";",
"}",
"return",
"new",
"QtiInteger",
"(",
"intval",
"(",
"floor",
"(",
"$",
"operand1",
"->",
"getValue",
"(",
")",
"/",
"$",
"operand2",
"->",
"getValue",
"(",
")",
")",
")",
")",
";",
"}"
] | Process the IntegerDivide operator.
@return integer|null An integer value that corresponds to the first expression divided by the second rounded down to the greatest integer i such that i <= x / y. If the second expression is 0 or if either of the sub-expressions is NULL, the result is NULL. | [
"Process",
"the",
"IntegerDivide",
"operator",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/IntegerDivideProcessor.php#L51-L78 |
oat-sa/qti-sdk | src/qtism/data/content/interactions/SliderInteraction.php | SliderInteraction.setLowerBound | public function setLowerBound($lowerBound)
{
if (is_float($lowerBound) === true) {
$this->lowerBound = $lowerBound;
} else {
$msg = "The 'lowerBound' argument must be a float value, '" . gettype($lowerBound) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setLowerBound($lowerBound)
{
if (is_float($lowerBound) === true) {
$this->lowerBound = $lowerBound;
} else {
$msg = "The 'lowerBound' argument must be a float value, '" . gettype($lowerBound) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setLowerBound",
"(",
"$",
"lowerBound",
")",
"{",
"if",
"(",
"is_float",
"(",
"$",
"lowerBound",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"lowerBound",
"=",
"$",
"lowerBound",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'lowerBound' argument must be a float value, '\"",
".",
"gettype",
"(",
"$",
"lowerBound",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Get the value of the lowerBound attribute.
@param float $lowerBound A float value.
@throws \InvalidArgumentException If $lowerBound is not a float value. | [
"Get",
"the",
"value",
"of",
"the",
"lowerBound",
"attribute",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/interactions/SliderInteraction.php#L163-L171 |
oat-sa/qti-sdk | src/qtism/data/content/interactions/SliderInteraction.php | SliderInteraction.setUpperBound | public function setUpperBound($upperBound)
{
if (is_float($upperBound) === true) {
$this->upperBound = $upperBound;
} else {
$msg = "The 'upperBound' argument must be a float value, '" . gettype($upperBound) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setUpperBound($upperBound)
{
if (is_float($upperBound) === true) {
$this->upperBound = $upperBound;
} else {
$msg = "The 'upperBound' argument must be a float value, '" . gettype($upperBound) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setUpperBound",
"(",
"$",
"upperBound",
")",
"{",
"if",
"(",
"is_float",
"(",
"$",
"upperBound",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"upperBound",
"=",
"$",
"upperBound",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'upperBound' argument must be a float value, '\"",
".",
"gettype",
"(",
"$",
"upperBound",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the value of the upperBound attribute.
@param float $upperBound A float value.
@throws \InvalidArgumentException If $upperBound is not a float value. | [
"Set",
"the",
"value",
"of",
"the",
"upperBound",
"attribute",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/interactions/SliderInteraction.php#L189-L197 |
oat-sa/qti-sdk | src/qtism/data/content/interactions/SliderInteraction.php | SliderInteraction.setStepLabel | public function setStepLabel($stepLabel)
{
if (is_bool($stepLabel) === true) {
$this->stepLabel = $stepLabel;
} else {
$msg = "The 'stepLabel' argument must be a boolean value, '" . gettype($stepLabel) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setStepLabel($stepLabel)
{
if (is_bool($stepLabel) === true) {
$this->stepLabel = $stepLabel;
} else {
$msg = "The 'stepLabel' argument must be a boolean value, '" . gettype($stepLabel) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setStepLabel",
"(",
"$",
"stepLabel",
")",
"{",
"if",
"(",
"is_bool",
"(",
"$",
"stepLabel",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"stepLabel",
"=",
"$",
"stepLabel",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'stepLabel' argument must be a boolean value, '\"",
".",
"gettype",
"(",
"$",
"stepLabel",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set whether or not each step on the slider has to be labelled.
@param boolean $stepLabel
@throws \InvalidArgumentException If $stepLabel is not a boolean value. | [
"Set",
"whether",
"or",
"not",
"each",
"step",
"on",
"the",
"slider",
"has",
"to",
"be",
"labelled",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/interactions/SliderInteraction.php#L252-L260 |
oat-sa/qti-sdk | src/qtism/data/content/interactions/SliderInteraction.php | SliderInteraction.setOrientation | public function setOrientation($orientation)
{
if (in_array($orientation, Orientation::asArray(), true) === true) {
$this->orientation = $orientation;
} else {
$msg = "The 'orientation' argument must be a value from the Orientation enumeration.";
throw new InvalidArgumentException($msg);
}
} | php | public function setOrientation($orientation)
{
if (in_array($orientation, Orientation::asArray(), true) === true) {
$this->orientation = $orientation;
} else {
$msg = "The 'orientation' argument must be a value from the Orientation enumeration.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setOrientation",
"(",
"$",
"orientation",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"orientation",
",",
"Orientation",
"::",
"asArray",
"(",
")",
",",
"true",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"orientation",
"=",
"$",
"orientation",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'orientation' argument must be a value from the Orientation enumeration.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the orientation of the slider (horizontal or vertical).
@param integer $orientation A value from the Orientation enumeration.
@throws \InvalidArgumentException If $orientation is not a value from the Orientation enumeration. | [
"Set",
"the",
"orientation",
"of",
"the",
"slider",
"(",
"horizontal",
"or",
"vertical",
")",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/interactions/SliderInteraction.php#L278-L286 |
oat-sa/qti-sdk | src/qtism/data/content/interactions/SliderInteraction.php | SliderInteraction.setReverse | public function setReverse($reverse)
{
if (is_bool($reverse) === true) {
$this->reverse = $reverse;
} else {
$msg = "The 'reverse' argument must be a boolean value, '" . gettype($reverse) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setReverse($reverse)
{
if (is_bool($reverse) === true) {
$this->reverse = $reverse;
} else {
$msg = "The 'reverse' argument must be a boolean value, '" . gettype($reverse) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setReverse",
"(",
"$",
"reverse",
")",
"{",
"if",
"(",
"is_bool",
"(",
"$",
"reverse",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"reverse",
"=",
"$",
"reverse",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'reverse' argument must be a boolean value, '\"",
".",
"gettype",
"(",
"$",
"reverse",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set whether or not the upper and lower bounds are reversed.
@param boolean $reverse
@throws \InvalidArgumentException If $reverse is not a boolean value. | [
"Set",
"whether",
"or",
"not",
"the",
"upper",
"and",
"lower",
"bounds",
"are",
"reversed",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/interactions/SliderInteraction.php#L304-L312 |
oat-sa/qti-sdk | src/qtism/data/content/Stylesheet.php | Stylesheet.setType | public function setType($type)
{
if (gettype($type) === 'string') {
$this->type = $type;
} else {
$msg = "Type must be a string, '" . gettype($type) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setType($type)
{
if (gettype($type) === 'string') {
$this->type = $type;
} else {
$msg = "Type must be a string, '" . gettype($type) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setType",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"gettype",
"(",
"$",
"type",
")",
"===",
"'string'",
")",
"{",
"$",
"this",
"->",
"type",
"=",
"$",
"type",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"Type must be a string, '\"",
".",
"gettype",
"(",
"$",
"type",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the mime-type of the stylesheet.
@param string $type A mime-type.
@throws \InvalidArgumentException If $type is not a string. | [
"Set",
"the",
"mime",
"-",
"type",
"of",
"the",
"stylesheet",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/Stylesheet.php#L137-L145 |
oat-sa/qti-sdk | src/qtism/data/content/Stylesheet.php | Stylesheet.setMedia | public function setMedia($media)
{
if (is_string($media)) {
$this->media = $media;
} else {
$msg = "Media must be a string, '" . gettype($media) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setMedia($media)
{
if (is_string($media)) {
$this->media = $media;
} else {
$msg = "Media must be a string, '" . gettype($media) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setMedia",
"(",
"$",
"media",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"media",
")",
")",
"{",
"$",
"this",
"->",
"media",
"=",
"$",
"media",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"Media must be a string, '\"",
".",
"gettype",
"(",
"$",
"media",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the media to apply the stylesheet on.
@param string $media A media.
@throws \InvalidArgumentException If $media is not a string. | [
"Set",
"the",
"media",
"to",
"apply",
"the",
"stylesheet",
"on",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/Stylesheet.php#L163-L171 |
oat-sa/qti-sdk | src/qtism/data/QtiIdentifiableCollection.php | QtiIdentifiableCollection.offsetExists | public function offsetExists($offset)
{
if (gettype($offset) !== 'string' && empty($offset) === false) {
$msg = "The requested offset must be a string.";
throw new OutOfRangeException($msg);
}
$data = &$this->getDataPlaceHolder();
return isset($data[$offset]);
} | php | public function offsetExists($offset)
{
if (gettype($offset) !== 'string' && empty($offset) === false) {
$msg = "The requested offset must be a string.";
throw new OutOfRangeException($msg);
}
$data = &$this->getDataPlaceHolder();
return isset($data[$offset]);
} | [
"public",
"function",
"offsetExists",
"(",
"$",
"offset",
")",
"{",
"if",
"(",
"gettype",
"(",
"$",
"offset",
")",
"!==",
"'string'",
"&&",
"empty",
"(",
"$",
"offset",
")",
"===",
"false",
")",
"{",
"$",
"msg",
"=",
"\"The requested offset must be a string.\"",
";",
"throw",
"new",
"OutOfRangeException",
"(",
"$",
"msg",
")",
";",
"}",
"$",
"data",
"=",
"&",
"$",
"this",
"->",
"getDataPlaceHolder",
"(",
")",
";",
"return",
"isset",
"(",
"$",
"data",
"[",
"$",
"offset",
"]",
")",
";",
"}"
] | Whether a QtiIdentifiable object with 'identifier' = $offset is in
the collection.
@return boolean
@throws \OutOfRangeException If the request $offset is not a string or is empty. | [
"Whether",
"a",
"QtiIdentifiable",
"object",
"with",
"identifier",
"=",
"$offset",
"is",
"in",
"the",
"collection",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/QtiIdentifiableCollection.php#L69-L79 |
oat-sa/qti-sdk | src/qtism/data/QtiIdentifiableCollection.php | QtiIdentifiableCollection.offsetGet | public function offsetGet($offset)
{
if (gettype($offset) !== 'string') {
$msg = "The requested offset must be a non-empty string.";
throw new OutOfRangeException($msg);
}
$returnValue = null;
$data = &$this->getDataPlaceHolder();
if (isset($data[$offset]) === true) {
$returnValue = $data[$offset];
}
return $returnValue;
} | php | public function offsetGet($offset)
{
if (gettype($offset) !== 'string') {
$msg = "The requested offset must be a non-empty string.";
throw new OutOfRangeException($msg);
}
$returnValue = null;
$data = &$this->getDataPlaceHolder();
if (isset($data[$offset]) === true) {
$returnValue = $data[$offset];
}
return $returnValue;
} | [
"public",
"function",
"offsetGet",
"(",
"$",
"offset",
")",
"{",
"if",
"(",
"gettype",
"(",
"$",
"offset",
")",
"!==",
"'string'",
")",
"{",
"$",
"msg",
"=",
"\"The requested offset must be a non-empty string.\"",
";",
"throw",
"new",
"OutOfRangeException",
"(",
"$",
"msg",
")",
";",
"}",
"$",
"returnValue",
"=",
"null",
";",
"$",
"data",
"=",
"&",
"$",
"this",
"->",
"getDataPlaceHolder",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"$",
"offset",
"]",
")",
"===",
"true",
")",
"{",
"$",
"returnValue",
"=",
"$",
"data",
"[",
"$",
"offset",
"]",
";",
"}",
"return",
"$",
"returnValue",
";",
"}"
] | Retrieve a QtiIdentifiable object from the collection.
@return \qtism\data\QtiIdentifiable|null The requested QtiIdentifiable object or null if no object with 'identifier' = $offset is found.
@throws \OutOfRangeException If the request $offset is not a string or is empty. | [
"Retrieve",
"a",
"QtiIdentifiable",
"object",
"from",
"the",
"collection",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/QtiIdentifiableCollection.php#L87-L102 |
oat-sa/qti-sdk | src/qtism/data/QtiIdentifiableCollection.php | QtiIdentifiableCollection.offsetSet | public function offsetSet($offset, $value)
{
$this->checkType($value);
if ($offset !== null) {
$msg = "No specific offset can be set in a QtiIdentifiableCollection. ";
$msg.= "The offset is always infered from the 'identifier' attribute of ";
$msg.= "the given QtiIdentifiable object. Given offset is '${offset}'.";
throw new OutOfRangeException($msg);
}
$this->dataPlaceHolder[$value->getIdentifier()] = $value;
// Listen to events thrown by this $value.
$value->attach($this);
} | php | public function offsetSet($offset, $value)
{
$this->checkType($value);
if ($offset !== null) {
$msg = "No specific offset can be set in a QtiIdentifiableCollection. ";
$msg.= "The offset is always infered from the 'identifier' attribute of ";
$msg.= "the given QtiIdentifiable object. Given offset is '${offset}'.";
throw new OutOfRangeException($msg);
}
$this->dataPlaceHolder[$value->getIdentifier()] = $value;
// Listen to events thrown by this $value.
$value->attach($this);
} | [
"public",
"function",
"offsetSet",
"(",
"$",
"offset",
",",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"checkType",
"(",
"$",
"value",
")",
";",
"if",
"(",
"$",
"offset",
"!==",
"null",
")",
"{",
"$",
"msg",
"=",
"\"No specific offset can be set in a QtiIdentifiableCollection. \"",
";",
"$",
"msg",
".=",
"\"The offset is always infered from the 'identifier' attribute of \"",
";",
"$",
"msg",
".=",
"\"the given QtiIdentifiable object. Given offset is '${offset}'.\"",
";",
"throw",
"new",
"OutOfRangeException",
"(",
"$",
"msg",
")",
";",
"}",
"$",
"this",
"->",
"dataPlaceHolder",
"[",
"$",
"value",
"->",
"getIdentifier",
"(",
")",
"]",
"=",
"$",
"value",
";",
"// Listen to events thrown by this $value.",
"$",
"value",
"->",
"attach",
"(",
"$",
"this",
")",
";",
"}"
] | Put a QtiIdentifiable object into the collection. No specific offset must be
set because the key associated to $value is always its 'identifier' attribute's
value.
@param null $offset
@param \qtism\data\QtiIdentifiable $value A QtiIdentifiable object.
@throws \InvalidArgumentException If $value is not a QtiIdentifiable object.
@throws \OutOfRangeException If the offset is not null. | [
"Put",
"a",
"QtiIdentifiable",
"object",
"into",
"the",
"collection",
".",
"No",
"specific",
"offset",
"must",
"be",
"set",
"because",
"the",
"key",
"associated",
"to",
"$value",
"is",
"always",
"its",
"identifier",
"attribute",
"s",
"value",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/QtiIdentifiableCollection.php#L114-L130 |
oat-sa/qti-sdk | src/qtism/data/QtiIdentifiableCollection.php | QtiIdentifiableCollection.offsetUnset | public function offsetUnset($offset)
{
if (gettype($offset) === 'string') {
$data = &$this->getDataPlaceHolder();
if (isset($data[$offset])) {
$data[$offset]->detach($this);
unset($data[$offset]);
}
} else {
$msg = "The requested offset must be a non-empty string.";
throw new OutOfRangeException($msg);
}
} | php | public function offsetUnset($offset)
{
if (gettype($offset) === 'string') {
$data = &$this->getDataPlaceHolder();
if (isset($data[$offset])) {
$data[$offset]->detach($this);
unset($data[$offset]);
}
} else {
$msg = "The requested offset must be a non-empty string.";
throw new OutOfRangeException($msg);
}
} | [
"public",
"function",
"offsetUnset",
"(",
"$",
"offset",
")",
"{",
"if",
"(",
"gettype",
"(",
"$",
"offset",
")",
"===",
"'string'",
")",
"{",
"$",
"data",
"=",
"&",
"$",
"this",
"->",
"getDataPlaceHolder",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"$",
"offset",
"]",
")",
")",
"{",
"$",
"data",
"[",
"$",
"offset",
"]",
"->",
"detach",
"(",
"$",
"this",
")",
";",
"unset",
"(",
"$",
"data",
"[",
"$",
"offset",
"]",
")",
";",
"}",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The requested offset must be a non-empty string.\"",
";",
"throw",
"new",
"OutOfRangeException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Remove a QTIIdentifiable object from the collection that has its
'identifier' attribute equals to $offset.
@throws \OutOfRangeException If $offset is not a string. | [
"Remove",
"a",
"QTIIdentifiable",
"object",
"from",
"the",
"collection",
"that",
"has",
"its",
"identifier",
"attribute",
"equals",
"to",
"$offset",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/QtiIdentifiableCollection.php#L152-L164 |
oat-sa/qti-sdk | src/qtism/data/QtiIdentifiableCollection.php | QtiIdentifiableCollection.replace | public function replace($object, $replacement)
{
$this->checkType($object);
$this->checkType($replacement);
if (($search = array_search($object, $this->dataPlaceHolder, true)) !== false) {
$objectKey = $search;
$replacementKey = $replacement->getIdentifier();
if ($objectKey === $replacementKey) {
// If they share the same key, just replace.
$this->dataPlaceHolder[$objectKey] = $replacement;
} else {
// Otherwise, we have to insert the $replacement object at the appropriate offset (just before $object),
// and then remove the former $object.
$objectOffset = array_search($objectKey, array_keys($this->dataPlaceHolder));
$this->dataPlaceHolder = array_merge(
array_slice($this->dataPlaceHolder, 0, $objectOffset),
array($replacementKey => $replacement),
array_slice($this->dataPlaceHolder, $objectOffset, null)
);
$this->offsetUnset($objectKey);
}
$replacement->attach($this);
$object->detach($this);
} else {
$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 (($search = array_search($object, $this->dataPlaceHolder, true)) !== false) {
$objectKey = $search;
$replacementKey = $replacement->getIdentifier();
if ($objectKey === $replacementKey) {
// If they share the same key, just replace.
$this->dataPlaceHolder[$objectKey] = $replacement;
} else {
// Otherwise, we have to insert the $replacement object at the appropriate offset (just before $object),
// and then remove the former $object.
$objectOffset = array_search($objectKey, array_keys($this->dataPlaceHolder));
$this->dataPlaceHolder = array_merge(
array_slice($this->dataPlaceHolder, 0, $objectOffset),
array($replacementKey => $replacement),
array_slice($this->dataPlaceHolder, $objectOffset, null)
);
$this->offsetUnset($objectKey);
}
$replacement->attach($this);
$object->detach($this);
} else {
$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",
"(",
"(",
"$",
"search",
"=",
"array_search",
"(",
"$",
"object",
",",
"$",
"this",
"->",
"dataPlaceHolder",
",",
"true",
")",
")",
"!==",
"false",
")",
"{",
"$",
"objectKey",
"=",
"$",
"search",
";",
"$",
"replacementKey",
"=",
"$",
"replacement",
"->",
"getIdentifier",
"(",
")",
";",
"if",
"(",
"$",
"objectKey",
"===",
"$",
"replacementKey",
")",
"{",
"// If they share the same key, just replace.",
"$",
"this",
"->",
"dataPlaceHolder",
"[",
"$",
"objectKey",
"]",
"=",
"$",
"replacement",
";",
"}",
"else",
"{",
"// Otherwise, we have to insert the $replacement object at the appropriate offset (just before $object),",
"// and then remove the former $object.",
"$",
"objectOffset",
"=",
"array_search",
"(",
"$",
"objectKey",
",",
"array_keys",
"(",
"$",
"this",
"->",
"dataPlaceHolder",
")",
")",
";",
"$",
"this",
"->",
"dataPlaceHolder",
"=",
"array_merge",
"(",
"array_slice",
"(",
"$",
"this",
"->",
"dataPlaceHolder",
",",
"0",
",",
"$",
"objectOffset",
")",
",",
"array",
"(",
"$",
"replacementKey",
"=>",
"$",
"replacement",
")",
",",
"array_slice",
"(",
"$",
"this",
"->",
"dataPlaceHolder",
",",
"$",
"objectOffset",
",",
"null",
")",
")",
";",
"$",
"this",
"->",
"offsetUnset",
"(",
"$",
"objectKey",
")",
";",
"}",
"$",
"replacement",
"->",
"attach",
"(",
"$",
"this",
")",
";",
"$",
"object",
"->",
"detach",
"(",
"$",
"this",
")",
";",
"}",
"else",
"{",
"$",
"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/data/QtiIdentifiableCollection.php#L174-L208 |
oat-sa/qti-sdk | src/qtism/runtime/rendering/qtipl/expressions/operators/StatsOperatorQtiPLRenderer.php | StatsOperatorQtiPLRenderer.render | public function render($something)
{
$renderer = new QtiPLRenderer($this->getCRO());
$attributes = [];
$attributes['name'] = "\"" . Statistics::getNameByConstant($something->getName()) . "\"";
return $something->getQtiClassName() . $renderer->writeAttributes($attributes)
. $renderer->writeChildElements($something->getExpressions());
} | php | public function render($something)
{
$renderer = new QtiPLRenderer($this->getCRO());
$attributes = [];
$attributes['name'] = "\"" . Statistics::getNameByConstant($something->getName()) . "\"";
return $something->getQtiClassName() . $renderer->writeAttributes($attributes)
. $renderer->writeChildElements($something->getExpressions());
} | [
"public",
"function",
"render",
"(",
"$",
"something",
")",
"{",
"$",
"renderer",
"=",
"new",
"QtiPLRenderer",
"(",
"$",
"this",
"->",
"getCRO",
"(",
")",
")",
";",
"$",
"attributes",
"=",
"[",
"]",
";",
"$",
"attributes",
"[",
"'name'",
"]",
"=",
"\"\\\"\"",
".",
"Statistics",
"::",
"getNameByConstant",
"(",
"$",
"something",
"->",
"getName",
"(",
")",
")",
".",
"\"\\\"\"",
";",
"return",
"$",
"something",
"->",
"getQtiClassName",
"(",
")",
".",
"$",
"renderer",
"->",
"writeAttributes",
"(",
"$",
"attributes",
")",
".",
"$",
"renderer",
"->",
"writeChildElements",
"(",
"$",
"something",
"->",
"getExpressions",
"(",
")",
")",
";",
"}"
] | Render a QtiComponent object into another constitution.
@param mixed $something Something to render into another consitution.
@return mixed The rendered component into another constitution.
@throws \qtism\runtime\rendering\RenderingException If something goes wrong while rendering the component. | [
"Render",
"a",
"QtiComponent",
"object",
"into",
"another",
"constitution",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/qtipl/expressions/operators/StatsOperatorQtiPLRenderer.php#L47-L55 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/SetTemplateValueMarshaller.php | SetTemplateValueMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
if (($identifier = $this->getDOMElementAttributeAs($element, 'identifier')) !== null) {
$expressionElt = self::getFirstChildElement($element);
if ($expressionElt !== false) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($expressionElt);
$object = new SetTemplateValue($identifier, $marshaller->unmarshall($expressionElt));
return $object;
} else {
$msg = "The mandatory child element 'expression' is missing from element 'setTemplateValue'.";
throw new UnmarshallingException($msg, $element);
}
} else {
$msg = "The mandatory attribute 'identifier' is missing from element 'setTemplateValue'.";
throw new UnmarshallingException($msg, $element);
}
} | php | protected function unmarshall(DOMElement $element)
{
if (($identifier = $this->getDOMElementAttributeAs($element, 'identifier')) !== null) {
$expressionElt = self::getFirstChildElement($element);
if ($expressionElt !== false) {
$marshaller = $this->getMarshallerFactory()->createMarshaller($expressionElt);
$object = new SetTemplateValue($identifier, $marshaller->unmarshall($expressionElt));
return $object;
} else {
$msg = "The mandatory child element 'expression' is missing from element 'setTemplateValue'.";
throw new UnmarshallingException($msg, $element);
}
} else {
$msg = "The mandatory attribute 'identifier' is missing from element 'setTemplateValue'.";
throw new UnmarshallingException($msg, $element);
}
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"if",
"(",
"(",
"$",
"identifier",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'identifier'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"expressionElt",
"=",
"self",
"::",
"getFirstChildElement",
"(",
"$",
"element",
")",
";",
"if",
"(",
"$",
"expressionElt",
"!==",
"false",
")",
"{",
"$",
"marshaller",
"=",
"$",
"this",
"->",
"getMarshallerFactory",
"(",
")",
"->",
"createMarshaller",
"(",
"$",
"expressionElt",
")",
";",
"$",
"object",
"=",
"new",
"SetTemplateValue",
"(",
"$",
"identifier",
",",
"$",
"marshaller",
"->",
"unmarshall",
"(",
"$",
"expressionElt",
")",
")",
";",
"return",
"$",
"object",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory child element 'expression' is missing from element 'setTemplateValue'.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The mandatory attribute 'identifier' is missing from element 'setTemplateValue'.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}"
] | Unmarshall a DOMElement object corresponding to a QTI setTemplateValue element.
@param \DOMElement $element A DOMElement object.
@return \qtism\data\QtiComponent A SetTemplateValue object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException | [
"Unmarshall",
"a",
"DOMElement",
"object",
"corresponding",
"to",
"a",
"QTI",
"setTemplateValue",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/SetTemplateValueMarshaller.php#L61-L79 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/AssessmentSectionRefMarshaller.php | AssessmentSectionRefMarshaller.marshall | protected function marshall(QtiComponent $component)
{
$element = parent::marshall($component);
$this->setDOMElementAttribute($element, 'href', $component->getHref());
return $element;
} | php | protected function marshall(QtiComponent $component)
{
$element = parent::marshall($component);
$this->setDOMElementAttribute($element, 'href', $component->getHref());
return $element;
} | [
"protected",
"function",
"marshall",
"(",
"QtiComponent",
"$",
"component",
")",
"{",
"$",
"element",
"=",
"parent",
"::",
"marshall",
"(",
"$",
"component",
")",
";",
"$",
"this",
"->",
"setDOMElementAttribute",
"(",
"$",
"element",
",",
"'href'",
",",
"$",
"component",
"->",
"getHref",
"(",
")",
")",
";",
"return",
"$",
"element",
";",
"}"
] | Marshall an AssessmentSectionRef object into a DOMElement object.
@param \qtism\data\QtiComponent $component An AssessmentSectionRef object.
@return \DOMElement The according DOMElement object. | [
"Marshall",
"an",
"AssessmentSectionRef",
"object",
"into",
"a",
"DOMElement",
"object",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/AssessmentSectionRefMarshaller.php#L43-L50 |
oat-sa/qti-sdk | src/qtism/data/storage/xml/marshalling/AssessmentSectionRefMarshaller.php | AssessmentSectionRefMarshaller.unmarshall | protected function unmarshall(DOMElement $element)
{
$baseComponent = parent::unmarshall($element);
if (($href = $this->getDOMElementAttributeAs($element, 'href', 'string')) !== null) {
$object = new AssessmentSectionRef($baseComponent->getIdentifier(), $href);
$object->setRequired($baseComponent->isRequired());
$object->setFixed($baseComponent->isFixed());
$object->setPreConditions($baseComponent->getPreConditions());
$object->setBranchRules($baseComponent->getBranchRules());
$object->setItemSessionControl($baseComponent->getItemSessionControl());
$object->setTimeLimits($baseComponent->getTimeLimits());
return $object;
} else {
$msg = "Mandatory attribute 'href' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} | php | protected function unmarshall(DOMElement $element)
{
$baseComponent = parent::unmarshall($element);
if (($href = $this->getDOMElementAttributeAs($element, 'href', 'string')) !== null) {
$object = new AssessmentSectionRef($baseComponent->getIdentifier(), $href);
$object->setRequired($baseComponent->isRequired());
$object->setFixed($baseComponent->isFixed());
$object->setPreConditions($baseComponent->getPreConditions());
$object->setBranchRules($baseComponent->getBranchRules());
$object->setItemSessionControl($baseComponent->getItemSessionControl());
$object->setTimeLimits($baseComponent->getTimeLimits());
return $object;
} else {
$msg = "Mandatory attribute 'href' is missing from element '" . $element->localName . "'.";
throw new UnmarshallingException($msg, $element);
}
} | [
"protected",
"function",
"unmarshall",
"(",
"DOMElement",
"$",
"element",
")",
"{",
"$",
"baseComponent",
"=",
"parent",
"::",
"unmarshall",
"(",
"$",
"element",
")",
";",
"if",
"(",
"(",
"$",
"href",
"=",
"$",
"this",
"->",
"getDOMElementAttributeAs",
"(",
"$",
"element",
",",
"'href'",
",",
"'string'",
")",
")",
"!==",
"null",
")",
"{",
"$",
"object",
"=",
"new",
"AssessmentSectionRef",
"(",
"$",
"baseComponent",
"->",
"getIdentifier",
"(",
")",
",",
"$",
"href",
")",
";",
"$",
"object",
"->",
"setRequired",
"(",
"$",
"baseComponent",
"->",
"isRequired",
"(",
")",
")",
";",
"$",
"object",
"->",
"setFixed",
"(",
"$",
"baseComponent",
"->",
"isFixed",
"(",
")",
")",
";",
"$",
"object",
"->",
"setPreConditions",
"(",
"$",
"baseComponent",
"->",
"getPreConditions",
"(",
")",
")",
";",
"$",
"object",
"->",
"setBranchRules",
"(",
"$",
"baseComponent",
"->",
"getBranchRules",
"(",
")",
")",
";",
"$",
"object",
"->",
"setItemSessionControl",
"(",
"$",
"baseComponent",
"->",
"getItemSessionControl",
"(",
")",
")",
";",
"$",
"object",
"->",
"setTimeLimits",
"(",
"$",
"baseComponent",
"->",
"getTimeLimits",
"(",
")",
")",
";",
"return",
"$",
"object",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"Mandatory attribute 'href' is missing from element '\"",
".",
"$",
"element",
"->",
"localName",
".",
"\"'.\"",
";",
"throw",
"new",
"UnmarshallingException",
"(",
"$",
"msg",
",",
"$",
"element",
")",
";",
"}",
"}"
] | Unmarshall a DOMElement object corresponding to a QTI assessmentSectionRef element.
@param \DOMElement $element A DOMElement object.
@return \qtism\data\QtiComponent An AssessmentSectionRef object.
@throws \qtism\data\storage\xml\marshalling\UnmarshallingException If the mandatory attribute 'href' is missing. | [
"Unmarshall",
"a",
"DOMElement",
"object",
"corresponding",
"to",
"a",
"QTI",
"assessmentSectionRef",
"element",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/AssessmentSectionRefMarshaller.php#L59-L77 |
oat-sa/qti-sdk | src/qtism/data/content/xhtml/tables/Table.php | Table.setSummary | public function setSummary($summary)
{
if (is_string($summary) === true) {
$this->summary = $summary;
} else {
$msg = "The 'summary' argument must be a string, '" . gettype($summary) . "' given.";
throw new InvalidArgumentException($msg);
}
} | php | public function setSummary($summary)
{
if (is_string($summary) === true) {
$this->summary = $summary;
} else {
$msg = "The 'summary' argument must be a string, '" . gettype($summary) . "' given.";
throw new InvalidArgumentException($msg);
}
} | [
"public",
"function",
"setSummary",
"(",
"$",
"summary",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"summary",
")",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"summary",
"=",
"$",
"summary",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"\"The 'summary' argument must be a string, '\"",
".",
"gettype",
"(",
"$",
"summary",
")",
".",
"\"' given.\"",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Set the value of the summary attribute. An empty string
means there is no summary.
@param string $summary
@throws \InvalidArgumentException If $summary is not a string. | [
"Set",
"the",
"value",
"of",
"the",
"summary",
"attribute",
".",
"An",
"empty",
"string",
"means",
"there",
"is",
"no",
"summary",
"."
] | train | https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/xhtml/tables/Table.php#L126-L134 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.