repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
oat-sa/qti-sdk
src/qtism/data/content/interactions/GraphicGapMatchInteraction.php
GraphicGapMatchInteraction.setAssociableHotspots
public function setAssociableHotspots(AssociableHotspotCollection $associableHotspots) { if (count($associableHotspots) > 0) { $this->associableHotspots = $associableHotspots; } else { $msg = "A GraphicGapMatch interaction must be composed of at least 1 AssociableHotspot object, none given."; throw new InvalidArgumentException($msg); } }
php
public function setAssociableHotspots(AssociableHotspotCollection $associableHotspots) { if (count($associableHotspots) > 0) { $this->associableHotspots = $associableHotspots; } else { $msg = "A GraphicGapMatch interaction must be composed of at least 1 AssociableHotspot object, none given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setAssociableHotspots", "(", "AssociableHotspotCollection", "$", "associableHotspots", ")", "{", "if", "(", "count", "(", "$", "associableHotspots", ")", ">", "0", ")", "{", "$", "this", "->", "associableHotspots", "=", "$", "associableHotspots", ";", "}", "else", "{", "$", "msg", "=", "\"A GraphicGapMatch interaction must be composed of at least 1 AssociableHotspot object, none given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set the hotspots that define the gaps that are to be filled by the candidate. @param \qtism\data\content\interactions\AssociableHotspotCollection $associableHotspots A collection of AssociableHotspot objects. @throws \InvalidArgumentException If $associableHotspots is empty.
[ "Set", "the", "hotspots", "that", "define", "the", "gaps", "that", "are", "to", "be", "filled", "by", "the", "candidate", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/interactions/GraphicGapMatchInteraction.php#L131-L139
oat-sa/qti-sdk
src/qtism/data/content/interactions/PositionObjectStage.php
PositionObjectStage.setPositionObjectInteractions
public function setPositionObjectInteractions(PositionObjectInteractionCollection $positionObjectInteractions) { if (count($positionObjectInteractions) > 0) { $this->positionObjectInteractions = $positionObjectInteractions; } else { $msg = "A PositionObjectStage object must be composed of at least 1 PositionObjectInteraction object, none given."; throw new InvalidArgumentException($msg); } }
php
public function setPositionObjectInteractions(PositionObjectInteractionCollection $positionObjectInteractions) { if (count($positionObjectInteractions) > 0) { $this->positionObjectInteractions = $positionObjectInteractions; } else { $msg = "A PositionObjectStage object must be composed of at least 1 PositionObjectInteraction object, none given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setPositionObjectInteractions", "(", "PositionObjectInteractionCollection", "$", "positionObjectInteractions", ")", "{", "if", "(", "count", "(", "$", "positionObjectInteractions", ")", ">", "0", ")", "{", "$", "this", "->", "positionObjectInteractions", "=", "$", "positionObjectInteractions", ";", "}", "else", "{", "$", "msg", "=", "\"A PositionObjectStage object must be composed of at least 1 PositionObjectInteraction object, none given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set the positionObjectInteractions composing the positionObjectStage. @param \qtism\data\content\interactions\PositionObjectInteractionCollection $positionObjectInteractions A collection of PositionObjectInteraction objects. @throws \InvalidArgumentException If $positionObjectInteractions is empty.
[ "Set", "the", "positionObjectInteractions", "composing", "the", "positionObjectStage", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/interactions/PositionObjectStage.php#L98-L106
oat-sa/qti-sdk
src/qtism/data/storage/xml/marshalling/SliderInteractionMarshaller.php
SliderInteractionMarshaller.marshall
protected function marshall(QtiComponent $component) { $element = $this->createElement($component); $this->fillElement($element, $component); $this->setDOMElementAttribute($element, 'responseIdentifier', $component->getResponseIdentifier()); $this->setDOMElementAttribute($element, 'lowerBound', $component->getLowerBound()); $this->setDOMElementAttribute($element, 'upperBound', $component->getUpperBound()); if ($component->hasStep() === true) { $this->setDOMElementAttribute($element, 'step', $component->getStep()); } if ($component->mustStepLabel() === true) { $this->setDOMElementAttribute($element, 'stepLabel', true); } if ($component->getOrientation() === Orientation::VERTICAL) { $this->setDOMElementAttribute($element, 'orientation', Orientation::getNameByConstant(Orientation::VERTICAL)); } if ($component->mustReverse() === true) { $this->setDOMElementAttribute($element, 'reverse', true); } if ($component->hasXmlBase() === true) { self::setXmlBase($element, $component->getXmlBase()); } if ($component->hasPrompt() === true) { $element->appendChild($this->getMarshallerFactory()->createMarshaller($component->getPrompt())->marshall($component->getPrompt())); } return $element; }
php
protected function marshall(QtiComponent $component) { $element = $this->createElement($component); $this->fillElement($element, $component); $this->setDOMElementAttribute($element, 'responseIdentifier', $component->getResponseIdentifier()); $this->setDOMElementAttribute($element, 'lowerBound', $component->getLowerBound()); $this->setDOMElementAttribute($element, 'upperBound', $component->getUpperBound()); if ($component->hasStep() === true) { $this->setDOMElementAttribute($element, 'step', $component->getStep()); } if ($component->mustStepLabel() === true) { $this->setDOMElementAttribute($element, 'stepLabel', true); } if ($component->getOrientation() === Orientation::VERTICAL) { $this->setDOMElementAttribute($element, 'orientation', Orientation::getNameByConstant(Orientation::VERTICAL)); } if ($component->mustReverse() === true) { $this->setDOMElementAttribute($element, 'reverse', true); } if ($component->hasXmlBase() === true) { self::setXmlBase($element, $component->getXmlBase()); } if ($component->hasPrompt() === true) { $element->appendChild($this->getMarshallerFactory()->createMarshaller($component->getPrompt())->marshall($component->getPrompt())); } return $element; }
[ "protected", "function", "marshall", "(", "QtiComponent", "$", "component", ")", "{", "$", "element", "=", "$", "this", "->", "createElement", "(", "$", "component", ")", ";", "$", "this", "->", "fillElement", "(", "$", "element", ",", "$", "component", ")", ";", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'responseIdentifier'", ",", "$", "component", "->", "getResponseIdentifier", "(", ")", ")", ";", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'lowerBound'", ",", "$", "component", "->", "getLowerBound", "(", ")", ")", ";", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'upperBound'", ",", "$", "component", "->", "getUpperBound", "(", ")", ")", ";", "if", "(", "$", "component", "->", "hasStep", "(", ")", "===", "true", ")", "{", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'step'", ",", "$", "component", "->", "getStep", "(", ")", ")", ";", "}", "if", "(", "$", "component", "->", "mustStepLabel", "(", ")", "===", "true", ")", "{", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'stepLabel'", ",", "true", ")", ";", "}", "if", "(", "$", "component", "->", "getOrientation", "(", ")", "===", "Orientation", "::", "VERTICAL", ")", "{", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'orientation'", ",", "Orientation", "::", "getNameByConstant", "(", "Orientation", "::", "VERTICAL", ")", ")", ";", "}", "if", "(", "$", "component", "->", "mustReverse", "(", ")", "===", "true", ")", "{", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'reverse'", ",", "true", ")", ";", "}", "if", "(", "$", "component", "->", "hasXmlBase", "(", ")", "===", "true", ")", "{", "self", "::", "setXmlBase", "(", "$", "element", ",", "$", "component", "->", "getXmlBase", "(", ")", ")", ";", "}", "if", "(", "$", "component", "->", "hasPrompt", "(", ")", "===", "true", ")", "{", "$", "element", "->", "appendChild", "(", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "component", "->", "getPrompt", "(", ")", ")", "->", "marshall", "(", "$", "component", "->", "getPrompt", "(", ")", ")", ")", ";", "}", "return", "$", "element", ";", "}" ]
Marshall a SliderInteraction object into a DOMElement object. @param \qtism\data\QtiComponent $component A SliderInteraction object. @return \DOMElement The according DOMElement object. @throws \qtism\data\storage\xml\marshalling\MarshallingException
[ "Marshall", "a", "SliderInteraction", "object", "into", "a", "DOMElement", "object", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/SliderInteractionMarshaller.php#L46-L79
oat-sa/qti-sdk
src/qtism/data/storage/xml/marshalling/SliderInteractionMarshaller.php
SliderInteractionMarshaller.unmarshall
protected function unmarshall(DOMElement $element) { if (($responseIdentifier = $this->getDOMElementAttributeAs($element, 'responseIdentifier')) !== null) { if (($lowerBound = $this->getDOMElementAttributeAs($element, 'lowerBound', 'float')) !== null) { if (($upperBound = $this->getDOMElementAttributeAs($element, 'upperBound', 'float')) !== null) { $component = new SliderInteraction($responseIdentifier, $lowerBound, $upperBound); $promptElts = $this->getChildElementsByTagName($element, 'prompt'); if (count($promptElts) > 0) { $promptElt = $promptElts[0]; $prompt = $this->getMarshallerFactory()->createMarshaller($promptElt)->unmarshall($promptElt); $component->setPrompt($prompt); } if (($step = $this->getDOMElementAttributeAs($element, 'step', 'integer')) !== null) { $component->setStep($step); } if (($stepLabel = $this->getDOMElementAttributeAs($element, 'stepLabel', 'boolean')) !== null) { $component->setStepLabel($stepLabel); } if (($orientation = $this->getDOMElementAttributeAs($element, 'orientation')) !== null) { try { $component->setOrientation(Orientation::getConstantByName($orientation)); } catch (InvalidArgumentException $e) { $msg = "The value of the 'orientation' attribute of the 'sliderInteraction' is invalid."; throw new UnmarshallingException($msg, $element, $e); } } if (($reverse = $this->getDOMElementAttributeAs($element, 'reverse', 'boolean')) !== null) { $component->setReverse($reverse); } if (($xmlBase = self::getXmlBase($element)) !== false) { $component->setXmlBase($xmlBase); } $this->fillBodyElement($component, $element); return $component; } else { $msg = "The mandatory 'upperBound' attribute is missing from the 'sliderInteraction' element."; throw new UnmarshallingException($msg, $element); } } else { $msg = "The mandatory 'lowerBound' attribute is missing from the 'sliderInteraction' element."; throw new UnmarshallingException($msg, $element); } } else { $msg = "The mandatory 'responseIdentifier' attribute is missing from the 'sliderInteraction' element."; throw new UnmarshallingException($msg, $element); } }
php
protected function unmarshall(DOMElement $element) { if (($responseIdentifier = $this->getDOMElementAttributeAs($element, 'responseIdentifier')) !== null) { if (($lowerBound = $this->getDOMElementAttributeAs($element, 'lowerBound', 'float')) !== null) { if (($upperBound = $this->getDOMElementAttributeAs($element, 'upperBound', 'float')) !== null) { $component = new SliderInteraction($responseIdentifier, $lowerBound, $upperBound); $promptElts = $this->getChildElementsByTagName($element, 'prompt'); if (count($promptElts) > 0) { $promptElt = $promptElts[0]; $prompt = $this->getMarshallerFactory()->createMarshaller($promptElt)->unmarshall($promptElt); $component->setPrompt($prompt); } if (($step = $this->getDOMElementAttributeAs($element, 'step', 'integer')) !== null) { $component->setStep($step); } if (($stepLabel = $this->getDOMElementAttributeAs($element, 'stepLabel', 'boolean')) !== null) { $component->setStepLabel($stepLabel); } if (($orientation = $this->getDOMElementAttributeAs($element, 'orientation')) !== null) { try { $component->setOrientation(Orientation::getConstantByName($orientation)); } catch (InvalidArgumentException $e) { $msg = "The value of the 'orientation' attribute of the 'sliderInteraction' is invalid."; throw new UnmarshallingException($msg, $element, $e); } } if (($reverse = $this->getDOMElementAttributeAs($element, 'reverse', 'boolean')) !== null) { $component->setReverse($reverse); } if (($xmlBase = self::getXmlBase($element)) !== false) { $component->setXmlBase($xmlBase); } $this->fillBodyElement($component, $element); return $component; } else { $msg = "The mandatory 'upperBound' attribute is missing from the 'sliderInteraction' element."; throw new UnmarshallingException($msg, $element); } } else { $msg = "The mandatory 'lowerBound' attribute is missing from the 'sliderInteraction' element."; throw new UnmarshallingException($msg, $element); } } else { $msg = "The mandatory 'responseIdentifier' attribute is missing from the 'sliderInteraction' element."; throw new UnmarshallingException($msg, $element); } }
[ "protected", "function", "unmarshall", "(", "DOMElement", "$", "element", ")", "{", "if", "(", "(", "$", "responseIdentifier", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'responseIdentifier'", ")", ")", "!==", "null", ")", "{", "if", "(", "(", "$", "lowerBound", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'lowerBound'", ",", "'float'", ")", ")", "!==", "null", ")", "{", "if", "(", "(", "$", "upperBound", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'upperBound'", ",", "'float'", ")", ")", "!==", "null", ")", "{", "$", "component", "=", "new", "SliderInteraction", "(", "$", "responseIdentifier", ",", "$", "lowerBound", ",", "$", "upperBound", ")", ";", "$", "promptElts", "=", "$", "this", "->", "getChildElementsByTagName", "(", "$", "element", ",", "'prompt'", ")", ";", "if", "(", "count", "(", "$", "promptElts", ")", ">", "0", ")", "{", "$", "promptElt", "=", "$", "promptElts", "[", "0", "]", ";", "$", "prompt", "=", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "promptElt", ")", "->", "unmarshall", "(", "$", "promptElt", ")", ";", "$", "component", "->", "setPrompt", "(", "$", "prompt", ")", ";", "}", "if", "(", "(", "$", "step", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'step'", ",", "'integer'", ")", ")", "!==", "null", ")", "{", "$", "component", "->", "setStep", "(", "$", "step", ")", ";", "}", "if", "(", "(", "$", "stepLabel", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'stepLabel'", ",", "'boolean'", ")", ")", "!==", "null", ")", "{", "$", "component", "->", "setStepLabel", "(", "$", "stepLabel", ")", ";", "}", "if", "(", "(", "$", "orientation", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'orientation'", ")", ")", "!==", "null", ")", "{", "try", "{", "$", "component", "->", "setOrientation", "(", "Orientation", "::", "getConstantByName", "(", "$", "orientation", ")", ")", ";", "}", "catch", "(", "InvalidArgumentException", "$", "e", ")", "{", "$", "msg", "=", "\"The value of the 'orientation' attribute of the 'sliderInteraction' is invalid.\"", ";", "throw", "new", "UnmarshallingException", "(", "$", "msg", ",", "$", "element", ",", "$", "e", ")", ";", "}", "}", "if", "(", "(", "$", "reverse", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'reverse'", ",", "'boolean'", ")", ")", "!==", "null", ")", "{", "$", "component", "->", "setReverse", "(", "$", "reverse", ")", ";", "}", "if", "(", "(", "$", "xmlBase", "=", "self", "::", "getXmlBase", "(", "$", "element", ")", ")", "!==", "false", ")", "{", "$", "component", "->", "setXmlBase", "(", "$", "xmlBase", ")", ";", "}", "$", "this", "->", "fillBodyElement", "(", "$", "component", ",", "$", "element", ")", ";", "return", "$", "component", ";", "}", "else", "{", "$", "msg", "=", "\"The mandatory 'upperBound' attribute is missing from the 'sliderInteraction' element.\"", ";", "throw", "new", "UnmarshallingException", "(", "$", "msg", ",", "$", "element", ")", ";", "}", "}", "else", "{", "$", "msg", "=", "\"The mandatory 'lowerBound' attribute is missing from the 'sliderInteraction' element.\"", ";", "throw", "new", "UnmarshallingException", "(", "$", "msg", ",", "$", "element", ")", ";", "}", "}", "else", "{", "$", "msg", "=", "\"The mandatory 'responseIdentifier' attribute is missing from the 'sliderInteraction' element.\"", ";", "throw", "new", "UnmarshallingException", "(", "$", "msg", ",", "$", "element", ")", ";", "}", "}" ]
Unmarshall a DOMElement object corresponding to a SliderInteraction element. @param \DOMElement $element A DOMElement object. @return \qtism\data\QtiComponent A SliderInteraction object. @throws \qtism\data\storage\xml\marshalling\UnmarshallingException
[ "Unmarshall", "a", "DOMElement", "object", "corresponding", "to", "a", "SliderInteraction", "element", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/SliderInteractionMarshaller.php#L88-L145
oat-sa/qti-sdk
src/qtism/data/QtiComponentIterator.php
QtiComponentIterator.pushOnTrail
protected function pushOnTrail(QtiComponent $source, QtiComponentCollection $components) { foreach (array_reverse($components->getArrayCopy()) as $c) { array_push($this->trail, array($source, $c)); $this->trailCount++; } }
php
protected function pushOnTrail(QtiComponent $source, QtiComponentCollection $components) { foreach (array_reverse($components->getArrayCopy()) as $c) { array_push($this->trail, array($source, $c)); $this->trailCount++; } }
[ "protected", "function", "pushOnTrail", "(", "QtiComponent", "$", "source", ",", "QtiComponentCollection", "$", "components", ")", "{", "foreach", "(", "array_reverse", "(", "$", "components", "->", "getArrayCopy", "(", ")", ")", "as", "$", "c", ")", "{", "array_push", "(", "$", "this", "->", "trail", ",", "array", "(", "$", "source", ",", "$", "c", ")", ")", ";", "$", "this", "->", "trailCount", "++", ";", "}", "}" ]
Push a trail entry on the trail. @param \qtism\data\QTIComponent $source From where we are coming from. @param \qtism\data\QTIComponentCollection $components The next components to explore.
[ "Push", "a", "trail", "entry", "on", "the", "trail", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/QtiComponentIterator.php#L188-L194
oat-sa/qti-sdk
src/qtism/data/QtiComponentIterator.php
QtiComponentIterator.rewind
public function rewind() { $trail = array(); $this->setTrail($trail); $classes = &$this->getClasses(); $traversed = array(); $this->setTraversed($traversed); $root = $this->getRootComponent(); $this->pushOnTrail($root, $root->getComponents()); $hasTrail = false; $foundClass = false; while (count($this->getTrail()) > 0) { $hasTrail = true; $trailEntry = $this->popFromTrail(); $this->setValid(true); $this->currentComponent = $trailEntry[1]; $this->currentContainer = $trailEntry[0]; $this->markTraversed($this->currentComponent); $this->pushOnTrail($this->currentComponent, $this->currentComponent->getComponents()); if (empty($classes) === true || in_array($this->currentComponent->getQtiClassName(), $classes) === true) { $foundClass = true; break; } } if (count($this->trail) === 0 && (($hasTrail && !$foundClass) || (!$hasTrail))) { $this->isValid = false; $this->currentComponent = null; $this->currentContainer = null; } }
php
public function rewind() { $trail = array(); $this->setTrail($trail); $classes = &$this->getClasses(); $traversed = array(); $this->setTraversed($traversed); $root = $this->getRootComponent(); $this->pushOnTrail($root, $root->getComponents()); $hasTrail = false; $foundClass = false; while (count($this->getTrail()) > 0) { $hasTrail = true; $trailEntry = $this->popFromTrail(); $this->setValid(true); $this->currentComponent = $trailEntry[1]; $this->currentContainer = $trailEntry[0]; $this->markTraversed($this->currentComponent); $this->pushOnTrail($this->currentComponent, $this->currentComponent->getComponents()); if (empty($classes) === true || in_array($this->currentComponent->getQtiClassName(), $classes) === true) { $foundClass = true; break; } } if (count($this->trail) === 0 && (($hasTrail && !$foundClass) || (!$hasTrail))) { $this->isValid = false; $this->currentComponent = null; $this->currentContainer = null; } }
[ "public", "function", "rewind", "(", ")", "{", "$", "trail", "=", "array", "(", ")", ";", "$", "this", "->", "setTrail", "(", "$", "trail", ")", ";", "$", "classes", "=", "&", "$", "this", "->", "getClasses", "(", ")", ";", "$", "traversed", "=", "array", "(", ")", ";", "$", "this", "->", "setTraversed", "(", "$", "traversed", ")", ";", "$", "root", "=", "$", "this", "->", "getRootComponent", "(", ")", ";", "$", "this", "->", "pushOnTrail", "(", "$", "root", ",", "$", "root", "->", "getComponents", "(", ")", ")", ";", "$", "hasTrail", "=", "false", ";", "$", "foundClass", "=", "false", ";", "while", "(", "count", "(", "$", "this", "->", "getTrail", "(", ")", ")", ">", "0", ")", "{", "$", "hasTrail", "=", "true", ";", "$", "trailEntry", "=", "$", "this", "->", "popFromTrail", "(", ")", ";", "$", "this", "->", "setValid", "(", "true", ")", ";", "$", "this", "->", "currentComponent", "=", "$", "trailEntry", "[", "1", "]", ";", "$", "this", "->", "currentContainer", "=", "$", "trailEntry", "[", "0", "]", ";", "$", "this", "->", "markTraversed", "(", "$", "this", "->", "currentComponent", ")", ";", "$", "this", "->", "pushOnTrail", "(", "$", "this", "->", "currentComponent", ",", "$", "this", "->", "currentComponent", "->", "getComponents", "(", ")", ")", ";", "if", "(", "empty", "(", "$", "classes", ")", "===", "true", "||", "in_array", "(", "$", "this", "->", "currentComponent", "->", "getQtiClassName", "(", ")", ",", "$", "classes", ")", "===", "true", ")", "{", "$", "foundClass", "=", "true", ";", "break", ";", "}", "}", "if", "(", "count", "(", "$", "this", "->", "trail", ")", "===", "0", "&&", "(", "(", "$", "hasTrail", "&&", "!", "$", "foundClass", ")", "||", "(", "!", "$", "hasTrail", ")", ")", ")", "{", "$", "this", "->", "isValid", "=", "false", ";", "$", "this", "->", "currentComponent", "=", "null", ";", "$", "this", "->", "currentContainer", "=", "null", ";", "}", "}" ]
Rewind the iterator.
[ "Rewind", "the", "iterator", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/QtiComponentIterator.php#L273-L308
oat-sa/qti-sdk
src/qtism/data/QtiComponentIterator.php
QtiComponentIterator.next
public function next() { if ($this->trailCount > 0) { while ($this->trailCount > 0) { $trailEntry = $this->popFromTrail(); $component = $trailEntry[1]; $source = $trailEntry[0]; if ($this->isTraversed($component) === false) { $this->currentComponent = $component; $this->currentContainer = $source; $this->pushOnTrail($component, $this->currentComponent->getComponents()); $this->markTraversed($this->currentComponent); if (empty($this->classes) === true || in_array($this->currentComponent->getQTIClassName(), $this->classes) === true) { // If all classes are seeked or the current component has a class name // that must be seeked, stop the iteration. return; } } } $this->isValid = false; $this->currentContainer = null; } else { $this->isValid = false; $this->currentContainer = null; } }
php
public function next() { if ($this->trailCount > 0) { while ($this->trailCount > 0) { $trailEntry = $this->popFromTrail(); $component = $trailEntry[1]; $source = $trailEntry[0]; if ($this->isTraversed($component) === false) { $this->currentComponent = $component; $this->currentContainer = $source; $this->pushOnTrail($component, $this->currentComponent->getComponents()); $this->markTraversed($this->currentComponent); if (empty($this->classes) === true || in_array($this->currentComponent->getQTIClassName(), $this->classes) === true) { // If all classes are seeked or the current component has a class name // that must be seeked, stop the iteration. return; } } } $this->isValid = false; $this->currentContainer = null; } else { $this->isValid = false; $this->currentContainer = null; } }
[ "public", "function", "next", "(", ")", "{", "if", "(", "$", "this", "->", "trailCount", ">", "0", ")", "{", "while", "(", "$", "this", "->", "trailCount", ">", "0", ")", "{", "$", "trailEntry", "=", "$", "this", "->", "popFromTrail", "(", ")", ";", "$", "component", "=", "$", "trailEntry", "[", "1", "]", ";", "$", "source", "=", "$", "trailEntry", "[", "0", "]", ";", "if", "(", "$", "this", "->", "isTraversed", "(", "$", "component", ")", "===", "false", ")", "{", "$", "this", "->", "currentComponent", "=", "$", "component", ";", "$", "this", "->", "currentContainer", "=", "$", "source", ";", "$", "this", "->", "pushOnTrail", "(", "$", "component", ",", "$", "this", "->", "currentComponent", "->", "getComponents", "(", ")", ")", ";", "$", "this", "->", "markTraversed", "(", "$", "this", "->", "currentComponent", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "classes", ")", "===", "true", "||", "in_array", "(", "$", "this", "->", "currentComponent", "->", "getQTIClassName", "(", ")", ",", "$", "this", "->", "classes", ")", "===", "true", ")", "{", "// If all classes are seeked or the current component has a class name", "// that must be seeked, stop the iteration.", "return", ";", "}", "}", "}", "$", "this", "->", "isValid", "=", "false", ";", "$", "this", "->", "currentContainer", "=", "null", ";", "}", "else", "{", "$", "this", "->", "isValid", "=", "false", ";", "$", "this", "->", "currentContainer", "=", "null", ";", "}", "}" ]
Moves the current position to the next QtiComponent object to be traversed.
[ "Moves", "the", "current", "position", "to", "the", "next", "QtiComponent", "object", "to", "be", "traversed", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/QtiComponentIterator.php#L353-L382
oat-sa/qti-sdk
src/qtism/data/storage/xml/XmlCompactDocument.php
XmlCompactDocument.resolveAssessmentItemRef
protected static function resolveAssessmentItemRef(ExtendedAssessmentItemRef $compactAssessmentItemRef, FileResolver $resolver) { try { $href = $resolver->resolve($compactAssessmentItemRef->getHref()); $doc = new XmlDocument(); $doc->load($href); // Resolve external documents. $doc->xInclude(); $doc->resolveTemplateLocation(); $item = $doc->getDocumentComponent(); foreach ($item->getResponseDeclarations() as $resp) { $compactAssessmentItemRef->addResponseDeclaration($resp); } foreach ($item->getOutcomeDeclarations() as $out) { $compactAssessmentItemRef->addOutcomeDeclaration($out); } foreach ($item->getTemplateDeclarations() as $tpl) { $compactAssessmentItemRef->addTemplateDeclaration($tpl); } foreach ($item->getModalFeedbackRules() as $modalFeedbackRule) { $compactAssessmentItemRef->addModalFeedbackRule($modalFeedbackRule); } if ($item->hasResponseProcessing() === true) { $compactAssessmentItemRef->setResponseProcessing($item->getResponseProcessing()); } if ($item->hasTemplateProcessing() === true) { $compactAssessmentItemRef->setTemplateProcessing($item->getTemplateProcessing()); } $compactAssessmentItemRef->setShufflings($item->getShufflings()); $compactAssessmentItemRef->setAdaptive($item->isAdaptive()); $compactAssessmentItemRef->setTimeDependent($item->isTimeDependent()); $compactAssessmentItemRef->setEndAttemptIdentifiers($item->getEndAttemptIdentifiers()); $compactAssessmentItemRef->setResponseValidityConstraints($item->getResponseValidityConstraints()); } catch (Exception $e) { $msg = "An error occured while unreferencing item reference with identifier '" . $compactAssessmentItemRef->getIdentifier() . "'."; throw new XmlStorageException($msg, XmlStorageException::RESOLUTION, $e); } }
php
protected static function resolveAssessmentItemRef(ExtendedAssessmentItemRef $compactAssessmentItemRef, FileResolver $resolver) { try { $href = $resolver->resolve($compactAssessmentItemRef->getHref()); $doc = new XmlDocument(); $doc->load($href); // Resolve external documents. $doc->xInclude(); $doc->resolveTemplateLocation(); $item = $doc->getDocumentComponent(); foreach ($item->getResponseDeclarations() as $resp) { $compactAssessmentItemRef->addResponseDeclaration($resp); } foreach ($item->getOutcomeDeclarations() as $out) { $compactAssessmentItemRef->addOutcomeDeclaration($out); } foreach ($item->getTemplateDeclarations() as $tpl) { $compactAssessmentItemRef->addTemplateDeclaration($tpl); } foreach ($item->getModalFeedbackRules() as $modalFeedbackRule) { $compactAssessmentItemRef->addModalFeedbackRule($modalFeedbackRule); } if ($item->hasResponseProcessing() === true) { $compactAssessmentItemRef->setResponseProcessing($item->getResponseProcessing()); } if ($item->hasTemplateProcessing() === true) { $compactAssessmentItemRef->setTemplateProcessing($item->getTemplateProcessing()); } $compactAssessmentItemRef->setShufflings($item->getShufflings()); $compactAssessmentItemRef->setAdaptive($item->isAdaptive()); $compactAssessmentItemRef->setTimeDependent($item->isTimeDependent()); $compactAssessmentItemRef->setEndAttemptIdentifiers($item->getEndAttemptIdentifiers()); $compactAssessmentItemRef->setResponseValidityConstraints($item->getResponseValidityConstraints()); } catch (Exception $e) { $msg = "An error occured while unreferencing item reference with identifier '" . $compactAssessmentItemRef->getIdentifier() . "'."; throw new XmlStorageException($msg, XmlStorageException::RESOLUTION, $e); } }
[ "protected", "static", "function", "resolveAssessmentItemRef", "(", "ExtendedAssessmentItemRef", "$", "compactAssessmentItemRef", ",", "FileResolver", "$", "resolver", ")", "{", "try", "{", "$", "href", "=", "$", "resolver", "->", "resolve", "(", "$", "compactAssessmentItemRef", "->", "getHref", "(", ")", ")", ";", "$", "doc", "=", "new", "XmlDocument", "(", ")", ";", "$", "doc", "->", "load", "(", "$", "href", ")", ";", "// Resolve external documents.", "$", "doc", "->", "xInclude", "(", ")", ";", "$", "doc", "->", "resolveTemplateLocation", "(", ")", ";", "$", "item", "=", "$", "doc", "->", "getDocumentComponent", "(", ")", ";", "foreach", "(", "$", "item", "->", "getResponseDeclarations", "(", ")", "as", "$", "resp", ")", "{", "$", "compactAssessmentItemRef", "->", "addResponseDeclaration", "(", "$", "resp", ")", ";", "}", "foreach", "(", "$", "item", "->", "getOutcomeDeclarations", "(", ")", "as", "$", "out", ")", "{", "$", "compactAssessmentItemRef", "->", "addOutcomeDeclaration", "(", "$", "out", ")", ";", "}", "foreach", "(", "$", "item", "->", "getTemplateDeclarations", "(", ")", "as", "$", "tpl", ")", "{", "$", "compactAssessmentItemRef", "->", "addTemplateDeclaration", "(", "$", "tpl", ")", ";", "}", "foreach", "(", "$", "item", "->", "getModalFeedbackRules", "(", ")", "as", "$", "modalFeedbackRule", ")", "{", "$", "compactAssessmentItemRef", "->", "addModalFeedbackRule", "(", "$", "modalFeedbackRule", ")", ";", "}", "if", "(", "$", "item", "->", "hasResponseProcessing", "(", ")", "===", "true", ")", "{", "$", "compactAssessmentItemRef", "->", "setResponseProcessing", "(", "$", "item", "->", "getResponseProcessing", "(", ")", ")", ";", "}", "if", "(", "$", "item", "->", "hasTemplateProcessing", "(", ")", "===", "true", ")", "{", "$", "compactAssessmentItemRef", "->", "setTemplateProcessing", "(", "$", "item", "->", "getTemplateProcessing", "(", ")", ")", ";", "}", "$", "compactAssessmentItemRef", "->", "setShufflings", "(", "$", "item", "->", "getShufflings", "(", ")", ")", ";", "$", "compactAssessmentItemRef", "->", "setAdaptive", "(", "$", "item", "->", "isAdaptive", "(", ")", ")", ";", "$", "compactAssessmentItemRef", "->", "setTimeDependent", "(", "$", "item", "->", "isTimeDependent", "(", ")", ")", ";", "$", "compactAssessmentItemRef", "->", "setEndAttemptIdentifiers", "(", "$", "item", "->", "getEndAttemptIdentifiers", "(", ")", ")", ";", "$", "compactAssessmentItemRef", "->", "setResponseValidityConstraints", "(", "$", "item", "->", "getResponseValidityConstraints", "(", ")", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "$", "msg", "=", "\"An error occured while unreferencing item reference with identifier '\"", ".", "$", "compactAssessmentItemRef", "->", "getIdentifier", "(", ")", ".", "\"'.\"", ";", "throw", "new", "XmlStorageException", "(", "$", "msg", ",", "XmlStorageException", "::", "RESOLUTION", ",", "$", "e", ")", ";", "}", "}" ]
Dereference the file referenced by an assessmentItemRef and add outcome/responseDeclarations to the compact one. @param \qtism\data\ExtendedAssessmentItemRef $compactAssessmentItemRef A previously instantiated ExtendedAssessmentItemRef object. @param \qtism\data\storage\FileResolver $resolver The Resolver to be used to resolver AssessmentItemRef's href attribute. @throws \qtism\data\storage\xml\XmlStorageException If an error occurs (e.g. file not found at URI or unmarshalling issue) during the dereferencing.
[ "Dereference", "the", "file", "referenced", "by", "an", "assessmentItemRef", "and", "add", "outcome", "/", "responseDeclarations", "to", "the", "compact", "one", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/XmlCompactDocument.php#L281-L328
oat-sa/qti-sdk
src/qtism/data/storage/xml/XmlCompactDocument.php
XmlCompactDocument.resolveAssessmentSectionRef
protected static function resolveAssessmentSectionRef(AssessmentSectionRef $assessmentSectionRef, FileResolver $resolver) { try { $href = $resolver->resolve($assessmentSectionRef->getHref()); $doc = new XmlDocument(); $doc->load($href); $doc->xInclude(); return $doc; } catch (XmlStorageException $e) { $msg = "An error occured while unreferencing section reference with identifier '" . $assessmentSectionRef->getIdentifier() . "'."; throw new XmlStorageException($msg, XmlStorageException::RESOLUTION, $e); } }
php
protected static function resolveAssessmentSectionRef(AssessmentSectionRef $assessmentSectionRef, FileResolver $resolver) { try { $href = $resolver->resolve($assessmentSectionRef->getHref()); $doc = new XmlDocument(); $doc->load($href); $doc->xInclude(); return $doc; } catch (XmlStorageException $e) { $msg = "An error occured while unreferencing section reference with identifier '" . $assessmentSectionRef->getIdentifier() . "'."; throw new XmlStorageException($msg, XmlStorageException::RESOLUTION, $e); } }
[ "protected", "static", "function", "resolveAssessmentSectionRef", "(", "AssessmentSectionRef", "$", "assessmentSectionRef", ",", "FileResolver", "$", "resolver", ")", "{", "try", "{", "$", "href", "=", "$", "resolver", "->", "resolve", "(", "$", "assessmentSectionRef", "->", "getHref", "(", ")", ")", ";", "$", "doc", "=", "new", "XmlDocument", "(", ")", ";", "$", "doc", "->", "load", "(", "$", "href", ")", ";", "$", "doc", "->", "xInclude", "(", ")", ";", "return", "$", "doc", ";", "}", "catch", "(", "XmlStorageException", "$", "e", ")", "{", "$", "msg", "=", "\"An error occured while unreferencing section reference with identifier '\"", ".", "$", "assessmentSectionRef", "->", "getIdentifier", "(", ")", ".", "\"'.\"", ";", "throw", "new", "XmlStorageException", "(", "$", "msg", ",", "XmlStorageException", "::", "RESOLUTION", ",", "$", "e", ")", ";", "}", "}" ]
Dereference the file referenced by an assessmentSectionRef. The xinclude elements in the target assessmentSection file will be resolved at the same time. @param \qtism\data\AssessmentSectionRef $assessmentSectionRef An AssessmentSectionRef object to dereference. @param \qtism\data\storage\FileResolver $resolver The Resolver object to be used to resolve AssessmentSectionRef's href attribute. @throws \qtism\data\storage\xml\XmlStorageException If an error occurs while dereferencing the referenced file. @return \qtism\data\XmlDocument The AssessmentSection referenced by $assessmentSectionRef as an XmlDocument object.
[ "Dereference", "the", "file", "referenced", "by", "an", "assessmentSectionRef", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/XmlCompactDocument.php#L340-L354
oat-sa/qti-sdk
src/qtism/data/storage/xml/XmlCompactDocument.php
XmlCompactDocument.schemaValidate
public function schemaValidate($filename = '') { if (empty($filename)) { $dS = DIRECTORY_SEPARATOR; // default xsd for AssessmentTest. $filename = dirname(__FILE__) . $dS . 'schemes' . $dS . 'qticompact_v1p0.xsd'; } parent::schemaValidate($filename); }
php
public function schemaValidate($filename = '') { if (empty($filename)) { $dS = DIRECTORY_SEPARATOR; // default xsd for AssessmentTest. $filename = dirname(__FILE__) . $dS . 'schemes' . $dS . 'qticompact_v1p0.xsd'; } parent::schemaValidate($filename); }
[ "public", "function", "schemaValidate", "(", "$", "filename", "=", "''", ")", "{", "if", "(", "empty", "(", "$", "filename", ")", ")", "{", "$", "dS", "=", "DIRECTORY_SEPARATOR", ";", "// default xsd for AssessmentTest.", "$", "filename", "=", "dirname", "(", "__FILE__", ")", ".", "$", "dS", ".", "'schemes'", ".", "$", "dS", ".", "'qticompact_v1p0.xsd'", ";", "}", "parent", "::", "schemaValidate", "(", "$", "filename", ")", ";", "}" ]
Validate the compact AssessmentTest XML document according to the relevant XSD schema. If $filename is provided, the file pointed by $filename will be used instead of the default schema. @param string $filename An optional filename to force the validation against a particular schema. @return boolean
[ "Validate", "the", "compact", "AssessmentTest", "XML", "document", "according", "to", "the", "relevant", "XSD", "schema", ".", "If", "$filename", "is", "provided", "the", "file", "pointed", "by", "$filename", "will", "be", "used", "instead", "of", "the", "default", "schema", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/XmlCompactDocument.php#L364-L373
oat-sa/qti-sdk
src/qtism/runtime/expressions/operators/OperatorProcessor.php
OperatorProcessor.setOperands
public function setOperands(OperandsCollection $operands) { // Check minimal operand count. $min = $this->getExpression()->getMinOperands(); $given = count($operands); if ($given < $min) { $msg = "The Operator to be processed '" . get_class($this) . "' requires at least ${min} operand(s). "; $msg.= "${given} operand(s) given."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::NOT_ENOUGH_OPERANDS); } // Check maximal operand count. $max = $this->getExpression()->getMaxOperands(); $given = count($operands); if ($max !== -1 && $given > $max) { $msg = "The Operator to be processed '" . get_class($this) . "' requires at most ${max} operand(s). "; $msg.= "${given} operand(s) given."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::TOO_MUCH_OPERANDS); } $this->operands = $operands; }
php
public function setOperands(OperandsCollection $operands) { // Check minimal operand count. $min = $this->getExpression()->getMinOperands(); $given = count($operands); if ($given < $min) { $msg = "The Operator to be processed '" . get_class($this) . "' requires at least ${min} operand(s). "; $msg.= "${given} operand(s) given."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::NOT_ENOUGH_OPERANDS); } // Check maximal operand count. $max = $this->getExpression()->getMaxOperands(); $given = count($operands); if ($max !== -1 && $given > $max) { $msg = "The Operator to be processed '" . get_class($this) . "' requires at most ${max} operand(s). "; $msg.= "${given} operand(s) given."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::TOO_MUCH_OPERANDS); } $this->operands = $operands; }
[ "public", "function", "setOperands", "(", "OperandsCollection", "$", "operands", ")", "{", "// Check minimal operand count.", "$", "min", "=", "$", "this", "->", "getExpression", "(", ")", "->", "getMinOperands", "(", ")", ";", "$", "given", "=", "count", "(", "$", "operands", ")", ";", "if", "(", "$", "given", "<", "$", "min", ")", "{", "$", "msg", "=", "\"The Operator to be processed '\"", ".", "get_class", "(", "$", "this", ")", ".", "\"' requires at least ${min} operand(s). \"", ";", "$", "msg", ".=", "\"${given} operand(s) given.\"", ";", "throw", "new", "OperatorProcessingException", "(", "$", "msg", ",", "$", "this", ",", "OperatorProcessingException", "::", "NOT_ENOUGH_OPERANDS", ")", ";", "}", "// Check maximal operand count.", "$", "max", "=", "$", "this", "->", "getExpression", "(", ")", "->", "getMaxOperands", "(", ")", ";", "$", "given", "=", "count", "(", "$", "operands", ")", ";", "if", "(", "$", "max", "!==", "-", "1", "&&", "$", "given", ">", "$", "max", ")", "{", "$", "msg", "=", "\"The Operator to be processed '\"", ".", "get_class", "(", "$", "this", ")", ".", "\"' requires at most ${max} operand(s). \"", ";", "$", "msg", ".=", "\"${given} operand(s) given.\"", ";", "throw", "new", "OperatorProcessingException", "(", "$", "msg", ",", "$", "this", ",", "OperatorProcessingException", "::", "TOO_MUCH_OPERANDS", ")", ";", "}", "$", "this", "->", "operands", "=", "$", "operands", ";", "}" ]
Set the collection of QTI Runtime compliant values to be used as the operands of the Operator to be processed. @param \qtism\runtime\expressions\operators\OperandsCollection $operands A collection of QTI Runtime compliant values. @throws \qtism\runtime\expressions\operators\OperatorProcessingException If The operands are not compliant with minimum or maximum amount of operands the operator can take.
[ "Set", "the", "collection", "of", "QTI", "Runtime", "compliant", "values", "to", "be", "used", "as", "the", "operands", "of", "the", "Operator", "to", "be", "processed", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/OperatorProcessor.php#L59-L82
oat-sa/qti-sdk
src/qtism/data/storage/xml/marshalling/ParamMarshaller.php
ParamMarshaller.marshall
protected function marshall(QtiComponent $component) { $element = self::getDOMCradle()->createElement('param'); $this->setDOMElementAttribute($element, 'name', $component->getName()); $this->setDOMElementAttribute($element, 'value', $component->getValue()); $this->setDOMElementAttribute($element, 'valuetype', ParamType::getNameByConstant($component->getValueType())); if ($component->hasType() === true) { $this->setDOMElementAttribute($element, 'type', $component->getType()); } return $element; }
php
protected function marshall(QtiComponent $component) { $element = self::getDOMCradle()->createElement('param'); $this->setDOMElementAttribute($element, 'name', $component->getName()); $this->setDOMElementAttribute($element, 'value', $component->getValue()); $this->setDOMElementAttribute($element, 'valuetype', ParamType::getNameByConstant($component->getValueType())); if ($component->hasType() === true) { $this->setDOMElementAttribute($element, 'type', $component->getType()); } return $element; }
[ "protected", "function", "marshall", "(", "QtiComponent", "$", "component", ")", "{", "$", "element", "=", "self", "::", "getDOMCradle", "(", ")", "->", "createElement", "(", "'param'", ")", ";", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'name'", ",", "$", "component", "->", "getName", "(", ")", ")", ";", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'value'", ",", "$", "component", "->", "getValue", "(", ")", ")", ";", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'valuetype'", ",", "ParamType", "::", "getNameByConstant", "(", "$", "component", "->", "getValueType", "(", ")", ")", ")", ";", "if", "(", "$", "component", "->", "hasType", "(", ")", "===", "true", ")", "{", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'type'", ",", "$", "component", "->", "getType", "(", ")", ")", ";", "}", "return", "$", "element", ";", "}" ]
Marshall a Param object into a DOMElement object. @param \qtism\data\QtiComponent $component A Param object. @return \DOMElement The according DOMElement object. @throws \qtism\data\storage\xml\marshalling\MarshallingException
[ "Marshall", "a", "Param", "object", "into", "a", "DOMElement", "object", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/ParamMarshaller.php#L45-L57
oat-sa/qti-sdk
src/qtism/data/storage/xml/marshalling/ParamMarshaller.php
ParamMarshaller.unmarshall
protected function unmarshall(DOMElement $element) { if (($name = $this->getDOMElementAttributeAs($element, 'name')) === null) { // XSD use="required" but can be empty. $name = ''; } if (($value = $this->getDOMElementAttributeAs($element, 'value')) === null) { // XSD use="required" but can be empty. $value = ''; } if (($valueType = $this->getDOMElementAttributeAs($element, 'valuetype')) !== null) { $component = new Param($name, $value, ParamType::getConstantByName($valueType)); if (($type = $this->getDOMElementAttributeAs($element, 'type')) !== null) { $component->setType($type); } return $component; } else { $msg = "The mandatory attribute 'valueType' is missing from the 'param' element."; throw new UnmarshallingException($msg, $element); } }
php
protected function unmarshall(DOMElement $element) { if (($name = $this->getDOMElementAttributeAs($element, 'name')) === null) { // XSD use="required" but can be empty. $name = ''; } if (($value = $this->getDOMElementAttributeAs($element, 'value')) === null) { // XSD use="required" but can be empty. $value = ''; } if (($valueType = $this->getDOMElementAttributeAs($element, 'valuetype')) !== null) { $component = new Param($name, $value, ParamType::getConstantByName($valueType)); if (($type = $this->getDOMElementAttributeAs($element, 'type')) !== null) { $component->setType($type); } return $component; } else { $msg = "The mandatory attribute 'valueType' is missing from the 'param' element."; throw new UnmarshallingException($msg, $element); } }
[ "protected", "function", "unmarshall", "(", "DOMElement", "$", "element", ")", "{", "if", "(", "(", "$", "name", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'name'", ")", ")", "===", "null", ")", "{", "// XSD use=\"required\" but can be empty.", "$", "name", "=", "''", ";", "}", "if", "(", "(", "$", "value", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'value'", ")", ")", "===", "null", ")", "{", "// XSD use=\"required\" but can be empty.", "$", "value", "=", "''", ";", "}", "if", "(", "(", "$", "valueType", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'valuetype'", ")", ")", "!==", "null", ")", "{", "$", "component", "=", "new", "Param", "(", "$", "name", ",", "$", "value", ",", "ParamType", "::", "getConstantByName", "(", "$", "valueType", ")", ")", ";", "if", "(", "(", "$", "type", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'type'", ")", ")", "!==", "null", ")", "{", "$", "component", "->", "setType", "(", "$", "type", ")", ";", "}", "return", "$", "component", ";", "}", "else", "{", "$", "msg", "=", "\"The mandatory attribute 'valueType' is missing from the 'param' element.\"", ";", "throw", "new", "UnmarshallingException", "(", "$", "msg", ",", "$", "element", ")", ";", "}", "}" ]
Unmarshall a DOMElement object corresponding to an XHTML param element. @param \DOMElement $element A DOMElement object. @return \qtism\data\QtiComponent A Param object. @throws \qtism\data\storage\xml\marshalling\UnmarshallingException
[ "Unmarshall", "a", "DOMElement", "object", "corresponding", "to", "an", "XHTML", "param", "element", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/ParamMarshaller.php#L66-L91
oat-sa/qti-sdk
src/qtism/runtime/expressions/operators/IntegerToFloatProcessor.php
IntegerToFloatProcessor.process
public function process() { $operands = $this->getOperands(); if ($operands->containsNull() === true) { return null; } if ($operands->exclusivelySingle() === false) { $msg = "The IntegerToFloat operator only accepts operands with a single cardinality."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY); } if ($operands->exclusivelyInteger() === false) { $msg = "The IntegerToFloat operator only accepts operands with baseType integer."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE); } $operand = $operands[0]; return new QtiFloat(floatval($operand->getValue())); }
php
public function process() { $operands = $this->getOperands(); if ($operands->containsNull() === true) { return null; } if ($operands->exclusivelySingle() === false) { $msg = "The IntegerToFloat operator only accepts operands with a single cardinality."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY); } if ($operands->exclusivelyInteger() === false) { $msg = "The IntegerToFloat operator only accepts operands with baseType integer."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE); } $operand = $operands[0]; return new QtiFloat(floatval($operand->getValue())); }
[ "public", "function", "process", "(", ")", "{", "$", "operands", "=", "$", "this", "->", "getOperands", "(", ")", ";", "if", "(", "$", "operands", "->", "containsNull", "(", ")", "===", "true", ")", "{", "return", "null", ";", "}", "if", "(", "$", "operands", "->", "exclusivelySingle", "(", ")", "===", "false", ")", "{", "$", "msg", "=", "\"The IntegerToFloat operator only accepts operands with a single cardinality.\"", ";", "throw", "new", "OperatorProcessingException", "(", "$", "msg", ",", "$", "this", ",", "OperatorProcessingException", "::", "WRONG_CARDINALITY", ")", ";", "}", "if", "(", "$", "operands", "->", "exclusivelyInteger", "(", ")", "===", "false", ")", "{", "$", "msg", "=", "\"The IntegerToFloat operator only accepts operands with baseType integer.\"", ";", "throw", "new", "OperatorProcessingException", "(", "$", "msg", ",", "$", "this", ",", "OperatorProcessingException", "::", "WRONG_BASETYPE", ")", ";", "}", "$", "operand", "=", "$", "operands", "[", "0", "]", ";", "return", "new", "QtiFloat", "(", "floatval", "(", "$", "operand", "->", "getValue", "(", ")", ")", ")", ";", "}" ]
Process the IntegerToFloat operator. @return float|null A float value with the same numeric value as the sub-expression or NULL if the sub-expression is considered to be NULL. @throws \qtism\runtime\expressions\operators\OperatorProcessingException
[ "Process", "the", "IntegerToFloat", "operator", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/IntegerToFloatProcessor.php#L51-L72
oat-sa/qti-sdk
src/qtism/runtime/rules/LookupOutcomeValueProcessor.php
LookupOutcomeValueProcessor.process
public function process() { $state = $this->getState(); $rule = $this->getRule(); $identifier = $rule->getIdentifier(); $var = $state->getVariable($identifier); if (is_null($var) === true) { $msg = "The variable to set '${identifier}' does not exist in the current state."; throw new RuleProcessingException($msg, $this, RuleProcessingException::NONEXISTENT_VARIABLE); } elseif (!$var instanceof OutcomeVariable) { $msg = "The variable to set '${identifier}' is not an OutcomeVariable."; throw new RuleProcessingException($msg, $this, RuleProcessingException::WRONG_VARIABLE_TYPE); } $expression = $rule->getExpression(); $expressionEngine = new ExpressionEngine($expression, $state); try { $val = $expressionEngine->process(); // Let's lookup the associated table. $table = $var->getLookupTable(); if (is_null($table) === true) { $msg = "No lookupTable in declaration of variable '${identifier}'."; throw new RuleProcessingException($msg, $this, RuleProcessingException::LOGIC_ERROR); } // $targetVal = The value that will be set to the target variable. // // As per specs: // The default outcome value to be used when no matching table // entry is found. If omitted, the NULL value is used. $targetVal = $table->getDefaultValue(); if ($table instanceof InterpolationTable) { if (!$val instanceof QtiFloat && !$val instanceof QtiInteger && !$val instanceof QtiDuration) { $msg = "The value of variable '${identifier}' must be integer, float or duration when used with an interpolationTable"; throw new RuleProcessingException($msg, $this, RuleProcessingException::LOGIC_ERROR); } foreach ($table->getInterpolationTableEntries() as $entry) { $lowerBound = $entry->getSourceValue(); $includeBoundary = $entry->doesIncludeBoundary(); if ($includeBoundary === true && $val->getValue() <= $lowerBound) { $targetVal = $entry->getTargetValue(); break; } elseif ($includeBoundary === false && $val->getValue() < $lowerBound) { $targetVal = $entry->getTargetValue(); break; } } } else { // $table instanceof MatchTable if (!$val instanceof QtiInteger) { $msg = "The value of the variable '${identifier}' must be integer when used with a matchTable."; throw new RuleProcessingException($msg, $this, RuleProcessingException::LOGIC_ERROR); } foreach ($table->getMatchTableEntries() as $entry) { if ($entry->getSourceValue() === $val->getValue()) { $targetVal = $entry->getTargetValue(); break; } } } // assign target value try { $finalVal = RuntimeUtils::valueToRuntime($targetVal, $var->getBaseType()); $state[$identifier] = $finalVal; } catch (InvalidArgumentException $e) { // $targetVal's baseType not compliant with target variable's baseType. $msg = "The looked up value's baseType is not compliant with the baseType of variable '${identifier}'."; throw new RuleProcessingException($msg, $this, RuleProcessingException::RUNTIME_ERROR); } } catch (ExpressionProcessingException $e) { $msg = "An error occured while processing the expression bound to the lookupOutcomeValue rule."; throw new RuleProcessingException($msg, $this, RuleProcessingException::RUNTIME_ERROR, $e); } }
php
public function process() { $state = $this->getState(); $rule = $this->getRule(); $identifier = $rule->getIdentifier(); $var = $state->getVariable($identifier); if (is_null($var) === true) { $msg = "The variable to set '${identifier}' does not exist in the current state."; throw new RuleProcessingException($msg, $this, RuleProcessingException::NONEXISTENT_VARIABLE); } elseif (!$var instanceof OutcomeVariable) { $msg = "The variable to set '${identifier}' is not an OutcomeVariable."; throw new RuleProcessingException($msg, $this, RuleProcessingException::WRONG_VARIABLE_TYPE); } $expression = $rule->getExpression(); $expressionEngine = new ExpressionEngine($expression, $state); try { $val = $expressionEngine->process(); // Let's lookup the associated table. $table = $var->getLookupTable(); if (is_null($table) === true) { $msg = "No lookupTable in declaration of variable '${identifier}'."; throw new RuleProcessingException($msg, $this, RuleProcessingException::LOGIC_ERROR); } // $targetVal = The value that will be set to the target variable. // // As per specs: // The default outcome value to be used when no matching table // entry is found. If omitted, the NULL value is used. $targetVal = $table->getDefaultValue(); if ($table instanceof InterpolationTable) { if (!$val instanceof QtiFloat && !$val instanceof QtiInteger && !$val instanceof QtiDuration) { $msg = "The value of variable '${identifier}' must be integer, float or duration when used with an interpolationTable"; throw new RuleProcessingException($msg, $this, RuleProcessingException::LOGIC_ERROR); } foreach ($table->getInterpolationTableEntries() as $entry) { $lowerBound = $entry->getSourceValue(); $includeBoundary = $entry->doesIncludeBoundary(); if ($includeBoundary === true && $val->getValue() <= $lowerBound) { $targetVal = $entry->getTargetValue(); break; } elseif ($includeBoundary === false && $val->getValue() < $lowerBound) { $targetVal = $entry->getTargetValue(); break; } } } else { // $table instanceof MatchTable if (!$val instanceof QtiInteger) { $msg = "The value of the variable '${identifier}' must be integer when used with a matchTable."; throw new RuleProcessingException($msg, $this, RuleProcessingException::LOGIC_ERROR); } foreach ($table->getMatchTableEntries() as $entry) { if ($entry->getSourceValue() === $val->getValue()) { $targetVal = $entry->getTargetValue(); break; } } } // assign target value try { $finalVal = RuntimeUtils::valueToRuntime($targetVal, $var->getBaseType()); $state[$identifier] = $finalVal; } catch (InvalidArgumentException $e) { // $targetVal's baseType not compliant with target variable's baseType. $msg = "The looked up value's baseType is not compliant with the baseType of variable '${identifier}'."; throw new RuleProcessingException($msg, $this, RuleProcessingException::RUNTIME_ERROR); } } catch (ExpressionProcessingException $e) { $msg = "An error occured while processing the expression bound to the lookupOutcomeValue rule."; throw new RuleProcessingException($msg, $this, RuleProcessingException::RUNTIME_ERROR, $e); } }
[ "public", "function", "process", "(", ")", "{", "$", "state", "=", "$", "this", "->", "getState", "(", ")", ";", "$", "rule", "=", "$", "this", "->", "getRule", "(", ")", ";", "$", "identifier", "=", "$", "rule", "->", "getIdentifier", "(", ")", ";", "$", "var", "=", "$", "state", "->", "getVariable", "(", "$", "identifier", ")", ";", "if", "(", "is_null", "(", "$", "var", ")", "===", "true", ")", "{", "$", "msg", "=", "\"The variable to set '${identifier}' does not exist in the current state.\"", ";", "throw", "new", "RuleProcessingException", "(", "$", "msg", ",", "$", "this", ",", "RuleProcessingException", "::", "NONEXISTENT_VARIABLE", ")", ";", "}", "elseif", "(", "!", "$", "var", "instanceof", "OutcomeVariable", ")", "{", "$", "msg", "=", "\"The variable to set '${identifier}' is not an OutcomeVariable.\"", ";", "throw", "new", "RuleProcessingException", "(", "$", "msg", ",", "$", "this", ",", "RuleProcessingException", "::", "WRONG_VARIABLE_TYPE", ")", ";", "}", "$", "expression", "=", "$", "rule", "->", "getExpression", "(", ")", ";", "$", "expressionEngine", "=", "new", "ExpressionEngine", "(", "$", "expression", ",", "$", "state", ")", ";", "try", "{", "$", "val", "=", "$", "expressionEngine", "->", "process", "(", ")", ";", "// Let's lookup the associated table.", "$", "table", "=", "$", "var", "->", "getLookupTable", "(", ")", ";", "if", "(", "is_null", "(", "$", "table", ")", "===", "true", ")", "{", "$", "msg", "=", "\"No lookupTable in declaration of variable '${identifier}'.\"", ";", "throw", "new", "RuleProcessingException", "(", "$", "msg", ",", "$", "this", ",", "RuleProcessingException", "::", "LOGIC_ERROR", ")", ";", "}", "// $targetVal = The value that will be set to the target variable.", "//", "// As per specs:", "// The default outcome value to be used when no matching table", "// entry is found. If omitted, the NULL value is used.", "$", "targetVal", "=", "$", "table", "->", "getDefaultValue", "(", ")", ";", "if", "(", "$", "table", "instanceof", "InterpolationTable", ")", "{", "if", "(", "!", "$", "val", "instanceof", "QtiFloat", "&&", "!", "$", "val", "instanceof", "QtiInteger", "&&", "!", "$", "val", "instanceof", "QtiDuration", ")", "{", "$", "msg", "=", "\"The value of variable '${identifier}' must be integer, float or duration when used with an interpolationTable\"", ";", "throw", "new", "RuleProcessingException", "(", "$", "msg", ",", "$", "this", ",", "RuleProcessingException", "::", "LOGIC_ERROR", ")", ";", "}", "foreach", "(", "$", "table", "->", "getInterpolationTableEntries", "(", ")", "as", "$", "entry", ")", "{", "$", "lowerBound", "=", "$", "entry", "->", "getSourceValue", "(", ")", ";", "$", "includeBoundary", "=", "$", "entry", "->", "doesIncludeBoundary", "(", ")", ";", "if", "(", "$", "includeBoundary", "===", "true", "&&", "$", "val", "->", "getValue", "(", ")", "<=", "$", "lowerBound", ")", "{", "$", "targetVal", "=", "$", "entry", "->", "getTargetValue", "(", ")", ";", "break", ";", "}", "elseif", "(", "$", "includeBoundary", "===", "false", "&&", "$", "val", "->", "getValue", "(", ")", "<", "$", "lowerBound", ")", "{", "$", "targetVal", "=", "$", "entry", "->", "getTargetValue", "(", ")", ";", "break", ";", "}", "}", "}", "else", "{", "// $table instanceof MatchTable", "if", "(", "!", "$", "val", "instanceof", "QtiInteger", ")", "{", "$", "msg", "=", "\"The value of the variable '${identifier}' must be integer when used with a matchTable.\"", ";", "throw", "new", "RuleProcessingException", "(", "$", "msg", ",", "$", "this", ",", "RuleProcessingException", "::", "LOGIC_ERROR", ")", ";", "}", "foreach", "(", "$", "table", "->", "getMatchTableEntries", "(", ")", "as", "$", "entry", ")", "{", "if", "(", "$", "entry", "->", "getSourceValue", "(", ")", "===", "$", "val", "->", "getValue", "(", ")", ")", "{", "$", "targetVal", "=", "$", "entry", "->", "getTargetValue", "(", ")", ";", "break", ";", "}", "}", "}", "// assign target value", "try", "{", "$", "finalVal", "=", "RuntimeUtils", "::", "valueToRuntime", "(", "$", "targetVal", ",", "$", "var", "->", "getBaseType", "(", ")", ")", ";", "$", "state", "[", "$", "identifier", "]", "=", "$", "finalVal", ";", "}", "catch", "(", "InvalidArgumentException", "$", "e", ")", "{", "// $targetVal's baseType not compliant with target variable's baseType.", "$", "msg", "=", "\"The looked up value's baseType is not compliant with the baseType of variable '${identifier}'.\"", ";", "throw", "new", "RuleProcessingException", "(", "$", "msg", ",", "$", "this", ",", "RuleProcessingException", "::", "RUNTIME_ERROR", ")", ";", "}", "}", "catch", "(", "ExpressionProcessingException", "$", "e", ")", "{", "$", "msg", "=", "\"An error occured while processing the expression bound to the lookupOutcomeValue rule.\"", ";", "throw", "new", "RuleProcessingException", "(", "$", "msg", ",", "$", "this", ",", "RuleProcessingException", "::", "RUNTIME_ERROR", ",", "$", "e", ")", ";", "}", "}" ]
Process the LookupOutcomeValue rule. A RuleProcessingException will be thrown if: * The outcome variable to set does not exist. * The variable to set is not an OutcomeVariable * The outcome variable's baseType does not match the baseType of the affected value (the result of the bound expression). * The outcome variable's declaration has no associated lookup table. * The variable's declaration contains a matchTable but the result of the bound expression is not an integer. * The variable's declaration contains an interpolationTable but the result of the bound expression is not an integer, nor a float. * There is no associated table in the variable's declaration. * An error occurs during the processing of the related expression. @throws \qtism\runtime\rules\RuleProcessingException If one of the error described above arise.
[ "Process", "the", "LookupOutcomeValue", "rule", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rules/LookupOutcomeValueProcessor.php#L65-L148
oat-sa/qti-sdk
src/qtism/runtime/expressions/operators/TruncateProcessor.php
TruncateProcessor.process
public function process() { $operands = $this->getOperands(); if ($operands->containsNull() === true) { return null; } if ($operands->exclusivelySingle() === false) { $msg = "The Truncate operator only accepts operands with a single cardinality."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY); } if ($operands->exclusivelyNumeric() === false) { $msg = "The Truncate operator only accepts operands with an integer or float baseType."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE); } $operand = $operands[0]; if (is_nan($operand->getValue())) { return null; } elseif (is_infinite($operand->getValue())) { return new QtiFloat(INF); } else { return new QtiInteger(intval($operand->getValue())); } }
php
public function process() { $operands = $this->getOperands(); if ($operands->containsNull() === true) { return null; } if ($operands->exclusivelySingle() === false) { $msg = "The Truncate operator only accepts operands with a single cardinality."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY); } if ($operands->exclusivelyNumeric() === false) { $msg = "The Truncate operator only accepts operands with an integer or float baseType."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE); } $operand = $operands[0]; if (is_nan($operand->getValue())) { return null; } elseif (is_infinite($operand->getValue())) { return new QtiFloat(INF); } else { return new QtiInteger(intval($operand->getValue())); } }
[ "public", "function", "process", "(", ")", "{", "$", "operands", "=", "$", "this", "->", "getOperands", "(", ")", ";", "if", "(", "$", "operands", "->", "containsNull", "(", ")", "===", "true", ")", "{", "return", "null", ";", "}", "if", "(", "$", "operands", "->", "exclusivelySingle", "(", ")", "===", "false", ")", "{", "$", "msg", "=", "\"The Truncate operator only accepts operands with a single cardinality.\"", ";", "throw", "new", "OperatorProcessingException", "(", "$", "msg", ",", "$", "this", ",", "OperatorProcessingException", "::", "WRONG_CARDINALITY", ")", ";", "}", "if", "(", "$", "operands", "->", "exclusivelyNumeric", "(", ")", "===", "false", ")", "{", "$", "msg", "=", "\"The Truncate operator only accepts operands with an integer or float baseType.\"", ";", "throw", "new", "OperatorProcessingException", "(", "$", "msg", ",", "$", "this", ",", "OperatorProcessingException", "::", "WRONG_BASETYPE", ")", ";", "}", "$", "operand", "=", "$", "operands", "[", "0", "]", ";", "if", "(", "is_nan", "(", "$", "operand", "->", "getValue", "(", ")", ")", ")", "{", "return", "null", ";", "}", "elseif", "(", "is_infinite", "(", "$", "operand", "->", "getValue", "(", ")", ")", ")", "{", "return", "new", "QtiFloat", "(", "INF", ")", ";", "}", "else", "{", "return", "new", "QtiInteger", "(", "intval", "(", "$", "operand", "->", "getValue", "(", ")", ")", ")", ";", "}", "}" ]
Process the Truncate operator. @return integer|null The truncated value or NULL if the sub-expression is NaN or if the sub-expression is NULL. @throws \qtism\runtime\expressions\operators\OperatorProcessingException
[ "Process", "the", "Truncate", "operator", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/TruncateProcessor.php#L56-L83
oat-sa/qti-sdk
src/qtism/runtime/expressions/ExpressionProcessor.php
ExpressionProcessor.setExpression
public function setExpression(Expression $expression) { $expectedType = $this->getExpressionType(); if (ReflectionUtils::isInstanceOf($expression, $expectedType) === true) { $this->expression = $expression; } else { $procClass = get_class($this); $givenType = get_class($expression); $msg = "The ${procClass} Expression Processor only processes ${expectedType} Expression objects, ${givenType} given."; throw new InvalidArgumentException($msg); } $this->expression = $expression; }
php
public function setExpression(Expression $expression) { $expectedType = $this->getExpressionType(); if (ReflectionUtils::isInstanceOf($expression, $expectedType) === true) { $this->expression = $expression; } else { $procClass = get_class($this); $givenType = get_class($expression); $msg = "The ${procClass} Expression Processor only processes ${expectedType} Expression objects, ${givenType} given."; throw new InvalidArgumentException($msg); } $this->expression = $expression; }
[ "public", "function", "setExpression", "(", "Expression", "$", "expression", ")", "{", "$", "expectedType", "=", "$", "this", "->", "getExpressionType", "(", ")", ";", "if", "(", "ReflectionUtils", "::", "isInstanceOf", "(", "$", "expression", ",", "$", "expectedType", ")", "===", "true", ")", "{", "$", "this", "->", "expression", "=", "$", "expression", ";", "}", "else", "{", "$", "procClass", "=", "get_class", "(", "$", "this", ")", ";", "$", "givenType", "=", "get_class", "(", "$", "expression", ")", ";", "$", "msg", "=", "\"The ${procClass} Expression Processor only processes ${expectedType} Expression objects, ${givenType} given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "$", "this", "->", "expression", "=", "$", "expression", ";", "}" ]
Set the QTI Data Model Expression to be processed. @param \qtism\data\expressions\Expression $expression A QTI Data Model Expression object. @throws \InvalidArgumentException If $expression is not a subclass nor implements the Expression type returned by the getExpressionType method.
[ "Set", "the", "QTI", "Data", "Model", "Expression", "to", "be", "processed", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/ExpressionProcessor.php#L72-L86
oat-sa/qti-sdk
src/qtism/data/state/VariableDeclaration.php
VariableDeclaration.setCardinality
public function setCardinality($cardinality) { if (in_array($cardinality, Cardinality::asArray())) { $this->cardinality = $cardinality; } else { $msg = "The cardinality must be a value from the Cardinality enumeration."; throw new InvalidArgumentException($msg); } }
php
public function setCardinality($cardinality) { if (in_array($cardinality, Cardinality::asArray())) { $this->cardinality = $cardinality; } else { $msg = "The cardinality must be a value from the Cardinality enumeration."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setCardinality", "(", "$", "cardinality", ")", "{", "if", "(", "in_array", "(", "$", "cardinality", ",", "Cardinality", "::", "asArray", "(", ")", ")", ")", "{", "$", "this", "->", "cardinality", "=", "$", "cardinality", ";", "}", "else", "{", "$", "msg", "=", "\"The cardinality must be a value from the Cardinality enumeration.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set the cardinality of the variable. @param int $cardinality A value from the Cardinality enumeration. @throws \InvalidArgumentException If $cardinality is not a value from the Cardinality enumeration.
[ "Set", "the", "cardinality", "of", "the", "variable", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/state/VariableDeclaration.php#L235-L243
oat-sa/qti-sdk
src/qtism/runtime/rendering/markup/xhtml/AbstractXhtmlRenderer.php
AbstractXhtmlRenderer.render
public function render($component, $base = '') { $renderingEngine = $this->getRenderingEngine(); $doc = $renderingEngine->getDocument(); $fragment = $doc->createDocumentFragment(); // Apply rendering... $this->renderingImplementation($fragment, $component, $base); // Specific case for stylesheet elements... if ($component instanceof Stylesheet && $renderingEngine->getStylesheetPolicy() === AbstractMarkupRenderingEngine::STYLESHEET_SEPARATE) { // Stylesheet must be rendered separately. $stylesheets = $renderingEngine->getStylesheets(); $stylesheets->appendChild($fragment); } else { // Stylesheet must be rendered at the same place. $renderingEngine->storeRendering($component, $fragment); } return $fragment; }
php
public function render($component, $base = '') { $renderingEngine = $this->getRenderingEngine(); $doc = $renderingEngine->getDocument(); $fragment = $doc->createDocumentFragment(); // Apply rendering... $this->renderingImplementation($fragment, $component, $base); // Specific case for stylesheet elements... if ($component instanceof Stylesheet && $renderingEngine->getStylesheetPolicy() === AbstractMarkupRenderingEngine::STYLESHEET_SEPARATE) { // Stylesheet must be rendered separately. $stylesheets = $renderingEngine->getStylesheets(); $stylesheets->appendChild($fragment); } else { // Stylesheet must be rendered at the same place. $renderingEngine->storeRendering($component, $fragment); } return $fragment; }
[ "public", "function", "render", "(", "$", "component", ",", "$", "base", "=", "''", ")", "{", "$", "renderingEngine", "=", "$", "this", "->", "getRenderingEngine", "(", ")", ";", "$", "doc", "=", "$", "renderingEngine", "->", "getDocument", "(", ")", ";", "$", "fragment", "=", "$", "doc", "->", "createDocumentFragment", "(", ")", ";", "// Apply rendering...", "$", "this", "->", "renderingImplementation", "(", "$", "fragment", ",", "$", "component", ",", "$", "base", ")", ";", "// Specific case for stylesheet elements...", "if", "(", "$", "component", "instanceof", "Stylesheet", "&&", "$", "renderingEngine", "->", "getStylesheetPolicy", "(", ")", "===", "AbstractMarkupRenderingEngine", "::", "STYLESHEET_SEPARATE", ")", "{", "// Stylesheet must be rendered separately.", "$", "stylesheets", "=", "$", "renderingEngine", "->", "getStylesheets", "(", ")", ";", "$", "stylesheets", "->", "appendChild", "(", "$", "fragment", ")", ";", "}", "else", "{", "// Stylesheet must be rendered at the same place.", "$", "renderingEngine", "->", "storeRendering", "(", "$", "component", ",", "$", "fragment", ")", ";", "}", "return", "$", "fragment", ";", "}" ]
Render a QtiComponent into a DOMDocumentFragment that will be registered in the current rendering context. @return \DOMDocumentFragment A DOMDocumentFragment object containing the rendered $component into another constitution with its children rendering appended. @throws \qtism\runtime\rendering\RenderingException If an error occurs while rendering $component.
[ "Render", "a", "QtiComponent", "into", "a", "DOMDocumentFragment", "that", "will", "be", "registered", "in", "the", "current", "rendering", "context", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/markup/xhtml/AbstractXhtmlRenderer.php#L82-L102
oat-sa/qti-sdk
src/qtism/runtime/rendering/markup/xhtml/AbstractXhtmlRenderer.php
AbstractXhtmlRenderer.renderingImplementation
protected function renderingImplementation(DOMDocumentFragment $fragment, QtiComponent $component, $base = '') { $this->appendElement($fragment, $component, $base); $this->appendChildren($fragment, $component, $base); $this->appendAttributes($fragment, $component, $base); if ($this->getRenderingEngine()->getCssClassPolicy() === AbstractMarkupRenderingEngine::CSSCLASS_ABSTRACT) { // The whole hierarchy of qti- CSS classes must be rendered. if ($this->hasAdditionalClasses() === true) { $classes = implode("\x20", $this->getAdditionalClasses()); $currentClasses = $fragment->firstChild->getAttribute('class'); $glue = ($currentClasses !== '') ? "\x20" : ""; $fragment->firstChild->setAttribute('class', $currentClasses . $glue . $classes); } } else { // Only the last added qti- CSS class must be rendered. if ($this->hasAdditionalClasses() === true) { $classes = $this->getAdditionalClasses(); $class = array_pop($classes); $fragment->firstChild->setAttribute('class', $class); } } // Add user specific CSS classes e.g. 'my-class' to rendering. if ($this->hasAdditionalUserClasses() === true) { $classes = implode("\x20", $this->getAdditionalUserClasses()); $currentClasses = $fragment->firstChild->getAttribute('class'); $glue = ($currentClasses !== '') ? "\x20" : ""; $fragment->firstChild->setAttribute('class', $currentClasses . $glue . $classes); } // Reset additional user classes for next rendering with this implementation. $this->setAdditionalUserClasses(array()); }
php
protected function renderingImplementation(DOMDocumentFragment $fragment, QtiComponent $component, $base = '') { $this->appendElement($fragment, $component, $base); $this->appendChildren($fragment, $component, $base); $this->appendAttributes($fragment, $component, $base); if ($this->getRenderingEngine()->getCssClassPolicy() === AbstractMarkupRenderingEngine::CSSCLASS_ABSTRACT) { // The whole hierarchy of qti- CSS classes must be rendered. if ($this->hasAdditionalClasses() === true) { $classes = implode("\x20", $this->getAdditionalClasses()); $currentClasses = $fragment->firstChild->getAttribute('class'); $glue = ($currentClasses !== '') ? "\x20" : ""; $fragment->firstChild->setAttribute('class', $currentClasses . $glue . $classes); } } else { // Only the last added qti- CSS class must be rendered. if ($this->hasAdditionalClasses() === true) { $classes = $this->getAdditionalClasses(); $class = array_pop($classes); $fragment->firstChild->setAttribute('class', $class); } } // Add user specific CSS classes e.g. 'my-class' to rendering. if ($this->hasAdditionalUserClasses() === true) { $classes = implode("\x20", $this->getAdditionalUserClasses()); $currentClasses = $fragment->firstChild->getAttribute('class'); $glue = ($currentClasses !== '') ? "\x20" : ""; $fragment->firstChild->setAttribute('class', $currentClasses . $glue . $classes); } // Reset additional user classes for next rendering with this implementation. $this->setAdditionalUserClasses(array()); }
[ "protected", "function", "renderingImplementation", "(", "DOMDocumentFragment", "$", "fragment", ",", "QtiComponent", "$", "component", ",", "$", "base", "=", "''", ")", "{", "$", "this", "->", "appendElement", "(", "$", "fragment", ",", "$", "component", ",", "$", "base", ")", ";", "$", "this", "->", "appendChildren", "(", "$", "fragment", ",", "$", "component", ",", "$", "base", ")", ";", "$", "this", "->", "appendAttributes", "(", "$", "fragment", ",", "$", "component", ",", "$", "base", ")", ";", "if", "(", "$", "this", "->", "getRenderingEngine", "(", ")", "->", "getCssClassPolicy", "(", ")", "===", "AbstractMarkupRenderingEngine", "::", "CSSCLASS_ABSTRACT", ")", "{", "// The whole hierarchy of qti- CSS classes must be rendered.", "if", "(", "$", "this", "->", "hasAdditionalClasses", "(", ")", "===", "true", ")", "{", "$", "classes", "=", "implode", "(", "\"\\x20\"", ",", "$", "this", "->", "getAdditionalClasses", "(", ")", ")", ";", "$", "currentClasses", "=", "$", "fragment", "->", "firstChild", "->", "getAttribute", "(", "'class'", ")", ";", "$", "glue", "=", "(", "$", "currentClasses", "!==", "''", ")", "?", "\"\\x20\"", ":", "\"\"", ";", "$", "fragment", "->", "firstChild", "->", "setAttribute", "(", "'class'", ",", "$", "currentClasses", ".", "$", "glue", ".", "$", "classes", ")", ";", "}", "}", "else", "{", "// Only the last added qti- CSS class must be rendered.", "if", "(", "$", "this", "->", "hasAdditionalClasses", "(", ")", "===", "true", ")", "{", "$", "classes", "=", "$", "this", "->", "getAdditionalClasses", "(", ")", ";", "$", "class", "=", "array_pop", "(", "$", "classes", ")", ";", "$", "fragment", "->", "firstChild", "->", "setAttribute", "(", "'class'", ",", "$", "class", ")", ";", "}", "}", "// Add user specific CSS classes e.g. 'my-class' to rendering. ", "if", "(", "$", "this", "->", "hasAdditionalUserClasses", "(", ")", "===", "true", ")", "{", "$", "classes", "=", "implode", "(", "\"\\x20\"", ",", "$", "this", "->", "getAdditionalUserClasses", "(", ")", ")", ";", "$", "currentClasses", "=", "$", "fragment", "->", "firstChild", "->", "getAttribute", "(", "'class'", ")", ";", "$", "glue", "=", "(", "$", "currentClasses", "!==", "''", ")", "?", "\"\\x20\"", ":", "\"\"", ";", "$", "fragment", "->", "firstChild", "->", "setAttribute", "(", "'class'", ",", "$", "currentClasses", ".", "$", "glue", ".", "$", "classes", ")", ";", "}", "// Reset additional user classes for next rendering with this implementation.", "$", "this", "->", "setAdditionalUserClasses", "(", "array", "(", ")", ")", ";", "}" ]
A default rendering implementation focusing on a given $fragment and $component. @param \DOMDocumentFragment $fragment @param \qtism\data\QtiComponent $component @param string $base An optional base path to be used for rendering.
[ "A", "default", "rendering", "implementation", "focusing", "on", "a", "given", "$fragment", "and", "$component", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/markup/xhtml/AbstractXhtmlRenderer.php#L111-L144
oat-sa/qti-sdk
src/qtism/runtime/rendering/markup/xhtml/AbstractXhtmlRenderer.php
AbstractXhtmlRenderer.appendElement
protected function appendElement(DOMDocumentFragment $fragment, QtiComponent $component, $base = '') { $tagName = ($this->hasReplacementTagName() === true) ? $this->getReplacementTagName() : $component->getQtiClassName(); $fragment->appendChild($this->getRenderingEngine()->getDocument()->createElement($tagName)); }
php
protected function appendElement(DOMDocumentFragment $fragment, QtiComponent $component, $base = '') { $tagName = ($this->hasReplacementTagName() === true) ? $this->getReplacementTagName() : $component->getQtiClassName(); $fragment->appendChild($this->getRenderingEngine()->getDocument()->createElement($tagName)); }
[ "protected", "function", "appendElement", "(", "DOMDocumentFragment", "$", "fragment", ",", "QtiComponent", "$", "component", ",", "$", "base", "=", "''", ")", "{", "$", "tagName", "=", "(", "$", "this", "->", "hasReplacementTagName", "(", ")", "===", "true", ")", "?", "$", "this", "->", "getReplacementTagName", "(", ")", ":", "$", "component", "->", "getQtiClassName", "(", ")", ";", "$", "fragment", "->", "appendChild", "(", "$", "this", "->", "getRenderingEngine", "(", ")", "->", "getDocument", "(", ")", "->", "createElement", "(", "$", "tagName", ")", ")", ";", "}" ]
Append a new DOMElement to the currently rendered $fragment which is suitable to $component. @param \DOMDocumentFragment $fragment @param \qtism\data\QtiComponent $component
[ "Append", "a", "new", "DOMElement", "to", "the", "currently", "rendered", "$fragment", "which", "is", "suitable", "to", "$component", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/markup/xhtml/AbstractXhtmlRenderer.php#L153-L157
oat-sa/qti-sdk
src/qtism/runtime/rendering/markup/xhtml/AbstractXhtmlRenderer.php
AbstractXhtmlRenderer.appendChildren
protected function appendChildren(DOMDocumentFragment $fragment, QtiComponent $component, $base = '') { foreach ($this->getRenderingEngine()->getChildrenRenderings($component) as $childrenRendering) { $fragment->firstChild->appendChild($childrenRendering); } }
php
protected function appendChildren(DOMDocumentFragment $fragment, QtiComponent $component, $base = '') { foreach ($this->getRenderingEngine()->getChildrenRenderings($component) as $childrenRendering) { $fragment->firstChild->appendChild($childrenRendering); } }
[ "protected", "function", "appendChildren", "(", "DOMDocumentFragment", "$", "fragment", ",", "QtiComponent", "$", "component", ",", "$", "base", "=", "''", ")", "{", "foreach", "(", "$", "this", "->", "getRenderingEngine", "(", ")", "->", "getChildrenRenderings", "(", "$", "component", ")", "as", "$", "childrenRendering", ")", "{", "$", "fragment", "->", "firstChild", "->", "appendChild", "(", "$", "childrenRendering", ")", ";", "}", "}" ]
Append the children renderings of $components to the currently rendered $fragment. @param \DOMDocumentFragment $fragment @param \qtism\data\QtiComponent $component
[ "Append", "the", "children", "renderings", "of", "$components", "to", "the", "currently", "rendered", "$fragment", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/markup/xhtml/AbstractXhtmlRenderer.php#L165-L170
oat-sa/qti-sdk
src/qtism/runtime/rendering/markup/xhtml/AbstractXhtmlRenderer.php
AbstractXhtmlRenderer.appendAttributes
protected function appendAttributes(DOMDocumentFragment $fragment, QtiComponent $component, $base = '') { $this->handleXmlBase($component, $fragment->firstChild); }
php
protected function appendAttributes(DOMDocumentFragment $fragment, QtiComponent $component, $base = '') { $this->handleXmlBase($component, $fragment->firstChild); }
[ "protected", "function", "appendAttributes", "(", "DOMDocumentFragment", "$", "fragment", ",", "QtiComponent", "$", "component", ",", "$", "base", "=", "''", ")", "{", "$", "this", "->", "handleXmlBase", "(", "$", "component", ",", "$", "fragment", "->", "firstChild", ")", ";", "}" ]
Append the necessary attributes of $component to the currently rendered $fragment. @param \DOMDocumentFragment $fragment @param \qtism\data\QtiComponent $component
[ "Append", "the", "necessary", "attributes", "of", "$component", "to", "the", "currently", "rendered", "$fragment", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/markup/xhtml/AbstractXhtmlRenderer.php#L178-L181
oat-sa/qti-sdk
src/qtism/runtime/rendering/markup/xhtml/AbstractXhtmlRenderer.php
AbstractXhtmlRenderer.additionalClass
public function additionalClass($additionalClass) { $additionalClasses = $this->getAdditionalClasses(); if (($key = array_search($additionalClass, $additionalClasses)) !== false) { unset($additionalClasses[$key]); } $additionalClasses[] = $additionalClass; $this->setAdditionalClasses($additionalClasses); }
php
public function additionalClass($additionalClass) { $additionalClasses = $this->getAdditionalClasses(); if (($key = array_search($additionalClass, $additionalClasses)) !== false) { unset($additionalClasses[$key]); } $additionalClasses[] = $additionalClass; $this->setAdditionalClasses($additionalClasses); }
[ "public", "function", "additionalClass", "(", "$", "additionalClass", ")", "{", "$", "additionalClasses", "=", "$", "this", "->", "getAdditionalClasses", "(", ")", ";", "if", "(", "(", "$", "key", "=", "array_search", "(", "$", "additionalClass", ",", "$", "additionalClasses", ")", ")", "!==", "false", ")", "{", "unset", "(", "$", "additionalClasses", "[", "$", "key", "]", ")", ";", "}", "$", "additionalClasses", "[", "]", "=", "$", "additionalClass", ";", "$", "this", "->", "setAdditionalClasses", "(", "$", "additionalClasses", ")", ";", "}" ]
Add an additional CSS class to be rendered. @param string $additionalClass A CSS class.
[ "Add", "an", "additional", "CSS", "class", "to", "be", "rendered", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/markup/xhtml/AbstractXhtmlRenderer.php#L262-L272
oat-sa/qti-sdk
src/qtism/runtime/rendering/markup/xhtml/AbstractXhtmlRenderer.php
AbstractXhtmlRenderer.additionalUserClass
public function additionalUserClass($additionalUserClass) { $additionalClasses = $this->getAdditionalUserClasses(); if (($key = array_search($additionalUserClass, $additionalClasses)) !== false) { unset($additionalClasses[$key]); } $additionalClasses[] = $additionalUserClass; $this->setAdditionalUserClasses($additionalClasses); }
php
public function additionalUserClass($additionalUserClass) { $additionalClasses = $this->getAdditionalUserClasses(); if (($key = array_search($additionalUserClass, $additionalClasses)) !== false) { unset($additionalClasses[$key]); } $additionalClasses[] = $additionalUserClass; $this->setAdditionalUserClasses($additionalClasses); }
[ "public", "function", "additionalUserClass", "(", "$", "additionalUserClass", ")", "{", "$", "additionalClasses", "=", "$", "this", "->", "getAdditionalUserClasses", "(", ")", ";", "if", "(", "(", "$", "key", "=", "array_search", "(", "$", "additionalUserClass", ",", "$", "additionalClasses", ")", ")", "!==", "false", ")", "{", "unset", "(", "$", "additionalClasses", "[", "$", "key", "]", ")", ";", "}", "$", "additionalClasses", "[", "]", "=", "$", "additionalUserClass", ";", "$", "this", "->", "setAdditionalUserClasses", "(", "$", "additionalClasses", ")", ";", "}" ]
Add an additional user CSS class to be rendered. @param string $additionalUserClass
[ "Add", "an", "additional", "user", "CSS", "class", "to", "be", "rendered", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/markup/xhtml/AbstractXhtmlRenderer.php#L309-L319
oat-sa/qti-sdk
src/qtism/runtime/rendering/qtipl/rules/OutcomeConditionQtiPLRenderer.php
OutcomeConditionQtiPLRenderer.render
public function render($something) { $renderer = new QtiPLRenderer($this->getCRO()); $qtipl = $renderer->render($something->getOutcomeIf()); foreach ($something->getOutcomeElseIfs() as $elseif) { $qtipl .= " " . $renderer->render($elseif); } $qtipl .= ($something->getOutcomeElse() == null) ? "" : $renderer->render($something->getOutcomeElse()); return $qtipl; }
php
public function render($something) { $renderer = new QtiPLRenderer($this->getCRO()); $qtipl = $renderer->render($something->getOutcomeIf()); foreach ($something->getOutcomeElseIfs() as $elseif) { $qtipl .= " " . $renderer->render($elseif); } $qtipl .= ($something->getOutcomeElse() == null) ? "" : $renderer->render($something->getOutcomeElse()); return $qtipl; }
[ "public", "function", "render", "(", "$", "something", ")", "{", "$", "renderer", "=", "new", "QtiPLRenderer", "(", "$", "this", "->", "getCRO", "(", ")", ")", ";", "$", "qtipl", "=", "$", "renderer", "->", "render", "(", "$", "something", "->", "getOutcomeIf", "(", ")", ")", ";", "foreach", "(", "$", "something", "->", "getOutcomeElseIfs", "(", ")", "as", "$", "elseif", ")", "{", "$", "qtipl", ".=", "\" \"", ".", "$", "renderer", "->", "render", "(", "$", "elseif", ")", ";", "}", "$", "qtipl", ".=", "(", "$", "something", "->", "getOutcomeElse", "(", ")", "==", "null", ")", "?", "\"\"", ":", "$", "renderer", "->", "render", "(", "$", "something", "->", "getOutcomeElse", "(", ")", ")", ";", "return", "$", "qtipl", ";", "}" ]
Render a QtiComponent object into another constitution. @param mixed $something Something to render into another consitution. @return mixed The rendered component into another constitution. @throws \qtism\runtime\rendering\RenderingException If something goes wrong while rendering the component.
[ "Render", "a", "QtiComponent", "object", "into", "another", "constitution", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/qtipl/rules/OutcomeConditionQtiPLRenderer.php#L45-L56
oat-sa/qti-sdk
src/qtism/data/expressions/operators/Equal.php
Equal.setToleranceMode
public function setToleranceMode($toleranceMode) { if (in_array($toleranceMode, ToleranceMode::asArray(), true)) { $this->toleranceMode = $toleranceMode; } else { $msg = "The toleranceMode argument must be a value from the ToleranceMode enumeration, '" . $toleranceMode . "' given."; throw new InvalidArgumentException($msg); } }
php
public function setToleranceMode($toleranceMode) { if (in_array($toleranceMode, ToleranceMode::asArray(), true)) { $this->toleranceMode = $toleranceMode; } else { $msg = "The toleranceMode argument must be a value from the ToleranceMode enumeration, '" . $toleranceMode . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setToleranceMode", "(", "$", "toleranceMode", ")", "{", "if", "(", "in_array", "(", "$", "toleranceMode", ",", "ToleranceMode", "::", "asArray", "(", ")", ",", "true", ")", ")", "{", "$", "this", "->", "toleranceMode", "=", "$", "toleranceMode", ";", "}", "else", "{", "$", "msg", "=", "\"The toleranceMode argument must be a value from the ToleranceMode enumeration, '\"", ".", "$", "toleranceMode", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set the tolerance mode. @param integer $toleranceMode A value from the ToleranceMode enumeration. @throws \InvalidArgumentException If $toleranceMode is not a value from the ToleranceMode enumeration.
[ "Set", "the", "tolerance", "mode", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/expressions/operators/Equal.php#L129-L137
oat-sa/qti-sdk
src/qtism/data/expressions/operators/Equal.php
Equal.setTolerance
public function setTolerance(array $tolerance) { if (($this->getToleranceMode() == ToleranceMode::ABSOLUTE || $this->getToleranceMode() == ToleranceMode::RELATIVE) && count($tolerance) < 1) { $msg = "The tolerance array must contain at least t0."; throw new InvalidArgumentException($msg); } elseif (($this->getToleranceMode() == ToleranceMode::ABSOLUTE || $this->getToleranceMode() == ToleranceMode::RELATIVE) && count($tolerance) > 2) { $msg = "The tolerance array must contain at most t0 and t1"; throw new InvalidArgumentException($msg); } $this->tolerance = $tolerance; }
php
public function setTolerance(array $tolerance) { if (($this->getToleranceMode() == ToleranceMode::ABSOLUTE || $this->getToleranceMode() == ToleranceMode::RELATIVE) && count($tolerance) < 1) { $msg = "The tolerance array must contain at least t0."; throw new InvalidArgumentException($msg); } elseif (($this->getToleranceMode() == ToleranceMode::ABSOLUTE || $this->getToleranceMode() == ToleranceMode::RELATIVE) && count($tolerance) > 2) { $msg = "The tolerance array must contain at most t0 and t1"; throw new InvalidArgumentException($msg); } $this->tolerance = $tolerance; }
[ "public", "function", "setTolerance", "(", "array", "$", "tolerance", ")", "{", "if", "(", "(", "$", "this", "->", "getToleranceMode", "(", ")", "==", "ToleranceMode", "::", "ABSOLUTE", "||", "$", "this", "->", "getToleranceMode", "(", ")", "==", "ToleranceMode", "::", "RELATIVE", ")", "&&", "count", "(", "$", "tolerance", ")", "<", "1", ")", "{", "$", "msg", "=", "\"The tolerance array must contain at least t0.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "elseif", "(", "(", "$", "this", "->", "getToleranceMode", "(", ")", "==", "ToleranceMode", "::", "ABSOLUTE", "||", "$", "this", "->", "getToleranceMode", "(", ")", "==", "ToleranceMode", "::", "RELATIVE", ")", "&&", "count", "(", "$", "tolerance", ")", ">", "2", ")", "{", "$", "msg", "=", "\"The tolerance array must contain at most t0 and t1\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "$", "this", "->", "tolerance", "=", "$", "tolerance", ";", "}" ]
Set the tolerance array where index[0] is t0 and index[1] is t1. Please note that if there is no t1, t0 is used as t0 AND t1. @param array $tolerance An array of float|variableRef. @throws \InvalidArgumentException If the $tolerance count is less than 1 or greather than 2.
[ "Set", "the", "tolerance", "array", "where", "index", "[", "0", "]", "is", "t0", "and", "index", "[", "1", "]", "is", "t1", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/expressions/operators/Equal.php#L157-L168
oat-sa/qti-sdk
src/qtism/data/expressions/operators/Equal.php
Equal.setIncludeLowerBound
public function setIncludeLowerBound($includeLowerBound) { if (is_bool($includeLowerBound)) { $this->includeLowerBound = $includeLowerBound; } else { $msg = "The includeLowerBound argument must be a boolean, '" . gettype($includeLowerBound) . "' given."; throw new InvalidArgumentException($msg); } }
php
public function setIncludeLowerBound($includeLowerBound) { if (is_bool($includeLowerBound)) { $this->includeLowerBound = $includeLowerBound; } else { $msg = "The includeLowerBound argument must be a boolean, '" . gettype($includeLowerBound) . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setIncludeLowerBound", "(", "$", "includeLowerBound", ")", "{", "if", "(", "is_bool", "(", "$", "includeLowerBound", ")", ")", "{", "$", "this", "->", "includeLowerBound", "=", "$", "includeLowerBound", ";", "}", "else", "{", "$", "msg", "=", "\"The includeLowerBound argument must be a boolean, '\"", ".", "gettype", "(", "$", "includeLowerBound", ")", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set whether or not the lower bound must be included in the comparison. @param boolean $includeLowerBound @throws \InvalidArgumentException If $includedLowerBound is not a boolean value.
[ "Set", "whether", "or", "not", "the", "lower", "bound", "must", "be", "included", "in", "the", "comparison", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/expressions/operators/Equal.php#L188-L196
oat-sa/qti-sdk
src/qtism/data/expressions/operators/Equal.php
Equal.setIncludeUpperBound
public function setIncludeUpperBound($includeUpperBound) { if (is_bool($includeUpperBound)) { $this->includeUpperBound = $includeUpperBound; } else { $msg = "The includeUpperBound argument must be a boolean, '" . gettype($includeUpperBound) . "' given."; throw new InvalidArgumentException($msg); } }
php
public function setIncludeUpperBound($includeUpperBound) { if (is_bool($includeUpperBound)) { $this->includeUpperBound = $includeUpperBound; } else { $msg = "The includeUpperBound argument must be a boolean, '" . gettype($includeUpperBound) . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setIncludeUpperBound", "(", "$", "includeUpperBound", ")", "{", "if", "(", "is_bool", "(", "$", "includeUpperBound", ")", ")", "{", "$", "this", "->", "includeUpperBound", "=", "$", "includeUpperBound", ";", "}", "else", "{", "$", "msg", "=", "\"The includeUpperBound argument must be a boolean, '\"", ".", "gettype", "(", "$", "includeUpperBound", ")", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set whether or not the upper bound must be included in the comparison. @param boolean $includeUpperBound @throws \InvalidArgumentException If $includeUpperBound is not a boolean.
[ "Set", "whether", "or", "not", "the", "upper", "bound", "must", "be", "included", "in", "the", "comparison", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/expressions/operators/Equal.php#L214-L222
oat-sa/qti-sdk
src/qtism/runtime/expressions/operators/MultipleProcessor.php
MultipleProcessor.process
public function process() { $operands = $this->getOperands(); if (count($operands) === 0) { return null; } if ($operands->exclusivelySingleOrMultiple() === false) { $msg = "The Multiple operator only accepts operands with single or omultiple cardinality."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY); } $refType = null; $returnValue = null; foreach ($operands as $operand) { if (is_null($operand) || ($operand instanceof MultipleContainer && $operand->isNull())) { // As per specs, ignore. continue; } else { if ($refType !== null) { // A reference type as already been identified. if (CommonUtils::inferBaseType($operand) === $refType) { // $operand can be added to $returnValue. static::appendValue($returnValue, $operand); } else { // baseType mismatch. $msg = "The Multiple operator only accepts values with a similar baseType."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE); } } elseif (($discoveryType = CommonUtils::inferBaseType($operand)) !== false) { // First value being identified as non-null. $refType = $discoveryType; $returnValue = new MultipleContainer($refType); static::appendValue($returnValue, $operand); } } } return $returnValue; }
php
public function process() { $operands = $this->getOperands(); if (count($operands) === 0) { return null; } if ($operands->exclusivelySingleOrMultiple() === false) { $msg = "The Multiple operator only accepts operands with single or omultiple cardinality."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY); } $refType = null; $returnValue = null; foreach ($operands as $operand) { if (is_null($operand) || ($operand instanceof MultipleContainer && $operand->isNull())) { // As per specs, ignore. continue; } else { if ($refType !== null) { // A reference type as already been identified. if (CommonUtils::inferBaseType($operand) === $refType) { // $operand can be added to $returnValue. static::appendValue($returnValue, $operand); } else { // baseType mismatch. $msg = "The Multiple operator only accepts values with a similar baseType."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE); } } elseif (($discoveryType = CommonUtils::inferBaseType($operand)) !== false) { // First value being identified as non-null. $refType = $discoveryType; $returnValue = new MultipleContainer($refType); static::appendValue($returnValue, $operand); } } } return $returnValue; }
[ "public", "function", "process", "(", ")", "{", "$", "operands", "=", "$", "this", "->", "getOperands", "(", ")", ";", "if", "(", "count", "(", "$", "operands", ")", "===", "0", ")", "{", "return", "null", ";", "}", "if", "(", "$", "operands", "->", "exclusivelySingleOrMultiple", "(", ")", "===", "false", ")", "{", "$", "msg", "=", "\"The Multiple operator only accepts operands with single or omultiple cardinality.\"", ";", "throw", "new", "OperatorProcessingException", "(", "$", "msg", ",", "$", "this", ",", "OperatorProcessingException", "::", "WRONG_CARDINALITY", ")", ";", "}", "$", "refType", "=", "null", ";", "$", "returnValue", "=", "null", ";", "foreach", "(", "$", "operands", "as", "$", "operand", ")", "{", "if", "(", "is_null", "(", "$", "operand", ")", "||", "(", "$", "operand", "instanceof", "MultipleContainer", "&&", "$", "operand", "->", "isNull", "(", ")", ")", ")", "{", "// As per specs, ignore.", "continue", ";", "}", "else", "{", "if", "(", "$", "refType", "!==", "null", ")", "{", "// A reference type as already been identified.", "if", "(", "CommonUtils", "::", "inferBaseType", "(", "$", "operand", ")", "===", "$", "refType", ")", "{", "// $operand can be added to $returnValue.", "static", "::", "appendValue", "(", "$", "returnValue", ",", "$", "operand", ")", ";", "}", "else", "{", "// baseType mismatch.", "$", "msg", "=", "\"The Multiple operator only accepts values with a similar baseType.\"", ";", "throw", "new", "OperatorProcessingException", "(", "$", "msg", ",", "$", "this", ",", "OperatorProcessingException", "::", "WRONG_BASETYPE", ")", ";", "}", "}", "elseif", "(", "(", "$", "discoveryType", "=", "CommonUtils", "::", "inferBaseType", "(", "$", "operand", ")", ")", "!==", "false", ")", "{", "// First value being identified as non-null.", "$", "refType", "=", "$", "discoveryType", ";", "$", "returnValue", "=", "new", "MultipleContainer", "(", "$", "refType", ")", ";", "static", "::", "appendValue", "(", "$", "returnValue", ",", "$", "operand", ")", ";", "}", "}", "}", "return", "$", "returnValue", ";", "}" ]
Process the current expression. @return \qtism\runtime\common\MultipleContainer|null A MultipleContainer object or NULL. @throws \qtism\runtime\expressions\operators\OperatorProcessingException
[ "Process", "the", "current", "expression", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/MultipleProcessor.php#L54-L96
oat-sa/qti-sdk
src/qtism/runtime/expressions/operators/MultipleProcessor.php
MultipleProcessor.appendValue
protected static function appendValue(MultipleContainer $container, $value) { if ($value instanceof MultipleContainer) { foreach ($value as $v) { $container[] = $v; } } else { // primitive type. $container[] = $value; } }
php
protected static function appendValue(MultipleContainer $container, $value) { if ($value instanceof MultipleContainer) { foreach ($value as $v) { $container[] = $v; } } else { // primitive type. $container[] = $value; } }
[ "protected", "static", "function", "appendValue", "(", "MultipleContainer", "$", "container", ",", "$", "value", ")", "{", "if", "(", "$", "value", "instanceof", "MultipleContainer", ")", "{", "foreach", "(", "$", "value", "as", "$", "v", ")", "{", "$", "container", "[", "]", "=", "$", "v", ";", "}", "}", "else", "{", "// primitive type.", "$", "container", "[", "]", "=", "$", "value", ";", "}", "}" ]
Append a value (A MultipleContainer or a primitive datatype) to a given $container. @param \qtism\runtime\common\MultipleContainer $container A MultipleContainer object you want to append something to. @param scalar|\qtism\runtime\common\MultipleContainer $value A value to append to the $container.
[ "Append", "a", "value", "(", "A", "MultipleContainer", "or", "a", "primitive", "datatype", ")", "to", "a", "given", "$container", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/MultipleProcessor.php#L104-L114
oat-sa/qti-sdk
src/qtism/data/content/PrintedVariable.php
PrintedVariable.setFormat
public function setFormat($format) { if (Format::isString256($format) === true) { $this->format = $format; } else { $msg = "The 'format' argument must be a string with at most 256 characters, '" . $format . "' given."; throw new InvalidArgumentException($msg); } }
php
public function setFormat($format) { if (Format::isString256($format) === true) { $this->format = $format; } else { $msg = "The 'format' argument must be a string with at most 256 characters, '" . $format . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setFormat", "(", "$", "format", ")", "{", "if", "(", "Format", "::", "isString256", "(", "$", "format", ")", "===", "true", ")", "{", "$", "this", "->", "format", "=", "$", "format", ";", "}", "else", "{", "$", "msg", "=", "\"The 'format' argument must be a string with at most 256 characters, '\"", ".", "$", "format", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set the format conversion to use when converting numerical values to strings. @param string $format See Number Formatting Rules for details. @throws \InvalidArgumentException If $format is not a string with at most 256 characters. @see http://www.imsglobal.org/question/qtiv2p1/imsqti_infov2p1.html#section10074
[ "Set", "the", "format", "conversion", "to", "use", "when", "converting", "numerical", "values", "to", "strings", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/PrintedVariable.php#L223-L231
oat-sa/qti-sdk
src/qtism/data/content/PrintedVariable.php
PrintedVariable.setPowerForm
public function setPowerForm($powerForm) { if (is_bool($powerForm) === true) { $this->powerForm = $powerForm; } else { $msg = "The 'powerForm' argument must be a boolean value, '" . gettype($powerForm) . "' given."; throw new InvalidArgumentException($msg); } }
php
public function setPowerForm($powerForm) { if (is_bool($powerForm) === true) { $this->powerForm = $powerForm; } else { $msg = "The 'powerForm' argument must be a boolean value, '" . gettype($powerForm) . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setPowerForm", "(", "$", "powerForm", ")", "{", "if", "(", "is_bool", "(", "$", "powerForm", ")", "===", "true", ")", "{", "$", "this", "->", "powerForm", "=", "$", "powerForm", ";", "}", "else", "{", "$", "msg", "=", "\"The 'powerForm' argument must be a boolean value, '\"", ".", "gettype", "(", "$", "powerForm", ")", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set whether the variable value (when it's a float) must use the 'e' format for display. @param boolean $powerForm @throws \InvalidArgumentException If $powerForm is not a boolean value.
[ "Set", "whether", "the", "variable", "value", "(", "when", "it", "s", "a", "float", ")", "must", "use", "the", "e", "format", "for", "display", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/PrintedVariable.php#L262-L270
oat-sa/qti-sdk
src/qtism/data/content/PrintedVariable.php
PrintedVariable.setBase
public function setBase($base) { if (is_int($base) === true || Format::isVariableRef($base) === true) { $this->base = $base; } else { $msg = "The 'base' argument must be an integer or a variable reference, '" . $base . "' given."; throw new InvalidArgumentException($msg); } }
php
public function setBase($base) { if (is_int($base) === true || Format::isVariableRef($base) === true) { $this->base = $base; } else { $msg = "The 'base' argument must be an integer or a variable reference, '" . $base . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setBase", "(", "$", "base", ")", "{", "if", "(", "is_int", "(", "$", "base", ")", "===", "true", "||", "Format", "::", "isVariableRef", "(", "$", "base", ")", "===", "true", ")", "{", "$", "this", "->", "base", "=", "$", "base", ";", "}", "else", "{", "$", "msg", "=", "\"The 'base' argument must be an integer or a variable reference, '\"", ".", "$", "base", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set the number base to use when converting integer variables to strings. @param integer|string $base A base to use for conversion as an integer or a variable reference. @throws \InvalidArgumentException If $base is not an integer nor a variable reference.
[ "Set", "the", "number", "base", "to", "use", "when", "converting", "integer", "variables", "to", "strings", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/PrintedVariable.php#L289-L297
oat-sa/qti-sdk
src/qtism/data/content/PrintedVariable.php
PrintedVariable.setIndex
public function setIndex($index) { if (is_int($index) === true || Format::isVariableRef($index) === true) { $this->index = $index; } else { $msg = "The 'index' argument must be an integer or a variable reference, '" . $index . "' given."; throw new InvalidArgumentException($msg); } }
php
public function setIndex($index) { if (is_int($index) === true || Format::isVariableRef($index) === true) { $this->index = $index; } else { $msg = "The 'index' argument must be an integer or a variable reference, '" . $index . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setIndex", "(", "$", "index", ")", "{", "if", "(", "is_int", "(", "$", "index", ")", "===", "true", "||", "Format", "::", "isVariableRef", "(", "$", "index", ")", "===", "true", ")", "{", "$", "this", "->", "index", "=", "$", "index", ";", "}", "else", "{", "$", "msg", "=", "\"The 'index' argument must be an integer or a variable reference, '\"", ".", "$", "index", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set the index to use when displaying a variable of ordered cardinality. Give a negative integer if there is no index indicated. @param integer|string $index An integer or variable reference. @throws \InvalidArgumentException If $index is not an integer nor a variable reference.
[ "Set", "the", "index", "to", "use", "when", "displaying", "a", "variable", "of", "ordered", "cardinality", ".", "Give", "a", "negative", "integer", "if", "there", "is", "no", "index", "indicated", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/PrintedVariable.php#L316-L324
oat-sa/qti-sdk
src/qtism/data/content/PrintedVariable.php
PrintedVariable.setDelimiter
public function setDelimiter($delimiter) { if (empty($delimiter) === false && Format::isString256($delimiter) === true) { $this->delimiter = $delimiter; } else { $msg = "The 'delimiter' argument must be a non-empty string, '" . gettype($delimiter) . "' given."; throw new InvalidArgumentException($msg); } }
php
public function setDelimiter($delimiter) { if (empty($delimiter) === false && Format::isString256($delimiter) === true) { $this->delimiter = $delimiter; } else { $msg = "The 'delimiter' argument must be a non-empty string, '" . gettype($delimiter) . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setDelimiter", "(", "$", "delimiter", ")", "{", "if", "(", "empty", "(", "$", "delimiter", ")", "===", "false", "&&", "Format", "::", "isString256", "(", "$", "delimiter", ")", "===", "true", ")", "{", "$", "this", "->", "delimiter", "=", "$", "delimiter", ";", "}", "else", "{", "$", "msg", "=", "\"The 'delimiter' argument must be a non-empty string, '\"", ".", "gettype", "(", "$", "delimiter", ")", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set the delimiter to use between values when displaying variables of ordered, multiple or record cardinality. @param string $delimiter A non-empty string with at most 256 characters. @throws \InvalidArgumentException If $delimiter is not a non-empty string with at most 256 characters.
[ "Set", "the", "delimiter", "to", "use", "between", "values", "when", "displaying", "variables", "of", "ordered", "multiple", "or", "record", "cardinality", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/PrintedVariable.php#L354-L362
oat-sa/qti-sdk
src/qtism/data/content/PrintedVariable.php
PrintedVariable.setField
public function setField($field) { if (Format::isString256($field) === true) { $this->field = $field; } else { $msg = "The 'field' argument must be a non-empty string, '" . gettype($field) . "' given."; throw new InvalidArgumentException($msg); } }
php
public function setField($field) { if (Format::isString256($field) === true) { $this->field = $field; } else { $msg = "The 'field' argument must be a non-empty string, '" . gettype($field) . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setField", "(", "$", "field", ")", "{", "if", "(", "Format", "::", "isString256", "(", "$", "field", ")", "===", "true", ")", "{", "$", "this", "->", "field", "=", "$", "field", ";", "}", "else", "{", "$", "msg", "=", "\"The 'field' argument must be a non-empty string, '\"", ".", "gettype", "(", "$", "field", ")", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set the field specifier to use when displaying variables of record cardinality. Give an empty string if no field is indicated. @param string $field A string with at most 256 characters. @throws \InvalidArgumentException If $field is not a string with at most 256 characters.
[ "Set", "the", "field", "specifier", "to", "use", "when", "displaying", "variables", "of", "record", "cardinality", ".", "Give", "an", "empty", "string", "if", "no", "field", "is", "indicated", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/PrintedVariable.php#L382-L390
oat-sa/qti-sdk
src/qtism/data/content/PrintedVariable.php
PrintedVariable.setMappingIndicator
public function setMappingIndicator($mappingIndicator) { if (empty($mappingIndicator) === false && Format::isString256($mappingIndicator) === true) { $this->mappingIndicator = $mappingIndicator; } else { $msg = "The 'mappingIndicator' argument must be a non-empty string with at most 256 characters, '" . gettype($mappingIndicator) . "' given."; throw new InvalidArgumentException($msg); } }
php
public function setMappingIndicator($mappingIndicator) { if (empty($mappingIndicator) === false && Format::isString256($mappingIndicator) === true) { $this->mappingIndicator = $mappingIndicator; } else { $msg = "The 'mappingIndicator' argument must be a non-empty string with at most 256 characters, '" . gettype($mappingIndicator) . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setMappingIndicator", "(", "$", "mappingIndicator", ")", "{", "if", "(", "empty", "(", "$", "mappingIndicator", ")", "===", "false", "&&", "Format", "::", "isString256", "(", "$", "mappingIndicator", ")", "===", "true", ")", "{", "$", "this", "->", "mappingIndicator", "=", "$", "mappingIndicator", ";", "}", "else", "{", "$", "msg", "=", "\"The 'mappingIndicator' argument must be a non-empty string with at most 256 characters, '\"", ".", "gettype", "(", "$", "mappingIndicator", ")", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set the mapping indicator to use between field name and field value when displaying variables of record cardinality. @param string $mappingIndicator A non-empty string with at most 256 characters. @throws \InvalidArgumentException If $mappingIndicator is not a non-empty string with at most 256 characters.
[ "Set", "the", "mapping", "indicator", "to", "use", "between", "field", "name", "and", "field", "value", "when", "displaying", "variables", "of", "record", "cardinality", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/PrintedVariable.php#L422-L430
oat-sa/qti-sdk
src/qtism/data/state/MatchTable.php
MatchTable.setMatchTableEntries
public function setMatchTableEntries(MatchTableEntryCollection $matchTableEntries) { if (count($matchTableEntries) > 0) { $this->matchTableEntries = $matchTableEntries; } else { $msg = "A MatchTable object must contain at least one MatchTableEntry object."; throw new InvalidArgumentException($msg); } }
php
public function setMatchTableEntries(MatchTableEntryCollection $matchTableEntries) { if (count($matchTableEntries) > 0) { $this->matchTableEntries = $matchTableEntries; } else { $msg = "A MatchTable object must contain at least one MatchTableEntry object."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setMatchTableEntries", "(", "MatchTableEntryCollection", "$", "matchTableEntries", ")", "{", "if", "(", "count", "(", "$", "matchTableEntries", ")", ">", "0", ")", "{", "$", "this", "->", "matchTableEntries", "=", "$", "matchTableEntries", ";", "}", "else", "{", "$", "msg", "=", "\"A MatchTable object must contain at least one MatchTableEntry object.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set the collection of MatchTableEntry objects. @param \qtism\data\state\MatchTableEntryCollection $matchTableEntries A collection of MatchTableEntry objects. @throws \InvalidArgumentException If $matchTableEntries is an empty collection.
[ "Set", "the", "collection", "of", "MatchTableEntry", "objects", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/state/MatchTable.php#L76-L84
oat-sa/qti-sdk
src/qtism/common/utils/Format.php
Format.isIdentifier
public static function isIdentifier($string, $strict = true) { if ($strict === true) { $letter = self::getPerlXmlLetter(); $digit = self::getPerlXmlDigit(); $combiningChar = self::getPerlXmlCombiningChar(); $extender = self::getPerlXmlExtender(); $string = str_split($string); $first = array_shift($string); if (preg_match("/(?:_|${letter})/u", $first) === 1) { foreach ($string as $s) { if (preg_match("/${letter}|${digit}/u", $s) === 0 && preg_match("/${combiningChar}|${extender}/u", $s) === 0 && preg_match("/_|\\-|\\./u", $s) === 0) { return false; } } return true; } else { return false; } } else { return preg_match("/^[a-zA-Z_][a-zA-Z0-9_\.-]*$/u", $string) === 1; } }
php
public static function isIdentifier($string, $strict = true) { if ($strict === true) { $letter = self::getPerlXmlLetter(); $digit = self::getPerlXmlDigit(); $combiningChar = self::getPerlXmlCombiningChar(); $extender = self::getPerlXmlExtender(); $string = str_split($string); $first = array_shift($string); if (preg_match("/(?:_|${letter})/u", $first) === 1) { foreach ($string as $s) { if (preg_match("/${letter}|${digit}/u", $s) === 0 && preg_match("/${combiningChar}|${extender}/u", $s) === 0 && preg_match("/_|\\-|\\./u", $s) === 0) { return false; } } return true; } else { return false; } } else { return preg_match("/^[a-zA-Z_][a-zA-Z0-9_\.-]*$/u", $string) === 1; } }
[ "public", "static", "function", "isIdentifier", "(", "$", "string", ",", "$", "strict", "=", "true", ")", "{", "if", "(", "$", "strict", "===", "true", ")", "{", "$", "letter", "=", "self", "::", "getPerlXmlLetter", "(", ")", ";", "$", "digit", "=", "self", "::", "getPerlXmlDigit", "(", ")", ";", "$", "combiningChar", "=", "self", "::", "getPerlXmlCombiningChar", "(", ")", ";", "$", "extender", "=", "self", "::", "getPerlXmlExtender", "(", ")", ";", "$", "string", "=", "str_split", "(", "$", "string", ")", ";", "$", "first", "=", "array_shift", "(", "$", "string", ")", ";", "if", "(", "preg_match", "(", "\"/(?:_|${letter})/u\"", ",", "$", "first", ")", "===", "1", ")", "{", "foreach", "(", "$", "string", "as", "$", "s", ")", "{", "if", "(", "preg_match", "(", "\"/${letter}|${digit}/u\"", ",", "$", "s", ")", "===", "0", "&&", "preg_match", "(", "\"/${combiningChar}|${extender}/u\"", ",", "$", "s", ")", "===", "0", "&&", "preg_match", "(", "\"/_|\\\\-|\\\\./u\"", ",", "$", "s", ")", "===", "0", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}", "else", "{", "return", "preg_match", "(", "\"/^[a-zA-Z_][a-zA-Z0-9_\\.-]*$/u\"", ",", "$", "string", ")", "===", "1", ";", "}", "}" ]
Check if string is compliant with the identifier datatype of IMS QTI. IMS Global says : Identifiers can contain the character classes Letter, Digit, Combining which are described in the Extensible Markup Language (XML) 1.0 (Second Edition). Identifiers should have no more than 32 characters for compatibility with version 1. They are always compared case-sensitively. @link http://www.w3.org/TR/2000/REC-xml-20001006 @return boolean Wether $string is a valid identifier.
[ "Check", "if", "string", "is", "compliant", "with", "the", "identifier", "datatype", "of", "IMS", "QTI", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/utils/Format.php#L58-L83
oat-sa/qti-sdk
src/qtism/common/utils/Format.php
Format.sanitizeIdentifier
public static function sanitizeIdentifier($dirtyIdentifier) { if (is_array($dirtyIdentifier) || is_object($dirtyIdentifier)) { return Format::generateIdentifier(); } if (preg_match("/^[a-zA-Z_][a-zA-Z0-9_\.-]*$/u", $dirtyIdentifier)) { return $dirtyIdentifier; } $cleanIdentifier = preg_replace("/^[^a-zA-Z_]+/u", "", $dirtyIdentifier); // Cleaning start $cleanIdentifier = preg_replace("/[^a-zA-Z0-9_\.-]+/u", "", $cleanIdentifier); // Cleaning content if (preg_match("/^[a-zA-Z_][a-zA-Z0-9_\.-]*$/u", $cleanIdentifier)) { return $cleanIdentifier; } else { return Format::generateIdentifier(); } }
php
public static function sanitizeIdentifier($dirtyIdentifier) { if (is_array($dirtyIdentifier) || is_object($dirtyIdentifier)) { return Format::generateIdentifier(); } if (preg_match("/^[a-zA-Z_][a-zA-Z0-9_\.-]*$/u", $dirtyIdentifier)) { return $dirtyIdentifier; } $cleanIdentifier = preg_replace("/^[^a-zA-Z_]+/u", "", $dirtyIdentifier); // Cleaning start $cleanIdentifier = preg_replace("/[^a-zA-Z0-9_\.-]+/u", "", $cleanIdentifier); // Cleaning content if (preg_match("/^[a-zA-Z_][a-zA-Z0-9_\.-]*$/u", $cleanIdentifier)) { return $cleanIdentifier; } else { return Format::generateIdentifier(); } }
[ "public", "static", "function", "sanitizeIdentifier", "(", "$", "dirtyIdentifier", ")", "{", "if", "(", "is_array", "(", "$", "dirtyIdentifier", ")", "||", "is_object", "(", "$", "dirtyIdentifier", ")", ")", "{", "return", "Format", "::", "generateIdentifier", "(", ")", ";", "}", "if", "(", "preg_match", "(", "\"/^[a-zA-Z_][a-zA-Z0-9_\\.-]*$/u\"", ",", "$", "dirtyIdentifier", ")", ")", "{", "return", "$", "dirtyIdentifier", ";", "}", "$", "cleanIdentifier", "=", "preg_replace", "(", "\"/^[^a-zA-Z_]+/u\"", ",", "\"\"", ",", "$", "dirtyIdentifier", ")", ";", "// Cleaning start", "$", "cleanIdentifier", "=", "preg_replace", "(", "\"/[^a-zA-Z0-9_\\.-]+/u\"", ",", "\"\"", ",", "$", "cleanIdentifier", ")", ";", "// Cleaning content", "if", "(", "preg_match", "(", "\"/^[a-zA-Z_][a-zA-Z0-9_\\.-]*$/u\"", ",", "$", "cleanIdentifier", ")", ")", "{", "return", "$", "cleanIdentifier", ";", "}", "else", "{", "return", "Format", "::", "generateIdentifier", "(", ")", ";", "}", "}" ]
"Sanitizes" an identifier : removes any non-valid character that does not correspond to the criteria written below, and returns a valid qti identifier. If after sanitizing, the identifier is stil not valid, a random identifier is generated. IMS Global says : Identifiers can contain the character classes Letter, Digit, Combining which are described in the Extensible Markup Language (XML) 1.0 (Second Edition). Identifiers should have no more than 32 characters for compatibility with version 1. They are always compared case-sensitively. @param $dirtyIdentifier string The string of the identifier to sanitize. @link http://www.w3.org/TR/2000/REC-xml-20001006 @return string A valid qti-identifier representation of the $identifier set as paramter
[ "Sanitizes", "an", "identifier", ":", "removes", "any", "non", "-", "valid", "character", "that", "does", "not", "correspond", "to", "the", "criteria", "written", "below", "and", "returns", "a", "valid", "qti", "identifier", ".", "If", "after", "sanitizing", "the", "identifier", "is", "stil", "not", "valid", "a", "random", "identifier", "is", "generated", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/utils/Format.php#L100-L118
oat-sa/qti-sdk
src/qtism/common/utils/Format.php
Format.isPair
public static function isPair($string) { $pair = explode("\x20", $string); if (count($pair) == 2) { if (self::isIdentifier(self::toLowerTrim($pair[0])) && self::isIdentifier(self::toLowerTrim($pair[1]))) { return true; } } return false; }
php
public static function isPair($string) { $pair = explode("\x20", $string); if (count($pair) == 2) { if (self::isIdentifier(self::toLowerTrim($pair[0])) && self::isIdentifier(self::toLowerTrim($pair[1]))) { return true; } } return false; }
[ "public", "static", "function", "isPair", "(", "$", "string", ")", "{", "$", "pair", "=", "explode", "(", "\"\\x20\"", ",", "$", "string", ")", ";", "if", "(", "count", "(", "$", "pair", ")", "==", "2", ")", "{", "if", "(", "self", "::", "isIdentifier", "(", "self", "::", "toLowerTrim", "(", "$", "pair", "[", "0", "]", ")", ")", "&&", "self", "::", "isIdentifier", "(", "self", "::", "toLowerTrim", "(", "$", "pair", "[", "1", "]", ")", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Wether a given $string can be cast into a pair. @param string $string A string value. @return boolean Wether $string can be converted to a pair.
[ "Wether", "a", "given", "$string", "can", "be", "cast", "into", "a", "pair", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/utils/Format.php#L274-L285
oat-sa/qti-sdk
src/qtism/common/utils/Format.php
Format.isBoolean
public static function isBoolean($string) { if (gettype($string) === 'string') { $string = self::toLowerTrim($string); if ($string == 'true') { return true; } elseif ($string == 'false') { return true; } else { return false; } } else { return false; } }
php
public static function isBoolean($string) { if (gettype($string) === 'string') { $string = self::toLowerTrim($string); if ($string == 'true') { return true; } elseif ($string == 'false') { return true; } else { return false; } } else { return false; } }
[ "public", "static", "function", "isBoolean", "(", "$", "string", ")", "{", "if", "(", "gettype", "(", "$", "string", ")", "===", "'string'", ")", "{", "$", "string", "=", "self", "::", "toLowerTrim", "(", "$", "string", ")", ";", "if", "(", "$", "string", "==", "'true'", ")", "{", "return", "true", ";", "}", "elseif", "(", "$", "string", "==", "'false'", ")", "{", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}", "else", "{", "return", "false", ";", "}", "}" ]
Whether a given $string can be transformed into a boolean. @param string $string A string value. @return boolean Whether $string can be converted to a boolean.
[ "Whether", "a", "given", "$string", "can", "be", "transformed", "into", "a", "boolean", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/utils/Format.php#L321-L335
oat-sa/qti-sdk
src/qtism/common/utils/Format.php
Format.isPoint
public static function isPoint($string) { if (gettype($string) === 'string') { $parts = explode("\x20", $string); if (count($parts) == 2) { if (self::isInteger($parts[0]) && self::isInteger($parts[1])) { return true; } } } return false; }
php
public static function isPoint($string) { if (gettype($string) === 'string') { $parts = explode("\x20", $string); if (count($parts) == 2) { if (self::isInteger($parts[0]) && self::isInteger($parts[1])) { return true; } } } return false; }
[ "public", "static", "function", "isPoint", "(", "$", "string", ")", "{", "if", "(", "gettype", "(", "$", "string", ")", "===", "'string'", ")", "{", "$", "parts", "=", "explode", "(", "\"\\x20\"", ",", "$", "string", ")", ";", "if", "(", "count", "(", "$", "parts", ")", "==", "2", ")", "{", "if", "(", "self", "::", "isInteger", "(", "$", "parts", "[", "0", "]", ")", "&&", "self", "::", "isInteger", "(", "$", "parts", "[", "1", "]", ")", ")", "{", "return", "true", ";", "}", "}", "}", "return", "false", ";", "}" ]
Whether a given $string can be cast into a Point datatype. @param string $string A string value. @return boolean Wheter $string can be transformed to a Point datatype.
[ "Whether", "a", "given", "$string", "can", "be", "cast", "into", "a", "Point", "datatype", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/utils/Format.php#L343-L355
oat-sa/qti-sdk
src/qtism/common/utils/Format.php
Format.isVariableRef
public static function isVariableRef($string) { $firstBrace = substr($string, 0, 1); $secondBrace = substr($string, -1); if ($firstBrace == '{' && $secondBrace == '}') { return self::isIdentifier(substr($string, 1, -1)); } else { return self::isIdentifier($string); } }
php
public static function isVariableRef($string) { $firstBrace = substr($string, 0, 1); $secondBrace = substr($string, -1); if ($firstBrace == '{' && $secondBrace == '}') { return self::isIdentifier(substr($string, 1, -1)); } else { return self::isIdentifier($string); } }
[ "public", "static", "function", "isVariableRef", "(", "$", "string", ")", "{", "$", "firstBrace", "=", "substr", "(", "$", "string", ",", "0", ",", "1", ")", ";", "$", "secondBrace", "=", "substr", "(", "$", "string", ",", "-", "1", ")", ";", "if", "(", "$", "firstBrace", "==", "'{'", "&&", "$", "secondBrace", "==", "'}'", ")", "{", "return", "self", "::", "isIdentifier", "(", "substr", "(", "$", "string", ",", "1", ",", "-", "1", ")", ")", ";", "}", "else", "{", "return", "self", "::", "isIdentifier", "(", "$", "string", ")", ";", "}", "}" ]
Whether or not a given string is a variable ref. @param string $string A given string. @return boolean Wheter $string is a valid variable ref. @example '{myIdentifier1}' is a valid variable ref but 'myIdentifier1' is not.
[ "Whether", "or", "not", "a", "given", "string", "is", "a", "variable", "ref", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/utils/Format.php#L376-L386
oat-sa/qti-sdk
src/qtism/common/utils/Format.php
Format.isClass
public static function isClass($string) { if (is_string($string) === true) { $pattern = "/^(?:[^\s]+?(?:\x20){0,})+$/"; return preg_match($pattern, $string) === 1; } else { return false; } }
php
public static function isClass($string) { if (is_string($string) === true) { $pattern = "/^(?:[^\s]+?(?:\x20){0,})+$/"; return preg_match($pattern, $string) === 1; } else { return false; } }
[ "public", "static", "function", "isClass", "(", "$", "string", ")", "{", "if", "(", "is_string", "(", "$", "string", ")", "===", "true", ")", "{", "$", "pattern", "=", "\"/^(?:[^\\s]+?(?:\\x20){0,})+$/\"", ";", "return", "preg_match", "(", "$", "pattern", ",", "$", "string", ")", "===", "1", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Whether a given $string is a valid value for a body element's class attribute e.g. 'qti-label' or 'qti-label qti-component'. @param string $string A string value. @return boolean
[ "Whether", "a", "given", "$string", "is", "a", "valid", "value", "for", "a", "body", "element", "s", "class", "attribute", "e", ".", "g", ".", "qti", "-", "label", "or", "qti", "-", "label", "qti", "-", "component", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/utils/Format.php#L424-L434
oat-sa/qti-sdk
src/qtism/common/utils/Format.php
Format.scale10
public static function scale10($float, $x = 'x', $precision = false) { // 1. Transform in 'E' notation. $mask = ($precision === false) ? '%e' : "%.${precision}e"; $strFloat = sprintf($mask, $float); // 2. Transform the 'E' notation into 'x 10^n' notation. $parts = explode('e', $strFloat); $mantissa = $parts[1]; $newMantissa = ''; for ($i = 0; $i < strlen($mantissa); $i++) { switch ($mantissa[$i]) { case '0': $newMantissa .= json_decode('"\u2070"'); break; case '1': $newMantissa .= json_decode('"\u00b9"'); break; case '2': $newMantissa .= json_decode('"\u00b2"'); break; case '3': $newMantissa .= json_decode('"\u00b3"'); break; case '4': $newMantissa .= json_decode('"\u2074"'); break; case '5': $newMantissa .= json_decode('"\u2075"'); break; case '6': $newMantissa .= json_decode('"\u2076"'); break; case '7': $newMantissa .= json_decode('"\u2077"'); break; case '8': $newMantissa .= json_decode('"\u2078"'); break; case '9': $newMantissa .= json_decode('"\u2079"'); break; case '-': $newMantissa .= json_decode('"\u207b"'); break; } } return $parts[0] . " ${x} 10" . $newMantissa; }
php
public static function scale10($float, $x = 'x', $precision = false) { // 1. Transform in 'E' notation. $mask = ($precision === false) ? '%e' : "%.${precision}e"; $strFloat = sprintf($mask, $float); // 2. Transform the 'E' notation into 'x 10^n' notation. $parts = explode('e', $strFloat); $mantissa = $parts[1]; $newMantissa = ''; for ($i = 0; $i < strlen($mantissa); $i++) { switch ($mantissa[$i]) { case '0': $newMantissa .= json_decode('"\u2070"'); break; case '1': $newMantissa .= json_decode('"\u00b9"'); break; case '2': $newMantissa .= json_decode('"\u00b2"'); break; case '3': $newMantissa .= json_decode('"\u00b3"'); break; case '4': $newMantissa .= json_decode('"\u2074"'); break; case '5': $newMantissa .= json_decode('"\u2075"'); break; case '6': $newMantissa .= json_decode('"\u2076"'); break; case '7': $newMantissa .= json_decode('"\u2077"'); break; case '8': $newMantissa .= json_decode('"\u2078"'); break; case '9': $newMantissa .= json_decode('"\u2079"'); break; case '-': $newMantissa .= json_decode('"\u207b"'); break; } } return $parts[0] . " ${x} 10" . $newMantissa; }
[ "public", "static", "function", "scale10", "(", "$", "float", ",", "$", "x", "=", "'x'", ",", "$", "precision", "=", "false", ")", "{", "// 1. Transform in 'E' notation.", "$", "mask", "=", "(", "$", "precision", "===", "false", ")", "?", "'%e'", ":", "\"%.${precision}e\"", ";", "$", "strFloat", "=", "sprintf", "(", "$", "mask", ",", "$", "float", ")", ";", "// 2. Transform the 'E' notation into 'x 10^n' notation.", "$", "parts", "=", "explode", "(", "'e'", ",", "$", "strFloat", ")", ";", "$", "mantissa", "=", "$", "parts", "[", "1", "]", ";", "$", "newMantissa", "=", "''", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "strlen", "(", "$", "mantissa", ")", ";", "$", "i", "++", ")", "{", "switch", "(", "$", "mantissa", "[", "$", "i", "]", ")", "{", "case", "'0'", ":", "$", "newMantissa", ".=", "json_decode", "(", "'\"\\u2070\"'", ")", ";", "break", ";", "case", "'1'", ":", "$", "newMantissa", ".=", "json_decode", "(", "'\"\\u00b9\"'", ")", ";", "break", ";", "case", "'2'", ":", "$", "newMantissa", ".=", "json_decode", "(", "'\"\\u00b2\"'", ")", ";", "break", ";", "case", "'3'", ":", "$", "newMantissa", ".=", "json_decode", "(", "'\"\\u00b3\"'", ")", ";", "break", ";", "case", "'4'", ":", "$", "newMantissa", ".=", "json_decode", "(", "'\"\\u2074\"'", ")", ";", "break", ";", "case", "'5'", ":", "$", "newMantissa", ".=", "json_decode", "(", "'\"\\u2075\"'", ")", ";", "break", ";", "case", "'6'", ":", "$", "newMantissa", ".=", "json_decode", "(", "'\"\\u2076\"'", ")", ";", "break", ";", "case", "'7'", ":", "$", "newMantissa", ".=", "json_decode", "(", "'\"\\u2077\"'", ")", ";", "break", ";", "case", "'8'", ":", "$", "newMantissa", ".=", "json_decode", "(", "'\"\\u2078\"'", ")", ";", "break", ";", "case", "'9'", ":", "$", "newMantissa", ".=", "json_decode", "(", "'\"\\u2079\"'", ")", ";", "break", ";", "case", "'-'", ":", "$", "newMantissa", ".=", "json_decode", "(", "'\"\\u207b\"'", ")", ";", "break", ";", "}", "}", "return", "$", "parts", "[", "0", "]", ".", "\" ${x} 10\"", ".", "$", "newMantissa", ";", "}" ]
Get a float variable into a Standard Form / Scientific notation e.g. 6.72 x 10⁴. * If no $precision is given, 6 significant numbers will be displayed after the decimal separator. * If no $x is given, the 'x' character will be used as the 'times' operator. @param float $float @param string $x The character to be used as the 'times' operator. @param false|integer $precision The number of requested significant numbers after the decimal separator. @return string
[ "Get", "a", "float", "variable", "into", "a", "Standard", "Form", "/", "Scientific", "notation", "e", ".", "g", ".", "6", ".", "72", "x", "10⁴", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/utils/Format.php#L447-L507
oat-sa/qti-sdk
src/qtism/common/utils/Format.php
Format.isPrintfIsoFormat
public static function isPrintfIsoFormat($isoFormat) { $subPattern = self::getPrintfFormatSpecifier(); $pattern = '/(?:(?:[^%]|^)(?:%%)+(' . $subPattern . '))|(?:(?:[^%])(' . $subPattern . '))|(?:^(' . $subPattern . '))/u'; $matches = array(); preg_match_all($pattern, $isoFormat, $matches); if (count($matches[1]) + count($matches[2]) + count($matches[3]) > 0) { // There is at least one format specifier in the string. return true; } else { return false; } }
php
public static function isPrintfIsoFormat($isoFormat) { $subPattern = self::getPrintfFormatSpecifier(); $pattern = '/(?:(?:[^%]|^)(?:%%)+(' . $subPattern . '))|(?:(?:[^%])(' . $subPattern . '))|(?:^(' . $subPattern . '))/u'; $matches = array(); preg_match_all($pattern, $isoFormat, $matches); if (count($matches[1]) + count($matches[2]) + count($matches[3]) > 0) { // There is at least one format specifier in the string. return true; } else { return false; } }
[ "public", "static", "function", "isPrintfIsoFormat", "(", "$", "isoFormat", ")", "{", "$", "subPattern", "=", "self", "::", "getPrintfFormatSpecifier", "(", ")", ";", "$", "pattern", "=", "'/(?:(?:[^%]|^)(?:%%)+('", ".", "$", "subPattern", ".", "'))|(?:(?:[^%])('", ".", "$", "subPattern", ".", "'))|(?:^('", ".", "$", "subPattern", ".", "'))/u'", ";", "$", "matches", "=", "array", "(", ")", ";", "preg_match_all", "(", "$", "pattern", ",", "$", "isoFormat", ",", "$", "matches", ")", ";", "if", "(", "count", "(", "$", "matches", "[", "1", "]", ")", "+", "count", "(", "$", "matches", "[", "2", "]", ")", "+", "count", "(", "$", "matches", "[", "3", "]", ")", ">", "0", ")", "{", "// There is at least one format specifier in the string.", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
This method is not absolutely safe because of the 'volatile' nature of the printf format. However, it can validate a lot of strings as a first barrier for further code to be implemented. Examples: Format::isPrintfIsoFormat('%#x') => true Format::isPrintfIsoFormat('%#llx') => true Format::isPrintfIsoFormat('Octal %#x is Octal %#llx') => true Format::isPrintfIsoFormat("%d\n") => true Format::isPrintfIsoFormat("%3d\n") => true Format::isPrintfIsoFormat("%03d\n") => true Format::isPrintfIsoFormat("Characters: %c %c \n") => true Format::isPrintfIsoFormat("Decimals: %d %ld\n") => true Format::isPrintfIsoFormat("Preceding with blanks: %10d \n") => true Format::isPrintfIsoFormat("Preceding with zeros: %010d \n") => true Format::isPrintfIsoFormat("Some different radices: %d %x %o %#x %#o \n") => true Format::isPrintfIsoFormat("floats: %4.2f %+.0e %E \n") => true Format::isPrintfIsoFormat("Width trick: %*d \n") => true Format::isPrintfIsoFormat("%s \n") => true Format::isPrintfIsoFormat("%3d %06.3f\n") => true Format::isPrintfIsoFormat("The color: %s\n") => true Format::isPrintfIsoFormat("First number: %d\n") => true Format::isPrintfIsoFormat("Second number: %04d\n") => true Format::isPrintfIsoFormat("Third number: %i\n") => true Format::isPrintfIsoFormat("Float number: %3.2f\n") => true Format::isPrintfIsoFormat("Hexadecimal: %x\n") => true Format::isPrintfIsoFormat("Octal: %o\n") => true Format::isPrintfIsoFormat("Unsigned value: %u\n") => true Format::isPrintfIsoFormat("Just print the percentage sign %%\n") => false // Do not contain valid specifier. Format::isPrintfIsoFormat(":%s:\n") => true Format::isPrintfIsoFormat(":%15s:\n") => true Format::isPrintfIsoFormat(":%.10s:\n") => true Format::isPrintfIsoFormat(":%-10s:\n") => true Format::isPrintfIsoFormat(":%-15s:\n") => true Format::isPrintfIsoFormat(":%.15s:\n") => true Format::isPrintfIsoFormat(":%15.10s:\n") => true Format::isPrintfIsoFormat(":%-15.10s:\n") => true Format::isPrintfIsoFormat("This is an integer with padding %03d\n") => true Format::isPrintfIsoFormat('This is an integer with padding...') => false Format::isPrintfIsoFormat("Escape or not? %%s") => false Format::isPrintfIsoFormat("Escape or not? %%%s") => true Format::isPrintfIsoFormat("Escape or not? %%%%s") => false Format::isPrintfIsoFormat("Escape or not? %%%%%s") => true Format::isPrintfIsoFormat("%s bla %s and %%%s is %s and %%%%s") => true Format::isPrintfIsoFormat("%%s bla %s and %%%s is %s and %%%%s") => true Format::isPrintfIsoFormat("%%s bla %%s and %%%s is %s and %%%%s") => true Format::isPrintfIsoFormat("%%s bla %%s and %%s is %s and %%%%s") => true Format::isPrintfIsoFormat("%%s bla %%s and %%s is %%%%s and %%%%s") => false Format::isPrintfIsoFormat("%s") => true Format::isPrintfIsoFormat("%S") => false Format::isPrintfIsoFormat("bla %S bli %s") => true @param string $isoFormat @return boolean
[ "This", "method", "is", "not", "absolutely", "safe", "because", "of", "the", "volatile", "nature", "of", "the", "printf", "format", ".", "However", "it", "can", "validate", "a", "lot", "of", "strings", "as", "a", "first", "barrier", "for", "further", "code", "to", "be", "implemented", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/utils/Format.php#L566-L580
oat-sa/qti-sdk
src/qtism/common/utils/Format.php
Format.printfFormatIsoToPhp
public static function printfFormatIsoToPhp($isoFormat) { // Valid format, do the modifications to be compliant with // PHP's printf. $pattern = '/' . self::getPrintfFormatSpecifier() . '/u'; $matches = array(); preg_match_all($pattern, $isoFormat, $matches); foreach ($matches[0] as $m) { // Don't worry, str_replace is multibyte safe! $newM = str_replace('#', '', $m); $newM = str_replace(array('h', 'l', 'j', 'z', 't', 'L'), '', $newM); $newM = str_replace(array('i', 'a', 'A', 'c', 'p', 'n', 'O'), array('d', 'x', 'X', 's', 'x', 'd', 'o'), $newM); $isoFormat = str_replace($m, $newM, $isoFormat); } return $isoFormat; }
php
public static function printfFormatIsoToPhp($isoFormat) { // Valid format, do the modifications to be compliant with // PHP's printf. $pattern = '/' . self::getPrintfFormatSpecifier() . '/u'; $matches = array(); preg_match_all($pattern, $isoFormat, $matches); foreach ($matches[0] as $m) { // Don't worry, str_replace is multibyte safe! $newM = str_replace('#', '', $m); $newM = str_replace(array('h', 'l', 'j', 'z', 't', 'L'), '', $newM); $newM = str_replace(array('i', 'a', 'A', 'c', 'p', 'n', 'O'), array('d', 'x', 'X', 's', 'x', 'd', 'o'), $newM); $isoFormat = str_replace($m, $newM, $isoFormat); } return $isoFormat; }
[ "public", "static", "function", "printfFormatIsoToPhp", "(", "$", "isoFormat", ")", "{", "// Valid format, do the modifications to be compliant with", "// PHP's printf.", "$", "pattern", "=", "'/'", ".", "self", "::", "getPrintfFormatSpecifier", "(", ")", ".", "'/u'", ";", "$", "matches", "=", "array", "(", ")", ";", "preg_match_all", "(", "$", "pattern", ",", "$", "isoFormat", ",", "$", "matches", ")", ";", "foreach", "(", "$", "matches", "[", "0", "]", "as", "$", "m", ")", "{", "// Don't worry, str_replace is multibyte safe!", "$", "newM", "=", "str_replace", "(", "'#'", ",", "''", ",", "$", "m", ")", ";", "$", "newM", "=", "str_replace", "(", "array", "(", "'h'", ",", "'l'", ",", "'j'", ",", "'z'", ",", "'t'", ",", "'L'", ")", ",", "''", ",", "$", "newM", ")", ";", "$", "newM", "=", "str_replace", "(", "array", "(", "'i'", ",", "'a'", ",", "'A'", ",", "'c'", ",", "'p'", ",", "'n'", ",", "'O'", ")", ",", "array", "(", "'d'", ",", "'x'", ",", "'X'", ",", "'s'", ",", "'x'", ",", "'d'", ",", "'o'", ")", ",", "$", "newM", ")", ";", "$", "isoFormat", "=", "str_replace", "(", "$", "m", ",", "$", "newM", ",", "$", "isoFormat", ")", ";", "}", "return", "$", "isoFormat", ";", "}" ]
Transform an ISO number formatting into a format that can be handled by PHP's printf/sprintf implementation. Please note that this method is not totally safe because of the "funky" nature of ISO number formats especially when used with C++. However, this method can be a good first attempt of transformation for further instructions to be executed. @param string $isoFormat @return string The transformed formatting.
[ "Transform", "an", "ISO", "number", "formatting", "into", "a", "format", "that", "can", "be", "handled", "by", "PHP", "s", "printf", "/", "sprintf", "implementation", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/utils/Format.php#L594-L611
oat-sa/qti-sdk
src/qtism/common/utils/Format.php
Format.isXhtmlLength
public static function isXhtmlLength($length) { if (is_int($length) === true) { return $length >= 0; } elseif (is_string($length) === true) { return preg_match("/[0-9]+%/", $length) === 1; } else { return false; } }
php
public static function isXhtmlLength($length) { if (is_int($length) === true) { return $length >= 0; } elseif (is_string($length) === true) { return preg_match("/[0-9]+%/", $length) === 1; } else { return false; } }
[ "public", "static", "function", "isXhtmlLength", "(", "$", "length", ")", "{", "if", "(", "is_int", "(", "$", "length", ")", "===", "true", ")", "{", "return", "$", "length", ">=", "0", ";", "}", "elseif", "(", "is_string", "(", "$", "length", ")", "===", "true", ")", "{", "return", "preg_match", "(", "\"/[0-9]+%/\"", ",", "$", "length", ")", "===", "1", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Whether or not a given $length is a compliant XHTML length (e.g. "10%", 10, ...). @param mixed $length A length as a string or integer. @return boolean
[ "Whether", "or", "not", "a", "given", "$length", "is", "a", "compliant", "XHTML", "length", "(", "e", ".", "g", ".", "10%", "10", "...", ")", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/utils/Format.php#L620-L629
oat-sa/qti-sdk
src/qtism/data/SectionPart.php
SectionPart.setFixed
public function setFixed($fixed) { if (is_bool($fixed)) { $this->fixed = $fixed; } else { $msg = "Fixed must be a boolean, '" . gettype($fixed) . "' given."; throw new InvalidArgumentException($msg); } }
php
public function setFixed($fixed) { if (is_bool($fixed)) { $this->fixed = $fixed; } else { $msg = "Fixed must be a boolean, '" . gettype($fixed) . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setFixed", "(", "$", "fixed", ")", "{", "if", "(", "is_bool", "(", "$", "fixed", ")", ")", "{", "$", "this", "->", "fixed", "=", "$", "fixed", ";", "}", "else", "{", "$", "msg", "=", "\"Fixed must be a boolean, '\"", ".", "gettype", "(", "$", "fixed", ")", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set if the section part is subject to shuffling. @param boolean $fixed true if subject to shuffling, false if not. @throws \InvalidArgumentException If $fixed is not a boolean.
[ "Set", "if", "the", "section", "part", "is", "subject", "to", "shuffling", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/SectionPart.php#L211-L219
oat-sa/qti-sdk
src/qtism/runtime/processing/ResponseProcessingException.php
ResponseProcessingException.setSource
public function setSource(Processable $source) { if ($source instanceof ResponseProcessingEngine) { parent::setSource($source); } else { $msg = "ResponseProcessingException::setSource only accepts ResponseProcessingEngine objects."; throw new InvalidArgumentException($msg); } }
php
public function setSource(Processable $source) { if ($source instanceof ResponseProcessingEngine) { parent::setSource($source); } else { $msg = "ResponseProcessingException::setSource only accepts ResponseProcessingEngine objects."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setSource", "(", "Processable", "$", "source", ")", "{", "if", "(", "$", "source", "instanceof", "ResponseProcessingEngine", ")", "{", "parent", "::", "setSource", "(", "$", "source", ")", ";", "}", "else", "{", "$", "msg", "=", "\"ResponseProcessingException::setSource only accepts ResponseProcessingEngine objects.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set the source of the error. @param \qtism\runtime\common\Processable $source The source of the error. @throws \InvalidArgumentException If $source is not a ResponseProcessingEngine object.
[ "Set", "the", "source", "of", "the", "error", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/processing/ResponseProcessingException.php#L60-L68
oat-sa/qti-sdk
src/qtism/data/AssessmentItem.php
AssessmentItem.setLang
public function setLang($lang = '') { if (gettype($lang) === 'string') { $this->lang = $lang; } else { $msg = "The lang argument must be a string, '" . gettype($lang) . "' given."; throw new InvalidArgumentException($msg); } }
php
public function setLang($lang = '') { if (gettype($lang) === 'string') { $this->lang = $lang; } else { $msg = "The lang argument must be a string, '" . gettype($lang) . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setLang", "(", "$", "lang", "=", "''", ")", "{", "if", "(", "gettype", "(", "$", "lang", ")", "===", "'string'", ")", "{", "$", "this", "->", "lang", "=", "$", "lang", ";", "}", "else", "{", "$", "msg", "=", "\"The lang argument must be a string, '\"", ".", "gettype", "(", "$", "lang", ")", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set the language code. @param string $lang A language code. @throws \InvalidArgumentException If $lang is not a string.
[ "Set", "the", "language", "code", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/AssessmentItem.php#L285-L293
oat-sa/qti-sdk
src/qtism/data/AssessmentItem.php
AssessmentItem.setLabel
public function setLabel($label) { if (Format::isString256($label) === true) { $this->label = $label; } else { $msg = "The label argument must be a string with at most 256 characters."; throw new InvalidArgumentException($msg); } }
php
public function setLabel($label) { if (Format::isString256($label) === true) { $this->label = $label; } else { $msg = "The label argument must be a string with at most 256 characters."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setLabel", "(", "$", "label", ")", "{", "if", "(", "Format", "::", "isString256", "(", "$", "label", ")", "===", "true", ")", "{", "$", "this", "->", "label", "=", "$", "label", ";", "}", "else", "{", "$", "msg", "=", "\"The label argument must be a string with at most 256 characters.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set the label of the item. @param string $label A string with at most 256 characters. @throws \InvalidArgumentException If $label is not a string with at most 256 characters.
[ "Set", "the", "label", "of", "the", "item", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/AssessmentItem.php#L301-L309
oat-sa/qti-sdk
src/qtism/data/AssessmentItem.php
AssessmentItem.setAdaptive
public function setAdaptive($adaptive) { if (is_bool($adaptive)) { $this->adaptive = $adaptive; } else { $msg = "The adaptive argument must be a boolean, '" . gettype($adaptive) . "' given."; throw new InvalidArgumentException($msg); } }
php
public function setAdaptive($adaptive) { if (is_bool($adaptive)) { $this->adaptive = $adaptive; } else { $msg = "The adaptive argument must be a boolean, '" . gettype($adaptive) . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setAdaptive", "(", "$", "adaptive", ")", "{", "if", "(", "is_bool", "(", "$", "adaptive", ")", ")", "{", "$", "this", "->", "adaptive", "=", "$", "adaptive", ";", "}", "else", "{", "$", "msg", "=", "\"The adaptive argument must be a boolean, '\"", ".", "gettype", "(", "$", "adaptive", ")", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set whether the item is adaptive. @param boolean $adaptive Adaptive or not. @throws \InvalidArgumentException If $adaptive is not a boolean value.
[ "Set", "whether", "the", "item", "is", "adaptive", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/AssessmentItem.php#L359-L367
oat-sa/qti-sdk
src/qtism/data/AssessmentItem.php
AssessmentItem.setToolName
public function setToolName($toolName) { if (Format::isString256($toolName) === true) { $this->toolName = $toolName; } else { $msg = "The toolName argument must be a string with at most 256 characters."; throw new InvalidArgumentException($msg); } }
php
public function setToolName($toolName) { if (Format::isString256($toolName) === true) { $this->toolName = $toolName; } else { $msg = "The toolName argument must be a string with at most 256 characters."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setToolName", "(", "$", "toolName", ")", "{", "if", "(", "Format", "::", "isString256", "(", "$", "toolName", ")", "===", "true", ")", "{", "$", "this", "->", "toolName", "=", "$", "toolName", ";", "}", "else", "{", "$", "msg", "=", "\"The toolName argument must be a string with at most 256 characters.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set the name of the tool with which the item was created. @param string $toolName A tool name with at most 256 characters. @throws \InvalidArgumentException If $toolName is not a string value with at most 256 characters.
[ "Set", "the", "name", "of", "the", "tool", "with", "which", "the", "item", "was", "created", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/AssessmentItem.php#L411-L419
oat-sa/qti-sdk
src/qtism/data/AssessmentItem.php
AssessmentItem.setToolVersion
public function setToolVersion($toolVersion) { if (Format::isString256($toolVersion) === true) { $this->toolVersion = $toolVersion; } else { $msg = "The toolVersion argument must be a string with at most 256 characters."; throw new InvalidArgumentException($msg); } }
php
public function setToolVersion($toolVersion) { if (Format::isString256($toolVersion) === true) { $this->toolVersion = $toolVersion; } else { $msg = "The toolVersion argument must be a string with at most 256 characters."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setToolVersion", "(", "$", "toolVersion", ")", "{", "if", "(", "Format", "::", "isString256", "(", "$", "toolVersion", ")", "===", "true", ")", "{", "$", "this", "->", "toolVersion", "=", "$", "toolVersion", ";", "}", "else", "{", "$", "msg", "=", "\"The toolVersion argument must be a string with at most 256 characters.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set the version of the tool with which the item was created. @param string $toolVersion A tool version with at most 256 characters. @throws \InvalidArgumentException If $toolVersion is not a string value with at most 256 characters.
[ "Set", "the", "version", "of", "the", "tool", "with", "which", "the", "item", "was", "created", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/AssessmentItem.php#L447-L455
oat-sa/qti-sdk
src/qtism/data/AssessmentItem.php
AssessmentItem.getEndAttemptIdentifiers
public function getEndAttemptIdentifiers() { $endAttemptIdentifiers = new IdentifierCollection(); foreach ($this->getComponentsByClassName('endAttemptInteraction') as $endAttemptInteraction) { $endAttemptIdentifiers[] = $endAttemptInteraction->getResponseIdentifier(); } return $endAttemptIdentifiers; }
php
public function getEndAttemptIdentifiers() { $endAttemptIdentifiers = new IdentifierCollection(); foreach ($this->getComponentsByClassName('endAttemptInteraction') as $endAttemptInteraction) { $endAttemptIdentifiers[] = $endAttemptInteraction->getResponseIdentifier(); } return $endAttemptIdentifiers; }
[ "public", "function", "getEndAttemptIdentifiers", "(", ")", "{", "$", "endAttemptIdentifiers", "=", "new", "IdentifierCollection", "(", ")", ";", "foreach", "(", "$", "this", "->", "getComponentsByClassName", "(", "'endAttemptInteraction'", ")", "as", "$", "endAttemptInteraction", ")", "{", "$", "endAttemptIdentifiers", "[", "]", "=", "$", "endAttemptInteraction", "->", "getResponseIdentifier", "(", ")", ";", "}", "return", "$", "endAttemptIdentifiers", ";", "}" ]
Get the response variable identifiers related to the endAttemptInteraction in the item content. @return \qtism\common\collections\IdentifierCollection @see \qtism\data\IAssessmentItem::getEndAttemptIdentifiers()
[ "Get", "the", "response", "variable", "identifiers", "related", "to", "the", "endAttemptInteraction", "in", "the", "item", "content", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/AssessmentItem.php#L695-L703
oat-sa/qti-sdk
src/qtism/data/storage/xml/marshalling/SubstringMarshaller.php
SubstringMarshaller.unmarshallChildrenKnown
protected function unmarshallChildrenKnown(DOMElement $element, QtiComponentCollection $children) { $object = new Substring($children); if (($caseSensitive = $this->getDOMElementAttributeAs($element, 'caseSensitive', 'boolean')) !== null) { $object->setCaseSensitive($caseSensitive); } return $object; }
php
protected function unmarshallChildrenKnown(DOMElement $element, QtiComponentCollection $children) { $object = new Substring($children); if (($caseSensitive = $this->getDOMElementAttributeAs($element, 'caseSensitive', 'boolean')) !== null) { $object->setCaseSensitive($caseSensitive); } return $object; }
[ "protected", "function", "unmarshallChildrenKnown", "(", "DOMElement", "$", "element", ",", "QtiComponentCollection", "$", "children", ")", "{", "$", "object", "=", "new", "Substring", "(", "$", "children", ")", ";", "if", "(", "(", "$", "caseSensitive", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'caseSensitive'", ",", "'boolean'", ")", ")", "!==", "null", ")", "{", "$", "object", "->", "setCaseSensitive", "(", "$", "caseSensitive", ")", ";", "}", "return", "$", "object", ";", "}" ]
Unmarshall a QTI substring operator element into a Substring object. @param \DOMElement The substring element to unmarshall. @param \qtism\data\QtiComponentCollection A collection containing the child Expression objects composing the Operator. @return \qtism\data\QtiComponent A Substring object. @throws \qtism\data\storage\xml\marshalling\UnmarshallingException
[ "Unmarshall", "a", "QTI", "substring", "operator", "element", "into", "a", "Substring", "object", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/SubstringMarshaller.php#L66-L75
oat-sa/qti-sdk
src/qtism/data/storage/xml/marshalling/SelectPointInteractionMarshaller.php
SelectPointInteractionMarshaller.unmarshall
protected function unmarshall(DOMElement $element) { $version = $this->getVersion(); if (($responseIdentifier = $this->getDOMElementAttributeAs($element, 'responseIdentifier')) !== null) { $objectElts = $this->getChildElementsByTagName($element, 'object'); if (count($objectElts) > 0) { $object = $this->getMarshallerFactory()->createMarshaller($objectElts[0])->unmarshall($objectElts[0]); $component = new SelectPointInteraction($responseIdentifier, $object); if (Version::compare($version, '2.1.0', '>=') === true && ($minChoices = $this->getDOMElementAttributeAs($element, 'minChoices', 'integer')) !== null) { $component->setMinChoices($minChoices); } if (($maxChoices = $this->getDOMElementAttributeAs($element, 'maxChoices', 'integer')) !== null) { $component->setMaxChoices($maxChoices); } elseif (Version::compare($version, '2.1.0', '<') === true) { $msg = "The mandatory 'maxChoices' attribute is missing from the 'selectPointInteraction' element."; throw new UnmarshallingException($msg, $element); } if (($xmlBase = self::getXmlBase($element)) !== false) { $component->setXmlBase($xmlBase); } $promptElts = $this->getChildElementsByTagName($element, 'prompt'); if (count($promptElts) > 0) { $promptElt = $promptElts[0]; $prompt = $this->getMarshallerFactory()->createMarshaller($promptElt)->unmarshall($promptElt); $component->setPrompt($prompt); } $this->fillBodyElement($component, $element); return $component; } else { $msg = "A 'selectPointInteraction' element must contain exactly one 'object' element, none given."; throw new UnmarshallingException($msg, $element); } } else { $msg = "The mandatory 'responseIdentifier' attribute is missing from the 'selectPointInteraction' element."; throw new UnmarshallingException($msg, $element); } }
php
protected function unmarshall(DOMElement $element) { $version = $this->getVersion(); if (($responseIdentifier = $this->getDOMElementAttributeAs($element, 'responseIdentifier')) !== null) { $objectElts = $this->getChildElementsByTagName($element, 'object'); if (count($objectElts) > 0) { $object = $this->getMarshallerFactory()->createMarshaller($objectElts[0])->unmarshall($objectElts[0]); $component = new SelectPointInteraction($responseIdentifier, $object); if (Version::compare($version, '2.1.0', '>=') === true && ($minChoices = $this->getDOMElementAttributeAs($element, 'minChoices', 'integer')) !== null) { $component->setMinChoices($minChoices); } if (($maxChoices = $this->getDOMElementAttributeAs($element, 'maxChoices', 'integer')) !== null) { $component->setMaxChoices($maxChoices); } elseif (Version::compare($version, '2.1.0', '<') === true) { $msg = "The mandatory 'maxChoices' attribute is missing from the 'selectPointInteraction' element."; throw new UnmarshallingException($msg, $element); } if (($xmlBase = self::getXmlBase($element)) !== false) { $component->setXmlBase($xmlBase); } $promptElts = $this->getChildElementsByTagName($element, 'prompt'); if (count($promptElts) > 0) { $promptElt = $promptElts[0]; $prompt = $this->getMarshallerFactory()->createMarshaller($promptElt)->unmarshall($promptElt); $component->setPrompt($prompt); } $this->fillBodyElement($component, $element); return $component; } else { $msg = "A 'selectPointInteraction' element must contain exactly one 'object' element, none given."; throw new UnmarshallingException($msg, $element); } } else { $msg = "The mandatory 'responseIdentifier' attribute is missing from the 'selectPointInteraction' element."; throw new UnmarshallingException($msg, $element); } }
[ "protected", "function", "unmarshall", "(", "DOMElement", "$", "element", ")", "{", "$", "version", "=", "$", "this", "->", "getVersion", "(", ")", ";", "if", "(", "(", "$", "responseIdentifier", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'responseIdentifier'", ")", ")", "!==", "null", ")", "{", "$", "objectElts", "=", "$", "this", "->", "getChildElementsByTagName", "(", "$", "element", ",", "'object'", ")", ";", "if", "(", "count", "(", "$", "objectElts", ")", ">", "0", ")", "{", "$", "object", "=", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "objectElts", "[", "0", "]", ")", "->", "unmarshall", "(", "$", "objectElts", "[", "0", "]", ")", ";", "$", "component", "=", "new", "SelectPointInteraction", "(", "$", "responseIdentifier", ",", "$", "object", ")", ";", "if", "(", "Version", "::", "compare", "(", "$", "version", ",", "'2.1.0'", ",", "'>='", ")", "===", "true", "&&", "(", "$", "minChoices", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'minChoices'", ",", "'integer'", ")", ")", "!==", "null", ")", "{", "$", "component", "->", "setMinChoices", "(", "$", "minChoices", ")", ";", "}", "if", "(", "(", "$", "maxChoices", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'maxChoices'", ",", "'integer'", ")", ")", "!==", "null", ")", "{", "$", "component", "->", "setMaxChoices", "(", "$", "maxChoices", ")", ";", "}", "elseif", "(", "Version", "::", "compare", "(", "$", "version", ",", "'2.1.0'", ",", "'<'", ")", "===", "true", ")", "{", "$", "msg", "=", "\"The mandatory 'maxChoices' attribute is missing from the 'selectPointInteraction' element.\"", ";", "throw", "new", "UnmarshallingException", "(", "$", "msg", ",", "$", "element", ")", ";", "}", "if", "(", "(", "$", "xmlBase", "=", "self", "::", "getXmlBase", "(", "$", "element", ")", ")", "!==", "false", ")", "{", "$", "component", "->", "setXmlBase", "(", "$", "xmlBase", ")", ";", "}", "$", "promptElts", "=", "$", "this", "->", "getChildElementsByTagName", "(", "$", "element", ",", "'prompt'", ")", ";", "if", "(", "count", "(", "$", "promptElts", ")", ">", "0", ")", "{", "$", "promptElt", "=", "$", "promptElts", "[", "0", "]", ";", "$", "prompt", "=", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "promptElt", ")", "->", "unmarshall", "(", "$", "promptElt", ")", ";", "$", "component", "->", "setPrompt", "(", "$", "prompt", ")", ";", "}", "$", "this", "->", "fillBodyElement", "(", "$", "component", ",", "$", "element", ")", ";", "return", "$", "component", ";", "}", "else", "{", "$", "msg", "=", "\"A 'selectPointInteraction' element must contain exactly one 'object' element, none given.\"", ";", "throw", "new", "UnmarshallingException", "(", "$", "msg", ",", "$", "element", ")", ";", "}", "}", "else", "{", "$", "msg", "=", "\"The mandatory 'responseIdentifier' attribute is missing from the 'selectPointInteraction' element.\"", ";", "throw", "new", "UnmarshallingException", "(", "$", "msg", ",", "$", "element", ")", ";", "}", "}" ]
Unmarshall a DOMElement object corresponding to a selectPointInteraction element. @param \DOMElement $element A DOMElement object. @return \qtism\data\QtiComponent A SelectPointInteraction object. @throws \qtism\data\storage\xml\marshalling\UnmarshallingException
[ "Unmarshall", "a", "DOMElement", "object", "corresponding", "to", "a", "selectPointInteraction", "element", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/SelectPointInteractionMarshaller.php#L80-L125
oat-sa/qti-sdk
src/qtism/data/AssessmentItemRef.php
AssessmentItemRef.setHref
public function setHref($href) { if (gettype($href) === 'string') { $this->href = $href; } else { $msg = "href must be a string, '" . gettype($href) . "' given."; throw new InvalidArgumentException($msg); } }
php
public function setHref($href) { if (gettype($href) === 'string') { $this->href = $href; } else { $msg = "href must be a string, '" . gettype($href) . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setHref", "(", "$", "href", ")", "{", "if", "(", "gettype", "(", "$", "href", ")", "===", "'string'", ")", "{", "$", "this", "->", "href", "=", "$", "href", ";", "}", "else", "{", "$", "msg", "=", "\"href must be a string, '\"", ".", "gettype", "(", "$", "href", ")", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set the URI that references the item's file. @param string $href A URI. @throws \InvalidArgumentException If $href is not a string.
[ "Set", "the", "URI", "that", "references", "the", "item", "s", "file", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/AssessmentItemRef.php#L126-L134
oat-sa/qti-sdk
src/qtism/common/datatypes/QtiString.php
QtiString.equals
public function equals($obj) { if ($obj instanceof QtiScalar) { return $obj->getValue() === $this->getValue(); } elseif ($this->getValue() === '' && $obj === null) { return true; } else { return $this->getValue() === $obj; } }
php
public function equals($obj) { if ($obj instanceof QtiScalar) { return $obj->getValue() === $this->getValue(); } elseif ($this->getValue() === '' && $obj === null) { return true; } else { return $this->getValue() === $obj; } }
[ "public", "function", "equals", "(", "$", "obj", ")", "{", "if", "(", "$", "obj", "instanceof", "QtiScalar", ")", "{", "return", "$", "obj", "->", "getValue", "(", ")", "===", "$", "this", "->", "getValue", "(", ")", ";", "}", "elseif", "(", "$", "this", "->", "getValue", "(", ")", "===", "''", "&&", "$", "obj", "===", "null", ")", "{", "return", "true", ";", "}", "else", "{", "return", "$", "this", "->", "getValue", "(", ")", "===", "$", "obj", ";", "}", "}" ]
Wheter or not the current QtiString object is equal to $obj. Two QtiString objects are considered to be identical if their intrinsic values are equals. If the current QtiString is an empty string, and $obj is NULL, the values are considered equal. @return boolean
[ "Wheter", "or", "not", "the", "current", "QtiString", "object", "is", "equal", "to", "$obj", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/datatypes/QtiString.php#L81-L90
oat-sa/qti-sdk
src/qtism/runtime/rendering/qtipl/expressions/operators/EqualQtiPLRenderer.php
EqualQtiPLRenderer.render
public function render($something) { $renderer = new QtiPLRenderer($this->getCRO()); $attributes = []; if ($something->getToleranceMode() != ToleranceMode::EXACT) { $attributes['toleranceMode'] = "\"" . ToleranceMode::getNameByConstant($something->getToleranceMode()) . "\""; } if (($something->getTolerance() != null) && count($something->getTolerance()) > 0) { $tolerance = "\"" . $something->getTolerance()[0]; $tolerance .= (count($something->getTolerance()) > 1) ? ";" . $something->getTolerance()[1] : ""; $tolerance .= "\""; $attributes['tolerance'] = $tolerance; } if (!$something->doesIncludeLowerBound()) { $attributes['includeLowerBound'] = "false"; } if (!$something->doesIncludeUpperBound()) { $attributes['includeUpperBound'] = "false"; } return $something->getQtiClassName() . $renderer->writeAttributes($attributes) . $renderer->writeChildElements($something->getExpressions()); }
php
public function render($something) { $renderer = new QtiPLRenderer($this->getCRO()); $attributes = []; if ($something->getToleranceMode() != ToleranceMode::EXACT) { $attributes['toleranceMode'] = "\"" . ToleranceMode::getNameByConstant($something->getToleranceMode()) . "\""; } if (($something->getTolerance() != null) && count($something->getTolerance()) > 0) { $tolerance = "\"" . $something->getTolerance()[0]; $tolerance .= (count($something->getTolerance()) > 1) ? ";" . $something->getTolerance()[1] : ""; $tolerance .= "\""; $attributes['tolerance'] = $tolerance; } if (!$something->doesIncludeLowerBound()) { $attributes['includeLowerBound'] = "false"; } if (!$something->doesIncludeUpperBound()) { $attributes['includeUpperBound'] = "false"; } return $something->getQtiClassName() . $renderer->writeAttributes($attributes) . $renderer->writeChildElements($something->getExpressions()); }
[ "public", "function", "render", "(", "$", "something", ")", "{", "$", "renderer", "=", "new", "QtiPLRenderer", "(", "$", "this", "->", "getCRO", "(", ")", ")", ";", "$", "attributes", "=", "[", "]", ";", "if", "(", "$", "something", "->", "getToleranceMode", "(", ")", "!=", "ToleranceMode", "::", "EXACT", ")", "{", "$", "attributes", "[", "'toleranceMode'", "]", "=", "\"\\\"\"", ".", "ToleranceMode", "::", "getNameByConstant", "(", "$", "something", "->", "getToleranceMode", "(", ")", ")", ".", "\"\\\"\"", ";", "}", "if", "(", "(", "$", "something", "->", "getTolerance", "(", ")", "!=", "null", ")", "&&", "count", "(", "$", "something", "->", "getTolerance", "(", ")", ")", ">", "0", ")", "{", "$", "tolerance", "=", "\"\\\"\"", ".", "$", "something", "->", "getTolerance", "(", ")", "[", "0", "]", ";", "$", "tolerance", ".=", "(", "count", "(", "$", "something", "->", "getTolerance", "(", ")", ")", ">", "1", ")", "?", "\";\"", ".", "$", "something", "->", "getTolerance", "(", ")", "[", "1", "]", ":", "\"\"", ";", "$", "tolerance", ".=", "\"\\\"\"", ";", "$", "attributes", "[", "'tolerance'", "]", "=", "$", "tolerance", ";", "}", "if", "(", "!", "$", "something", "->", "doesIncludeLowerBound", "(", ")", ")", "{", "$", "attributes", "[", "'includeLowerBound'", "]", "=", "\"false\"", ";", "}", "if", "(", "!", "$", "something", "->", "doesIncludeUpperBound", "(", ")", ")", "{", "$", "attributes", "[", "'includeUpperBound'", "]", "=", "\"false\"", ";", "}", "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/EqualQtiPLRenderer.php#L46-L72
oat-sa/qti-sdk
src/qtism/common/datatypes/QtiCoords.php
QtiCoords.inside
public function inside(QtiPoint $point) { if ($this->getShape() === QtiShape::DEF) { return true; } elseif ($this->getShape() === QtiShape::RECT) { return $point->getX() >= $this[0] && $point->getX() <= $this[2] && $point->getY() >= $this[1] && $point->getY() <= $this[3]; } elseif ($this->getShape() === QtiShape::CIRCLE) { return pow($point->getX() - $this[0], 2) + pow($point->getY() - $this[1], 2) < pow($this[2], 2); } else { // we consider it is a polygon. // - Transform coordinates in vertices. // -- Use of the "point in polygon" algorithm. $vertices = array(); for ($i = 0; $i < count($this); $i++) { $vertex = array(); $vertex[] = $this[$i]; //x $i++; $vertex[] = $this[$i]; //y $vertices[] = $vertex; } $intersects = 0; for ($i = 1; $i < count($vertices); $i++) { $vertex1 = $vertices[$i -1]; $vertex2 = $vertices[$i]; if ($vertex1[1] === $vertex2[1] && $vertex1[1] === $point->getY() && $point->getX() > min($vertex1[0], $vertex2[0]) && $point->getX() < max($vertex1[0], $vertex2[0])) { // we are on a boundary. return true; } if ($point->getY() > min($vertex1[1], $vertex2[1]) && $point->getY() <= max($vertex1[1], $vertex2[1]) && $point->getX() <= max($vertex1[0], $vertex2[0]) && $vertex1[1] !== $vertex2[1]) { $xinters = ($point->getY() - $vertex1[1]) * ($vertex2[0] - $vertex1[0]) / ($vertex2[1] - $vertex1[1]) + $vertex1[0]; if ($xinters === $point->getX()) { // Again, we are on a boundary. return true; } if ($vertex1[0] === $vertex2[0] || $point->getX() <= $xinters) { // We have a single intersection. $intersects++; } } } // If we passed through an odd number of edges, we are in the polygon! return $intersects % 2 !== 0; } }
php
public function inside(QtiPoint $point) { if ($this->getShape() === QtiShape::DEF) { return true; } elseif ($this->getShape() === QtiShape::RECT) { return $point->getX() >= $this[0] && $point->getX() <= $this[2] && $point->getY() >= $this[1] && $point->getY() <= $this[3]; } elseif ($this->getShape() === QtiShape::CIRCLE) { return pow($point->getX() - $this[0], 2) + pow($point->getY() - $this[1], 2) < pow($this[2], 2); } else { // we consider it is a polygon. // - Transform coordinates in vertices. // -- Use of the "point in polygon" algorithm. $vertices = array(); for ($i = 0; $i < count($this); $i++) { $vertex = array(); $vertex[] = $this[$i]; //x $i++; $vertex[] = $this[$i]; //y $vertices[] = $vertex; } $intersects = 0; for ($i = 1; $i < count($vertices); $i++) { $vertex1 = $vertices[$i -1]; $vertex2 = $vertices[$i]; if ($vertex1[1] === $vertex2[1] && $vertex1[1] === $point->getY() && $point->getX() > min($vertex1[0], $vertex2[0]) && $point->getX() < max($vertex1[0], $vertex2[0])) { // we are on a boundary. return true; } if ($point->getY() > min($vertex1[1], $vertex2[1]) && $point->getY() <= max($vertex1[1], $vertex2[1]) && $point->getX() <= max($vertex1[0], $vertex2[0]) && $vertex1[1] !== $vertex2[1]) { $xinters = ($point->getY() - $vertex1[1]) * ($vertex2[0] - $vertex1[0]) / ($vertex2[1] - $vertex1[1]) + $vertex1[0]; if ($xinters === $point->getX()) { // Again, we are on a boundary. return true; } if ($vertex1[0] === $vertex2[0] || $point->getX() <= $xinters) { // We have a single intersection. $intersects++; } } } // If we passed through an odd number of edges, we are in the polygon! return $intersects % 2 !== 0; } }
[ "public", "function", "inside", "(", "QtiPoint", "$", "point", ")", "{", "if", "(", "$", "this", "->", "getShape", "(", ")", "===", "QtiShape", "::", "DEF", ")", "{", "return", "true", ";", "}", "elseif", "(", "$", "this", "->", "getShape", "(", ")", "===", "QtiShape", "::", "RECT", ")", "{", "return", "$", "point", "->", "getX", "(", ")", ">=", "$", "this", "[", "0", "]", "&&", "$", "point", "->", "getX", "(", ")", "<=", "$", "this", "[", "2", "]", "&&", "$", "point", "->", "getY", "(", ")", ">=", "$", "this", "[", "1", "]", "&&", "$", "point", "->", "getY", "(", ")", "<=", "$", "this", "[", "3", "]", ";", "}", "elseif", "(", "$", "this", "->", "getShape", "(", ")", "===", "QtiShape", "::", "CIRCLE", ")", "{", "return", "pow", "(", "$", "point", "->", "getX", "(", ")", "-", "$", "this", "[", "0", "]", ",", "2", ")", "+", "pow", "(", "$", "point", "->", "getY", "(", ")", "-", "$", "this", "[", "1", "]", ",", "2", ")", "<", "pow", "(", "$", "this", "[", "2", "]", ",", "2", ")", ";", "}", "else", "{", "// we consider it is a polygon.", "// - Transform coordinates in vertices.", "// -- Use of the \"point in polygon\" algorithm.", "$", "vertices", "=", "array", "(", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "count", "(", "$", "this", ")", ";", "$", "i", "++", ")", "{", "$", "vertex", "=", "array", "(", ")", ";", "$", "vertex", "[", "]", "=", "$", "this", "[", "$", "i", "]", ";", "//x", "$", "i", "++", ";", "$", "vertex", "[", "]", "=", "$", "this", "[", "$", "i", "]", ";", "//y", "$", "vertices", "[", "]", "=", "$", "vertex", ";", "}", "$", "intersects", "=", "0", ";", "for", "(", "$", "i", "=", "1", ";", "$", "i", "<", "count", "(", "$", "vertices", ")", ";", "$", "i", "++", ")", "{", "$", "vertex1", "=", "$", "vertices", "[", "$", "i", "-", "1", "]", ";", "$", "vertex2", "=", "$", "vertices", "[", "$", "i", "]", ";", "if", "(", "$", "vertex1", "[", "1", "]", "===", "$", "vertex2", "[", "1", "]", "&&", "$", "vertex1", "[", "1", "]", "===", "$", "point", "->", "getY", "(", ")", "&&", "$", "point", "->", "getX", "(", ")", ">", "min", "(", "$", "vertex1", "[", "0", "]", ",", "$", "vertex2", "[", "0", "]", ")", "&&", "$", "point", "->", "getX", "(", ")", "<", "max", "(", "$", "vertex1", "[", "0", "]", ",", "$", "vertex2", "[", "0", "]", ")", ")", "{", "// we are on a boundary.", "return", "true", ";", "}", "if", "(", "$", "point", "->", "getY", "(", ")", ">", "min", "(", "$", "vertex1", "[", "1", "]", ",", "$", "vertex2", "[", "1", "]", ")", "&&", "$", "point", "->", "getY", "(", ")", "<=", "max", "(", "$", "vertex1", "[", "1", "]", ",", "$", "vertex2", "[", "1", "]", ")", "&&", "$", "point", "->", "getX", "(", ")", "<=", "max", "(", "$", "vertex1", "[", "0", "]", ",", "$", "vertex2", "[", "0", "]", ")", "&&", "$", "vertex1", "[", "1", "]", "!==", "$", "vertex2", "[", "1", "]", ")", "{", "$", "xinters", "=", "(", "$", "point", "->", "getY", "(", ")", "-", "$", "vertex1", "[", "1", "]", ")", "*", "(", "$", "vertex2", "[", "0", "]", "-", "$", "vertex1", "[", "0", "]", ")", "/", "(", "$", "vertex2", "[", "1", "]", "-", "$", "vertex1", "[", "1", "]", ")", "+", "$", "vertex1", "[", "0", "]", ";", "if", "(", "$", "xinters", "===", "$", "point", "->", "getX", "(", ")", ")", "{", "// Again, we are on a boundary.", "return", "true", ";", "}", "if", "(", "$", "vertex1", "[", "0", "]", "===", "$", "vertex2", "[", "0", "]", "||", "$", "point", "->", "getX", "(", ")", "<=", "$", "xinters", ")", "{", "// We have a single intersection.", "$", "intersects", "++", ";", "}", "}", "}", "// If we passed through an odd number of edges, we are in the polygon!", "return", "$", "intersects", "%", "2", "!==", "0", ";", "}", "}" ]
Whether the given $point is inside the coordinates. @param Point $point A Point object. @return boolean
[ "Whether", "the", "given", "$point", "is", "inside", "the", "coordinates", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/datatypes/QtiCoords.php#L120-L170
oat-sa/qti-sdk
src/qtism/common/datatypes/QtiCoords.php
QtiCoords.equals
public function equals($obj) { return $obj instanceof QtiCoords && $this->getShape() === $obj->getShape() && $this->getArrayCopy() == $obj->getArrayCopy(); }
php
public function equals($obj) { return $obj instanceof QtiCoords && $this->getShape() === $obj->getShape() && $this->getArrayCopy() == $obj->getArrayCopy(); }
[ "public", "function", "equals", "(", "$", "obj", ")", "{", "return", "$", "obj", "instanceof", "QtiCoords", "&&", "$", "this", "->", "getShape", "(", ")", "===", "$", "obj", "->", "getShape", "(", ")", "&&", "$", "this", "->", "getArrayCopy", "(", ")", "==", "$", "obj", "->", "getArrayCopy", "(", ")", ";", "}" ]
Whether or not $obj is equals to $this. Two Coords objects are considered to be equal if they have the same coordinates and shape. return boolean
[ "Whether", "or", "not", "$obj", "is", "equals", "to", "$this", ".", "Two", "Coords", "objects", "are", "considered", "to", "be", "equal", "if", "they", "have", "the", "same", "coordinates", "and", "shape", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/datatypes/QtiCoords.php#L188-L191
oat-sa/qti-sdk
src/qtism/data/storage/xml/marshalling/ColgroupMarshaller.php
ColgroupMarshaller.marshall
protected function marshall(QtiComponent $component) { $element = self::getDOMCradle()->createElement('colgroup'); $this->setDOMElementAttribute($element, 'span', $component->getSpan()); foreach ($component->getContent() as $col) { $marshaller = $this->getMarshallerFactory()->createMarshaller($col); $element->appendChild($marshaller->marshall($col)); } $this->fillElement($element, $component); return $element; }
php
protected function marshall(QtiComponent $component) { $element = self::getDOMCradle()->createElement('colgroup'); $this->setDOMElementAttribute($element, 'span', $component->getSpan()); foreach ($component->getContent() as $col) { $marshaller = $this->getMarshallerFactory()->createMarshaller($col); $element->appendChild($marshaller->marshall($col)); } $this->fillElement($element, $component); return $element; }
[ "protected", "function", "marshall", "(", "QtiComponent", "$", "component", ")", "{", "$", "element", "=", "self", "::", "getDOMCradle", "(", ")", "->", "createElement", "(", "'colgroup'", ")", ";", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'span'", ",", "$", "component", "->", "getSpan", "(", ")", ")", ";", "foreach", "(", "$", "component", "->", "getContent", "(", ")", "as", "$", "col", ")", "{", "$", "marshaller", "=", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "col", ")", ";", "$", "element", "->", "appendChild", "(", "$", "marshaller", "->", "marshall", "(", "$", "col", ")", ")", ";", "}", "$", "this", "->", "fillElement", "(", "$", "element", ",", "$", "component", ")", ";", "return", "$", "element", ";", "}" ]
Marshall a Colgroup object into a DOMElement object. @param \qtism\data\QtiComponent $component A Colgroup object. @return \DOMElement The according DOMElement object. @throws \qtism\data\storage\xml\marshalling\MarshallingException
[ "Marshall", "a", "Colgroup", "object", "into", "a", "DOMElement", "object", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/ColgroupMarshaller.php#L45-L58
oat-sa/qti-sdk
src/qtism/data/storage/xml/marshalling/ColgroupMarshaller.php
ColgroupMarshaller.unmarshall
protected function unmarshall(DOMElement $element) { $component = new Colgroup(); if (($span = $this->getDOMElementAttributeAs($element, 'span', 'integer')) !== null) { $component->setSpan($span); } $cols = new ColCollection(); foreach ($this->getChildElementsByTagName($element, 'col') as $colElt) { $marshaller = $this->getMarshallerFactory()->createMarshaller($colElt); $cols[] = $marshaller->unmarshall($colElt); } $component->setContent($cols); $this->fillBodyElement($component, $element); return $component; }
php
protected function unmarshall(DOMElement $element) { $component = new Colgroup(); if (($span = $this->getDOMElementAttributeAs($element, 'span', 'integer')) !== null) { $component->setSpan($span); } $cols = new ColCollection(); foreach ($this->getChildElementsByTagName($element, 'col') as $colElt) { $marshaller = $this->getMarshallerFactory()->createMarshaller($colElt); $cols[] = $marshaller->unmarshall($colElt); } $component->setContent($cols); $this->fillBodyElement($component, $element); return $component; }
[ "protected", "function", "unmarshall", "(", "DOMElement", "$", "element", ")", "{", "$", "component", "=", "new", "Colgroup", "(", ")", ";", "if", "(", "(", "$", "span", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'span'", ",", "'integer'", ")", ")", "!==", "null", ")", "{", "$", "component", "->", "setSpan", "(", "$", "span", ")", ";", "}", "$", "cols", "=", "new", "ColCollection", "(", ")", ";", "foreach", "(", "$", "this", "->", "getChildElementsByTagName", "(", "$", "element", ",", "'col'", ")", "as", "$", "colElt", ")", "{", "$", "marshaller", "=", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "colElt", ")", ";", "$", "cols", "[", "]", "=", "$", "marshaller", "->", "unmarshall", "(", "$", "colElt", ")", ";", "}", "$", "component", "->", "setContent", "(", "$", "cols", ")", ";", "$", "this", "->", "fillBodyElement", "(", "$", "component", ",", "$", "element", ")", ";", "return", "$", "component", ";", "}" ]
Unmarshall a DOMElement object corresponding to an XHTML colgroup table element. @param \DOMElement $element A DOMElement object. @return \qtism\data\QtiComponent A Colgroup object. @throws \qtism\data\storage\xml\marshalling\UnmarshallingException
[ "Unmarshall", "a", "DOMElement", "object", "corresponding", "to", "an", "XHTML", "colgroup", "table", "element", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/ColgroupMarshaller.php#L67-L85
oat-sa/qti-sdk
src/qtism/runtime/rendering/qtipl/rules/ResponseConditionQtiPLRenderer.php
ResponseConditionQtiPLRenderer.render
public function render($something) { $renderer = new QtiPLRenderer($this->getCRO()); $qtipl = $renderer->render($something->getResponseIf()); foreach ($something->getResponseElseIfs() as $elseif) { $qtipl .= " " . $renderer->render($elseif); } $qtipl .= ($something->getResponseElse() == null) ? "" : $renderer->render($something->getResponseElse()); return $qtipl; }
php
public function render($something) { $renderer = new QtiPLRenderer($this->getCRO()); $qtipl = $renderer->render($something->getResponseIf()); foreach ($something->getResponseElseIfs() as $elseif) { $qtipl .= " " . $renderer->render($elseif); } $qtipl .= ($something->getResponseElse() == null) ? "" : $renderer->render($something->getResponseElse()); return $qtipl; }
[ "public", "function", "render", "(", "$", "something", ")", "{", "$", "renderer", "=", "new", "QtiPLRenderer", "(", "$", "this", "->", "getCRO", "(", ")", ")", ";", "$", "qtipl", "=", "$", "renderer", "->", "render", "(", "$", "something", "->", "getResponseIf", "(", ")", ")", ";", "foreach", "(", "$", "something", "->", "getResponseElseIfs", "(", ")", "as", "$", "elseif", ")", "{", "$", "qtipl", ".=", "\" \"", ".", "$", "renderer", "->", "render", "(", "$", "elseif", ")", ";", "}", "$", "qtipl", ".=", "(", "$", "something", "->", "getResponseElse", "(", ")", "==", "null", ")", "?", "\"\"", ":", "$", "renderer", "->", "render", "(", "$", "something", "->", "getResponseElse", "(", ")", ")", ";", "return", "$", "qtipl", ";", "}" ]
Render a QtiComponent object into another constitution. @param mixed $something Something to render into another consitution. @return mixed The rendered component into another constitution. @throws \qtism\runtime\rendering\RenderingException If something goes wrong while rendering the component.
[ "Render", "a", "QtiComponent", "object", "into", "another", "constitution", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/qtipl/rules/ResponseConditionQtiPLRenderer.php#L45-L56
oat-sa/qti-sdk
src/qtism/data/storage/xml/marshalling/ShufflingMarshaller.php
ShufflingMarshaller.marshall
protected function marshall(QtiComponent $component) { $element = static::getDOMCradle()->createElement($component->getQtiClassName()); $this->setDOMElementAttribute($element, 'responseIdentifier', $component->getResponseIdentifier()); foreach ($component->getShufflingGroups() as $shufflingGroup) { $marshaller = $this->getMarshallerFactory()->createMarshaller($shufflingGroup); $element->appendChild($marshaller->marshall($shufflingGroup)); } return $element; }
php
protected function marshall(QtiComponent $component) { $element = static::getDOMCradle()->createElement($component->getQtiClassName()); $this->setDOMElementAttribute($element, 'responseIdentifier', $component->getResponseIdentifier()); foreach ($component->getShufflingGroups() as $shufflingGroup) { $marshaller = $this->getMarshallerFactory()->createMarshaller($shufflingGroup); $element->appendChild($marshaller->marshall($shufflingGroup)); } return $element; }
[ "protected", "function", "marshall", "(", "QtiComponent", "$", "component", ")", "{", "$", "element", "=", "static", "::", "getDOMCradle", "(", ")", "->", "createElement", "(", "$", "component", "->", "getQtiClassName", "(", ")", ")", ";", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'responseIdentifier'", ",", "$", "component", "->", "getResponseIdentifier", "(", ")", ")", ";", "foreach", "(", "$", "component", "->", "getShufflingGroups", "(", ")", "as", "$", "shufflingGroup", ")", "{", "$", "marshaller", "=", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "shufflingGroup", ")", ";", "$", "element", "->", "appendChild", "(", "$", "marshaller", "->", "marshall", "(", "$", "shufflingGroup", ")", ")", ";", "}", "return", "$", "element", ";", "}" ]
Marshall a Shuffling object into a DOMElement object. @param \qtism\data\QtiComponent $component A Shuffling object. @return \DOMElement The according DOMElement object.
[ "Marshall", "a", "Shuffling", "object", "into", "a", "DOMElement", "object", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/ShufflingMarshaller.php#L45-L56
oat-sa/qti-sdk
src/qtism/data/storage/xml/marshalling/ShufflingMarshaller.php
ShufflingMarshaller.unmarshall
protected function unmarshall(DOMElement $element) { if (($responseIdentifier = $this->getDOMElementAttributeAs($element, 'responseIdentifier')) !== null) { $shufflingGroupElts = self::getChildElements($element, 'shufflingGroup'); if (($c = count($shufflingGroupElts)) === 0) { $msg = "A 'shuffling' element must contain at least 1 'shufflingGroup' element. None given."; throw new UnmarshallingException($msg, $element); } else if ($c > 2) { $msg = "A 'shuffling' element must contain at most 2 'shufflingGroup' elements. ${c} given."; throw new UnmarshallingException($msg, $element); } else { $shufflingGroups = new ShufflingGroupCollection(); for ($i = 0; $i < $c; $i++) { $marshaller = $this->getMarshallerFactory()->createMarshaller($shufflingGroupElts[$i]); $shufflingGroups[] = $marshaller->unmarshall($shufflingGroupElts[$i]); } return new Shuffling($responseIdentifier, $shufflingGroups); } } else { $msg = "The mandatory attribute 'responseIdentifier' is missing from element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element); } }
php
protected function unmarshall(DOMElement $element) { if (($responseIdentifier = $this->getDOMElementAttributeAs($element, 'responseIdentifier')) !== null) { $shufflingGroupElts = self::getChildElements($element, 'shufflingGroup'); if (($c = count($shufflingGroupElts)) === 0) { $msg = "A 'shuffling' element must contain at least 1 'shufflingGroup' element. None given."; throw new UnmarshallingException($msg, $element); } else if ($c > 2) { $msg = "A 'shuffling' element must contain at most 2 'shufflingGroup' elements. ${c} given."; throw new UnmarshallingException($msg, $element); } else { $shufflingGroups = new ShufflingGroupCollection(); for ($i = 0; $i < $c; $i++) { $marshaller = $this->getMarshallerFactory()->createMarshaller($shufflingGroupElts[$i]); $shufflingGroups[] = $marshaller->unmarshall($shufflingGroupElts[$i]); } return new Shuffling($responseIdentifier, $shufflingGroups); } } else { $msg = "The mandatory attribute 'responseIdentifier' is missing from element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element); } }
[ "protected", "function", "unmarshall", "(", "DOMElement", "$", "element", ")", "{", "if", "(", "(", "$", "responseIdentifier", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'responseIdentifier'", ")", ")", "!==", "null", ")", "{", "$", "shufflingGroupElts", "=", "self", "::", "getChildElements", "(", "$", "element", ",", "'shufflingGroup'", ")", ";", "if", "(", "(", "$", "c", "=", "count", "(", "$", "shufflingGroupElts", ")", ")", "===", "0", ")", "{", "$", "msg", "=", "\"A 'shuffling' element must contain at least 1 'shufflingGroup' element. None given.\"", ";", "throw", "new", "UnmarshallingException", "(", "$", "msg", ",", "$", "element", ")", ";", "}", "else", "if", "(", "$", "c", ">", "2", ")", "{", "$", "msg", "=", "\"A 'shuffling' element must contain at most 2 'shufflingGroup' elements. ${c} given.\"", ";", "throw", "new", "UnmarshallingException", "(", "$", "msg", ",", "$", "element", ")", ";", "}", "else", "{", "$", "shufflingGroups", "=", "new", "ShufflingGroupCollection", "(", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "c", ";", "$", "i", "++", ")", "{", "$", "marshaller", "=", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "shufflingGroupElts", "[", "$", "i", "]", ")", ";", "$", "shufflingGroups", "[", "]", "=", "$", "marshaller", "->", "unmarshall", "(", "$", "shufflingGroupElts", "[", "$", "i", "]", ")", ";", "}", "return", "new", "Shuffling", "(", "$", "responseIdentifier", ",", "$", "shufflingGroups", ")", ";", "}", "}", "else", "{", "$", "msg", "=", "\"The mandatory attribute 'responseIdentifier' is missing from element '\"", ".", "$", "element", "->", "localName", ".", "\"'.\"", ";", "throw", "new", "UnmarshallingException", "(", "$", "msg", ",", "$", "element", ")", ";", "}", "}" ]
Unmarshall a DOMElement object corresponding to a QTI ShufflingGroup element. @param \DOMElement $element A DOMElement object. @return \qtism\data\QtiComponent A ShufflingGroup object. @throws \qtism\data\storage\xml\marshalling\UnmarshallingException
[ "Unmarshall", "a", "DOMElement", "object", "corresponding", "to", "a", "QTI", "ShufflingGroup", "element", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/ShufflingMarshaller.php#L65-L91
oat-sa/qti-sdk
src/qtism/runtime/expressions/operators/GcdProcessor.php
GcdProcessor.process
public function process() { $operands = $this->getOperands(); if ($operands->containsNull() === true) { return null; } if ($operands->anythingButRecord() === false) { $msg = "The Gcd operator only accepts operands with a cardinality of single, multiple or ordered."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY); } if ($operands->exclusivelyInteger() === false) { $msg = "The Gcd operator only accepts operands with an integer baseType."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE); } // Make a flat collection first. $flatCollection = new OperandsCollection(); $zeroCount = 0; $valueCount = 0; foreach ($operands as $operand) { if ($operand instanceof QtiScalar) { $valueCount++; if ($operand->getValue() !== 0) { $flatCollection[] = $operand; } else { $zeroCount++; } } elseif ($operand->contains(null)) { // Container with at least one null value inside. // -> If any of the sub-expressions is null or not numeric, returns null. return null; } else { // Container with no null values. foreach ($operand as $o) { $valueCount++; if ($o->getValue() !== 0) { $flatCollection[] = $o; } else { $zeroCount++; } } } } if ($zeroCount === $valueCount) { // All arguments of gcd() are 0. return new QtiInteger(0); } else { $g = $flatCollection[0]; $loopLimit = count($flatCollection) - 1; $i = 0; while ($i < $loopLimit) { $g = new QtiInteger(Utils::gcd($g->getValue(), $flatCollection[$i + 1]->getValue())); $i++; } return $g; } }
php
public function process() { $operands = $this->getOperands(); if ($operands->containsNull() === true) { return null; } if ($operands->anythingButRecord() === false) { $msg = "The Gcd operator only accepts operands with a cardinality of single, multiple or ordered."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY); } if ($operands->exclusivelyInteger() === false) { $msg = "The Gcd operator only accepts operands with an integer baseType."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE); } // Make a flat collection first. $flatCollection = new OperandsCollection(); $zeroCount = 0; $valueCount = 0; foreach ($operands as $operand) { if ($operand instanceof QtiScalar) { $valueCount++; if ($operand->getValue() !== 0) { $flatCollection[] = $operand; } else { $zeroCount++; } } elseif ($operand->contains(null)) { // Container with at least one null value inside. // -> If any of the sub-expressions is null or not numeric, returns null. return null; } else { // Container with no null values. foreach ($operand as $o) { $valueCount++; if ($o->getValue() !== 0) { $flatCollection[] = $o; } else { $zeroCount++; } } } } if ($zeroCount === $valueCount) { // All arguments of gcd() are 0. return new QtiInteger(0); } else { $g = $flatCollection[0]; $loopLimit = count($flatCollection) - 1; $i = 0; while ($i < $loopLimit) { $g = new QtiInteger(Utils::gcd($g->getValue(), $flatCollection[$i + 1]->getValue())); $i++; } return $g; } }
[ "public", "function", "process", "(", ")", "{", "$", "operands", "=", "$", "this", "->", "getOperands", "(", ")", ";", "if", "(", "$", "operands", "->", "containsNull", "(", ")", "===", "true", ")", "{", "return", "null", ";", "}", "if", "(", "$", "operands", "->", "anythingButRecord", "(", ")", "===", "false", ")", "{", "$", "msg", "=", "\"The Gcd operator only accepts operands with a cardinality of single, multiple or ordered.\"", ";", "throw", "new", "OperatorProcessingException", "(", "$", "msg", ",", "$", "this", ",", "OperatorProcessingException", "::", "WRONG_CARDINALITY", ")", ";", "}", "if", "(", "$", "operands", "->", "exclusivelyInteger", "(", ")", "===", "false", ")", "{", "$", "msg", "=", "\"The Gcd operator only accepts operands with an integer baseType.\"", ";", "throw", "new", "OperatorProcessingException", "(", "$", "msg", ",", "$", "this", ",", "OperatorProcessingException", "::", "WRONG_BASETYPE", ")", ";", "}", "// Make a flat collection first.", "$", "flatCollection", "=", "new", "OperandsCollection", "(", ")", ";", "$", "zeroCount", "=", "0", ";", "$", "valueCount", "=", "0", ";", "foreach", "(", "$", "operands", "as", "$", "operand", ")", "{", "if", "(", "$", "operand", "instanceof", "QtiScalar", ")", "{", "$", "valueCount", "++", ";", "if", "(", "$", "operand", "->", "getValue", "(", ")", "!==", "0", ")", "{", "$", "flatCollection", "[", "]", "=", "$", "operand", ";", "}", "else", "{", "$", "zeroCount", "++", ";", "}", "}", "elseif", "(", "$", "operand", "->", "contains", "(", "null", ")", ")", "{", "// Container with at least one null value inside.", "// -> If any of the sub-expressions is null or not numeric, returns null.", "return", "null", ";", "}", "else", "{", "// Container with no null values.", "foreach", "(", "$", "operand", "as", "$", "o", ")", "{", "$", "valueCount", "++", ";", "if", "(", "$", "o", "->", "getValue", "(", ")", "!==", "0", ")", "{", "$", "flatCollection", "[", "]", "=", "$", "o", ";", "}", "else", "{", "$", "zeroCount", "++", ";", "}", "}", "}", "}", "if", "(", "$", "zeroCount", "===", "$", "valueCount", ")", "{", "// All arguments of gcd() are 0.", "return", "new", "QtiInteger", "(", "0", ")", ";", "}", "else", "{", "$", "g", "=", "$", "flatCollection", "[", "0", "]", ";", "$", "loopLimit", "=", "count", "(", "$", "flatCollection", ")", "-", "1", ";", "$", "i", "=", "0", ";", "while", "(", "$", "i", "<", "$", "loopLimit", ")", "{", "$", "g", "=", "new", "QtiInteger", "(", "Utils", "::", "gcd", "(", "$", "g", "->", "getValue", "(", ")", ",", "$", "flatCollection", "[", "$", "i", "+", "1", "]", "->", "getValue", "(", ")", ")", ")", ";", "$", "i", "++", ";", "}", "return", "$", "g", ";", "}", "}" ]
Process the Gcd operator. @return integer The integer value equal in value to the greatest common divisor of the sub-expressions. If any of the sub-expressions is NULL, the result is NULL. @throws \qtism\runtime\expressions\operators\OperatorProcessingException
[ "Process", "the", "Gcd", "operator", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/GcdProcessor.php#L59-L124
oat-sa/qti-sdk
src/qtism/data/storage/xml/marshalling/InterpolationTableMarshaller.php
InterpolationTableMarshaller.marshall
protected function marshall(QtiComponent $component) { $element = static::getDOMCradle()->createElement($component->getQtiClassName()); foreach ($component->getInterpolationTableEntries() as $interpolationTableEntry) { $marshaller = $this->getMarshallerFactory()->createMarshaller($interpolationTableEntry, array($this->getBaseType())); $element->appendChild($marshaller->marshall($interpolationTableEntry)); } if ($component->getDefaultValue() !== null) { $this->setDOMElementAttribute($element, 'defaultValue', $component->getDefaultValue()); } return $element; }
php
protected function marshall(QtiComponent $component) { $element = static::getDOMCradle()->createElement($component->getQtiClassName()); foreach ($component->getInterpolationTableEntries() as $interpolationTableEntry) { $marshaller = $this->getMarshallerFactory()->createMarshaller($interpolationTableEntry, array($this->getBaseType())); $element->appendChild($marshaller->marshall($interpolationTableEntry)); } if ($component->getDefaultValue() !== null) { $this->setDOMElementAttribute($element, 'defaultValue', $component->getDefaultValue()); } return $element; }
[ "protected", "function", "marshall", "(", "QtiComponent", "$", "component", ")", "{", "$", "element", "=", "static", "::", "getDOMCradle", "(", ")", "->", "createElement", "(", "$", "component", "->", "getQtiClassName", "(", ")", ")", ";", "foreach", "(", "$", "component", "->", "getInterpolationTableEntries", "(", ")", "as", "$", "interpolationTableEntry", ")", "{", "$", "marshaller", "=", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "interpolationTableEntry", ",", "array", "(", "$", "this", "->", "getBaseType", "(", ")", ")", ")", ";", "$", "element", "->", "appendChild", "(", "$", "marshaller", "->", "marshall", "(", "$", "interpolationTableEntry", ")", ")", ";", "}", "if", "(", "$", "component", "->", "getDefaultValue", "(", ")", "!==", "null", ")", "{", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'defaultValue'", ",", "$", "component", "->", "getDefaultValue", "(", ")", ")", ";", "}", "return", "$", "element", ";", "}" ]
Marshall an InterpolationTable object into a DOMElement object. @param \qtism\data\QtiComponent $component An InterpolationTable object. @return \DOMElement The according DOMElement object.
[ "Marshall", "an", "InterpolationTable", "object", "into", "a", "DOMElement", "object", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/InterpolationTableMarshaller.php#L98-L111
oat-sa/qti-sdk
src/qtism/data/storage/xml/marshalling/InterpolationTableMarshaller.php
InterpolationTableMarshaller.unmarshall
protected function unmarshall(DOMElement $element) { $interpolationTableEntryElements = $element->getElementsByTagName('interpolationTableEntry'); if ($interpolationTableEntryElements->length > 0) { $interpolationTableEntryCollection = new InterpolationTableEntryCollection(); for ($i = 0; $i < $interpolationTableEntryElements->length; $i++) { $marshaller = $this->getMarshallerFactory()->createMarshaller($interpolationTableEntryElements->item($i), array($this->getBaseType())); $interpolationTableEntryCollection[] = $marshaller->unmarshall($interpolationTableEntryElements->item($i)); } $object = new InterpolationTable($interpolationTableEntryCollection); if (($defaultValue = $this->getDOMElementAttributeAs($element, 'defaultValue')) !== null) { try { $object->setDefaultValue(Utils::stringToDatatype($defaultValue, $this->getBaseType())); } catch (\UnexpectedValueException $e) { $msg = "Unable to transform '${defaultValue}' into float."; throw new UnmarshallingException($msg, $element, $e); } } return $object; } else { $msg = "An 'interpolationTable' element must contain at least one 'interpolationTableEntry' element."; throw new UnmarshallingException($msg, $element); } }
php
protected function unmarshall(DOMElement $element) { $interpolationTableEntryElements = $element->getElementsByTagName('interpolationTableEntry'); if ($interpolationTableEntryElements->length > 0) { $interpolationTableEntryCollection = new InterpolationTableEntryCollection(); for ($i = 0; $i < $interpolationTableEntryElements->length; $i++) { $marshaller = $this->getMarshallerFactory()->createMarshaller($interpolationTableEntryElements->item($i), array($this->getBaseType())); $interpolationTableEntryCollection[] = $marshaller->unmarshall($interpolationTableEntryElements->item($i)); } $object = new InterpolationTable($interpolationTableEntryCollection); if (($defaultValue = $this->getDOMElementAttributeAs($element, 'defaultValue')) !== null) { try { $object->setDefaultValue(Utils::stringToDatatype($defaultValue, $this->getBaseType())); } catch (\UnexpectedValueException $e) { $msg = "Unable to transform '${defaultValue}' into float."; throw new UnmarshallingException($msg, $element, $e); } } return $object; } else { $msg = "An 'interpolationTable' element must contain at least one 'interpolationTableEntry' element."; throw new UnmarshallingException($msg, $element); } }
[ "protected", "function", "unmarshall", "(", "DOMElement", "$", "element", ")", "{", "$", "interpolationTableEntryElements", "=", "$", "element", "->", "getElementsByTagName", "(", "'interpolationTableEntry'", ")", ";", "if", "(", "$", "interpolationTableEntryElements", "->", "length", ">", "0", ")", "{", "$", "interpolationTableEntryCollection", "=", "new", "InterpolationTableEntryCollection", "(", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "interpolationTableEntryElements", "->", "length", ";", "$", "i", "++", ")", "{", "$", "marshaller", "=", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "interpolationTableEntryElements", "->", "item", "(", "$", "i", ")", ",", "array", "(", "$", "this", "->", "getBaseType", "(", ")", ")", ")", ";", "$", "interpolationTableEntryCollection", "[", "]", "=", "$", "marshaller", "->", "unmarshall", "(", "$", "interpolationTableEntryElements", "->", "item", "(", "$", "i", ")", ")", ";", "}", "$", "object", "=", "new", "InterpolationTable", "(", "$", "interpolationTableEntryCollection", ")", ";", "if", "(", "(", "$", "defaultValue", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'defaultValue'", ")", ")", "!==", "null", ")", "{", "try", "{", "$", "object", "->", "setDefaultValue", "(", "Utils", "::", "stringToDatatype", "(", "$", "defaultValue", ",", "$", "this", "->", "getBaseType", "(", ")", ")", ")", ";", "}", "catch", "(", "\\", "UnexpectedValueException", "$", "e", ")", "{", "$", "msg", "=", "\"Unable to transform '${defaultValue}' into float.\"", ";", "throw", "new", "UnmarshallingException", "(", "$", "msg", ",", "$", "element", ",", "$", "e", ")", ";", "}", "}", "return", "$", "object", ";", "}", "else", "{", "$", "msg", "=", "\"An 'interpolationTable' element must contain at least one 'interpolationTableEntry' element.\"", ";", "throw", "new", "UnmarshallingException", "(", "$", "msg", ",", "$", "element", ")", ";", "}", "}" ]
Unmarshall a DOMElement object corresponding to a QTI InterpolationTable element. @param \DOMElement $element A DOMElement object. @return \qtism\data\QtiComponent An InterpolationTable object. @throws \qtism\data\storage\xml\marshalling\UnmarshallingException If $element does not contain any interpolationTableEntry QTI elements.
[ "Unmarshall", "a", "DOMElement", "object", "corresponding", "to", "a", "QTI", "InterpolationTable", "element", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/InterpolationTableMarshaller.php#L120-L147
oat-sa/qti-sdk
src/qtism/runtime/pci/json/Marshaller.php
Marshaller.marshall
public function marshall($data, $output = Marshaller::MARSHALL_JSON) { if (is_null($data) === true) { $json = array('base' => $data); } elseif ($data instanceof State) { $json = array(); foreach ($data as $variable) { $json[$variable->getIdentifier()] = $this->marshallUnit($variable->getValue()); } } elseif ($data instanceof QtiDatatype) { $json = $this->marshallUnit($data); } else { $className = get_class($this); $msg = "The '${className}::marshall' method only takes State, QtiDatatype and null values as arguments, '"; if (is_object($data) === true) { $msg .= get_class($data); } else { $msg .= gettype($data); } $msg .= "' given."; $code = MarshallingException::NOT_SUPPORTED; throw new MarshallingException($msg, $code); } return ($output === self::MARSHALL_JSON) ? json_encode($json) : $json; }
php
public function marshall($data, $output = Marshaller::MARSHALL_JSON) { if (is_null($data) === true) { $json = array('base' => $data); } elseif ($data instanceof State) { $json = array(); foreach ($data as $variable) { $json[$variable->getIdentifier()] = $this->marshallUnit($variable->getValue()); } } elseif ($data instanceof QtiDatatype) { $json = $this->marshallUnit($data); } else { $className = get_class($this); $msg = "The '${className}::marshall' method only takes State, QtiDatatype and null values as arguments, '"; if (is_object($data) === true) { $msg .= get_class($data); } else { $msg .= gettype($data); } $msg .= "' given."; $code = MarshallingException::NOT_SUPPORTED; throw new MarshallingException($msg, $code); } return ($output === self::MARSHALL_JSON) ? json_encode($json) : $json; }
[ "public", "function", "marshall", "(", "$", "data", ",", "$", "output", "=", "Marshaller", "::", "MARSHALL_JSON", ")", "{", "if", "(", "is_null", "(", "$", "data", ")", "===", "true", ")", "{", "$", "json", "=", "array", "(", "'base'", "=>", "$", "data", ")", ";", "}", "elseif", "(", "$", "data", "instanceof", "State", ")", "{", "$", "json", "=", "array", "(", ")", ";", "foreach", "(", "$", "data", "as", "$", "variable", ")", "{", "$", "json", "[", "$", "variable", "->", "getIdentifier", "(", ")", "]", "=", "$", "this", "->", "marshallUnit", "(", "$", "variable", "->", "getValue", "(", ")", ")", ";", "}", "}", "elseif", "(", "$", "data", "instanceof", "QtiDatatype", ")", "{", "$", "json", "=", "$", "this", "->", "marshallUnit", "(", "$", "data", ")", ";", "}", "else", "{", "$", "className", "=", "get_class", "(", "$", "this", ")", ";", "$", "msg", "=", "\"The '${className}::marshall' method only takes State, QtiDatatype and null values as arguments, '\"", ";", "if", "(", "is_object", "(", "$", "data", ")", "===", "true", ")", "{", "$", "msg", ".=", "get_class", "(", "$", "data", ")", ";", "}", "else", "{", "$", "msg", ".=", "gettype", "(", "$", "data", ")", ";", "}", "$", "msg", ".=", "\"' given.\"", ";", "$", "code", "=", "MarshallingException", "::", "NOT_SUPPORTED", ";", "throw", "new", "MarshallingException", "(", "$", "msg", ",", "$", "code", ")", ";", "}", "return", "(", "$", "output", "===", "self", "::", "MARSHALL_JSON", ")", "?", "json_encode", "(", "$", "json", ")", ":", "$", "json", ";", "}" ]
Marshall some QTI data into JSON. @param \qtism\runtime\common\State|\qtism\common\datatypes\QtiDatatype|null $data The data to be marshalled into JSON. @param integer How the output will be returned (see class constants). Default is plain JSON string. @return string|array The JSONified data. @throws \InvalidArgumentException If $data has not a compliant type. @throws \qtism\runtime\pci\json\MarshallingException If an error occurs while marshalling $data into JSON.
[ "Marshall", "some", "QTI", "data", "into", "JSON", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/pci/json/Marshaller.php#L89-L118
oat-sa/qti-sdk
src/qtism/runtime/pci/json/Marshaller.php
Marshaller.marshallUnit
protected function marshallUnit($unit) { if (is_null($unit) === true) { $json = array('base' => null); } elseif ($unit instanceof QtiScalar) { $json = $this->marshallScalar($unit); } elseif ($unit instanceof MultipleContainer) { $json = array(); $strBaseType = BaseType::getNameByConstant($unit->getBaseType()); $json['list'] = array($strBaseType => array()); foreach ($unit as $u) { $data = $this->marshallUnit($u); $json['list'][$strBaseType][] = $data['base'][$strBaseType]; } } elseif ($unit instanceof RecordContainer) { $json = array(); $json['record'] = array(); foreach ($unit as $k => $u) { $data = $this->marshallUnit($u); $jsonEntry = array(); $jsonEntry['name'] = $k; if (array_key_exists('base', $data) === true) { // Primitive base type. $jsonEntry['base'] = $data['base']; } else { // A nested list. $jsonEntry['list'] = $data['list']; } $json['record'][] = $jsonEntry; } } else { $json = $this->marshallComplex($unit); } return $json; }
php
protected function marshallUnit($unit) { if (is_null($unit) === true) { $json = array('base' => null); } elseif ($unit instanceof QtiScalar) { $json = $this->marshallScalar($unit); } elseif ($unit instanceof MultipleContainer) { $json = array(); $strBaseType = BaseType::getNameByConstant($unit->getBaseType()); $json['list'] = array($strBaseType => array()); foreach ($unit as $u) { $data = $this->marshallUnit($u); $json['list'][$strBaseType][] = $data['base'][$strBaseType]; } } elseif ($unit instanceof RecordContainer) { $json = array(); $json['record'] = array(); foreach ($unit as $k => $u) { $data = $this->marshallUnit($u); $jsonEntry = array(); $jsonEntry['name'] = $k; if (array_key_exists('base', $data) === true) { // Primitive base type. $jsonEntry['base'] = $data['base']; } else { // A nested list. $jsonEntry['list'] = $data['list']; } $json['record'][] = $jsonEntry; } } else { $json = $this->marshallComplex($unit); } return $json; }
[ "protected", "function", "marshallUnit", "(", "$", "unit", ")", "{", "if", "(", "is_null", "(", "$", "unit", ")", "===", "true", ")", "{", "$", "json", "=", "array", "(", "'base'", "=>", "null", ")", ";", "}", "elseif", "(", "$", "unit", "instanceof", "QtiScalar", ")", "{", "$", "json", "=", "$", "this", "->", "marshallScalar", "(", "$", "unit", ")", ";", "}", "elseif", "(", "$", "unit", "instanceof", "MultipleContainer", ")", "{", "$", "json", "=", "array", "(", ")", ";", "$", "strBaseType", "=", "BaseType", "::", "getNameByConstant", "(", "$", "unit", "->", "getBaseType", "(", ")", ")", ";", "$", "json", "[", "'list'", "]", "=", "array", "(", "$", "strBaseType", "=>", "array", "(", ")", ")", ";", "foreach", "(", "$", "unit", "as", "$", "u", ")", "{", "$", "data", "=", "$", "this", "->", "marshallUnit", "(", "$", "u", ")", ";", "$", "json", "[", "'list'", "]", "[", "$", "strBaseType", "]", "[", "]", "=", "$", "data", "[", "'base'", "]", "[", "$", "strBaseType", "]", ";", "}", "}", "elseif", "(", "$", "unit", "instanceof", "RecordContainer", ")", "{", "$", "json", "=", "array", "(", ")", ";", "$", "json", "[", "'record'", "]", "=", "array", "(", ")", ";", "foreach", "(", "$", "unit", "as", "$", "k", "=>", "$", "u", ")", "{", "$", "data", "=", "$", "this", "->", "marshallUnit", "(", "$", "u", ")", ";", "$", "jsonEntry", "=", "array", "(", ")", ";", "$", "jsonEntry", "[", "'name'", "]", "=", "$", "k", ";", "if", "(", "array_key_exists", "(", "'base'", ",", "$", "data", ")", "===", "true", ")", "{", "// Primitive base type.", "$", "jsonEntry", "[", "'base'", "]", "=", "$", "data", "[", "'base'", "]", ";", "}", "else", "{", "// A nested list.", "$", "jsonEntry", "[", "'list'", "]", "=", "$", "data", "[", "'list'", "]", ";", "}", "$", "json", "[", "'record'", "]", "[", "]", "=", "$", "jsonEntry", ";", "}", "}", "else", "{", "$", "json", "=", "$", "this", "->", "marshallComplex", "(", "$", "unit", ")", ";", "}", "return", "$", "json", ";", "}" ]
Marshall a single unit of QTI data. @param \qtism\runtime\common\State|\qtism\common\datatypes\QtiDatatype|null $unit @return array An array representing the JSON data to be encoded later on.
[ "Marshall", "a", "single", "unit", "of", "QTI", "data", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/pci/json/Marshaller.php#L126-L165
oat-sa/qti-sdk
src/qtism/runtime/pci/json/Marshaller.php
Marshaller.marshallScalar
protected function marshallScalar($scalar) { if ($scalar instanceof QtiBoolean) { return $this->marshallBoolean($scalar); } elseif ($scalar instanceof QtiInteger) { return $this->marshallInteger($scalar); } elseif ($scalar instanceof QtiFloat) { return $this->marshallFloat($scalar); } elseif ($scalar instanceof QtiIdentifier) { return $this->marshallIdentifier($scalar); } elseif ($scalar instanceof QtiUri) { return $this->marshallUri($scalar); } elseif ($scalar instanceof QtiString) { return $this->marshallString($scalar); } elseif ($scalar instanceof QtiIntOrIdentifier) { return $this->marshallIntOrIdentifier($scalar); } }
php
protected function marshallScalar($scalar) { if ($scalar instanceof QtiBoolean) { return $this->marshallBoolean($scalar); } elseif ($scalar instanceof QtiInteger) { return $this->marshallInteger($scalar); } elseif ($scalar instanceof QtiFloat) { return $this->marshallFloat($scalar); } elseif ($scalar instanceof QtiIdentifier) { return $this->marshallIdentifier($scalar); } elseif ($scalar instanceof QtiUri) { return $this->marshallUri($scalar); } elseif ($scalar instanceof QtiString) { return $this->marshallString($scalar); } elseif ($scalar instanceof QtiIntOrIdentifier) { return $this->marshallIntOrIdentifier($scalar); } }
[ "protected", "function", "marshallScalar", "(", "$", "scalar", ")", "{", "if", "(", "$", "scalar", "instanceof", "QtiBoolean", ")", "{", "return", "$", "this", "->", "marshallBoolean", "(", "$", "scalar", ")", ";", "}", "elseif", "(", "$", "scalar", "instanceof", "QtiInteger", ")", "{", "return", "$", "this", "->", "marshallInteger", "(", "$", "scalar", ")", ";", "}", "elseif", "(", "$", "scalar", "instanceof", "QtiFloat", ")", "{", "return", "$", "this", "->", "marshallFloat", "(", "$", "scalar", ")", ";", "}", "elseif", "(", "$", "scalar", "instanceof", "QtiIdentifier", ")", "{", "return", "$", "this", "->", "marshallIdentifier", "(", "$", "scalar", ")", ";", "}", "elseif", "(", "$", "scalar", "instanceof", "QtiUri", ")", "{", "return", "$", "this", "->", "marshallUri", "(", "$", "scalar", ")", ";", "}", "elseif", "(", "$", "scalar", "instanceof", "QtiString", ")", "{", "return", "$", "this", "->", "marshallString", "(", "$", "scalar", ")", ";", "}", "elseif", "(", "$", "scalar", "instanceof", "QtiIntOrIdentifier", ")", "{", "return", "$", "this", "->", "marshallIntOrIdentifier", "(", "$", "scalar", ")", ";", "}", "}" ]
Marshall a single scalar data into a PHP datatype (that can be transformed easilly in JSON later on). @param null|\qtism\common\datatypes\QtiDatatype $scalar A scalar to be transformed into a PHP datatype for later JSON encoding. @return array An array representing the JSON data to be encoded later on. @throws \qtism\runtime\pci\json\MarshallingException
[ "Marshall", "a", "single", "scalar", "data", "into", "a", "PHP", "datatype", "(", "that", "can", "be", "transformed", "easilly", "in", "JSON", "later", "on", ")", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/pci/json/Marshaller.php#L175-L192
oat-sa/qti-sdk
src/qtism/runtime/pci/json/Marshaller.php
Marshaller.marshallComplex
protected function marshallComplex(QtiDatatype $complex) { if ($complex instanceof QtiPoint) { return $this->marshallPoint($complex); } elseif ($complex instanceof QtiDirectedPair) { return $this->marshallDirectedPair($complex); } elseif ($complex instanceof QtiPair) { return $this->marshallPair($complex); } elseif ($complex instanceof QtiDuration) { return $this->marshallDuration($complex); } elseif ($complex instanceof QtiFile) { return $this->marshallFile($complex); } }
php
protected function marshallComplex(QtiDatatype $complex) { if ($complex instanceof QtiPoint) { return $this->marshallPoint($complex); } elseif ($complex instanceof QtiDirectedPair) { return $this->marshallDirectedPair($complex); } elseif ($complex instanceof QtiPair) { return $this->marshallPair($complex); } elseif ($complex instanceof QtiDuration) { return $this->marshallDuration($complex); } elseif ($complex instanceof QtiFile) { return $this->marshallFile($complex); } }
[ "protected", "function", "marshallComplex", "(", "QtiDatatype", "$", "complex", ")", "{", "if", "(", "$", "complex", "instanceof", "QtiPoint", ")", "{", "return", "$", "this", "->", "marshallPoint", "(", "$", "complex", ")", ";", "}", "elseif", "(", "$", "complex", "instanceof", "QtiDirectedPair", ")", "{", "return", "$", "this", "->", "marshallDirectedPair", "(", "$", "complex", ")", ";", "}", "elseif", "(", "$", "complex", "instanceof", "QtiPair", ")", "{", "return", "$", "this", "->", "marshallPair", "(", "$", "complex", ")", ";", "}", "elseif", "(", "$", "complex", "instanceof", "QtiDuration", ")", "{", "return", "$", "this", "->", "marshallDuration", "(", "$", "complex", ")", ";", "}", "elseif", "(", "$", "complex", "instanceof", "QtiFile", ")", "{", "return", "$", "this", "->", "marshallFile", "(", "$", "complex", ")", ";", "}", "}" ]
Marshall a single complex QtiDataType object. @param \qtism\common\datatypes\QtiDatatype $complex @throws \qtism\runtime\pci\json\MarshallingException @return array An array representing the JSON data to be encoded later on.
[ "Marshall", "a", "single", "complex", "QtiDataType", "object", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/pci/json/Marshaller.php#L201-L214
oat-sa/qti-sdk
src/qtism/runtime/pci/json/Marshaller.php
Marshaller.marshallFile
protected function marshallFile(QtiFile $file) { $data = array('base' => array('file' => array('mime' => $file->getMimeType(), 'data' => base64_encode($file->getData())))); if ($file->hasFilename() === true) { $data['base']['file']['name'] = $file->getFilename(); } return $data; }
php
protected function marshallFile(QtiFile $file) { $data = array('base' => array('file' => array('mime' => $file->getMimeType(), 'data' => base64_encode($file->getData())))); if ($file->hasFilename() === true) { $data['base']['file']['name'] = $file->getFilename(); } return $data; }
[ "protected", "function", "marshallFile", "(", "QtiFile", "$", "file", ")", "{", "$", "data", "=", "array", "(", "'base'", "=>", "array", "(", "'file'", "=>", "array", "(", "'mime'", "=>", "$", "file", "->", "getMimeType", "(", ")", ",", "'data'", "=>", "base64_encode", "(", "$", "file", "->", "getData", "(", ")", ")", ")", ")", ")", ";", "if", "(", "$", "file", "->", "hasFilename", "(", ")", "===", "true", ")", "{", "$", "data", "[", "'base'", "]", "[", "'file'", "]", "[", "'name'", "]", "=", "$", "file", "->", "getFilename", "(", ")", ";", "}", "return", "$", "data", ";", "}" ]
Marshall a QTI file datatype into its PCI JSON Representation. @param \qtism\common\datatypes\File $file @return array
[ "Marshall", "a", "QTI", "file", "datatype", "into", "its", "PCI", "JSON", "Representation", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/pci/json/Marshaller.php#L343-L352
oat-sa/qti-sdk
src/qtism/runtime/expressions/MapResponsePointProcessor.php
MapResponsePointProcessor.process
public function process() { $expr = $this->getExpression(); $identifier = $expr->getIdentifier(); $state = $this->getState(); $var = $state->getVariable($identifier); if (!is_null($var)) { if ($var instanceof ResponseVariable) { $areaMapping = $var->getAreaMapping(); if (is_null($areaMapping)) { return new QtiFloat(0.0); } // Correct cardinality ? if ($var->getBaseType() === BaseType::POINT && ($var->isSingle() || $var->isMultiple())) { // We can begin! // -- Null value, nothing will match if ($var->isNull()) { return new QtiFloat($areaMapping->getDefaultValue()); } if ($var->isSingle()) { $val = new MultipleContainer(BaseType::POINT, array($state[$identifier])); } else { $val = $state[$identifier]; } $result = 0; $mapped = array(); foreach ($val as $point) { foreach ($areaMapping->getAreaMapEntries() as $areaMapEntry) { $coords = $areaMapEntry->getCoords(); if (!in_array($coords, $mapped) && $coords->inside($point)) { $mapped[] = $coords; $result += $areaMapEntry->getMappedValue(); } } } // If no relevant mapping found, return the default. if (count($mapped) === 0) { return new QtiFloat($areaMapping->getDefaultValue()); } else { // Check upper and lower bound. if ($areaMapping->hasLowerBound() && $result < $areaMapping->getLowerBound()) { return new QtiFloat($areaMapping->getLowerBound()); } elseif ($areaMapping->hasUpperBound() && $result > $areaMapping->getUpperBound()) { return new QtiFloat($areaMapping->getUpperBound()); } else { return new QtiFloat(floatval($result)); } } } else { if ($var->isRecord()) { $msg = "The MapResponsePoint expression cannot be applied to RECORD variables."; throw new ExpressionProcessingException($msg, $this, ExpressionProcessingException::WRONG_VARIABLE_CARDINALITY); } else { $strBaseType = BaseType::getNameByConstant($var->getBaseType()); $msg = "The MapResponsePoint expression applies only on variables with baseType 'point', baseType '${strBaseType}' given."; throw new ExpressionProcessingException($msg, $this, ExpressionProcessingException::WRONG_VARIABLE_BASETYPE); } } } else { $msg = "The variable with identifier '${identifier}' is not a ResponseVariable."; throw new ExpressionProcessingException($msg, $this, ExpressionProcessingException::WRONG_VARIABLE_TYPE); } } else { $msg = "No variable with identifier '${identifier}' could be found in the current State object."; throw new ExpressionProcessingException($msg, $this, ExpressionProcessingException::NONEXISTENT_VARIABLE); } }
php
public function process() { $expr = $this->getExpression(); $identifier = $expr->getIdentifier(); $state = $this->getState(); $var = $state->getVariable($identifier); if (!is_null($var)) { if ($var instanceof ResponseVariable) { $areaMapping = $var->getAreaMapping(); if (is_null($areaMapping)) { return new QtiFloat(0.0); } // Correct cardinality ? if ($var->getBaseType() === BaseType::POINT && ($var->isSingle() || $var->isMultiple())) { // We can begin! // -- Null value, nothing will match if ($var->isNull()) { return new QtiFloat($areaMapping->getDefaultValue()); } if ($var->isSingle()) { $val = new MultipleContainer(BaseType::POINT, array($state[$identifier])); } else { $val = $state[$identifier]; } $result = 0; $mapped = array(); foreach ($val as $point) { foreach ($areaMapping->getAreaMapEntries() as $areaMapEntry) { $coords = $areaMapEntry->getCoords(); if (!in_array($coords, $mapped) && $coords->inside($point)) { $mapped[] = $coords; $result += $areaMapEntry->getMappedValue(); } } } // If no relevant mapping found, return the default. if (count($mapped) === 0) { return new QtiFloat($areaMapping->getDefaultValue()); } else { // Check upper and lower bound. if ($areaMapping->hasLowerBound() && $result < $areaMapping->getLowerBound()) { return new QtiFloat($areaMapping->getLowerBound()); } elseif ($areaMapping->hasUpperBound() && $result > $areaMapping->getUpperBound()) { return new QtiFloat($areaMapping->getUpperBound()); } else { return new QtiFloat(floatval($result)); } } } else { if ($var->isRecord()) { $msg = "The MapResponsePoint expression cannot be applied to RECORD variables."; throw new ExpressionProcessingException($msg, $this, ExpressionProcessingException::WRONG_VARIABLE_CARDINALITY); } else { $strBaseType = BaseType::getNameByConstant($var->getBaseType()); $msg = "The MapResponsePoint expression applies only on variables with baseType 'point', baseType '${strBaseType}' given."; throw new ExpressionProcessingException($msg, $this, ExpressionProcessingException::WRONG_VARIABLE_BASETYPE); } } } else { $msg = "The variable with identifier '${identifier}' is not a ResponseVariable."; throw new ExpressionProcessingException($msg, $this, ExpressionProcessingException::WRONG_VARIABLE_TYPE); } } else { $msg = "No variable with identifier '${identifier}' could be found in the current State object."; throw new ExpressionProcessingException($msg, $this, ExpressionProcessingException::NONEXISTENT_VARIABLE); } }
[ "public", "function", "process", "(", ")", "{", "$", "expr", "=", "$", "this", "->", "getExpression", "(", ")", ";", "$", "identifier", "=", "$", "expr", "->", "getIdentifier", "(", ")", ";", "$", "state", "=", "$", "this", "->", "getState", "(", ")", ";", "$", "var", "=", "$", "state", "->", "getVariable", "(", "$", "identifier", ")", ";", "if", "(", "!", "is_null", "(", "$", "var", ")", ")", "{", "if", "(", "$", "var", "instanceof", "ResponseVariable", ")", "{", "$", "areaMapping", "=", "$", "var", "->", "getAreaMapping", "(", ")", ";", "if", "(", "is_null", "(", "$", "areaMapping", ")", ")", "{", "return", "new", "QtiFloat", "(", "0.0", ")", ";", "}", "// Correct cardinality ?", "if", "(", "$", "var", "->", "getBaseType", "(", ")", "===", "BaseType", "::", "POINT", "&&", "(", "$", "var", "->", "isSingle", "(", ")", "||", "$", "var", "->", "isMultiple", "(", ")", ")", ")", "{", "// We can begin!", "// -- Null value, nothing will match", "if", "(", "$", "var", "->", "isNull", "(", ")", ")", "{", "return", "new", "QtiFloat", "(", "$", "areaMapping", "->", "getDefaultValue", "(", ")", ")", ";", "}", "if", "(", "$", "var", "->", "isSingle", "(", ")", ")", "{", "$", "val", "=", "new", "MultipleContainer", "(", "BaseType", "::", "POINT", ",", "array", "(", "$", "state", "[", "$", "identifier", "]", ")", ")", ";", "}", "else", "{", "$", "val", "=", "$", "state", "[", "$", "identifier", "]", ";", "}", "$", "result", "=", "0", ";", "$", "mapped", "=", "array", "(", ")", ";", "foreach", "(", "$", "val", "as", "$", "point", ")", "{", "foreach", "(", "$", "areaMapping", "->", "getAreaMapEntries", "(", ")", "as", "$", "areaMapEntry", ")", "{", "$", "coords", "=", "$", "areaMapEntry", "->", "getCoords", "(", ")", ";", "if", "(", "!", "in_array", "(", "$", "coords", ",", "$", "mapped", ")", "&&", "$", "coords", "->", "inside", "(", "$", "point", ")", ")", "{", "$", "mapped", "[", "]", "=", "$", "coords", ";", "$", "result", "+=", "$", "areaMapEntry", "->", "getMappedValue", "(", ")", ";", "}", "}", "}", "// If no relevant mapping found, return the default.", "if", "(", "count", "(", "$", "mapped", ")", "===", "0", ")", "{", "return", "new", "QtiFloat", "(", "$", "areaMapping", "->", "getDefaultValue", "(", ")", ")", ";", "}", "else", "{", "// Check upper and lower bound.", "if", "(", "$", "areaMapping", "->", "hasLowerBound", "(", ")", "&&", "$", "result", "<", "$", "areaMapping", "->", "getLowerBound", "(", ")", ")", "{", "return", "new", "QtiFloat", "(", "$", "areaMapping", "->", "getLowerBound", "(", ")", ")", ";", "}", "elseif", "(", "$", "areaMapping", "->", "hasUpperBound", "(", ")", "&&", "$", "result", ">", "$", "areaMapping", "->", "getUpperBound", "(", ")", ")", "{", "return", "new", "QtiFloat", "(", "$", "areaMapping", "->", "getUpperBound", "(", ")", ")", ";", "}", "else", "{", "return", "new", "QtiFloat", "(", "floatval", "(", "$", "result", ")", ")", ";", "}", "}", "}", "else", "{", "if", "(", "$", "var", "->", "isRecord", "(", ")", ")", "{", "$", "msg", "=", "\"The MapResponsePoint expression cannot be applied to RECORD variables.\"", ";", "throw", "new", "ExpressionProcessingException", "(", "$", "msg", ",", "$", "this", ",", "ExpressionProcessingException", "::", "WRONG_VARIABLE_CARDINALITY", ")", ";", "}", "else", "{", "$", "strBaseType", "=", "BaseType", "::", "getNameByConstant", "(", "$", "var", "->", "getBaseType", "(", ")", ")", ";", "$", "msg", "=", "\"The MapResponsePoint expression applies only on variables with baseType 'point', baseType '${strBaseType}' given.\"", ";", "throw", "new", "ExpressionProcessingException", "(", "$", "msg", ",", "$", "this", ",", "ExpressionProcessingException", "::", "WRONG_VARIABLE_BASETYPE", ")", ";", "}", "}", "}", "else", "{", "$", "msg", "=", "\"The variable with identifier '${identifier}' is not a ResponseVariable.\"", ";", "throw", "new", "ExpressionProcessingException", "(", "$", "msg", ",", "$", "this", ",", "ExpressionProcessingException", "::", "WRONG_VARIABLE_TYPE", ")", ";", "}", "}", "else", "{", "$", "msg", "=", "\"No variable with identifier '${identifier}' could be found in the current State object.\"", ";", "throw", "new", "ExpressionProcessingException", "(", "$", "msg", ",", "$", "this", ",", "ExpressionProcessingException", "::", "NONEXISTENT_VARIABLE", ")", ";", "}", "}" ]
Process the MapResponsePoint Expression. An ExpressionProcessingException is throw if: * The expression's identifier attribute does not point a variable in the current State object. * The targeted variable is not a ResponseVariable object. * The targeted variable has no areaMapping. * The target variable has the RECORD cardinality. @return float A transformed float value according to the areaMapping of the target variable. @throws \qtism\runtime\expressions\ExpressionProcessingException
[ "Process", "the", "MapResponsePoint", "Expression", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/MapResponsePointProcessor.php#L65-L142
oat-sa/qti-sdk
src/qtism/runtime/rendering/qtipl/expressions/operators/IndexQtiPLRenderer.php
IndexQtiPLRenderer.render
public function render($something) { $renderer = new QtiPLRenderer($this->getCRO()); $attributes = []; $attributes['n'] = $something->getN(); return $something->getQtiClassName() . $renderer->writeAttributes($attributes) . $renderer->writeChildElements($something->getExpressions()); }
php
public function render($something) { $renderer = new QtiPLRenderer($this->getCRO()); $attributes = []; $attributes['n'] = $something->getN(); return $something->getQtiClassName() . $renderer->writeAttributes($attributes) . $renderer->writeChildElements($something->getExpressions()); }
[ "public", "function", "render", "(", "$", "something", ")", "{", "$", "renderer", "=", "new", "QtiPLRenderer", "(", "$", "this", "->", "getCRO", "(", ")", ")", ";", "$", "attributes", "=", "[", "]", ";", "$", "attributes", "[", "'n'", "]", "=", "$", "something", "->", "getN", "(", ")", ";", "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/IndexQtiPLRenderer.php#L46-L54
oat-sa/qti-sdk
src/qtism/runtime/expressions/operators/SubtractProcessor.php
SubtractProcessor.process
public function process() { $operands = $this->getOperands(); if ($operands->containsNull() === true) { return null; } if ($operands->exclusivelySingle() === false) { $msg = "The Subtract operator only accepts operands with a single cardinality"; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY); } if ($operands->exclusivelyNumeric() === false) { $msg = "The Subtract operator only accepts operands with a baseType of integer or float"; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE); } $operand1 = $operands[0]; $operand2 = $operands[1]; $subtract = $operand1->getValue() - $operand2->getValue(); return (is_int($subtract) === true) ? new QtiInteger($subtract) : new QtiFloat($subtract); }
php
public function process() { $operands = $this->getOperands(); if ($operands->containsNull() === true) { return null; } if ($operands->exclusivelySingle() === false) { $msg = "The Subtract operator only accepts operands with a single cardinality"; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY); } if ($operands->exclusivelyNumeric() === false) { $msg = "The Subtract operator only accepts operands with a baseType of integer or float"; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE); } $operand1 = $operands[0]; $operand2 = $operands[1]; $subtract = $operand1->getValue() - $operand2->getValue(); return (is_int($subtract) === true) ? new QtiInteger($subtract) : new QtiFloat($subtract); }
[ "public", "function", "process", "(", ")", "{", "$", "operands", "=", "$", "this", "->", "getOperands", "(", ")", ";", "if", "(", "$", "operands", "->", "containsNull", "(", ")", "===", "true", ")", "{", "return", "null", ";", "}", "if", "(", "$", "operands", "->", "exclusivelySingle", "(", ")", "===", "false", ")", "{", "$", "msg", "=", "\"The Subtract operator only accepts operands with a single cardinality\"", ";", "throw", "new", "OperatorProcessingException", "(", "$", "msg", ",", "$", "this", ",", "OperatorProcessingException", "::", "WRONG_CARDINALITY", ")", ";", "}", "if", "(", "$", "operands", "->", "exclusivelyNumeric", "(", ")", "===", "false", ")", "{", "$", "msg", "=", "\"The Subtract operator only accepts operands with a baseType of integer or float\"", ";", "throw", "new", "OperatorProcessingException", "(", "$", "msg", ",", "$", "this", ",", "OperatorProcessingException", "::", "WRONG_BASETYPE", ")", ";", "}", "$", "operand1", "=", "$", "operands", "[", "0", "]", ";", "$", "operand2", "=", "$", "operands", "[", "1", "]", ";", "$", "subtract", "=", "$", "operand1", "->", "getValue", "(", ")", "-", "$", "operand2", "->", "getValue", "(", ")", ";", "return", "(", "is_int", "(", "$", "subtract", ")", "===", "true", ")", "?", "new", "QtiInteger", "(", "$", "subtract", ")", ":", "new", "QtiFloat", "(", "$", "subtract", ")", ";", "}" ]
Process the Subtract operator. @return float|integer|null A single float or if both sub-expressions are integers, a single integer or NULL if either of the sub-expressions is NULL. @throws \qtism\runtime\expressions\operators\OperatorProcessingException
[ "Process", "the", "Subtract", "operator", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/SubtractProcessor.php#L53-L77
oat-sa/qti-sdk
src/qtism/data/storage/xml/marshalling/OrderingMarshaller.php
OrderingMarshaller.unmarshall
protected function unmarshall(DOMElement $element) { $object = new Ordering(); if (($value = $this->getDOMElementAttributeAs($element, 'shuffle', 'boolean')) !== null) { $object->setShuffle($value); } return $object; }
php
protected function unmarshall(DOMElement $element) { $object = new Ordering(); if (($value = $this->getDOMElementAttributeAs($element, 'shuffle', 'boolean')) !== null) { $object->setShuffle($value); } return $object; }
[ "protected", "function", "unmarshall", "(", "DOMElement", "$", "element", ")", "{", "$", "object", "=", "new", "Ordering", "(", ")", ";", "if", "(", "(", "$", "value", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'shuffle'", ",", "'boolean'", ")", ")", "!==", "null", ")", "{", "$", "object", "->", "setShuffle", "(", "$", "value", ")", ";", "}", "return", "$", "object", ";", "}" ]
Unmarshall a DOMElement object corresponding to a QTI Ordering element. @param \DOMElement $element A DOMElement object. @return \qtism\data\QtiComponent An Ordering object.
[ "Unmarshall", "a", "DOMElement", "object", "corresponding", "to", "a", "QTI", "Ordering", "element", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/OrderingMarshaller.php#L58-L67
oat-sa/qti-sdk
src/qtism/runtime/expressions/operators/InsideProcessor.php
InsideProcessor.process
public function process() { $operands = $this->getOperands(); if ($operands->containsNull() === true) { return null; } if ($operands->exclusivelySingle() === false) { $msg = "The Inside operator only accepts operands with a single cardinality."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY); } if ($operands->exclusivelyPoint() === false) { $msg = "The Inside operator only accepts operands with a baseType of point."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE); } $operand = $operands[0]; $coords = $this->getExpression()->getCoords(); return new QtiBoolean($coords->inside($operand)); }
php
public function process() { $operands = $this->getOperands(); if ($operands->containsNull() === true) { return null; } if ($operands->exclusivelySingle() === false) { $msg = "The Inside operator only accepts operands with a single cardinality."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY); } if ($operands->exclusivelyPoint() === false) { $msg = "The Inside operator only accepts operands with a baseType of point."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE); } $operand = $operands[0]; $coords = $this->getExpression()->getCoords(); return new QtiBoolean($coords->inside($operand)); }
[ "public", "function", "process", "(", ")", "{", "$", "operands", "=", "$", "this", "->", "getOperands", "(", ")", ";", "if", "(", "$", "operands", "->", "containsNull", "(", ")", "===", "true", ")", "{", "return", "null", ";", "}", "if", "(", "$", "operands", "->", "exclusivelySingle", "(", ")", "===", "false", ")", "{", "$", "msg", "=", "\"The Inside operator only accepts operands with a single cardinality.\"", ";", "throw", "new", "OperatorProcessingException", "(", "$", "msg", ",", "$", "this", ",", "OperatorProcessingException", "::", "WRONG_CARDINALITY", ")", ";", "}", "if", "(", "$", "operands", "->", "exclusivelyPoint", "(", ")", "===", "false", ")", "{", "$", "msg", "=", "\"The Inside operator only accepts operands with a baseType of point.\"", ";", "throw", "new", "OperatorProcessingException", "(", "$", "msg", ",", "$", "this", ",", "OperatorProcessingException", "::", "WRONG_BASETYPE", ")", ";", "}", "$", "operand", "=", "$", "operands", "[", "0", "]", ";", "$", "coords", "=", "$", "this", "->", "getExpression", "(", ")", "->", "getCoords", "(", ")", ";", "return", "new", "QtiBoolean", "(", "$", "coords", "->", "inside", "(", "$", "operand", ")", ")", ";", "}" ]
Process the Inside operator. @return boolean|null Whether the given point is inside the area defined by shape and coords or NULL if the sub-expression is NULL. @throws \qtism\runtime\expressions\operators\OperatorProcessingException
[ "Process", "the", "Inside", "operator", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/InsideProcessor.php#L52-L74
oat-sa/qti-sdk
src/qtism/data/state/TemplateDefault.php
TemplateDefault.setTemplateIdentifier
public function setTemplateIdentifier($templateIdentifier) { if (Format::isIdentifier($templateIdentifier)) { $this->templateIdentifier = $templateIdentifier; } else { $msg = "'${templateIdentifier}' is not a valid QTI Identifier."; throw new InvalidArgumentException($msg); } }
php
public function setTemplateIdentifier($templateIdentifier) { if (Format::isIdentifier($templateIdentifier)) { $this->templateIdentifier = $templateIdentifier; } else { $msg = "'${templateIdentifier}' is not a valid QTI Identifier."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setTemplateIdentifier", "(", "$", "templateIdentifier", ")", "{", "if", "(", "Format", "::", "isIdentifier", "(", "$", "templateIdentifier", ")", ")", "{", "$", "this", "->", "templateIdentifier", "=", "$", "templateIdentifier", ";", "}", "else", "{", "$", "msg", "=", "\"'${templateIdentifier}' is not a valid QTI Identifier.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set the identifier of the template variable affected. @param string $templateIdentifier A QTI identifier. @throws \InvalidArgumentException If $templateIdentifier is not a valid QTI Identifier.
[ "Set", "the", "identifier", "of", "the", "template", "variable", "affected", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/state/TemplateDefault.php#L91-L99
oat-sa/qti-sdk
src/qtism/data/storage/xml/marshalling/AssessmentItemMarshaller.php
AssessmentItemMarshaller.marshall
protected function marshall(QtiComponent $component) { $element = static::getDOMCradle()->createElement($component->getQtiClassName()); $this->setDOMElementAttribute($element, 'identifier', $component->getIdentifier()); $this->setDOMElementAttribute($element, 'title', $component->getTitle()); $this->setDOMElementAttribute($element, 'timeDependent', $component->isTimeDependent()); $this->setDOMElementAttribute($element, 'adaptive', $component->isAdaptive()); if ($component->hasLang() === true) { $this->setDOMElementAttribute($element, 'lang', $component->getLang()); } if ($component->hasLabel() === true) { $this->setDOMElementAttribute($element, 'label', $component->getLabel()); } if ($component->hasToolName() === true) { $this->setDOMElementAttribute($element, 'toolName', $component->getToolName()); } if ($component->hasToolVersion() === true) { $this->setDOMElementAttribute($element, 'toolVersion', $component->getToolVersion()); } foreach ($component->getResponseDeclarations() as $responseDeclaration) { $marshaller = $this->getMarshallerFactory()->createMarshaller($responseDeclaration); $element->appendChild($marshaller->marshall($responseDeclaration)); } foreach ($component->getOutcomeDeclarations() as $outcomeDeclaration) { $marshaller = $this->getMarshallerFactory()->createMarshaller($outcomeDeclaration); $element->appendChild($marshaller->marshall($outcomeDeclaration)); } foreach ($component->getTemplateDeclarations() as $templateDeclaration) { $marshaller = $this->getMarshallerFactory()->createMarshaller($templateDeclaration); $element->appendChild($marshaller->marshall($templateDeclaration)); } if ($component->hasTemplateProcessing() === true) { $marshaller = $this->getMarshallerFactory()->createMarshaller($component->getTemplateProcessing()); $element->appendChild($marshaller->marshall($component->getTemplateProcessing())); } foreach ($component->getStylesheets() as $stylesheet) { $marshaller = $this->getMarshallerFactory()->createMarshaller($stylesheet); $element->appendChild($marshaller->marshall($stylesheet)); } if ($component->hasItemBody() === true) { $itemBody = $component->getItemBody(); $marshaller = $this->getMarshallerFactory()->createMarshaller($itemBody); $element->appendChild($marshaller->marshall($itemBody)); } if ($component->hasResponseProcessing() === true) { $marshaller = $this->getMarshallerFactory()->createMarshaller($component->getResponseProcessing()); $element->appendChild($marshaller->marshall($component->getResponseProcessing())); } foreach ($component->getModalFeedbacks() as $modalFeedback) { $marshaller = $this->getMarshallerFactory()->createMarshaller($modalFeedback); $element->appendChild($marshaller->marshall($modalFeedback)); } return $element; }
php
protected function marshall(QtiComponent $component) { $element = static::getDOMCradle()->createElement($component->getQtiClassName()); $this->setDOMElementAttribute($element, 'identifier', $component->getIdentifier()); $this->setDOMElementAttribute($element, 'title', $component->getTitle()); $this->setDOMElementAttribute($element, 'timeDependent', $component->isTimeDependent()); $this->setDOMElementAttribute($element, 'adaptive', $component->isAdaptive()); if ($component->hasLang() === true) { $this->setDOMElementAttribute($element, 'lang', $component->getLang()); } if ($component->hasLabel() === true) { $this->setDOMElementAttribute($element, 'label', $component->getLabel()); } if ($component->hasToolName() === true) { $this->setDOMElementAttribute($element, 'toolName', $component->getToolName()); } if ($component->hasToolVersion() === true) { $this->setDOMElementAttribute($element, 'toolVersion', $component->getToolVersion()); } foreach ($component->getResponseDeclarations() as $responseDeclaration) { $marshaller = $this->getMarshallerFactory()->createMarshaller($responseDeclaration); $element->appendChild($marshaller->marshall($responseDeclaration)); } foreach ($component->getOutcomeDeclarations() as $outcomeDeclaration) { $marshaller = $this->getMarshallerFactory()->createMarshaller($outcomeDeclaration); $element->appendChild($marshaller->marshall($outcomeDeclaration)); } foreach ($component->getTemplateDeclarations() as $templateDeclaration) { $marshaller = $this->getMarshallerFactory()->createMarshaller($templateDeclaration); $element->appendChild($marshaller->marshall($templateDeclaration)); } if ($component->hasTemplateProcessing() === true) { $marshaller = $this->getMarshallerFactory()->createMarshaller($component->getTemplateProcessing()); $element->appendChild($marshaller->marshall($component->getTemplateProcessing())); } foreach ($component->getStylesheets() as $stylesheet) { $marshaller = $this->getMarshallerFactory()->createMarshaller($stylesheet); $element->appendChild($marshaller->marshall($stylesheet)); } if ($component->hasItemBody() === true) { $itemBody = $component->getItemBody(); $marshaller = $this->getMarshallerFactory()->createMarshaller($itemBody); $element->appendChild($marshaller->marshall($itemBody)); } if ($component->hasResponseProcessing() === true) { $marshaller = $this->getMarshallerFactory()->createMarshaller($component->getResponseProcessing()); $element->appendChild($marshaller->marshall($component->getResponseProcessing())); } foreach ($component->getModalFeedbacks() as $modalFeedback) { $marshaller = $this->getMarshallerFactory()->createMarshaller($modalFeedback); $element->appendChild($marshaller->marshall($modalFeedback)); } return $element; }
[ "protected", "function", "marshall", "(", "QtiComponent", "$", "component", ")", "{", "$", "element", "=", "static", "::", "getDOMCradle", "(", ")", "->", "createElement", "(", "$", "component", "->", "getQtiClassName", "(", ")", ")", ";", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'identifier'", ",", "$", "component", "->", "getIdentifier", "(", ")", ")", ";", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'title'", ",", "$", "component", "->", "getTitle", "(", ")", ")", ";", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'timeDependent'", ",", "$", "component", "->", "isTimeDependent", "(", ")", ")", ";", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'adaptive'", ",", "$", "component", "->", "isAdaptive", "(", ")", ")", ";", "if", "(", "$", "component", "->", "hasLang", "(", ")", "===", "true", ")", "{", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'lang'", ",", "$", "component", "->", "getLang", "(", ")", ")", ";", "}", "if", "(", "$", "component", "->", "hasLabel", "(", ")", "===", "true", ")", "{", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'label'", ",", "$", "component", "->", "getLabel", "(", ")", ")", ";", "}", "if", "(", "$", "component", "->", "hasToolName", "(", ")", "===", "true", ")", "{", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'toolName'", ",", "$", "component", "->", "getToolName", "(", ")", ")", ";", "}", "if", "(", "$", "component", "->", "hasToolVersion", "(", ")", "===", "true", ")", "{", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'toolVersion'", ",", "$", "component", "->", "getToolVersion", "(", ")", ")", ";", "}", "foreach", "(", "$", "component", "->", "getResponseDeclarations", "(", ")", "as", "$", "responseDeclaration", ")", "{", "$", "marshaller", "=", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "responseDeclaration", ")", ";", "$", "element", "->", "appendChild", "(", "$", "marshaller", "->", "marshall", "(", "$", "responseDeclaration", ")", ")", ";", "}", "foreach", "(", "$", "component", "->", "getOutcomeDeclarations", "(", ")", "as", "$", "outcomeDeclaration", ")", "{", "$", "marshaller", "=", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "outcomeDeclaration", ")", ";", "$", "element", "->", "appendChild", "(", "$", "marshaller", "->", "marshall", "(", "$", "outcomeDeclaration", ")", ")", ";", "}", "foreach", "(", "$", "component", "->", "getTemplateDeclarations", "(", ")", "as", "$", "templateDeclaration", ")", "{", "$", "marshaller", "=", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "templateDeclaration", ")", ";", "$", "element", "->", "appendChild", "(", "$", "marshaller", "->", "marshall", "(", "$", "templateDeclaration", ")", ")", ";", "}", "if", "(", "$", "component", "->", "hasTemplateProcessing", "(", ")", "===", "true", ")", "{", "$", "marshaller", "=", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "component", "->", "getTemplateProcessing", "(", ")", ")", ";", "$", "element", "->", "appendChild", "(", "$", "marshaller", "->", "marshall", "(", "$", "component", "->", "getTemplateProcessing", "(", ")", ")", ")", ";", "}", "foreach", "(", "$", "component", "->", "getStylesheets", "(", ")", "as", "$", "stylesheet", ")", "{", "$", "marshaller", "=", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "stylesheet", ")", ";", "$", "element", "->", "appendChild", "(", "$", "marshaller", "->", "marshall", "(", "$", "stylesheet", ")", ")", ";", "}", "if", "(", "$", "component", "->", "hasItemBody", "(", ")", "===", "true", ")", "{", "$", "itemBody", "=", "$", "component", "->", "getItemBody", "(", ")", ";", "$", "marshaller", "=", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "itemBody", ")", ";", "$", "element", "->", "appendChild", "(", "$", "marshaller", "->", "marshall", "(", "$", "itemBody", ")", ")", ";", "}", "if", "(", "$", "component", "->", "hasResponseProcessing", "(", ")", "===", "true", ")", "{", "$", "marshaller", "=", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "component", "->", "getResponseProcessing", "(", ")", ")", ";", "$", "element", "->", "appendChild", "(", "$", "marshaller", "->", "marshall", "(", "$", "component", "->", "getResponseProcessing", "(", ")", ")", ")", ";", "}", "foreach", "(", "$", "component", "->", "getModalFeedbacks", "(", ")", "as", "$", "modalFeedback", ")", "{", "$", "marshaller", "=", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "modalFeedback", ")", ";", "$", "element", "->", "appendChild", "(", "$", "marshaller", "->", "marshall", "(", "$", "modalFeedback", ")", ")", ";", "}", "return", "$", "element", ";", "}" ]
Marshall an AssessmentItem object into a DOMElement object. @param \qtism\data\QtiComponent $component An AssessmentItem object. @return \DOMElement The according DOMElement object.
[ "Marshall", "an", "AssessmentItem", "object", "into", "a", "DOMElement", "object", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/AssessmentItemMarshaller.php#L48-L115
oat-sa/qti-sdk
src/qtism/data/storage/xml/marshalling/AssessmentItemMarshaller.php
AssessmentItemMarshaller.unmarshall
protected function unmarshall(DOMElement $element, AssessmentItem $assessmentItem = null) { if (($identifier = $this->getDOMElementAttributeAs($element, 'identifier')) !== null) { if (($timeDependent = $this->getDOMElementAttributeAs($element, 'timeDependent', 'boolean')) !== null) { if (($title= $this->getDOMElementAttributeAs($element, 'title')) !== null) { if (empty($assessmentItem)) { $object = new AssessmentItem($identifier, $title, $timeDependent); } else { $object = $assessmentItem; $object->setIdentifier($identifier); $object->setTimeDependent($timeDependent); } if (($lang = $this->getDOMElementAttributeAs($element, 'lang')) !== null) { $object->setLang($lang); } if (($label = $this->getDOMElementAttributeAs($element, 'label')) !== null) { $object->setLabel($label); } if (($adaptive = $this->getDOMElementAttributeAs($element, 'adaptive', 'boolean')) !== null) { $object->setAdaptive($adaptive); } if (($toolName = $this->getDOMElementAttributeAs($element, 'toolName')) !== null) { $object->setToolName($toolName); } if (($toolVersion = $this->getDOMElementAttributeAs($element, 'toolVersion')) !== null) { $object->setToolVersion($toolVersion); } $responseDeclarationElts = $this->getChildElementsByTagName($element, 'responseDeclaration'); if (!empty($responseDeclarationElts)) { $responseDeclarations = new ResponseDeclarationCollection(); foreach ($responseDeclarationElts as $responseDeclarationElt) { $marshaller = $this->getMarshallerFactory()->createMarshaller($responseDeclarationElt); $responseDeclarations[] = $marshaller->unmarshall($responseDeclarationElt); } $object->setResponseDeclarations($responseDeclarations); } $outcomeDeclarationElts = $this->getChildElementsByTagName($element, 'outcomeDeclaration'); if (!empty($outcomeDeclarationElts)) { $outcomeDeclarations = new OutcomeDeclarationCollection(); foreach ($outcomeDeclarationElts as $outcomeDeclarationElt) { $marshaller = $this->getMarshallerFactory()->createMarshaller($outcomeDeclarationElt); $outcomeDeclarations[] = $marshaller->unmarshall($outcomeDeclarationElt); } $object->setOutcomeDeclarations($outcomeDeclarations); } $templateDeclarationElts = $this->getChildElementsByTagName($element, 'templateDeclaration'); if (!empty($templateDeclarationElts)) { $templateDeclarations = new TemplateDeclarationCollection(); foreach ($templateDeclarationElts as $templateDeclarationElt) { $marshaller = $this->getMarshallerFactory()->createMarshaller($templateDeclarationElt); $templateDeclarations[] = $marshaller->unmarshall($templateDeclarationElt); } $object->setTemplateDeclarations($templateDeclarations); } $templateProcessingElts = $this->getChildElementsByTagName($element, 'templateProcessing'); if (!empty($templateProcessingElts)) { $marshaller = $this->getMarshallerFactory()->createMarshaller($templateProcessingElts[0]); $object->setTemplateProcessing($marshaller->unmarshall($templateProcessingElts[0])); } $stylesheetElts = $this->getChildElementsByTagName($element, 'stylesheet'); if (!empty($stylesheetElts)) { $stylesheets = new StylesheetCollection(); foreach ($stylesheetElts as $stylesheetElt) { $marshaller = $this->getMarshallerFactory()->createMarshaller($stylesheetElt); $stylesheets[] = $marshaller->unmarshall($stylesheetElt); } $object->setStylesheets($stylesheets); } $itemBodyElts = $this->getChildElementsByTagName($element, 'itemBody'); if (count($itemBodyElts) > 0) { $marshaller = $this->getMarshallerFactory()->createMarshaller($itemBodyElts[0]); $object->setItemBody($marshaller->unmarshall($itemBodyElts[0])); } $responseProcessingElts = $this->getChildElementsByTagName($element, 'responseProcessing'); if (!empty($responseProcessingElts)) { $marshaller = $this->getMarshallerFactory()->createMarshaller($responseProcessingElts[0]); $object->setResponseProcessing($marshaller->unmarshall($responseProcessingElts[0])); } $modalFeedbackElts = $this->getChildElementsByTagName($element, 'modalFeedback'); if (!empty($modalFeedbackElts)) { $modalFeedbacks = new ModalFeedbackCollection(); foreach ($modalFeedbackElts as $modalFeedbackElt) { $marshaller = $this->getMarshallerFactory()->createMarshaller($modalFeedbackElt); $modalFeedbacks[] = $marshaller->unmarshall($modalFeedbackElt); } $object->setModalFeedbacks($modalFeedbacks); } return $object; } else { $msg = "The mandatory attribute 'title' is missing from element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element); } } else { $msg = "The mandatory attribute 'timeDependent' is missing from element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element); } } else { $msg = "The mandatory attribute 'identifier' is missing from element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element); } }
php
protected function unmarshall(DOMElement $element, AssessmentItem $assessmentItem = null) { if (($identifier = $this->getDOMElementAttributeAs($element, 'identifier')) !== null) { if (($timeDependent = $this->getDOMElementAttributeAs($element, 'timeDependent', 'boolean')) !== null) { if (($title= $this->getDOMElementAttributeAs($element, 'title')) !== null) { if (empty($assessmentItem)) { $object = new AssessmentItem($identifier, $title, $timeDependent); } else { $object = $assessmentItem; $object->setIdentifier($identifier); $object->setTimeDependent($timeDependent); } if (($lang = $this->getDOMElementAttributeAs($element, 'lang')) !== null) { $object->setLang($lang); } if (($label = $this->getDOMElementAttributeAs($element, 'label')) !== null) { $object->setLabel($label); } if (($adaptive = $this->getDOMElementAttributeAs($element, 'adaptive', 'boolean')) !== null) { $object->setAdaptive($adaptive); } if (($toolName = $this->getDOMElementAttributeAs($element, 'toolName')) !== null) { $object->setToolName($toolName); } if (($toolVersion = $this->getDOMElementAttributeAs($element, 'toolVersion')) !== null) { $object->setToolVersion($toolVersion); } $responseDeclarationElts = $this->getChildElementsByTagName($element, 'responseDeclaration'); if (!empty($responseDeclarationElts)) { $responseDeclarations = new ResponseDeclarationCollection(); foreach ($responseDeclarationElts as $responseDeclarationElt) { $marshaller = $this->getMarshallerFactory()->createMarshaller($responseDeclarationElt); $responseDeclarations[] = $marshaller->unmarshall($responseDeclarationElt); } $object->setResponseDeclarations($responseDeclarations); } $outcomeDeclarationElts = $this->getChildElementsByTagName($element, 'outcomeDeclaration'); if (!empty($outcomeDeclarationElts)) { $outcomeDeclarations = new OutcomeDeclarationCollection(); foreach ($outcomeDeclarationElts as $outcomeDeclarationElt) { $marshaller = $this->getMarshallerFactory()->createMarshaller($outcomeDeclarationElt); $outcomeDeclarations[] = $marshaller->unmarshall($outcomeDeclarationElt); } $object->setOutcomeDeclarations($outcomeDeclarations); } $templateDeclarationElts = $this->getChildElementsByTagName($element, 'templateDeclaration'); if (!empty($templateDeclarationElts)) { $templateDeclarations = new TemplateDeclarationCollection(); foreach ($templateDeclarationElts as $templateDeclarationElt) { $marshaller = $this->getMarshallerFactory()->createMarshaller($templateDeclarationElt); $templateDeclarations[] = $marshaller->unmarshall($templateDeclarationElt); } $object->setTemplateDeclarations($templateDeclarations); } $templateProcessingElts = $this->getChildElementsByTagName($element, 'templateProcessing'); if (!empty($templateProcessingElts)) { $marshaller = $this->getMarshallerFactory()->createMarshaller($templateProcessingElts[0]); $object->setTemplateProcessing($marshaller->unmarshall($templateProcessingElts[0])); } $stylesheetElts = $this->getChildElementsByTagName($element, 'stylesheet'); if (!empty($stylesheetElts)) { $stylesheets = new StylesheetCollection(); foreach ($stylesheetElts as $stylesheetElt) { $marshaller = $this->getMarshallerFactory()->createMarshaller($stylesheetElt); $stylesheets[] = $marshaller->unmarshall($stylesheetElt); } $object->setStylesheets($stylesheets); } $itemBodyElts = $this->getChildElementsByTagName($element, 'itemBody'); if (count($itemBodyElts) > 0) { $marshaller = $this->getMarshallerFactory()->createMarshaller($itemBodyElts[0]); $object->setItemBody($marshaller->unmarshall($itemBodyElts[0])); } $responseProcessingElts = $this->getChildElementsByTagName($element, 'responseProcessing'); if (!empty($responseProcessingElts)) { $marshaller = $this->getMarshallerFactory()->createMarshaller($responseProcessingElts[0]); $object->setResponseProcessing($marshaller->unmarshall($responseProcessingElts[0])); } $modalFeedbackElts = $this->getChildElementsByTagName($element, 'modalFeedback'); if (!empty($modalFeedbackElts)) { $modalFeedbacks = new ModalFeedbackCollection(); foreach ($modalFeedbackElts as $modalFeedbackElt) { $marshaller = $this->getMarshallerFactory()->createMarshaller($modalFeedbackElt); $modalFeedbacks[] = $marshaller->unmarshall($modalFeedbackElt); } $object->setModalFeedbacks($modalFeedbacks); } return $object; } else { $msg = "The mandatory attribute 'title' is missing from element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element); } } else { $msg = "The mandatory attribute 'timeDependent' is missing from element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element); } } else { $msg = "The mandatory attribute 'identifier' is missing from element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element); } }
[ "protected", "function", "unmarshall", "(", "DOMElement", "$", "element", ",", "AssessmentItem", "$", "assessmentItem", "=", "null", ")", "{", "if", "(", "(", "$", "identifier", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'identifier'", ")", ")", "!==", "null", ")", "{", "if", "(", "(", "$", "timeDependent", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'timeDependent'", ",", "'boolean'", ")", ")", "!==", "null", ")", "{", "if", "(", "(", "$", "title", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'title'", ")", ")", "!==", "null", ")", "{", "if", "(", "empty", "(", "$", "assessmentItem", ")", ")", "{", "$", "object", "=", "new", "AssessmentItem", "(", "$", "identifier", ",", "$", "title", ",", "$", "timeDependent", ")", ";", "}", "else", "{", "$", "object", "=", "$", "assessmentItem", ";", "$", "object", "->", "setIdentifier", "(", "$", "identifier", ")", ";", "$", "object", "->", "setTimeDependent", "(", "$", "timeDependent", ")", ";", "}", "if", "(", "(", "$", "lang", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'lang'", ")", ")", "!==", "null", ")", "{", "$", "object", "->", "setLang", "(", "$", "lang", ")", ";", "}", "if", "(", "(", "$", "label", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'label'", ")", ")", "!==", "null", ")", "{", "$", "object", "->", "setLabel", "(", "$", "label", ")", ";", "}", "if", "(", "(", "$", "adaptive", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'adaptive'", ",", "'boolean'", ")", ")", "!==", "null", ")", "{", "$", "object", "->", "setAdaptive", "(", "$", "adaptive", ")", ";", "}", "if", "(", "(", "$", "toolName", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'toolName'", ")", ")", "!==", "null", ")", "{", "$", "object", "->", "setToolName", "(", "$", "toolName", ")", ";", "}", "if", "(", "(", "$", "toolVersion", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'toolVersion'", ")", ")", "!==", "null", ")", "{", "$", "object", "->", "setToolVersion", "(", "$", "toolVersion", ")", ";", "}", "$", "responseDeclarationElts", "=", "$", "this", "->", "getChildElementsByTagName", "(", "$", "element", ",", "'responseDeclaration'", ")", ";", "if", "(", "!", "empty", "(", "$", "responseDeclarationElts", ")", ")", "{", "$", "responseDeclarations", "=", "new", "ResponseDeclarationCollection", "(", ")", ";", "foreach", "(", "$", "responseDeclarationElts", "as", "$", "responseDeclarationElt", ")", "{", "$", "marshaller", "=", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "responseDeclarationElt", ")", ";", "$", "responseDeclarations", "[", "]", "=", "$", "marshaller", "->", "unmarshall", "(", "$", "responseDeclarationElt", ")", ";", "}", "$", "object", "->", "setResponseDeclarations", "(", "$", "responseDeclarations", ")", ";", "}", "$", "outcomeDeclarationElts", "=", "$", "this", "->", "getChildElementsByTagName", "(", "$", "element", ",", "'outcomeDeclaration'", ")", ";", "if", "(", "!", "empty", "(", "$", "outcomeDeclarationElts", ")", ")", "{", "$", "outcomeDeclarations", "=", "new", "OutcomeDeclarationCollection", "(", ")", ";", "foreach", "(", "$", "outcomeDeclarationElts", "as", "$", "outcomeDeclarationElt", ")", "{", "$", "marshaller", "=", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "outcomeDeclarationElt", ")", ";", "$", "outcomeDeclarations", "[", "]", "=", "$", "marshaller", "->", "unmarshall", "(", "$", "outcomeDeclarationElt", ")", ";", "}", "$", "object", "->", "setOutcomeDeclarations", "(", "$", "outcomeDeclarations", ")", ";", "}", "$", "templateDeclarationElts", "=", "$", "this", "->", "getChildElementsByTagName", "(", "$", "element", ",", "'templateDeclaration'", ")", ";", "if", "(", "!", "empty", "(", "$", "templateDeclarationElts", ")", ")", "{", "$", "templateDeclarations", "=", "new", "TemplateDeclarationCollection", "(", ")", ";", "foreach", "(", "$", "templateDeclarationElts", "as", "$", "templateDeclarationElt", ")", "{", "$", "marshaller", "=", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "templateDeclarationElt", ")", ";", "$", "templateDeclarations", "[", "]", "=", "$", "marshaller", "->", "unmarshall", "(", "$", "templateDeclarationElt", ")", ";", "}", "$", "object", "->", "setTemplateDeclarations", "(", "$", "templateDeclarations", ")", ";", "}", "$", "templateProcessingElts", "=", "$", "this", "->", "getChildElementsByTagName", "(", "$", "element", ",", "'templateProcessing'", ")", ";", "if", "(", "!", "empty", "(", "$", "templateProcessingElts", ")", ")", "{", "$", "marshaller", "=", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "templateProcessingElts", "[", "0", "]", ")", ";", "$", "object", "->", "setTemplateProcessing", "(", "$", "marshaller", "->", "unmarshall", "(", "$", "templateProcessingElts", "[", "0", "]", ")", ")", ";", "}", "$", "stylesheetElts", "=", "$", "this", "->", "getChildElementsByTagName", "(", "$", "element", ",", "'stylesheet'", ")", ";", "if", "(", "!", "empty", "(", "$", "stylesheetElts", ")", ")", "{", "$", "stylesheets", "=", "new", "StylesheetCollection", "(", ")", ";", "foreach", "(", "$", "stylesheetElts", "as", "$", "stylesheetElt", ")", "{", "$", "marshaller", "=", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "stylesheetElt", ")", ";", "$", "stylesheets", "[", "]", "=", "$", "marshaller", "->", "unmarshall", "(", "$", "stylesheetElt", ")", ";", "}", "$", "object", "->", "setStylesheets", "(", "$", "stylesheets", ")", ";", "}", "$", "itemBodyElts", "=", "$", "this", "->", "getChildElementsByTagName", "(", "$", "element", ",", "'itemBody'", ")", ";", "if", "(", "count", "(", "$", "itemBodyElts", ")", ">", "0", ")", "{", "$", "marshaller", "=", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "itemBodyElts", "[", "0", "]", ")", ";", "$", "object", "->", "setItemBody", "(", "$", "marshaller", "->", "unmarshall", "(", "$", "itemBodyElts", "[", "0", "]", ")", ")", ";", "}", "$", "responseProcessingElts", "=", "$", "this", "->", "getChildElementsByTagName", "(", "$", "element", ",", "'responseProcessing'", ")", ";", "if", "(", "!", "empty", "(", "$", "responseProcessingElts", ")", ")", "{", "$", "marshaller", "=", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "responseProcessingElts", "[", "0", "]", ")", ";", "$", "object", "->", "setResponseProcessing", "(", "$", "marshaller", "->", "unmarshall", "(", "$", "responseProcessingElts", "[", "0", "]", ")", ")", ";", "}", "$", "modalFeedbackElts", "=", "$", "this", "->", "getChildElementsByTagName", "(", "$", "element", ",", "'modalFeedback'", ")", ";", "if", "(", "!", "empty", "(", "$", "modalFeedbackElts", ")", ")", "{", "$", "modalFeedbacks", "=", "new", "ModalFeedbackCollection", "(", ")", ";", "foreach", "(", "$", "modalFeedbackElts", "as", "$", "modalFeedbackElt", ")", "{", "$", "marshaller", "=", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "modalFeedbackElt", ")", ";", "$", "modalFeedbacks", "[", "]", "=", "$", "marshaller", "->", "unmarshall", "(", "$", "modalFeedbackElt", ")", ";", "}", "$", "object", "->", "setModalFeedbacks", "(", "$", "modalFeedbacks", ")", ";", "}", "return", "$", "object", ";", "}", "else", "{", "$", "msg", "=", "\"The mandatory attribute 'title' is missing from element '\"", ".", "$", "element", "->", "localName", ".", "\"'.\"", ";", "throw", "new", "UnmarshallingException", "(", "$", "msg", ",", "$", "element", ")", ";", "}", "}", "else", "{", "$", "msg", "=", "\"The mandatory attribute 'timeDependent' is missing from element '\"", ".", "$", "element", "->", "localName", ".", "\"'.\"", ";", "throw", "new", "UnmarshallingException", "(", "$", "msg", ",", "$", "element", ")", ";", "}", "}", "else", "{", "$", "msg", "=", "\"The mandatory attribute 'identifier' is missing from element '\"", ".", "$", "element", "->", "localName", ".", "\"'.\"", ";", "throw", "new", "UnmarshallingException", "(", "$", "msg", ",", "$", "element", ")", ";", "}", "}" ]
Unmarshall a DOMElement object corresponding to a QTI assessmentItem element. If $assessmentItem is provided, it will be used as the unmarshalled component instead of creating a new one. @param \DOMElement $element A DOMElement object. @param \qtism\data\AssessmentItem $assessmentItem An optional AssessmentItem object to be decorated. @return \qtism\data\QtiComponent An AssessmentItem object. @throws \qtism\data\storage\xml\marshalling\UnmarshallingException
[ "Unmarshall", "a", "DOMElement", "object", "corresponding", "to", "a", "QTI", "assessmentItem", "element", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/AssessmentItemMarshaller.php#L128-L258
oat-sa/qti-sdk
src/qtism/data/content/interactions/MediaInteraction.php
MediaInteraction.setAutostart
public function setAutostart($autostart) { if (is_bool($autostart) === true) { $this->autostart = $autostart; } else { $msg = "The 'autostart' argument must be a boolean value, '" . gettype($autostart) . "' given."; throw new InvalidArgumentException($msg); } }
php
public function setAutostart($autostart) { if (is_bool($autostart) === true) { $this->autostart = $autostart; } else { $msg = "The 'autostart' argument must be a boolean value, '" . gettype($autostart) . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setAutostart", "(", "$", "autostart", ")", "{", "if", "(", "is_bool", "(", "$", "autostart", ")", "===", "true", ")", "{", "$", "this", "->", "autostart", "=", "$", "autostart", ";", "}", "else", "{", "$", "msg", "=", "\"The 'autostart' argument must be a boolean value, '\"", ".", "gettype", "(", "$", "autostart", ")", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set whether or not the media must start as soon as the candidate starts the attempt. @param boolean $autostart @throws \InvalidArgumentException If $autostart is not a boolean value.
[ "Set", "whether", "or", "not", "the", "media", "must", "start", "as", "soon", "as", "the", "candidate", "starts", "the", "attempt", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/interactions/MediaInteraction.php#L126-L134
oat-sa/qti-sdk
src/qtism/data/content/interactions/MediaInteraction.php
MediaInteraction.setMinPlays
public function setMinPlays($minPlays) { if (is_int($minPlays) === true && $minPlays >= 0) { $this->minPlays = $minPlays; } else { $msg = "The 'minPlays' argument must be a positive (>= 0) integer, '" . gettype($minPlays) . "' given."; throw new InvalidArgumentException($msg); } }
php
public function setMinPlays($minPlays) { if (is_int($minPlays) === true && $minPlays >= 0) { $this->minPlays = $minPlays; } else { $msg = "The 'minPlays' argument must be a positive (>= 0) integer, '" . gettype($minPlays) . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setMinPlays", "(", "$", "minPlays", ")", "{", "if", "(", "is_int", "(", "$", "minPlays", ")", "===", "true", "&&", "$", "minPlays", ">=", "0", ")", "{", "$", "this", "->", "minPlays", "=", "$", "minPlays", ";", "}", "else", "{", "$", "msg", "=", "\"The 'minPlays' argument must be a positive (>= 0) integer, '\"", ".", "gettype", "(", "$", "minPlays", ")", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set the minimum number of times the media must be played. @param integer $minPlays A positive (>= 0) integer. @throws \InvalidArgumentException If $minPlays is not a positive integer.
[ "Set", "the", "minimum", "number", "of", "times", "the", "media", "must", "be", "played", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/interactions/MediaInteraction.php#L152-L160
oat-sa/qti-sdk
src/qtism/data/content/interactions/MediaInteraction.php
MediaInteraction.setMaxPlays
public function setMaxPlays($maxPlays) { if (is_int($maxPlays) && $maxPlays >= 0) { $this->maxPlays = $maxPlays; } else { $msg = "The 'maxPlays' argument must be a positive (>= 0) integer, '" . gettype($maxPlays) . "' given."; throw new InvalidArgumentException($msg); } }
php
public function setMaxPlays($maxPlays) { if (is_int($maxPlays) && $maxPlays >= 0) { $this->maxPlays = $maxPlays; } else { $msg = "The 'maxPlays' argument must be a positive (>= 0) integer, '" . gettype($maxPlays) . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setMaxPlays", "(", "$", "maxPlays", ")", "{", "if", "(", "is_int", "(", "$", "maxPlays", ")", "&&", "$", "maxPlays", ">=", "0", ")", "{", "$", "this", "->", "maxPlays", "=", "$", "maxPlays", ";", "}", "else", "{", "$", "msg", "=", "\"The 'maxPlays' argument must be a positive (>= 0) integer, '\"", ".", "gettype", "(", "$", "maxPlays", ")", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set the maximum number of times the media can be played. @param integer $maxPlays A positive (>= 0) integer. @throws \InvalidArgumentException If $maxPlays is not a positive integer.
[ "Set", "the", "maximum", "number", "of", "times", "the", "media", "can", "be", "played", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/interactions/MediaInteraction.php#L188-L196
oat-sa/qti-sdk
src/qtism/data/content/interactions/MediaInteraction.php
MediaInteraction.setLoop
public function setLoop($loop) { if (is_bool($loop) === true) { $this->loop = $loop; } else { $msg = "The 'loop' argument must be a boolean value, '" . gettype($loop) . "' given."; throw new InvalidArgumentException($msg); } }
php
public function setLoop($loop) { if (is_bool($loop) === true) { $this->loop = $loop; } else { $msg = "The 'loop' argument must be a boolean value, '" . gettype($loop) . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setLoop", "(", "$", "loop", ")", "{", "if", "(", "is_bool", "(", "$", "loop", ")", "===", "true", ")", "{", "$", "this", "->", "loop", "=", "$", "loop", ";", "}", "else", "{", "$", "msg", "=", "\"The 'loop' argument must be a boolean value, '\"", ".", "gettype", "(", "$", "loop", ")", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set whether or not the continuous play (subject to maxPlays) of the media is in force. @param boolean $loop @throws \InvalidArgumentException If $loop is not a boolean value.
[ "Set", "whether", "or", "not", "the", "continuous", "play", "(", "subject", "to", "maxPlays", ")", "of", "the", "media", "is", "in", "force", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/interactions/MediaInteraction.php#L224-L232
oat-sa/qti-sdk
src/qtism/runtime/expressions/operators/PowerProcessor.php
PowerProcessor.process
public function process() { $operands = $this->getOperands(); if ($operands->containsNull() === true) { return null; } if ($operands->exclusivelySingle() === false) { $msg = "The Power operator only accepts operands with a single cardinality."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY); } if ($operands->exclusivelyNumeric() === false) { $msg = "The Power operator only accepts operands with a baseType of integer or float."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE); } $operand1 = $operands[0]; $operand2 = $operands[1]; $raised = pow($operand1->getValue(), $operand2->getValue()); if (is_nan($raised)) { return null; } // If the first operand was not 0 but the result is 0, it means // we are subject to a lower overflow. if ($operand1->getValue() != 0 && $raised == 0) { return null; } // If the first and the second operands are not infinite but the result is infinite // it means we are subject to an upper overflow. if (!is_infinite($operand1->getValue()) && !is_infinite($operand2->getValue()) && is_infinite($raised)) { return null; } // pow() returns integers as much as it can, so we must cast. // If the casted value cannot be contained in a float, we are // subject to an overflow/underflow. $floatval = floatval($raised); if ($raised != 0 && $floatval == 0) { // underflow return null; } elseif (!is_infinite($raised) && is_infinite($floatval)) { // overflow return null; } else { return new QtiFloat($floatval); } }
php
public function process() { $operands = $this->getOperands(); if ($operands->containsNull() === true) { return null; } if ($operands->exclusivelySingle() === false) { $msg = "The Power operator only accepts operands with a single cardinality."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY); } if ($operands->exclusivelyNumeric() === false) { $msg = "The Power operator only accepts operands with a baseType of integer or float."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE); } $operand1 = $operands[0]; $operand2 = $operands[1]; $raised = pow($operand1->getValue(), $operand2->getValue()); if (is_nan($raised)) { return null; } // If the first operand was not 0 but the result is 0, it means // we are subject to a lower overflow. if ($operand1->getValue() != 0 && $raised == 0) { return null; } // If the first and the second operands are not infinite but the result is infinite // it means we are subject to an upper overflow. if (!is_infinite($operand1->getValue()) && !is_infinite($operand2->getValue()) && is_infinite($raised)) { return null; } // pow() returns integers as much as it can, so we must cast. // If the casted value cannot be contained in a float, we are // subject to an overflow/underflow. $floatval = floatval($raised); if ($raised != 0 && $floatval == 0) { // underflow return null; } elseif (!is_infinite($raised) && is_infinite($floatval)) { // overflow return null; } else { return new QtiFloat($floatval); } }
[ "public", "function", "process", "(", ")", "{", "$", "operands", "=", "$", "this", "->", "getOperands", "(", ")", ";", "if", "(", "$", "operands", "->", "containsNull", "(", ")", "===", "true", ")", "{", "return", "null", ";", "}", "if", "(", "$", "operands", "->", "exclusivelySingle", "(", ")", "===", "false", ")", "{", "$", "msg", "=", "\"The Power operator only accepts operands with a single cardinality.\"", ";", "throw", "new", "OperatorProcessingException", "(", "$", "msg", ",", "$", "this", ",", "OperatorProcessingException", "::", "WRONG_CARDINALITY", ")", ";", "}", "if", "(", "$", "operands", "->", "exclusivelyNumeric", "(", ")", "===", "false", ")", "{", "$", "msg", "=", "\"The Power operator only accepts operands with a baseType of integer or float.\"", ";", "throw", "new", "OperatorProcessingException", "(", "$", "msg", ",", "$", "this", ",", "OperatorProcessingException", "::", "WRONG_BASETYPE", ")", ";", "}", "$", "operand1", "=", "$", "operands", "[", "0", "]", ";", "$", "operand2", "=", "$", "operands", "[", "1", "]", ";", "$", "raised", "=", "pow", "(", "$", "operand1", "->", "getValue", "(", ")", ",", "$", "operand2", "->", "getValue", "(", ")", ")", ";", "if", "(", "is_nan", "(", "$", "raised", ")", ")", "{", "return", "null", ";", "}", "// If the first operand was not 0 but the result is 0, it means", "// we are subject to a lower overflow.", "if", "(", "$", "operand1", "->", "getValue", "(", ")", "!=", "0", "&&", "$", "raised", "==", "0", ")", "{", "return", "null", ";", "}", "// If the first and the second operands are not infinite but the result is infinite", "// it means we are subject to an upper overflow.", "if", "(", "!", "is_infinite", "(", "$", "operand1", "->", "getValue", "(", ")", ")", "&&", "!", "is_infinite", "(", "$", "operand2", "->", "getValue", "(", ")", ")", "&&", "is_infinite", "(", "$", "raised", ")", ")", "{", "return", "null", ";", "}", "// pow() returns integers as much as it can, so we must cast.", "// If the casted value cannot be contained in a float, we are", "// subject to an overflow/underflow.", "$", "floatval", "=", "floatval", "(", "$", "raised", ")", ";", "if", "(", "$", "raised", "!=", "0", "&&", "$", "floatval", "==", "0", ")", "{", "// underflow", "return", "null", ";", "}", "elseif", "(", "!", "is_infinite", "(", "$", "raised", ")", "&&", "is_infinite", "(", "$", "floatval", ")", ")", "{", "// overflow", "return", "null", ";", "}", "else", "{", "return", "new", "QtiFloat", "(", "$", "floatval", ")", ";", "}", "}" ]
Process the Power operator. @return float|null A float value that corresponds to the first expression raised to the power of the second or NULL if the either sub-expression is NULL. @throws \qtism\runtime\expressions\operators\OperatorProcessingException
[ "Process", "the", "Power", "operator", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/PowerProcessor.php#L53-L104
oat-sa/qti-sdk
src/qtism/data/expressions/operators/Repeat.php
Repeat.setNumberRepeats
public function setNumberRepeats($numberRepeats) { if (is_int($numberRepeats) || (gettype($numberRepeats) === 'string' && Format::isVariableRef($numberRepeats))) { $this->numberRepeats = $numberRepeats; } else { $msg = "The numberRepeats argument must be an integer or a variable reference, '" . gettype($numberRepeats) . "' given."; throw new InvalidArgumentException($msg); } }
php
public function setNumberRepeats($numberRepeats) { if (is_int($numberRepeats) || (gettype($numberRepeats) === 'string' && Format::isVariableRef($numberRepeats))) { $this->numberRepeats = $numberRepeats; } else { $msg = "The numberRepeats argument must be an integer or a variable reference, '" . gettype($numberRepeats) . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setNumberRepeats", "(", "$", "numberRepeats", ")", "{", "if", "(", "is_int", "(", "$", "numberRepeats", ")", "||", "(", "gettype", "(", "$", "numberRepeats", ")", "===", "'string'", "&&", "Format", "::", "isVariableRef", "(", "$", "numberRepeats", ")", ")", ")", "{", "$", "this", "->", "numberRepeats", "=", "$", "numberRepeats", ";", "}", "else", "{", "$", "msg", "=", "\"The numberRepeats argument must be an integer or a variable reference, '\"", ".", "gettype", "(", "$", "numberRepeats", ")", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set the numberRepeats attribute. @param integer|string $numberRepeats An integer or a QTI variable reference. @throws \InvalidArgumentException If $numberRepeats is not an integer nor a valid QTI variable reference.
[ "Set", "the", "numberRepeats", "attribute", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/expressions/operators/Repeat.php#L75-L83
oat-sa/qti-sdk
src/qtism/cli/Render.php
Render.run
protected function run() { $engine = $this->instantiateEngine(); $arguments = $this->getArguments(); // Load XML Document. $source = $arguments['source']; $doc = new XmlDocument(); $validate = !($arguments['novalidate'] === true); try { $doc->load($source, $validate); $renderingData = ''; switch (strtolower($arguments['flavour'])) { case 'goldilocks': $renderingData = $this->runGoldilocks($doc, $engine); break; case 'xhtml': $renderingData = $this->runXhtml($doc, $engine); break; } // Add final new line? $nl = false; if ($arguments['document'] !== true && $arguments['format'] !== true) { $nl = true; } $this->out($renderingData, $nl); $this->success("QTI XML file successfully rendered."); } catch (XmlStorageException $e) { switch ($e->getCode()) { case XmlStorageException::READ: $msg = "An error occured while reading QTI file '${source}'.\nThe system returned the following error:\n"; $msg .= ExceptionUtils::formatMessage($e); $this->fail($msg); break; case XmlStorageException::XSD_VALIDATION: $msg = "The QTI file '${source}' is invalid against XML Schema.\nThe system returned the following error:\n"; $msg .= ExceptionUtils::formatMessage($e); $this->fail($msg); break; case XmlStorageException::VERSION: $msg = "The QTI version of file '${source}' could not be detected."; $this->fail($msg); break; default: $msg = "An fatal error occured while reading QTI file '${source}'."; $this->fail($msg); break; } } }
php
protected function run() { $engine = $this->instantiateEngine(); $arguments = $this->getArguments(); // Load XML Document. $source = $arguments['source']; $doc = new XmlDocument(); $validate = !($arguments['novalidate'] === true); try { $doc->load($source, $validate); $renderingData = ''; switch (strtolower($arguments['flavour'])) { case 'goldilocks': $renderingData = $this->runGoldilocks($doc, $engine); break; case 'xhtml': $renderingData = $this->runXhtml($doc, $engine); break; } // Add final new line? $nl = false; if ($arguments['document'] !== true && $arguments['format'] !== true) { $nl = true; } $this->out($renderingData, $nl); $this->success("QTI XML file successfully rendered."); } catch (XmlStorageException $e) { switch ($e->getCode()) { case XmlStorageException::READ: $msg = "An error occured while reading QTI file '${source}'.\nThe system returned the following error:\n"; $msg .= ExceptionUtils::formatMessage($e); $this->fail($msg); break; case XmlStorageException::XSD_VALIDATION: $msg = "The QTI file '${source}' is invalid against XML Schema.\nThe system returned the following error:\n"; $msg .= ExceptionUtils::formatMessage($e); $this->fail($msg); break; case XmlStorageException::VERSION: $msg = "The QTI version of file '${source}' could not be detected."; $this->fail($msg); break; default: $msg = "An fatal error occured while reading QTI file '${source}'."; $this->fail($msg); break; } } }
[ "protected", "function", "run", "(", ")", "{", "$", "engine", "=", "$", "this", "->", "instantiateEngine", "(", ")", ";", "$", "arguments", "=", "$", "this", "->", "getArguments", "(", ")", ";", "// Load XML Document.", "$", "source", "=", "$", "arguments", "[", "'source'", "]", ";", "$", "doc", "=", "new", "XmlDocument", "(", ")", ";", "$", "validate", "=", "!", "(", "$", "arguments", "[", "'novalidate'", "]", "===", "true", ")", ";", "try", "{", "$", "doc", "->", "load", "(", "$", "source", ",", "$", "validate", ")", ";", "$", "renderingData", "=", "''", ";", "switch", "(", "strtolower", "(", "$", "arguments", "[", "'flavour'", "]", ")", ")", "{", "case", "'goldilocks'", ":", "$", "renderingData", "=", "$", "this", "->", "runGoldilocks", "(", "$", "doc", ",", "$", "engine", ")", ";", "break", ";", "case", "'xhtml'", ":", "$", "renderingData", "=", "$", "this", "->", "runXhtml", "(", "$", "doc", ",", "$", "engine", ")", ";", "break", ";", "}", "// Add final new line?", "$", "nl", "=", "false", ";", "if", "(", "$", "arguments", "[", "'document'", "]", "!==", "true", "&&", "$", "arguments", "[", "'format'", "]", "!==", "true", ")", "{", "$", "nl", "=", "true", ";", "}", "$", "this", "->", "out", "(", "$", "renderingData", ",", "$", "nl", ")", ";", "$", "this", "->", "success", "(", "\"QTI XML file successfully rendered.\"", ")", ";", "}", "catch", "(", "XmlStorageException", "$", "e", ")", "{", "switch", "(", "$", "e", "->", "getCode", "(", ")", ")", "{", "case", "XmlStorageException", "::", "READ", ":", "$", "msg", "=", "\"An error occured while reading QTI file '${source}'.\\nThe system returned the following error:\\n\"", ";", "$", "msg", ".=", "ExceptionUtils", "::", "formatMessage", "(", "$", "e", ")", ";", "$", "this", "->", "fail", "(", "$", "msg", ")", ";", "break", ";", "case", "XmlStorageException", "::", "XSD_VALIDATION", ":", "$", "msg", "=", "\"The QTI file '${source}' is invalid against XML Schema.\\nThe system returned the following error:\\n\"", ";", "$", "msg", ".=", "ExceptionUtils", "::", "formatMessage", "(", "$", "e", ")", ";", "$", "this", "->", "fail", "(", "$", "msg", ")", ";", "break", ";", "case", "XmlStorageException", "::", "VERSION", ":", "$", "msg", "=", "\"The QTI version of file '${source}' could not be detected.\"", ";", "$", "this", "->", "fail", "(", "$", "msg", ")", ";", "break", ";", "default", ":", "$", "msg", "=", "\"An fatal error occured while reading QTI file '${source}'.\"", ";", "$", "this", "->", "fail", "(", "$", "msg", ")", ";", "break", ";", "}", "}", "}" ]
Renders a QTI XML File into another flavour. This implementations considers that all necessary checks about arguments and their values were performed in \qtism\cli\Render::checkArguments(). @see \qtism\cli\Cli::run() @see \qtism\cli\Render::checkArguments()
[ "Renders", "a", "QTI", "XML", "File", "into", "another", "flavour", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/cli/Render.php#L170-L228
oat-sa/qti-sdk
src/qtism/cli/Render.php
Render.runGoldilocks
private function runGoldilocks(XmlDocument $doc, GoldilocksRenderingEngine $renderer) { $arguments = $this->getArguments(); $profile = $arguments['flavour']; $xml = $renderer->render($doc->getDocumentComponent()); $header = ''; $footer = ''; $indent = ''; $nl = ''; if ($arguments['format'] === true) { $xml->formatOutput = true; $indent .= "\x20\x20"; $nl .= "\n"; } if ($arguments['document'] === true) { $header .= "<!doctype html>\n"; } $xpath = new DOMXPath($xml); $assessmentItemElts = $xpath->query("//div[contains(@class, 'qti-assessmentItem')]"); if ($assessmentItemElts->length > 0 && $arguments['document'] === true) { $rootComponent = $doc->getDocumentComponent(); $htmlAttributes = array(); // Take the content of <assessmentItem> and put it into <html>. $attributes = $assessmentItemElts->item(0)->attributes; foreach ($attributes as $name => $attr) { $htmlAttributes[$name] = $name . '="'. XmlUtils::escapeXmlSpecialChars($attr->value, true) . '"'; } while ($attributes->length > 0) { $assessmentItemElts->item(0)->removeAttribute($attributes->item(0)->name); } $header .= "<html " . implode(' ', $htmlAttributes) . ">${nl}"; $header .= "${indent}<head>${nl}"; $header .= "${indent}${indent}<meta charset=\"utf-8\">${nl}"; $header .= "${indent}${indent}<title>" . XmlUtils::escapeXmlSpecialChars($rootComponent->getTitle()) . "</title>${nl}"; $header .= "${indent}${indent}" . $renderer->getStylesheets()->ownerDocument->saveXML($renderer->getStylesheets()); $header .= "${indent}</head>${nl}"; $itemBodyElts = $xpath->query("//div[contains(@class, 'qti-itemBody')]"); if ($itemBodyElts->length > 0) { $body = $xml->saveXml($itemBodyElts->item(0)); $body = substr($body, strlen('<div>')); $body = substr($body, 0, strlen('</div>') * -1); $body = "<body ${body}</body>${nl}"; } else { $body = $xml->saveXml($xml->documentElement) . "${nl}"; } if ($arguments['document'] === true) { $footer = "</html>\n"; } } else { $body = $xml->saveXml($xml->documentElement) . "${nl}"; } // Indent body... $indentBody = ''; if ($arguments['document'] === null) { $indent = ''; } foreach (preg_split('/\n|\r/u', $body, -1, PREG_SPLIT_NO_EMPTY) as $bodyLine) { // do stuff with $line $indentBody .= "${indent}${bodyLine}${nl}"; } $body = $indentBody; return "{$header}{$body}{$footer}"; }
php
private function runGoldilocks(XmlDocument $doc, GoldilocksRenderingEngine $renderer) { $arguments = $this->getArguments(); $profile = $arguments['flavour']; $xml = $renderer->render($doc->getDocumentComponent()); $header = ''; $footer = ''; $indent = ''; $nl = ''; if ($arguments['format'] === true) { $xml->formatOutput = true; $indent .= "\x20\x20"; $nl .= "\n"; } if ($arguments['document'] === true) { $header .= "<!doctype html>\n"; } $xpath = new DOMXPath($xml); $assessmentItemElts = $xpath->query("//div[contains(@class, 'qti-assessmentItem')]"); if ($assessmentItemElts->length > 0 && $arguments['document'] === true) { $rootComponent = $doc->getDocumentComponent(); $htmlAttributes = array(); // Take the content of <assessmentItem> and put it into <html>. $attributes = $assessmentItemElts->item(0)->attributes; foreach ($attributes as $name => $attr) { $htmlAttributes[$name] = $name . '="'. XmlUtils::escapeXmlSpecialChars($attr->value, true) . '"'; } while ($attributes->length > 0) { $assessmentItemElts->item(0)->removeAttribute($attributes->item(0)->name); } $header .= "<html " . implode(' ', $htmlAttributes) . ">${nl}"; $header .= "${indent}<head>${nl}"; $header .= "${indent}${indent}<meta charset=\"utf-8\">${nl}"; $header .= "${indent}${indent}<title>" . XmlUtils::escapeXmlSpecialChars($rootComponent->getTitle()) . "</title>${nl}"; $header .= "${indent}${indent}" . $renderer->getStylesheets()->ownerDocument->saveXML($renderer->getStylesheets()); $header .= "${indent}</head>${nl}"; $itemBodyElts = $xpath->query("//div[contains(@class, 'qti-itemBody')]"); if ($itemBodyElts->length > 0) { $body = $xml->saveXml($itemBodyElts->item(0)); $body = substr($body, strlen('<div>')); $body = substr($body, 0, strlen('</div>') * -1); $body = "<body ${body}</body>${nl}"; } else { $body = $xml->saveXml($xml->documentElement) . "${nl}"; } if ($arguments['document'] === true) { $footer = "</html>\n"; } } else { $body = $xml->saveXml($xml->documentElement) . "${nl}"; } // Indent body... $indentBody = ''; if ($arguments['document'] === null) { $indent = ''; } foreach (preg_split('/\n|\r/u', $body, -1, PREG_SPLIT_NO_EMPTY) as $bodyLine) { // do stuff with $line $indentBody .= "${indent}${bodyLine}${nl}"; } $body = $indentBody; return "{$header}{$body}{$footer}"; }
[ "private", "function", "runGoldilocks", "(", "XmlDocument", "$", "doc", ",", "GoldilocksRenderingEngine", "$", "renderer", ")", "{", "$", "arguments", "=", "$", "this", "->", "getArguments", "(", ")", ";", "$", "profile", "=", "$", "arguments", "[", "'flavour'", "]", ";", "$", "xml", "=", "$", "renderer", "->", "render", "(", "$", "doc", "->", "getDocumentComponent", "(", ")", ")", ";", "$", "header", "=", "''", ";", "$", "footer", "=", "''", ";", "$", "indent", "=", "''", ";", "$", "nl", "=", "''", ";", "if", "(", "$", "arguments", "[", "'format'", "]", "===", "true", ")", "{", "$", "xml", "->", "formatOutput", "=", "true", ";", "$", "indent", ".=", "\"\\x20\\x20\"", ";", "$", "nl", ".=", "\"\\n\"", ";", "}", "if", "(", "$", "arguments", "[", "'document'", "]", "===", "true", ")", "{", "$", "header", ".=", "\"<!doctype html>\\n\"", ";", "}", "$", "xpath", "=", "new", "DOMXPath", "(", "$", "xml", ")", ";", "$", "assessmentItemElts", "=", "$", "xpath", "->", "query", "(", "\"//div[contains(@class, 'qti-assessmentItem')]\"", ")", ";", "if", "(", "$", "assessmentItemElts", "->", "length", ">", "0", "&&", "$", "arguments", "[", "'document'", "]", "===", "true", ")", "{", "$", "rootComponent", "=", "$", "doc", "->", "getDocumentComponent", "(", ")", ";", "$", "htmlAttributes", "=", "array", "(", ")", ";", "// Take the content of <assessmentItem> and put it into <html>.", "$", "attributes", "=", "$", "assessmentItemElts", "->", "item", "(", "0", ")", "->", "attributes", ";", "foreach", "(", "$", "attributes", "as", "$", "name", "=>", "$", "attr", ")", "{", "$", "htmlAttributes", "[", "$", "name", "]", "=", "$", "name", ".", "'=\"'", ".", "XmlUtils", "::", "escapeXmlSpecialChars", "(", "$", "attr", "->", "value", ",", "true", ")", ".", "'\"'", ";", "}", "while", "(", "$", "attributes", "->", "length", ">", "0", ")", "{", "$", "assessmentItemElts", "->", "item", "(", "0", ")", "->", "removeAttribute", "(", "$", "attributes", "->", "item", "(", "0", ")", "->", "name", ")", ";", "}", "$", "header", ".=", "\"<html \"", ".", "implode", "(", "' '", ",", "$", "htmlAttributes", ")", ".", "\">${nl}\"", ";", "$", "header", ".=", "\"${indent}<head>${nl}\"", ";", "$", "header", ".=", "\"${indent}${indent}<meta charset=\\\"utf-8\\\">${nl}\"", ";", "$", "header", ".=", "\"${indent}${indent}<title>\"", ".", "XmlUtils", "::", "escapeXmlSpecialChars", "(", "$", "rootComponent", "->", "getTitle", "(", ")", ")", ".", "\"</title>${nl}\"", ";", "$", "header", ".=", "\"${indent}${indent}\"", ".", "$", "renderer", "->", "getStylesheets", "(", ")", "->", "ownerDocument", "->", "saveXML", "(", "$", "renderer", "->", "getStylesheets", "(", ")", ")", ";", "$", "header", ".=", "\"${indent}</head>${nl}\"", ";", "$", "itemBodyElts", "=", "$", "xpath", "->", "query", "(", "\"//div[contains(@class, 'qti-itemBody')]\"", ")", ";", "if", "(", "$", "itemBodyElts", "->", "length", ">", "0", ")", "{", "$", "body", "=", "$", "xml", "->", "saveXml", "(", "$", "itemBodyElts", "->", "item", "(", "0", ")", ")", ";", "$", "body", "=", "substr", "(", "$", "body", ",", "strlen", "(", "'<div>'", ")", ")", ";", "$", "body", "=", "substr", "(", "$", "body", ",", "0", ",", "strlen", "(", "'</div>'", ")", "*", "-", "1", ")", ";", "$", "body", "=", "\"<body ${body}</body>${nl}\"", ";", "}", "else", "{", "$", "body", "=", "$", "xml", "->", "saveXml", "(", "$", "xml", "->", "documentElement", ")", ".", "\"${nl}\"", ";", "}", "if", "(", "$", "arguments", "[", "'document'", "]", "===", "true", ")", "{", "$", "footer", "=", "\"</html>\\n\"", ";", "}", "}", "else", "{", "$", "body", "=", "$", "xml", "->", "saveXml", "(", "$", "xml", "->", "documentElement", ")", ".", "\"${nl}\"", ";", "}", "// Indent body...", "$", "indentBody", "=", "''", ";", "if", "(", "$", "arguments", "[", "'document'", "]", "===", "null", ")", "{", "$", "indent", "=", "''", ";", "}", "foreach", "(", "preg_split", "(", "'/\\n|\\r/u'", ",", "$", "body", ",", "-", "1", ",", "PREG_SPLIT_NO_EMPTY", ")", "as", "$", "bodyLine", ")", "{", "// do stuff with $line", "$", "indentBody", ".=", "\"${indent}${bodyLine}${nl}\"", ";", "}", "$", "body", "=", "$", "indentBody", ";", "return", "\"{$header}{$body}{$footer}\"", ";", "}" ]
Run the rendering behaviour related to the "Goldilocks" flavour. @param \qtism\data\storage\xml\XmlDocument $doc the QTI XML document to be rendered. @param \qtism\runtime\rendering\markup\goldilocks\GoldilocksRenderingEngine $renderer
[ "Run", "the", "rendering", "behaviour", "related", "to", "the", "Goldilocks", "flavour", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/cli/Render.php#L236-L314
oat-sa/qti-sdk
src/qtism/cli/Render.php
Render.runXhtml
private function runXhtml(XmlDocument $doc, XhtmlRenderingEngine $renderer) { $arguments = $this->getArguments(); $profile = $arguments['flavour']; $xml = $renderer->render($doc->getDocumentComponent()); $header = ''; $footer = ''; $indent = ''; $nl = ''; if ($arguments['format'] === true) { $xml->formatOutput = true; $indent .= "\x20\x20"; $nl .= "\n"; } if ($arguments['document'] === true) { $rootComponent = $doc->getDocumentComponent(); $title = ''; if ($rootComponent->getQtiClassName() === 'assessmentItem') { $title = XmlUtils::escapeXmlSpecialChars($rootComponent->getTitle()); } $header .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; $header .= "<html>${nl}"; $header .= "${indent}<head>${nl}"; $header .= "${indent}${indent}<meta charset=\"utf-8\">${nl}"; if (empty($title) !== false) { $header .= "${indent}${indent}<title>" . $title . "</title>${nl}"; } $header .= "${indent}${indent}" . $renderer->getStylesheets()->ownerDocument->saveXML($renderer->getStylesheets()); $header .= "${indent}</head>${nl}"; $header .= "${indent}<body>${nl}"; $footer = "${indent}</body>${nl}"; $footer .= "</html>\n"; } $body = $xml->saveXml($xml->documentElement) . "${nl}"; // Indent body... $indentBody = ''; if ($arguments['document'] === null) { $indent = ''; } foreach (preg_split('/\n|\r/u', $body, -1, PREG_SPLIT_NO_EMPTY) as $bodyLine) { // do stuff with $line $indentBody .= "${indent}${indent}${bodyLine}${nl}"; } $body = $indentBody; return "{$header}{$indentBody}{$footer}"; }
php
private function runXhtml(XmlDocument $doc, XhtmlRenderingEngine $renderer) { $arguments = $this->getArguments(); $profile = $arguments['flavour']; $xml = $renderer->render($doc->getDocumentComponent()); $header = ''; $footer = ''; $indent = ''; $nl = ''; if ($arguments['format'] === true) { $xml->formatOutput = true; $indent .= "\x20\x20"; $nl .= "\n"; } if ($arguments['document'] === true) { $rootComponent = $doc->getDocumentComponent(); $title = ''; if ($rootComponent->getQtiClassName() === 'assessmentItem') { $title = XmlUtils::escapeXmlSpecialChars($rootComponent->getTitle()); } $header .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"; $header .= "<html>${nl}"; $header .= "${indent}<head>${nl}"; $header .= "${indent}${indent}<meta charset=\"utf-8\">${nl}"; if (empty($title) !== false) { $header .= "${indent}${indent}<title>" . $title . "</title>${nl}"; } $header .= "${indent}${indent}" . $renderer->getStylesheets()->ownerDocument->saveXML($renderer->getStylesheets()); $header .= "${indent}</head>${nl}"; $header .= "${indent}<body>${nl}"; $footer = "${indent}</body>${nl}"; $footer .= "</html>\n"; } $body = $xml->saveXml($xml->documentElement) . "${nl}"; // Indent body... $indentBody = ''; if ($arguments['document'] === null) { $indent = ''; } foreach (preg_split('/\n|\r/u', $body, -1, PREG_SPLIT_NO_EMPTY) as $bodyLine) { // do stuff with $line $indentBody .= "${indent}${indent}${bodyLine}${nl}"; } $body = $indentBody; return "{$header}{$indentBody}{$footer}"; }
[ "private", "function", "runXhtml", "(", "XmlDocument", "$", "doc", ",", "XhtmlRenderingEngine", "$", "renderer", ")", "{", "$", "arguments", "=", "$", "this", "->", "getArguments", "(", ")", ";", "$", "profile", "=", "$", "arguments", "[", "'flavour'", "]", ";", "$", "xml", "=", "$", "renderer", "->", "render", "(", "$", "doc", "->", "getDocumentComponent", "(", ")", ")", ";", "$", "header", "=", "''", ";", "$", "footer", "=", "''", ";", "$", "indent", "=", "''", ";", "$", "nl", "=", "''", ";", "if", "(", "$", "arguments", "[", "'format'", "]", "===", "true", ")", "{", "$", "xml", "->", "formatOutput", "=", "true", ";", "$", "indent", ".=", "\"\\x20\\x20\"", ";", "$", "nl", ".=", "\"\\n\"", ";", "}", "if", "(", "$", "arguments", "[", "'document'", "]", "===", "true", ")", "{", "$", "rootComponent", "=", "$", "doc", "->", "getDocumentComponent", "(", ")", ";", "$", "title", "=", "''", ";", "if", "(", "$", "rootComponent", "->", "getQtiClassName", "(", ")", "===", "'assessmentItem'", ")", "{", "$", "title", "=", "XmlUtils", "::", "escapeXmlSpecialChars", "(", "$", "rootComponent", "->", "getTitle", "(", ")", ")", ";", "}", "$", "header", ".=", "\"<!DOCTYPE html PUBLIC \\\"-//W3C//DTD XHTML 1.0 Transitional//EN\\\"\\n\\\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\\\">\\n\"", ";", "$", "header", ".=", "\"<html>${nl}\"", ";", "$", "header", ".=", "\"${indent}<head>${nl}\"", ";", "$", "header", ".=", "\"${indent}${indent}<meta charset=\\\"utf-8\\\">${nl}\"", ";", "if", "(", "empty", "(", "$", "title", ")", "!==", "false", ")", "{", "$", "header", ".=", "\"${indent}${indent}<title>\"", ".", "$", "title", ".", "\"</title>${nl}\"", ";", "}", "$", "header", ".=", "\"${indent}${indent}\"", ".", "$", "renderer", "->", "getStylesheets", "(", ")", "->", "ownerDocument", "->", "saveXML", "(", "$", "renderer", "->", "getStylesheets", "(", ")", ")", ";", "$", "header", ".=", "\"${indent}</head>${nl}\"", ";", "$", "header", ".=", "\"${indent}<body>${nl}\"", ";", "$", "footer", "=", "\"${indent}</body>${nl}\"", ";", "$", "footer", ".=", "\"</html>\\n\"", ";", "}", "$", "body", "=", "$", "xml", "->", "saveXml", "(", "$", "xml", "->", "documentElement", ")", ".", "\"${nl}\"", ";", "// Indent body...", "$", "indentBody", "=", "''", ";", "if", "(", "$", "arguments", "[", "'document'", "]", "===", "null", ")", "{", "$", "indent", "=", "''", ";", "}", "foreach", "(", "preg_split", "(", "'/\\n|\\r/u'", ",", "$", "body", ",", "-", "1", ",", "PREG_SPLIT_NO_EMPTY", ")", "as", "$", "bodyLine", ")", "{", "// do stuff with $line", "$", "indentBody", ".=", "\"${indent}${indent}${bodyLine}${nl}\"", ";", "}", "$", "body", "=", "$", "indentBody", ";", "return", "\"{$header}{$indentBody}{$footer}\"", ";", "}" ]
Run the rendering behaviour related to the "XHTML" flavour. @param \qtism\data\storage\xml\XmlDocument $doc The QTI XML document to be rendered. @param \qtism\runtime\rendering\markup\xhtml\XhtmlRenderingEngine $renderer @return string The raw rendering data.
[ "Run", "the", "rendering", "behaviour", "related", "to", "the", "XHTML", "flavour", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/cli/Render.php#L323-L383
oat-sa/qti-sdk
src/qtism/cli/Render.php
Render.instantiateEngine
private function instantiateEngine() { $arguments = $this->getArguments(); $engine = null; switch (strtolower($arguments['flavour'])) { case 'goldilocks': $engine = new GoldilocksRenderingEngine(); break; case 'xhtml': $engine = new XhtmlRenderingEngine(); break; } if ($arguments['xmlbase'] === 'process') { $engine->setXmlBasePolicy(AbstractMarkupRenderingEngine::XMLBASE_PROCESS); } elseif ($arguments['xmlbase'] === 'keep') { $engine->setXmlBasePolicy(AbstractMarkupRenderingEngine::XMLBASE_KEEP); } elseif ($arguments['xmlbase'] === 'ignore') { $engine->setXmlBasePolicy(AbstractMarkupRenderingEngine::XMLBASE_IGNORE); } if ($arguments['document'] === true) { $engine->setStylesheetPolicy(AbstractMarkupRenderingEngine::STYLESHEET_SEPARATE); } if ($arguments['csshierarchy'] === true) { $engine->setCssClassPolicy(AbstractMarkupRenderingEngine::CSSCLASS_ABSTRACT); } return $engine; }
php
private function instantiateEngine() { $arguments = $this->getArguments(); $engine = null; switch (strtolower($arguments['flavour'])) { case 'goldilocks': $engine = new GoldilocksRenderingEngine(); break; case 'xhtml': $engine = new XhtmlRenderingEngine(); break; } if ($arguments['xmlbase'] === 'process') { $engine->setXmlBasePolicy(AbstractMarkupRenderingEngine::XMLBASE_PROCESS); } elseif ($arguments['xmlbase'] === 'keep') { $engine->setXmlBasePolicy(AbstractMarkupRenderingEngine::XMLBASE_KEEP); } elseif ($arguments['xmlbase'] === 'ignore') { $engine->setXmlBasePolicy(AbstractMarkupRenderingEngine::XMLBASE_IGNORE); } if ($arguments['document'] === true) { $engine->setStylesheetPolicy(AbstractMarkupRenderingEngine::STYLESHEET_SEPARATE); } if ($arguments['csshierarchy'] === true) { $engine->setCssClassPolicy(AbstractMarkupRenderingEngine::CSSCLASS_ABSTRACT); } return $engine; }
[ "private", "function", "instantiateEngine", "(", ")", "{", "$", "arguments", "=", "$", "this", "->", "getArguments", "(", ")", ";", "$", "engine", "=", "null", ";", "switch", "(", "strtolower", "(", "$", "arguments", "[", "'flavour'", "]", ")", ")", "{", "case", "'goldilocks'", ":", "$", "engine", "=", "new", "GoldilocksRenderingEngine", "(", ")", ";", "break", ";", "case", "'xhtml'", ":", "$", "engine", "=", "new", "XhtmlRenderingEngine", "(", ")", ";", "break", ";", "}", "if", "(", "$", "arguments", "[", "'xmlbase'", "]", "===", "'process'", ")", "{", "$", "engine", "->", "setXmlBasePolicy", "(", "AbstractMarkupRenderingEngine", "::", "XMLBASE_PROCESS", ")", ";", "}", "elseif", "(", "$", "arguments", "[", "'xmlbase'", "]", "===", "'keep'", ")", "{", "$", "engine", "->", "setXmlBasePolicy", "(", "AbstractMarkupRenderingEngine", "::", "XMLBASE_KEEP", ")", ";", "}", "elseif", "(", "$", "arguments", "[", "'xmlbase'", "]", "===", "'ignore'", ")", "{", "$", "engine", "->", "setXmlBasePolicy", "(", "AbstractMarkupRenderingEngine", "::", "XMLBASE_IGNORE", ")", ";", "}", "if", "(", "$", "arguments", "[", "'document'", "]", "===", "true", ")", "{", "$", "engine", "->", "setStylesheetPolicy", "(", "AbstractMarkupRenderingEngine", "::", "STYLESHEET_SEPARATE", ")", ";", "}", "if", "(", "$", "arguments", "[", "'csshierarchy'", "]", "===", "true", ")", "{", "$", "engine", "->", "setCssClassPolicy", "(", "AbstractMarkupRenderingEngine", "::", "CSSCLASS_ABSTRACT", ")", ";", "}", "return", "$", "engine", ";", "}" ]
Instantiate an appropriate Rendering Engine. The instantiated Rendering Engine implementation will depend on the "flavour" CLI argument. @return \qtism\runtime\rendering\markup\AbstractMarkupRenderingEngine
[ "Instantiate", "an", "appropriate", "Rendering", "Engine", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/cli/Render.php#L393-L424
oat-sa/qti-sdk
src/qtism/data/storage/xml/marshalling/UploadInteractionMarshaller.php
UploadInteractionMarshaller.unmarshall
protected function unmarshall(DOMElement $element) { if (($responseIdentifier = $this->getDOMElementAttributeAs($element, 'responseIdentifier')) !== null) { $component = new UploadInteraction($responseIdentifier); $promptElts = $this->getChildElementsByTagName($element, 'prompt'); if (count($promptElts) > 0) { $promptElt = $promptElts[0]; $prompt = $this->getMarshallerFactory()->createMarshaller($promptElt)->unmarshall($promptElt); $component->setPrompt($prompt); } if (($type = $this->getDOMElementAttributeAs($element, 'type')) !== null) { $component->setType($type); } if (($xmlBase = self::getXmlBase($element)) !== false) { $component->setXmlBase($xmlBase); } $this->fillBodyElement($component, $element); return $component; } else { $msg = "The mandatory 'responseIdentifier' attribute is missing from the 'uploadInteraction' element."; throw new UnmarshallingException($msg, $element); } }
php
protected function unmarshall(DOMElement $element) { if (($responseIdentifier = $this->getDOMElementAttributeAs($element, 'responseIdentifier')) !== null) { $component = new UploadInteraction($responseIdentifier); $promptElts = $this->getChildElementsByTagName($element, 'prompt'); if (count($promptElts) > 0) { $promptElt = $promptElts[0]; $prompt = $this->getMarshallerFactory()->createMarshaller($promptElt)->unmarshall($promptElt); $component->setPrompt($prompt); } if (($type = $this->getDOMElementAttributeAs($element, 'type')) !== null) { $component->setType($type); } if (($xmlBase = self::getXmlBase($element)) !== false) { $component->setXmlBase($xmlBase); } $this->fillBodyElement($component, $element); return $component; } else { $msg = "The mandatory 'responseIdentifier' attribute is missing from the 'uploadInteraction' element."; throw new UnmarshallingException($msg, $element); } }
[ "protected", "function", "unmarshall", "(", "DOMElement", "$", "element", ")", "{", "if", "(", "(", "$", "responseIdentifier", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'responseIdentifier'", ")", ")", "!==", "null", ")", "{", "$", "component", "=", "new", "UploadInteraction", "(", "$", "responseIdentifier", ")", ";", "$", "promptElts", "=", "$", "this", "->", "getChildElementsByTagName", "(", "$", "element", ",", "'prompt'", ")", ";", "if", "(", "count", "(", "$", "promptElts", ")", ">", "0", ")", "{", "$", "promptElt", "=", "$", "promptElts", "[", "0", "]", ";", "$", "prompt", "=", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "promptElt", ")", "->", "unmarshall", "(", "$", "promptElt", ")", ";", "$", "component", "->", "setPrompt", "(", "$", "prompt", ")", ";", "}", "if", "(", "(", "$", "type", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'type'", ")", ")", "!==", "null", ")", "{", "$", "component", "->", "setType", "(", "$", "type", ")", ";", "}", "if", "(", "(", "$", "xmlBase", "=", "self", "::", "getXmlBase", "(", "$", "element", ")", ")", "!==", "false", ")", "{", "$", "component", "->", "setXmlBase", "(", "$", "xmlBase", ")", ";", "}", "$", "this", "->", "fillBodyElement", "(", "$", "component", ",", "$", "element", ")", ";", "return", "$", "component", ";", "}", "else", "{", "$", "msg", "=", "\"The mandatory 'responseIdentifier' attribute is missing from the 'uploadInteraction' element.\"", ";", "throw", "new", "UnmarshallingException", "(", "$", "msg", ",", "$", "element", ")", ";", "}", "}" ]
Unmarshall a DOMElement object corresponding to an uploadInteraction element. @param \DOMElement $element A DOMElement object. @return \qtism\data\QtiComponent An UploadInteraction object. @throws \qtism\data\storage\xml\marshalling\UnmarshallingException
[ "Unmarshall", "a", "DOMElement", "object", "corresponding", "to", "an", "uploadInteraction", "element", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/UploadInteractionMarshaller.php#L72-L101
oat-sa/qti-sdk
src/qtism/runtime/expressions/operators/DurationGTEProcessor.php
DurationGTEProcessor.process
public function process() { $operands = $this->getOperands(); if ($operands->containsNull() === true) { return null; } if ($operands->exclusivelySingle() === false) { $msg = "The DurationGTE operator only accepts operands with a single cardinality."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY); } if ($operands->exclusivelyDuration() === false) { $msg = "The DurationGTE operator only accepts operands with a duration baseType."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE); } return new QtiBoolean($operands[0]->longerThanOrEquals($operands[1])); }
php
public function process() { $operands = $this->getOperands(); if ($operands->containsNull() === true) { return null; } if ($operands->exclusivelySingle() === false) { $msg = "The DurationGTE operator only accepts operands with a single cardinality."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY); } if ($operands->exclusivelyDuration() === false) { $msg = "The DurationGTE operator only accepts operands with a duration baseType."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE); } return new QtiBoolean($operands[0]->longerThanOrEquals($operands[1])); }
[ "public", "function", "process", "(", ")", "{", "$", "operands", "=", "$", "this", "->", "getOperands", "(", ")", ";", "if", "(", "$", "operands", "->", "containsNull", "(", ")", "===", "true", ")", "{", "return", "null", ";", "}", "if", "(", "$", "operands", "->", "exclusivelySingle", "(", ")", "===", "false", ")", "{", "$", "msg", "=", "\"The DurationGTE operator only accepts operands with a single cardinality.\"", ";", "throw", "new", "OperatorProcessingException", "(", "$", "msg", ",", "$", "this", ",", "OperatorProcessingException", "::", "WRONG_CARDINALITY", ")", ";", "}", "if", "(", "$", "operands", "->", "exclusivelyDuration", "(", ")", "===", "false", ")", "{", "$", "msg", "=", "\"The DurationGTE operator only accepts operands with a duration baseType.\"", ";", "throw", "new", "OperatorProcessingException", "(", "$", "msg", ",", "$", "this", ",", "OperatorProcessingException", "::", "WRONG_BASETYPE", ")", ";", "}", "return", "new", "QtiBoolean", "(", "$", "operands", "[", "0", "]", "->", "longerThanOrEquals", "(", "$", "operands", "[", "1", "]", ")", ")", ";", "}" ]
Process the DurationGTE operator. @return boolean|null A boolean with a value of true if the first duration is longer or equal to the second, otherwise false. If either sub-expression is NULL, the result of the operator is NULL. @throws \qtism\runtime\expressions\operators\OperatorProcessingException
[ "Process", "the", "DurationGTE", "operator", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/DurationGTEProcessor.php#L54-L73
oat-sa/qti-sdk
src/qtism/data/expressions/operators/EqualRounded.php
EqualRounded.setRoundingMode
public function setRoundingMode($roundingMode) { if (in_array($roundingMode, RoundingMode::asArray())) { $this->roundingMode = $roundingMode; } else { $msg = "The roundingMode argument must be a value from the RoundingMode enumeration, '" . $roundingMode . "' given."; throw new InvalidArgumentException($msg); } }
php
public function setRoundingMode($roundingMode) { if (in_array($roundingMode, RoundingMode::asArray())) { $this->roundingMode = $roundingMode; } else { $msg = "The roundingMode argument must be a value from the RoundingMode enumeration, '" . $roundingMode . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setRoundingMode", "(", "$", "roundingMode", ")", "{", "if", "(", "in_array", "(", "$", "roundingMode", ",", "RoundingMode", "::", "asArray", "(", ")", ")", ")", "{", "$", "this", "->", "roundingMode", "=", "$", "roundingMode", ";", "}", "else", "{", "$", "msg", "=", "\"The roundingMode argument must be a value from the RoundingMode enumeration, '\"", ".", "$", "roundingMode", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set the rounding mode. @param integer $roundingMode A value from the RoundingMode enumeration. @throws \InvalidArgumentException If $roundingMode is not a value from the RoundingMode enumeration.
[ "Set", "the", "rounding", "mode", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/expressions/operators/EqualRounded.php#L87-L95