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/expressions/operators/EqualRounded.php
EqualRounded.setFigures
public function setFigures($figures) { if (is_int($figures) || (gettype($figures) === 'string' && Format::isVariableRef($figures))) { $this->figures = $figures; } else { $msg = "The figures argument must be an integer or a variable reference, '" . $figures . "' given."; throw new InvalidArgumentException($msg); } }
php
public function setFigures($figures) { if (is_int($figures) || (gettype($figures) === 'string' && Format::isVariableRef($figures))) { $this->figures = $figures; } else { $msg = "The figures argument must be an integer or a variable reference, '" . $figures . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setFigures", "(", "$", "figures", ")", "{", "if", "(", "is_int", "(", "$", "figures", ")", "||", "(", "gettype", "(", "$", "figures", ")", "===", "'string'", "&&", "Format", "::", "isVariableRef", "(", "$", "figures", ")", ")", ")", "{", "$", "this", "->", "figures", "=", "$", "figures", ";", "}", "else", "{", "$", "msg", "=", "\"The figures argument must be an integer or a variable reference, '\"", ".", "$", "figures", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set the number of figures to round to. @param integer|string $figures An integer value or a variable reference. @throws \InvalidArgumentException If $figures is not an integer nor a variable reference.
[ "Set", "the", "number", "of", "figures", "to", "round", "to", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/expressions/operators/EqualRounded.php#L113-L121
oat-sa/qti-sdk
src/qtism/runtime/rendering/markup/AbstractMarkupRenderingEngine.php
AbstractMarkupRenderingEngine.createFinalRendering
protected function createFinalRendering(QtiComponent $component) { $dom = $this->getDocument(); if (($last = $this->getLastRendering()) !== null) { $dom->appendChild($last); } // If we are rendering an item, let's try to find some Math to // for template variable mapping. if ($component instanceof AssessmentItem && count($templateDeclarations = $component->getTemplateDeclarations()) > 0) { $xpath = new DOMXPath($dom); $xpath->registerNamespace('m', 'http://www.w3.org/1998/Math/MathML'); $maths = $xpath->query('//m:math|//math'); if ($maths->length > 0) { $printedVariableRenderer = new PrintedVariableRenderer($this); foreach ($templateDeclarations as $templateDeclaration) { if ($templateDeclaration->isMathVariable() === true) { $templateIdentifier = $templateDeclaration->getIdentifier(); foreach ($maths as $math) { // Find <mi> and <ci> elements. foreach ($xpath->query(".//m:mi[text() = '${templateIdentifier}']|.//m:ci[text() = '${templateIdentifier}']|.//mi[text() = '${templateIdentifier}']|.//ci[text() = '${templateIdentifier}']", $math) as $mathElement) { $localElementName = ($mathElement->localName === 'mi') ? 'mn' : 'cn'; $newMathElement = $mathElement->ownerDocument->createElement($localElementName); $printedVariable = new PrintedVariable($templateIdentifier); $printedVariableFragment = $printedVariableRenderer->render($printedVariable); if ($this->getPrintedVariablePolicy() === self::CONTEXT_STATIC) { foreach ($printedVariableFragment->childNodes as $node) { $newMathElement->appendChild($node); $mathElement->parentNode->replaceChild($newMathElement, $mathElement); } } else if ($this->getPrintedVariablePolicy() === self::CONTEXT_AWARE) { $newMathElement->appendChild($newMathElement->ownerDocument->createTextNode($printedVariableFragment->firstChild->nodeValue)); $mathElement->parentNode->replaceChild($newMathElement, $mathElement); } else { foreach ($printedVariableFragment->firstChild->childNodes as $node) { $newMathElement->appendChild($node); $mathElement->parentNode->replaceChild($newMathElement, $mathElement); } } } } } } } } return $dom; }
php
protected function createFinalRendering(QtiComponent $component) { $dom = $this->getDocument(); if (($last = $this->getLastRendering()) !== null) { $dom->appendChild($last); } // If we are rendering an item, let's try to find some Math to // for template variable mapping. if ($component instanceof AssessmentItem && count($templateDeclarations = $component->getTemplateDeclarations()) > 0) { $xpath = new DOMXPath($dom); $xpath->registerNamespace('m', 'http://www.w3.org/1998/Math/MathML'); $maths = $xpath->query('//m:math|//math'); if ($maths->length > 0) { $printedVariableRenderer = new PrintedVariableRenderer($this); foreach ($templateDeclarations as $templateDeclaration) { if ($templateDeclaration->isMathVariable() === true) { $templateIdentifier = $templateDeclaration->getIdentifier(); foreach ($maths as $math) { // Find <mi> and <ci> elements. foreach ($xpath->query(".//m:mi[text() = '${templateIdentifier}']|.//m:ci[text() = '${templateIdentifier}']|.//mi[text() = '${templateIdentifier}']|.//ci[text() = '${templateIdentifier}']", $math) as $mathElement) { $localElementName = ($mathElement->localName === 'mi') ? 'mn' : 'cn'; $newMathElement = $mathElement->ownerDocument->createElement($localElementName); $printedVariable = new PrintedVariable($templateIdentifier); $printedVariableFragment = $printedVariableRenderer->render($printedVariable); if ($this->getPrintedVariablePolicy() === self::CONTEXT_STATIC) { foreach ($printedVariableFragment->childNodes as $node) { $newMathElement->appendChild($node); $mathElement->parentNode->replaceChild($newMathElement, $mathElement); } } else if ($this->getPrintedVariablePolicy() === self::CONTEXT_AWARE) { $newMathElement->appendChild($newMathElement->ownerDocument->createTextNode($printedVariableFragment->firstChild->nodeValue)); $mathElement->parentNode->replaceChild($newMathElement, $mathElement); } else { foreach ($printedVariableFragment->firstChild->childNodes as $node) { $newMathElement->appendChild($node); $mathElement->parentNode->replaceChild($newMathElement, $mathElement); } } } } } } } } return $dom; }
[ "protected", "function", "createFinalRendering", "(", "QtiComponent", "$", "component", ")", "{", "$", "dom", "=", "$", "this", "->", "getDocument", "(", ")", ";", "if", "(", "(", "$", "last", "=", "$", "this", "->", "getLastRendering", "(", ")", ")", "!==", "null", ")", "{", "$", "dom", "->", "appendChild", "(", "$", "last", ")", ";", "}", "// If we are rendering an item, let's try to find some Math to", "// for template variable mapping. ", "if", "(", "$", "component", "instanceof", "AssessmentItem", "&&", "count", "(", "$", "templateDeclarations", "=", "$", "component", "->", "getTemplateDeclarations", "(", ")", ")", ">", "0", ")", "{", "$", "xpath", "=", "new", "DOMXPath", "(", "$", "dom", ")", ";", "$", "xpath", "->", "registerNamespace", "(", "'m'", ",", "'http://www.w3.org/1998/Math/MathML'", ")", ";", "$", "maths", "=", "$", "xpath", "->", "query", "(", "'//m:math|//math'", ")", ";", "if", "(", "$", "maths", "->", "length", ">", "0", ")", "{", "$", "printedVariableRenderer", "=", "new", "PrintedVariableRenderer", "(", "$", "this", ")", ";", "foreach", "(", "$", "templateDeclarations", "as", "$", "templateDeclaration", ")", "{", "if", "(", "$", "templateDeclaration", "->", "isMathVariable", "(", ")", "===", "true", ")", "{", "$", "templateIdentifier", "=", "$", "templateDeclaration", "->", "getIdentifier", "(", ")", ";", "foreach", "(", "$", "maths", "as", "$", "math", ")", "{", "// Find <mi> and <ci> elements.", "foreach", "(", "$", "xpath", "->", "query", "(", "\".//m:mi[text() = '${templateIdentifier}']|.//m:ci[text() = '${templateIdentifier}']|.//mi[text() = '${templateIdentifier}']|.//ci[text() = '${templateIdentifier}']\"", ",", "$", "math", ")", "as", "$", "mathElement", ")", "{", "$", "localElementName", "=", "(", "$", "mathElement", "->", "localName", "===", "'mi'", ")", "?", "'mn'", ":", "'cn'", ";", "$", "newMathElement", "=", "$", "mathElement", "->", "ownerDocument", "->", "createElement", "(", "$", "localElementName", ")", ";", "$", "printedVariable", "=", "new", "PrintedVariable", "(", "$", "templateIdentifier", ")", ";", "$", "printedVariableFragment", "=", "$", "printedVariableRenderer", "->", "render", "(", "$", "printedVariable", ")", ";", "if", "(", "$", "this", "->", "getPrintedVariablePolicy", "(", ")", "===", "self", "::", "CONTEXT_STATIC", ")", "{", "foreach", "(", "$", "printedVariableFragment", "->", "childNodes", "as", "$", "node", ")", "{", "$", "newMathElement", "->", "appendChild", "(", "$", "node", ")", ";", "$", "mathElement", "->", "parentNode", "->", "replaceChild", "(", "$", "newMathElement", ",", "$", "mathElement", ")", ";", "}", "}", "else", "if", "(", "$", "this", "->", "getPrintedVariablePolicy", "(", ")", "===", "self", "::", "CONTEXT_AWARE", ")", "{", "$", "newMathElement", "->", "appendChild", "(", "$", "newMathElement", "->", "ownerDocument", "->", "createTextNode", "(", "$", "printedVariableFragment", "->", "firstChild", "->", "nodeValue", ")", ")", ";", "$", "mathElement", "->", "parentNode", "->", "replaceChild", "(", "$", "newMathElement", ",", "$", "mathElement", ")", ";", "}", "else", "{", "foreach", "(", "$", "printedVariableFragment", "->", "firstChild", "->", "childNodes", "as", "$", "node", ")", "{", "$", "newMathElement", "->", "appendChild", "(", "$", "node", ")", ";", "$", "mathElement", "->", "parentNode", "->", "replaceChild", "(", "$", "newMathElement", ",", "$", "mathElement", ")", ";", "}", "}", "}", "}", "}", "}", "}", "}", "return", "$", "dom", ";", "}" ]
Create the final rendering of the rendered $component as it must be rendered by the final implementation. @return mixed
[ "Create", "the", "final", "rendering", "of", "the", "rendered", "$component", "as", "it", "must", "be", "rendered", "by", "the", "final", "implementation", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/markup/AbstractMarkupRenderingEngine.php#L561-L612
oat-sa/qti-sdk
src/qtism/runtime/rendering/markup/AbstractMarkupRenderingEngine.php
AbstractMarkupRenderingEngine.processNode
protected function processNode($base = '') { $component = $this->getExploredComponent(); $renderer = $this->getRenderer($component); $rendering = $renderer->render($component, $base); if ($this->mustTemplateFeedbackComponent($component) === true) { $this->templateFeedbackComponent($component, $rendering); } if ($this->mustTemplateRubricBlockComponent($component) === true) { $this->templateRubricBlockComponent($component, $rendering); } if ($this->mustTemplateChoiceComponent($component) === true) { $this->templateChoiceComponent($component, $rendering); } if ($this->mustIncludeChoiceComponent($component) === true) { $this->includeChoiceComponent($component, $rendering); } $this->setLastRendering($rendering); }
php
protected function processNode($base = '') { $component = $this->getExploredComponent(); $renderer = $this->getRenderer($component); $rendering = $renderer->render($component, $base); if ($this->mustTemplateFeedbackComponent($component) === true) { $this->templateFeedbackComponent($component, $rendering); } if ($this->mustTemplateRubricBlockComponent($component) === true) { $this->templateRubricBlockComponent($component, $rendering); } if ($this->mustTemplateChoiceComponent($component) === true) { $this->templateChoiceComponent($component, $rendering); } if ($this->mustIncludeChoiceComponent($component) === true) { $this->includeChoiceComponent($component, $rendering); } $this->setLastRendering($rendering); }
[ "protected", "function", "processNode", "(", "$", "base", "=", "''", ")", "{", "$", "component", "=", "$", "this", "->", "getExploredComponent", "(", ")", ";", "$", "renderer", "=", "$", "this", "->", "getRenderer", "(", "$", "component", ")", ";", "$", "rendering", "=", "$", "renderer", "->", "render", "(", "$", "component", ",", "$", "base", ")", ";", "if", "(", "$", "this", "->", "mustTemplateFeedbackComponent", "(", "$", "component", ")", "===", "true", ")", "{", "$", "this", "->", "templateFeedbackComponent", "(", "$", "component", ",", "$", "rendering", ")", ";", "}", "if", "(", "$", "this", "->", "mustTemplateRubricBlockComponent", "(", "$", "component", ")", "===", "true", ")", "{", "$", "this", "->", "templateRubricBlockComponent", "(", "$", "component", ",", "$", "rendering", ")", ";", "}", "if", "(", "$", "this", "->", "mustTemplateChoiceComponent", "(", "$", "component", ")", "===", "true", ")", "{", "$", "this", "->", "templateChoiceComponent", "(", "$", "component", ",", "$", "rendering", ")", ";", "}", "if", "(", "$", "this", "->", "mustIncludeChoiceComponent", "(", "$", "component", ")", "===", "true", ")", "{", "$", "this", "->", "includeChoiceComponent", "(", "$", "component", ",", "$", "rendering", ")", ";", "}", "$", "this", "->", "setLastRendering", "(", "$", "rendering", ")", ";", "}" ]
Process the current node (Ascending phase). @param string $base the value of xml:base for the node to be processed. @throws RenderingException If an error occurs while processing the node.
[ "Process", "the", "current", "node", "(", "Ascending", "phase", ")", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/markup/AbstractMarkupRenderingEngine.php#L620-L643
oat-sa/qti-sdk
src/qtism/runtime/rendering/markup/AbstractMarkupRenderingEngine.php
AbstractMarkupRenderingEngine.mustIgnoreComponent
protected function mustIgnoreComponent(QtiComponent $component) { // In the list of QTI class names to be ignored? if (in_array($component->getQtiClassName(), $this->getIgnoreClasses()) === true) { return true; } // Context Aware + FeedbackElement OR Context Aware + Choice Templating. elseif ((self::isFeedback($component) && $this->getFeedbackShowHidePolicy() === AbstractMarkupRenderingEngine::CONTEXT_AWARE) || ($component instanceof Choice && $component->hasTemplateIdentifier() === true && $this->getChoiceShowHidePolicy() === AbstractMarkupRenderingEngine::CONTEXT_AWARE)) { $matches = $this->identifierMatches($component); $showHide = $component->getShowHide(); return ($showHide === ShowHide::SHOW) ? !$matches : $matches; } // Context Aware + RubricBlock elseif ($this->getViewPolicy() === AbstractMarkupRenderingEngine::CONTEXT_AWARE && $component instanceof RubricBlock) { $renderingViews = $this->getViews(); $rubricViews = $component->getViews(); // If one of the rendering views matches a single view // in the rubricBlock's view, render! foreach ($renderingViews as $v) { if ($rubricViews->contains($v) === true) { return false; } } return true; } else { return false; } }
php
protected function mustIgnoreComponent(QtiComponent $component) { // In the list of QTI class names to be ignored? if (in_array($component->getQtiClassName(), $this->getIgnoreClasses()) === true) { return true; } // Context Aware + FeedbackElement OR Context Aware + Choice Templating. elseif ((self::isFeedback($component) && $this->getFeedbackShowHidePolicy() === AbstractMarkupRenderingEngine::CONTEXT_AWARE) || ($component instanceof Choice && $component->hasTemplateIdentifier() === true && $this->getChoiceShowHidePolicy() === AbstractMarkupRenderingEngine::CONTEXT_AWARE)) { $matches = $this->identifierMatches($component); $showHide = $component->getShowHide(); return ($showHide === ShowHide::SHOW) ? !$matches : $matches; } // Context Aware + RubricBlock elseif ($this->getViewPolicy() === AbstractMarkupRenderingEngine::CONTEXT_AWARE && $component instanceof RubricBlock) { $renderingViews = $this->getViews(); $rubricViews = $component->getViews(); // If one of the rendering views matches a single view // in the rubricBlock's view, render! foreach ($renderingViews as $v) { if ($rubricViews->contains($v) === true) { return false; } } return true; } else { return false; } }
[ "protected", "function", "mustIgnoreComponent", "(", "QtiComponent", "$", "component", ")", "{", "// In the list of QTI class names to be ignored?", "if", "(", "in_array", "(", "$", "component", "->", "getQtiClassName", "(", ")", ",", "$", "this", "->", "getIgnoreClasses", "(", ")", ")", "===", "true", ")", "{", "return", "true", ";", "}", "// Context Aware + FeedbackElement OR Context Aware + Choice Templating.", "elseif", "(", "(", "self", "::", "isFeedback", "(", "$", "component", ")", "&&", "$", "this", "->", "getFeedbackShowHidePolicy", "(", ")", "===", "AbstractMarkupRenderingEngine", "::", "CONTEXT_AWARE", ")", "||", "(", "$", "component", "instanceof", "Choice", "&&", "$", "component", "->", "hasTemplateIdentifier", "(", ")", "===", "true", "&&", "$", "this", "->", "getChoiceShowHidePolicy", "(", ")", "===", "AbstractMarkupRenderingEngine", "::", "CONTEXT_AWARE", ")", ")", "{", "$", "matches", "=", "$", "this", "->", "identifierMatches", "(", "$", "component", ")", ";", "$", "showHide", "=", "$", "component", "->", "getShowHide", "(", ")", ";", "return", "(", "$", "showHide", "===", "ShowHide", "::", "SHOW", ")", "?", "!", "$", "matches", ":", "$", "matches", ";", "}", "// Context Aware + RubricBlock", "elseif", "(", "$", "this", "->", "getViewPolicy", "(", ")", "===", "AbstractMarkupRenderingEngine", "::", "CONTEXT_AWARE", "&&", "$", "component", "instanceof", "RubricBlock", ")", "{", "$", "renderingViews", "=", "$", "this", "->", "getViews", "(", ")", ";", "$", "rubricViews", "=", "$", "component", "->", "getViews", "(", ")", ";", "// If one of the rendering views matches a single view", "// in the rubricBlock's view, render!", "foreach", "(", "$", "renderingViews", "as", "$", "v", ")", "{", "if", "(", "$", "rubricViews", "->", "contains", "(", "$", "v", ")", "===", "true", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Whether or not a component must be ignored or not while rendering. The following cases makes a component to be ignored: * The ChoiceHideShow policy is set to CONTEXT_AWARE and the variable referenced by the Choice's templateIdentifier attribute does not match the expected value. * The FeedbackHideShow policy is set to CONTEXT_AWARE and the variable referenced by the FeedbackElement's identifier attribute does not match the expected value. * The class of the Component is in the list of QTI classes to be ignored. @param QtiComponent $component A Component you want to know if it has to be ignored or not. @return boolean
[ "Whether", "or", "not", "a", "component", "must", "be", "ignored", "or", "not", "while", "rendering", ".", "The", "following", "cases", "makes", "a", "component", "to", "be", "ignored", ":" ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/markup/AbstractMarkupRenderingEngine.php#L656-L686
oat-sa/qti-sdk
src/qtism/runtime/rendering/markup/AbstractMarkupRenderingEngine.php
AbstractMarkupRenderingEngine.identifierMatches
protected function identifierMatches(QtiComponent $component) { $variableIdentifier = ($component instanceof FeedbackElement || $component instanceof ModalFeedback) ? $component->getOutcomeIdentifier() : $component->getTemplateIdentifier(); $identifier = new QtiIdentifier($component->getIdentifier()); $showHide = $component->getShowHide(); $state = $this->getState(); $matches = false; if (($val = $state[$variableIdentifier]) !== null) { if ($val instanceof QtiScalar) { $matches = $val->equals($identifier); } elseif ($val instanceof Container) { $matches = $val->contains($identifier); } } return $matches; }
php
protected function identifierMatches(QtiComponent $component) { $variableIdentifier = ($component instanceof FeedbackElement || $component instanceof ModalFeedback) ? $component->getOutcomeIdentifier() : $component->getTemplateIdentifier(); $identifier = new QtiIdentifier($component->getIdentifier()); $showHide = $component->getShowHide(); $state = $this->getState(); $matches = false; if (($val = $state[$variableIdentifier]) !== null) { if ($val instanceof QtiScalar) { $matches = $val->equals($identifier); } elseif ($val instanceof Container) { $matches = $val->contains($identifier); } } return $matches; }
[ "protected", "function", "identifierMatches", "(", "QtiComponent", "$", "component", ")", "{", "$", "variableIdentifier", "=", "(", "$", "component", "instanceof", "FeedbackElement", "||", "$", "component", "instanceof", "ModalFeedback", ")", "?", "$", "component", "->", "getOutcomeIdentifier", "(", ")", ":", "$", "component", "->", "getTemplateIdentifier", "(", ")", ";", "$", "identifier", "=", "new", "QtiIdentifier", "(", "$", "component", "->", "getIdentifier", "(", ")", ")", ";", "$", "showHide", "=", "$", "component", "->", "getShowHide", "(", ")", ";", "$", "state", "=", "$", "this", "->", "getState", "(", ")", ";", "$", "matches", "=", "false", ";", "if", "(", "(", "$", "val", "=", "$", "state", "[", "$", "variableIdentifier", "]", ")", "!==", "null", ")", "{", "if", "(", "$", "val", "instanceof", "QtiScalar", ")", "{", "$", "matches", "=", "$", "val", "->", "equals", "(", "$", "identifier", ")", ";", "}", "elseif", "(", "$", "val", "instanceof", "Container", ")", "{", "$", "matches", "=", "$", "val", "->", "contains", "(", "$", "identifier", ")", ";", "}", "}", "return", "$", "matches", ";", "}" ]
Whether or not the 'outcomeIdentifier'/'templateIdentifier' set on a templateElement/feedbackElement/choice matches its 'identifier' attribute. @param QtiComponent $component A TemplateElement or FeedbackElement or Choice element. @return boolean
[ "Whether", "or", "not", "the", "outcomeIdentifier", "/", "templateIdentifier", "set", "on", "a", "templateElement", "/", "feedbackElement", "/", "choice", "matches", "its", "identifier", "attribute", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/markup/AbstractMarkupRenderingEngine.php#L695-L713
oat-sa/qti-sdk
src/qtism/runtime/rendering/markup/AbstractMarkupRenderingEngine.php
AbstractMarkupRenderingEngine.registerRenderer
public function registerRenderer($qtiClassName, AbstractMarkupRenderer $renderer, $ns = 'qtism') { $renderer->setRenderingEngine($this); $renderers = $this->getRenderers(); $renderers[$ns][$qtiClassName] = $renderer; $this->setRenderers($renderers); }
php
public function registerRenderer($qtiClassName, AbstractMarkupRenderer $renderer, $ns = 'qtism') { $renderer->setRenderingEngine($this); $renderers = $this->getRenderers(); $renderers[$ns][$qtiClassName] = $renderer; $this->setRenderers($renderers); }
[ "public", "function", "registerRenderer", "(", "$", "qtiClassName", ",", "AbstractMarkupRenderer", "$", "renderer", ",", "$", "ns", "=", "'qtism'", ")", "{", "$", "renderer", "->", "setRenderingEngine", "(", "$", "this", ")", ";", "$", "renderers", "=", "$", "this", "->", "getRenderers", "(", ")", ";", "$", "renderers", "[", "$", "ns", "]", "[", "$", "qtiClassName", "]", "=", "$", "renderer", ";", "$", "this", "->", "setRenderers", "(", "$", "renderers", ")", ";", "}" ]
Register a $renderer object to a given $qtiClassName. @param string $qtiClassName A QTI class name. @param \qtism\runtime\rendering\markup\AbstractMarkupRenderer $renderer An AbstractRenderer object. @param string $ns
[ "Register", "a", "$renderer", "object", "to", "a", "given", "$qtiClassName", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/markup/AbstractMarkupRenderingEngine.php#L770-L776
oat-sa/qti-sdk
src/qtism/runtime/rendering/markup/AbstractMarkupRenderingEngine.php
AbstractMarkupRenderingEngine.getRenderer
public function getRenderer(QtiComponent $component) { $renderers = $this->getRenderers(); $className = $component->getQtiClassName(); if ($component instanceof ExternalQtiComponent && isset($renderers[$component->getTargetNamespace()][$className])) { return $renderers[$component->getTargetNamespace()][$className]; } elseif (isset($renderers['qtism'][$className]) === true) { return $renderers['qtism'][$className]; } else { $msg = "No AbstractRenderer implementation registered for QTI class name '${className}'."; throw new RenderingException($msg, RenderingException::NO_RENDERER); } }
php
public function getRenderer(QtiComponent $component) { $renderers = $this->getRenderers(); $className = $component->getQtiClassName(); if ($component instanceof ExternalQtiComponent && isset($renderers[$component->getTargetNamespace()][$className])) { return $renderers[$component->getTargetNamespace()][$className]; } elseif (isset($renderers['qtism'][$className]) === true) { return $renderers['qtism'][$className]; } else { $msg = "No AbstractRenderer implementation registered for QTI class name '${className}'."; throw new RenderingException($msg, RenderingException::NO_RENDERER); } }
[ "public", "function", "getRenderer", "(", "QtiComponent", "$", "component", ")", "{", "$", "renderers", "=", "$", "this", "->", "getRenderers", "(", ")", ";", "$", "className", "=", "$", "component", "->", "getQtiClassName", "(", ")", ";", "if", "(", "$", "component", "instanceof", "ExternalQtiComponent", "&&", "isset", "(", "$", "renderers", "[", "$", "component", "->", "getTargetNamespace", "(", ")", "]", "[", "$", "className", "]", ")", ")", "{", "return", "$", "renderers", "[", "$", "component", "->", "getTargetNamespace", "(", ")", "]", "[", "$", "className", "]", ";", "}", "elseif", "(", "isset", "(", "$", "renderers", "[", "'qtism'", "]", "[", "$", "className", "]", ")", "===", "true", ")", "{", "return", "$", "renderers", "[", "'qtism'", "]", "[", "$", "className", "]", ";", "}", "else", "{", "$", "msg", "=", "\"No AbstractRenderer implementation registered for QTI class name '${className}'.\"", ";", "throw", "new", "RenderingException", "(", "$", "msg", ",", "RenderingException", "::", "NO_RENDERER", ")", ";", "}", "}" ]
Get the AbstractRenderer implementation which is appropriate to render the given QtiComponent $component. @param QtiComponent $component A QtiComponent object you want to get the appropriate AbstractRenderer implementation. @throws RenderingException If no implementation of AbstractRenderer is registered for $component. @return \qtism\runtime\rendering\markup\AbstractMarkupRenderer The AbstractRenderer implementation to render $component.
[ "Get", "the", "AbstractRenderer", "implementation", "which", "is", "appropriate", "to", "render", "the", "given", "QtiComponent", "$component", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/markup/AbstractMarkupRenderingEngine.php#L786-L799
oat-sa/qti-sdk
src/qtism/runtime/rendering/markup/AbstractMarkupRenderingEngine.php
AbstractMarkupRenderingEngine.getChildrenRenderings
public function getChildrenRenderings(QtiComponent $component) { $returnValue = array(); foreach (array_reverse($component->getComponents()->getArrayCopy()) as $c) { if (count($this->getRenderingStack()) > 0) { list($renderedComponent, $rendering) = $this->getRenderingStack()->pop(); if ($c === $renderedComponent) { array_unshift($returnValue, $rendering); } else { // repush... $this->storeRendering($renderedComponent, $rendering); } } } return $returnValue; }
php
public function getChildrenRenderings(QtiComponent $component) { $returnValue = array(); foreach (array_reverse($component->getComponents()->getArrayCopy()) as $c) { if (count($this->getRenderingStack()) > 0) { list($renderedComponent, $rendering) = $this->getRenderingStack()->pop(); if ($c === $renderedComponent) { array_unshift($returnValue, $rendering); } else { // repush... $this->storeRendering($renderedComponent, $rendering); } } } return $returnValue; }
[ "public", "function", "getChildrenRenderings", "(", "QtiComponent", "$", "component", ")", "{", "$", "returnValue", "=", "array", "(", ")", ";", "foreach", "(", "array_reverse", "(", "$", "component", "->", "getComponents", "(", ")", "->", "getArrayCopy", "(", ")", ")", "as", "$", "c", ")", "{", "if", "(", "count", "(", "$", "this", "->", "getRenderingStack", "(", ")", ")", ">", "0", ")", "{", "list", "(", "$", "renderedComponent", ",", "$", "rendering", ")", "=", "$", "this", "->", "getRenderingStack", "(", ")", "->", "pop", "(", ")", ";", "if", "(", "$", "c", "===", "$", "renderedComponent", ")", "{", "array_unshift", "(", "$", "returnValue", ",", "$", "rendering", ")", ";", "}", "else", "{", "// repush...", "$", "this", "->", "storeRendering", "(", "$", "renderedComponent", ",", "$", "rendering", ")", ";", "}", "}", "}", "return", "$", "returnValue", ";", "}" ]
Get the renderings related to the children of $component. @param QtiComponent $component A QtiComponent object to be rendered. @return array
[ "Get", "the", "renderings", "related", "to", "the", "children", "of", "$component", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/markup/AbstractMarkupRenderingEngine.php#L863-L882
oat-sa/qti-sdk
src/qtism/runtime/rendering/markup/AbstractMarkupRenderingEngine.php
AbstractMarkupRenderingEngine.reset
public function reset() { $this->choiceCounter = 0; $this->setExploration(new SplStack()); $this->setExplorationMarker(array()); $this->setLastRendering(null); $this->setRenderingStack(new SplStack()); $this->setXmlBaseStack(new SplStack()); $this->setDocument(new DOMDocument('1.0', 'UTF-8')); $this->setStylesheets($this->getDocument()->createDocumentFragment()); $this->setCurrentInteraction(null); }
php
public function reset() { $this->choiceCounter = 0; $this->setExploration(new SplStack()); $this->setExplorationMarker(array()); $this->setLastRendering(null); $this->setRenderingStack(new SplStack()); $this->setXmlBaseStack(new SplStack()); $this->setDocument(new DOMDocument('1.0', 'UTF-8')); $this->setStylesheets($this->getDocument()->createDocumentFragment()); $this->setCurrentInteraction(null); }
[ "public", "function", "reset", "(", ")", "{", "$", "this", "->", "choiceCounter", "=", "0", ";", "$", "this", "->", "setExploration", "(", "new", "SplStack", "(", ")", ")", ";", "$", "this", "->", "setExplorationMarker", "(", "array", "(", ")", ")", ";", "$", "this", "->", "setLastRendering", "(", "null", ")", ";", "$", "this", "->", "setRenderingStack", "(", "new", "SplStack", "(", ")", ")", ";", "$", "this", "->", "setXmlBaseStack", "(", "new", "SplStack", "(", ")", ")", ";", "$", "this", "->", "setDocument", "(", "new", "DOMDocument", "(", "'1.0'", ",", "'UTF-8'", ")", ")", ";", "$", "this", "->", "setStylesheets", "(", "$", "this", "->", "getDocument", "(", ")", "->", "createDocumentFragment", "(", ")", ")", ";", "$", "this", "->", "setCurrentInteraction", "(", "null", ")", ";", "}" ]
Reset the engine to its initial state, in order to be ready for reuse i.e. render a new component. However, configuration such as policies are kept intact.
[ "Reset", "the", "engine", "to", "its", "initial", "state", "in", "order", "to", "be", "ready", "for", "reuse", "i", ".", "e", ".", "render", "a", "new", "component", ".", "However", "configuration", "such", "as", "policies", "are", "kept", "intact", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/markup/AbstractMarkupRenderingEngine.php#L889-L900
oat-sa/qti-sdk
src/qtism/runtime/rendering/markup/AbstractMarkupRenderingEngine.php
AbstractMarkupRenderingEngine.registerXmlBase
protected function registerXmlBase($substitution = '') { $c = $this->getExploredComponent(); $toPush = $substitution; if ($c instanceof Flow) { if (empty($substitution) === true) { $toPush = $c->getXmlBase(); } } $this->getXmlBaseStack()->push($toPush); }
php
protected function registerXmlBase($substitution = '') { $c = $this->getExploredComponent(); $toPush = $substitution; if ($c instanceof Flow) { if (empty($substitution) === true) { $toPush = $c->getXmlBase(); } } $this->getXmlBaseStack()->push($toPush); }
[ "protected", "function", "registerXmlBase", "(", "$", "substitution", "=", "''", ")", "{", "$", "c", "=", "$", "this", "->", "getExploredComponent", "(", ")", ";", "$", "toPush", "=", "$", "substitution", ";", "if", "(", "$", "c", "instanceof", "Flow", ")", "{", "if", "(", "empty", "(", "$", "substitution", ")", "===", "true", ")", "{", "$", "toPush", "=", "$", "c", "->", "getXmlBase", "(", ")", ";", "}", "}", "$", "this", "->", "getXmlBaseStack", "(", ")", "->", "push", "(", "$", "toPush", ")", ";", "}" ]
Register the value of xml:base of the currently explored component into the xmlBaseStack. @param string $substitution If set, the registered xml:base value will be the value of the argument instead of the currently explored component's xml:base value.
[ "Register", "the", "value", "of", "xml", ":", "base", "of", "the", "currently", "explored", "component", "into", "the", "xmlBaseStack", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/markup/AbstractMarkupRenderingEngine.php#L908-L920
oat-sa/qti-sdk
src/qtism/runtime/rendering/markup/AbstractMarkupRenderingEngine.php
AbstractMarkupRenderingEngine.resolveXmlBase
protected function resolveXmlBase() { $stack = $this->getXmlBaseStack(); $stack->rewind(); $resolvedBase = ''; while ($stack->valid() === true) { if (($currentBase = $stack->current()) !== '') { if ($resolvedBase === '') { $resolvedBase = $currentBase; } else { $resolvedBase = Url::rtrim($currentBase) . '/' . Url::ltrim($resolvedBase); } } $stack->next(); } if ($stack->count() > 0) { $stack->pop(); } return $resolvedBase; }
php
protected function resolveXmlBase() { $stack = $this->getXmlBaseStack(); $stack->rewind(); $resolvedBase = ''; while ($stack->valid() === true) { if (($currentBase = $stack->current()) !== '') { if ($resolvedBase === '') { $resolvedBase = $currentBase; } else { $resolvedBase = Url::rtrim($currentBase) . '/' . Url::ltrim($resolvedBase); } } $stack->next(); } if ($stack->count() > 0) { $stack->pop(); } return $resolvedBase; }
[ "protected", "function", "resolveXmlBase", "(", ")", "{", "$", "stack", "=", "$", "this", "->", "getXmlBaseStack", "(", ")", ";", "$", "stack", "->", "rewind", "(", ")", ";", "$", "resolvedBase", "=", "''", ";", "while", "(", "$", "stack", "->", "valid", "(", ")", "===", "true", ")", "{", "if", "(", "(", "$", "currentBase", "=", "$", "stack", "->", "current", "(", ")", ")", "!==", "''", ")", "{", "if", "(", "$", "resolvedBase", "===", "''", ")", "{", "$", "resolvedBase", "=", "$", "currentBase", ";", "}", "else", "{", "$", "resolvedBase", "=", "Url", "::", "rtrim", "(", "$", "currentBase", ")", ".", "'/'", ".", "Url", "::", "ltrim", "(", "$", "resolvedBase", ")", ";", "}", "}", "$", "stack", "->", "next", "(", ")", ";", "}", "if", "(", "$", "stack", "->", "count", "(", ")", ">", "0", ")", "{", "$", "stack", "->", "pop", "(", ")", ";", "}", "return", "$", "resolvedBase", ";", "}" ]
Resolve what is the base URL to be used for the currently explored component. @return string A URL or the empty string ('') if no base URL could be resolved.
[ "Resolve", "what", "is", "the", "base", "URL", "to", "be", "used", "for", "the", "currently", "explored", "component", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/markup/AbstractMarkupRenderingEngine.php#L927-L952
oat-sa/qti-sdk
src/qtism/runtime/rendering/markup/AbstractMarkupRenderingEngine.php
AbstractMarkupRenderingEngine.mustTemplateFeedbackComponent
protected function mustTemplateFeedbackComponent(QtiComponent $component) { return (self::isFeedback($component) && $this->getFeedbackShowHidePolicy() === AbstractMarkupRenderingEngine::TEMPLATE_ORIENTED); }
php
protected function mustTemplateFeedbackComponent(QtiComponent $component) { return (self::isFeedback($component) && $this->getFeedbackShowHidePolicy() === AbstractMarkupRenderingEngine::TEMPLATE_ORIENTED); }
[ "protected", "function", "mustTemplateFeedbackComponent", "(", "QtiComponent", "$", "component", ")", "{", "return", "(", "self", "::", "isFeedback", "(", "$", "component", ")", "&&", "$", "this", "->", "getFeedbackShowHidePolicy", "(", ")", "===", "AbstractMarkupRenderingEngine", "::", "TEMPLATE_ORIENTED", ")", ";", "}" ]
Whether or not a given component (expected to be a feedback) must be templated. A component is considered to be templatable if: * it is an instance of FeedbackElement or ModalFeedback * the current policy for feedback elements is TEMPLATE_ORIENTED @param QtiComponent $component @return boolean
[ "Whether", "or", "not", "a", "given", "component", "(", "expected", "to", "be", "a", "feedback", ")", "must", "be", "templated", ".", "A", "component", "is", "considered", "to", "be", "templatable", "if", ":" ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/markup/AbstractMarkupRenderingEngine.php#L964-L967
oat-sa/qti-sdk
src/qtism/runtime/rendering/markup/AbstractMarkupRenderingEngine.php
AbstractMarkupRenderingEngine.mustTemplateRubricBlockComponent
protected function mustTemplateRubricBlockComponent(QtiComponent $component) { return (self::isRubricBlock($component) && $this->getViewPolicy() === AbstractMarkupRenderingEngine::TEMPLATE_ORIENTED); }
php
protected function mustTemplateRubricBlockComponent(QtiComponent $component) { return (self::isRubricBlock($component) && $this->getViewPolicy() === AbstractMarkupRenderingEngine::TEMPLATE_ORIENTED); }
[ "protected", "function", "mustTemplateRubricBlockComponent", "(", "QtiComponent", "$", "component", ")", "{", "return", "(", "self", "::", "isRubricBlock", "(", "$", "component", ")", "&&", "$", "this", "->", "getViewPolicy", "(", ")", "===", "AbstractMarkupRenderingEngine", "::", "TEMPLATE_ORIENTED", ")", ";", "}" ]
Whether or not a given component (expected to be a rubricBlock) must be templated. A component is considered to be templatable if: * it is an instance of RubricBlock * the current policy for views is TEMPLATE_ORIENTED @param QtiComponent $component @return boolean
[ "Whether", "or", "not", "a", "given", "component", "(", "expected", "to", "be", "a", "rubricBlock", ")", "must", "be", "templated", ".", "A", "component", "is", "considered", "to", "be", "templatable", "if", ":" ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/markup/AbstractMarkupRenderingEngine.php#L979-L982
oat-sa/qti-sdk
src/qtism/runtime/rendering/markup/AbstractMarkupRenderingEngine.php
AbstractMarkupRenderingEngine.mustTemplateChoiceComponent
protected function mustTemplateChoiceComponent(QtiComponent $component) { return self::isChoice($component) && $this->getChoiceShowHidePolicy() === self::TEMPLATE_ORIENTED && $component->hasTemplateIdentifier(); }
php
protected function mustTemplateChoiceComponent(QtiComponent $component) { return self::isChoice($component) && $this->getChoiceShowHidePolicy() === self::TEMPLATE_ORIENTED && $component->hasTemplateIdentifier(); }
[ "protected", "function", "mustTemplateChoiceComponent", "(", "QtiComponent", "$", "component", ")", "{", "return", "self", "::", "isChoice", "(", "$", "component", ")", "&&", "$", "this", "->", "getChoiceShowHidePolicy", "(", ")", "===", "self", "::", "TEMPLATE_ORIENTED", "&&", "$", "component", "->", "hasTemplateIdentifier", "(", ")", ";", "}" ]
Whether or not a given component (expected to be a choice) must be templated. A component is considered to be templatable if: * it is an instance of Choice * the current policy for choice show/hide is TEMPLATE_ORIENTED @param QtiComponent $component @return boolean
[ "Whether", "or", "not", "a", "given", "component", "(", "expected", "to", "be", "a", "choice", ")", "must", "be", "templated", ".", "A", "component", "is", "considered", "to", "be", "templatable", "if", ":" ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/markup/AbstractMarkupRenderingEngine.php#L994-L997
oat-sa/qti-sdk
src/qtism/runtime/rendering/markup/AbstractMarkupRenderingEngine.php
AbstractMarkupRenderingEngine.templateFeedbackComponent
protected function templateFeedbackComponent(QtiComponent $component, DOMDocumentFragment $rendering) { if (self::isFeedback($component) === false) { $msg = "Cannot template a component which is not an instance of FeedbackElement nor ModalFeedback."; throw new RenderingException($msg, RenderingException::RUNTIME); } $operator = ($component->getShowHide() === ShowHide::SHOW) ? '' : '!'; $val = '$' . $this->getStateName() . "['" . $component->getOutcomeIdentifier() . "']"; $identifier = $component->getIdentifier(); $identifierType = 'qtism\\common\\datatypes\\QtiIdentifier'; $scalarType = 'qtism\\common\\datatypes\\QtiScalar'; $containerType = 'qtism\\common\\collections\\Container'; $scalarCheck = "${val} instanceof ${identifierType} && ${val}->equals(new ${identifierType}('${identifier}'))"; $containerCheck = "${val} instanceof ${containerType} && ${val}->contains(new ${identifierType}('${identifier}'))"; $valCheck = "(${scalarCheck} || ${containerCheck})"; $ifStmt = " qtism-if (${operator}(${val} !== null && ${valCheck})): "; $endifStmt = " qtism-endif "; $ifStmtCmt = $rendering->ownerDocument->createComment($ifStmt); $endifStmtCmt = $rendering->ownerDocument->createComment($endifStmt); $rendering->insertBefore($ifStmtCmt, $rendering->firstChild); $rendering->appendChild($endifStmtCmt); }
php
protected function templateFeedbackComponent(QtiComponent $component, DOMDocumentFragment $rendering) { if (self::isFeedback($component) === false) { $msg = "Cannot template a component which is not an instance of FeedbackElement nor ModalFeedback."; throw new RenderingException($msg, RenderingException::RUNTIME); } $operator = ($component->getShowHide() === ShowHide::SHOW) ? '' : '!'; $val = '$' . $this->getStateName() . "['" . $component->getOutcomeIdentifier() . "']"; $identifier = $component->getIdentifier(); $identifierType = 'qtism\\common\\datatypes\\QtiIdentifier'; $scalarType = 'qtism\\common\\datatypes\\QtiScalar'; $containerType = 'qtism\\common\\collections\\Container'; $scalarCheck = "${val} instanceof ${identifierType} && ${val}->equals(new ${identifierType}('${identifier}'))"; $containerCheck = "${val} instanceof ${containerType} && ${val}->contains(new ${identifierType}('${identifier}'))"; $valCheck = "(${scalarCheck} || ${containerCheck})"; $ifStmt = " qtism-if (${operator}(${val} !== null && ${valCheck})): "; $endifStmt = " qtism-endif "; $ifStmtCmt = $rendering->ownerDocument->createComment($ifStmt); $endifStmtCmt = $rendering->ownerDocument->createComment($endifStmt); $rendering->insertBefore($ifStmtCmt, $rendering->firstChild); $rendering->appendChild($endifStmtCmt); }
[ "protected", "function", "templateFeedbackComponent", "(", "QtiComponent", "$", "component", ",", "DOMDocumentFragment", "$", "rendering", ")", "{", "if", "(", "self", "::", "isFeedback", "(", "$", "component", ")", "===", "false", ")", "{", "$", "msg", "=", "\"Cannot template a component which is not an instance of FeedbackElement nor ModalFeedback.\"", ";", "throw", "new", "RenderingException", "(", "$", "msg", ",", "RenderingException", "::", "RUNTIME", ")", ";", "}", "$", "operator", "=", "(", "$", "component", "->", "getShowHide", "(", ")", "===", "ShowHide", "::", "SHOW", ")", "?", "''", ":", "'!'", ";", "$", "val", "=", "'$'", ".", "$", "this", "->", "getStateName", "(", ")", ".", "\"['\"", ".", "$", "component", "->", "getOutcomeIdentifier", "(", ")", ".", "\"']\"", ";", "$", "identifier", "=", "$", "component", "->", "getIdentifier", "(", ")", ";", "$", "identifierType", "=", "'qtism\\\\common\\\\datatypes\\\\QtiIdentifier'", ";", "$", "scalarType", "=", "'qtism\\\\common\\\\datatypes\\\\QtiScalar'", ";", "$", "containerType", "=", "'qtism\\\\common\\\\collections\\\\Container'", ";", "$", "scalarCheck", "=", "\"${val} instanceof ${identifierType} && ${val}->equals(new ${identifierType}('${identifier}'))\"", ";", "$", "containerCheck", "=", "\"${val} instanceof ${containerType} && ${val}->contains(new ${identifierType}('${identifier}'))\"", ";", "$", "valCheck", "=", "\"(${scalarCheck} || ${containerCheck})\"", ";", "$", "ifStmt", "=", "\" qtism-if (${operator}(${val} !== null && ${valCheck})): \"", ";", "$", "endifStmt", "=", "\" qtism-endif \"", ";", "$", "ifStmtCmt", "=", "$", "rendering", "->", "ownerDocument", "->", "createComment", "(", "$", "ifStmt", ")", ";", "$", "endifStmtCmt", "=", "$", "rendering", "->", "ownerDocument", "->", "createComment", "(", "$", "endifStmt", ")", ";", "$", "rendering", "->", "insertBefore", "(", "$", "ifStmtCmt", ",", "$", "rendering", "->", "firstChild", ")", ";", "$", "rendering", "->", "appendChild", "(", "$", "endifStmtCmt", ")", ";", "}" ]
Contains the logic of templating a QTI feedback (feedbackElement, modalFeedback). @param QtiComponent $component The QtiComponent being rendered. @param DOMDocumentFragment $rendering The rendering corresponding to $component. @throws RenderingException If $component is not an instance of FeedbackElement nor ModalFeedback.
[ "Contains", "the", "logic", "of", "templating", "a", "QTI", "feedback", "(", "feedbackElement", "modalFeedback", ")", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/markup/AbstractMarkupRenderingEngine.php#L1056-L1081
oat-sa/qti-sdk
src/qtism/runtime/rendering/markup/AbstractMarkupRenderingEngine.php
AbstractMarkupRenderingEngine.templateRubricBlockComponent
protected function templateRubricBlockComponent(QtiComponent $component, DOMDocumentFragment $rendering) { if (self::isRubricBlock($component) === false) { $msg = "Cannot template a component which is not an instance of RubricBlock."; throw new RenderingException($msg, RenderingException::RUNTIME); } $viewsName = '$' . $this->getViewsName(); $views = $component->getViews(); $conds = array(); foreach ($component->getViews() as $v) { $conds[] = "in_array(${v}, ${viewsName})"; } $conds = (count($views) > 1) ? implode(' || ', $conds) : $conds[0]; $ifStmt = " qtism-if (${conds}): "; $endifStmt = " qtism-endif "; $ifStmtCmt = $rendering->ownerDocument->createComment($ifStmt); $endifStmtCmt = $rendering->ownerDocument->createComment($endifStmt); $rendering->insertBefore($ifStmtCmt, $rendering->firstChild); $rendering->appendChild($endifStmtCmt); }
php
protected function templateRubricBlockComponent(QtiComponent $component, DOMDocumentFragment $rendering) { if (self::isRubricBlock($component) === false) { $msg = "Cannot template a component which is not an instance of RubricBlock."; throw new RenderingException($msg, RenderingException::RUNTIME); } $viewsName = '$' . $this->getViewsName(); $views = $component->getViews(); $conds = array(); foreach ($component->getViews() as $v) { $conds[] = "in_array(${v}, ${viewsName})"; } $conds = (count($views) > 1) ? implode(' || ', $conds) : $conds[0]; $ifStmt = " qtism-if (${conds}): "; $endifStmt = " qtism-endif "; $ifStmtCmt = $rendering->ownerDocument->createComment($ifStmt); $endifStmtCmt = $rendering->ownerDocument->createComment($endifStmt); $rendering->insertBefore($ifStmtCmt, $rendering->firstChild); $rendering->appendChild($endifStmtCmt); }
[ "protected", "function", "templateRubricBlockComponent", "(", "QtiComponent", "$", "component", ",", "DOMDocumentFragment", "$", "rendering", ")", "{", "if", "(", "self", "::", "isRubricBlock", "(", "$", "component", ")", "===", "false", ")", "{", "$", "msg", "=", "\"Cannot template a component which is not an instance of RubricBlock.\"", ";", "throw", "new", "RenderingException", "(", "$", "msg", ",", "RenderingException", "::", "RUNTIME", ")", ";", "}", "$", "viewsName", "=", "'$'", ".", "$", "this", "->", "getViewsName", "(", ")", ";", "$", "views", "=", "$", "component", "->", "getViews", "(", ")", ";", "$", "conds", "=", "array", "(", ")", ";", "foreach", "(", "$", "component", "->", "getViews", "(", ")", "as", "$", "v", ")", "{", "$", "conds", "[", "]", "=", "\"in_array(${v}, ${viewsName})\"", ";", "}", "$", "conds", "=", "(", "count", "(", "$", "views", ")", ">", "1", ")", "?", "implode", "(", "' || '", ",", "$", "conds", ")", ":", "$", "conds", "[", "0", "]", ";", "$", "ifStmt", "=", "\" qtism-if (${conds}): \"", ";", "$", "endifStmt", "=", "\" qtism-endif \"", ";", "$", "ifStmtCmt", "=", "$", "rendering", "->", "ownerDocument", "->", "createComment", "(", "$", "ifStmt", ")", ";", "$", "endifStmtCmt", "=", "$", "rendering", "->", "ownerDocument", "->", "createComment", "(", "$", "endifStmt", ")", ";", "$", "rendering", "->", "insertBefore", "(", "$", "ifStmtCmt", ",", "$", "rendering", "->", "firstChild", ")", ";", "$", "rendering", "->", "appendChild", "(", "$", "endifStmtCmt", ")", ";", "}" ]
Contains the logic of templating a QTI rubricBlock (RubricBlock). @param QtiComponent $component The QtiComponent being rendered. @param DOMDocumentFragment $rendering The rendering corresponding to $component. @throws RenderingException If $component is not an instance of RubricBlock.
[ "Contains", "the", "logic", "of", "templating", "a", "QTI", "rubricBlock", "(", "RubricBlock", ")", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/markup/AbstractMarkupRenderingEngine.php#L1090-L1114
oat-sa/qti-sdk
src/qtism/runtime/expressions/NumberPresentedProcessor.php
NumberPresentedProcessor.process
public function process() { $testSession = $this->getState(); $itemSubset = $this->getItemSubset(); $numberPresented = 0; foreach ($itemSubset as $item) { $itemSessions = $testSession->getAssessmentItemSessions($item->getIdentifier()); if ($itemSessions !== false) { foreach ($itemSessions as $itemSession) { if ($itemSession->isPresented() === true) { $numberPresented++; } } } } return new QtiInteger($numberPresented); }
php
public function process() { $testSession = $this->getState(); $itemSubset = $this->getItemSubset(); $numberPresented = 0; foreach ($itemSubset as $item) { $itemSessions = $testSession->getAssessmentItemSessions($item->getIdentifier()); if ($itemSessions !== false) { foreach ($itemSessions as $itemSession) { if ($itemSession->isPresented() === true) { $numberPresented++; } } } } return new QtiInteger($numberPresented); }
[ "public", "function", "process", "(", ")", "{", "$", "testSession", "=", "$", "this", "->", "getState", "(", ")", ";", "$", "itemSubset", "=", "$", "this", "->", "getItemSubset", "(", ")", ";", "$", "numberPresented", "=", "0", ";", "foreach", "(", "$", "itemSubset", "as", "$", "item", ")", "{", "$", "itemSessions", "=", "$", "testSession", "->", "getAssessmentItemSessions", "(", "$", "item", "->", "getIdentifier", "(", ")", ")", ";", "if", "(", "$", "itemSessions", "!==", "false", ")", "{", "foreach", "(", "$", "itemSessions", "as", "$", "itemSession", ")", "{", "if", "(", "$", "itemSession", "->", "isPresented", "(", ")", "===", "true", ")", "{", "$", "numberPresented", "++", ";", "}", "}", "}", "}", "return", "new", "QtiInteger", "(", "$", "numberPresented", ")", ";", "}" ]
Process the related NumberPresented expression. @return integer The number of items in the given item sub-set that have been attempted (at least once). @throws \qtism\runtime\expressions\ExpressionProcessingException
[ "Process", "the", "related", "NumberPresented", "expression", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/NumberPresentedProcessor.php#L52-L73
oat-sa/qti-sdk
src/qtism/data/content/interactions/InlineChoiceInteraction.php
InlineChoiceInteraction.setRequired
public function setRequired($required) { if (is_bool($required) === true) { $this->required = $required; } else { $msg = "The 'required' argument must be a boolean value, '" . gettype($required) . "' given."; throw new InvalidArgumentException($msg); } }
php
public function setRequired($required) { if (is_bool($required) === true) { $this->required = $required; } else { $msg = "The 'required' argument must be a boolean value, '" . gettype($required) . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setRequired", "(", "$", "required", ")", "{", "if", "(", "is_bool", "(", "$", "required", ")", "===", "true", ")", "{", "$", "this", "->", "required", "=", "$", "required", ";", "}", "else", "{", "$", "msg", "=", "\"The 'required' argument must be a boolean value, '\"", ".", "gettype", "(", "$", "required", ")", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set whether a choice is required to be selected by the candidate. @param boolean $required @throws \InvalidArgumentException If $required is not a boolean value.
[ "Set", "whether", "a", "choice", "is", "required", "to", "be", "selected", "by", "the", "candidate", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/interactions/InlineChoiceInteraction.php#L134-L142
oat-sa/qti-sdk
src/qtism/data/content/interactions/InlineChoiceInteraction.php
InlineChoiceInteraction.setContent
public function setContent(InlineChoiceCollection $content) { if (count($content) > 0) { $this->content = $content; } else { $msg = "An InlineChoiceInteraction must be composed by at lease one InlineChoice object, none given."; throw new InvalidArgumentException($msg); } }
php
public function setContent(InlineChoiceCollection $content) { if (count($content) > 0) { $this->content = $content; } else { $msg = "An InlineChoiceInteraction must be composed by at lease one InlineChoice object, none given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setContent", "(", "InlineChoiceCollection", "$", "content", ")", "{", "if", "(", "count", "(", "$", "content", ")", ">", "0", ")", "{", "$", "this", "->", "content", "=", "$", "content", ";", "}", "else", "{", "$", "msg", "=", "\"An InlineChoiceInteraction must be composed by at lease one InlineChoice object, none given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set the InlineChoice objects composing the interaction. @param \qtism\data\content\interactions\InlineChoiceCollection $content A collection of at least one InlineChoice object. @throws \InvalidArgumentException If $content is empty.
[ "Set", "the", "InlineChoice", "objects", "composing", "the", "interaction", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/interactions/InlineChoiceInteraction.php#L160-L168
oat-sa/qti-sdk
src/qtism/data/content/xhtml/Img.php
Img.setSrc
public function setSrc($src) { if (Format::isUri($src) === true) { $this->src = $src; } else { $msg = "The 'src' argument must be a valid URI, '" . $src . "' given."; throw new InvalidArgumentException($msg); } }
php
public function setSrc($src) { if (Format::isUri($src) === true) { $this->src = $src; } else { $msg = "The 'src' argument must be a valid URI, '" . $src . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setSrc", "(", "$", "src", ")", "{", "if", "(", "Format", "::", "isUri", "(", "$", "src", ")", "===", "true", ")", "{", "$", "this", "->", "src", "=", "$", "src", ";", "}", "else", "{", "$", "msg", "=", "\"The 'src' argument must be a valid URI, '\"", ".", "$", "src", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set the src attribute. @param string $src A URI. @throws \InvalidArgumentException If $src is not a valid URI.
[ "Set", "the", "src", "attribute", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/xhtml/Img.php#L116-L124
oat-sa/qti-sdk
src/qtism/data/content/xhtml/Img.php
Img.setAlt
public function setAlt($alt) { if (is_string($alt)) { $this->alt = $alt; } else { $msg = "The 'alt' argument must be a string, '" . gettype($alt) . "' given."; throw new InvalidArgumentException($msg); } }
php
public function setAlt($alt) { if (is_string($alt)) { $this->alt = $alt; } else { $msg = "The 'alt' argument must be a string, '" . gettype($alt) . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setAlt", "(", "$", "alt", ")", "{", "if", "(", "is_string", "(", "$", "alt", ")", ")", "{", "$", "this", "->", "alt", "=", "$", "alt", ";", "}", "else", "{", "$", "msg", "=", "\"The 'alt' argument must be a string, '\"", ".", "gettype", "(", "$", "alt", ")", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set the alt attribute. @param string $alt A string @throws \InvalidArgumentException If $alt is not a string.
[ "Set", "the", "alt", "attribute", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/xhtml/Img.php#L142-L150
oat-sa/qti-sdk
src/qtism/data/content/xhtml/Img.php
Img.setLongdesc
public function setLongdesc($longdesc) { if (Format::isUri($longdesc) === true || (is_string($longdesc) === true && empty($longdesc) === true)) { $this->longdesc = $longdesc; } else { $msg = "The 'longdesc' argument must be a valid URI, '" . $longdesc . "' given."; throw new InvalidArgumentException($msg); } }
php
public function setLongdesc($longdesc) { if (Format::isUri($longdesc) === true || (is_string($longdesc) === true && empty($longdesc) === true)) { $this->longdesc = $longdesc; } else { $msg = "The 'longdesc' argument must be a valid URI, '" . $longdesc . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setLongdesc", "(", "$", "longdesc", ")", "{", "if", "(", "Format", "::", "isUri", "(", "$", "longdesc", ")", "===", "true", "||", "(", "is_string", "(", "$", "longdesc", ")", "===", "true", "&&", "empty", "(", "$", "longdesc", ")", "===", "true", ")", ")", "{", "$", "this", "->", "longdesc", "=", "$", "longdesc", ";", "}", "else", "{", "$", "msg", "=", "\"The 'longdesc' argument must be a valid URI, '\"", ".", "$", "longdesc", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Get the longdesc attribute. @param string $longdesc A valid URI. @throws \InvalidArgumentException If $longdesc is not a valid URI.
[ "Get", "the", "longdesc", "attribute", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/xhtml/Img.php#L168-L176
oat-sa/qti-sdk
src/qtism/data/content/xhtml/Img.php
Img.setHeight
public function setHeight($height) { if ((is_int($height) && $height === -1) || Format::isXhtmlLength($height) === true) { $this->height = $height; } else { $msg = "The 'height' argument must be a valid XHTML length value, '" . $height . "' given."; throw new InvalidArgumentException($msg); } }
php
public function setHeight($height) { if ((is_int($height) && $height === -1) || Format::isXhtmlLength($height) === true) { $this->height = $height; } else { $msg = "The 'height' argument must be a valid XHTML length value, '" . $height . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setHeight", "(", "$", "height", ")", "{", "if", "(", "(", "is_int", "(", "$", "height", ")", "&&", "$", "height", "===", "-", "1", ")", "||", "Format", "::", "isXhtmlLength", "(", "$", "height", ")", "===", "true", ")", "{", "$", "this", "->", "height", "=", "$", "height", ";", "}", "else", "{", "$", "msg", "=", "\"The 'height' argument must be a valid XHTML length value, '\"", ".", "$", "height", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set the height attribute. A negative (< 0) value for $height means there is no height indicated. @param integer|string $height An integer (pixels) or a string (percentage). @throws \InvalidArgumentException If $height is not a valid integer or string value.
[ "Set", "the", "height", "attribute", ".", "A", "negative", "(", "<", "0", ")", "value", "for", "$height", "means", "there", "is", "no", "height", "indicated", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/xhtml/Img.php#L205-L213
oat-sa/qti-sdk
src/qtism/data/content/xhtml/Img.php
Img.setWidth
public function setWidth($width) { if ((is_int($width) && $width === -1) || Format::isXhtmlLength($width) === true) { $this->width = $width; } else { $msg = "The 'width' argument must be a valid XHTML length value, '" . $width . "' given."; throw new InvalidArgumentException($msg); } }
php
public function setWidth($width) { if ((is_int($width) && $width === -1) || Format::isXhtmlLength($width) === true) { $this->width = $width; } else { $msg = "The 'width' argument must be a valid XHTML length value, '" . $width . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setWidth", "(", "$", "width", ")", "{", "if", "(", "(", "is_int", "(", "$", "width", ")", "&&", "$", "width", "===", "-", "1", ")", "||", "Format", "::", "isXhtmlLength", "(", "$", "width", ")", "===", "true", ")", "{", "$", "this", "->", "width", "=", "$", "width", ";", "}", "else", "{", "$", "msg", "=", "\"The 'width' argument must be a valid XHTML length value, '\"", ".", "$", "width", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set the width attribute. A negative (< 0) value for $width means there is no width indicated. @param integer $width An integer (pixels) or a string (percentage). @throws \InvalidArgumentException If $width is not an integer value.
[ "Set", "the", "width", "attribute", ".", "A", "negative", "(", "<", "0", ")", "value", "for", "$width", "means", "there", "is", "no", "width", "indicated", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/xhtml/Img.php#L243-L251
oat-sa/qti-sdk
src/qtism/data/storage/xml/marshalling/GraphicGapMatchInteractionMarshaller.php
GraphicGapMatchInteractionMarshaller.unmarshall
protected function unmarshall(DOMElement $element) { 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]); $associableHotspotElts = $this->getChildElementsByTagName($element, 'associableHotspot'); if (count($associableHotspotElts) > 0) { $associableHotspots = new AssociableHotspotCollection(); foreach ($associableHotspotElts as $associableHotspotElt) { $associableHotspots[] = $this->getMarshallerFactory()->createMarshaller($associableHotspotElt)->unmarshall($associableHotspotElt); } $gapImgElts = $this->getChildElementsByTagName($element, 'gapImg'); if (count($gapImgElts) > 0) { $gapImgs = new GapImgCollection(); foreach ($gapImgElts as $gapImgElt) { $gapImgs[] = $this->getMarshallerFactory()->createMarshaller($gapImgElt)->unmarshall($gapImgElt); } $component = new GraphicGapMatchInteraction($responseIdentifier, $object, $gapImgs, $associableHotspots); $promptElts = $this->getChildElementsByTagName($element, 'prompt'); if (count($promptElts) > 0) { $promptElt = $promptElts[0]; $prompt = $this->getMarshallerFactory()->createMarshaller($promptElt)->unmarshall($promptElt); $component->setPrompt($prompt); } if (($xmlBase = self::getXmlBase($element)) !== false) { $component->setXmlBase($xmlBase); } $this->fillBodyElement($component, $element); return $component; } else { $msg = "A 'graphicGapMatchInteraction' element must contain at least one 'gapImg' element, none given."; throw new UnmarshallingException($msg, $element); } } else { $msg = "A 'graphiGapMatchInteraction' element must contain at least one 'associableHotspot' element, none given."; throw new UnmarshallingException($msg, $element); } } else { $msg = "A 'graphicGapMatchInteraction' element must contain exactly one 'object' element, none given."; throw new UnmarshallingException($msg, $element); } } else { $msg = "The mandatory 'responseIdentifier' attribute is missing from the 'graphicGapMatchInteraction' element."; throw new UnmarshallingException($msg, $element); } }
php
protected function unmarshall(DOMElement $element) { if (($responseIdentifier = $this->getDOMElementAttributeAs($element, 'responseIdentifier')) !== null) { $objectElts = $this->getChildElementsByTagName($element, 'object'); if (count($objectElts) > 0) { $object = $this->getMarshallerFactory()->createMarshaller($objectElts[0])->unmarshall($objectElts[0]); $associableHotspotElts = $this->getChildElementsByTagName($element, 'associableHotspot'); if (count($associableHotspotElts) > 0) { $associableHotspots = new AssociableHotspotCollection(); foreach ($associableHotspotElts as $associableHotspotElt) { $associableHotspots[] = $this->getMarshallerFactory()->createMarshaller($associableHotspotElt)->unmarshall($associableHotspotElt); } $gapImgElts = $this->getChildElementsByTagName($element, 'gapImg'); if (count($gapImgElts) > 0) { $gapImgs = new GapImgCollection(); foreach ($gapImgElts as $gapImgElt) { $gapImgs[] = $this->getMarshallerFactory()->createMarshaller($gapImgElt)->unmarshall($gapImgElt); } $component = new GraphicGapMatchInteraction($responseIdentifier, $object, $gapImgs, $associableHotspots); $promptElts = $this->getChildElementsByTagName($element, 'prompt'); if (count($promptElts) > 0) { $promptElt = $promptElts[0]; $prompt = $this->getMarshallerFactory()->createMarshaller($promptElt)->unmarshall($promptElt); $component->setPrompt($prompt); } if (($xmlBase = self::getXmlBase($element)) !== false) { $component->setXmlBase($xmlBase); } $this->fillBodyElement($component, $element); return $component; } else { $msg = "A 'graphicGapMatchInteraction' element must contain at least one 'gapImg' element, none given."; throw new UnmarshallingException($msg, $element); } } else { $msg = "A 'graphiGapMatchInteraction' element must contain at least one 'associableHotspot' element, none given."; throw new UnmarshallingException($msg, $element); } } else { $msg = "A 'graphicGapMatchInteraction' element must contain exactly one 'object' element, none given."; throw new UnmarshallingException($msg, $element); } } else { $msg = "The mandatory 'responseIdentifier' attribute is missing from the 'graphicGapMatchInteraction' element."; throw new UnmarshallingException($msg, $element); } }
[ "protected", "function", "unmarshall", "(", "DOMElement", "$", "element", ")", "{", "if", "(", "(", "$", "responseIdentifier", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'responseIdentifier'", ")", ")", "!==", "null", ")", "{", "$", "objectElts", "=", "$", "this", "->", "getChildElementsByTagName", "(", "$", "element", ",", "'object'", ")", ";", "if", "(", "count", "(", "$", "objectElts", ")", ">", "0", ")", "{", "$", "object", "=", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "objectElts", "[", "0", "]", ")", "->", "unmarshall", "(", "$", "objectElts", "[", "0", "]", ")", ";", "$", "associableHotspotElts", "=", "$", "this", "->", "getChildElementsByTagName", "(", "$", "element", ",", "'associableHotspot'", ")", ";", "if", "(", "count", "(", "$", "associableHotspotElts", ")", ">", "0", ")", "{", "$", "associableHotspots", "=", "new", "AssociableHotspotCollection", "(", ")", ";", "foreach", "(", "$", "associableHotspotElts", "as", "$", "associableHotspotElt", ")", "{", "$", "associableHotspots", "[", "]", "=", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "associableHotspotElt", ")", "->", "unmarshall", "(", "$", "associableHotspotElt", ")", ";", "}", "$", "gapImgElts", "=", "$", "this", "->", "getChildElementsByTagName", "(", "$", "element", ",", "'gapImg'", ")", ";", "if", "(", "count", "(", "$", "gapImgElts", ")", ">", "0", ")", "{", "$", "gapImgs", "=", "new", "GapImgCollection", "(", ")", ";", "foreach", "(", "$", "gapImgElts", "as", "$", "gapImgElt", ")", "{", "$", "gapImgs", "[", "]", "=", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "gapImgElt", ")", "->", "unmarshall", "(", "$", "gapImgElt", ")", ";", "}", "$", "component", "=", "new", "GraphicGapMatchInteraction", "(", "$", "responseIdentifier", ",", "$", "object", ",", "$", "gapImgs", ",", "$", "associableHotspots", ")", ";", "$", "promptElts", "=", "$", "this", "->", "getChildElementsByTagName", "(", "$", "element", ",", "'prompt'", ")", ";", "if", "(", "count", "(", "$", "promptElts", ")", ">", "0", ")", "{", "$", "promptElt", "=", "$", "promptElts", "[", "0", "]", ";", "$", "prompt", "=", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "promptElt", ")", "->", "unmarshall", "(", "$", "promptElt", ")", ";", "$", "component", "->", "setPrompt", "(", "$", "prompt", ")", ";", "}", "if", "(", "(", "$", "xmlBase", "=", "self", "::", "getXmlBase", "(", "$", "element", ")", ")", "!==", "false", ")", "{", "$", "component", "->", "setXmlBase", "(", "$", "xmlBase", ")", ";", "}", "$", "this", "->", "fillBodyElement", "(", "$", "component", ",", "$", "element", ")", ";", "return", "$", "component", ";", "}", "else", "{", "$", "msg", "=", "\"A 'graphicGapMatchInteraction' element must contain at least one 'gapImg' element, none given.\"", ";", "throw", "new", "UnmarshallingException", "(", "$", "msg", ",", "$", "element", ")", ";", "}", "}", "else", "{", "$", "msg", "=", "\"A 'graphiGapMatchInteraction' element must contain at least one 'associableHotspot' element, none given.\"", ";", "throw", "new", "UnmarshallingException", "(", "$", "msg", ",", "$", "element", ")", ";", "}", "}", "else", "{", "$", "msg", "=", "\"A 'graphicGapMatchInteraction' element must contain exactly one 'object' element, none given.\"", ";", "throw", "new", "UnmarshallingException", "(", "$", "msg", ",", "$", "element", ")", ";", "}", "}", "else", "{", "$", "msg", "=", "\"The mandatory 'responseIdentifier' attribute is missing from the 'graphicGapMatchInteraction' element.\"", ";", "throw", "new", "UnmarshallingException", "(", "$", "msg", ",", "$", "element", ")", ";", "}", "}" ]
Unmarshall a DOMElement object corresponding to a graphicGapMatchInteraction element. @param \DOMElement $element A DOMElement object. @return \qtism\data\QtiComponent A GraphicGapMatchInteraction object. @throws \qtism\data\storage\xml\marshalling\UnmarshallingException
[ "Unmarshall", "a", "DOMElement", "object", "corresponding", "to", "a", "graphicGapMatchInteraction", "element", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/GraphicGapMatchInteractionMarshaller.php#L46-L108
oat-sa/qti-sdk
src/qtism/data/storage/xml/marshalling/GraphicGapMatchInteractionMarshaller.php
GraphicGapMatchInteractionMarshaller.marshall
protected function marshall(QtiComponent $component) { $element = $this->createElement($component); $this->fillElement($element, $component); $this->setDOMElementAttribute($element, 'responseIdentifier', $component->getResponseIdentifier()); if ($component->hasPrompt() === true) { $element->appendChild($this->getMarshallerFactory()->createMarshaller($component->getPrompt())->marshall($component->getPrompt())); } if ($component->hasXmlBase() === true) { self::setXmlBase($element, $component->getXmlBase()); } $element->appendChild($this->getMarshallerFactory()->createMarshaller($component->getObject())->marshall($component->getObject())); foreach ($component->getGapImgs() as $gapImg) { $element->appendChild($this->getMarshallerFactory()->createMarshaller($gapImg)->marshall($gapImg)); } foreach ($component->getAssociableHotspots() as $associableHotspot) { $element->appendChild($this->getMarshallerFactory()->createMarshaller($associableHotspot)->marshall($associableHotspot)); } return $element; }
php
protected function marshall(QtiComponent $component) { $element = $this->createElement($component); $this->fillElement($element, $component); $this->setDOMElementAttribute($element, 'responseIdentifier', $component->getResponseIdentifier()); if ($component->hasPrompt() === true) { $element->appendChild($this->getMarshallerFactory()->createMarshaller($component->getPrompt())->marshall($component->getPrompt())); } if ($component->hasXmlBase() === true) { self::setXmlBase($element, $component->getXmlBase()); } $element->appendChild($this->getMarshallerFactory()->createMarshaller($component->getObject())->marshall($component->getObject())); foreach ($component->getGapImgs() as $gapImg) { $element->appendChild($this->getMarshallerFactory()->createMarshaller($gapImg)->marshall($gapImg)); } foreach ($component->getAssociableHotspots() as $associableHotspot) { $element->appendChild($this->getMarshallerFactory()->createMarshaller($associableHotspot)->marshall($associableHotspot)); } return $element; }
[ "protected", "function", "marshall", "(", "QtiComponent", "$", "component", ")", "{", "$", "element", "=", "$", "this", "->", "createElement", "(", "$", "component", ")", ";", "$", "this", "->", "fillElement", "(", "$", "element", ",", "$", "component", ")", ";", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'responseIdentifier'", ",", "$", "component", "->", "getResponseIdentifier", "(", ")", ")", ";", "if", "(", "$", "component", "->", "hasPrompt", "(", ")", "===", "true", ")", "{", "$", "element", "->", "appendChild", "(", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "component", "->", "getPrompt", "(", ")", ")", "->", "marshall", "(", "$", "component", "->", "getPrompt", "(", ")", ")", ")", ";", "}", "if", "(", "$", "component", "->", "hasXmlBase", "(", ")", "===", "true", ")", "{", "self", "::", "setXmlBase", "(", "$", "element", ",", "$", "component", "->", "getXmlBase", "(", ")", ")", ";", "}", "$", "element", "->", "appendChild", "(", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "component", "->", "getObject", "(", ")", ")", "->", "marshall", "(", "$", "component", "->", "getObject", "(", ")", ")", ")", ";", "foreach", "(", "$", "component", "->", "getGapImgs", "(", ")", "as", "$", "gapImg", ")", "{", "$", "element", "->", "appendChild", "(", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "gapImg", ")", "->", "marshall", "(", "$", "gapImg", ")", ")", ";", "}", "foreach", "(", "$", "component", "->", "getAssociableHotspots", "(", ")", "as", "$", "associableHotspot", ")", "{", "$", "element", "->", "appendChild", "(", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "associableHotspot", ")", "->", "marshall", "(", "$", "associableHotspot", ")", ")", ";", "}", "return", "$", "element", ";", "}" ]
Marshall an GraphicGapMatchInteraction object into a DOMElement object. @param \qtism\data\QtiComponent $component A GraphicGapMatchInteraction object. @return \DOMElement The according DOMElement object. @throws \qtism\data\storage\xml\marshalling\MarshallingException
[ "Marshall", "an", "GraphicGapMatchInteraction", "object", "into", "a", "DOMElement", "object", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/GraphicGapMatchInteractionMarshaller.php#L117-L142
oat-sa/qti-sdk
src/qtism/data/state/Value.php
Value.setPartOfRecord
public function setPartOfRecord($partOfRecord) { if (is_bool($partOfRecord)) { $this->isPartOfRecord = $partOfRecord; } else { $msg = "The argument must be a boolean, '" . gettype($partOfRecord) . "' given."; throw new InvalidArgumentException($msg); } }
php
public function setPartOfRecord($partOfRecord) { if (is_bool($partOfRecord)) { $this->isPartOfRecord = $partOfRecord; } else { $msg = "The argument must be a boolean, '" . gettype($partOfRecord) . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setPartOfRecord", "(", "$", "partOfRecord", ")", "{", "if", "(", "is_bool", "(", "$", "partOfRecord", ")", ")", "{", "$", "this", "->", "isPartOfRecord", "=", "$", "partOfRecord", ";", "}", "else", "{", "$", "msg", "=", "\"The argument must be a boolean, '\"", ".", "gettype", "(", "$", "partOfRecord", ")", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set wether or not the value is part of a record. @param boolean $partOfRecord @throws \InvalidArgumentException If $partOfRecord is not a boolean.
[ "Set", "wether", "or", "not", "the", "value", "is", "part", "of", "a", "record", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/state/Value.php#L111-L119
oat-sa/qti-sdk
src/qtism/data/state/Value.php
Value.setFieldIdentifier
public function setFieldIdentifier($fieldIdentifier) { if ($fieldIdentifier == '' || Format::isIdentifier($fieldIdentifier)) { $this->fieldIdentifier = $fieldIdentifier; } else { $msg = "'${fieldIdentifier}' is not a valid QTI identifier."; throw new InvalidArgumentException($msg); } }
php
public function setFieldIdentifier($fieldIdentifier) { if ($fieldIdentifier == '' || Format::isIdentifier($fieldIdentifier)) { $this->fieldIdentifier = $fieldIdentifier; } else { $msg = "'${fieldIdentifier}' is not a valid QTI identifier."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setFieldIdentifier", "(", "$", "fieldIdentifier", ")", "{", "if", "(", "$", "fieldIdentifier", "==", "''", "||", "Format", "::", "isIdentifier", "(", "$", "fieldIdentifier", ")", ")", "{", "$", "this", "->", "fieldIdentifier", "=", "$", "fieldIdentifier", ";", "}", "else", "{", "$", "msg", "=", "\"'${fieldIdentifier}' is not a valid QTI identifier.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set the field identifier. An empty string means it is not specified. @param string $fieldIdentifier A QTI identifier. @throws \InvalidArgumentException If $fieldIdentifier is not a valid QTI Identifier.
[ "Set", "the", "field", "identifier", ".", "An", "empty", "string", "means", "it", "is", "not", "specified", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/state/Value.php#L147-L155
oat-sa/qti-sdk
src/qtism/common/datatypes/QtiShape.php
QtiShape.asArray
public static function asArray() { return array( 'DEF' => self::DEF, 'RECT' => self::RECT, 'CIRCLE' => self::CIRCLE, 'POLY' => self::POLY, 'ELLIPSE' => self::ELLIPSE ); }
php
public static function asArray() { return array( 'DEF' => self::DEF, 'RECT' => self::RECT, 'CIRCLE' => self::CIRCLE, 'POLY' => self::POLY, 'ELLIPSE' => self::ELLIPSE ); }
[ "public", "static", "function", "asArray", "(", ")", "{", "return", "array", "(", "'DEF'", "=>", "self", "::", "DEF", ",", "'RECT'", "=>", "self", "::", "RECT", ",", "'CIRCLE'", "=>", "self", "::", "CIRCLE", ",", "'POLY'", "=>", "self", "::", "POLY", ",", "'ELLIPSE'", "=>", "self", "::", "ELLIPSE", ")", ";", "}" ]
Get the enumeration as an array. @return array An associative array.
[ "Get", "the", "enumeration", "as", "an", "array", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/datatypes/QtiShape.php#L92-L101
oat-sa/qti-sdk
src/qtism/common/datatypes/QtiShape.php
QtiShape.getConstantByName
public static function getConstantByName($name) { switch (strtolower($name)) { case 'default': return self::DEF; break; case 'rect': return self::RECT; break; case 'circle': return self::CIRCLE; break; case 'poly': return self::POLY; break; case 'ellipse': return self::ELLIPSE; break; default: return false; break; } }
php
public static function getConstantByName($name) { switch (strtolower($name)) { case 'default': return self::DEF; break; case 'rect': return self::RECT; break; case 'circle': return self::CIRCLE; break; case 'poly': return self::POLY; break; case 'ellipse': return self::ELLIPSE; break; default: return false; break; } }
[ "public", "static", "function", "getConstantByName", "(", "$", "name", ")", "{", "switch", "(", "strtolower", "(", "$", "name", ")", ")", "{", "case", "'default'", ":", "return", "self", "::", "DEF", ";", "break", ";", "case", "'rect'", ":", "return", "self", "::", "RECT", ";", "break", ";", "case", "'circle'", ":", "return", "self", "::", "CIRCLE", ";", "break", ";", "case", "'poly'", ":", "return", "self", "::", "POLY", ";", "break", ";", "case", "'ellipse'", ":", "return", "self", "::", "ELLIPSE", ";", "break", ";", "default", ":", "return", "false", ";", "break", ";", "}", "}" ]
Get the constant value associated with $name. @param string $name @return integer|boolean The constant value associated with the name or false if not found.
[ "Get", "the", "constant", "value", "associated", "with", "$name", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/datatypes/QtiShape.php#L109-L136
oat-sa/qti-sdk
src/qtism/common/datatypes/QtiShape.php
QtiShape.getNameByConstant
public static function getNameByConstant($constant) { switch ($constant) { case self::DEF: return 'default'; break; case self::RECT: return 'rect'; break; case self::CIRCLE: return 'circle'; break; case self::POLY: return 'poly'; break; case self::ELLIPSE: return 'ellipse'; break; default: return false; break; } }
php
public static function getNameByConstant($constant) { switch ($constant) { case self::DEF: return 'default'; break; case self::RECT: return 'rect'; break; case self::CIRCLE: return 'circle'; break; case self::POLY: return 'poly'; break; case self::ELLIPSE: return 'ellipse'; break; default: return false; break; } }
[ "public", "static", "function", "getNameByConstant", "(", "$", "constant", ")", "{", "switch", "(", "$", "constant", ")", "{", "case", "self", "::", "DEF", ":", "return", "'default'", ";", "break", ";", "case", "self", "::", "RECT", ":", "return", "'rect'", ";", "break", ";", "case", "self", "::", "CIRCLE", ":", "return", "'circle'", ";", "break", ";", "case", "self", "::", "POLY", ":", "return", "'poly'", ";", "break", ";", "case", "self", "::", "ELLIPSE", ":", "return", "'ellipse'", ";", "break", ";", "default", ":", "return", "false", ";", "break", ";", "}", "}" ]
Get the name associated with $constant. @param integer $constant @return string|boolean The name or false if not found.
[ "Get", "the", "name", "associated", "with", "$constant", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/datatypes/QtiShape.php#L144-L171
oat-sa/qti-sdk
src/qtism/data/state/Weight.php
Weight.setValue
public function setValue($value) { if (is_int($value) || is_float($value)) { $this->value = $value; } else { $msg = "The value of a Weight must be a valid integer or float value, '" . gettype($value) . "' given."; throw new InvalidArgumentException($msg); } }
php
public function setValue($value) { if (is_int($value) || is_float($value)) { $this->value = $value; } else { $msg = "The value of a Weight must be a valid integer or float value, '" . gettype($value) . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setValue", "(", "$", "value", ")", "{", "if", "(", "is_int", "(", "$", "value", ")", "||", "is_float", "(", "$", "value", ")", ")", "{", "$", "this", "->", "value", "=", "$", "value", ";", "}", "else", "{", "$", "msg", "=", "\"The value of a Weight must be a valid integer or float value, '\"", ".", "gettype", "(", "$", "value", ")", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set the value of the Weight. @param int|float $value A in integer/float value. @throws \InvalidArgumentException If $value is not an integer nor a float.
[ "Set", "the", "value", "of", "the", "Weight", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/state/Weight.php#L123-L131
oat-sa/qti-sdk
src/qtism/runtime/expressions/MapResponseProcessor.php
MapResponseProcessor.process
public function process() { $expr = $this->getExpression(); $state = $this->getState(); $identifier = $expr->getIdentifier(); $variable = $state->getVariable($identifier); if (!is_null($variable)) { if ($variable instanceof ResponseVariable) { $mapping = $variable->getMapping(); if (is_null($mapping)) { return new QtiFloat(0.0); } // Single cardinality behaviour. if ($variable->isSingle()) { $result = 0.0; $mappedCount = 0; foreach ($mapping->getMapEntries() as $mapEntry) { $val = $state[$identifier]; $mapKey = $mapEntry->getMapKey(); if ($val instanceof QtiString && $mapEntry->isCaseSensitive() === false) { $val = mb_strtolower($val->getValue(), 'UTF-8'); $mapKey = mb_strtolower($mapKey, 'UTF-8'); } if ($val instanceof Comparable && $val->equals($mapKey) || $val === $mapKey) { $result += $mapEntry->getMappedValue(); $mappedCount++; } elseif ($variable->getBaseType() === BaseType::STRING && $val === null && $mapKey === '') { $result += $mapEntry->getMappedValue(); $mappedCount++; } } if ($mappedCount === 0) { // No relevant mapping found, return mapping default. $result = $mapping->getDefaultValue(); } // Always compare the result with lower or upper bound. if ($mapping->hasLowerBound() && $result < $mapping->getLowerBound()) { return new QtiFloat($mapping->getLowerBound()); } elseif ($mapping->hasUpperBound() && $result > $mapping->getUpperBound()) { return new QtiFloat($mapping->getUpperBound()); } else { return new QtiFloat($result); } // Multiple cardinality behaviour. } elseif ($variable->isMultiple()) { // Make the values in the collection unique values. // See QTI 2.1 Spec (mapResponse) expression: "If a container contains multiple instances of the same // value then that value is counted once only". $result = 0.0; $variableValue = ($variable->getValue() === null || count($variable->getValue()) === 0) ? array(null) : $variable->getValue()->distinct(); $mapEntries = $mapping->getMapEntries(); foreach ($variableValue as $val) { $mappedCount = 0; for ($i = 0; $i < count($mapEntries); $i++) { $mapKey = $rawMapKey = $mapEntries[$i]->getMapKey(); if ($val instanceof QtiString && $mapEntries[$i]->isCaseSensitive() === false) { $val = new QtiString(mb_strtolower($val->getValue(), 'UTF-8')); $mapKey = mb_strtolower($mapKey, 'UTF-8'); } if (($val instanceof Comparable && $val->equals($mapKey) === true) || ($variable->getBaseType() === BaseType::STRING && $val === null && $mapKey === '')) { $result += $mapEntries[$i]->getMappedValue(); $mappedCount++; } } if ($mappedCount === 0) { // No explicit mapping found for source value $val. $result += $mapping->getDefaultValue(); } } // When mapping a container, try to apply lower or upper bound. if ($mapping->hasLowerBound() && $result < $mapping->getLowerBound()) { return new QtiFloat($mapping->getLowerBound()); } elseif ($mapping->hasUpperBound() && $result > $mapping->getUpperBound()) { return new QtiFloat($mapping->getUpperBound()); } else { return new QtiFloat($result); } } else { $msg = "MapResponse cannot be applied on a Record container."; throw new ExpressionProcessingException($msg, $this, ExpressionProcessingException::WRONG_VARIABLE_BASETYPE); } } else { $msg = "The target variable of a MapResponse expression must be a ResponseVariable."; throw new ExpressionProcessingException($msg, $this, ExpressionProcessingException::WRONG_VARIABLE_TYPE); } } else { $msg = "No variable with identifier '${identifier}' could be found while processing MapResponse."; throw new ExpressionProcessingException($msg, $this, ExpressionProcessingException::NONEXISTENT_VARIABLE); } }
php
public function process() { $expr = $this->getExpression(); $state = $this->getState(); $identifier = $expr->getIdentifier(); $variable = $state->getVariable($identifier); if (!is_null($variable)) { if ($variable instanceof ResponseVariable) { $mapping = $variable->getMapping(); if (is_null($mapping)) { return new QtiFloat(0.0); } // Single cardinality behaviour. if ($variable->isSingle()) { $result = 0.0; $mappedCount = 0; foreach ($mapping->getMapEntries() as $mapEntry) { $val = $state[$identifier]; $mapKey = $mapEntry->getMapKey(); if ($val instanceof QtiString && $mapEntry->isCaseSensitive() === false) { $val = mb_strtolower($val->getValue(), 'UTF-8'); $mapKey = mb_strtolower($mapKey, 'UTF-8'); } if ($val instanceof Comparable && $val->equals($mapKey) || $val === $mapKey) { $result += $mapEntry->getMappedValue(); $mappedCount++; } elseif ($variable->getBaseType() === BaseType::STRING && $val === null && $mapKey === '') { $result += $mapEntry->getMappedValue(); $mappedCount++; } } if ($mappedCount === 0) { // No relevant mapping found, return mapping default. $result = $mapping->getDefaultValue(); } // Always compare the result with lower or upper bound. if ($mapping->hasLowerBound() && $result < $mapping->getLowerBound()) { return new QtiFloat($mapping->getLowerBound()); } elseif ($mapping->hasUpperBound() && $result > $mapping->getUpperBound()) { return new QtiFloat($mapping->getUpperBound()); } else { return new QtiFloat($result); } // Multiple cardinality behaviour. } elseif ($variable->isMultiple()) { // Make the values in the collection unique values. // See QTI 2.1 Spec (mapResponse) expression: "If a container contains multiple instances of the same // value then that value is counted once only". $result = 0.0; $variableValue = ($variable->getValue() === null || count($variable->getValue()) === 0) ? array(null) : $variable->getValue()->distinct(); $mapEntries = $mapping->getMapEntries(); foreach ($variableValue as $val) { $mappedCount = 0; for ($i = 0; $i < count($mapEntries); $i++) { $mapKey = $rawMapKey = $mapEntries[$i]->getMapKey(); if ($val instanceof QtiString && $mapEntries[$i]->isCaseSensitive() === false) { $val = new QtiString(mb_strtolower($val->getValue(), 'UTF-8')); $mapKey = mb_strtolower($mapKey, 'UTF-8'); } if (($val instanceof Comparable && $val->equals($mapKey) === true) || ($variable->getBaseType() === BaseType::STRING && $val === null && $mapKey === '')) { $result += $mapEntries[$i]->getMappedValue(); $mappedCount++; } } if ($mappedCount === 0) { // No explicit mapping found for source value $val. $result += $mapping->getDefaultValue(); } } // When mapping a container, try to apply lower or upper bound. if ($mapping->hasLowerBound() && $result < $mapping->getLowerBound()) { return new QtiFloat($mapping->getLowerBound()); } elseif ($mapping->hasUpperBound() && $result > $mapping->getUpperBound()) { return new QtiFloat($mapping->getUpperBound()); } else { return new QtiFloat($result); } } else { $msg = "MapResponse cannot be applied on a Record container."; throw new ExpressionProcessingException($msg, $this, ExpressionProcessingException::WRONG_VARIABLE_BASETYPE); } } else { $msg = "The target variable of a MapResponse expression must be a ResponseVariable."; throw new ExpressionProcessingException($msg, $this, ExpressionProcessingException::WRONG_VARIABLE_TYPE); } } else { $msg = "No variable with identifier '${identifier}' could be found while processing MapResponse."; throw new ExpressionProcessingException($msg, $this, ExpressionProcessingException::NONEXISTENT_VARIABLE); } }
[ "public", "function", "process", "(", ")", "{", "$", "expr", "=", "$", "this", "->", "getExpression", "(", ")", ";", "$", "state", "=", "$", "this", "->", "getState", "(", ")", ";", "$", "identifier", "=", "$", "expr", "->", "getIdentifier", "(", ")", ";", "$", "variable", "=", "$", "state", "->", "getVariable", "(", "$", "identifier", ")", ";", "if", "(", "!", "is_null", "(", "$", "variable", ")", ")", "{", "if", "(", "$", "variable", "instanceof", "ResponseVariable", ")", "{", "$", "mapping", "=", "$", "variable", "->", "getMapping", "(", ")", ";", "if", "(", "is_null", "(", "$", "mapping", ")", ")", "{", "return", "new", "QtiFloat", "(", "0.0", ")", ";", "}", "// Single cardinality behaviour.", "if", "(", "$", "variable", "->", "isSingle", "(", ")", ")", "{", "$", "result", "=", "0.0", ";", "$", "mappedCount", "=", "0", ";", "foreach", "(", "$", "mapping", "->", "getMapEntries", "(", ")", "as", "$", "mapEntry", ")", "{", "$", "val", "=", "$", "state", "[", "$", "identifier", "]", ";", "$", "mapKey", "=", "$", "mapEntry", "->", "getMapKey", "(", ")", ";", "if", "(", "$", "val", "instanceof", "QtiString", "&&", "$", "mapEntry", "->", "isCaseSensitive", "(", ")", "===", "false", ")", "{", "$", "val", "=", "mb_strtolower", "(", "$", "val", "->", "getValue", "(", ")", ",", "'UTF-8'", ")", ";", "$", "mapKey", "=", "mb_strtolower", "(", "$", "mapKey", ",", "'UTF-8'", ")", ";", "}", "if", "(", "$", "val", "instanceof", "Comparable", "&&", "$", "val", "->", "equals", "(", "$", "mapKey", ")", "||", "$", "val", "===", "$", "mapKey", ")", "{", "$", "result", "+=", "$", "mapEntry", "->", "getMappedValue", "(", ")", ";", "$", "mappedCount", "++", ";", "}", "elseif", "(", "$", "variable", "->", "getBaseType", "(", ")", "===", "BaseType", "::", "STRING", "&&", "$", "val", "===", "null", "&&", "$", "mapKey", "===", "''", ")", "{", "$", "result", "+=", "$", "mapEntry", "->", "getMappedValue", "(", ")", ";", "$", "mappedCount", "++", ";", "}", "}", "if", "(", "$", "mappedCount", "===", "0", ")", "{", "// No relevant mapping found, return mapping default.", "$", "result", "=", "$", "mapping", "->", "getDefaultValue", "(", ")", ";", "}", "// Always compare the result with lower or upper bound.", "if", "(", "$", "mapping", "->", "hasLowerBound", "(", ")", "&&", "$", "result", "<", "$", "mapping", "->", "getLowerBound", "(", ")", ")", "{", "return", "new", "QtiFloat", "(", "$", "mapping", "->", "getLowerBound", "(", ")", ")", ";", "}", "elseif", "(", "$", "mapping", "->", "hasUpperBound", "(", ")", "&&", "$", "result", ">", "$", "mapping", "->", "getUpperBound", "(", ")", ")", "{", "return", "new", "QtiFloat", "(", "$", "mapping", "->", "getUpperBound", "(", ")", ")", ";", "}", "else", "{", "return", "new", "QtiFloat", "(", "$", "result", ")", ";", "}", "// Multiple cardinality behaviour.", "}", "elseif", "(", "$", "variable", "->", "isMultiple", "(", ")", ")", "{", "// Make the values in the collection unique values.", "// See QTI 2.1 Spec (mapResponse) expression: \"If a container contains multiple instances of the same ", "// value then that value is counted once only\".", "$", "result", "=", "0.0", ";", "$", "variableValue", "=", "(", "$", "variable", "->", "getValue", "(", ")", "===", "null", "||", "count", "(", "$", "variable", "->", "getValue", "(", ")", ")", "===", "0", ")", "?", "array", "(", "null", ")", ":", "$", "variable", "->", "getValue", "(", ")", "->", "distinct", "(", ")", ";", "$", "mapEntries", "=", "$", "mapping", "->", "getMapEntries", "(", ")", ";", "foreach", "(", "$", "variableValue", "as", "$", "val", ")", "{", "$", "mappedCount", "=", "0", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "count", "(", "$", "mapEntries", ")", ";", "$", "i", "++", ")", "{", "$", "mapKey", "=", "$", "rawMapKey", "=", "$", "mapEntries", "[", "$", "i", "]", "->", "getMapKey", "(", ")", ";", "if", "(", "$", "val", "instanceof", "QtiString", "&&", "$", "mapEntries", "[", "$", "i", "]", "->", "isCaseSensitive", "(", ")", "===", "false", ")", "{", "$", "val", "=", "new", "QtiString", "(", "mb_strtolower", "(", "$", "val", "->", "getValue", "(", ")", ",", "'UTF-8'", ")", ")", ";", "$", "mapKey", "=", "mb_strtolower", "(", "$", "mapKey", ",", "'UTF-8'", ")", ";", "}", "if", "(", "(", "$", "val", "instanceof", "Comparable", "&&", "$", "val", "->", "equals", "(", "$", "mapKey", ")", "===", "true", ")", "||", "(", "$", "variable", "->", "getBaseType", "(", ")", "===", "BaseType", "::", "STRING", "&&", "$", "val", "===", "null", "&&", "$", "mapKey", "===", "''", ")", ")", "{", "$", "result", "+=", "$", "mapEntries", "[", "$", "i", "]", "->", "getMappedValue", "(", ")", ";", "$", "mappedCount", "++", ";", "}", "}", "if", "(", "$", "mappedCount", "===", "0", ")", "{", "// No explicit mapping found for source value $val.", "$", "result", "+=", "$", "mapping", "->", "getDefaultValue", "(", ")", ";", "}", "}", "// When mapping a container, try to apply lower or upper bound.", "if", "(", "$", "mapping", "->", "hasLowerBound", "(", ")", "&&", "$", "result", "<", "$", "mapping", "->", "getLowerBound", "(", ")", ")", "{", "return", "new", "QtiFloat", "(", "$", "mapping", "->", "getLowerBound", "(", ")", ")", ";", "}", "elseif", "(", "$", "mapping", "->", "hasUpperBound", "(", ")", "&&", "$", "result", ">", "$", "mapping", "->", "getUpperBound", "(", ")", ")", "{", "return", "new", "QtiFloat", "(", "$", "mapping", "->", "getUpperBound", "(", ")", ")", ";", "}", "else", "{", "return", "new", "QtiFloat", "(", "$", "result", ")", ";", "}", "}", "else", "{", "$", "msg", "=", "\"MapResponse cannot be applied on a Record container.\"", ";", "throw", "new", "ExpressionProcessingException", "(", "$", "msg", ",", "$", "this", ",", "ExpressionProcessingException", "::", "WRONG_VARIABLE_BASETYPE", ")", ";", "}", "}", "else", "{", "$", "msg", "=", "\"The target variable of a MapResponse expression must be a ResponseVariable.\"", ";", "throw", "new", "ExpressionProcessingException", "(", "$", "msg", ",", "$", "this", ",", "ExpressionProcessingException", "::", "WRONG_VARIABLE_TYPE", ")", ";", "}", "}", "else", "{", "$", "msg", "=", "\"No variable with identifier '${identifier}' could be found while processing MapResponse.\"", ";", "throw", "new", "ExpressionProcessingException", "(", "$", "msg", ",", "$", "this", ",", "ExpressionProcessingException", "::", "NONEXISTENT_VARIABLE", ")", ";", "}", "}" ]
Process the MapResponse expression. * An ExpressionProcessingException is thrown if the variable is not defined. * An ExpressionProcessingException is thrown if the variable has no mapping defined. * An ExpressionProcessingException is thrown if the variable is not a ResponseVariable. * An ExpressionProcessingException is thrown if the cardinality of the variable is RECORD. @return QtiFloat a QTI float value. @throws \qtism\runtime\expressions\ExpressionProcessingException
[ "Process", "the", "MapResponse", "expression", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/MapResponseProcessor.php#L69-L179
oat-sa/qti-sdk
src/qtism/runtime/rendering/qtipl/rules/TemplateConditionQtiPLRenderer.php
TemplateConditionQtiPLRenderer.render
public function render($something) { $renderer = new QtiPLRenderer($this->getCRO()); $qtipl = $renderer->render($something->getTemplateIf()); foreach ($something->getTemplateElseIfs() as $elseif) { $qtipl .= " " . $renderer->render($elseif); } $qtipl .= ($something->getTemplateElse() == null) ? "" : $renderer->render($something->getTemplateElse()); return $qtipl; }
php
public function render($something) { $renderer = new QtiPLRenderer($this->getCRO()); $qtipl = $renderer->render($something->getTemplateIf()); foreach ($something->getTemplateElseIfs() as $elseif) { $qtipl .= " " . $renderer->render($elseif); } $qtipl .= ($something->getTemplateElse() == null) ? "" : $renderer->render($something->getTemplateElse()); return $qtipl; }
[ "public", "function", "render", "(", "$", "something", ")", "{", "$", "renderer", "=", "new", "QtiPLRenderer", "(", "$", "this", "->", "getCRO", "(", ")", ")", ";", "$", "qtipl", "=", "$", "renderer", "->", "render", "(", "$", "something", "->", "getTemplateIf", "(", ")", ")", ";", "foreach", "(", "$", "something", "->", "getTemplateElseIfs", "(", ")", "as", "$", "elseif", ")", "{", "$", "qtipl", ".=", "\" \"", ".", "$", "renderer", "->", "render", "(", "$", "elseif", ")", ";", "}", "$", "qtipl", ".=", "(", "$", "something", "->", "getTemplateElse", "(", ")", "==", "null", ")", "?", "\"\"", ":", "$", "renderer", "->", "render", "(", "$", "something", "->", "getTemplateElse", "(", ")", ")", ";", "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/TemplateConditionQtiPLRenderer.php#L45-L56
oat-sa/qti-sdk
src/qtism/common/datatypes/QtiIdentifier.php
QtiIdentifier.checkType
protected function checkType($value) { if (is_string($value) !== true) { $msg = "The Identifier Datatype only accepts to store identifier values."; throw new InvalidArgumentException($msg); } elseif ($value === '') { $msg = "The Identifier Datatype do not accept empty strings as valid identifiers."; throw new InvalidArgumentException($msg); } }
php
protected function checkType($value) { if (is_string($value) !== true) { $msg = "The Identifier Datatype only accepts to store identifier values."; throw new InvalidArgumentException($msg); } elseif ($value === '') { $msg = "The Identifier Datatype do not accept empty strings as valid identifiers."; throw new InvalidArgumentException($msg); } }
[ "protected", "function", "checkType", "(", "$", "value", ")", "{", "if", "(", "is_string", "(", "$", "value", ")", "!==", "true", ")", "{", "$", "msg", "=", "\"The Identifier Datatype only accepts to store identifier values.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "elseif", "(", "$", "value", "===", "''", ")", "{", "$", "msg", "=", "\"The Identifier Datatype do not accept empty strings as valid identifiers.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Checks whether or not $value is a string value. @throws \InvalidArgumentException If $value is not a string value.
[ "Checks", "whether", "or", "not", "$value", "is", "a", "string", "value", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/datatypes/QtiIdentifier.php#L42-L51
oat-sa/qti-sdk
src/qtism/data/expressions/operators/StringMatch.php
StringMatch.setSubstring
public function setSubstring($substring) { if (is_bool($substring)) { $this->substring = $substring; } else { $msg = "The substring argument must be a boolean, '" . gettype($substring) . "' given."; throw new InvalidArgumentException($msg); } }
php
public function setSubstring($substring) { if (is_bool($substring)) { $this->substring = $substring; } else { $msg = "The substring argument must be a boolean, '" . gettype($substring) . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setSubstring", "(", "$", "substring", ")", "{", "if", "(", "is_bool", "(", "$", "substring", ")", ")", "{", "$", "this", "->", "substring", "=", "$", "substring", ";", "}", "else", "{", "$", "msg", "=", "\"The substring argument must be a boolean, '\"", ".", "gettype", "(", "$", "substring", ")", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set the substring attribute. @param boolean $substring A boolean value. @throws \InvalidArgumentException If $substring is not a boolean. @deprecated
[ "Set", "the", "substring", "attribute", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/expressions/operators/StringMatch.php#L113-L121
oat-sa/qti-sdk
src/qtism/data/storage/xml/marshalling/RandomIntegerMarshaller.php
RandomIntegerMarshaller.marshall
protected function marshall(QtiComponent $component) { $element = static::getDOMCradle()->createElement($component->getQtiClassName()); $this->setDOMElementAttribute($element, 'min', $component->getMin()); $this->setDOMElementAttribute($element, 'max', $component->getMax()); if ($component->getStep() !== 1) { // default value of the step attribute is 1. $this->setDOMElementAttribute($element, 'step', $component->getStep()); } return $element; }
php
protected function marshall(QtiComponent $component) { $element = static::getDOMCradle()->createElement($component->getQtiClassName()); $this->setDOMElementAttribute($element, 'min', $component->getMin()); $this->setDOMElementAttribute($element, 'max', $component->getMax()); if ($component->getStep() !== 1) { // default value of the step attribute is 1. $this->setDOMElementAttribute($element, 'step', $component->getStep()); } return $element; }
[ "protected", "function", "marshall", "(", "QtiComponent", "$", "component", ")", "{", "$", "element", "=", "static", "::", "getDOMCradle", "(", ")", "->", "createElement", "(", "$", "component", "->", "getQtiClassName", "(", ")", ")", ";", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'min'", ",", "$", "component", "->", "getMin", "(", ")", ")", ";", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'max'", ",", "$", "component", "->", "getMax", "(", ")", ")", ";", "if", "(", "$", "component", "->", "getStep", "(", ")", "!==", "1", ")", "{", "// default value of the step attribute is 1.", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'step'", ",", "$", "component", "->", "getStep", "(", ")", ")", ";", "}", "return", "$", "element", ";", "}" ]
Marshall a RandomInteger object into a DOMElement object. @param \qtism\data\QtiComponent $component A RandomInteger object. @return \DOMElement The according DOMElement object.
[ "Marshall", "a", "RandomInteger", "object", "into", "a", "DOMElement", "object", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/RandomIntegerMarshaller.php#L44-L56
oat-sa/qti-sdk
src/qtism/data/storage/xml/marshalling/RandomIntegerMarshaller.php
RandomIntegerMarshaller.unmarshall
protected function unmarshall(DOMElement $element) { if (($max = $this->getDOMElementAttributeAs($element, 'max', 'string')) !== null) { $max = (Format::isVariableRef($max)) ? $max : intval($max); $object = new RandomInteger(0, $max); if (($step = $this->getDOMElementAttributeAs($element, 'step')) !== null) { $object->setStep(abs(intval($step))); } if (($min = $this->getDOMElementAttributeAs($element, 'min')) !== null) { $min = (Format::isVariableRef($min)) ? $min : intval($min); $object->setMin($min); } return $object; } else { $msg = "The mandatory attribute 'max' is missing from element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element); } }
php
protected function unmarshall(DOMElement $element) { if (($max = $this->getDOMElementAttributeAs($element, 'max', 'string')) !== null) { $max = (Format::isVariableRef($max)) ? $max : intval($max); $object = new RandomInteger(0, $max); if (($step = $this->getDOMElementAttributeAs($element, 'step')) !== null) { $object->setStep(abs(intval($step))); } if (($min = $this->getDOMElementAttributeAs($element, 'min')) !== null) { $min = (Format::isVariableRef($min)) ? $min : intval($min); $object->setMin($min); } return $object; } else { $msg = "The mandatory attribute 'max' is missing from element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element); } }
[ "protected", "function", "unmarshall", "(", "DOMElement", "$", "element", ")", "{", "if", "(", "(", "$", "max", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'max'", ",", "'string'", ")", ")", "!==", "null", ")", "{", "$", "max", "=", "(", "Format", "::", "isVariableRef", "(", "$", "max", ")", ")", "?", "$", "max", ":", "intval", "(", "$", "max", ")", ";", "$", "object", "=", "new", "RandomInteger", "(", "0", ",", "$", "max", ")", ";", "if", "(", "(", "$", "step", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'step'", ")", ")", "!==", "null", ")", "{", "$", "object", "->", "setStep", "(", "abs", "(", "intval", "(", "$", "step", ")", ")", ")", ";", "}", "if", "(", "(", "$", "min", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'min'", ")", ")", "!==", "null", ")", "{", "$", "min", "=", "(", "Format", "::", "isVariableRef", "(", "$", "min", ")", ")", "?", "$", "min", ":", "intval", "(", "$", "min", ")", ";", "$", "object", "->", "setMin", "(", "$", "min", ")", ";", "}", "return", "$", "object", ";", "}", "else", "{", "$", "msg", "=", "\"The mandatory attribute 'max' is missing from element '\"", ".", "$", "element", "->", "localName", ".", "\"'.\"", ";", "throw", "new", "UnmarshallingException", "(", "$", "msg", ",", "$", "element", ")", ";", "}", "}" ]
Unmarshall a DOMElement object corresponding to a QTI randomInteger element. @param \DOMElement $element A DOMElement object. @return \qtism\data\QtiComponent A RandomInteger object. @throws \qtism\data\storage\xml\marshalling\UnmarshallingException If the mandatory attributes 'min' or 'max' are missing from $element.
[ "Unmarshall", "a", "DOMElement", "object", "corresponding", "to", "a", "QTI", "randomInteger", "element", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/RandomIntegerMarshaller.php#L65-L85
oat-sa/qti-sdk
src/qtism/data/storage/xml/marshalling/OutcomeDeclarationMarshaller.php
OutcomeDeclarationMarshaller.marshall
protected function marshall(QtiComponent $component) { $element = parent::marshall($component); $version = $this->getVersion(); // deal with views. // !!! If $arrayViews contain all possible views, it means that the treated // !!! outcome is relevant to all views, as per QTI 2.1 spec. if (Version::compare($version, '2.1.0', '>=') === true && !in_array($component->getViews()->getArrayCopy(), View::asArray())) { $arrayViews = array(); foreach ($component->getViews() as $view) { $arrayViews[] = View::getNameByConstant($view); } if (count($arrayViews) > 0) { $this->setDOMElementAttribute($element, 'view', implode("\x20", $arrayViews)); } } // deal with interpretation. if ($component->getInterpretation() != '') { $this->setDOMElementAttribute($element, 'interpretation', $component->getInterpretation()); } // deal with long interpretation. if ($component->getLongInterpretation() != '') { $this->setDOMElementAttribute($element, 'longInterpretation', $component->getLongInterpretation()); } // Deal with normal maximum. if ($component->getNormalMaximum() !== false) { $this->setDOMElementAttribute($element, 'normalMaximum', $component->getNormalMaximum()); } // Deal with normal minimum. if (Version::compare($version, '2.1.0', '>=') === true && $component->getNormalMinimum() !== false) { $this->setDOMElementAttribute($element, 'normalMinimum', $component->getNormalMinimum()); } // Deal with mastery value. if (Version::compare($version, '2.1.0', '>=') === true && $component->getMasteryValue() !== false) { $this->setDOMElementAttribute($element, 'masteryValue', $component->getMasteryValue()); } // Deal with lookup table. if ($component->getLookupTable() != null) { $lookupTableMarshaller = $this->getMarshallerFactory()->createMarshaller($component->getLookupTable(), array($component->getBaseType())); $element->appendChild($lookupTableMarshaller->marshall($component->geTLookupTable())); } return $element; }
php
protected function marshall(QtiComponent $component) { $element = parent::marshall($component); $version = $this->getVersion(); // deal with views. // !!! If $arrayViews contain all possible views, it means that the treated // !!! outcome is relevant to all views, as per QTI 2.1 spec. if (Version::compare($version, '2.1.0', '>=') === true && !in_array($component->getViews()->getArrayCopy(), View::asArray())) { $arrayViews = array(); foreach ($component->getViews() as $view) { $arrayViews[] = View::getNameByConstant($view); } if (count($arrayViews) > 0) { $this->setDOMElementAttribute($element, 'view', implode("\x20", $arrayViews)); } } // deal with interpretation. if ($component->getInterpretation() != '') { $this->setDOMElementAttribute($element, 'interpretation', $component->getInterpretation()); } // deal with long interpretation. if ($component->getLongInterpretation() != '') { $this->setDOMElementAttribute($element, 'longInterpretation', $component->getLongInterpretation()); } // Deal with normal maximum. if ($component->getNormalMaximum() !== false) { $this->setDOMElementAttribute($element, 'normalMaximum', $component->getNormalMaximum()); } // Deal with normal minimum. if (Version::compare($version, '2.1.0', '>=') === true && $component->getNormalMinimum() !== false) { $this->setDOMElementAttribute($element, 'normalMinimum', $component->getNormalMinimum()); } // Deal with mastery value. if (Version::compare($version, '2.1.0', '>=') === true && $component->getMasteryValue() !== false) { $this->setDOMElementAttribute($element, 'masteryValue', $component->getMasteryValue()); } // Deal with lookup table. if ($component->getLookupTable() != null) { $lookupTableMarshaller = $this->getMarshallerFactory()->createMarshaller($component->getLookupTable(), array($component->getBaseType())); $element->appendChild($lookupTableMarshaller->marshall($component->geTLookupTable())); } return $element; }
[ "protected", "function", "marshall", "(", "QtiComponent", "$", "component", ")", "{", "$", "element", "=", "parent", "::", "marshall", "(", "$", "component", ")", ";", "$", "version", "=", "$", "this", "->", "getVersion", "(", ")", ";", "// deal with views.", "// !!! If $arrayViews contain all possible views, it means that the treated", "// !!! outcome is relevant to all views, as per QTI 2.1 spec.", "if", "(", "Version", "::", "compare", "(", "$", "version", ",", "'2.1.0'", ",", "'>='", ")", "===", "true", "&&", "!", "in_array", "(", "$", "component", "->", "getViews", "(", ")", "->", "getArrayCopy", "(", ")", ",", "View", "::", "asArray", "(", ")", ")", ")", "{", "$", "arrayViews", "=", "array", "(", ")", ";", "foreach", "(", "$", "component", "->", "getViews", "(", ")", "as", "$", "view", ")", "{", "$", "arrayViews", "[", "]", "=", "View", "::", "getNameByConstant", "(", "$", "view", ")", ";", "}", "if", "(", "count", "(", "$", "arrayViews", ")", ">", "0", ")", "{", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'view'", ",", "implode", "(", "\"\\x20\"", ",", "$", "arrayViews", ")", ")", ";", "}", "}", "// deal with interpretation.", "if", "(", "$", "component", "->", "getInterpretation", "(", ")", "!=", "''", ")", "{", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'interpretation'", ",", "$", "component", "->", "getInterpretation", "(", ")", ")", ";", "}", "// deal with long interpretation.", "if", "(", "$", "component", "->", "getLongInterpretation", "(", ")", "!=", "''", ")", "{", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'longInterpretation'", ",", "$", "component", "->", "getLongInterpretation", "(", ")", ")", ";", "}", "// Deal with normal maximum.", "if", "(", "$", "component", "->", "getNormalMaximum", "(", ")", "!==", "false", ")", "{", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'normalMaximum'", ",", "$", "component", "->", "getNormalMaximum", "(", ")", ")", ";", "}", "// Deal with normal minimum.", "if", "(", "Version", "::", "compare", "(", "$", "version", ",", "'2.1.0'", ",", "'>='", ")", "===", "true", "&&", "$", "component", "->", "getNormalMinimum", "(", ")", "!==", "false", ")", "{", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'normalMinimum'", ",", "$", "component", "->", "getNormalMinimum", "(", ")", ")", ";", "}", "// Deal with mastery value.", "if", "(", "Version", "::", "compare", "(", "$", "version", ",", "'2.1.0'", ",", "'>='", ")", "===", "true", "&&", "$", "component", "->", "getMasteryValue", "(", ")", "!==", "false", ")", "{", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'masteryValue'", ",", "$", "component", "->", "getMasteryValue", "(", ")", ")", ";", "}", "// Deal with lookup table.", "if", "(", "$", "component", "->", "getLookupTable", "(", ")", "!=", "null", ")", "{", "$", "lookupTableMarshaller", "=", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "component", "->", "getLookupTable", "(", ")", ",", "array", "(", "$", "component", "->", "getBaseType", "(", ")", ")", ")", ";", "$", "element", "->", "appendChild", "(", "$", "lookupTableMarshaller", "->", "marshall", "(", "$", "component", "->", "geTLookupTable", "(", ")", ")", ")", ";", "}", "return", "$", "element", ";", "}" ]
Marshall an OutcomeDeclaration object into a DOMElement object. @param \qtism\data\QtiComponent $component An OutcomeDeclaration object. @return \DOMElement The according DOMElement object.
[ "Marshall", "an", "OutcomeDeclaration", "object", "into", "a", "DOMElement", "object", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/OutcomeDeclarationMarshaller.php#L47-L98
oat-sa/qti-sdk
src/qtism/data/storage/xml/marshalling/OutcomeDeclarationMarshaller.php
OutcomeDeclarationMarshaller.unmarshall
protected function unmarshall(DOMElement $element) { try { $version = $this->getVersion(); $baseComponent = parent::unmarshall($element); $object = new OutcomeDeclaration($baseComponent->getIdentifier()); $object->setBaseType($baseComponent->getBaseType()); $object->setCardinality($baseComponent->getCardinality()); $object->setDefaultValue($baseComponent->getDefaultValue()); // deal with views. if (Version::compare($version, '2.1.0', '>=') === true && ($views = $this->getDOMElementAttributeAs($element, 'view')) != null) { $viewCollection = new ViewCollection(); foreach (explode("\x20", $views) as $viewName) { $viewCollection[] = View::getConstantByName($viewName); } $object->setViews($viewCollection); } // deal with interpretation. if (($interpretation = $this->getDOMElementAttributeAs($element, 'interpretation')) != null) { $object->setInterpretation($interpretation); } // deal with longInterpretation. if (($longInterpretation = $this->getDOMElementAttributeAs($element, 'longInterpretation')) != null) { $object->setLongInterpretation($longInterpretation); } // deal with normalMaximum. if (($normalMaximum = $this->getDOMElementAttributeAs($element, 'normalMaximum', 'float')) !== null) { $object->setNormalMaximum($normalMaximum); } // deal with normalMinimum. if (Version::compare($version, '2.1.0', '>=') === true && ($normalMinimum = $this->getDOMElementAttributeAs($element, 'normalMinimum', 'float')) !== null) { $object->setNormalMinimum($normalMinimum); } // deal with matseryValue. if (Version::compare($version, '2.1.0', '>=') === true && ($masteryValue = $this->getDOMElementAttributeAs($element, 'masteryValue', 'float')) !== null) { $object->setMasteryValue($masteryValue); } // deal with lookupTable. $interpolationTables = $element->getElementsByTagName('interpolationTable'); $matchTable = $element->getElementsByTagName('matchTable'); if ($interpolationTables->length == 1 || $matchTable->length == 1) { // we have a lookupTable defined. $lookupTable = null; if ($interpolationTables->length == 1) { $lookupTable = $interpolationTables->item(0); } else { $lookupTable = $matchTable->item(0); } $lookupTableMarshaller = $this->getMarshallerFactory()->createMarshaller($lookupTable, array($object->getBaseType())); $object->setLookupTable($lookupTableMarshaller->unmarshall($lookupTable)); } return $object; } catch (InvalidArgumentException $e) { $msg = "An unexpected error occured while unmarshalling the outcomeDeclaration."; throw new UnmarshallingException($msg, $element, $e); } }
php
protected function unmarshall(DOMElement $element) { try { $version = $this->getVersion(); $baseComponent = parent::unmarshall($element); $object = new OutcomeDeclaration($baseComponent->getIdentifier()); $object->setBaseType($baseComponent->getBaseType()); $object->setCardinality($baseComponent->getCardinality()); $object->setDefaultValue($baseComponent->getDefaultValue()); // deal with views. if (Version::compare($version, '2.1.0', '>=') === true && ($views = $this->getDOMElementAttributeAs($element, 'view')) != null) { $viewCollection = new ViewCollection(); foreach (explode("\x20", $views) as $viewName) { $viewCollection[] = View::getConstantByName($viewName); } $object->setViews($viewCollection); } // deal with interpretation. if (($interpretation = $this->getDOMElementAttributeAs($element, 'interpretation')) != null) { $object->setInterpretation($interpretation); } // deal with longInterpretation. if (($longInterpretation = $this->getDOMElementAttributeAs($element, 'longInterpretation')) != null) { $object->setLongInterpretation($longInterpretation); } // deal with normalMaximum. if (($normalMaximum = $this->getDOMElementAttributeAs($element, 'normalMaximum', 'float')) !== null) { $object->setNormalMaximum($normalMaximum); } // deal with normalMinimum. if (Version::compare($version, '2.1.0', '>=') === true && ($normalMinimum = $this->getDOMElementAttributeAs($element, 'normalMinimum', 'float')) !== null) { $object->setNormalMinimum($normalMinimum); } // deal with matseryValue. if (Version::compare($version, '2.1.0', '>=') === true && ($masteryValue = $this->getDOMElementAttributeAs($element, 'masteryValue', 'float')) !== null) { $object->setMasteryValue($masteryValue); } // deal with lookupTable. $interpolationTables = $element->getElementsByTagName('interpolationTable'); $matchTable = $element->getElementsByTagName('matchTable'); if ($interpolationTables->length == 1 || $matchTable->length == 1) { // we have a lookupTable defined. $lookupTable = null; if ($interpolationTables->length == 1) { $lookupTable = $interpolationTables->item(0); } else { $lookupTable = $matchTable->item(0); } $lookupTableMarshaller = $this->getMarshallerFactory()->createMarshaller($lookupTable, array($object->getBaseType())); $object->setLookupTable($lookupTableMarshaller->unmarshall($lookupTable)); } return $object; } catch (InvalidArgumentException $e) { $msg = "An unexpected error occured while unmarshalling the outcomeDeclaration."; throw new UnmarshallingException($msg, $element, $e); } }
[ "protected", "function", "unmarshall", "(", "DOMElement", "$", "element", ")", "{", "try", "{", "$", "version", "=", "$", "this", "->", "getVersion", "(", ")", ";", "$", "baseComponent", "=", "parent", "::", "unmarshall", "(", "$", "element", ")", ";", "$", "object", "=", "new", "OutcomeDeclaration", "(", "$", "baseComponent", "->", "getIdentifier", "(", ")", ")", ";", "$", "object", "->", "setBaseType", "(", "$", "baseComponent", "->", "getBaseType", "(", ")", ")", ";", "$", "object", "->", "setCardinality", "(", "$", "baseComponent", "->", "getCardinality", "(", ")", ")", ";", "$", "object", "->", "setDefaultValue", "(", "$", "baseComponent", "->", "getDefaultValue", "(", ")", ")", ";", "// deal with views.", "if", "(", "Version", "::", "compare", "(", "$", "version", ",", "'2.1.0'", ",", "'>='", ")", "===", "true", "&&", "(", "$", "views", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'view'", ")", ")", "!=", "null", ")", "{", "$", "viewCollection", "=", "new", "ViewCollection", "(", ")", ";", "foreach", "(", "explode", "(", "\"\\x20\"", ",", "$", "views", ")", "as", "$", "viewName", ")", "{", "$", "viewCollection", "[", "]", "=", "View", "::", "getConstantByName", "(", "$", "viewName", ")", ";", "}", "$", "object", "->", "setViews", "(", "$", "viewCollection", ")", ";", "}", "// deal with interpretation.", "if", "(", "(", "$", "interpretation", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'interpretation'", ")", ")", "!=", "null", ")", "{", "$", "object", "->", "setInterpretation", "(", "$", "interpretation", ")", ";", "}", "// deal with longInterpretation.", "if", "(", "(", "$", "longInterpretation", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'longInterpretation'", ")", ")", "!=", "null", ")", "{", "$", "object", "->", "setLongInterpretation", "(", "$", "longInterpretation", ")", ";", "}", "// deal with normalMaximum.", "if", "(", "(", "$", "normalMaximum", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'normalMaximum'", ",", "'float'", ")", ")", "!==", "null", ")", "{", "$", "object", "->", "setNormalMaximum", "(", "$", "normalMaximum", ")", ";", "}", "// deal with normalMinimum.", "if", "(", "Version", "::", "compare", "(", "$", "version", ",", "'2.1.0'", ",", "'>='", ")", "===", "true", "&&", "(", "$", "normalMinimum", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'normalMinimum'", ",", "'float'", ")", ")", "!==", "null", ")", "{", "$", "object", "->", "setNormalMinimum", "(", "$", "normalMinimum", ")", ";", "}", "// deal with matseryValue.", "if", "(", "Version", "::", "compare", "(", "$", "version", ",", "'2.1.0'", ",", "'>='", ")", "===", "true", "&&", "(", "$", "masteryValue", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'masteryValue'", ",", "'float'", ")", ")", "!==", "null", ")", "{", "$", "object", "->", "setMasteryValue", "(", "$", "masteryValue", ")", ";", "}", "// deal with lookupTable.", "$", "interpolationTables", "=", "$", "element", "->", "getElementsByTagName", "(", "'interpolationTable'", ")", ";", "$", "matchTable", "=", "$", "element", "->", "getElementsByTagName", "(", "'matchTable'", ")", ";", "if", "(", "$", "interpolationTables", "->", "length", "==", "1", "||", "$", "matchTable", "->", "length", "==", "1", ")", "{", "// we have a lookupTable defined.", "$", "lookupTable", "=", "null", ";", "if", "(", "$", "interpolationTables", "->", "length", "==", "1", ")", "{", "$", "lookupTable", "=", "$", "interpolationTables", "->", "item", "(", "0", ")", ";", "}", "else", "{", "$", "lookupTable", "=", "$", "matchTable", "->", "item", "(", "0", ")", ";", "}", "$", "lookupTableMarshaller", "=", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "lookupTable", ",", "array", "(", "$", "object", "->", "getBaseType", "(", ")", ")", ")", ";", "$", "object", "->", "setLookupTable", "(", "$", "lookupTableMarshaller", "->", "unmarshall", "(", "$", "lookupTable", ")", ")", ";", "}", "return", "$", "object", ";", "}", "catch", "(", "InvalidArgumentException", "$", "e", ")", "{", "$", "msg", "=", "\"An unexpected error occured while unmarshalling the outcomeDeclaration.\"", ";", "throw", "new", "UnmarshallingException", "(", "$", "msg", ",", "$", "element", ",", "$", "e", ")", ";", "}", "}" ]
Unmarshall a DOMElement object corresponding to a QTI outcomeDeclaration element. @param \DOMElement $element A DOMElement object. @return \qtism\data\QtiComponent An OutcomeDeclaration object. @throws \qtism\data\storage\xml\marshalling\UnmarshallingException
[ "Unmarshall", "a", "DOMElement", "object", "corresponding", "to", "a", "QTI", "outcomeDeclaration", "element", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/OutcomeDeclarationMarshaller.php#L107-L176
oat-sa/qti-sdk
src/qtism/data/state/Utils.php
Utils.createShufflingFromInteraction
static public function createShufflingFromInteraction(Interaction $interaction) { $className = $interaction->getQtiClassName(); $groups = array(); $shufflableInteractions = array( 'choiceInteraction', 'orderInteraction', 'associateInteraction', 'matchInteraction', 'gapMatchInteraction', 'inlineChoiceInteraction' ); $returnValue = false; if (in_array($className, $shufflableInteractions) === true && $interaction->mustShuffle() === true) { if ($className === 'choiceInteraction' || $className === 'orderInteraction') { $choices = $interaction->getComponentsByClassName('simpleChoice'); $groups[] = array('identifiers' => array(), 'fixed' => array()); foreach ($choices as $choice) { $groups[0]['identifiers'][] = $choice->getIdentifier(); if ($choice->isFixed() === true) { $groups[0]['fixed'][] = $choice->getIdentifier(); } } } elseif ($className === 'associateInteraction') { $choices = $interaction->getComponentsByClassName('simpleAssociableChoice'); $groups[] = array('identifiers' => array(), 'fixed' => array()); foreach ($choices as $choice) { $groups[0]['identifiers'][] = $choice->getIdentifier(); if ($choice->isFixed() === true) { $groups[0]['fixed'][] = $choice->getIdentifier(); } } } elseif ($className === 'matchInteraction') { $matchSets = $interaction->getComponentsByClassName('simpleMatchSet'); $groups[] = array('identifiers' => array(), 'fixed' => array()); $groups[] = array('identifiers' => array(), 'fixed' => array()); for ($i = 0; $i < count($matchSets); $i++) { foreach ($matchSets[$i]->getComponentsByClassName('simpleAssociableChoice') as $choice) { $groups[$i]['identifiers'][] = $choice->getIdentifier(); if ($choice->isFixed() === true) { $groups[0]['fixed'][] = $choice->getIdentifier(); } } } } elseif ($className === 'gapMatchInteraction') { $choices = $interaction->getComponentsByClassName(array('gapText', 'gapImg')); $groups[] = array('identifiers' => array(), 'fixed' => array()); foreach ($choices as $choice) { $groups[0]['identifiers'][] = $choice->getIdentifier(); if ($choice->isFixed() === true) { $groups[0]['fixed'][] = $choice->getIdentifier(); } } } elseif ($className === 'inlineChoiceInteraction') { $choices = $interaction->getComponentsByClassName('inlineChoice'); $groups[] = array('identifiers' => array(), 'fixed' => array()); foreach ($choices as $choice) { $groups[0]['identifiers'][] = $choice->getIdentifier(); if ($choice->isFixed() === true) { $groups[0]['fixed'][] = $choice->getIdentifier(); } } } $responseIdentifier = $interaction->getResponseIdentifier(); $shufflingGroups = new ShufflingGroupCollection(); foreach ($groups as $group) { $shufflingGroup = new ShufflingGroup(new IdentifierCollection($group['identifiers'])); $shufflingGroup->setFixedIdentifiers(new IdentifierCollection($group['fixed'])); $shufflingGroups[] = $shufflingGroup; } $returnValue = new Shuffling($responseIdentifier, $shufflingGroups); } return $returnValue; }
php
static public function createShufflingFromInteraction(Interaction $interaction) { $className = $interaction->getQtiClassName(); $groups = array(); $shufflableInteractions = array( 'choiceInteraction', 'orderInteraction', 'associateInteraction', 'matchInteraction', 'gapMatchInteraction', 'inlineChoiceInteraction' ); $returnValue = false; if (in_array($className, $shufflableInteractions) === true && $interaction->mustShuffle() === true) { if ($className === 'choiceInteraction' || $className === 'orderInteraction') { $choices = $interaction->getComponentsByClassName('simpleChoice'); $groups[] = array('identifiers' => array(), 'fixed' => array()); foreach ($choices as $choice) { $groups[0]['identifiers'][] = $choice->getIdentifier(); if ($choice->isFixed() === true) { $groups[0]['fixed'][] = $choice->getIdentifier(); } } } elseif ($className === 'associateInteraction') { $choices = $interaction->getComponentsByClassName('simpleAssociableChoice'); $groups[] = array('identifiers' => array(), 'fixed' => array()); foreach ($choices as $choice) { $groups[0]['identifiers'][] = $choice->getIdentifier(); if ($choice->isFixed() === true) { $groups[0]['fixed'][] = $choice->getIdentifier(); } } } elseif ($className === 'matchInteraction') { $matchSets = $interaction->getComponentsByClassName('simpleMatchSet'); $groups[] = array('identifiers' => array(), 'fixed' => array()); $groups[] = array('identifiers' => array(), 'fixed' => array()); for ($i = 0; $i < count($matchSets); $i++) { foreach ($matchSets[$i]->getComponentsByClassName('simpleAssociableChoice') as $choice) { $groups[$i]['identifiers'][] = $choice->getIdentifier(); if ($choice->isFixed() === true) { $groups[0]['fixed'][] = $choice->getIdentifier(); } } } } elseif ($className === 'gapMatchInteraction') { $choices = $interaction->getComponentsByClassName(array('gapText', 'gapImg')); $groups[] = array('identifiers' => array(), 'fixed' => array()); foreach ($choices as $choice) { $groups[0]['identifiers'][] = $choice->getIdentifier(); if ($choice->isFixed() === true) { $groups[0]['fixed'][] = $choice->getIdentifier(); } } } elseif ($className === 'inlineChoiceInteraction') { $choices = $interaction->getComponentsByClassName('inlineChoice'); $groups[] = array('identifiers' => array(), 'fixed' => array()); foreach ($choices as $choice) { $groups[0]['identifiers'][] = $choice->getIdentifier(); if ($choice->isFixed() === true) { $groups[0]['fixed'][] = $choice->getIdentifier(); } } } $responseIdentifier = $interaction->getResponseIdentifier(); $shufflingGroups = new ShufflingGroupCollection(); foreach ($groups as $group) { $shufflingGroup = new ShufflingGroup(new IdentifierCollection($group['identifiers'])); $shufflingGroup->setFixedIdentifiers(new IdentifierCollection($group['fixed'])); $shufflingGroups[] = $shufflingGroup; } $returnValue = new Shuffling($responseIdentifier, $shufflingGroups); } return $returnValue; }
[ "static", "public", "function", "createShufflingFromInteraction", "(", "Interaction", "$", "interaction", ")", "{", "$", "className", "=", "$", "interaction", "->", "getQtiClassName", "(", ")", ";", "$", "groups", "=", "array", "(", ")", ";", "$", "shufflableInteractions", "=", "array", "(", "'choiceInteraction'", ",", "'orderInteraction'", ",", "'associateInteraction'", ",", "'matchInteraction'", ",", "'gapMatchInteraction'", ",", "'inlineChoiceInteraction'", ")", ";", "$", "returnValue", "=", "false", ";", "if", "(", "in_array", "(", "$", "className", ",", "$", "shufflableInteractions", ")", "===", "true", "&&", "$", "interaction", "->", "mustShuffle", "(", ")", "===", "true", ")", "{", "if", "(", "$", "className", "===", "'choiceInteraction'", "||", "$", "className", "===", "'orderInteraction'", ")", "{", "$", "choices", "=", "$", "interaction", "->", "getComponentsByClassName", "(", "'simpleChoice'", ")", ";", "$", "groups", "[", "]", "=", "array", "(", "'identifiers'", "=>", "array", "(", ")", ",", "'fixed'", "=>", "array", "(", ")", ")", ";", "foreach", "(", "$", "choices", "as", "$", "choice", ")", "{", "$", "groups", "[", "0", "]", "[", "'identifiers'", "]", "[", "]", "=", "$", "choice", "->", "getIdentifier", "(", ")", ";", "if", "(", "$", "choice", "->", "isFixed", "(", ")", "===", "true", ")", "{", "$", "groups", "[", "0", "]", "[", "'fixed'", "]", "[", "]", "=", "$", "choice", "->", "getIdentifier", "(", ")", ";", "}", "}", "}", "elseif", "(", "$", "className", "===", "'associateInteraction'", ")", "{", "$", "choices", "=", "$", "interaction", "->", "getComponentsByClassName", "(", "'simpleAssociableChoice'", ")", ";", "$", "groups", "[", "]", "=", "array", "(", "'identifiers'", "=>", "array", "(", ")", ",", "'fixed'", "=>", "array", "(", ")", ")", ";", "foreach", "(", "$", "choices", "as", "$", "choice", ")", "{", "$", "groups", "[", "0", "]", "[", "'identifiers'", "]", "[", "]", "=", "$", "choice", "->", "getIdentifier", "(", ")", ";", "if", "(", "$", "choice", "->", "isFixed", "(", ")", "===", "true", ")", "{", "$", "groups", "[", "0", "]", "[", "'fixed'", "]", "[", "]", "=", "$", "choice", "->", "getIdentifier", "(", ")", ";", "}", "}", "}", "elseif", "(", "$", "className", "===", "'matchInteraction'", ")", "{", "$", "matchSets", "=", "$", "interaction", "->", "getComponentsByClassName", "(", "'simpleMatchSet'", ")", ";", "$", "groups", "[", "]", "=", "array", "(", "'identifiers'", "=>", "array", "(", ")", ",", "'fixed'", "=>", "array", "(", ")", ")", ";", "$", "groups", "[", "]", "=", "array", "(", "'identifiers'", "=>", "array", "(", ")", ",", "'fixed'", "=>", "array", "(", ")", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "count", "(", "$", "matchSets", ")", ";", "$", "i", "++", ")", "{", "foreach", "(", "$", "matchSets", "[", "$", "i", "]", "->", "getComponentsByClassName", "(", "'simpleAssociableChoice'", ")", "as", "$", "choice", ")", "{", "$", "groups", "[", "$", "i", "]", "[", "'identifiers'", "]", "[", "]", "=", "$", "choice", "->", "getIdentifier", "(", ")", ";", "if", "(", "$", "choice", "->", "isFixed", "(", ")", "===", "true", ")", "{", "$", "groups", "[", "0", "]", "[", "'fixed'", "]", "[", "]", "=", "$", "choice", "->", "getIdentifier", "(", ")", ";", "}", "}", "}", "}", "elseif", "(", "$", "className", "===", "'gapMatchInteraction'", ")", "{", "$", "choices", "=", "$", "interaction", "->", "getComponentsByClassName", "(", "array", "(", "'gapText'", ",", "'gapImg'", ")", ")", ";", "$", "groups", "[", "]", "=", "array", "(", "'identifiers'", "=>", "array", "(", ")", ",", "'fixed'", "=>", "array", "(", ")", ")", ";", "foreach", "(", "$", "choices", "as", "$", "choice", ")", "{", "$", "groups", "[", "0", "]", "[", "'identifiers'", "]", "[", "]", "=", "$", "choice", "->", "getIdentifier", "(", ")", ";", "if", "(", "$", "choice", "->", "isFixed", "(", ")", "===", "true", ")", "{", "$", "groups", "[", "0", "]", "[", "'fixed'", "]", "[", "]", "=", "$", "choice", "->", "getIdentifier", "(", ")", ";", "}", "}", "}", "elseif", "(", "$", "className", "===", "'inlineChoiceInteraction'", ")", "{", "$", "choices", "=", "$", "interaction", "->", "getComponentsByClassName", "(", "'inlineChoice'", ")", ";", "$", "groups", "[", "]", "=", "array", "(", "'identifiers'", "=>", "array", "(", ")", ",", "'fixed'", "=>", "array", "(", ")", ")", ";", "foreach", "(", "$", "choices", "as", "$", "choice", ")", "{", "$", "groups", "[", "0", "]", "[", "'identifiers'", "]", "[", "]", "=", "$", "choice", "->", "getIdentifier", "(", ")", ";", "if", "(", "$", "choice", "->", "isFixed", "(", ")", "===", "true", ")", "{", "$", "groups", "[", "0", "]", "[", "'fixed'", "]", "[", "]", "=", "$", "choice", "->", "getIdentifier", "(", ")", ";", "}", "}", "}", "$", "responseIdentifier", "=", "$", "interaction", "->", "getResponseIdentifier", "(", ")", ";", "$", "shufflingGroups", "=", "new", "ShufflingGroupCollection", "(", ")", ";", "foreach", "(", "$", "groups", "as", "$", "group", ")", "{", "$", "shufflingGroup", "=", "new", "ShufflingGroup", "(", "new", "IdentifierCollection", "(", "$", "group", "[", "'identifiers'", "]", ")", ")", ";", "$", "shufflingGroup", "->", "setFixedIdentifiers", "(", "new", "IdentifierCollection", "(", "$", "group", "[", "'fixed'", "]", ")", ")", ";", "$", "shufflingGroups", "[", "]", "=", "$", "shufflingGroup", ";", "}", "$", "returnValue", "=", "new", "Shuffling", "(", "$", "responseIdentifier", ",", "$", "shufflingGroups", ")", ";", "}", "return", "$", "returnValue", ";", "}" ]
Create a Shuffling component from a given Interaction object. A Shuffling object will be created depending on the $interaction object given. If $interaction is an interaction type subject to shuffling e.g. choiceInteraction, orderInteraction, associateInteraction, matchInteraction, gapMatchInteraction, inlineChoiceInteraction, a Shuffling object is returned. Otherwise, the method returns false to indicate that no Shuffling component can be built from the given $interaction object. @param \qtism\data\content\interactions\Interaction $interaction @return \qtism\data\state\Shuffling|boolean
[ "Create", "a", "Shuffling", "component", "from", "a", "given", "Interaction", "object", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/state/Utils.php#L50-L129
oat-sa/qti-sdk
src/qtism/data/storage/xml/marshalling/AnyNMarshaller.php
AnyNMarshaller.unmarshallChildrenKnown
protected function unmarshallChildrenKnown(DOMElement $element, QtiComponentCollection $children) { if (($min = $this->getDOMElementAttributeAs($element, 'min')) !== null) { if (Format::isInteger($min)) { $min = intval($min); } if (($max = $this->getDOMElementAttributeAs($element, 'max')) !== null) { if (Format::isInteger($max)) { $max = intval($max); } $object = new AnyN($children, $min, $max); return $object; } else { $msg = "The mandatory attribute 'max' is missing from element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element); } } else { $msg = "The mandatory attribute 'min' is missing from element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element); } }
php
protected function unmarshallChildrenKnown(DOMElement $element, QtiComponentCollection $children) { if (($min = $this->getDOMElementAttributeAs($element, 'min')) !== null) { if (Format::isInteger($min)) { $min = intval($min); } if (($max = $this->getDOMElementAttributeAs($element, 'max')) !== null) { if (Format::isInteger($max)) { $max = intval($max); } $object = new AnyN($children, $min, $max); return $object; } else { $msg = "The mandatory attribute 'max' is missing from element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element); } } else { $msg = "The mandatory attribute 'min' is missing from element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element); } }
[ "protected", "function", "unmarshallChildrenKnown", "(", "DOMElement", "$", "element", ",", "QtiComponentCollection", "$", "children", ")", "{", "if", "(", "(", "$", "min", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'min'", ")", ")", "!==", "null", ")", "{", "if", "(", "Format", "::", "isInteger", "(", "$", "min", ")", ")", "{", "$", "min", "=", "intval", "(", "$", "min", ")", ";", "}", "if", "(", "(", "$", "max", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'max'", ")", ")", "!==", "null", ")", "{", "if", "(", "Format", "::", "isInteger", "(", "$", "max", ")", ")", "{", "$", "max", "=", "intval", "(", "$", "max", ")", ";", "}", "$", "object", "=", "new", "AnyN", "(", "$", "children", ",", "$", "min", ",", "$", "max", ")", ";", "return", "$", "object", ";", "}", "else", "{", "$", "msg", "=", "\"The mandatory attribute 'max' is missing from element '\"", ".", "$", "element", "->", "localName", ".", "\"'.\"", ";", "throw", "new", "UnmarshallingException", "(", "$", "msg", ",", "$", "element", ")", ";", "}", "}", "else", "{", "$", "msg", "=", "\"The mandatory attribute 'min' is missing from element '\"", ".", "$", "element", "->", "localName", ".", "\"'.\"", ";", "throw", "new", "UnmarshallingException", "(", "$", "msg", ",", "$", "element", ")", ";", "}", "}" ]
Unmarshall a QTI anyN operator element into an AnyN object. @param \DOMElement $element The anyN element to unmarshall. @param \qtism\data\QtiComponentCollection $children A collection containing the child Expression objects composing the Operator. @return \qtism\data\QtiComponent An AnyN object. @throws \qtism\data\storage\xml\marshalling\UnmarshallingException
[ "Unmarshall", "a", "QTI", "anyN", "operator", "element", "into", "an", "AnyN", "object", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/AnyNMarshaller.php#L68-L93
oat-sa/qti-sdk
src/qtism/data/expressions/operators/StatsOperator.php
StatsOperator.setName
public function setName($name) { if (in_array($name, Statistics::asArray())) { $this->name = $name; } else { $msg = "The name argument must be a value from the Statistics enumeration, '" . $name . "' given."; throw new InvalidArgumentException($msg); } }
php
public function setName($name) { if (in_array($name, Statistics::asArray())) { $this->name = $name; } else { $msg = "The name argument must be a value from the Statistics enumeration, '" . $name . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setName", "(", "$", "name", ")", "{", "if", "(", "in_array", "(", "$", "name", ",", "Statistics", "::", "asArray", "(", ")", ")", ")", "{", "$", "this", "->", "name", "=", "$", "name", ";", "}", "else", "{", "$", "msg", "=", "\"The name argument must be a value from the Statistics enumeration, '\"", ".", "$", "name", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set the statistics operator to use. @param integer $name A value from the Statistics enumeration. @throws \InvalidArgumentException If $name is not a value from the Statistics enumeration.
[ "Set", "the", "statistics", "operator", "to", "use", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/expressions/operators/StatsOperator.php#L71-L79
oat-sa/qti-sdk
src/qtism/data/state/Shuffling.php
Shuffling.setShufflingGroups
public function setShufflingGroups(ShufflingGroupCollection $shufflingGroups) { if (count($shufflingGroups) === 0) { $msg = "A Shuffling object must be composed of at least 1 ShufflingGroup object. None given"; throw new InvalidArgumentException($msg); } elseif (($c = count($shufflingGroups)) > 2) { $msg = "A Shuffling object must be composed of at most 2 ShufflingGroup objects. ${c} given."; throw new InvalidArgumentException($msg); } else { $this->shufflingGroups = $shufflingGroups; } }
php
public function setShufflingGroups(ShufflingGroupCollection $shufflingGroups) { if (count($shufflingGroups) === 0) { $msg = "A Shuffling object must be composed of at least 1 ShufflingGroup object. None given"; throw new InvalidArgumentException($msg); } elseif (($c = count($shufflingGroups)) > 2) { $msg = "A Shuffling object must be composed of at most 2 ShufflingGroup objects. ${c} given."; throw new InvalidArgumentException($msg); } else { $this->shufflingGroups = $shufflingGroups; } }
[ "public", "function", "setShufflingGroups", "(", "ShufflingGroupCollection", "$", "shufflingGroups", ")", "{", "if", "(", "count", "(", "$", "shufflingGroups", ")", "===", "0", ")", "{", "$", "msg", "=", "\"A Shuffling object must be composed of at least 1 ShufflingGroup object. None given\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "elseif", "(", "(", "$", "c", "=", "count", "(", "$", "shufflingGroups", ")", ")", ">", "2", ")", "{", "$", "msg", "=", "\"A Shuffling object must be composed of at most 2 ShufflingGroup objects. ${c} given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "else", "{", "$", "this", "->", "shufflingGroups", "=", "$", "shufflingGroups", ";", "}", "}" ]
Set the ShufflingGroups. @param \qtism\data\state\ShufflingGroupCollection $shufflingGroups @throws \InvalidArgumentException If $shufflingGroups does not contain 1 to 2 ShufflingGroup objects.
[ "Set", "the", "ShufflingGroups", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/state/Shuffling.php#L99-L110
oat-sa/qti-sdk
src/qtism/data/state/Shuffling.php
Shuffling.shuffle
public function shuffle() { $shuffling = clone $this; $groups = $shuffling->getShufflingGroups(); for ($i = 0; $i < count($groups); $i++) { $identifiers = $groups[$i]->getIdentifiers(); $fixedIdentifiers = $groups[$i]->getFixedIdentifiers()->getArrayCopy(); $shufflableIndexes = array(); // Find shuffblable indexes. for ($n = 0; $n < count($identifiers); $n++) { if (in_array($identifiers[$n], $fixedIdentifiers) === false) { $shufflableIndexes[] = $n; } } // Shuffle the new group. $n = count($shufflableIndexes) - 1; for ($j = $n; $j > 0; $j--) { $k = mt_rand(0, $n); $tmp1 = $identifiers[$shufflableIndexes[$j]]; $tmp2 = $identifiers[$shufflableIndexes[$k]]; $identifiers[$shufflableIndexes[$j]] = $tmp2; $identifiers[$shufflableIndexes[$k]] = $tmp1; } } return $shuffling; }
php
public function shuffle() { $shuffling = clone $this; $groups = $shuffling->getShufflingGroups(); for ($i = 0; $i < count($groups); $i++) { $identifiers = $groups[$i]->getIdentifiers(); $fixedIdentifiers = $groups[$i]->getFixedIdentifiers()->getArrayCopy(); $shufflableIndexes = array(); // Find shuffblable indexes. for ($n = 0; $n < count($identifiers); $n++) { if (in_array($identifiers[$n], $fixedIdentifiers) === false) { $shufflableIndexes[] = $n; } } // Shuffle the new group. $n = count($shufflableIndexes) - 1; for ($j = $n; $j > 0; $j--) { $k = mt_rand(0, $n); $tmp1 = $identifiers[$shufflableIndexes[$j]]; $tmp2 = $identifiers[$shufflableIndexes[$k]]; $identifiers[$shufflableIndexes[$j]] = $tmp2; $identifiers[$shufflableIndexes[$k]] = $tmp1; } } return $shuffling; }
[ "public", "function", "shuffle", "(", ")", "{", "$", "shuffling", "=", "clone", "$", "this", ";", "$", "groups", "=", "$", "shuffling", "->", "getShufflingGroups", "(", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "count", "(", "$", "groups", ")", ";", "$", "i", "++", ")", "{", "$", "identifiers", "=", "$", "groups", "[", "$", "i", "]", "->", "getIdentifiers", "(", ")", ";", "$", "fixedIdentifiers", "=", "$", "groups", "[", "$", "i", "]", "->", "getFixedIdentifiers", "(", ")", "->", "getArrayCopy", "(", ")", ";", "$", "shufflableIndexes", "=", "array", "(", ")", ";", "// Find shuffblable indexes.", "for", "(", "$", "n", "=", "0", ";", "$", "n", "<", "count", "(", "$", "identifiers", ")", ";", "$", "n", "++", ")", "{", "if", "(", "in_array", "(", "$", "identifiers", "[", "$", "n", "]", ",", "$", "fixedIdentifiers", ")", "===", "false", ")", "{", "$", "shufflableIndexes", "[", "]", "=", "$", "n", ";", "}", "}", "// Shuffle the new group.", "$", "n", "=", "count", "(", "$", "shufflableIndexes", ")", "-", "1", ";", "for", "(", "$", "j", "=", "$", "n", ";", "$", "j", ">", "0", ";", "$", "j", "--", ")", "{", "$", "k", "=", "mt_rand", "(", "0", ",", "$", "n", ")", ";", "$", "tmp1", "=", "$", "identifiers", "[", "$", "shufflableIndexes", "[", "$", "j", "]", "]", ";", "$", "tmp2", "=", "$", "identifiers", "[", "$", "shufflableIndexes", "[", "$", "k", "]", "]", ";", "$", "identifiers", "[", "$", "shufflableIndexes", "[", "$", "j", "]", "]", "=", "$", "tmp2", ";", "$", "identifiers", "[", "$", "shufflableIndexes", "[", "$", "k", "]", "]", "=", "$", "tmp1", ";", "}", "}", "return", "$", "shuffling", ";", "}" ]
Shuffles the identifiers of the ShufflingGroups. Calling this method will create a new deep copy of this Shuffling object, with identifiers of the Shuffling Groups shuffled again. @return \qtism\data\state\Shuffling
[ "Shuffles", "the", "identifiers", "of", "the", "ShufflingGroups", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/state/Shuffling.php#L130-L161
oat-sa/qti-sdk
src/qtism/data/state/Shuffling.php
Shuffling.getIdentifierAt
public function getIdentifierAt($index) { $i = 0; foreach ($this->getShufflingGroups() as $shufflingGroup) { foreach ($shufflingGroup->getIdentifiers() as $identifier) { if ($i === $index) { return $identifier; } $i++; } } throw new OutOfBoundsException("No identifier at index ${index}."); }
php
public function getIdentifierAt($index) { $i = 0; foreach ($this->getShufflingGroups() as $shufflingGroup) { foreach ($shufflingGroup->getIdentifiers() as $identifier) { if ($i === $index) { return $identifier; } $i++; } } throw new OutOfBoundsException("No identifier at index ${index}."); }
[ "public", "function", "getIdentifierAt", "(", "$", "index", ")", "{", "$", "i", "=", "0", ";", "foreach", "(", "$", "this", "->", "getShufflingGroups", "(", ")", "as", "$", "shufflingGroup", ")", "{", "foreach", "(", "$", "shufflingGroup", "->", "getIdentifiers", "(", ")", "as", "$", "identifier", ")", "{", "if", "(", "$", "i", "===", "$", "index", ")", "{", "return", "$", "identifier", ";", "}", "$", "i", "++", ";", "}", "}", "throw", "new", "OutOfBoundsException", "(", "\"No identifier at index ${index}.\"", ")", ";", "}" ]
Retrieve an identifier by $index. You can reach identifiers in all the ShufflingGroup objects composing the Shuffling object. For instance, if the Shuffling object is composed of 2 ShufflingGroup objects containing respectively ['id1', 'id2', 'id3'] and ['id4', 'id5', 'id6'], then 'id2' is at index 1 and 'id5' is at index 4. @param integer $index @throws OutOfBoundsException @return string
[ "Retrieve", "an", "identifier", "by", "$index", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/state/Shuffling.php#L175-L188
oat-sa/qti-sdk
src/qtism/data/storage/xml/marshalling/ResponseProcessingMarshaller.php
ResponseProcessingMarshaller.marshall
protected function marshall(QtiComponent $component) { $element = self::getDOMCradle()->createElement($component->getQtiClassName()); if ($component->hasTemplate() === true) { $this->setDOMElementAttribute($element, 'template', $component->getTemplate()); } if ($component->hasTemplateLocation() === true) { $this->setDOMElementAttribute($element, 'templateLocation', $component->getTemplateLocation()); } foreach ($component->getResponseRules() as $responseRule) { $marshaller = $this->getMarshallerFactory()->createMarshaller($responseRule); $element->appendChild($marshaller->marshall($responseRule)); } return $element; }
php
protected function marshall(QtiComponent $component) { $element = self::getDOMCradle()->createElement($component->getQtiClassName()); if ($component->hasTemplate() === true) { $this->setDOMElementAttribute($element, 'template', $component->getTemplate()); } if ($component->hasTemplateLocation() === true) { $this->setDOMElementAttribute($element, 'templateLocation', $component->getTemplateLocation()); } foreach ($component->getResponseRules() as $responseRule) { $marshaller = $this->getMarshallerFactory()->createMarshaller($responseRule); $element->appendChild($marshaller->marshall($responseRule)); } return $element; }
[ "protected", "function", "marshall", "(", "QtiComponent", "$", "component", ")", "{", "$", "element", "=", "self", "::", "getDOMCradle", "(", ")", "->", "createElement", "(", "$", "component", "->", "getQtiClassName", "(", ")", ")", ";", "if", "(", "$", "component", "->", "hasTemplate", "(", ")", "===", "true", ")", "{", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'template'", ",", "$", "component", "->", "getTemplate", "(", ")", ")", ";", "}", "if", "(", "$", "component", "->", "hasTemplateLocation", "(", ")", "===", "true", ")", "{", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'templateLocation'", ",", "$", "component", "->", "getTemplateLocation", "(", ")", ")", ";", "}", "foreach", "(", "$", "component", "->", "getResponseRules", "(", ")", "as", "$", "responseRule", ")", "{", "$", "marshaller", "=", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "responseRule", ")", ";", "$", "element", "->", "appendChild", "(", "$", "marshaller", "->", "marshall", "(", "$", "responseRule", ")", ")", ";", "}", "return", "$", "element", ";", "}" ]
Marshall a ResponseProcessing object into a DOMElement object. @param \qtism\data\QtiComponent $component A ResponseProcessing object. @return \DOMElement The according DOMElement object. @throws \qtism\data\storage\xml\marshalling\MarshallingException
[ "Marshall", "a", "ResponseProcessing", "object", "into", "a", "DOMElement", "object", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/ResponseProcessingMarshaller.php#L45-L63
oat-sa/qti-sdk
src/qtism/data/storage/xml/marshalling/ResponseProcessingMarshaller.php
ResponseProcessingMarshaller.unmarshall
protected function unmarshall(DOMElement $element, ResponseProcessing $responseProcessing = null) { $responseRuleElts = self::getChildElements($element); $responseRules = new ResponseRuleCollection(); for ($i = 0; $i < count($responseRuleElts); $i++) { $marshaller = $this->getMarshallerFactory()->createMarshaller($responseRuleElts[$i]); $responseRules[] = $marshaller->unmarshall($responseRuleElts[$i]); } if (is_null($responseProcessing) === true) { $object = new ResponseProcessing($responseRules); } else { $object = $responseProcessing; $object->setResponseRules($responseRules); } if (($template = $this->getDOMElementAttributeAs($element, 'template')) !== null) { $object->setTemplate($template); } if (($templateLocation = $this->getDOMElementAttributeAs($element, 'templateLocation')) !== null) { $object->setTemplateLocation($templateLocation); } return $object; }
php
protected function unmarshall(DOMElement $element, ResponseProcessing $responseProcessing = null) { $responseRuleElts = self::getChildElements($element); $responseRules = new ResponseRuleCollection(); for ($i = 0; $i < count($responseRuleElts); $i++) { $marshaller = $this->getMarshallerFactory()->createMarshaller($responseRuleElts[$i]); $responseRules[] = $marshaller->unmarshall($responseRuleElts[$i]); } if (is_null($responseProcessing) === true) { $object = new ResponseProcessing($responseRules); } else { $object = $responseProcessing; $object->setResponseRules($responseRules); } if (($template = $this->getDOMElementAttributeAs($element, 'template')) !== null) { $object->setTemplate($template); } if (($templateLocation = $this->getDOMElementAttributeAs($element, 'templateLocation')) !== null) { $object->setTemplateLocation($templateLocation); } return $object; }
[ "protected", "function", "unmarshall", "(", "DOMElement", "$", "element", ",", "ResponseProcessing", "$", "responseProcessing", "=", "null", ")", "{", "$", "responseRuleElts", "=", "self", "::", "getChildElements", "(", "$", "element", ")", ";", "$", "responseRules", "=", "new", "ResponseRuleCollection", "(", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "count", "(", "$", "responseRuleElts", ")", ";", "$", "i", "++", ")", "{", "$", "marshaller", "=", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "responseRuleElts", "[", "$", "i", "]", ")", ";", "$", "responseRules", "[", "]", "=", "$", "marshaller", "->", "unmarshall", "(", "$", "responseRuleElts", "[", "$", "i", "]", ")", ";", "}", "if", "(", "is_null", "(", "$", "responseProcessing", ")", "===", "true", ")", "{", "$", "object", "=", "new", "ResponseProcessing", "(", "$", "responseRules", ")", ";", "}", "else", "{", "$", "object", "=", "$", "responseProcessing", ";", "$", "object", "->", "setResponseRules", "(", "$", "responseRules", ")", ";", "}", "if", "(", "(", "$", "template", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'template'", ")", ")", "!==", "null", ")", "{", "$", "object", "->", "setTemplate", "(", "$", "template", ")", ";", "}", "if", "(", "(", "$", "templateLocation", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'templateLocation'", ")", ")", "!==", "null", ")", "{", "$", "object", "->", "setTemplateLocation", "(", "$", "templateLocation", ")", ";", "}", "return", "$", "object", ";", "}" ]
Unmarshall a DOMElement object corresponding to a QTI responseProcessing element. @param \DOMElement $element A DOMElement object. @return \qtism\data\QtiComponent A ResponseProcessing object. @throws \qtism\data\storage\xml\marshalling\UnmarshallingException
[ "Unmarshall", "a", "DOMElement", "object", "corresponding", "to", "a", "QTI", "responseProcessing", "element", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/ResponseProcessingMarshaller.php#L72-L98
oat-sa/qti-sdk
src/qtism/data/content/TemplateInline.php
TemplateInline.setXmlBase
public function setXmlBase($xmlBase = '') { if (is_string($xmlBase) && (empty($xmlBase) || Format::isUri($xmlBase))) { $this->xmlBase = $xmlBase; } else { $msg = "The 'base' argument must be an empty string or a valid URI, '" . $xmlBase . "' given"; throw new InvalidArgumentException($msg); } }
php
public function setXmlBase($xmlBase = '') { if (is_string($xmlBase) && (empty($xmlBase) || Format::isUri($xmlBase))) { $this->xmlBase = $xmlBase; } else { $msg = "The 'base' argument must be an empty string or a valid URI, '" . $xmlBase . "' given"; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setXmlBase", "(", "$", "xmlBase", "=", "''", ")", "{", "if", "(", "is_string", "(", "$", "xmlBase", ")", "&&", "(", "empty", "(", "$", "xmlBase", ")", "||", "Format", "::", "isUri", "(", "$", "xmlBase", ")", ")", ")", "{", "$", "this", "->", "xmlBase", "=", "$", "xmlBase", ";", "}", "else", "{", "$", "msg", "=", "\"The 'base' argument must be an empty string or a valid URI, '\"", ".", "$", "xmlBase", ".", "\"' given\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set the base URI of the TemplateBlock. @param string $xmlBase A URI. @throws \InvalidArgumentException if $base is not a valid URI nor an empty string.
[ "Set", "the", "base", "URI", "of", "the", "TemplateBlock", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/TemplateInline.php#L96-L104
oat-sa/qti-sdk
src/qtism/runtime/common/Utils.php
Utils.isBaseTypeCompliant
static public function isBaseTypeCompliant($baseType, $value) { if ($value === null) { return true; // A value can always be null. } elseif ($value instanceof QtiDatatype && $baseType === $value->getBaseType()) { return true; } else { return false; } }
php
static public function isBaseTypeCompliant($baseType, $value) { if ($value === null) { return true; // A value can always be null. } elseif ($value instanceof QtiDatatype && $baseType === $value->getBaseType()) { return true; } else { return false; } }
[ "static", "public", "function", "isBaseTypeCompliant", "(", "$", "baseType", ",", "$", "value", ")", "{", "if", "(", "$", "value", "===", "null", ")", "{", "return", "true", ";", "// A value can always be null.", "}", "elseif", "(", "$", "value", "instanceof", "QtiDatatype", "&&", "$", "baseType", "===", "$", "value", "->", "getBaseType", "(", ")", ")", "{", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Whether a given $value is compliant with a given $baseType. @param int $baseType A value from the BaseType enumeration. @param mixed $value A value. @return boolean
[ "Whether", "a", "given", "$value", "is", "compliant", "with", "a", "given", "$baseType", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/common/Utils.php#L78-L87
oat-sa/qti-sdk
src/qtism/runtime/common/Utils.php
Utils.isCardinalityCompliant
static public function isCardinalityCompliant($cardinality, $value) { if ($value === null) { return true; } elseif ($value instanceof QtiDatatype && $cardinality === $value->getCardinality()) { return true; } else { return false; } }
php
static public function isCardinalityCompliant($cardinality, $value) { if ($value === null) { return true; } elseif ($value instanceof QtiDatatype && $cardinality === $value->getCardinality()) { return true; } else { return false; } }
[ "static", "public", "function", "isCardinalityCompliant", "(", "$", "cardinality", ",", "$", "value", ")", "{", "if", "(", "$", "value", "===", "null", ")", "{", "return", "true", ";", "}", "elseif", "(", "$", "value", "instanceof", "QtiDatatype", "&&", "$", "cardinality", "===", "$", "value", "->", "getCardinality", "(", ")", ")", "{", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Whether a given $cardinality is compliant with a given $value. @param integer $cardinality @param mixed $value @return boolean
[ "Whether", "a", "given", "$cardinality", "is", "compliant", "with", "a", "given", "$value", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/common/Utils.php#L96-L105
oat-sa/qti-sdk
src/qtism/runtime/common/Utils.php
Utils.throwTypingError
static public function throwTypingError($value) { $givenValue = (gettype($value) == 'object') ? get_class($value) : gettype($value); $acceptedTypes = array('boolean', 'integer', 'float', 'double', 'string', 'Duration', 'Pair', 'DirectedPair', 'Point'); $acceptedTypes = implode(", ", $acceptedTypes); $msg = "A value is not compliant with the QTI runtime model datatypes: ${acceptedTypes} . '${givenValue}' given."; throw new InvalidArgumentException($msg); }
php
static public function throwTypingError($value) { $givenValue = (gettype($value) == 'object') ? get_class($value) : gettype($value); $acceptedTypes = array('boolean', 'integer', 'float', 'double', 'string', 'Duration', 'Pair', 'DirectedPair', 'Point'); $acceptedTypes = implode(", ", $acceptedTypes); $msg = "A value is not compliant with the QTI runtime model datatypes: ${acceptedTypes} . '${givenValue}' given."; throw new InvalidArgumentException($msg); }
[ "static", "public", "function", "throwTypingError", "(", "$", "value", ")", "{", "$", "givenValue", "=", "(", "gettype", "(", "$", "value", ")", "==", "'object'", ")", "?", "get_class", "(", "$", "value", ")", ":", "gettype", "(", "$", "value", ")", ";", "$", "acceptedTypes", "=", "array", "(", "'boolean'", ",", "'integer'", ",", "'float'", ",", "'double'", ",", "'string'", ",", "'Duration'", ",", "'Pair'", ",", "'DirectedPair'", ",", "'Point'", ")", ";", "$", "acceptedTypes", "=", "implode", "(", "\", \"", ",", "$", "acceptedTypes", ")", ";", "$", "msg", "=", "\"A value is not compliant with the QTI runtime model datatypes: ${acceptedTypes} . '${givenValue}' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}" ]
Throw an InvalidArgumentException depending on a PHP in-memory value. @param mixed $value A given PHP primitive value. @throws \InvalidArgumentException In any case.
[ "Throw", "an", "InvalidArgumentException", "depending", "on", "a", "PHP", "in", "-", "memory", "value", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/common/Utils.php#L113-L120
oat-sa/qti-sdk
src/qtism/runtime/common/Utils.php
Utils.throwBaseTypeTypingError
static public function throwBaseTypeTypingError($baseType, $value) { $givenValue = (gettype($value) == 'object') ? get_class($value) : gettype($value) . ':' . $value; $acceptedTypes = BaseType::getNameByConstant($baseType); $msg = "The value '${givenValue}' is not compliant with the '${acceptedTypes}' baseType."; throw new InvalidArgumentException($msg); }
php
static public function throwBaseTypeTypingError($baseType, $value) { $givenValue = (gettype($value) == 'object') ? get_class($value) : gettype($value) . ':' . $value; $acceptedTypes = BaseType::getNameByConstant($baseType); $msg = "The value '${givenValue}' is not compliant with the '${acceptedTypes}' baseType."; throw new InvalidArgumentException($msg); }
[ "static", "public", "function", "throwBaseTypeTypingError", "(", "$", "baseType", ",", "$", "value", ")", "{", "$", "givenValue", "=", "(", "gettype", "(", "$", "value", ")", "==", "'object'", ")", "?", "get_class", "(", "$", "value", ")", ":", "gettype", "(", "$", "value", ")", ".", "':'", ".", "$", "value", ";", "$", "acceptedTypes", "=", "BaseType", "::", "getNameByConstant", "(", "$", "baseType", ")", ";", "$", "msg", "=", "\"The value '${givenValue}' is not compliant with the '${acceptedTypes}' baseType.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}" ]
Throw an InvalidArgumentException depending on a given qti:baseType and an in-memory PHP value. @param int $baseType A value from the BaseType enumeration. @param mixed $value A given PHP primitive value. @throws \InvalidArgumentException In any case.
[ "Throw", "an", "InvalidArgumentException", "depending", "on", "a", "given", "qti", ":", "baseType", "and", "an", "in", "-", "memory", "PHP", "value", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/common/Utils.php#L130-L136
oat-sa/qti-sdk
src/qtism/runtime/common/Utils.php
Utils.inferBaseType
static public function inferBaseType($value) { if ($value === null) { return false; } elseif ($value instanceof RecordContainer) { return false; } elseif ($value instanceof QtiDatatype) { return $value->getBaseType(); } else { return false; } }
php
static public function inferBaseType($value) { if ($value === null) { return false; } elseif ($value instanceof RecordContainer) { return false; } elseif ($value instanceof QtiDatatype) { return $value->getBaseType(); } else { return false; } }
[ "static", "public", "function", "inferBaseType", "(", "$", "value", ")", "{", "if", "(", "$", "value", "===", "null", ")", "{", "return", "false", ";", "}", "elseif", "(", "$", "value", "instanceof", "RecordContainer", ")", "{", "return", "false", ";", "}", "elseif", "(", "$", "value", "instanceof", "QtiDatatype", ")", "{", "return", "$", "value", "->", "getBaseType", "(", ")", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Infer the QTI baseType of a given $value. @param mixed $value A value you want to know the QTI baseType. @return integer|false A value from the BaseType enumeration or false if the baseType could not be infered.
[ "Infer", "the", "QTI", "baseType", "of", "a", "given", "$value", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/common/Utils.php#L144-L155
oat-sa/qti-sdk
src/qtism/runtime/common/Utils.php
Utils.inferCardinality
static public function inferCardinality($value) { if ($value === null) { return false; } elseif ($value instanceof QtiDatatype) { return $value->getCardinality(); } else { return false; } }
php
static public function inferCardinality($value) { if ($value === null) { return false; } elseif ($value instanceof QtiDatatype) { return $value->getCardinality(); } else { return false; } }
[ "static", "public", "function", "inferCardinality", "(", "$", "value", ")", "{", "if", "(", "$", "value", "===", "null", ")", "{", "return", "false", ";", "}", "elseif", "(", "$", "value", "instanceof", "QtiDatatype", ")", "{", "return", "$", "value", "->", "getCardinality", "(", ")", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Infer the cardinality of a given $value. Please note that: * A RecordContainer has no cardinality, thus it always returns false for such a container. * The null value has no cardinality, this it always returns false for such a value. @param mixed $value A value you want to infer the cardinality. @return integer|boolean A value from the Cardinality enumeration or false if it could not be infered.
[ "Infer", "the", "cardinality", "of", "a", "given", "$value", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/common/Utils.php#L168-L177
oat-sa/qti-sdk
src/qtism/runtime/common/Utils.php
Utils.isValidVariableIdentifier
static public function isValidVariableIdentifier($string) { if (gettype($string) !== 'string' || empty($string)) { return false; } $pattern = '/^[a-z][a-z0-9_\-]*(?:(?:\.[1-9][0-9]*){0,1}(?:\.[a-z][a-z0-9_\-]*){0,1}){0,1}$/iu'; return preg_match($pattern, $string) === 1; }
php
static public function isValidVariableIdentifier($string) { if (gettype($string) !== 'string' || empty($string)) { return false; } $pattern = '/^[a-z][a-z0-9_\-]*(?:(?:\.[1-9][0-9]*){0,1}(?:\.[a-z][a-z0-9_\-]*){0,1}){0,1}$/iu'; return preg_match($pattern, $string) === 1; }
[ "static", "public", "function", "isValidVariableIdentifier", "(", "$", "string", ")", "{", "if", "(", "gettype", "(", "$", "string", ")", "!==", "'string'", "||", "empty", "(", "$", "string", ")", ")", "{", "return", "false", ";", "}", "$", "pattern", "=", "'/^[a-z][a-z0-9_\\-]*(?:(?:\\.[1-9][0-9]*){0,1}(?:\\.[a-z][a-z0-9_\\-]*){0,1}){0,1}$/iu'", ";", "return", "preg_match", "(", "$", "pattern", ",", "$", "string", ")", "===", "1", ";", "}" ]
Whether a given $string is a valid variable identifier. Q01 -> Valid Q_01 -> Valid 1_Q01 -> Invalid Q01.SCORE -> Valid Q-01.1.Score -> Valid Q*01.2.Score -> Invalid @param string $string A string value. @return boolean Whether the given $string is a valid variable identifier.
[ "Whether", "a", "given", "$string", "is", "a", "valid", "variable", "identifier", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/common/Utils.php#L192-L201
oat-sa/qti-sdk
src/qtism/runtime/common/Utils.php
Utils.floatArrayToInteger
static public function floatArrayToInteger($floatArray) { $integerArray = array(); foreach ($floatArray as $f) { $integerArray[] = (is_null($f) === false) ? intval($f) : null; } return $integerArray; }
php
static public function floatArrayToInteger($floatArray) { $integerArray = array(); foreach ($floatArray as $f) { $integerArray[] = (is_null($f) === false) ? intval($f) : null; } return $integerArray; }
[ "static", "public", "function", "floatArrayToInteger", "(", "$", "floatArray", ")", "{", "$", "integerArray", "=", "array", "(", ")", ";", "foreach", "(", "$", "floatArray", "as", "$", "f", ")", "{", "$", "integerArray", "[", "]", "=", "(", "is_null", "(", "$", "f", ")", "===", "false", ")", "?", "intval", "(", "$", "f", ")", ":", "null", ";", "}", "return", "$", "integerArray", ";", "}" ]
Transforms the content of float array to an integer array. @param array $floatArray An array containing float values. @return array An array containing integer values.
[ "Transforms", "the", "content", "of", "float", "array", "to", "an", "integer", "array", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/common/Utils.php#L209-L217
oat-sa/qti-sdk
src/qtism/runtime/common/Utils.php
Utils.integerArrayToFloat
static public function integerArrayToFloat($integerArray) { $floatArray = array(); foreach ($integerArray as $i) { $floatArray[] = (is_null($i) === false) ? floatval($i) : null; } return $floatArray; }
php
static public function integerArrayToFloat($integerArray) { $floatArray = array(); foreach ($integerArray as $i) { $floatArray[] = (is_null($i) === false) ? floatval($i) : null; } return $floatArray; }
[ "static", "public", "function", "integerArrayToFloat", "(", "$", "integerArray", ")", "{", "$", "floatArray", "=", "array", "(", ")", ";", "foreach", "(", "$", "integerArray", "as", "$", "i", ")", "{", "$", "floatArray", "[", "]", "=", "(", "is_null", "(", "$", "i", ")", "===", "false", ")", "?", "floatval", "(", "$", "i", ")", ":", "null", ";", "}", "return", "$", "floatArray", ";", "}" ]
Transforms the content of an integer array to a float array. @param array $integerArray An array containing integer values. @return array An array containing float values.
[ "Transforms", "the", "content", "of", "an", "integer", "array", "to", "a", "float", "array", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/common/Utils.php#L225-L233
oat-sa/qti-sdk
src/qtism/runtime/common/Utils.php
Utils.valueToRuntime
static public function valueToRuntime($v, $baseType) { if ($v !== null) { if (is_int($v) === true) { if ($baseType === -1 || $baseType === BaseType::INTEGER) { return new QtiInteger($v); } elseif ($baseType === BaseType::INT_OR_IDENTIFIER) { return new QtiIntOrIdentifier($v); } } elseif (is_string($v) === true) { if ($baseType === BaseType::IDENTIFIER) { return new QtiIdentifier($v); } if ($baseType === -1 || $baseType === BaseType::STRING) { return new QtiString($v); } elseif ($baseType === BaseType::URI) { return new QtiUri($v); } elseif ($baseType === BaseType::INT_OR_IDENTIFIER) { return new QtiIntOrIdentifier($v); } } elseif (is_float($v) === true) { return new QtiFloat($v); } elseif (is_bool($v) === true) { return new QtiBoolean($v); } } return $v; }
php
static public function valueToRuntime($v, $baseType) { if ($v !== null) { if (is_int($v) === true) { if ($baseType === -1 || $baseType === BaseType::INTEGER) { return new QtiInteger($v); } elseif ($baseType === BaseType::INT_OR_IDENTIFIER) { return new QtiIntOrIdentifier($v); } } elseif (is_string($v) === true) { if ($baseType === BaseType::IDENTIFIER) { return new QtiIdentifier($v); } if ($baseType === -1 || $baseType === BaseType::STRING) { return new QtiString($v); } elseif ($baseType === BaseType::URI) { return new QtiUri($v); } elseif ($baseType === BaseType::INT_OR_IDENTIFIER) { return new QtiIntOrIdentifier($v); } } elseif (is_float($v) === true) { return new QtiFloat($v); } elseif (is_bool($v) === true) { return new QtiBoolean($v); } } return $v; }
[ "static", "public", "function", "valueToRuntime", "(", "$", "v", ",", "$", "baseType", ")", "{", "if", "(", "$", "v", "!==", "null", ")", "{", "if", "(", "is_int", "(", "$", "v", ")", "===", "true", ")", "{", "if", "(", "$", "baseType", "===", "-", "1", "||", "$", "baseType", "===", "BaseType", "::", "INTEGER", ")", "{", "return", "new", "QtiInteger", "(", "$", "v", ")", ";", "}", "elseif", "(", "$", "baseType", "===", "BaseType", "::", "INT_OR_IDENTIFIER", ")", "{", "return", "new", "QtiIntOrIdentifier", "(", "$", "v", ")", ";", "}", "}", "elseif", "(", "is_string", "(", "$", "v", ")", "===", "true", ")", "{", "if", "(", "$", "baseType", "===", "BaseType", "::", "IDENTIFIER", ")", "{", "return", "new", "QtiIdentifier", "(", "$", "v", ")", ";", "}", "if", "(", "$", "baseType", "===", "-", "1", "||", "$", "baseType", "===", "BaseType", "::", "STRING", ")", "{", "return", "new", "QtiString", "(", "$", "v", ")", ";", "}", "elseif", "(", "$", "baseType", "===", "BaseType", "::", "URI", ")", "{", "return", "new", "QtiUri", "(", "$", "v", ")", ";", "}", "elseif", "(", "$", "baseType", "===", "BaseType", "::", "INT_OR_IDENTIFIER", ")", "{", "return", "new", "QtiIntOrIdentifier", "(", "$", "v", ")", ";", "}", "}", "elseif", "(", "is_float", "(", "$", "v", ")", "===", "true", ")", "{", "return", "new", "QtiFloat", "(", "$", "v", ")", ";", "}", "elseif", "(", "is_bool", "(", "$", "v", ")", "===", "true", ")", "{", "return", "new", "QtiBoolean", "(", "$", "v", ")", ";", "}", "}", "return", "$", "v", ";", "}" ]
Transform a given PHP scalar value to a QtiScalar equivalent object. @param mixed|null $v @param integer $baseType A value from the BaseType enumeration. @return \qtism\common\datatypes\QtiScalar
[ "Transform", "a", "given", "PHP", "scalar", "value", "to", "a", "QtiScalar", "equivalent", "object", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/common/Utils.php#L242-L274
oat-sa/qti-sdk
src/qtism/runtime/common/Utils.php
Utils.isNull
static public function isNull(QtiDatatype $value = null) { return is_null($value) === true || ($value instanceof QtiString && $value->getValue() === '') || ($value instanceof Container && count($value) === 0); }
php
static public function isNull(QtiDatatype $value = null) { return is_null($value) === true || ($value instanceof QtiString && $value->getValue() === '') || ($value instanceof Container && count($value) === 0); }
[ "static", "public", "function", "isNull", "(", "QtiDatatype", "$", "value", "=", "null", ")", "{", "return", "is_null", "(", "$", "value", ")", "===", "true", "||", "(", "$", "value", "instanceof", "QtiString", "&&", "$", "value", "->", "getValue", "(", ")", "===", "''", ")", "||", "(", "$", "value", "instanceof", "Container", "&&", "count", "(", "$", "value", ")", "===", "0", ")", ";", "}" ]
Whether or not a QtiDatatype is considered to be null. As per the QTI specification, the NULL value, empty strings and empty containers are always treated as NULL values. @param \qtism\common\datatypes\QtiDatatype $value @return boolean
[ "Whether", "or", "not", "a", "QtiDatatype", "is", "considered", "to", "be", "null", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/common/Utils.php#L285-L288
oat-sa/qti-sdk
src/qtism/runtime/common/Utils.php
Utils.equals
static public function equals(QtiDatatype $a = null, QtiDatatype $b = null) { return (is_null($a) ? is_null($b) : $a->equals($b)); }
php
static public function equals(QtiDatatype $a = null, QtiDatatype $b = null) { return (is_null($a) ? is_null($b) : $a->equals($b)); }
[ "static", "public", "function", "equals", "(", "QtiDatatype", "$", "a", "=", "null", ",", "QtiDatatype", "$", "b", "=", "null", ")", "{", "return", "(", "is_null", "(", "$", "a", ")", "?", "is_null", "(", "$", "b", ")", ":", "$", "a", "->", "equals", "(", "$", "b", ")", ")", ";", "}" ]
Whether or not two QtiDatatype instances are equals. Because the runtime model also deals with null values, this utility method helps to determine equality easily, without testing specifically if one or both values are null prior to perform QtiDatatype::equals(). @param QtiDatatype $a @param QtiDatatype $b @return boolean
[ "Whether", "or", "not", "two", "QtiDatatype", "instances", "are", "equals", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/common/Utils.php#L302-L305
oat-sa/qti-sdk
src/qtism/data/storage/xml/marshalling/PrintedVariableMarshaller.php
PrintedVariableMarshaller.marshall
protected function marshall(QtiComponent $component) { $element = $this->createElement($component); $version = $this->getVersion(); $this->setDOMElementAttribute($element, 'identifier', $component->getIdentifier()); $this->setDOMElementAttribute($element, 'base', $component->getBase()); if (Version::compare($version, '2.1.0', '>=') === true) { $this->setDOMElementAttribute($element, 'powerForm', $component->mustPowerForm()); $this->setDOMElementAttribute($element, 'delimiter', $component->getDelimiter()); $this->setDOMElementAttribute($element, 'mappingIndicator', $component->getMappingIndicator()); } if ($component->hasFormat() === true) { $this->setDOMElementAttribute($element, 'format', $component->getFormat()); } if ($component->hasIndex() === true) { $this->setDOMElementAttribute($element, 'index', $component->getIndex()); } if ($component->hasField() === true) { $this->setDOMElementAttribute($element, 'field', $component->getField()); } if ($component->hasXmlBase() === true) { self::setXmlBase($element, $component->getXmlBase()); } $this->fillElement($element, $component); return $element; }
php
protected function marshall(QtiComponent $component) { $element = $this->createElement($component); $version = $this->getVersion(); $this->setDOMElementAttribute($element, 'identifier', $component->getIdentifier()); $this->setDOMElementAttribute($element, 'base', $component->getBase()); if (Version::compare($version, '2.1.0', '>=') === true) { $this->setDOMElementAttribute($element, 'powerForm', $component->mustPowerForm()); $this->setDOMElementAttribute($element, 'delimiter', $component->getDelimiter()); $this->setDOMElementAttribute($element, 'mappingIndicator', $component->getMappingIndicator()); } if ($component->hasFormat() === true) { $this->setDOMElementAttribute($element, 'format', $component->getFormat()); } if ($component->hasIndex() === true) { $this->setDOMElementAttribute($element, 'index', $component->getIndex()); } if ($component->hasField() === true) { $this->setDOMElementAttribute($element, 'field', $component->getField()); } if ($component->hasXmlBase() === true) { self::setXmlBase($element, $component->getXmlBase()); } $this->fillElement($element, $component); return $element; }
[ "protected", "function", "marshall", "(", "QtiComponent", "$", "component", ")", "{", "$", "element", "=", "$", "this", "->", "createElement", "(", "$", "component", ")", ";", "$", "version", "=", "$", "this", "->", "getVersion", "(", ")", ";", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'identifier'", ",", "$", "component", "->", "getIdentifier", "(", ")", ")", ";", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'base'", ",", "$", "component", "->", "getBase", "(", ")", ")", ";", "if", "(", "Version", "::", "compare", "(", "$", "version", ",", "'2.1.0'", ",", "'>='", ")", "===", "true", ")", "{", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'powerForm'", ",", "$", "component", "->", "mustPowerForm", "(", ")", ")", ";", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'delimiter'", ",", "$", "component", "->", "getDelimiter", "(", ")", ")", ";", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'mappingIndicator'", ",", "$", "component", "->", "getMappingIndicator", "(", ")", ")", ";", "}", "if", "(", "$", "component", "->", "hasFormat", "(", ")", "===", "true", ")", "{", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'format'", ",", "$", "component", "->", "getFormat", "(", ")", ")", ";", "}", "if", "(", "$", "component", "->", "hasIndex", "(", ")", "===", "true", ")", "{", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'index'", ",", "$", "component", "->", "getIndex", "(", ")", ")", ";", "}", "if", "(", "$", "component", "->", "hasField", "(", ")", "===", "true", ")", "{", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'field'", ",", "$", "component", "->", "getField", "(", ")", ")", ";", "}", "if", "(", "$", "component", "->", "hasXmlBase", "(", ")", "===", "true", ")", "{", "self", "::", "setXmlBase", "(", "$", "element", ",", "$", "component", "->", "getXmlBase", "(", ")", ")", ";", "}", "$", "this", "->", "fillElement", "(", "$", "element", ",", "$", "component", ")", ";", "return", "$", "element", ";", "}" ]
Marshall a PrintedVariable object into a DOMElement object. @param \qtism\data\QtiComponent $component A PrintedVariable object. @return \DOMElement The according DOMElement object. @throws \qtism\data\storage\xml\marshalling\MarshallingException
[ "Marshall", "a", "PrintedVariable", "object", "into", "a", "DOMElement", "object", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/PrintedVariableMarshaller.php#L47-L80
oat-sa/qti-sdk
src/qtism/data/storage/xml/marshalling/PrintedVariableMarshaller.php
PrintedVariableMarshaller.unmarshall
protected function unmarshall(DOMElement $element) { $version = $this->getVersion(); if (($identifier = $this->getDOMElementAttributeAs($element, 'identifier')) !== null) { $component = new PrintedVariable($identifier); if (($format = $this->getDOMElementAttributeAs($element, 'format')) !== null) { $component->setFormat($format); } if (Version::compare($version, '2.1.0', '>=') === true && ($powerForm = $this->getDOMElementAttributeAs($element, 'powerForm', 'boolean')) !== null) { $component->setPowerForm($powerForm); } if (($base = $this->getDOMElementAttributeAs($element, 'base')) !== null) { $component->setBase((Format::isInteger($base) === true) ? intval($base) : $base); } if (($index = $this->getDOMElementAttributeAs($element, 'index')) !== null) { $component->setIndex((Format::isInteger($index) === true) ? intval($index) : $base); } if (Version::compare($version, '2.1.0', '>=') === true && ($delimiter = $this->getDOMElementAttributeAs($element, 'delimiter')) !== null) { $component->setDelimiter($delimiter); } if (($field = $this->getDOMElementAttributeAs($element, 'field')) !== null) { $component->setField($field); } if (Version::compare($version, '2.1.0', '>=') === true && ($mappingIndicator = $this->getDOMElementAttributeAs($element, 'mappingIndicator')) !== null) { $component->setMappingIndicator($mappingIndicator); } if (($xmlBase = self::getXmlBase($element)) !== false) { $component->setXmlBase($xmlBase); } $this->fillBodyElement($component, $element); return $component; } else { $msg = "The mandatory 'identifier' attribute is missing from the 'printedVariable' element."; throw new UnmarshallingException($msg, $element); } }
php
protected function unmarshall(DOMElement $element) { $version = $this->getVersion(); if (($identifier = $this->getDOMElementAttributeAs($element, 'identifier')) !== null) { $component = new PrintedVariable($identifier); if (($format = $this->getDOMElementAttributeAs($element, 'format')) !== null) { $component->setFormat($format); } if (Version::compare($version, '2.1.0', '>=') === true && ($powerForm = $this->getDOMElementAttributeAs($element, 'powerForm', 'boolean')) !== null) { $component->setPowerForm($powerForm); } if (($base = $this->getDOMElementAttributeAs($element, 'base')) !== null) { $component->setBase((Format::isInteger($base) === true) ? intval($base) : $base); } if (($index = $this->getDOMElementAttributeAs($element, 'index')) !== null) { $component->setIndex((Format::isInteger($index) === true) ? intval($index) : $base); } if (Version::compare($version, '2.1.0', '>=') === true && ($delimiter = $this->getDOMElementAttributeAs($element, 'delimiter')) !== null) { $component->setDelimiter($delimiter); } if (($field = $this->getDOMElementAttributeAs($element, 'field')) !== null) { $component->setField($field); } if (Version::compare($version, '2.1.0', '>=') === true && ($mappingIndicator = $this->getDOMElementAttributeAs($element, 'mappingIndicator')) !== null) { $component->setMappingIndicator($mappingIndicator); } if (($xmlBase = self::getXmlBase($element)) !== false) { $component->setXmlBase($xmlBase); } $this->fillBodyElement($component, $element); return $component; } else { $msg = "The mandatory 'identifier' attribute is missing from the 'printedVariable' element."; throw new UnmarshallingException($msg, $element); } }
[ "protected", "function", "unmarshall", "(", "DOMElement", "$", "element", ")", "{", "$", "version", "=", "$", "this", "->", "getVersion", "(", ")", ";", "if", "(", "(", "$", "identifier", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'identifier'", ")", ")", "!==", "null", ")", "{", "$", "component", "=", "new", "PrintedVariable", "(", "$", "identifier", ")", ";", "if", "(", "(", "$", "format", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'format'", ")", ")", "!==", "null", ")", "{", "$", "component", "->", "setFormat", "(", "$", "format", ")", ";", "}", "if", "(", "Version", "::", "compare", "(", "$", "version", ",", "'2.1.0'", ",", "'>='", ")", "===", "true", "&&", "(", "$", "powerForm", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'powerForm'", ",", "'boolean'", ")", ")", "!==", "null", ")", "{", "$", "component", "->", "setPowerForm", "(", "$", "powerForm", ")", ";", "}", "if", "(", "(", "$", "base", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'base'", ")", ")", "!==", "null", ")", "{", "$", "component", "->", "setBase", "(", "(", "Format", "::", "isInteger", "(", "$", "base", ")", "===", "true", ")", "?", "intval", "(", "$", "base", ")", ":", "$", "base", ")", ";", "}", "if", "(", "(", "$", "index", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'index'", ")", ")", "!==", "null", ")", "{", "$", "component", "->", "setIndex", "(", "(", "Format", "::", "isInteger", "(", "$", "index", ")", "===", "true", ")", "?", "intval", "(", "$", "index", ")", ":", "$", "base", ")", ";", "}", "if", "(", "Version", "::", "compare", "(", "$", "version", ",", "'2.1.0'", ",", "'>='", ")", "===", "true", "&&", "(", "$", "delimiter", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'delimiter'", ")", ")", "!==", "null", ")", "{", "$", "component", "->", "setDelimiter", "(", "$", "delimiter", ")", ";", "}", "if", "(", "(", "$", "field", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'field'", ")", ")", "!==", "null", ")", "{", "$", "component", "->", "setField", "(", "$", "field", ")", ";", "}", "if", "(", "Version", "::", "compare", "(", "$", "version", ",", "'2.1.0'", ",", "'>='", ")", "===", "true", "&&", "(", "$", "mappingIndicator", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'mappingIndicator'", ")", ")", "!==", "null", ")", "{", "$", "component", "->", "setMappingIndicator", "(", "$", "mappingIndicator", ")", ";", "}", "if", "(", "(", "$", "xmlBase", "=", "self", "::", "getXmlBase", "(", "$", "element", ")", ")", "!==", "false", ")", "{", "$", "component", "->", "setXmlBase", "(", "$", "xmlBase", ")", ";", "}", "$", "this", "->", "fillBodyElement", "(", "$", "component", ",", "$", "element", ")", ";", "return", "$", "component", ";", "}", "else", "{", "$", "msg", "=", "\"The mandatory 'identifier' attribute is missing from the 'printedVariable' element.\"", ";", "throw", "new", "UnmarshallingException", "(", "$", "msg", ",", "$", "element", ")", ";", "}", "}" ]
Unmarshall a DOMElement object corresponding to a printedVariable element. @param \DOMElement $element A DOMElement object. @return \qtism\data\QtiComponent A PrintedVariable object. @throws \qtism\data\storage\xml\marshalling\UnmarshallingException
[ "Unmarshall", "a", "DOMElement", "object", "corresponding", "to", "a", "printedVariable", "element", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/PrintedVariableMarshaller.php#L89-L135
oat-sa/qti-sdk
src/qtism/data/content/interactions/GapImg.php
GapImg.setObjectLabel
public function setObjectLabel($objectLabel) { if (is_string($objectLabel) === true) { $this->objectLabel = $objectLabel; } else { $msg = "The 'objectLabel' argument must be a string, '" . gettype($objectLabel) . "' given."; throw new InvalidArgumentException($msg); } }
php
public function setObjectLabel($objectLabel) { if (is_string($objectLabel) === true) { $this->objectLabel = $objectLabel; } else { $msg = "The 'objectLabel' argument must be a string, '" . gettype($objectLabel) . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setObjectLabel", "(", "$", "objectLabel", ")", "{", "if", "(", "is_string", "(", "$", "objectLabel", ")", "===", "true", ")", "{", "$", "this", "->", "objectLabel", "=", "$", "objectLabel", ";", "}", "else", "{", "$", "msg", "=", "\"The 'objectLabel' argument must be a string, '\"", ".", "gettype", "(", "$", "objectLabel", ")", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set an optional label for the image object to be inserted. An empty string indicates the GapImg has no objectLabel. @param string $objectLabel A label for the image. @throws \InvalidArgumentException If $objectLabel is not a string value.
[ "Set", "an", "optional", "label", "for", "the", "image", "object", "to", "be", "inserted", ".", "An", "empty", "string", "indicates", "the", "GapImg", "has", "no", "objectLabel", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/interactions/GapImg.php#L84-L92
oat-sa/qti-sdk
src/qtism/common/enums/Cardinality.php
Cardinality.getConstantByName
public static function getConstantByName($name) { switch (strtolower($name)) { case 'single': return self::SINGLE; break; case 'multiple': return self::MULTIPLE; break; case 'ordered': return self::ORDERED; break; case 'record': return self::RECORD; break; default: return false; break; } }
php
public static function getConstantByName($name) { switch (strtolower($name)) { case 'single': return self::SINGLE; break; case 'multiple': return self::MULTIPLE; break; case 'ordered': return self::ORDERED; break; case 'record': return self::RECORD; break; default: return false; break; } }
[ "public", "static", "function", "getConstantByName", "(", "$", "name", ")", "{", "switch", "(", "strtolower", "(", "$", "name", ")", ")", "{", "case", "'single'", ":", "return", "self", "::", "SINGLE", ";", "break", ";", "case", "'multiple'", ":", "return", "self", "::", "MULTIPLE", ";", "break", ";", "case", "'ordered'", ":", "return", "self", "::", "ORDERED", ";", "break", ";", "case", "'record'", ":", "return", "self", "::", "RECORD", ";", "break", ";", "default", ":", "return", "false", ";", "break", ";", "}", "}" ]
Get a constant value from its name. @param unknown_type $name The name of the constant, as per QTI spec. @return integer|boolean The constant value or false if not found.
[ "Get", "a", "constant", "value", "from", "its", "name", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/enums/Cardinality.php#L98-L121
oat-sa/qti-sdk
src/qtism/common/enums/Cardinality.php
Cardinality.getNameByConstant
public static function getNameByConstant($constant) { switch ($constant) { case self::SINGLE: return 'single'; break; case self::MULTIPLE: return 'multiple'; break; case self::ORDERED: return 'ordered'; break; case self::RECORD: return 'record'; break; default: return false; break; } }
php
public static function getNameByConstant($constant) { switch ($constant) { case self::SINGLE: return 'single'; break; case self::MULTIPLE: return 'multiple'; break; case self::ORDERED: return 'ordered'; break; case self::RECORD: return 'record'; break; default: return false; break; } }
[ "public", "static", "function", "getNameByConstant", "(", "$", "constant", ")", "{", "switch", "(", "$", "constant", ")", "{", "case", "self", "::", "SINGLE", ":", "return", "'single'", ";", "break", ";", "case", "self", "::", "MULTIPLE", ":", "return", "'multiple'", ";", "break", ";", "case", "self", "::", "ORDERED", ":", "return", "'ordered'", ";", "break", ";", "case", "self", "::", "RECORD", ":", "return", "'record'", ";", "break", ";", "default", ":", "return", "false", ";", "break", ";", "}", "}" ]
Get the name of a constant from its value. @param string $constant The constant value to search the name for. @return string|boolean The name of the constant or false if not found.
[ "Get", "the", "name", "of", "a", "constant", "from", "its", "value", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/enums/Cardinality.php#L129-L152
oat-sa/qti-sdk
src/qtism/runtime/expressions/operators/MatchProcessor.php
MatchProcessor.process
public function process() { $operands = $this->getOperands(); $expression = $this->getExpression(); if ($operands->containsNull() === true) { return null; } if ($operands->sameCardinality() === false) { $msg = "The Match Expression only accepts operands with the same cardinality."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY); } if ($operands->sameBaseType() === false) { $msg = "The Match Expression only accepts operands with the same baseType."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE); } $firstOperand = $operands[0]; $secondOperand = $operands[1]; if ($operands[0] instanceof Comparable) { // 2 containers to compare. return new QtiBoolean($operands[0]->equals($operands[1])); } else { return new QtiBoolean($operands[0] === $operands[1]); } }
php
public function process() { $operands = $this->getOperands(); $expression = $this->getExpression(); if ($operands->containsNull() === true) { return null; } if ($operands->sameCardinality() === false) { $msg = "The Match Expression only accepts operands with the same cardinality."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY); } if ($operands->sameBaseType() === false) { $msg = "The Match Expression only accepts operands with the same baseType."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE); } $firstOperand = $operands[0]; $secondOperand = $operands[1]; if ($operands[0] instanceof Comparable) { // 2 containers to compare. return new QtiBoolean($operands[0]->equals($operands[1])); } else { return new QtiBoolean($operands[0] === $operands[1]); } }
[ "public", "function", "process", "(", ")", "{", "$", "operands", "=", "$", "this", "->", "getOperands", "(", ")", ";", "$", "expression", "=", "$", "this", "->", "getExpression", "(", ")", ";", "if", "(", "$", "operands", "->", "containsNull", "(", ")", "===", "true", ")", "{", "return", "null", ";", "}", "if", "(", "$", "operands", "->", "sameCardinality", "(", ")", "===", "false", ")", "{", "$", "msg", "=", "\"The Match Expression only accepts operands with the same cardinality.\"", ";", "throw", "new", "OperatorProcessingException", "(", "$", "msg", ",", "$", "this", ",", "OperatorProcessingException", "::", "WRONG_CARDINALITY", ")", ";", "}", "if", "(", "$", "operands", "->", "sameBaseType", "(", ")", "===", "false", ")", "{", "$", "msg", "=", "\"The Match Expression only accepts operands with the same baseType.\"", ";", "throw", "new", "OperatorProcessingException", "(", "$", "msg", ",", "$", "this", ",", "OperatorProcessingException", "::", "WRONG_BASETYPE", ")", ";", "}", "$", "firstOperand", "=", "$", "operands", "[", "0", "]", ";", "$", "secondOperand", "=", "$", "operands", "[", "1", "]", ";", "if", "(", "$", "operands", "[", "0", "]", "instanceof", "Comparable", ")", "{", "// 2 containers to compare.", "return", "new", "QtiBoolean", "(", "$", "operands", "[", "0", "]", "->", "equals", "(", "$", "operands", "[", "1", "]", ")", ")", ";", "}", "else", "{", "return", "new", "QtiBoolean", "(", "$", "operands", "[", "0", "]", "===", "$", "operands", "[", "1", "]", ")", ";", "}", "}" ]
Process the Match Expression object. @return boolean|null Whether the two expressions represent the same value or NULL if either of the sub-expressions is NULL. @throws \qtism\runtime\expressions\operators\OperatorProcessingException
[ "Process", "the", "Match", "Expression", "object", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/MatchProcessor.php#L56-L84
oat-sa/qti-sdk
src/qtism/data/ExtendedAssessmentItemRef.php
ExtendedAssessmentItemRef.setTimeDependent
public function setTimeDependent($timeDependent) { if (gettype($timeDependent) === 'boolean') { $this->timeDependent = $timeDependent; } else { $msg = "The timeDependent argument must be a boolean value, '" . gettype($timeDependent) . "' given."; throw new InvalidArgumentException($msg); } }
php
public function setTimeDependent($timeDependent) { if (gettype($timeDependent) === 'boolean') { $this->timeDependent = $timeDependent; } else { $msg = "The timeDependent argument must be a boolean value, '" . gettype($timeDependent) . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setTimeDependent", "(", "$", "timeDependent", ")", "{", "if", "(", "gettype", "(", "$", "timeDependent", ")", "===", "'boolean'", ")", "{", "$", "this", "->", "timeDependent", "=", "$", "timeDependent", ";", "}", "else", "{", "$", "msg", "=", "\"The timeDependent argument must be a boolean value, '\"", ".", "gettype", "(", "$", "timeDependent", ")", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set if the referenced Item is considered to be time dependent or not. @param boolean $timeDependent Whether the referenced item is time dependent. @throws \InvalidArgumentException If $timeDependent is not a boolean value.
[ "Set", "if", "the", "referenced", "Item", "is", "considered", "to", "be", "time", "dependent", "or", "not", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/ExtendedAssessmentItemRef.php#L452-L460
oat-sa/qti-sdk
src/qtism/data/ExtendedAssessmentItemRef.php
ExtendedAssessmentItemRef.createFromAssessmentItemRef
public static function createFromAssessmentItemRef(AssessmentItemRef $assessmentItemRef) { $identifier = $assessmentItemRef->getIdentifier(); $href = $assessmentItemRef->getHref(); $compactRef = new static($identifier, $href); $compactRef->setBranchRules($assessmentItemRef->getBranchRules()); $compactRef->setCategories($assessmentItemRef->getCategories()); $compactRef->setFixed($assessmentItemRef->isFixed()); $compactRef->setItemSessionControl($assessmentItemRef->getItemSessionControl()); $compactRef->setTimeLimits($assessmentItemRef->getTimeLimits()); $compactRef->setPreConditions($assessmentItemRef->getPreConditions()); $compactRef->setRequired($assessmentItemRef->isRequired()); $compactRef->setTemplateDefaults($assessmentItemRef->getTemplateDefaults()); $compactRef->setWeights($assessmentItemRef->getWeights()); return $compactRef; }
php
public static function createFromAssessmentItemRef(AssessmentItemRef $assessmentItemRef) { $identifier = $assessmentItemRef->getIdentifier(); $href = $assessmentItemRef->getHref(); $compactRef = new static($identifier, $href); $compactRef->setBranchRules($assessmentItemRef->getBranchRules()); $compactRef->setCategories($assessmentItemRef->getCategories()); $compactRef->setFixed($assessmentItemRef->isFixed()); $compactRef->setItemSessionControl($assessmentItemRef->getItemSessionControl()); $compactRef->setTimeLimits($assessmentItemRef->getTimeLimits()); $compactRef->setPreConditions($assessmentItemRef->getPreConditions()); $compactRef->setRequired($assessmentItemRef->isRequired()); $compactRef->setTemplateDefaults($assessmentItemRef->getTemplateDefaults()); $compactRef->setWeights($assessmentItemRef->getWeights()); return $compactRef; }
[ "public", "static", "function", "createFromAssessmentItemRef", "(", "AssessmentItemRef", "$", "assessmentItemRef", ")", "{", "$", "identifier", "=", "$", "assessmentItemRef", "->", "getIdentifier", "(", ")", ";", "$", "href", "=", "$", "assessmentItemRef", "->", "getHref", "(", ")", ";", "$", "compactRef", "=", "new", "static", "(", "$", "identifier", ",", "$", "href", ")", ";", "$", "compactRef", "->", "setBranchRules", "(", "$", "assessmentItemRef", "->", "getBranchRules", "(", ")", ")", ";", "$", "compactRef", "->", "setCategories", "(", "$", "assessmentItemRef", "->", "getCategories", "(", ")", ")", ";", "$", "compactRef", "->", "setFixed", "(", "$", "assessmentItemRef", "->", "isFixed", "(", ")", ")", ";", "$", "compactRef", "->", "setItemSessionControl", "(", "$", "assessmentItemRef", "->", "getItemSessionControl", "(", ")", ")", ";", "$", "compactRef", "->", "setTimeLimits", "(", "$", "assessmentItemRef", "->", "getTimeLimits", "(", ")", ")", ";", "$", "compactRef", "->", "setPreConditions", "(", "$", "assessmentItemRef", "->", "getPreConditions", "(", ")", ")", ";", "$", "compactRef", "->", "setRequired", "(", "$", "assessmentItemRef", "->", "isRequired", "(", ")", ")", ";", "$", "compactRef", "->", "setTemplateDefaults", "(", "$", "assessmentItemRef", "->", "getTemplateDefaults", "(", ")", ")", ";", "$", "compactRef", "->", "setWeights", "(", "$", "assessmentItemRef", "->", "getWeights", "(", ")", ")", ";", "return", "$", "compactRef", ";", "}" ]
Create a new ExtendedAssessmentItemRef object from an AssessmentItemRef object. @param \qtism\data\AssessmentItemRef $assessmentItemRef An AssessmentItemRef object. @return \qtism\data\ExtendedAssessmentItemRef An ExtendedAssessmentItemRef object.
[ "Create", "a", "new", "ExtendedAssessmentItemRef", "object", "from", "an", "AssessmentItemRef", "object", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/ExtendedAssessmentItemRef.php#L538-L554
oat-sa/qti-sdk
src/qtism/runtime/expressions/operators/MaxProcessor.php
MaxProcessor.process
public function process() { $operands = $this->getOperands(); if ($operands->containsNull() === true) { return null; } if ($operands->anythingButRecord() === false) { $msg = "The Max operator only accept values with a cardinality of single, multiple or ordered."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY); } if ($operands->exclusivelyNumeric() === false) { // As per QTI 2.1 spec, If any of the sub-expressions is not a numerical value, then the result is NULL. return null; } // As per QTI 2.1 spec, // The result is a single float, or, if all sub-expressions are of // integer type, a single integer. $integerCount = 0; $valueCount = 0; $max = -PHP_INT_MAX; foreach ($operands as $operand) { if (!$operand instanceof Container) { $baseType = ($operand instanceof QtiFloat) ? BaseType::FLOAT : BaseType::INTEGER; $value = new MultipleContainer($baseType, array($operand)); } else { $value = $operand; } foreach ($value as $v) { if (is_null($v)) { return null; } $valueCount++; $integerCount += ($v instanceof QtiInteger) ? 1 : 0; if ($v->getValue() > $max) { $max = $v->getValue(); } } } return ($integerCount === $valueCount) ? new QtiInteger(intval($max)) : new QtiFloat(floatval($max)); }
php
public function process() { $operands = $this->getOperands(); if ($operands->containsNull() === true) { return null; } if ($operands->anythingButRecord() === false) { $msg = "The Max operator only accept values with a cardinality of single, multiple or ordered."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY); } if ($operands->exclusivelyNumeric() === false) { // As per QTI 2.1 spec, If any of the sub-expressions is not a numerical value, then the result is NULL. return null; } // As per QTI 2.1 spec, // The result is a single float, or, if all sub-expressions are of // integer type, a single integer. $integerCount = 0; $valueCount = 0; $max = -PHP_INT_MAX; foreach ($operands as $operand) { if (!$operand instanceof Container) { $baseType = ($operand instanceof QtiFloat) ? BaseType::FLOAT : BaseType::INTEGER; $value = new MultipleContainer($baseType, array($operand)); } else { $value = $operand; } foreach ($value as $v) { if (is_null($v)) { return null; } $valueCount++; $integerCount += ($v instanceof QtiInteger) ? 1 : 0; if ($v->getValue() > $max) { $max = $v->getValue(); } } } return ($integerCount === $valueCount) ? new QtiInteger(intval($max)) : new QtiFloat(floatval($max)); }
[ "public", "function", "process", "(", ")", "{", "$", "operands", "=", "$", "this", "->", "getOperands", "(", ")", ";", "if", "(", "$", "operands", "->", "containsNull", "(", ")", "===", "true", ")", "{", "return", "null", ";", "}", "if", "(", "$", "operands", "->", "anythingButRecord", "(", ")", "===", "false", ")", "{", "$", "msg", "=", "\"The Max operator only accept values with a cardinality of single, multiple or ordered.\"", ";", "throw", "new", "OperatorProcessingException", "(", "$", "msg", ",", "$", "this", ",", "OperatorProcessingException", "::", "WRONG_CARDINALITY", ")", ";", "}", "if", "(", "$", "operands", "->", "exclusivelyNumeric", "(", ")", "===", "false", ")", "{", "// As per QTI 2.1 spec, If any of the sub-expressions is not a numerical value, then the result is NULL.", "return", "null", ";", "}", "// As per QTI 2.1 spec,", "// The result is a single float, or, if all sub-expressions are of", "// integer type, a single integer.", "$", "integerCount", "=", "0", ";", "$", "valueCount", "=", "0", ";", "$", "max", "=", "-", "PHP_INT_MAX", ";", "foreach", "(", "$", "operands", "as", "$", "operand", ")", "{", "if", "(", "!", "$", "operand", "instanceof", "Container", ")", "{", "$", "baseType", "=", "(", "$", "operand", "instanceof", "QtiFloat", ")", "?", "BaseType", "::", "FLOAT", ":", "BaseType", "::", "INTEGER", ";", "$", "value", "=", "new", "MultipleContainer", "(", "$", "baseType", ",", "array", "(", "$", "operand", ")", ")", ";", "}", "else", "{", "$", "value", "=", "$", "operand", ";", "}", "foreach", "(", "$", "value", "as", "$", "v", ")", "{", "if", "(", "is_null", "(", "$", "v", ")", ")", "{", "return", "null", ";", "}", "$", "valueCount", "++", ";", "$", "integerCount", "+=", "(", "$", "v", "instanceof", "QtiInteger", ")", "?", "1", ":", "0", ";", "if", "(", "$", "v", "->", "getValue", "(", ")", ">", "$", "max", ")", "{", "$", "max", "=", "$", "v", "->", "getValue", "(", ")", ";", "}", "}", "}", "return", "(", "$", "integerCount", "===", "$", "valueCount", ")", "?", "new", "QtiInteger", "(", "intval", "(", "$", "max", ")", ")", ":", "new", "QtiFloat", "(", "floatval", "(", "$", "max", ")", ")", ";", "}" ]
Process the current expression. @return float|integer|null The greatest of the operand values or NULL if any of the operand values is 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/MaxProcessor.php#L59-L107
oat-sa/qti-sdk
src/qtism/runtime/common/TemplateVariable.php
TemplateVariable.setParamVariable
public function setParamVariable($paramVariable) { if (is_bool($paramVariable) === true) { $this->paramVariable = $paramVariable; } else { $msg = "The 'paramVariable' argument must be a boolean value, '" . gettype($paramVariable) . "'."; throw new InvalidArgumentException($msg); } }
php
public function setParamVariable($paramVariable) { if (is_bool($paramVariable) === true) { $this->paramVariable = $paramVariable; } else { $msg = "The 'paramVariable' argument must be a boolean value, '" . gettype($paramVariable) . "'."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setParamVariable", "(", "$", "paramVariable", ")", "{", "if", "(", "is_bool", "(", "$", "paramVariable", ")", "===", "true", ")", "{", "$", "this", "->", "paramVariable", "=", "$", "paramVariable", ";", "}", "else", "{", "$", "msg", "=", "\"The 'paramVariable' argument must be a boolean value, '\"", ".", "gettype", "(", "$", "paramVariable", ")", ".", "\"'.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set whether or not the template's value should be substituted for object parameter values. @param boolean $paramVariable @throws \InvalidArgumentException
[ "Set", "whether", "or", "not", "the", "template", "s", "value", "should", "be", "substituted", "for", "object", "parameter", "values", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/common/TemplateVariable.php#L82-L90
oat-sa/qti-sdk
src/qtism/runtime/common/TemplateVariable.php
TemplateVariable.setMathVariable
public function setMathVariable($mathVariable) { if (is_bool($mathVariable) === true) { $this->mathVariable = $mathVariable; } else { $msg = "The 'mathVariable' argument must be a boolean value, '" . gettype($mathVariable) . "'."; throw new InvalidArgumentException($msg); } }
php
public function setMathVariable($mathVariable) { if (is_bool($mathVariable) === true) { $this->mathVariable = $mathVariable; } else { $msg = "The 'mathVariable' argument must be a boolean value, '" . gettype($mathVariable) . "'."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setMathVariable", "(", "$", "mathVariable", ")", "{", "if", "(", "is_bool", "(", "$", "mathVariable", ")", "===", "true", ")", "{", "$", "this", "->", "mathVariable", "=", "$", "mathVariable", ";", "}", "else", "{", "$", "msg", "=", "\"The 'mathVariable' argument must be a boolean value, '\"", ".", "gettype", "(", "$", "mathVariable", ")", ".", "\"'.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set whether or not the template variable's value should be substituted for identifiers that match its name in MathML expressions. @param boolean $mathVariable @throws \InvalidArgumentException
[ "Set", "whether", "or", "not", "the", "template", "variable", "s", "value", "should", "be", "substituted", "for", "identifiers", "that", "match", "its", "name", "in", "MathML", "expressions", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/common/TemplateVariable.php#L110-L118
oat-sa/qti-sdk
src/qtism/runtime/common/TemplateVariable.php
TemplateVariable.createFromDataModel
public static function createFromDataModel(VariableDeclaration $variableDeclaration) { $variable = parent::createFromDataModel($variableDeclaration); if ($variableDeclaration instanceof TemplateDeclaration) { $variable->setParamVariable($variableDeclaration->isParamVariable()); $variable->setMathVariable($variableDeclaration->isMathVariable()); return $variable; } else { $msg = "TemplateVariable::createFromDataModel only accept 'qtism\\data\\state\\TemplateVariable' objects, '" . get_class($variableDeclaration) . "' given."; throw new InvalidArgumentException($msg); } }
php
public static function createFromDataModel(VariableDeclaration $variableDeclaration) { $variable = parent::createFromDataModel($variableDeclaration); if ($variableDeclaration instanceof TemplateDeclaration) { $variable->setParamVariable($variableDeclaration->isParamVariable()); $variable->setMathVariable($variableDeclaration->isMathVariable()); return $variable; } else { $msg = "TemplateVariable::createFromDataModel only accept 'qtism\\data\\state\\TemplateVariable' objects, '" . get_class($variableDeclaration) . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "static", "function", "createFromDataModel", "(", "VariableDeclaration", "$", "variableDeclaration", ")", "{", "$", "variable", "=", "parent", "::", "createFromDataModel", "(", "$", "variableDeclaration", ")", ";", "if", "(", "$", "variableDeclaration", "instanceof", "TemplateDeclaration", ")", "{", "$", "variable", "->", "setParamVariable", "(", "$", "variableDeclaration", "->", "isParamVariable", "(", ")", ")", ";", "$", "variable", "->", "setMathVariable", "(", "$", "variableDeclaration", "->", "isMathVariable", "(", ")", ")", ";", "return", "$", "variable", ";", "}", "else", "{", "$", "msg", "=", "\"TemplateVariable::createFromDataModel only accept 'qtism\\\\data\\\\state\\\\TemplateVariable' objects, '\"", ".", "get_class", "(", "$", "variableDeclaration", ")", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Create a TemplateVariable object from its data model representation. @param \qtism\data\state\VariableDeclaration $variableDeclaration @throws \InvalidArgumentException @return \qtism\runtime\common\TemplateVariable
[ "Create", "a", "TemplateVariable", "object", "from", "its", "data", "model", "representation", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/common/TemplateVariable.php#L138-L152
oat-sa/qti-sdk
src/qtism/data/storage/xml/marshalling/TemplateConstraintMarshaller.php
TemplateConstraintMarshaller.unmarshall
protected function unmarshall(DOMElement $element) { $expressionElt = self::getFirstChildElement($element); try { return new TemplateConstraint($this->getMarshallerFactory()->createMarshaller($expressionElt)->unmarshall($expressionElt)); } catch (InvalidArgumentException $e) { $msg = "A 'templateConstraint' element must contain an 'expression' element, '" . $expressionElt->localName . "' given."; throw new UnmarshallingException($msg, $element); } return new TemplateConstraint($expressions); }
php
protected function unmarshall(DOMElement $element) { $expressionElt = self::getFirstChildElement($element); try { return new TemplateConstraint($this->getMarshallerFactory()->createMarshaller($expressionElt)->unmarshall($expressionElt)); } catch (InvalidArgumentException $e) { $msg = "A 'templateConstraint' element must contain an 'expression' element, '" . $expressionElt->localName . "' given."; throw new UnmarshallingException($msg, $element); } return new TemplateConstraint($expressions); }
[ "protected", "function", "unmarshall", "(", "DOMElement", "$", "element", ")", "{", "$", "expressionElt", "=", "self", "::", "getFirstChildElement", "(", "$", "element", ")", ";", "try", "{", "return", "new", "TemplateConstraint", "(", "$", "this", "->", "getMarshallerFactory", "(", ")", "->", "createMarshaller", "(", "$", "expressionElt", ")", "->", "unmarshall", "(", "$", "expressionElt", ")", ")", ";", "}", "catch", "(", "InvalidArgumentException", "$", "e", ")", "{", "$", "msg", "=", "\"A 'templateConstraint' element must contain an 'expression' element, '\"", ".", "$", "expressionElt", "->", "localName", ".", "\"' given.\"", ";", "throw", "new", "UnmarshallingException", "(", "$", "msg", ",", "$", "element", ")", ";", "}", "return", "new", "TemplateConstraint", "(", "$", "expressions", ")", ";", "}" ]
Unmarshall a DOMElement object corresponding to a QTI templateConstraint element. @param \DOMElement $element A DOMElement object. @return \qtism\data\QtiComponent A TemplateConstraint object. @throws \qtism\data\storage\xml\marshalling\UnmarshallingException
[ "Unmarshall", "a", "DOMElement", "object", "corresponding", "to", "a", "QTI", "templateConstraint", "element", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/TemplateConstraintMarshaller.php#L61-L73
oat-sa/qti-sdk
src/qtism/data/storage/Utils.php
Utils.stringToDatatype
public static function stringToDatatype($string, $baseType) { if (in_array($baseType, BaseType::asArray(), true)) { $value = null; switch ($baseType) { case BaseType::BOOLEAN: if (Format::isBoolean($string)) { $value = (Format::toLowerTrim($string) == 'true') ? true : false; return $value; } else { $msg = "'${string}' cannot be transformed into boolean."; throw new UnexpectedValueException($msg); } break; case BaseType::INTEGER: if (Format::isInteger($string)) { $value = intval($string); return $value; } else { $msg = "'${string}' cannot be transformed into integer."; throw new UnexpectedValueException($msg); } break; case BaseType::FLOAT: if (Format::isFloat($string)) { $value = floatval($string); return $value; } else { $msg = "'${string}' cannot be transformed into float."; throw new UnexpectedValueException($msg); } break; case BaseType::URI: if (Format::isUri($string)) { return $string; } else { $msg = "'${string}' is not a valid URI."; throw new UnexpectedValueException($msg); } break; case BaseType::IDENTIFIER: if (Format::isIdentifier($string)) { return $string; } else { $msg = "'${string}' is not a valid QTI Identifier."; throw new UnexpectedValueException($msg); } break; case BaseType::INT_OR_IDENTIFIER: if (Format::isIdentifier($string)) { return $string; } elseif (Format::isInteger($string)) { return intval($string); } else { $msg = "'${string}' is not a valid QTI Identifier nor a valid integer."; throw new UnexpectedValueException($msg); } break; case BaseType::PAIR: if (Format::isPair($string)) { $pair = explode("\x20", $string); return new QtiPair($pair[0], $pair[1]); } else { $msg = "'${string}' is not a valid pair."; throw new UnexpectedValueException($msg); } break; case BaseType::DIRECTED_PAIR: if (Format::isDirectedPair($string)) { $pair = explode("\x20", $string); return new QtiDirectedPair($pair[0], $pair[1]); } else { $msg = "'${string}' is not a valid directed pair."; throw new UnexpectedValueException($msg); } break; case BaseType::DURATION: if (Format::isDuration($string)) { return new QtiDuration($string); } else { $msg = "'${string}' is not a valid duration."; throw new UnexpectedValueException($msg); } break; case BaseType::FILE: throw new \RuntimeException("Unsupported baseType: file."); break; case BaseType::STRING: return '' . $string; break; case BaseType::POINT: if (Format::isPoint($string)) { $parts = explode("\x20", $string); return new QtiPoint(intval($parts[0]), intval($parts[1])); } else { $msg = "'${string}' is not valid point."; throw new UnexpectedValueException($msg); } break; } } else { $msg = "BaseType must be a value from the BaseType enumeration."; throw new InvalidArgumentException($msg); } }
php
public static function stringToDatatype($string, $baseType) { if (in_array($baseType, BaseType::asArray(), true)) { $value = null; switch ($baseType) { case BaseType::BOOLEAN: if (Format::isBoolean($string)) { $value = (Format::toLowerTrim($string) == 'true') ? true : false; return $value; } else { $msg = "'${string}' cannot be transformed into boolean."; throw new UnexpectedValueException($msg); } break; case BaseType::INTEGER: if (Format::isInteger($string)) { $value = intval($string); return $value; } else { $msg = "'${string}' cannot be transformed into integer."; throw new UnexpectedValueException($msg); } break; case BaseType::FLOAT: if (Format::isFloat($string)) { $value = floatval($string); return $value; } else { $msg = "'${string}' cannot be transformed into float."; throw new UnexpectedValueException($msg); } break; case BaseType::URI: if (Format::isUri($string)) { return $string; } else { $msg = "'${string}' is not a valid URI."; throw new UnexpectedValueException($msg); } break; case BaseType::IDENTIFIER: if (Format::isIdentifier($string)) { return $string; } else { $msg = "'${string}' is not a valid QTI Identifier."; throw new UnexpectedValueException($msg); } break; case BaseType::INT_OR_IDENTIFIER: if (Format::isIdentifier($string)) { return $string; } elseif (Format::isInteger($string)) { return intval($string); } else { $msg = "'${string}' is not a valid QTI Identifier nor a valid integer."; throw new UnexpectedValueException($msg); } break; case BaseType::PAIR: if (Format::isPair($string)) { $pair = explode("\x20", $string); return new QtiPair($pair[0], $pair[1]); } else { $msg = "'${string}' is not a valid pair."; throw new UnexpectedValueException($msg); } break; case BaseType::DIRECTED_PAIR: if (Format::isDirectedPair($string)) { $pair = explode("\x20", $string); return new QtiDirectedPair($pair[0], $pair[1]); } else { $msg = "'${string}' is not a valid directed pair."; throw new UnexpectedValueException($msg); } break; case BaseType::DURATION: if (Format::isDuration($string)) { return new QtiDuration($string); } else { $msg = "'${string}' is not a valid duration."; throw new UnexpectedValueException($msg); } break; case BaseType::FILE: throw new \RuntimeException("Unsupported baseType: file."); break; case BaseType::STRING: return '' . $string; break; case BaseType::POINT: if (Format::isPoint($string)) { $parts = explode("\x20", $string); return new QtiPoint(intval($parts[0]), intval($parts[1])); } else { $msg = "'${string}' is not valid point."; throw new UnexpectedValueException($msg); } break; } } else { $msg = "BaseType must be a value from the BaseType enumeration."; throw new InvalidArgumentException($msg); } }
[ "public", "static", "function", "stringToDatatype", "(", "$", "string", ",", "$", "baseType", ")", "{", "if", "(", "in_array", "(", "$", "baseType", ",", "BaseType", "::", "asArray", "(", ")", ",", "true", ")", ")", "{", "$", "value", "=", "null", ";", "switch", "(", "$", "baseType", ")", "{", "case", "BaseType", "::", "BOOLEAN", ":", "if", "(", "Format", "::", "isBoolean", "(", "$", "string", ")", ")", "{", "$", "value", "=", "(", "Format", "::", "toLowerTrim", "(", "$", "string", ")", "==", "'true'", ")", "?", "true", ":", "false", ";", "return", "$", "value", ";", "}", "else", "{", "$", "msg", "=", "\"'${string}' cannot be transformed into boolean.\"", ";", "throw", "new", "UnexpectedValueException", "(", "$", "msg", ")", ";", "}", "break", ";", "case", "BaseType", "::", "INTEGER", ":", "if", "(", "Format", "::", "isInteger", "(", "$", "string", ")", ")", "{", "$", "value", "=", "intval", "(", "$", "string", ")", ";", "return", "$", "value", ";", "}", "else", "{", "$", "msg", "=", "\"'${string}' cannot be transformed into integer.\"", ";", "throw", "new", "UnexpectedValueException", "(", "$", "msg", ")", ";", "}", "break", ";", "case", "BaseType", "::", "FLOAT", ":", "if", "(", "Format", "::", "isFloat", "(", "$", "string", ")", ")", "{", "$", "value", "=", "floatval", "(", "$", "string", ")", ";", "return", "$", "value", ";", "}", "else", "{", "$", "msg", "=", "\"'${string}' cannot be transformed into float.\"", ";", "throw", "new", "UnexpectedValueException", "(", "$", "msg", ")", ";", "}", "break", ";", "case", "BaseType", "::", "URI", ":", "if", "(", "Format", "::", "isUri", "(", "$", "string", ")", ")", "{", "return", "$", "string", ";", "}", "else", "{", "$", "msg", "=", "\"'${string}' is not a valid URI.\"", ";", "throw", "new", "UnexpectedValueException", "(", "$", "msg", ")", ";", "}", "break", ";", "case", "BaseType", "::", "IDENTIFIER", ":", "if", "(", "Format", "::", "isIdentifier", "(", "$", "string", ")", ")", "{", "return", "$", "string", ";", "}", "else", "{", "$", "msg", "=", "\"'${string}' is not a valid QTI Identifier.\"", ";", "throw", "new", "UnexpectedValueException", "(", "$", "msg", ")", ";", "}", "break", ";", "case", "BaseType", "::", "INT_OR_IDENTIFIER", ":", "if", "(", "Format", "::", "isIdentifier", "(", "$", "string", ")", ")", "{", "return", "$", "string", ";", "}", "elseif", "(", "Format", "::", "isInteger", "(", "$", "string", ")", ")", "{", "return", "intval", "(", "$", "string", ")", ";", "}", "else", "{", "$", "msg", "=", "\"'${string}' is not a valid QTI Identifier nor a valid integer.\"", ";", "throw", "new", "UnexpectedValueException", "(", "$", "msg", ")", ";", "}", "break", ";", "case", "BaseType", "::", "PAIR", ":", "if", "(", "Format", "::", "isPair", "(", "$", "string", ")", ")", "{", "$", "pair", "=", "explode", "(", "\"\\x20\"", ",", "$", "string", ")", ";", "return", "new", "QtiPair", "(", "$", "pair", "[", "0", "]", ",", "$", "pair", "[", "1", "]", ")", ";", "}", "else", "{", "$", "msg", "=", "\"'${string}' is not a valid pair.\"", ";", "throw", "new", "UnexpectedValueException", "(", "$", "msg", ")", ";", "}", "break", ";", "case", "BaseType", "::", "DIRECTED_PAIR", ":", "if", "(", "Format", "::", "isDirectedPair", "(", "$", "string", ")", ")", "{", "$", "pair", "=", "explode", "(", "\"\\x20\"", ",", "$", "string", ")", ";", "return", "new", "QtiDirectedPair", "(", "$", "pair", "[", "0", "]", ",", "$", "pair", "[", "1", "]", ")", ";", "}", "else", "{", "$", "msg", "=", "\"'${string}' is not a valid directed pair.\"", ";", "throw", "new", "UnexpectedValueException", "(", "$", "msg", ")", ";", "}", "break", ";", "case", "BaseType", "::", "DURATION", ":", "if", "(", "Format", "::", "isDuration", "(", "$", "string", ")", ")", "{", "return", "new", "QtiDuration", "(", "$", "string", ")", ";", "}", "else", "{", "$", "msg", "=", "\"'${string}' is not a valid duration.\"", ";", "throw", "new", "UnexpectedValueException", "(", "$", "msg", ")", ";", "}", "break", ";", "case", "BaseType", "::", "FILE", ":", "throw", "new", "\\", "RuntimeException", "(", "\"Unsupported baseType: file.\"", ")", ";", "break", ";", "case", "BaseType", "::", "STRING", ":", "return", "''", ".", "$", "string", ";", "break", ";", "case", "BaseType", "::", "POINT", ":", "if", "(", "Format", "::", "isPoint", "(", "$", "string", ")", ")", "{", "$", "parts", "=", "explode", "(", "\"\\x20\"", ",", "$", "string", ")", ";", "return", "new", "QtiPoint", "(", "intval", "(", "$", "parts", "[", "0", "]", ")", ",", "intval", "(", "$", "parts", "[", "1", "]", ")", ")", ";", "}", "else", "{", "$", "msg", "=", "\"'${string}' is not valid point.\"", ";", "throw", "new", "UnexpectedValueException", "(", "$", "msg", ")", ";", "}", "break", ";", "}", "}", "else", "{", "$", "msg", "=", "\"BaseType must be a value from the BaseType enumeration.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Transform a string representing a QTI valueType value in a the correct datatype. @param string $string The QTI valueType value as a string. @param integer $baseType The QTI baseType that defines the datatype of $string. @return mixed A converted object/primitive type. @throws \InvalidArgumentException If $baseType is not a value from the BaseType enumeration. @throws \UnexpectedValueException If $string cannot be transformed in a Value expression with the given $baseType.
[ "Transform", "a", "string", "representing", "a", "QTI", "valueType", "value", "in", "a", "the", "correct", "datatype", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/Utils.php#L54-L176
oat-sa/qti-sdk
src/qtism/data/storage/Utils.php
Utils.stringToCoords
public static function stringToCoords($string, $shape) { if (Format::isCoords($string)) { $stringCoords = explode(",", $string); $intCoords = array(); foreach ($stringCoords as $sC) { $intCoords[] = intval($sC); } // Maybe it was accepted has coords, but is it buildable with // the given shape? return new QtiCoords($shape, $intCoords); } else { throw new UnexpectedValueException("'${string}' cannot be converted to Coords."); } }
php
public static function stringToCoords($string, $shape) { if (Format::isCoords($string)) { $stringCoords = explode(",", $string); $intCoords = array(); foreach ($stringCoords as $sC) { $intCoords[] = intval($sC); } // Maybe it was accepted has coords, but is it buildable with // the given shape? return new QtiCoords($shape, $intCoords); } else { throw new UnexpectedValueException("'${string}' cannot be converted to Coords."); } }
[ "public", "static", "function", "stringToCoords", "(", "$", "string", ",", "$", "shape", ")", "{", "if", "(", "Format", "::", "isCoords", "(", "$", "string", ")", ")", "{", "$", "stringCoords", "=", "explode", "(", "\",\"", ",", "$", "string", ")", ";", "$", "intCoords", "=", "array", "(", ")", ";", "foreach", "(", "$", "stringCoords", "as", "$", "sC", ")", "{", "$", "intCoords", "[", "]", "=", "intval", "(", "$", "sC", ")", ";", "}", "// Maybe it was accepted has coords, but is it buildable with", "// the given shape?", "return", "new", "QtiCoords", "(", "$", "shape", ",", "$", "intCoords", ")", ";", "}", "else", "{", "throw", "new", "UnexpectedValueException", "(", "\"'${string}' cannot be converted to Coords.\"", ")", ";", "}", "}" ]
Transforms a string to a Coord object according to a given shape. @param string $string Coordinates as a string. @param int $shape A value from the Shape enumeration. @throws \InvalidArgumentException If $string is are not valid coordinates or $shape is not a value from the Shape enumeration. @throws \UnexpectedValueException If $string cannot be converted to a Coords object. @return \qtism\common\datatypes\Coords A Coords object.
[ "Transforms", "a", "string", "to", "a", "Coord", "object", "according", "to", "a", "given", "shape", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/Utils.php#L187-L204
oat-sa/qti-sdk
src/qtism/data/storage/Utils.php
Utils.sanitizeUri
public static function sanitizeUri($uri) { if (gettype($uri) === 'string') { return rtrim($uri, '/'); } $msg = "The uri argument must be a string, '" . gettype($uri) . "' given."; throw new InvalidArgumentException($msg); }
php
public static function sanitizeUri($uri) { if (gettype($uri) === 'string') { return rtrim($uri, '/'); } $msg = "The uri argument must be a string, '" . gettype($uri) . "' given."; throw new InvalidArgumentException($msg); }
[ "public", "static", "function", "sanitizeUri", "(", "$", "uri", ")", "{", "if", "(", "gettype", "(", "$", "uri", ")", "===", "'string'", ")", "{", "return", "rtrim", "(", "$", "uri", ",", "'/'", ")", ";", "}", "$", "msg", "=", "\"The uri argument must be a string, '\"", ".", "gettype", "(", "$", "uri", ")", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}" ]
Sanitize a URI (Uniform Resource Identifier). The following processings will be applied: * If there is/are trailing slashe(s), they will be removed. @param string $uri A Uniform Resource Identifier. @throws \InvalidArgumentException If $uri is not a string. @return string A sanitized Uniform Resource Identifier.
[ "Sanitize", "a", "URI", "(", "Uniform", "Resource", "Identifier", ")", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/Utils.php#L217-L225
oat-sa/qti-sdk
src/qtism/runtime/expressions/operators/custom/Implode.php
Implode.process
public function process() { $operands = $this->getOperands(); if (($c = count($operands)) < 2) { $msg = "The 'qtism.runtime.expressions.operators.custom.Implode' custom operator takes 2 sub-expressions as parameters, ${c} given."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::NOT_ENOUGH_OPERANDS); } elseif ($operands->containsNull() === true) { return null; } elseif ($operands->exclusivelyString() === false) { $msg = "The 'qtism.runtime.expressions.operators.custom.Implode' custom operator only accepts operands with a string baseType."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE); } elseif ($operands[0]->getCardinality() !== Cardinality::SINGLE) { $msg = "The 'qtism.runtime.expressions.operators.custom.Implode' custom operator only accepts a first operand with single cardinality."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY); } elseif ($operands[1]->getCardinality() !== Cardinality::MULTIPLE && $operands[1]->getCardinality() !== Cardinality::ORDERED) { $msg = "The 'qtism.runtime.expressions.operators.custom.Implode' custom operator only accepts a second operand with multiple or ordered cardinality."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY); } $glue = $operands[0]->getValue(); $pieces = $operands[1]; // Note: implode() is binary-safe \0/! $string = implode($glue, $pieces->getArrayCopy()); return new QtiString($string); }
php
public function process() { $operands = $this->getOperands(); if (($c = count($operands)) < 2) { $msg = "The 'qtism.runtime.expressions.operators.custom.Implode' custom operator takes 2 sub-expressions as parameters, ${c} given."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::NOT_ENOUGH_OPERANDS); } elseif ($operands->containsNull() === true) { return null; } elseif ($operands->exclusivelyString() === false) { $msg = "The 'qtism.runtime.expressions.operators.custom.Implode' custom operator only accepts operands with a string baseType."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE); } elseif ($operands[0]->getCardinality() !== Cardinality::SINGLE) { $msg = "The 'qtism.runtime.expressions.operators.custom.Implode' custom operator only accepts a first operand with single cardinality."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY); } elseif ($operands[1]->getCardinality() !== Cardinality::MULTIPLE && $operands[1]->getCardinality() !== Cardinality::ORDERED) { $msg = "The 'qtism.runtime.expressions.operators.custom.Implode' custom operator only accepts a second operand with multiple or ordered cardinality."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY); } $glue = $operands[0]->getValue(); $pieces = $operands[1]; // Note: implode() is binary-safe \0/! $string = implode($glue, $pieces->getArrayCopy()); return new QtiString($string); }
[ "public", "function", "process", "(", ")", "{", "$", "operands", "=", "$", "this", "->", "getOperands", "(", ")", ";", "if", "(", "(", "$", "c", "=", "count", "(", "$", "operands", ")", ")", "<", "2", ")", "{", "$", "msg", "=", "\"The 'qtism.runtime.expressions.operators.custom.Implode' custom operator takes 2 sub-expressions as parameters, ${c} given.\"", ";", "throw", "new", "OperatorProcessingException", "(", "$", "msg", ",", "$", "this", ",", "OperatorProcessingException", "::", "NOT_ENOUGH_OPERANDS", ")", ";", "}", "elseif", "(", "$", "operands", "->", "containsNull", "(", ")", "===", "true", ")", "{", "return", "null", ";", "}", "elseif", "(", "$", "operands", "->", "exclusivelyString", "(", ")", "===", "false", ")", "{", "$", "msg", "=", "\"The 'qtism.runtime.expressions.operators.custom.Implode' custom operator only accepts operands with a string baseType.\"", ";", "throw", "new", "OperatorProcessingException", "(", "$", "msg", ",", "$", "this", ",", "OperatorProcessingException", "::", "WRONG_BASETYPE", ")", ";", "}", "elseif", "(", "$", "operands", "[", "0", "]", "->", "getCardinality", "(", ")", "!==", "Cardinality", "::", "SINGLE", ")", "{", "$", "msg", "=", "\"The 'qtism.runtime.expressions.operators.custom.Implode' custom operator only accepts a first operand with single cardinality.\"", ";", "throw", "new", "OperatorProcessingException", "(", "$", "msg", ",", "$", "this", ",", "OperatorProcessingException", "::", "WRONG_CARDINALITY", ")", ";", "}", "elseif", "(", "$", "operands", "[", "1", "]", "->", "getCardinality", "(", ")", "!==", "Cardinality", "::", "MULTIPLE", "&&", "$", "operands", "[", "1", "]", "->", "getCardinality", "(", ")", "!==", "Cardinality", "::", "ORDERED", ")", "{", "$", "msg", "=", "\"The 'qtism.runtime.expressions.operators.custom.Implode' custom operator only accepts a second operand with multiple or ordered cardinality.\"", ";", "throw", "new", "OperatorProcessingException", "(", "$", "msg", ",", "$", "this", ",", "OperatorProcessingException", "::", "WRONG_CARDINALITY", ")", ";", "}", "$", "glue", "=", "$", "operands", "[", "0", "]", "->", "getValue", "(", ")", ";", "$", "pieces", "=", "$", "operands", "[", "1", "]", ";", "// Note: implode() is binary-safe \\0/!", "$", "string", "=", "implode", "(", "$", "glue", ",", "$", "pieces", "->", "getArrayCopy", "(", ")", ")", ";", "return", "new", "QtiString", "(", "$", "string", ")", ";", "}" ]
Process the expression by implementing PHP core's implode function. @return String The split value of the second sub-expression given as a parameter. @throws \qtism\runtime\expressions\operators\OperatorProcessingException If something goes wrong.
[ "Process", "the", "expression", "by", "implementing", "PHP", "core", "s", "implode", "function", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/custom/Implode.php#L51-L78
oat-sa/qti-sdk
src/qtism/runtime/expressions/operators/AnyNProcessor.php
AnyNProcessor.process
public function process() { $operands = $this->getOperands(); // Retrieve the values of min and max. $min = $this->getExpression()->getMin(); $max = $this->getExpression()->getMax(); // @todo write a generic method to retrieve variable references. if (is_string($min) === true) { // variable reference for 'min' to handle. $state = $this->getState(); $varName = Utils::sanitizeVariableRef($min); $varValue = $state[$varName]; if (is_null($varValue)) { $msg = "The variable with name '${varName}' could not be resolved or is null."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::NONEXISTENT_VARIABLE); } elseif (!$varValue instanceof QtiInteger) { $msg = "The variable with name '${varName}' is not an integer."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE); } else { $min = $varValue->getValue(); } } if (is_string($max) === true) { // variable reference for 'max' to handle. $state = $this->getState(); $varName = Utils::sanitizeVariableRef($max); $varValue = $state[$varName]; if (is_null($varValue)) { $msg = "The variable with name '${varName}' could not be resolved or is null."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::NONEXISTENT_VARIABLE); } elseif (!$varValue instanceof QtiInteger) { $msg = "The variable with name '${varName}' is not an integer."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_VARIABLE_BASETYPE); } else { $max = $varValue->getValue(); } } $nullCount = 0; $trueCount = 0; foreach ($operands as $operand) { if (is_null($operand)) { $nullCount++; continue; } elseif ($operand instanceof QtiBoolean) { if ($operand->getValue() === true) { $trueCount++; } } else { // Not null, not a boolean, we have a problem... $msg = "The AnyN operator only accepts values with cardinality single and baseType boolean."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE_OR_CARDINALITY); } } if ($trueCount >= $min && $trueCount <= $max) { return new QtiBoolean(true); } else { // Should we return false or null? if ($trueCount + $nullCount >= $min && $trueCount + $nullCount <= $max) { // It could have match if nulls were true values. return null; } else { return new QtiBoolean(false); } } }
php
public function process() { $operands = $this->getOperands(); // Retrieve the values of min and max. $min = $this->getExpression()->getMin(); $max = $this->getExpression()->getMax(); // @todo write a generic method to retrieve variable references. if (is_string($min) === true) { // variable reference for 'min' to handle. $state = $this->getState(); $varName = Utils::sanitizeVariableRef($min); $varValue = $state[$varName]; if (is_null($varValue)) { $msg = "The variable with name '${varName}' could not be resolved or is null."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::NONEXISTENT_VARIABLE); } elseif (!$varValue instanceof QtiInteger) { $msg = "The variable with name '${varName}' is not an integer."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE); } else { $min = $varValue->getValue(); } } if (is_string($max) === true) { // variable reference for 'max' to handle. $state = $this->getState(); $varName = Utils::sanitizeVariableRef($max); $varValue = $state[$varName]; if (is_null($varValue)) { $msg = "The variable with name '${varName}' could not be resolved or is null."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::NONEXISTENT_VARIABLE); } elseif (!$varValue instanceof QtiInteger) { $msg = "The variable with name '${varName}' is not an integer."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_VARIABLE_BASETYPE); } else { $max = $varValue->getValue(); } } $nullCount = 0; $trueCount = 0; foreach ($operands as $operand) { if (is_null($operand)) { $nullCount++; continue; } elseif ($operand instanceof QtiBoolean) { if ($operand->getValue() === true) { $trueCount++; } } else { // Not null, not a boolean, we have a problem... $msg = "The AnyN operator only accepts values with cardinality single and baseType boolean."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE_OR_CARDINALITY); } } if ($trueCount >= $min && $trueCount <= $max) { return new QtiBoolean(true); } else { // Should we return false or null? if ($trueCount + $nullCount >= $min && $trueCount + $nullCount <= $max) { // It could have match if nulls were true values. return null; } else { return new QtiBoolean(false); } } }
[ "public", "function", "process", "(", ")", "{", "$", "operands", "=", "$", "this", "->", "getOperands", "(", ")", ";", "// Retrieve the values of min and max.", "$", "min", "=", "$", "this", "->", "getExpression", "(", ")", "->", "getMin", "(", ")", ";", "$", "max", "=", "$", "this", "->", "getExpression", "(", ")", "->", "getMax", "(", ")", ";", "// @todo write a generic method to retrieve variable references.", "if", "(", "is_string", "(", "$", "min", ")", "===", "true", ")", "{", "// variable reference for 'min' to handle.", "$", "state", "=", "$", "this", "->", "getState", "(", ")", ";", "$", "varName", "=", "Utils", "::", "sanitizeVariableRef", "(", "$", "min", ")", ";", "$", "varValue", "=", "$", "state", "[", "$", "varName", "]", ";", "if", "(", "is_null", "(", "$", "varValue", ")", ")", "{", "$", "msg", "=", "\"The variable with name '${varName}' could not be resolved or is null.\"", ";", "throw", "new", "OperatorProcessingException", "(", "$", "msg", ",", "$", "this", ",", "OperatorProcessingException", "::", "NONEXISTENT_VARIABLE", ")", ";", "}", "elseif", "(", "!", "$", "varValue", "instanceof", "QtiInteger", ")", "{", "$", "msg", "=", "\"The variable with name '${varName}' is not an integer.\"", ";", "throw", "new", "OperatorProcessingException", "(", "$", "msg", ",", "$", "this", ",", "OperatorProcessingException", "::", "WRONG_BASETYPE", ")", ";", "}", "else", "{", "$", "min", "=", "$", "varValue", "->", "getValue", "(", ")", ";", "}", "}", "if", "(", "is_string", "(", "$", "max", ")", "===", "true", ")", "{", "// variable reference for 'max' to handle.", "$", "state", "=", "$", "this", "->", "getState", "(", ")", ";", "$", "varName", "=", "Utils", "::", "sanitizeVariableRef", "(", "$", "max", ")", ";", "$", "varValue", "=", "$", "state", "[", "$", "varName", "]", ";", "if", "(", "is_null", "(", "$", "varValue", ")", ")", "{", "$", "msg", "=", "\"The variable with name '${varName}' could not be resolved or is null.\"", ";", "throw", "new", "OperatorProcessingException", "(", "$", "msg", ",", "$", "this", ",", "OperatorProcessingException", "::", "NONEXISTENT_VARIABLE", ")", ";", "}", "elseif", "(", "!", "$", "varValue", "instanceof", "QtiInteger", ")", "{", "$", "msg", "=", "\"The variable with name '${varName}' is not an integer.\"", ";", "throw", "new", "OperatorProcessingException", "(", "$", "msg", ",", "$", "this", ",", "OperatorProcessingException", "::", "WRONG_VARIABLE_BASETYPE", ")", ";", "}", "else", "{", "$", "max", "=", "$", "varValue", "->", "getValue", "(", ")", ";", "}", "}", "$", "nullCount", "=", "0", ";", "$", "trueCount", "=", "0", ";", "foreach", "(", "$", "operands", "as", "$", "operand", ")", "{", "if", "(", "is_null", "(", "$", "operand", ")", ")", "{", "$", "nullCount", "++", ";", "continue", ";", "}", "elseif", "(", "$", "operand", "instanceof", "QtiBoolean", ")", "{", "if", "(", "$", "operand", "->", "getValue", "(", ")", "===", "true", ")", "{", "$", "trueCount", "++", ";", "}", "}", "else", "{", "// Not null, not a boolean, we have a problem...", "$", "msg", "=", "\"The AnyN operator only accepts values with cardinality single and baseType boolean.\"", ";", "throw", "new", "OperatorProcessingException", "(", "$", "msg", ",", "$", "this", ",", "OperatorProcessingException", "::", "WRONG_BASETYPE_OR_CARDINALITY", ")", ";", "}", "}", "if", "(", "$", "trueCount", ">=", "$", "min", "&&", "$", "trueCount", "<=", "$", "max", ")", "{", "return", "new", "QtiBoolean", "(", "true", ")", ";", "}", "else", "{", "// Should we return false or null?", "if", "(", "$", "trueCount", "+", "$", "nullCount", ">=", "$", "min", "&&", "$", "trueCount", "+", "$", "nullCount", "<=", "$", "max", ")", "{", "// It could have match if nulls were true values.", "return", "null", ";", "}", "else", "{", "return", "new", "QtiBoolean", "(", "false", ")", ";", "}", "}", "}" ]
Process the AnyN processor. @return boolean|null A boolean value of true if at least min of the sub-expressions are true and at most max of the sub-expressions are true. NULL is returned if the correct value for the operator cannot be determined. @throws \qtism\runtime\expressions\operators\OperatorProcessingException
[ "Process", "the", "AnyN", "processor", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/AnyNProcessor.php#L61-L134
oat-sa/qti-sdk
src/qtism/data/storage/xml/marshalling/AreaMapEntryMarshaller.php
AreaMapEntryMarshaller.marshall
protected function marshall(QtiComponent $component) { $element = static::getDOMCradle()->createElement($component->getQtiClassName()); $this->setDOMElementAttribute($element, 'shape', QtiShape::getNameByConstant($component->getShape())); $this->setDOMElementAttribute($element, 'coords', $component->getCoords()); $this->setDOMElementAttribute($element, 'mappedValue', $component->getMappedValue()); return $element; }
php
protected function marshall(QtiComponent $component) { $element = static::getDOMCradle()->createElement($component->getQtiClassName()); $this->setDOMElementAttribute($element, 'shape', QtiShape::getNameByConstant($component->getShape())); $this->setDOMElementAttribute($element, 'coords', $component->getCoords()); $this->setDOMElementAttribute($element, 'mappedValue', $component->getMappedValue()); return $element; }
[ "protected", "function", "marshall", "(", "QtiComponent", "$", "component", ")", "{", "$", "element", "=", "static", "::", "getDOMCradle", "(", ")", "->", "createElement", "(", "$", "component", "->", "getQtiClassName", "(", ")", ")", ";", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'shape'", ",", "QtiShape", "::", "getNameByConstant", "(", "$", "component", "->", "getShape", "(", ")", ")", ")", ";", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'coords'", ",", "$", "component", "->", "getCoords", "(", ")", ")", ";", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'mappedValue'", ",", "$", "component", "->", "getMappedValue", "(", ")", ")", ";", "return", "$", "element", ";", "}" ]
Marshall an AreaMapEntry object into a DOMElement object. @param \qtism\data\QtiComponent $component An AreaMapEntry object. @return \DOMElement The according DOMElement object.
[ "Marshall", "an", "AreaMapEntry", "object", "into", "a", "DOMElement", "object", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/AreaMapEntryMarshaller.php#L46-L55
oat-sa/qti-sdk
src/qtism/data/storage/xml/marshalling/AreaMapEntryMarshaller.php
AreaMapEntryMarshaller.unmarshall
protected function unmarshall(DOMElement $element) { if (($shape = $this->getDOMElementAttributeAs($element, 'shape')) !== null) { $shapeVal = QtiShape::getConstantByName($shape); if ($shapeVal !== false) { if (($coords = $this->getDOMElementAttributeAs($element, 'coords')) !== null) { try { $coords = Utils::stringToCoords($coords, $shapeVal); if (($mappedValue = $this->getDOMElementAttributeAs($element, 'mappedValue', 'float')) !== null) { return new AreaMapEntry($shapeVal, $coords, $mappedValue); } else { $msg = "The mandatory attribute 'mappedValue' is missing from element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element); } } catch (Exception $e) { if (!$e instanceof UnmarshallingException) { $msg = "The attribute 'coords' with value '${coords}' has an invalid value."; throw new UnmarshallingException($msg, $element, $e); } else { throw $e; } } } else { $msg = "The mandatory attribute 'coords' is missing from element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element); } } else { $msg = "The 'shape' attribute value '${shape}' is not a valid value to represent QTI shapes."; throw new UnmarshallingException($msg, $element); } } else { $msg = "The mandatory attribute 'shape' is missing from element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element); } }
php
protected function unmarshall(DOMElement $element) { if (($shape = $this->getDOMElementAttributeAs($element, 'shape')) !== null) { $shapeVal = QtiShape::getConstantByName($shape); if ($shapeVal !== false) { if (($coords = $this->getDOMElementAttributeAs($element, 'coords')) !== null) { try { $coords = Utils::stringToCoords($coords, $shapeVal); if (($mappedValue = $this->getDOMElementAttributeAs($element, 'mappedValue', 'float')) !== null) { return new AreaMapEntry($shapeVal, $coords, $mappedValue); } else { $msg = "The mandatory attribute 'mappedValue' is missing from element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element); } } catch (Exception $e) { if (!$e instanceof UnmarshallingException) { $msg = "The attribute 'coords' with value '${coords}' has an invalid value."; throw new UnmarshallingException($msg, $element, $e); } else { throw $e; } } } else { $msg = "The mandatory attribute 'coords' is missing from element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element); } } else { $msg = "The 'shape' attribute value '${shape}' is not a valid value to represent QTI shapes."; throw new UnmarshallingException($msg, $element); } } else { $msg = "The mandatory attribute 'shape' is missing from element '" . $element->localName . "'."; throw new UnmarshallingException($msg, $element); } }
[ "protected", "function", "unmarshall", "(", "DOMElement", "$", "element", ")", "{", "if", "(", "(", "$", "shape", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'shape'", ")", ")", "!==", "null", ")", "{", "$", "shapeVal", "=", "QtiShape", "::", "getConstantByName", "(", "$", "shape", ")", ";", "if", "(", "$", "shapeVal", "!==", "false", ")", "{", "if", "(", "(", "$", "coords", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'coords'", ")", ")", "!==", "null", ")", "{", "try", "{", "$", "coords", "=", "Utils", "::", "stringToCoords", "(", "$", "coords", ",", "$", "shapeVal", ")", ";", "if", "(", "(", "$", "mappedValue", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'mappedValue'", ",", "'float'", ")", ")", "!==", "null", ")", "{", "return", "new", "AreaMapEntry", "(", "$", "shapeVal", ",", "$", "coords", ",", "$", "mappedValue", ")", ";", "}", "else", "{", "$", "msg", "=", "\"The mandatory attribute 'mappedValue' is missing from element '\"", ".", "$", "element", "->", "localName", ".", "\"'.\"", ";", "throw", "new", "UnmarshallingException", "(", "$", "msg", ",", "$", "element", ")", ";", "}", "}", "catch", "(", "Exception", "$", "e", ")", "{", "if", "(", "!", "$", "e", "instanceof", "UnmarshallingException", ")", "{", "$", "msg", "=", "\"The attribute 'coords' with value '${coords}' has an invalid value.\"", ";", "throw", "new", "UnmarshallingException", "(", "$", "msg", ",", "$", "element", ",", "$", "e", ")", ";", "}", "else", "{", "throw", "$", "e", ";", "}", "}", "}", "else", "{", "$", "msg", "=", "\"The mandatory attribute 'coords' is missing from element '\"", ".", "$", "element", "->", "localName", ".", "\"'.\"", ";", "throw", "new", "UnmarshallingException", "(", "$", "msg", ",", "$", "element", ")", ";", "}", "}", "else", "{", "$", "msg", "=", "\"The 'shape' attribute value '${shape}' is not a valid value to represent QTI shapes.\"", ";", "throw", "new", "UnmarshallingException", "(", "$", "msg", ",", "$", "element", ")", ";", "}", "}", "else", "{", "$", "msg", "=", "\"The mandatory attribute 'shape' is missing from element '\"", ".", "$", "element", "->", "localName", ".", "\"'.\"", ";", "throw", "new", "UnmarshallingException", "(", "$", "msg", ",", "$", "element", ")", ";", "}", "}" ]
Unmarshall a DOMElement object corresponding to a QTI areaMapEntry element. @param \DOMElement $element A DOMElement object. @return \qtism\data\QtiComponent An AreaMapEntry object. @throws \qtism\data\storage\xml\marshalling\UnmarshallingException
[ "Unmarshall", "a", "DOMElement", "object", "corresponding", "to", "a", "QTI", "areaMapEntry", "element", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/AreaMapEntryMarshaller.php#L64-L104
oat-sa/qti-sdk
src/qtism/data/content/xhtml/A.php
A.setHref
public function setHref($href) { if (Format::isUri($href) === true) { $this->href = $href; } else { $msg = "The 'href' argument must be a URI, '" . $href . "' given."; throw new InvalidArgumentException($msg); } }
php
public function setHref($href) { if (Format::isUri($href) === true) { $this->href = $href; } else { $msg = "The 'href' argument must be a URI, '" . $href . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setHref", "(", "$", "href", ")", "{", "if", "(", "Format", "::", "isUri", "(", "$", "href", ")", "===", "true", ")", "{", "$", "this", "->", "href", "=", "$", "href", ";", "}", "else", "{", "$", "msg", "=", "\"The 'href' argument must be a URI, '\"", ".", "$", "href", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set the href attribute. @param string $href A URI (Uniform Resource Identifier). @throws InvalidArgumentException If $href is not a URI.
[ "Set", "the", "href", "attribute", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/xhtml/A.php#L79-L87
oat-sa/qti-sdk
src/qtism/data/content/xhtml/A.php
A.setType
public function setType($type) { if (is_string($type) === true) { $this->type = $type; } else { $msg = "The 'type' argument must be a non-empty string representing a mime-type, '" . gettype($type) . "' given."; throw new InvalidArgumentException($msg); } }
php
public function setType($type) { if (is_string($type) === true) { $this->type = $type; } else { $msg = "The 'type' argument must be a non-empty string representing a mime-type, '" . gettype($type) . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setType", "(", "$", "type", ")", "{", "if", "(", "is_string", "(", "$", "type", ")", "===", "true", ")", "{", "$", "this", "->", "type", "=", "$", "type", ";", "}", "else", "{", "$", "msg", "=", "\"The 'type' argument must be a non-empty string representing a mime-type, '\"", ".", "gettype", "(", "$", "type", ")", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set the type attribute (mime-type). Give an empty string to indicate there is no mime-type. @param string $type A mime-type. @throws InvalidArgumentException If $type is not a string value.
[ "Set", "the", "type", "attribute", "(", "mime", "-", "type", ")", ".", "Give", "an", "empty", "string", "to", "indicate", "there", "is", "no", "mime", "-", "type", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/xhtml/A.php#L106-L114
oat-sa/qti-sdk
src/qtism/data/storage/xml/marshalling/GapMarshaller.php
GapMarshaller.marshall
protected function marshall(QtiComponent $component) { $version = $this->getVersion(); $element = $this->createElement($component); $this->setDOMElementAttribute($element, 'identifier', $component->getIdentifier()); if ($component->isFixed() === true) { $this->setDOMElementAttribute($element, 'fixed' , true); } if (Version::compare($version, '2.1.0', '>=') === true && $component->hasTemplateIdentifier() === true) { $this->setDOMElementAttribute($element, 'templateIdentifier', $component->getTemplateIdentifier()); } if (Version::compare($version, '2.1.0', '>=') === true && $component->getShowHide() === ShowHide::HIDE) { $this->setDOMElementAttribute($element, 'showHide', ShowHide::getNameByConstant(ShowHide::HIDE)); } if (Version::compare($version, '2.1.0', '>=') === true && $component->isRequired() === true) { $this->setDOMElementAttribute($element, 'required', true); } if (Version::compare($version, '2.1.0', '<') === true) { $matchGroup = $component->getMatchGroup(); if (count($matchGroup) > 0) { $this->setDOMElementAttribute($element, 'matchGroup', implode(' ', $matchGroup->getArrayCopy())); } } $this->fillElement($element, $component); return $element; }
php
protected function marshall(QtiComponent $component) { $version = $this->getVersion(); $element = $this->createElement($component); $this->setDOMElementAttribute($element, 'identifier', $component->getIdentifier()); if ($component->isFixed() === true) { $this->setDOMElementAttribute($element, 'fixed' , true); } if (Version::compare($version, '2.1.0', '>=') === true && $component->hasTemplateIdentifier() === true) { $this->setDOMElementAttribute($element, 'templateIdentifier', $component->getTemplateIdentifier()); } if (Version::compare($version, '2.1.0', '>=') === true && $component->getShowHide() === ShowHide::HIDE) { $this->setDOMElementAttribute($element, 'showHide', ShowHide::getNameByConstant(ShowHide::HIDE)); } if (Version::compare($version, '2.1.0', '>=') === true && $component->isRequired() === true) { $this->setDOMElementAttribute($element, 'required', true); } if (Version::compare($version, '2.1.0', '<') === true) { $matchGroup = $component->getMatchGroup(); if (count($matchGroup) > 0) { $this->setDOMElementAttribute($element, 'matchGroup', implode(' ', $matchGroup->getArrayCopy())); } } $this->fillElement($element, $component); return $element; }
[ "protected", "function", "marshall", "(", "QtiComponent", "$", "component", ")", "{", "$", "version", "=", "$", "this", "->", "getVersion", "(", ")", ";", "$", "element", "=", "$", "this", "->", "createElement", "(", "$", "component", ")", ";", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'identifier'", ",", "$", "component", "->", "getIdentifier", "(", ")", ")", ";", "if", "(", "$", "component", "->", "isFixed", "(", ")", "===", "true", ")", "{", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'fixed'", ",", "true", ")", ";", "}", "if", "(", "Version", "::", "compare", "(", "$", "version", ",", "'2.1.0'", ",", "'>='", ")", "===", "true", "&&", "$", "component", "->", "hasTemplateIdentifier", "(", ")", "===", "true", ")", "{", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'templateIdentifier'", ",", "$", "component", "->", "getTemplateIdentifier", "(", ")", ")", ";", "}", "if", "(", "Version", "::", "compare", "(", "$", "version", ",", "'2.1.0'", ",", "'>='", ")", "===", "true", "&&", "$", "component", "->", "getShowHide", "(", ")", "===", "ShowHide", "::", "HIDE", ")", "{", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'showHide'", ",", "ShowHide", "::", "getNameByConstant", "(", "ShowHide", "::", "HIDE", ")", ")", ";", "}", "if", "(", "Version", "::", "compare", "(", "$", "version", ",", "'2.1.0'", ",", "'>='", ")", "===", "true", "&&", "$", "component", "->", "isRequired", "(", ")", "===", "true", ")", "{", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'required'", ",", "true", ")", ";", "}", "if", "(", "Version", "::", "compare", "(", "$", "version", ",", "'2.1.0'", ",", "'<'", ")", "===", "true", ")", "{", "$", "matchGroup", "=", "$", "component", "->", "getMatchGroup", "(", ")", ";", "if", "(", "count", "(", "$", "matchGroup", ")", ">", "0", ")", "{", "$", "this", "->", "setDOMElementAttribute", "(", "$", "element", ",", "'matchGroup'", ",", "implode", "(", "' '", ",", "$", "matchGroup", "->", "getArrayCopy", "(", ")", ")", ")", ";", "}", "}", "$", "this", "->", "fillElement", "(", "$", "element", ",", "$", "component", ")", ";", "return", "$", "element", ";", "}" ]
Marshall a Gap object into a DOMElement object. @param \qtism\data\QtiComponent $component A Gap object. @return \DOMElement The according DOMElement object. @throws \qtism\data\storage\xml\marshalling\MarshallingException
[ "Marshall", "a", "Gap", "object", "into", "a", "DOMElement", "object", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/GapMarshaller.php#L47-L79
oat-sa/qti-sdk
src/qtism/data/storage/xml/marshalling/GapMarshaller.php
GapMarshaller.unmarshall
protected function unmarshall(DOMElement $element) { $version = $this->getVersion(); if (($identifier = $this->getDOMElementAttributeAs($element, 'identifier')) !== null) { $component = new Gap($identifier); if (($fixed = $this->getDOMElementAttributeAs($element, 'fixed', 'boolean')) !== null) { $component->setFixed($fixed); } if (Version::compare($version, '2.1.0', '>=') === true && ($templateIdentifier = $this->getDOMElementAttributeAs($element, 'templateIdentifier')) !== null) { $component->setTemplateIdentifier($templateIdentifier); } if (Version::compare($version, '2.1.0', '>=') === true && ($showHide = $this->getDOMElementAttributeAs($element, 'showHide')) !== null) { $component->setShowHide(ShowHide::getConstantByName($showHide)); } if (Version::compare($version, '2.1.0', '>=') === true && ($required = $this->getDOMElementAttributeAs($element, 'required', 'boolean')) !== null) { $component->setRequired($required); } if (Version::compare($version, '2.1.0', '<') === true && ($matchGroup = $this->getDOMElementAttributeAs($element, 'matchGroup')) !== null) { $component->setMatchGroup(new IdentifierCollection(explode("\x20", $matchGroup))); } $this->fillBodyElement($component, $element); return $component; } else { $msg = "The mandatory 'identifier' attribute is missing from the 'gap' element."; throw new UnmarshallingException($msg, $element); } }
php
protected function unmarshall(DOMElement $element) { $version = $this->getVersion(); if (($identifier = $this->getDOMElementAttributeAs($element, 'identifier')) !== null) { $component = new Gap($identifier); if (($fixed = $this->getDOMElementAttributeAs($element, 'fixed', 'boolean')) !== null) { $component->setFixed($fixed); } if (Version::compare($version, '2.1.0', '>=') === true && ($templateIdentifier = $this->getDOMElementAttributeAs($element, 'templateIdentifier')) !== null) { $component->setTemplateIdentifier($templateIdentifier); } if (Version::compare($version, '2.1.0', '>=') === true && ($showHide = $this->getDOMElementAttributeAs($element, 'showHide')) !== null) { $component->setShowHide(ShowHide::getConstantByName($showHide)); } if (Version::compare($version, '2.1.0', '>=') === true && ($required = $this->getDOMElementAttributeAs($element, 'required', 'boolean')) !== null) { $component->setRequired($required); } if (Version::compare($version, '2.1.0', '<') === true && ($matchGroup = $this->getDOMElementAttributeAs($element, 'matchGroup')) !== null) { $component->setMatchGroup(new IdentifierCollection(explode("\x20", $matchGroup))); } $this->fillBodyElement($component, $element); return $component; } else { $msg = "The mandatory 'identifier' attribute is missing from the 'gap' element."; throw new UnmarshallingException($msg, $element); } }
[ "protected", "function", "unmarshall", "(", "DOMElement", "$", "element", ")", "{", "$", "version", "=", "$", "this", "->", "getVersion", "(", ")", ";", "if", "(", "(", "$", "identifier", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'identifier'", ")", ")", "!==", "null", ")", "{", "$", "component", "=", "new", "Gap", "(", "$", "identifier", ")", ";", "if", "(", "(", "$", "fixed", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'fixed'", ",", "'boolean'", ")", ")", "!==", "null", ")", "{", "$", "component", "->", "setFixed", "(", "$", "fixed", ")", ";", "}", "if", "(", "Version", "::", "compare", "(", "$", "version", ",", "'2.1.0'", ",", "'>='", ")", "===", "true", "&&", "(", "$", "templateIdentifier", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'templateIdentifier'", ")", ")", "!==", "null", ")", "{", "$", "component", "->", "setTemplateIdentifier", "(", "$", "templateIdentifier", ")", ";", "}", "if", "(", "Version", "::", "compare", "(", "$", "version", ",", "'2.1.0'", ",", "'>='", ")", "===", "true", "&&", "(", "$", "showHide", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'showHide'", ")", ")", "!==", "null", ")", "{", "$", "component", "->", "setShowHide", "(", "ShowHide", "::", "getConstantByName", "(", "$", "showHide", ")", ")", ";", "}", "if", "(", "Version", "::", "compare", "(", "$", "version", ",", "'2.1.0'", ",", "'>='", ")", "===", "true", "&&", "(", "$", "required", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'required'", ",", "'boolean'", ")", ")", "!==", "null", ")", "{", "$", "component", "->", "setRequired", "(", "$", "required", ")", ";", "}", "if", "(", "Version", "::", "compare", "(", "$", "version", ",", "'2.1.0'", ",", "'<'", ")", "===", "true", "&&", "(", "$", "matchGroup", "=", "$", "this", "->", "getDOMElementAttributeAs", "(", "$", "element", ",", "'matchGroup'", ")", ")", "!==", "null", ")", "{", "$", "component", "->", "setMatchGroup", "(", "new", "IdentifierCollection", "(", "explode", "(", "\"\\x20\"", ",", "$", "matchGroup", ")", ")", ")", ";", "}", "$", "this", "->", "fillBodyElement", "(", "$", "component", ",", "$", "element", ")", ";", "return", "$", "component", ";", "}", "else", "{", "$", "msg", "=", "\"The mandatory 'identifier' attribute is missing from the 'gap' element.\"", ";", "throw", "new", "UnmarshallingException", "(", "$", "msg", ",", "$", "element", ")", ";", "}", "}" ]
Unmarshall a DOMElement object corresponding to an XHTML gap element. @param \DOMElement $element A DOMElement object. @return \qtism\data\QtiComponent A Gap object. @throws \qtism\data\storage\xml\marshalling\UnmarshallingException
[ "Unmarshall", "a", "DOMElement", "object", "corresponding", "to", "an", "XHTML", "gap", "element", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/GapMarshaller.php#L88-L123
oat-sa/qti-sdk
src/qtism/runtime/rules/RuleProcessor.php
RuleProcessor.setRule
public function setRule(Rule $rule) { $expectedType = $this->getRuleType(); if (Reflection::isInstanceOf($rule, $expectedType) === true) { $this->rule = $rule; } else { $procClass = get_class($this); $givenType = get_class($rule); $msg = "The ${procClass} Rule Processor only processes ${expectedType} Rule objects, ${givenType} given."; throw new InvalidArgumentException($msg); } }
php
public function setRule(Rule $rule) { $expectedType = $this->getRuleType(); if (Reflection::isInstanceOf($rule, $expectedType) === true) { $this->rule = $rule; } else { $procClass = get_class($this); $givenType = get_class($rule); $msg = "The ${procClass} Rule Processor only processes ${expectedType} Rule objects, ${givenType} given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setRule", "(", "Rule", "$", "rule", ")", "{", "$", "expectedType", "=", "$", "this", "->", "getRuleType", "(", ")", ";", "if", "(", "Reflection", "::", "isInstanceOf", "(", "$", "rule", ",", "$", "expectedType", ")", "===", "true", ")", "{", "$", "this", "->", "rule", "=", "$", "rule", ";", "}", "else", "{", "$", "procClass", "=", "get_class", "(", "$", "this", ")", ";", "$", "givenType", "=", "get_class", "(", "$", "rule", ")", ";", "$", "msg", "=", "\"The ${procClass} Rule Processor only processes ${expectedType} Rule objects, ${givenType} given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set the QTI Data Model Rule object to be processed. @param \qtism\runtime\rules\Rule $rule @throws \InvalidArgumentException If $rule is not compliant with the rule processor implementation.
[ "Set", "the", "QTI", "Data", "Model", "Rule", "object", "to", "be", "processed", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rules/RuleProcessor.php#L77-L89
oat-sa/qti-sdk
src/qtism/common/storage/MemoryStream.php
MemoryStream.open
public function open() { if ($this->isOpen() === true) { $msg = "The MemoryStream is already open."; throw new MemoryStreamException($msg, $this, MemoryStreamException::ALREADY_OPEN); } $this->setOpen(true); }
php
public function open() { if ($this->isOpen() === true) { $msg = "The MemoryStream is already open."; throw new MemoryStreamException($msg, $this, MemoryStreamException::ALREADY_OPEN); } $this->setOpen(true); }
[ "public", "function", "open", "(", ")", "{", "if", "(", "$", "this", "->", "isOpen", "(", ")", "===", "true", ")", "{", "$", "msg", "=", "\"The MemoryStream is already open.\"", ";", "throw", "new", "MemoryStreamException", "(", "$", "msg", ",", "$", "this", ",", "MemoryStreamException", "::", "ALREADY_OPEN", ")", ";", "}", "$", "this", "->", "setOpen", "(", "true", ")", ";", "}" ]
Open the binary stream. @throws \qtism\common\storage\MemoryStreamException If the stream is already opened.
[ "Open", "the", "binary", "stream", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/storage/MemoryStream.php#L147-L155
oat-sa/qti-sdk
src/qtism/common/storage/MemoryStream.php
MemoryStream.close
public function close() { if ($this->isOpen() === false) { $msg = "Cannot call close() a closed stream."; throw new MemoryStreamException($msg, $this, MemoryStreamException::NOT_OPEN); } $this->setOpen(false); }
php
public function close() { if ($this->isOpen() === false) { $msg = "Cannot call close() a closed stream."; throw new MemoryStreamException($msg, $this, MemoryStreamException::NOT_OPEN); } $this->setOpen(false); }
[ "public", "function", "close", "(", ")", "{", "if", "(", "$", "this", "->", "isOpen", "(", ")", "===", "false", ")", "{", "$", "msg", "=", "\"Cannot call close() a closed stream.\"", ";", "throw", "new", "MemoryStreamException", "(", "$", "msg", ",", "$", "this", ",", "MemoryStreamException", "::", "NOT_OPEN", ")", ";", "}", "$", "this", "->", "setOpen", "(", "false", ")", ";", "}" ]
Close the binary stream. @throws \qtism\common\storage\MemoryStreamException If the stream is closed prior the call.
[ "Close", "the", "binary", "stream", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/storage/MemoryStream.php#L162-L170
oat-sa/qti-sdk
src/qtism/common/storage/MemoryStream.php
MemoryStream.read
public function read($length) { if ($this->isOpen() === false) { $msg = "Cannot read from a closed MemoryStream."; throw new MemoryStreamAccess($msg, $this, MemoryStreamException::NOT_OPEN); } if ($length === 0) { return ''; } $position = $this->position; $finalPosition = $position + $length; if ($finalPosition > $this->length) { $msg = "Cannot read outside the bounds of the MemoryStream."; throw new MemoryStreamException($msg, $this, MemoryStreamException::READ); } $this->incrementPosition($length); $returnValue = ''; while ($position < $finalPosition) { $returnValue .= $this->binary[$position]; $position++; } return $returnValue; }
php
public function read($length) { if ($this->isOpen() === false) { $msg = "Cannot read from a closed MemoryStream."; throw new MemoryStreamAccess($msg, $this, MemoryStreamException::NOT_OPEN); } if ($length === 0) { return ''; } $position = $this->position; $finalPosition = $position + $length; if ($finalPosition > $this->length) { $msg = "Cannot read outside the bounds of the MemoryStream."; throw new MemoryStreamException($msg, $this, MemoryStreamException::READ); } $this->incrementPosition($length); $returnValue = ''; while ($position < $finalPosition) { $returnValue .= $this->binary[$position]; $position++; } return $returnValue; }
[ "public", "function", "read", "(", "$", "length", ")", "{", "if", "(", "$", "this", "->", "isOpen", "(", ")", "===", "false", ")", "{", "$", "msg", "=", "\"Cannot read from a closed MemoryStream.\"", ";", "throw", "new", "MemoryStreamAccess", "(", "$", "msg", ",", "$", "this", ",", "MemoryStreamException", "::", "NOT_OPEN", ")", ";", "}", "if", "(", "$", "length", "===", "0", ")", "{", "return", "''", ";", "}", "$", "position", "=", "$", "this", "->", "position", ";", "$", "finalPosition", "=", "$", "position", "+", "$", "length", ";", "if", "(", "$", "finalPosition", ">", "$", "this", "->", "length", ")", "{", "$", "msg", "=", "\"Cannot read outside the bounds of the MemoryStream.\"", ";", "throw", "new", "MemoryStreamException", "(", "$", "msg", ",", "$", "this", ",", "MemoryStreamException", "::", "READ", ")", ";", "}", "$", "this", "->", "incrementPosition", "(", "$", "length", ")", ";", "$", "returnValue", "=", "''", ";", "while", "(", "$", "position", "<", "$", "finalPosition", ")", "{", "$", "returnValue", ".=", "$", "this", "->", "binary", "[", "$", "position", "]", ";", "$", "position", "++", ";", "}", "return", "$", "returnValue", ";", "}" ]
Read $length bytes from the MemoryStream. @throws \qtism\common\storage\MemoryStreamException If the read is out of the bounds of the stream e.g. EOF reach. @return string The read value or an empty string if length = 0.
[ "Read", "$length", "bytes", "from", "the", "MemoryStream", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/storage/MemoryStream.php#L178-L207
oat-sa/qti-sdk
src/qtism/common/storage/MemoryStream.php
MemoryStream.write
public function write($data) { if ($this->isOpen() === false) { $msg = "Cannot write in a closed MemoryStream."; throw new MemoryStreamException($msg, $this, MemoryStreamException::NOT_OPEN); } if ($this->length - 1 === $this->position) { // simply append. $this->binary .= $data; } elseif ($this->position === 0) { // simply prepend. $this->binary = ($data . $this->binary); } else { // we are in the middle of the string. $part1 = substr($this->binary, 0, $this->position); $part2 = substr($this->binary, $this->position); $this->binary = ($part1 . $data . $part2); } $dataLen = strlen($data); $this->incrementPosition($dataLen); $this->incrementLength($dataLen); return $dataLen; }
php
public function write($data) { if ($this->isOpen() === false) { $msg = "Cannot write in a closed MemoryStream."; throw new MemoryStreamException($msg, $this, MemoryStreamException::NOT_OPEN); } if ($this->length - 1 === $this->position) { // simply append. $this->binary .= $data; } elseif ($this->position === 0) { // simply prepend. $this->binary = ($data . $this->binary); } else { // we are in the middle of the string. $part1 = substr($this->binary, 0, $this->position); $part2 = substr($this->binary, $this->position); $this->binary = ($part1 . $data . $part2); } $dataLen = strlen($data); $this->incrementPosition($dataLen); $this->incrementLength($dataLen); return $dataLen; }
[ "public", "function", "write", "(", "$", "data", ")", "{", "if", "(", "$", "this", "->", "isOpen", "(", ")", "===", "false", ")", "{", "$", "msg", "=", "\"Cannot write in a closed MemoryStream.\"", ";", "throw", "new", "MemoryStreamException", "(", "$", "msg", ",", "$", "this", ",", "MemoryStreamException", "::", "NOT_OPEN", ")", ";", "}", "if", "(", "$", "this", "->", "length", "-", "1", "===", "$", "this", "->", "position", ")", "{", "// simply append.", "$", "this", "->", "binary", ".=", "$", "data", ";", "}", "elseif", "(", "$", "this", "->", "position", "===", "0", ")", "{", "// simply prepend.", "$", "this", "->", "binary", "=", "(", "$", "data", ".", "$", "this", "->", "binary", ")", ";", "}", "else", "{", "// we are in the middle of the string.", "$", "part1", "=", "substr", "(", "$", "this", "->", "binary", ",", "0", ",", "$", "this", "->", "position", ")", ";", "$", "part2", "=", "substr", "(", "$", "this", "->", "binary", ",", "$", "this", "->", "position", ")", ";", "$", "this", "->", "binary", "=", "(", "$", "part1", ".", "$", "data", ".", "$", "part2", ")", ";", "}", "$", "dataLen", "=", "strlen", "(", "$", "data", ")", ";", "$", "this", "->", "incrementPosition", "(", "$", "dataLen", ")", ";", "$", "this", "->", "incrementLength", "(", "$", "dataLen", ")", ";", "return", "$", "dataLen", ";", "}" ]
Write some $data in the stream. @param string $data
[ "Write", "some", "$data", "in", "the", "stream", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/storage/MemoryStream.php#L214-L239
oat-sa/qti-sdk
src/qtism/common/storage/MemoryStream.php
MemoryStream.rewind
public function rewind() { if ($this->isOpen() === false) { $msg = "Cannot call rewind() on a closed MemoryStream."; throw new MemoryStreamException($msg, $this, MemoryStreamException::NOT_OPEN); } $this->setPosition(0); }
php
public function rewind() { if ($this->isOpen() === false) { $msg = "Cannot call rewind() on a closed MemoryStream."; throw new MemoryStreamException($msg, $this, MemoryStreamException::NOT_OPEN); } $this->setPosition(0); }
[ "public", "function", "rewind", "(", ")", "{", "if", "(", "$", "this", "->", "isOpen", "(", ")", "===", "false", ")", "{", "$", "msg", "=", "\"Cannot call rewind() on a closed MemoryStream.\"", ";", "throw", "new", "MemoryStreamException", "(", "$", "msg", ",", "$", "this", ",", "MemoryStreamException", "::", "NOT_OPEN", ")", ";", "}", "$", "this", "->", "setPosition", "(", "0", ")", ";", "}" ]
Rewind the stream to its initial position. @throws \qtism\common\storage\MemoryStreamException If the binary stream is not open.
[ "Rewind", "the", "stream", "to", "its", "initial", "position", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/storage/MemoryStream.php#L266-L274
oat-sa/qti-sdk
src/qtism/common/storage/MemoryStream.php
MemoryStream.flush
public function flush() { if ($this->isOpen() === true) { $this->setBinary(''); $this->rewind(); } else { $msg = "Cannot flush a closed MemoryStream."; throw new MemoryStreamException($msg, $this, MemoryStreamException::NOT_OPEN); } }
php
public function flush() { if ($this->isOpen() === true) { $this->setBinary(''); $this->rewind(); } else { $msg = "Cannot flush a closed MemoryStream."; throw new MemoryStreamException($msg, $this, MemoryStreamException::NOT_OPEN); } }
[ "public", "function", "flush", "(", ")", "{", "if", "(", "$", "this", "->", "isOpen", "(", ")", "===", "true", ")", "{", "$", "this", "->", "setBinary", "(", "''", ")", ";", "$", "this", "->", "rewind", "(", ")", ";", "}", "else", "{", "$", "msg", "=", "\"Cannot flush a closed MemoryStream.\"", ";", "throw", "new", "MemoryStreamException", "(", "$", "msg", ",", "$", "this", ",", "MemoryStreamException", "::", "NOT_OPEN", ")", ";", "}", "}" ]
Flush the whole stream. @throws \qtism\common\storage\MemoryStreamException If the binary stream is closed.
[ "Flush", "the", "whole", "stream", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/storage/MemoryStream.php#L291-L300
oat-sa/qti-sdk
src/qtism/runtime/expressions/operators/EqualRoundedProcessor.php
EqualRoundedProcessor.process
public function process() { $operands = $this->getOperands(); if ($operands->containsNull()) { return null; } if ($operands->exclusivelySingle() === false) { $msg = "The EqualRounded operator only accepts operands with a single cardinality."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY); } if ($operands->exclusivelyNumeric() === false) { $msg = "The EqualRounded operator only accepts operands with an integer or float baseType."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE); } // delegate the rounding to the RoundTo operator. $expression = $this->getExpression(); $roundingMode = $expression->getRoundingMode(); $figures = $expression->getFigures(); if (gettype($figures) === 'string') { // Variable reference to deal with. $state = $this->getState(); $varName = Utils::sanitizeVariableRef($figures); $varValue = $state[$varName]; if (is_null($varValue) === true) { $msg = "The variable with name '${varName}' could not be resolved."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::NONEXISTENT_VARIABLE); } elseif (!$varValue instanceof QtiInteger) { $msg = "The variable with name '${varName}' is not an integer."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_VARIABLE_BASETYPE); } $figures = $varValue->getValue(); } $rounded = new OperandsCollection(); // will contain the rounded operands. foreach ($operands as $operand) { $baseType = RuntimeUtils::inferBaseType($operand); $subExpression = new BaseValue($baseType, $operand); $roundToExpression = new RoundTo(new ExpressionCollection(array($subExpression)), $figures, $roundingMode); $roundToProcessor = new RoundToProcessor($roundToExpression, new OperandsCollection(array($operand))); try { $rounded[] = $roundToProcessor->process(); } catch (OperatorProcessingException $e) { $msg = "An error occured while rounding '${operand}'."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::LOGIC_ERROR, $e); } } return new QtiBoolean($rounded[0]->getValue() == $rounded[1]->getValue()); }
php
public function process() { $operands = $this->getOperands(); if ($operands->containsNull()) { return null; } if ($operands->exclusivelySingle() === false) { $msg = "The EqualRounded operator only accepts operands with a single cardinality."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY); } if ($operands->exclusivelyNumeric() === false) { $msg = "The EqualRounded operator only accepts operands with an integer or float baseType."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE); } // delegate the rounding to the RoundTo operator. $expression = $this->getExpression(); $roundingMode = $expression->getRoundingMode(); $figures = $expression->getFigures(); if (gettype($figures) === 'string') { // Variable reference to deal with. $state = $this->getState(); $varName = Utils::sanitizeVariableRef($figures); $varValue = $state[$varName]; if (is_null($varValue) === true) { $msg = "The variable with name '${varName}' could not be resolved."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::NONEXISTENT_VARIABLE); } elseif (!$varValue instanceof QtiInteger) { $msg = "The variable with name '${varName}' is not an integer."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_VARIABLE_BASETYPE); } $figures = $varValue->getValue(); } $rounded = new OperandsCollection(); // will contain the rounded operands. foreach ($operands as $operand) { $baseType = RuntimeUtils::inferBaseType($operand); $subExpression = new BaseValue($baseType, $operand); $roundToExpression = new RoundTo(new ExpressionCollection(array($subExpression)), $figures, $roundingMode); $roundToProcessor = new RoundToProcessor($roundToExpression, new OperandsCollection(array($operand))); try { $rounded[] = $roundToProcessor->process(); } catch (OperatorProcessingException $e) { $msg = "An error occured while rounding '${operand}'."; throw new OperatorProcessingException($msg, $this, OperatorProcessingException::LOGIC_ERROR, $e); } } return new QtiBoolean($rounded[0]->getValue() == $rounded[1]->getValue()); }
[ "public", "function", "process", "(", ")", "{", "$", "operands", "=", "$", "this", "->", "getOperands", "(", ")", ";", "if", "(", "$", "operands", "->", "containsNull", "(", ")", ")", "{", "return", "null", ";", "}", "if", "(", "$", "operands", "->", "exclusivelySingle", "(", ")", "===", "false", ")", "{", "$", "msg", "=", "\"The EqualRounded operator only accepts operands with a single cardinality.\"", ";", "throw", "new", "OperatorProcessingException", "(", "$", "msg", ",", "$", "this", ",", "OperatorProcessingException", "::", "WRONG_CARDINALITY", ")", ";", "}", "if", "(", "$", "operands", "->", "exclusivelyNumeric", "(", ")", "===", "false", ")", "{", "$", "msg", "=", "\"The EqualRounded operator only accepts operands with an integer or float baseType.\"", ";", "throw", "new", "OperatorProcessingException", "(", "$", "msg", ",", "$", "this", ",", "OperatorProcessingException", "::", "WRONG_BASETYPE", ")", ";", "}", "// delegate the rounding to the RoundTo operator.", "$", "expression", "=", "$", "this", "->", "getExpression", "(", ")", ";", "$", "roundingMode", "=", "$", "expression", "->", "getRoundingMode", "(", ")", ";", "$", "figures", "=", "$", "expression", "->", "getFigures", "(", ")", ";", "if", "(", "gettype", "(", "$", "figures", ")", "===", "'string'", ")", "{", "// Variable reference to deal with.", "$", "state", "=", "$", "this", "->", "getState", "(", ")", ";", "$", "varName", "=", "Utils", "::", "sanitizeVariableRef", "(", "$", "figures", ")", ";", "$", "varValue", "=", "$", "state", "[", "$", "varName", "]", ";", "if", "(", "is_null", "(", "$", "varValue", ")", "===", "true", ")", "{", "$", "msg", "=", "\"The variable with name '${varName}' could not be resolved.\"", ";", "throw", "new", "OperatorProcessingException", "(", "$", "msg", ",", "$", "this", ",", "OperatorProcessingException", "::", "NONEXISTENT_VARIABLE", ")", ";", "}", "elseif", "(", "!", "$", "varValue", "instanceof", "QtiInteger", ")", "{", "$", "msg", "=", "\"The variable with name '${varName}' is not an integer.\"", ";", "throw", "new", "OperatorProcessingException", "(", "$", "msg", ",", "$", "this", ",", "OperatorProcessingException", "::", "WRONG_VARIABLE_BASETYPE", ")", ";", "}", "$", "figures", "=", "$", "varValue", "->", "getValue", "(", ")", ";", "}", "$", "rounded", "=", "new", "OperandsCollection", "(", ")", ";", "// will contain the rounded operands.", "foreach", "(", "$", "operands", "as", "$", "operand", ")", "{", "$", "baseType", "=", "RuntimeUtils", "::", "inferBaseType", "(", "$", "operand", ")", ";", "$", "subExpression", "=", "new", "BaseValue", "(", "$", "baseType", ",", "$", "operand", ")", ";", "$", "roundToExpression", "=", "new", "RoundTo", "(", "new", "ExpressionCollection", "(", "array", "(", "$", "subExpression", ")", ")", ",", "$", "figures", ",", "$", "roundingMode", ")", ";", "$", "roundToProcessor", "=", "new", "RoundToProcessor", "(", "$", "roundToExpression", ",", "new", "OperandsCollection", "(", "array", "(", "$", "operand", ")", ")", ")", ";", "try", "{", "$", "rounded", "[", "]", "=", "$", "roundToProcessor", "->", "process", "(", ")", ";", "}", "catch", "(", "OperatorProcessingException", "$", "e", ")", "{", "$", "msg", "=", "\"An error occured while rounding '${operand}'.\"", ";", "throw", "new", "OperatorProcessingException", "(", "$", "msg", ",", "$", "this", ",", "OperatorProcessingException", "::", "LOGIC_ERROR", ",", "$", "e", ")", ";", "}", "}", "return", "new", "QtiBoolean", "(", "$", "rounded", "[", "0", "]", "->", "getValue", "(", ")", "==", "$", "rounded", "[", "1", "]", "->", "getValue", "(", ")", ")", ";", "}" ]
Process the EqualRounded operator. @return boolean|null A boolean with a value of true if the two expressions are numerically equal after rounding and false if they are not. If either sub-expression is NULL, the operator results in NULL. @throws \qtism\runtime\expressions\operators\OperatorProcessingException
[ "Process", "the", "EqualRounded", "operator", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/expressions/operators/EqualRoundedProcessor.php#L69-L126
oat-sa/qti-sdk
src/qtism/data/storage/xml/marshalling/MarshallerFactory.php
MarshallerFactory.addMappingEntry
public function addMappingEntry($qtiClassName, $marshallerClassName, $ns = 'qtism') { $mapping = &$this->getMapping(); $mapping[$ns][$qtiClassName] = $marshallerClassName; }
php
public function addMappingEntry($qtiClassName, $marshallerClassName, $ns = 'qtism') { $mapping = &$this->getMapping(); $mapping[$ns][$qtiClassName] = $marshallerClassName; }
[ "public", "function", "addMappingEntry", "(", "$", "qtiClassName", ",", "$", "marshallerClassName", ",", "$", "ns", "=", "'qtism'", ")", "{", "$", "mapping", "=", "&", "$", "this", "->", "getMapping", "(", ")", ";", "$", "mapping", "[", "$", "ns", "]", "[", "$", "qtiClassName", "]", "=", "$", "marshallerClassName", ";", "}" ]
Add a mapping entry for a given tuple $qtiClassName <-> $marshallerClassName. @param string $qtiClassName A QTI class name. @param string $marshallerClassName A PHP marshaller class name (fully qualified). @param string $ns
[ "Add", "a", "mapping", "entry", "for", "a", "given", "tuple", "$qtiClassName", "<", "-", ">", "$marshallerClassName", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/MarshallerFactory.php#L314-L318
oat-sa/qti-sdk
src/qtism/data/storage/xml/marshalling/MarshallerFactory.php
MarshallerFactory.hasMappingEntry
public function hasMappingEntry($qtiClassName, $ns = 'qtism') { $mapping = &$this->getMapping(); return isset($mapping[$ns]) && isset($mapping[$ns][$qtiClassName]); }
php
public function hasMappingEntry($qtiClassName, $ns = 'qtism') { $mapping = &$this->getMapping(); return isset($mapping[$ns]) && isset($mapping[$ns][$qtiClassName]); }
[ "public", "function", "hasMappingEntry", "(", "$", "qtiClassName", ",", "$", "ns", "=", "'qtism'", ")", "{", "$", "mapping", "=", "&", "$", "this", "->", "getMapping", "(", ")", ";", "return", "isset", "(", "$", "mapping", "[", "$", "ns", "]", ")", "&&", "isset", "(", "$", "mapping", "[", "$", "ns", "]", "[", "$", "qtiClassName", "]", ")", ";", "}" ]
Whether a mapping entry is defined for a given $qtiClassName. @param string $qtiClassName A QTI class name. @param string $ns @return boolean Whether a mapping entry is defined.
[ "Whether", "a", "mapping", "entry", "is", "defined", "for", "a", "given", "$qtiClassName", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/MarshallerFactory.php#L327-L332
oat-sa/qti-sdk
src/qtism/data/storage/xml/marshalling/MarshallerFactory.php
MarshallerFactory.removeMappingEntry
public function removeMappingEntry($qtiClassName, $ns = 'qtism') { $mapping = &$this->getMapping(); if ($this->hasMappingEntry($qtiClassName, $ns)) { unset($mapping[$ns][$qtiClassName]); } }
php
public function removeMappingEntry($qtiClassName, $ns = 'qtism') { $mapping = &$this->getMapping(); if ($this->hasMappingEntry($qtiClassName, $ns)) { unset($mapping[$ns][$qtiClassName]); } }
[ "public", "function", "removeMappingEntry", "(", "$", "qtiClassName", ",", "$", "ns", "=", "'qtism'", ")", "{", "$", "mapping", "=", "&", "$", "this", "->", "getMapping", "(", ")", ";", "if", "(", "$", "this", "->", "hasMappingEntry", "(", "$", "qtiClassName", ",", "$", "ns", ")", ")", "{", "unset", "(", "$", "mapping", "[", "$", "ns", "]", "[", "$", "qtiClassName", "]", ")", ";", "}", "}" ]
Remove a mapping for $qtiClassName. @param string $qtiClassName A QTI class name. @param string $ns
[ "Remove", "a", "mapping", "for", "$qtiClassName", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/MarshallerFactory.php#L354-L361
oat-sa/qti-sdk
src/qtism/data/storage/xml/marshalling/MarshallerFactory.php
MarshallerFactory.createMarshaller
public function createMarshaller($object, array $args = array()) { if ($object instanceof QtiComponent) { // Asking for a Marshaller... $qtiClassName = $object->getQtiClassName(); if ($this->isWebComponentFriendly() === true && in_array($qtiClassName, Marshaller::$webComponentFriendlyClasses)) { $qtiClassName = XmlUtils::webComponentFriendlyClassName($qtiClassName); } } elseif ($object instanceof DOMElement) { // Asking for an Unmarshaller... $qtiClassName = $object->localName; } if (isset($qtiClassName)) { try { // Look for a mapping entry. if ($object instanceof DOMElement && $this->hasMappingEntry($qtiClassName, $object->namespaceURI)) { $class = new ReflectionClass($this->getMappingEntry($qtiClassName, $object->namespaceURI)); } elseif ($object instanceof ExternalQtiComponent && $this->hasMappingEntry($qtiClassName, $object->getTargetNamespace())) { $class = new ReflectionClass($this->getMappingEntry($qtiClassName, $object->getTargetNamespace())); } elseif ($this->hasMappingEntry($qtiClassName)) { $class = new ReflectionClass($this->getMappingEntry($qtiClassName)); } else { // No qtiClassName/mapping entry found. $msg ="No mapping entry found for QTI class name '${qtiClassName}'."; throw new MarshallerNotFoundException($msg, $qtiClassName); } } catch (ReflectionException $e) { $msg = "No marshaller implementation could be found for component '${qtiClassName}'."; throw new MarshallerNotFoundException($msg, $qtiClassName, $e); } $marshaller = $this->instantiateMarshaller($class, $args); $marshaller->setMarshallerFactory($this); return $marshaller; } else { $msg = "The object argument must be a QtiComponent or a DOMElementObject, '" . gettype($object) . "' given."; throw new InvalidArgumentException($msg); } }
php
public function createMarshaller($object, array $args = array()) { if ($object instanceof QtiComponent) { // Asking for a Marshaller... $qtiClassName = $object->getQtiClassName(); if ($this->isWebComponentFriendly() === true && in_array($qtiClassName, Marshaller::$webComponentFriendlyClasses)) { $qtiClassName = XmlUtils::webComponentFriendlyClassName($qtiClassName); } } elseif ($object instanceof DOMElement) { // Asking for an Unmarshaller... $qtiClassName = $object->localName; } if (isset($qtiClassName)) { try { // Look for a mapping entry. if ($object instanceof DOMElement && $this->hasMappingEntry($qtiClassName, $object->namespaceURI)) { $class = new ReflectionClass($this->getMappingEntry($qtiClassName, $object->namespaceURI)); } elseif ($object instanceof ExternalQtiComponent && $this->hasMappingEntry($qtiClassName, $object->getTargetNamespace())) { $class = new ReflectionClass($this->getMappingEntry($qtiClassName, $object->getTargetNamespace())); } elseif ($this->hasMappingEntry($qtiClassName)) { $class = new ReflectionClass($this->getMappingEntry($qtiClassName)); } else { // No qtiClassName/mapping entry found. $msg ="No mapping entry found for QTI class name '${qtiClassName}'."; throw new MarshallerNotFoundException($msg, $qtiClassName); } } catch (ReflectionException $e) { $msg = "No marshaller implementation could be found for component '${qtiClassName}'."; throw new MarshallerNotFoundException($msg, $qtiClassName, $e); } $marshaller = $this->instantiateMarshaller($class, $args); $marshaller->setMarshallerFactory($this); return $marshaller; } else { $msg = "The object argument must be a QtiComponent or a DOMElementObject, '" . gettype($object) . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "createMarshaller", "(", "$", "object", ",", "array", "$", "args", "=", "array", "(", ")", ")", "{", "if", "(", "$", "object", "instanceof", "QtiComponent", ")", "{", "// Asking for a Marshaller...", "$", "qtiClassName", "=", "$", "object", "->", "getQtiClassName", "(", ")", ";", "if", "(", "$", "this", "->", "isWebComponentFriendly", "(", ")", "===", "true", "&&", "in_array", "(", "$", "qtiClassName", ",", "Marshaller", "::", "$", "webComponentFriendlyClasses", ")", ")", "{", "$", "qtiClassName", "=", "XmlUtils", "::", "webComponentFriendlyClassName", "(", "$", "qtiClassName", ")", ";", "}", "}", "elseif", "(", "$", "object", "instanceof", "DOMElement", ")", "{", "// Asking for an Unmarshaller...", "$", "qtiClassName", "=", "$", "object", "->", "localName", ";", "}", "if", "(", "isset", "(", "$", "qtiClassName", ")", ")", "{", "try", "{", "// Look for a mapping entry.", "if", "(", "$", "object", "instanceof", "DOMElement", "&&", "$", "this", "->", "hasMappingEntry", "(", "$", "qtiClassName", ",", "$", "object", "->", "namespaceURI", ")", ")", "{", "$", "class", "=", "new", "ReflectionClass", "(", "$", "this", "->", "getMappingEntry", "(", "$", "qtiClassName", ",", "$", "object", "->", "namespaceURI", ")", ")", ";", "}", "elseif", "(", "$", "object", "instanceof", "ExternalQtiComponent", "&&", "$", "this", "->", "hasMappingEntry", "(", "$", "qtiClassName", ",", "$", "object", "->", "getTargetNamespace", "(", ")", ")", ")", "{", "$", "class", "=", "new", "ReflectionClass", "(", "$", "this", "->", "getMappingEntry", "(", "$", "qtiClassName", ",", "$", "object", "->", "getTargetNamespace", "(", ")", ")", ")", ";", "}", "elseif", "(", "$", "this", "->", "hasMappingEntry", "(", "$", "qtiClassName", ")", ")", "{", "$", "class", "=", "new", "ReflectionClass", "(", "$", "this", "->", "getMappingEntry", "(", "$", "qtiClassName", ")", ")", ";", "}", "else", "{", "// No qtiClassName/mapping entry found.", "$", "msg", "=", "\"No mapping entry found for QTI class name '${qtiClassName}'.\"", ";", "throw", "new", "MarshallerNotFoundException", "(", "$", "msg", ",", "$", "qtiClassName", ")", ";", "}", "}", "catch", "(", "ReflectionException", "$", "e", ")", "{", "$", "msg", "=", "\"No marshaller implementation could be found for component '${qtiClassName}'.\"", ";", "throw", "new", "MarshallerNotFoundException", "(", "$", "msg", ",", "$", "qtiClassName", ",", "$", "e", ")", ";", "}", "$", "marshaller", "=", "$", "this", "->", "instantiateMarshaller", "(", "$", "class", ",", "$", "args", ")", ";", "$", "marshaller", "->", "setMarshallerFactory", "(", "$", "this", ")", ";", "return", "$", "marshaller", ";", "}", "else", "{", "$", "msg", "=", "\"The object argument must be a QtiComponent or a DOMElementObject, '\"", ".", "gettype", "(", "$", "object", ")", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Create a marshaller for a given QtiComponent or DOMElement object, depending on the current mapping of the MarshallerFactory. If no mapping entry can be found, the factory will perform a ultimate trial in the qtism\\data\\storage\\xml\\marshalling namespace to find the relevant Marshaller object. The newly created marshaller will be set up with the MarshallerFactory itself as its MarshallerFactory object (yes, we know, this is highly recursive but necessary x)). @param \DOMElement|\qtism\data\QtiComponent $object A QtiComponent or DOMElement object you want to get the corresponding Marshaller object. @param array $args An optional array of arguments to be passed to the Marshaller constructor. @throws \InvalidArgumentException If $object is not a QtiComponent nor a DOMElement object. @throws \RuntimeException If no Marshaller object can be created for the given $object. @throws \qtism\data\storage\xml\marshalling\MarshallerNotFoundException If no Marshaller mapping is set for a given $object. @return \qtism\data\storage\xml\marshalling\Marshaller The corresponding Marshaller object.
[ "Create", "a", "marshaller", "for", "a", "given", "QtiComponent", "or", "DOMElement", "object", "depending", "on", "the", "current", "mapping", "of", "the", "MarshallerFactory", ".", "If", "no", "mapping", "entry", "can", "be", "found", "the", "factory", "will", "perform", "a", "ultimate", "trial", "in", "the", "qtism", "\\\\", "data", "\\\\", "storage", "\\\\", "xml", "\\\\", "marshalling", "namespace", "to", "find", "the", "relevant", "Marshaller", "object", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/storage/xml/marshalling/MarshallerFactory.php#L402-L445
oat-sa/qti-sdk
src/qtism/runtime/rendering/css/Utils.php
Utils.mapSelector
public static function mapSelector($selector, array $map) { foreach ($map as $k => $v) { $pattern = "/(?:(^|\s|\+|,|~|>)(${k})(\$|\s|,|\+|\.|\~|>|:|\[))/u"; $count = 1; while ($count > 0) { $selector = preg_replace($pattern, '$1.' . $v . '$3', $selector, -1, $count); } } return $selector; }
php
public static function mapSelector($selector, array $map) { foreach ($map as $k => $v) { $pattern = "/(?:(^|\s|\+|,|~|>)(${k})(\$|\s|,|\+|\.|\~|>|:|\[))/u"; $count = 1; while ($count > 0) { $selector = preg_replace($pattern, '$1.' . $v . '$3', $selector, -1, $count); } } return $selector; }
[ "public", "static", "function", "mapSelector", "(", "$", "selector", ",", "array", "$", "map", ")", "{", "foreach", "(", "$", "map", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "pattern", "=", "\"/(?:(^|\\s|\\+|,|~|>)(${k})(\\$|\\s|,|\\+|\\.|\\~|>|:|\\[))/u\"", ";", "$", "count", "=", "1", ";", "while", "(", "$", "count", ">", "0", ")", "{", "$", "selector", "=", "preg_replace", "(", "$", "pattern", ",", "'$1.'", ".", "$", "v", ".", "'$3'", ",", "$", "selector", ",", "-", "1", ",", "$", "count", ")", ";", "}", "}", "return", "$", "selector", ";", "}" ]
Remap a given CSS selector following the $map array. Example: <code> $map = array('prompt' => 'qti-prompt', 'div' => 'qti-div'); $selector = 'div > prompt'; echo Utils::mapSelector($selector, $map); // .qti-div > .qti-prompt </code> @param string $selector A Cascading Style Sheet selector. @param array $map A QTI to XHTML CSS class map. @param array @return string
[ "Remap", "a", "given", "CSS", "selector", "following", "the", "$map", "array", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/runtime/rendering/css/Utils.php#L51-L64
oat-sa/qti-sdk
src/qtism/common/utils/Php.php
Php.displayType
static public function displayType($value) { if (is_null($value) === true) { return 'null'; } elseif (is_object($value) === true) { return get_class($value); } else { return 'php:' . gettype($value); } }
php
static public function displayType($value) { if (is_null($value) === true) { return 'null'; } elseif (is_object($value) === true) { return get_class($value); } else { return 'php:' . gettype($value); } }
[ "static", "public", "function", "displayType", "(", "$", "value", ")", "{", "if", "(", "is_null", "(", "$", "value", ")", "===", "true", ")", "{", "return", "'null'", ";", "}", "elseif", "(", "is_object", "(", "$", "value", ")", "===", "true", ")", "{", "return", "get_class", "(", "$", "value", ")", ";", "}", "else", "{", "return", "'php:'", ".", "gettype", "(", "$", "value", ")", ";", "}", "}" ]
Returns a displayable datatype for any $value. Example: echo Php::displayType(null); echo Php::displayType(12); echo Php::displayType(12.1); echo Php::displayType(new stdClass()); // null // php:integer // php:double // stdClass @param mixed $value @return string
[ "Returns", "a", "displayable", "datatype", "for", "any", "$value", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/common/utils/Php.php#L43-L52
oat-sa/qti-sdk
src/qtism/data/content/interactions/HottextInteraction.php
HottextInteraction.setMinChoices
public function setMinChoices($minChoices) { if (is_int($minChoices) && $minChoices > 0) { if ($minChoices > $this->getMaxChoices() && $this->getMaxChoices() > 0) { $msg = "The 'minChoices' argument must respect the limits imposed by 'maxChoices'."; throw new InvalidArgumentException($msg); } else { $this->minChoices = $minChoices; } } elseif (is_int($minChoices) && $minChoices === 0) { $this->minChoices = $minChoices; } else { $msg = "The 'minChoices' argument must be a positive (>= 0) integer value, '" . gettype($minChoices) . "' given."; throw new InvalidArgumentException($msg); } }
php
public function setMinChoices($minChoices) { if (is_int($minChoices) && $minChoices > 0) { if ($minChoices > $this->getMaxChoices() && $this->getMaxChoices() > 0) { $msg = "The 'minChoices' argument must respect the limits imposed by 'maxChoices'."; throw new InvalidArgumentException($msg); } else { $this->minChoices = $minChoices; } } elseif (is_int($minChoices) && $minChoices === 0) { $this->minChoices = $minChoices; } else { $msg = "The 'minChoices' argument must be a positive (>= 0) integer value, '" . gettype($minChoices) . "' given."; throw new InvalidArgumentException($msg); } }
[ "public", "function", "setMinChoices", "(", "$", "minChoices", ")", "{", "if", "(", "is_int", "(", "$", "minChoices", ")", "&&", "$", "minChoices", ">", "0", ")", "{", "if", "(", "$", "minChoices", ">", "$", "this", "->", "getMaxChoices", "(", ")", "&&", "$", "this", "->", "getMaxChoices", "(", ")", ">", "0", ")", "{", "$", "msg", "=", "\"The 'minChoices' argument must respect the limits imposed by 'maxChoices'.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "else", "{", "$", "this", "->", "minChoices", "=", "$", "minChoices", ";", "}", "}", "elseif", "(", "is_int", "(", "$", "minChoices", ")", "&&", "$", "minChoices", "===", "0", ")", "{", "$", "this", "->", "minChoices", "=", "$", "minChoices", ";", "}", "else", "{", "$", "msg", "=", "\"The 'minChoices' argument must be a positive (>= 0) integer value, '\"", ".", "gettype", "(", "$", "minChoices", ")", ".", "\"' given.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$", "msg", ")", ";", "}", "}" ]
Set the minimum number of choices that the candidate is required to select to form a valid response. @param integer $minChoices A positive (>= 0) integer. @throws \InvalidArgumentException If $minChoices is not a positive integer or does not respect the limits imposed by maxChoices.
[ "Set", "the", "minimum", "number", "of", "choices", "that", "the", "candidate", "is", "required", "to", "select", "to", "form", "a", "valid", "response", "." ]
train
https://github.com/oat-sa/qti-sdk/blob/fc3568d2a293ae6dbfe9f400dad2b94a0033ddb2/src/qtism/data/content/interactions/HottextInteraction.php#L137-L153