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/extension-tao-itemqti | model/qti/IdentifiedElement.php | IdentifiedElement.getIdentifier | public function getIdentifier($generate = true){
if(empty($this->identifier) && $generate){
//try generating an identifier
$relatedItem = $this->getRelatedItem();
if(!is_null($relatedItem)){
$this->identifier = $this->generateIdentifier();
}
}
return (string) $this->identifier;
} | php | public function getIdentifier($generate = true){
if(empty($this->identifier) && $generate){
//try generating an identifier
$relatedItem = $this->getRelatedItem();
if(!is_null($relatedItem)){
$this->identifier = $this->generateIdentifier();
}
}
return (string) $this->identifier;
} | [
"public",
"function",
"getIdentifier",
"(",
"$",
"generate",
"=",
"true",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"identifier",
")",
"&&",
"$",
"generate",
")",
"{",
"//try generating an identifier",
"$",
"relatedItem",
"=",
"$",
"this",
"->"... | get the identifier
@access public
@author Sam, <sam@taotesting.com>
@return string | [
"get",
"the",
"identifier"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/IdentifiedElement.php#L77-L86 |
oat-sa/extension-tao-itemqti | model/qti/IdentifiedElement.php | IdentifiedElement.setIdentifier | public function setIdentifier($identifier, $collisionFree = false){
$returnValue = false;
if(empty($identifier) || is_null($identifier)){
common_Logger::w('ss');
throw new \InvalidArgumentException("Id must not be empty");
}
if($this->isIdentifierAvailable($identifier)){
$returnValue = true;
}else{
if($collisionFree){
$identifier = $this->generateIdentifier($identifier);
$returnValue = true;
}else{
$relatedItem = $this->getRelatedItem();
if(!is_null($relatedItem)){
$identifiedElements = $relatedItem->getIdentifiedElements();
}
common_Logger::w("Tried to set non unique identifier ".$identifier, array('TAOITEMS', 'QTI'));
throw new \InvalidArgumentException("The identifier \"{$identifier}\" is already in use");
}
}
if($returnValue){
$this->identifier = $identifier;
}
return $returnValue;
} | php | public function setIdentifier($identifier, $collisionFree = false){
$returnValue = false;
if(empty($identifier) || is_null($identifier)){
common_Logger::w('ss');
throw new \InvalidArgumentException("Id must not be empty");
}
if($this->isIdentifierAvailable($identifier)){
$returnValue = true;
}else{
if($collisionFree){
$identifier = $this->generateIdentifier($identifier);
$returnValue = true;
}else{
$relatedItem = $this->getRelatedItem();
if(!is_null($relatedItem)){
$identifiedElements = $relatedItem->getIdentifiedElements();
}
common_Logger::w("Tried to set non unique identifier ".$identifier, array('TAOITEMS', 'QTI'));
throw new \InvalidArgumentException("The identifier \"{$identifier}\" is already in use");
}
}
if($returnValue){
$this->identifier = $identifier;
}
return $returnValue;
} | [
"public",
"function",
"setIdentifier",
"(",
"$",
"identifier",
",",
"$",
"collisionFree",
"=",
"false",
")",
"{",
"$",
"returnValue",
"=",
"false",
";",
"if",
"(",
"empty",
"(",
"$",
"identifier",
")",
"||",
"is_null",
"(",
"$",
"identifier",
")",
")",
... | Set a unique identifier.
If the identifier is already given to another qti element in the same item an InvalidArgumentException is thrown.
The option collisionFree allows to ensure that a new identifier is generated if a collision happens
@access public
@author Sam, <sam@taotesting.com>
@param string id
@return boolean | [
"Set",
"a",
"unique",
"identifier",
".",
"If",
"the",
"identifier",
"is",
"already",
"given",
"to",
"another",
"qti",
"element",
"in",
"the",
"same",
"item",
"an",
"InvalidArgumentException",
"is",
"thrown",
".",
"The",
"option",
"collisionFree",
"allows",
"to... | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/IdentifiedElement.php#L119-L148 |
oat-sa/extension-tao-itemqti | model/qti/IdentifiedElement.php | IdentifiedElement.validateCurrentIdentifier | public function validateCurrentIdentifier($collisionFree = false){
$returnValue = false;
if(empty($this->identifier)){
//empty identifier, nothing to check
$returnValue = true;
}else{
$returnValue = $this->setIdentifier($this->identifier, $collisionFree);
}
return $returnValue;
} | php | public function validateCurrentIdentifier($collisionFree = false){
$returnValue = false;
if(empty($this->identifier)){
//empty identifier, nothing to check
$returnValue = true;
}else{
$returnValue = $this->setIdentifier($this->identifier, $collisionFree);
}
return $returnValue;
} | [
"public",
"function",
"validateCurrentIdentifier",
"(",
"$",
"collisionFree",
"=",
"false",
")",
"{",
"$",
"returnValue",
"=",
"false",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"identifier",
")",
")",
"{",
"//empty identifier, nothing to check",
"$",
"... | Validate if the current identifier of the qti element does not collide with another one's
CollisionFree option allows to ensure that no collision subsides after the fonction call.
It indeed ensures that that the identifier becomes unique if it collides with another one's.
@param boolean $collisionFree
@return boolean | [
"Validate",
"if",
"the",
"current",
"identifier",
"of",
"the",
"qti",
"element",
"does",
"not",
"collide",
"with",
"another",
"one",
"s",
"CollisionFree",
"option",
"allows",
"to",
"ensure",
"that",
"no",
"collision",
"subsides",
"after",
"the",
"fonction",
"c... | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/IdentifiedElement.php#L158-L170 |
oat-sa/extension-tao-itemqti | model/qti/IdentifiedElement.php | IdentifiedElement.isIdentifierAvailable | public function isIdentifierAvailable($newIdentifier){
$returnValue = false;
if(empty($newIdentifier) || is_null($newIdentifier)){
throw new InvalidArgumentException("newIdentifier must be set");
}
if(!empty($this->identifier) && $newIdentifier == $this->identifier){
$returnValue = true;
}else{
$relatedItem = $this->getRelatedItem();
if(is_null($relatedItem)){
$returnValue = true; //no restriction on identifier since not attached to any qti item
}else{
$idCollection = $relatedItem->getIdentifiedElements();
$returnValue = !$idCollection->exists($newIdentifier);
}
}
return $returnValue;
} | php | public function isIdentifierAvailable($newIdentifier){
$returnValue = false;
if(empty($newIdentifier) || is_null($newIdentifier)){
throw new InvalidArgumentException("newIdentifier must be set");
}
if(!empty($this->identifier) && $newIdentifier == $this->identifier){
$returnValue = true;
}else{
$relatedItem = $this->getRelatedItem();
if(is_null($relatedItem)){
$returnValue = true; //no restriction on identifier since not attached to any qti item
}else{
$idCollection = $relatedItem->getIdentifiedElements();
$returnValue = !$idCollection->exists($newIdentifier);
}
}
return $returnValue;
} | [
"public",
"function",
"isIdentifierAvailable",
"(",
"$",
"newIdentifier",
")",
"{",
"$",
"returnValue",
"=",
"false",
";",
"if",
"(",
"empty",
"(",
"$",
"newIdentifier",
")",
"||",
"is_null",
"(",
"$",
"newIdentifier",
")",
")",
"{",
"throw",
"new",
"Inval... | Check if the given new identifier is valid in the current state of the qti element
@param string $newIdentifier
@return boolean
@throws InvalidArgumentException | [
"Check",
"if",
"the",
"given",
"new",
"identifier",
"is",
"valid",
"in",
"the",
"current",
"state",
"of",
"the",
"qti",
"element"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/IdentifiedElement.php#L179-L200 |
oat-sa/extension-tao-itemqti | model/qti/IdentifiedElement.php | IdentifiedElement.generateIdentifier | protected function generateIdentifier($prefix = ''){
$relatedItem = $this->getRelatedItem();
if(is_null($relatedItem)){
throw new QtiModelException('cannot generate the identifier because the element does not belong to any item');
}
$identifiedElementsCollection = $relatedItem->getIdentifiedElements();
$index = 1;
$suffix = '';
if(empty($prefix)){
$clazz = get_class($this);
if(preg_match('/[A-Z]{1}[a-z]*$/', $clazz, $matches)){
$prefix = $matches[0];
}else{
$prefix = substr($clazz, strripos($clazz, '_')+1);
}
$suffix = '_'.$index;
}else{
$prefix = preg_replace('/_[0-9]+$/', '_', $prefix); //detect incremental id of type choice_12, response_3, etc.
$prefix = preg_replace('/[^a-zA-Z0-9_]/', '_', $prefix);
$prefix = preg_replace('/(_)+/', '_', $prefix);
}
do{
$exist = false;
$id = $prefix.$suffix;
if($identifiedElementsCollection->exists($id)){
$exist = true;
$suffix = '_'.$index;
$index++;
}
} while($exist);
return $id;
} | php | protected function generateIdentifier($prefix = ''){
$relatedItem = $this->getRelatedItem();
if(is_null($relatedItem)){
throw new QtiModelException('cannot generate the identifier because the element does not belong to any item');
}
$identifiedElementsCollection = $relatedItem->getIdentifiedElements();
$index = 1;
$suffix = '';
if(empty($prefix)){
$clazz = get_class($this);
if(preg_match('/[A-Z]{1}[a-z]*$/', $clazz, $matches)){
$prefix = $matches[0];
}else{
$prefix = substr($clazz, strripos($clazz, '_')+1);
}
$suffix = '_'.$index;
}else{
$prefix = preg_replace('/_[0-9]+$/', '_', $prefix); //detect incremental id of type choice_12, response_3, etc.
$prefix = preg_replace('/[^a-zA-Z0-9_]/', '_', $prefix);
$prefix = preg_replace('/(_)+/', '_', $prefix);
}
do{
$exist = false;
$id = $prefix.$suffix;
if($identifiedElementsCollection->exists($id)){
$exist = true;
$suffix = '_'.$index;
$index++;
}
} while($exist);
return $id;
} | [
"protected",
"function",
"generateIdentifier",
"(",
"$",
"prefix",
"=",
"''",
")",
"{",
"$",
"relatedItem",
"=",
"$",
"this",
"->",
"getRelatedItem",
"(",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"relatedItem",
")",
")",
"{",
"throw",
"new",
"QtiModelEx... | Create a unique identifier, based on the class if the qti element.
@access protected
@author Sam, <sam@taotesting.com>
@param string $prefix
@return mixed
@throws QtiModelException | [
"Create",
"a",
"unique",
"identifier",
"based",
"on",
"the",
"class",
"if",
"the",
"qti",
"element",
"."
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/IdentifiedElement.php#L213-L249 |
oat-sa/extension-tao-itemqti | model/qti/AssetParser.php | AssetParser.extract | public function extract(){
foreach($this->item->getComposingElements() as $element){
$this->extractImg($element);
$this->extractObject($element);
$this->extractStyleSheet($element);
$this->extractCustomElement($element);
if($this->getGetXinclude()){
$this->extractXinclude($element);
}
}
return $this->assets;
} | php | public function extract(){
foreach($this->item->getComposingElements() as $element){
$this->extractImg($element);
$this->extractObject($element);
$this->extractStyleSheet($element);
$this->extractCustomElement($element);
if($this->getGetXinclude()){
$this->extractXinclude($element);
}
}
return $this->assets;
} | [
"public",
"function",
"extract",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"item",
"->",
"getComposingElements",
"(",
")",
"as",
"$",
"element",
")",
"{",
"$",
"this",
"->",
"extractImg",
"(",
"$",
"element",
")",
";",
"$",
"this",
"->",
"ext... | Extract all assets from the current item
@return array the assets by type | [
"Extract",
"all",
"assets",
"from",
"the",
"current",
"item"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/AssetParser.php#L98-L109 |
oat-sa/extension-tao-itemqti | model/qti/AssetParser.php | AssetParser.extractImg | private function extractImg(Element $element){
if($element instanceof Container){
foreach($element->getElements('oat\taoQtiItem\model\qti\Img') as $img){
$this->addAsset('img', $img->attr('src'));
}
}
} | php | private function extractImg(Element $element){
if($element instanceof Container){
foreach($element->getElements('oat\taoQtiItem\model\qti\Img') as $img){
$this->addAsset('img', $img->attr('src'));
}
}
} | [
"private",
"function",
"extractImg",
"(",
"Element",
"$",
"element",
")",
"{",
"if",
"(",
"$",
"element",
"instanceof",
"Container",
")",
"{",
"foreach",
"(",
"$",
"element",
"->",
"getElements",
"(",
"'oat\\taoQtiItem\\model\\qti\\Img'",
")",
"as",
"$",
"img"... | Lookup and extract assets from IMG elements
@param Element $element container of the target element | [
"Lookup",
"and",
"extract",
"assets",
"from",
"IMG",
"elements"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/AssetParser.php#L115-L121 |
oat-sa/extension-tao-itemqti | model/qti/AssetParser.php | AssetParser.extractObject | private function extractObject(Element $element){
if($element instanceof Container){
foreach($element->getElements('oat\taoQtiItem\model\qti\QtiObject') as $object){
$this->loadObjectAssets($object);
}
}
if($element instanceof QtiObject){
$this->loadObjectAssets($element);
}
} | php | private function extractObject(Element $element){
if($element instanceof Container){
foreach($element->getElements('oat\taoQtiItem\model\qti\QtiObject') as $object){
$this->loadObjectAssets($object);
}
}
if($element instanceof QtiObject){
$this->loadObjectAssets($element);
}
} | [
"private",
"function",
"extractObject",
"(",
"Element",
"$",
"element",
")",
"{",
"if",
"(",
"$",
"element",
"instanceof",
"Container",
")",
"{",
"foreach",
"(",
"$",
"element",
"->",
"getElements",
"(",
"'oat\\taoQtiItem\\model\\qti\\QtiObject'",
")",
"as",
"$"... | Lookup and extract assets from a QTI Object
@param Element $element the element itself or a container of the target element | [
"Lookup",
"and",
"extract",
"assets",
"from",
"a",
"QTI",
"Object"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/AssetParser.php#L127-L136 |
oat-sa/extension-tao-itemqti | model/qti/AssetParser.php | AssetParser.extractXinclude | private function extractXinclude(Element $element){
if($element instanceof Container){
foreach($element->getElements('oat\taoQtiItem\model\qti\Xinclude') as $xinclude){
$this->addAsset('xinclude', $xinclude->attr('href'));
}
}
} | php | private function extractXinclude(Element $element){
if($element instanceof Container){
foreach($element->getElements('oat\taoQtiItem\model\qti\Xinclude') as $xinclude){
$this->addAsset('xinclude', $xinclude->attr('href'));
}
}
} | [
"private",
"function",
"extractXinclude",
"(",
"Element",
"$",
"element",
")",
"{",
"if",
"(",
"$",
"element",
"instanceof",
"Container",
")",
"{",
"foreach",
"(",
"$",
"element",
"->",
"getElements",
"(",
"'oat\\taoQtiItem\\model\\qti\\Xinclude'",
")",
"as",
"$... | Lookup and extract assets from IMG elements
@param Element $element container of the target element | [
"Lookup",
"and",
"extract",
"assets",
"from",
"IMG",
"elements"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/AssetParser.php#L142-L148 |
oat-sa/extension-tao-itemqti | model/qti/AssetParser.php | AssetParser.extractStyleSheet | private function extractStyleSheet(Element $element){
if($element instanceof StyleSheet){
$href = $element->attr('href');
$this->addAsset('css', $href);
$parsedUrl = parse_url($href);
if ($this->isDeepParsing() && array_key_exists('path', $parsedUrl) && !array_key_exists('host',
$parsedUrl)
) {
$file = $this->directory->getFile($parsedUrl['path']);
if ($file->exists()) {
$this->loadStyleSheetAsset($file->read());
}
}
}
} | php | private function extractStyleSheet(Element $element){
if($element instanceof StyleSheet){
$href = $element->attr('href');
$this->addAsset('css', $href);
$parsedUrl = parse_url($href);
if ($this->isDeepParsing() && array_key_exists('path', $parsedUrl) && !array_key_exists('host',
$parsedUrl)
) {
$file = $this->directory->getFile($parsedUrl['path']);
if ($file->exists()) {
$this->loadStyleSheetAsset($file->read());
}
}
}
} | [
"private",
"function",
"extractStyleSheet",
"(",
"Element",
"$",
"element",
")",
"{",
"if",
"(",
"$",
"element",
"instanceof",
"StyleSheet",
")",
"{",
"$",
"href",
"=",
"$",
"element",
"->",
"attr",
"(",
"'href'",
")",
";",
"$",
"this",
"->",
"addAsset",... | Lookup and extract assets from a stylesheet element
@param Element $element the stylesheet element | [
"Lookup",
"and",
"extract",
"assets",
"from",
"a",
"stylesheet",
"element"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/AssetParser.php#L154-L169 |
oat-sa/extension-tao-itemqti | model/qti/AssetParser.php | AssetParser.loadObjectAssets | private function loadObjectAssets(QtiObject $object){
$type = $object->attr('type');
if(strpos($type, "image") !== false){
$this->addAsset('img', $object->attr('data'));
} else if (strpos($type, "video") !== false || strpos($type, "ogg") !== false){
$this->addAsset('video', $object->attr('data'));
} else if (strpos($type, "audio") !== false){
$this->addAsset('audio', $object->attr('data'));
}
else if (strpos($type, "text/html") !== false){
$this->addAsset('html', $object->attr('data'));
}
} | php | private function loadObjectAssets(QtiObject $object){
$type = $object->attr('type');
if(strpos($type, "image") !== false){
$this->addAsset('img', $object->attr('data'));
} else if (strpos($type, "video") !== false || strpos($type, "ogg") !== false){
$this->addAsset('video', $object->attr('data'));
} else if (strpos($type, "audio") !== false){
$this->addAsset('audio', $object->attr('data'));
}
else if (strpos($type, "text/html") !== false){
$this->addAsset('html', $object->attr('data'));
}
} | [
"private",
"function",
"loadObjectAssets",
"(",
"QtiObject",
"$",
"object",
")",
"{",
"$",
"type",
"=",
"$",
"object",
"->",
"attr",
"(",
"'type'",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"type",
",",
"\"image\"",
")",
"!==",
"false",
")",
"{",
"$",... | Loads assets from an QTI object element
@param QtiObject $object the object | [
"Loads",
"assets",
"from",
"an",
"QTI",
"object",
"element"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/AssetParser.php#L216-L230 |
oat-sa/extension-tao-itemqti | model/qti/AssetParser.php | AssetParser.addAsset | private function addAsset($type, $uri)
{
if(!array_key_exists($type, $this->assets)){
$this->assets[$type] = array();
}
if(!empty($uri) && !in_array($uri, $this->assets[$type])){
$this->assets[$type][] = $uri;
}
} | php | private function addAsset($type, $uri)
{
if(!array_key_exists($type, $this->assets)){
$this->assets[$type] = array();
}
if(!empty($uri) && !in_array($uri, $this->assets[$type])){
$this->assets[$type][] = $uri;
}
} | [
"private",
"function",
"addAsset",
"(",
"$",
"type",
",",
"$",
"uri",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"type",
",",
"$",
"this",
"->",
"assets",
")",
")",
"{",
"$",
"this",
"->",
"assets",
"[",
"$",
"type",
"]",
"=",
"array... | Add the asset to the current list
@param string $type the asset type: img, css, js, audio, video, font, etc.
@param string $uri the asset URI | [
"Add",
"the",
"asset",
"to",
"the",
"current",
"list"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/AssetParser.php#L237-L245 |
oat-sa/extension-tao-itemqti | model/qti/AssetParser.php | AssetParser.loadCustomElementPropertiesAssets | private function loadCustomElementPropertiesAssets($properties) {
if (is_array($properties)) {
if (isset($properties['uri'])) {
$this->addAsset('document', urldecode($properties['uri']));
} else {
foreach($properties as $property) {
if (is_array($property)) {
$this->loadCustomElementPropertiesAssets($property);
}
}
}
}
} | php | private function loadCustomElementPropertiesAssets($properties) {
if (is_array($properties)) {
if (isset($properties['uri'])) {
$this->addAsset('document', urldecode($properties['uri']));
} else {
foreach($properties as $property) {
if (is_array($property)) {
$this->loadCustomElementPropertiesAssets($property);
}
}
}
}
} | [
"private",
"function",
"loadCustomElementPropertiesAssets",
"(",
"$",
"properties",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"properties",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"properties",
"[",
"'uri'",
"]",
")",
")",
"{",
"$",
"this",
"->",
... | Search assets URI in custom element properties
The PCI standard will be extended in the future with typed property value (boolean, integer, float, string, uri, html etc.)
Meanwhile, we use the special property name uri for the special type "URI" that represents a file URI.
Portable element using this reserved property should be migrated later on when the standard is updated.
@param array $properties | [
"Search",
"assets",
"URI",
"in",
"custom",
"element",
"properties",
"The",
"PCI",
"standard",
"will",
"be",
"extended",
"in",
"the",
"future",
"with",
"typed",
"property",
"value",
"(",
"boolean",
"integer",
"float",
"string",
"uri",
"html",
"etc",
".",
")",... | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/AssetParser.php#L255-L267 |
oat-sa/extension-tao-itemqti | model/qti/AssetParser.php | AssetParser.loadCustomElementAssets | private function loadCustomElementAssets(Element $element)
{
if($this->getGetCustomElementDefinition()) {
$this->assets[$element->getTypeIdentifier()] = $element;
}
$xmls = array();
if($element instanceof PortableCustomInteraction || $element instanceof PortableInfoControl){
//some portable elements contains htmlentitied markup in their properties...
$xmls = $this->getXmlProperties($element->getProperties());
}
//parse and extract assets from markup using XPATH
if ($element instanceof CustomInteraction || $element instanceof InfoControl) {
// http://php.net/manual/fr/simplexmlelement.xpath.php#116622
$sanitizedMarkup = str_replace('xmlns=', 'ns=', $element->getMarkup());
$xmls[] = new SimpleXMLElement($sanitizedMarkup);
$this->loadCustomElementPropertiesAssets($element->getProperties());
/** @var SimpleXMLElement $xml */
foreach ($xmls as $xml) {
foreach ($xml->xpath('//img') as $img) {
$this->addAsset('img', (string)$img['src']);
}
foreach ($xml->xpath('//video') as $video) {
$this->addAsset('video', (string)$video['src']);
}
foreach ($xml->xpath('//audio') as $audio) {
$this->addAsset('audio', (string)$audio['src']);
}
}
}
} | php | private function loadCustomElementAssets(Element $element)
{
if($this->getGetCustomElementDefinition()) {
$this->assets[$element->getTypeIdentifier()] = $element;
}
$xmls = array();
if($element instanceof PortableCustomInteraction || $element instanceof PortableInfoControl){
//some portable elements contains htmlentitied markup in their properties...
$xmls = $this->getXmlProperties($element->getProperties());
}
//parse and extract assets from markup using XPATH
if ($element instanceof CustomInteraction || $element instanceof InfoControl) {
// http://php.net/manual/fr/simplexmlelement.xpath.php#116622
$sanitizedMarkup = str_replace('xmlns=', 'ns=', $element->getMarkup());
$xmls[] = new SimpleXMLElement($sanitizedMarkup);
$this->loadCustomElementPropertiesAssets($element->getProperties());
/** @var SimpleXMLElement $xml */
foreach ($xmls as $xml) {
foreach ($xml->xpath('//img') as $img) {
$this->addAsset('img', (string)$img['src']);
}
foreach ($xml->xpath('//video') as $video) {
$this->addAsset('video', (string)$video['src']);
}
foreach ($xml->xpath('//audio') as $audio) {
$this->addAsset('audio', (string)$audio['src']);
}
}
}
} | [
"private",
"function",
"loadCustomElementAssets",
"(",
"Element",
"$",
"element",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getGetCustomElementDefinition",
"(",
")",
")",
"{",
"$",
"this",
"->",
"assets",
"[",
"$",
"element",
"->",
"getTypeIdentifier",
"(",
"... | Load assets from the custom elements (CustomInteraction, PCI, PIC)
@param Element $element the custom element | [
"Load",
"assets",
"from",
"the",
"custom",
"elements",
"(",
"CustomInteraction",
"PCI",
"PIC",
")"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/AssetParser.php#L273-L307 |
oat-sa/extension-tao-itemqti | model/qti/AssetParser.php | AssetParser.loadStyleSheetAsset | private function loadStyleSheetAsset($css){
$imageRe = "/url\\s*\\(['|\"]?([^)]*\.(png|jpg|jpeg|gif|svg))['|\"]?\\)/mi";
$importRe = "/@import\\s*(url\\s*\\()?['\"]?([^;]*)['\"]/mi";
$fontFaceRe = "/@font-face\\s*\\{(.*)?\\}/mi";
$fontRe = "/url\\s*\\(['|\"]?([^)'|\"]*)['|\"]?\\)/i";
//extract images
preg_match_all($imageRe, $css, $matches);
if(isset($matches[1])){
foreach($matches[1] as $match){
$this->addAsset('img', $match);
}
}
//extract @import
preg_match_all($importRe, $css, $matches);
if(isset($matches[2])){
foreach($matches[2] as $match){
$this->addAsset('css', $match);
}
}
//extract fonts
preg_match_all($fontFaceRe, $css, $matches);
if(isset($matches[1])){
foreach($matches[1] as $faceMatch){
preg_match_all($fontRe, $faceMatch, $fontMatches);
if(isset($fontMatches[1])){
foreach($fontMatches[1] as $fontMatch){
$this->addAsset('font', $fontMatch);
}
}
}
}
} | php | private function loadStyleSheetAsset($css){
$imageRe = "/url\\s*\\(['|\"]?([^)]*\.(png|jpg|jpeg|gif|svg))['|\"]?\\)/mi";
$importRe = "/@import\\s*(url\\s*\\()?['\"]?([^;]*)['\"]/mi";
$fontFaceRe = "/@font-face\\s*\\{(.*)?\\}/mi";
$fontRe = "/url\\s*\\(['|\"]?([^)'|\"]*)['|\"]?\\)/i";
//extract images
preg_match_all($imageRe, $css, $matches);
if(isset($matches[1])){
foreach($matches[1] as $match){
$this->addAsset('img', $match);
}
}
//extract @import
preg_match_all($importRe, $css, $matches);
if(isset($matches[2])){
foreach($matches[2] as $match){
$this->addAsset('css', $match);
}
}
//extract fonts
preg_match_all($fontFaceRe, $css, $matches);
if(isset($matches[1])){
foreach($matches[1] as $faceMatch){
preg_match_all($fontRe, $faceMatch, $fontMatches);
if(isset($fontMatches[1])){
foreach($fontMatches[1] as $fontMatch){
$this->addAsset('font', $fontMatch);
}
}
}
}
} | [
"private",
"function",
"loadStyleSheetAsset",
"(",
"$",
"css",
")",
"{",
"$",
"imageRe",
"=",
"\"/url\\\\s*\\\\(['|\\\"]?([^)]*\\.(png|jpg|jpeg|gif|svg))['|\\\"]?\\\\)/mi\"",
";",
"$",
"importRe",
"=",
"\"/@import\\\\s*(url\\\\s*\\\\()?['\\\"]?([^;]*)['\\\"]/mi\"",
";",
"$",
"f... | Parse, extract and load assets from the stylesheet content
@param string $css the stylesheet content | [
"Parse",
"extract",
"and",
"load",
"assets",
"from",
"the",
"stylesheet",
"content"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/AssetParser.php#L329-L364 |
oat-sa/extension-tao-itemqti | model/qti/metadata/imsManifest/classificationMetadata/ClassificationEntryMetadataValue.php | ClassificationEntryMetadataValue.getEntryPath | static public function getEntryPath()
{
return [
LomMetadata::LOM_NAMESPACE . '#lom',
LomMetadata::LOM_NAMESPACE . '#classification',
LomMetadata::LOM_NAMESPACE . '#taxonPath',
LomMetadata::LOM_NAMESPACE . '#taxon',
LomMetadata::LOM_NAMESPACE . '#entry',
LomMetadata::LOM_NAMESPACE . '#string'
];
} | php | static public function getEntryPath()
{
return [
LomMetadata::LOM_NAMESPACE . '#lom',
LomMetadata::LOM_NAMESPACE . '#classification',
LomMetadata::LOM_NAMESPACE . '#taxonPath',
LomMetadata::LOM_NAMESPACE . '#taxon',
LomMetadata::LOM_NAMESPACE . '#entry',
LomMetadata::LOM_NAMESPACE . '#string'
];
} | [
"static",
"public",
"function",
"getEntryPath",
"(",
")",
"{",
"return",
"[",
"LomMetadata",
"::",
"LOM_NAMESPACE",
".",
"'#lom'",
",",
"LomMetadata",
"::",
"LOM_NAMESPACE",
".",
"'#classification'",
",",
"LomMetadata",
"::",
"LOM_NAMESPACE",
".",
"'#taxonPath'",
... | Get default entry path into DomDocument
@return array | [
"Get",
"default",
"entry",
"path",
"into",
"DomDocument"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/imsManifest/classificationMetadata/ClassificationEntryMetadataValue.php#L59-L69 |
oat-sa/extension-tao-itemqti | model/qti/Service.php | Service.getDataItemByRdfItem | public function getDataItemByRdfItem(core_kernel_classes_Resource $item, $langCode = '', $resolveXInclude = false)
{
$returnValue = null;
try {
//Parse it and build the QTI_Data_Item
$file = $this->getXmlByRdfItem($item, $langCode);
$qtiParser = new Parser($file);
$returnValue = $qtiParser->load();
if(is_null($returnValue) && !empty($qtiParser->getErrors())){
common_Logger::w($qtiParser->displayErrors(false));
}
if($resolveXInclude && !empty($langCode)){
try{
//loadxinclude
$resolver = new ItemMediaResolver($item, $langCode);
$xincludeLoader = new XIncludeLoader($returnValue, $resolver);
$xincludeLoader->load(true);
} catch(XIncludeException $exception){
common_Logger::e($exception->getMessage());
}
}
if (!$returnValue->getAttributeValue('xml:lang')) {
$returnValue->setAttribute('xml:lang', \common_session_SessionManager::getSession()->getDataLanguage());
}
} catch (FileNotFoundException $e) {
// fail silently, since file might not have been created yet
// $returnValue is then NULL.
common_Logger::d('item('.$item->getUri().') is empty, newly created?');
} catch (common_Exception $e){
common_Logger::d('item('.$item->getUri().') is not existing');
}
return $returnValue;
} | php | public function getDataItemByRdfItem(core_kernel_classes_Resource $item, $langCode = '', $resolveXInclude = false)
{
$returnValue = null;
try {
//Parse it and build the QTI_Data_Item
$file = $this->getXmlByRdfItem($item, $langCode);
$qtiParser = new Parser($file);
$returnValue = $qtiParser->load();
if(is_null($returnValue) && !empty($qtiParser->getErrors())){
common_Logger::w($qtiParser->displayErrors(false));
}
if($resolveXInclude && !empty($langCode)){
try{
//loadxinclude
$resolver = new ItemMediaResolver($item, $langCode);
$xincludeLoader = new XIncludeLoader($returnValue, $resolver);
$xincludeLoader->load(true);
} catch(XIncludeException $exception){
common_Logger::e($exception->getMessage());
}
}
if (!$returnValue->getAttributeValue('xml:lang')) {
$returnValue->setAttribute('xml:lang', \common_session_SessionManager::getSession()->getDataLanguage());
}
} catch (FileNotFoundException $e) {
// fail silently, since file might not have been created yet
// $returnValue is then NULL.
common_Logger::d('item('.$item->getUri().') is empty, newly created?');
} catch (common_Exception $e){
common_Logger::d('item('.$item->getUri().') is not existing');
}
return $returnValue;
} | [
"public",
"function",
"getDataItemByRdfItem",
"(",
"core_kernel_classes_Resource",
"$",
"item",
",",
"$",
"langCode",
"=",
"''",
",",
"$",
"resolveXInclude",
"=",
"false",
")",
"{",
"$",
"returnValue",
"=",
"null",
";",
"try",
"{",
"//Parse it and build the QTI_Da... | Load a QTI_Item from an, RDF Item using the itemContent property of the
Item as the QTI xml
@access public
@author Somsack Sipasseuth, <somsack.sipasseuth@tudor.lu>
@param Resource item
@throws \common_Exception If $item is not representing an item with a QTI item model.
@return Item An item as a business object. | [
"Load",
"a",
"QTI_Item",
"from",
"an",
"RDF",
"Item",
"using",
"the",
"itemContent",
"property",
"of",
"the",
"Item",
"as",
"the",
"QTI",
"xml"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/Service.php#L62-L99 |
oat-sa/extension-tao-itemqti | model/qti/Service.php | Service.getXmlByRdfItem | public function getXmlByRdfItem(core_kernel_classes_Resource $item, $language = '')
{
$itemService = taoItems_models_classes_ItemsService::singleton();
//check if the item is QTI item
if (! $itemService->hasItemModel($item, array(ItemModel::MODEL_URI))) {
throw new common_Exception('Non QTI item('.$item->getUri().') opened via QTI Service');
}
$file = $itemService->getItemDirectory($item, $language)->getFile(self::QTI_ITEM_FILE);
return $file->read();
} | php | public function getXmlByRdfItem(core_kernel_classes_Resource $item, $language = '')
{
$itemService = taoItems_models_classes_ItemsService::singleton();
//check if the item is QTI item
if (! $itemService->hasItemModel($item, array(ItemModel::MODEL_URI))) {
throw new common_Exception('Non QTI item('.$item->getUri().') opened via QTI Service');
}
$file = $itemService->getItemDirectory($item, $language)->getFile(self::QTI_ITEM_FILE);
return $file->read();
} | [
"public",
"function",
"getXmlByRdfItem",
"(",
"core_kernel_classes_Resource",
"$",
"item",
",",
"$",
"language",
"=",
"''",
")",
"{",
"$",
"itemService",
"=",
"taoItems_models_classes_ItemsService",
"::",
"singleton",
"(",
")",
";",
"//check if the item is QTI item",
... | Load the XML of the QTI item
@param core_kernel_classes_Resource $item
@param string $language
@return false|string
@throws common_Exception | [
"Load",
"the",
"XML",
"of",
"the",
"QTI",
"item"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/Service.php#L109-L120 |
oat-sa/extension-tao-itemqti | model/qti/Service.php | Service.saveDataItemToRdfItem | public function saveDataItemToRdfItem(Item $qtiItem, core_kernel_classes_Resource $rdfItem)
{
$label = mb_substr($rdfItem->getLabel(), 0, 256, 'UTF-8');
//set the current data lang in the item content to keep the integrity
if ($qtiItem->hasAttribute('xml:lang') && !empty($qtiItem->getAttributeValue('xml:lang'))) {
$lang = $qtiItem->getAttributeValue('xml:lang');
} else {
$lang = \common_session_SessionManager::getSession()->getDataLanguage();
}
$qtiItem->setAttribute('xml:lang', $lang);
$qtiItem->setAttribute('label', $label);
$directory = taoItems_models_classes_ItemsService::singleton()->getItemDirectory($rdfItem);
$success = $directory->getFile(self::QTI_ITEM_FILE)->put($qtiItem->toXML());
if ($success) {
$this->getEventManager()->trigger(new ItemUpdatedEvent($rdfItem->getUri()));
}
return $success;
} | php | public function saveDataItemToRdfItem(Item $qtiItem, core_kernel_classes_Resource $rdfItem)
{
$label = mb_substr($rdfItem->getLabel(), 0, 256, 'UTF-8');
//set the current data lang in the item content to keep the integrity
if ($qtiItem->hasAttribute('xml:lang') && !empty($qtiItem->getAttributeValue('xml:lang'))) {
$lang = $qtiItem->getAttributeValue('xml:lang');
} else {
$lang = \common_session_SessionManager::getSession()->getDataLanguage();
}
$qtiItem->setAttribute('xml:lang', $lang);
$qtiItem->setAttribute('label', $label);
$directory = taoItems_models_classes_ItemsService::singleton()->getItemDirectory($rdfItem);
$success = $directory->getFile(self::QTI_ITEM_FILE)->put($qtiItem->toXML());
if ($success) {
$this->getEventManager()->trigger(new ItemUpdatedEvent($rdfItem->getUri()));
}
return $success;
} | [
"public",
"function",
"saveDataItemToRdfItem",
"(",
"Item",
"$",
"qtiItem",
",",
"core_kernel_classes_Resource",
"$",
"rdfItem",
")",
"{",
"$",
"label",
"=",
"mb_substr",
"(",
"$",
"rdfItem",
"->",
"getLabel",
"(",
")",
",",
"0",
",",
"256",
",",
"'UTF-8'",
... | Save a QTI_Item into an RDF Item, by exporting the QTI_Item to QTI xml
and saving it in the itemContent property of the RDF Item
@param \oat\taoQtiItem\model\qti\Item $qtiItem
@param core_kernel_classes_Resource $rdfItem
@return bool
@throws \common_exception_Error
@throws \common_exception_NotFound
@throws common_Exception
@throws exception\QtiModelException | [
"Save",
"a",
"QTI_Item",
"into",
"an",
"RDF",
"Item",
"by",
"exporting",
"the",
"QTI_Item",
"to",
"QTI",
"xml",
"and",
"saving",
"it",
"in",
"the",
"itemContent",
"property",
"of",
"the",
"RDF",
"Item"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/Service.php#L134-L154 |
oat-sa/extension-tao-itemqti | model/qti/Service.php | Service.loadItemFromFile | public function loadItemFromFile($file)
{
$returnValue = null;
if (is_string($file) && !empty($file)) {
//validate the file to import
try {
$qtiParser = new Parser($file);
$qtiParser->validate();
if (!$qtiParser->isValid()) {
throw new ParsingException($qtiParser->displayErrors());
}
$returnValue = $qtiParser->load();
} catch(ParsingException $pe) {
throw new ParsingException($pe->getMessage());
} catch(Exception $e) {
throw new Exception("Unable to load file {$file} caused by {$e->getMessage()}");
}
}
return $returnValue;
} | php | public function loadItemFromFile($file)
{
$returnValue = null;
if (is_string($file) && !empty($file)) {
//validate the file to import
try {
$qtiParser = new Parser($file);
$qtiParser->validate();
if (!$qtiParser->isValid()) {
throw new ParsingException($qtiParser->displayErrors());
}
$returnValue = $qtiParser->load();
} catch(ParsingException $pe) {
throw new ParsingException($pe->getMessage());
} catch(Exception $e) {
throw new Exception("Unable to load file {$file} caused by {$e->getMessage()}");
}
}
return $returnValue;
} | [
"public",
"function",
"loadItemFromFile",
"(",
"$",
"file",
")",
"{",
"$",
"returnValue",
"=",
"null",
";",
"if",
"(",
"is_string",
"(",
"$",
"file",
")",
"&&",
"!",
"empty",
"(",
"$",
"file",
")",
")",
"{",
"//validate the file to import",
"try",
"{",
... | Load a QTI item from a qti file in parameter.
@param $file
@return null|Item
@throws Exception
@throws ParsingException | [
"Load",
"a",
"QTI",
"item",
"from",
"a",
"qti",
"file",
"in",
"parameter",
"."
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/Service.php#L181-L205 |
oat-sa/extension-tao-itemqti | controller/AbstractRestQti.php | AbstractRestQti.getStatus | public function getStatus()
{
try {
if (!$this->hasRequestParameter(self::TASK_ID_PARAM)) {
throw new \common_exception_MissingParameter(self::TASK_ID_PARAM, $this->getRequestURI());
}
$data = $this->getTaskLogReturnData(
$this->getRequestParameter(self::TASK_ID_PARAM),
$this->getTaskName()
);
$this->returnSuccess($data);
} catch (\Exception $e) {
$this->returnFailure($e);
}
} | php | public function getStatus()
{
try {
if (!$this->hasRequestParameter(self::TASK_ID_PARAM)) {
throw new \common_exception_MissingParameter(self::TASK_ID_PARAM, $this->getRequestURI());
}
$data = $this->getTaskLogReturnData(
$this->getRequestParameter(self::TASK_ID_PARAM),
$this->getTaskName()
);
$this->returnSuccess($data);
} catch (\Exception $e) {
$this->returnFailure($e);
}
} | [
"public",
"function",
"getStatus",
"(",
")",
"{",
"try",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasRequestParameter",
"(",
"self",
"::",
"TASK_ID_PARAM",
")",
")",
"{",
"throw",
"new",
"\\",
"common_exception_MissingParameter",
"(",
"self",
"::",
"TASK_ID_... | Action to retrieve test import status from queue | [
"Action",
"to",
"retrieve",
"test",
"import",
"status",
"from",
"queue"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/controller/AbstractRestQti.php#L64-L80 |
oat-sa/extension-tao-itemqti | controller/AbstractRestQti.php | AbstractRestQti.getTaskStatus | protected function getTaskStatus(EntityInterface $taskLogEntity)
{
if ($taskLogEntity->getStatus()->isCreated()) {
return __('In Progress');
} else if ($taskLogEntity->getStatus()->isCompleted()){
return __('Success');
}
return $taskLogEntity->getStatus()->getLabel();
} | php | protected function getTaskStatus(EntityInterface $taskLogEntity)
{
if ($taskLogEntity->getStatus()->isCreated()) {
return __('In Progress');
} else if ($taskLogEntity->getStatus()->isCompleted()){
return __('Success');
}
return $taskLogEntity->getStatus()->getLabel();
} | [
"protected",
"function",
"getTaskStatus",
"(",
"EntityInterface",
"$",
"taskLogEntity",
")",
"{",
"if",
"(",
"$",
"taskLogEntity",
"->",
"getStatus",
"(",
")",
"->",
"isCreated",
"(",
")",
")",
"{",
"return",
"__",
"(",
"'In Progress'",
")",
";",
"}",
"els... | Return 'Success' instead of 'Completed', required by the specified API.
@param EntityInterface $taskLogEntity
@return string | [
"Return",
"Success",
"instead",
"of",
"Completed",
"required",
"by",
"the",
"specified",
"API",
"."
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/controller/AbstractRestQti.php#L88-L97 |
oat-sa/extension-tao-itemqti | model/qti/response/Template.php | Template.getRule | public function getRule(){
$returnValue = (string) '';
if($this->uri == self::MATCH_CORRECT){
$returnValue = taoQTI_models_classes_Matching_Matching::MATCH_CORRECT;
}else if($this->uri == self::MAP_RESPONSE){
$returnValue = taoQTI_models_classes_Matching_Matching::MAP_RESPONSE;
}else if($this->uri == self::MAP_RESPONSE_POINT){
$returnValue = taoQTI_models_classes_Matching_Matching::MAP_RESPONSE_POINT;
}
return (string) $returnValue;
} | php | public function getRule(){
$returnValue = (string) '';
if($this->uri == self::MATCH_CORRECT){
$returnValue = taoQTI_models_classes_Matching_Matching::MATCH_CORRECT;
}else if($this->uri == self::MAP_RESPONSE){
$returnValue = taoQTI_models_classes_Matching_Matching::MAP_RESPONSE;
}else if($this->uri == self::MAP_RESPONSE_POINT){
$returnValue = taoQTI_models_classes_Matching_Matching::MAP_RESPONSE_POINT;
}
return (string) $returnValue;
} | [
"public",
"function",
"getRule",
"(",
")",
"{",
"$",
"returnValue",
"=",
"(",
"string",
")",
"''",
";",
"if",
"(",
"$",
"this",
"->",
"uri",
"==",
"self",
"::",
"MATCH_CORRECT",
")",
"{",
"$",
"returnValue",
"=",
"taoQTI_models_classes_Matching_Matching",
... | Short description of method getRule
@access public
@author Cedric Alfonsi, <cedric.alfonsi@tudor.lu>
@return string | [
"Short",
"description",
"of",
"method",
"getRule"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/response/Template.php#L131-L146 |
oat-sa/extension-tao-itemqti | model/qti/response/Template.php | Template.getTemplateContent | public function getTemplateContent(){
$standardRpTemplateFolder = dirname(__FILE__).'/../data/qtiv2p1/rptemplates/';
switch($this->uri){
case self::MATCH_CORRECT:
$returnValue = file_get_contents($standardRpTemplateFolder.'match_correct.xml');
break;
case self::MAP_RESPONSE:
$returnValue = file_get_contents($standardRpTemplateFolder.'map_response.xml');
break;
case self::MAP_RESPONSE_POINT:
$returnValue = file_get_contents($standardRpTemplateFolder.'map_response_point.xml');
break;
case self::NONE:
$returnValue = '';
break;
default:
throw new QtiModelException('unknown rp template');
}
return $returnValue;
} | php | public function getTemplateContent(){
$standardRpTemplateFolder = dirname(__FILE__).'/../data/qtiv2p1/rptemplates/';
switch($this->uri){
case self::MATCH_CORRECT:
$returnValue = file_get_contents($standardRpTemplateFolder.'match_correct.xml');
break;
case self::MAP_RESPONSE:
$returnValue = file_get_contents($standardRpTemplateFolder.'map_response.xml');
break;
case self::MAP_RESPONSE_POINT:
$returnValue = file_get_contents($standardRpTemplateFolder.'map_response_point.xml');
break;
case self::NONE:
$returnValue = '';
break;
default:
throw new QtiModelException('unknown rp template');
}
return $returnValue;
} | [
"public",
"function",
"getTemplateContent",
"(",
")",
"{",
"$",
"standardRpTemplateFolder",
"=",
"dirname",
"(",
"__FILE__",
")",
".",
"'/../data/qtiv2p1/rptemplates/'",
";",
"switch",
"(",
"$",
"this",
"->",
"uri",
")",
"{",
"case",
"self",
"::",
"MATCH_CORRECT... | Get the content of the response processing template identified by its uri
@todo make it dynamic in the future
@return string
@throws \oat\taoQtiItem\model\qti\exception\QtiModelException | [
"Get",
"the",
"content",
"of",
"the",
"response",
"processing",
"template",
"identified",
"by",
"its",
"uri"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/response/Template.php#L155-L175 |
oat-sa/extension-tao-itemqti | model/qti/response/Template.php | Template.toQTI | public function toQTI(){
$returnValue = '';
if($this->uri != self::NONE){
//if there is actually a real response template involved, render the template
$tplRenderer = new taoItems_models_classes_TemplateRenderer(static::getTemplatePath().'/qti.rptemplate.tpl.php', array('uri' => $this->uri));
$returnValue = $tplRenderer->render();
}
return (string) $returnValue;
} | php | public function toQTI(){
$returnValue = '';
if($this->uri != self::NONE){
//if there is actually a real response template involved, render the template
$tplRenderer = new taoItems_models_classes_TemplateRenderer(static::getTemplatePath().'/qti.rptemplate.tpl.php', array('uri' => $this->uri));
$returnValue = $tplRenderer->render();
}
return (string) $returnValue;
} | [
"public",
"function",
"toQTI",
"(",
")",
"{",
"$",
"returnValue",
"=",
"''",
";",
"if",
"(",
"$",
"this",
"->",
"uri",
"!=",
"self",
"::",
"NONE",
")",
"{",
"//if there is actually a real response template involved, render the template",
"$",
"tplRenderer",
"=",
... | Short description of method toQTI
@access public
@author Cedric Alfonsi, <cedric.alfonsi@tudor.lu>
@return string | [
"Short",
"description",
"of",
"method",
"toQTI"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/response/Template.php#L221-L232 |
oat-sa/extension-tao-itemqti | model/portableElement/validator/PortableElementAssetValidator.php | PortableElementAssetValidator.validateAssets | public function validateAssets(PortableElementObject $object, $source, array $files=[])
{
$errorReport = \common_report_Report::createFailure('Portable element validation has failed.');
if (empty($files)) {
//if no files requested, get all all assets
try{
$files = $this->getAssets($object);
}catch(PortableElementInvalidAssetException $e){
$subReport = \common_report_Report::createFailure($e->getMessage());
$errorReport->add($subReport);
}
}
if (!empty($files)) {
foreach ($files as $key => $file) {
try {
$this->validFile($source, $file);
} catch (PortableElementInvalidAssetException $e) {
$subReport = \common_report_Report::createFailure(__('Cannot locate the file "%s"', $file));
$errorReport->add($subReport);
}
}
}
if ($errorReport->containsError()) {
$exception = new PortableElementInvalidModelException();
$exception->setReport($errorReport);
throw $exception;
}
return true;
} | php | public function validateAssets(PortableElementObject $object, $source, array $files=[])
{
$errorReport = \common_report_Report::createFailure('Portable element validation has failed.');
if (empty($files)) {
//if no files requested, get all all assets
try{
$files = $this->getAssets($object);
}catch(PortableElementInvalidAssetException $e){
$subReport = \common_report_Report::createFailure($e->getMessage());
$errorReport->add($subReport);
}
}
if (!empty($files)) {
foreach ($files as $key => $file) {
try {
$this->validFile($source, $file);
} catch (PortableElementInvalidAssetException $e) {
$subReport = \common_report_Report::createFailure(__('Cannot locate the file "%s"', $file));
$errorReport->add($subReport);
}
}
}
if ($errorReport->containsError()) {
$exception = new PortableElementInvalidModelException();
$exception->setReport($errorReport);
throw $exception;
}
return true;
} | [
"public",
"function",
"validateAssets",
"(",
"PortableElementObject",
"$",
"object",
",",
"$",
"source",
",",
"array",
"$",
"files",
"=",
"[",
"]",
")",
"{",
"$",
"errorReport",
"=",
"\\",
"common_report_Report",
"::",
"createFailure",
"(",
"'Portable element va... | Validate files by checking:
- Model requirement
- Existing as file or alias
@param PortableElementObject $object
@param string $source Temporary directory source
@param array $files Array of file relative path
@return bool
@throws PortableElementInvalidAssetException
@throws PortableElementInvalidModelException
@throws PortableElementParserException
@throws \common_exception_Error | [
"Validate",
"files",
"by",
"checking",
":",
"-",
"Model",
"requirement",
"-",
"Existing",
"as",
"file",
"or",
"alias"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/validator/PortableElementAssetValidator.php#L45-L76 |
oat-sa/extension-tao-itemqti | model/portableElement/validator/PortableElementAssetValidator.php | PortableElementAssetValidator.getAssets | public function getAssets(PortableElementObject $object, $type=null)
{
$assets = [];
if (is_null($type) || ($type == 'runtime')) {
$assets = ['runtime' => $object->getRuntimePath()];
}
if (is_null($type) || ($type == 'creator')) {
if (! empty($object->getCreator())) {
$assets['creator'] = $object->getCreatorPath();
}
}
$files = [];
foreach ($assets as $key => $asset) {
$constraints = $this->getAssetConstraints($key);
foreach ($constraints as $constraint) {
if (! isset($asset[$constraint])) {
if ($this->isOptionalConstraint($key, $constraint)) {
continue;
}
throw new PortableElementInvalidAssetException('Missing asset file for ' . $key . ':' . $constraint);
}
if (is_array($asset[$constraint])) {
//get a flat list out of the structure of file data
$it = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($asset[$constraint]));
foreach($it as $k => $v) {
if(!in_array(strval($k), $object->getRegistrationExcludedKey()) && !empty($v)){
$files[] = $v;
}
}
} else {
if(!empty($asset[$constraint])){
$files[] = $asset[$constraint];
}
}
}
}
return $files;
} | php | public function getAssets(PortableElementObject $object, $type=null)
{
$assets = [];
if (is_null($type) || ($type == 'runtime')) {
$assets = ['runtime' => $object->getRuntimePath()];
}
if (is_null($type) || ($type == 'creator')) {
if (! empty($object->getCreator())) {
$assets['creator'] = $object->getCreatorPath();
}
}
$files = [];
foreach ($assets as $key => $asset) {
$constraints = $this->getAssetConstraints($key);
foreach ($constraints as $constraint) {
if (! isset($asset[$constraint])) {
if ($this->isOptionalConstraint($key, $constraint)) {
continue;
}
throw new PortableElementInvalidAssetException('Missing asset file for ' . $key . ':' . $constraint);
}
if (is_array($asset[$constraint])) {
//get a flat list out of the structure of file data
$it = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($asset[$constraint]));
foreach($it as $k => $v) {
if(!in_array(strval($k), $object->getRegistrationExcludedKey()) && !empty($v)){
$files[] = $v;
}
}
} else {
if(!empty($asset[$constraint])){
$files[] = $asset[$constraint];
}
}
}
}
return $files;
} | [
"public",
"function",
"getAssets",
"(",
"PortableElementObject",
"$",
"object",
",",
"$",
"type",
"=",
"null",
")",
"{",
"$",
"assets",
"=",
"[",
"]",
";",
"if",
"(",
"is_null",
"(",
"$",
"type",
")",
"||",
"(",
"$",
"type",
"==",
"'runtime'",
")",
... | Return all assets of a portable element in a array of string
Path is relative to Portable Element location
@param PortableElementObject $object
@param null $type Object key to focus
@return array List of file relative path
@throws PortableElementInvalidAssetException | [
"Return",
"all",
"assets",
"of",
"a",
"portable",
"element",
"in",
"a",
"array",
"of",
"string",
"Path",
"is",
"relative",
"to",
"Portable",
"Element",
"location"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/validator/PortableElementAssetValidator.php#L87-L126 |
oat-sa/extension-tao-itemqti | model/portableElement/validator/PortableElementAssetValidator.php | PortableElementAssetValidator.validFile | public function validFile($source, $file)
{
if (! file_exists($source)) {
throw new PortableElementParserException('Unable to locate extracted zip file.');
}
$filePath = rtrim($source, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . preg_replace('/^\.\//', '', $file);
if (file_exists($filePath) || file_exists($filePath . '.js')) {
return true;
}
if (array_key_exists($file, ClientLibRegistry::getRegistry()->getLibAliasMap())) {
return true;
}
throw new PortableElementInvalidAssetException(
'Asset "' . $file . '" is not found in the source "'.$source.'"" neither through alias'
);
} | php | public function validFile($source, $file)
{
if (! file_exists($source)) {
throw new PortableElementParserException('Unable to locate extracted zip file.');
}
$filePath = rtrim($source, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . preg_replace('/^\.\//', '', $file);
if (file_exists($filePath) || file_exists($filePath . '.js')) {
return true;
}
if (array_key_exists($file, ClientLibRegistry::getRegistry()->getLibAliasMap())) {
return true;
}
throw new PortableElementInvalidAssetException(
'Asset "' . $file . '" is not found in the source "'.$source.'"" neither through alias'
);
} | [
"public",
"function",
"validFile",
"(",
"$",
"source",
",",
"$",
"file",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"source",
")",
")",
"{",
"throw",
"new",
"PortableElementParserException",
"(",
"'Unable to locate extracted zip file.'",
")",
";",
"}",... | Valid a file if exists or alias
@param string $source Temporary directory source
@param string $file Path to the file
@return bool
@throws PortableElementInvalidAssetException
@throws PortableElementParserException | [
"Valid",
"a",
"file",
"if",
"exists",
"or",
"alias"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/validator/PortableElementAssetValidator.php#L137-L156 |
oat-sa/extension-tao-itemqti | model/portableElement/action/RegisterPortableElement.php | RegisterPortableElement.createFailure | private function createFailure($userMessage, $model = null){
$typeIdentifier = is_null($model) ? 'unknown type' : $model->getTypeIdentifier();
$message = 'The portable element cannot be registered "'.$typeIdentifier.'", reason: '.$userMessage;
\common_Logger::w($message);
return Report::createFailure($message);
} | php | private function createFailure($userMessage, $model = null){
$typeIdentifier = is_null($model) ? 'unknown type' : $model->getTypeIdentifier();
$message = 'The portable element cannot be registered "'.$typeIdentifier.'", reason: '.$userMessage;
\common_Logger::w($message);
return Report::createFailure($message);
} | [
"private",
"function",
"createFailure",
"(",
"$",
"userMessage",
",",
"$",
"model",
"=",
"null",
")",
"{",
"$",
"typeIdentifier",
"=",
"is_null",
"(",
"$",
"model",
")",
"?",
"'unknown type'",
":",
"$",
"model",
"->",
"getTypeIdentifier",
"(",
")",
";",
... | Create a formatted failure report and log a warning
@param $userMessage
@param null $model
@return Report | [
"Create",
"a",
"formatted",
"failure",
"report",
"and",
"log",
"a",
"warning"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/action/RegisterPortableElement.php#L80-L85 |
oat-sa/extension-tao-itemqti | model/qti/expression/BaseValue.php | BaseValue.getRule | public function getRule()
{
$returnValue = (string) '';
// JSON ENCODE the value to get quote when quote are required function of the variable base type
// not so easy ;)
//$returnValue = json_encode($this->value);
// @todo make usable for complex variable such as pair, directed pair ..
// @todo centralize the management of the options (attributes)
$options = Array();
$value = null;
switch ($this->attributes['baseType']){
case "boolean":
$options['type'] = "boolean";
$value = json_encode ($this->value);
break;
case "integer":
$options['type'] = "integer";
$value = json_encode ($this->value);
break;
case "float":
$options['type'] = "float";
$value = json_encode ($this->value);
break;
case "identifier":
case "string":
$options['type'] = "string";
$value = json_encode ($this->value);
break;
case "pair":
$options['type'] = "list";
$value = '"'.implode ('","', $this->value).'"';
break;
case "directedPair":
$options['type'] = "tuple";
$value = '"'.implode ('","', (array)$this->value).'"'; // Méchant casting, won't work with a dictionnary, but with a tuple it is okay
break;
default:
throw new common_Exception("taoQTI_models_classes_QTI_response_BaseValue::getRule an error occured : the type ".$this->attributes['baseType']." is unknown");
}
$returnValue = 'createVariable('
. (count($options) ? '"'.addslashes(json_encode($options)).'"' : 'null') .
', '. $value .
')';
return (string) $returnValue;
} | php | public function getRule()
{
$returnValue = (string) '';
// JSON ENCODE the value to get quote when quote are required function of the variable base type
// not so easy ;)
//$returnValue = json_encode($this->value);
// @todo make usable for complex variable such as pair, directed pair ..
// @todo centralize the management of the options (attributes)
$options = Array();
$value = null;
switch ($this->attributes['baseType']){
case "boolean":
$options['type'] = "boolean";
$value = json_encode ($this->value);
break;
case "integer":
$options['type'] = "integer";
$value = json_encode ($this->value);
break;
case "float":
$options['type'] = "float";
$value = json_encode ($this->value);
break;
case "identifier":
case "string":
$options['type'] = "string";
$value = json_encode ($this->value);
break;
case "pair":
$options['type'] = "list";
$value = '"'.implode ('","', $this->value).'"';
break;
case "directedPair":
$options['type'] = "tuple";
$value = '"'.implode ('","', (array)$this->value).'"'; // Méchant casting, won't work with a dictionnary, but with a tuple it is okay
break;
default:
throw new common_Exception("taoQTI_models_classes_QTI_response_BaseValue::getRule an error occured : the type ".$this->attributes['baseType']." is unknown");
}
$returnValue = 'createVariable('
. (count($options) ? '"'.addslashes(json_encode($options)).'"' : 'null') .
', '. $value .
')';
return (string) $returnValue;
} | [
"public",
"function",
"getRule",
"(",
")",
"{",
"$",
"returnValue",
"=",
"(",
"string",
")",
"''",
";",
"// JSON ENCODE the value to get quote when quote are required function of the variable base type",
"// not so easy ;)",
"//$returnValue = json_encode($this->value);",
"// @todo ... | Short description of method getRule
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@return string | [
"Short",
"description",
"of",
"method",
"getRule"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/expression/BaseValue.php#L52-L102 |
oat-sa/extension-tao-itemqti | model/qti/ParserFactory.php | ParserFactory.getBodyData | public function getBodyData(DOMElement $data, $removeNamespace = false, $keepEmptyTags = false){
//prepare the data string
$bodyData = '';
$saveOptions = $keepEmptyTags ? LIBXML_NOEMPTYTAG : 0;
$children = $data->childNodes;
foreach ($children as $child)
{
$bodyData .= $data->ownerDocument->saveXML($child, $saveOptions);
}
if($removeNamespace){
$bodyData = preg_replace('/<(\/)?(\w*):/i', '<$1', $bodyData);
}
return $bodyData;
} | php | public function getBodyData(DOMElement $data, $removeNamespace = false, $keepEmptyTags = false){
//prepare the data string
$bodyData = '';
$saveOptions = $keepEmptyTags ? LIBXML_NOEMPTYTAG : 0;
$children = $data->childNodes;
foreach ($children as $child)
{
$bodyData .= $data->ownerDocument->saveXML($child, $saveOptions);
}
if($removeNamespace){
$bodyData = preg_replace('/<(\/)?(\w*):/i', '<$1', $bodyData);
}
return $bodyData;
} | [
"public",
"function",
"getBodyData",
"(",
"DOMElement",
"$",
"data",
",",
"$",
"removeNamespace",
"=",
"false",
",",
"$",
"keepEmptyTags",
"=",
"false",
")",
"{",
"//prepare the data string",
"$",
"bodyData",
"=",
"''",
";",
"$",
"saveOptions",
"=",
"$",
"ke... | Get the body data (markups) of an element.
@param \DOMElement $data the element
@param boolean $removeNamespace if XML namespaces should be removed
@param boolean $keepEmptyTags if true, the empty tags are kept expanded (useful when tags are HTML)
@return string the body data (XML markup) | [
"Get",
"the",
"body",
"data",
"(",
"markups",
")",
"of",
"an",
"element",
"."
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/ParserFactory.php#L126-L144 |
oat-sa/extension-tao-itemqti | model/qti/ParserFactory.php | ParserFactory.buildItem | protected function buildItem(DOMElement $data){
//check on the root tag.
$itemId = (string) $data->getAttribute('identifier');
$this->logDebug('Started parsing of QTI item'.(isset($itemId) ? ' '.$itemId : ''), array('TAOITEMS'));
//create the item instance
$this->item = new Item($this->extractAttributes($data));
//load xml ns and schema locations
$this->loadNamespaces();
$this->loadSchemaLocations($data);
//load stylesheets
$styleSheetNodes = $this->queryXPath("*[name(.) = 'stylesheet']", $data);
foreach($styleSheetNodes as $styleSheetNode){
$styleSheet = $this->buildStylesheet($styleSheetNode);
$this->item->addStylesheet($styleSheet);
}
//extract the responses
$responseNodes = $this->queryXPath("*[name(.) = 'responseDeclaration']", $data);
foreach($responseNodes as $responseNode){
$response = $this->buildResponseDeclaration($responseNode);
if(!is_null($response)){
$this->item->addResponse($response);
}
}
//extract outcome variables
$outcomes = array();
$outComeNodes = $this->queryXPath("*[name(.) = 'outcomeDeclaration']", $data);
foreach($outComeNodes as $outComeNode){
$outcome = $this->buildOutcomeDeclaration($outComeNode);
if(!is_null($outcome)){
$outcomes[] = $outcome;
}
}
if(count($outcomes) > 0){
$this->item->setOutcomes($outcomes);
}
//extract modal feedbacks
$feedbackNodes = $this->queryXPath("*[name(.) = 'modalFeedback']", $data);
foreach($feedbackNodes as $feedbackNode){
$modalFeedback = $this->buildFeedback($feedbackNode);
if(!is_null($modalFeedback)){
$this->item->addModalFeedback($modalFeedback);
}
}
//extract the item structure to separate the structural/style content to the item content
$itemBodies = $this->queryXPath("*[name(.) = 'itemBody']", $data); // array with 1 or zero bodies
if($itemBodies === false){
$errors = libxml_get_errors();
if(count($errors) > 0){
$error = array_shift($errors);
$errormsg = $error->message;
}else{
$errormsg = "without errormessage";
}
throw new ParsingException('XML error('.$errormsg.') on itemBody read'.(isset($itemId) ? ' for item '.$itemId : ''));
}elseif($itemBodies->length){
$this->parseContainerItemBody($itemBodies->item(0), $this->item->getBody());
$this->item->addClass($itemBodies->item(0)->getAttribute('class'));
}
//warning: extract the response processing at the latest to make oat\taoQtiItem\model\qti\response\TemplatesDriven::takeOverFrom() work
$rpNodes = $this->queryXPath("*[name(.) = 'responseProcessing']", $data);
if($rpNodes->length === 0){
//no response processing node found: the template for an empty response processing is simply "NONE"
$rProcessing = new TemplatesDriven();
$rProcessing->setRelatedItem($this->item);
foreach($this->item->getInteractions() as $interaction){
$rProcessing->setTemplate($interaction->getResponse(), Template::NONE);
}
$this->item->setResponseProcessing($rProcessing);
}else{
//if there is a response processing node, try parsing it
$rpNode = $rpNodes->item(0);
$rProcessing = $this->buildResponseProcessing($rpNode, $this->item);
if(!is_null($rProcessing)){
$this->item->setResponseProcessing($rProcessing);
}
}
$this->buildApipAccessibility($data);
return $this->item;
} | php | protected function buildItem(DOMElement $data){
//check on the root tag.
$itemId = (string) $data->getAttribute('identifier');
$this->logDebug('Started parsing of QTI item'.(isset($itemId) ? ' '.$itemId : ''), array('TAOITEMS'));
//create the item instance
$this->item = new Item($this->extractAttributes($data));
//load xml ns and schema locations
$this->loadNamespaces();
$this->loadSchemaLocations($data);
//load stylesheets
$styleSheetNodes = $this->queryXPath("*[name(.) = 'stylesheet']", $data);
foreach($styleSheetNodes as $styleSheetNode){
$styleSheet = $this->buildStylesheet($styleSheetNode);
$this->item->addStylesheet($styleSheet);
}
//extract the responses
$responseNodes = $this->queryXPath("*[name(.) = 'responseDeclaration']", $data);
foreach($responseNodes as $responseNode){
$response = $this->buildResponseDeclaration($responseNode);
if(!is_null($response)){
$this->item->addResponse($response);
}
}
//extract outcome variables
$outcomes = array();
$outComeNodes = $this->queryXPath("*[name(.) = 'outcomeDeclaration']", $data);
foreach($outComeNodes as $outComeNode){
$outcome = $this->buildOutcomeDeclaration($outComeNode);
if(!is_null($outcome)){
$outcomes[] = $outcome;
}
}
if(count($outcomes) > 0){
$this->item->setOutcomes($outcomes);
}
//extract modal feedbacks
$feedbackNodes = $this->queryXPath("*[name(.) = 'modalFeedback']", $data);
foreach($feedbackNodes as $feedbackNode){
$modalFeedback = $this->buildFeedback($feedbackNode);
if(!is_null($modalFeedback)){
$this->item->addModalFeedback($modalFeedback);
}
}
//extract the item structure to separate the structural/style content to the item content
$itemBodies = $this->queryXPath("*[name(.) = 'itemBody']", $data); // array with 1 or zero bodies
if($itemBodies === false){
$errors = libxml_get_errors();
if(count($errors) > 0){
$error = array_shift($errors);
$errormsg = $error->message;
}else{
$errormsg = "without errormessage";
}
throw new ParsingException('XML error('.$errormsg.') on itemBody read'.(isset($itemId) ? ' for item '.$itemId : ''));
}elseif($itemBodies->length){
$this->parseContainerItemBody($itemBodies->item(0), $this->item->getBody());
$this->item->addClass($itemBodies->item(0)->getAttribute('class'));
}
//warning: extract the response processing at the latest to make oat\taoQtiItem\model\qti\response\TemplatesDriven::takeOverFrom() work
$rpNodes = $this->queryXPath("*[name(.) = 'responseProcessing']", $data);
if($rpNodes->length === 0){
//no response processing node found: the template for an empty response processing is simply "NONE"
$rProcessing = new TemplatesDriven();
$rProcessing->setRelatedItem($this->item);
foreach($this->item->getInteractions() as $interaction){
$rProcessing->setTemplate($interaction->getResponse(), Template::NONE);
}
$this->item->setResponseProcessing($rProcessing);
}else{
//if there is a response processing node, try parsing it
$rpNode = $rpNodes->item(0);
$rProcessing = $this->buildResponseProcessing($rpNode, $this->item);
if(!is_null($rProcessing)){
$this->item->setResponseProcessing($rProcessing);
}
}
$this->buildApipAccessibility($data);
return $this->item;
} | [
"protected",
"function",
"buildItem",
"(",
"DOMElement",
"$",
"data",
")",
"{",
"//check on the root tag.",
"$",
"itemId",
"=",
"(",
"string",
")",
"$",
"data",
"->",
"getAttribute",
"(",
"'identifier'",
")",
";",
"$",
"this",
"->",
"logDebug",
"(",
"'Starte... | Build a QTI_Item from a DOMElement, the root tag of which is root assessmentItem
@param DOMElement $data
@return \oat\taoQtiItem\model\qti\Item
@throws InvalidArgumentException
@throws ParsingException
@throws UnsupportedQtiElement | [
"Build",
"a",
"QTI_Item",
"from",
"a",
"DOMElement",
"the",
"root",
"tag",
"of",
"which",
"is",
"root",
"assessmentItem"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/ParserFactory.php#L511-L601 |
oat-sa/extension-tao-itemqti | model/qti/ParserFactory.php | ParserFactory.loadNamespaces | protected function loadNamespaces(){
$namespaces = [];
foreach($this->queryXPath('namespace::*') as $node){
$name = preg_replace('/xmlns(:)?/', '', $node->nodeName);
if($name !== 'xml'){//always removed the implicit xml namespace
$namespaces[$name] = $node->nodeValue;
}
}
ksort($namespaces);
foreach($namespaces as $name => $uri){
$this->item->addNamespace($name, $uri);
}
} | php | protected function loadNamespaces(){
$namespaces = [];
foreach($this->queryXPath('namespace::*') as $node){
$name = preg_replace('/xmlns(:)?/', '', $node->nodeName);
if($name !== 'xml'){//always removed the implicit xml namespace
$namespaces[$name] = $node->nodeValue;
}
}
ksort($namespaces);
foreach($namespaces as $name => $uri){
$this->item->addNamespace($name, $uri);
}
} | [
"protected",
"function",
"loadNamespaces",
"(",
")",
"{",
"$",
"namespaces",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"queryXPath",
"(",
"'namespace::*'",
")",
"as",
"$",
"node",
")",
"{",
"$",
"name",
"=",
"preg_replace",
"(",
"'/xmlns(:)?... | Load xml namespaces into the item model | [
"Load",
"xml",
"namespaces",
"into",
"the",
"item",
"model"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/ParserFactory.php#L606-L618 |
oat-sa/extension-tao-itemqti | model/qti/ParserFactory.php | ParserFactory.loadSchemaLocations | protected function loadSchemaLocations(DOMElement $itemData){
$schemaLoc = preg_replace('/\s+/', ' ', trim($itemData->getAttributeNS($itemData->lookupNamespaceURI('xsi'), 'schemaLocation')));
$schemaLocToken = explode(' ', $schemaLoc);
$schemaCount = count($schemaLocToken);
if($schemaCount%2){
throw new ParsingException('invalid schema location');
}
for($i=0; $i<$schemaCount; $i=$i+2){
$this->item->addSchemaLocation($schemaLocToken[$i], $schemaLocToken[$i+1]);
}
} | php | protected function loadSchemaLocations(DOMElement $itemData){
$schemaLoc = preg_replace('/\s+/', ' ', trim($itemData->getAttributeNS($itemData->lookupNamespaceURI('xsi'), 'schemaLocation')));
$schemaLocToken = explode(' ', $schemaLoc);
$schemaCount = count($schemaLocToken);
if($schemaCount%2){
throw new ParsingException('invalid schema location');
}
for($i=0; $i<$schemaCount; $i=$i+2){
$this->item->addSchemaLocation($schemaLocToken[$i], $schemaLocToken[$i+1]);
}
} | [
"protected",
"function",
"loadSchemaLocations",
"(",
"DOMElement",
"$",
"itemData",
")",
"{",
"$",
"schemaLoc",
"=",
"preg_replace",
"(",
"'/\\s+/'",
",",
"' '",
",",
"trim",
"(",
"$",
"itemData",
"->",
"getAttributeNS",
"(",
"$",
"itemData",
"->",
"lookupName... | Load xml schema locations into the item model
@param DOMElement $itemData
@throws ParsingException | [
"Load",
"xml",
"schema",
"locations",
"into",
"the",
"item",
"model"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/ParserFactory.php#L626-L636 |
oat-sa/extension-tao-itemqti | model/qti/ParserFactory.php | ParserFactory.buildInteraction | protected function buildInteraction(DOMElement $data){
$returnValue = null;
if($data->nodeName === 'customInteraction'){
$returnValue = $this->buildCustomInteraction($data);
}else{
//build one of the standard interaction
try{
$type = ucfirst($data->nodeName);
$interactionClass = '\\oat\\taoQtiItem\\model\\qti\\interaction\\'.$type;
if(!class_exists($interactionClass)){
throw new ParsingException('The interaction class cannot be found: '.$interactionClass);
}
$myInteraction = new $interactionClass($this->extractAttributes($data), $this->item);
if($myInteraction instanceof BlockInteraction){
//extract prompt:
$promptNodes = $this->queryXPath("*[name(.) = 'prompt']", $data); //prompt
foreach($promptNodes as $promptNode){
//only block interactions have prompt
$this->parseContainerStatic($promptNode, $myInteraction->getPrompt());
$this->deleteNode($promptNode);
}
}
//build the interaction's choices regarding it's type
switch(strtolower($type)){
case 'matchinteraction':
//extract simpleMatchSet choices
$matchSetNodes = $this->queryXPath("*[name(.) = 'simpleMatchSet']", $data); //simpleMatchSet
$matchSetNumber = 0;
foreach($matchSetNodes as $matchSetNode){
$choiceNodes = $this->queryXPath("*[name(.) = 'simpleAssociableChoice']", $matchSetNode); //simpleAssociableChoice
foreach($choiceNodes as $choiceNode){
$choice = $this->buildChoice($choiceNode);
if(!is_null($choice)){
$myInteraction->addChoice($choice, $matchSetNumber);
}
}
if(++$matchSetNumber === 2){
//matchSet is limited to 2 maximum
break;
}
}
break;
case 'gapmatchinteraction':
//create choices with the gapText nodes
$choiceNodes = $this->queryXPath("*[name(.)='gapText']", $data); //or gapImg!!
$choices = array();
foreach($choiceNodes as $choiceNode){
$choice = $this->buildChoice($choiceNode);
if(!is_null($choice)){
$myInteraction->addChoice($choice);
$this->deleteNode($choiceNode);
}
//remove node so it does not pollute subsequent parsing data
unset($choiceNode);
}
$this->parseContainerGap($data, $myInteraction->getBody());
break;
case 'hottextinteraction':
$this->parseContainerHottext($data, $myInteraction->getBody());
break;
case 'graphicgapmatchinteraction':
//create choices with the gapImg nodes
$choiceNodes = $this->queryXPath("*[name(.)='gapImg']", $data);
$choices = array();
foreach($choiceNodes as $choiceNode){
$choice = $this->buildChoice($choiceNode);
if(!is_null($choice)){
$myInteraction->addGapImg($choice);
}
}
default :
//parse, extract and build the choice nodes contained in the interaction
$exp = "*[contains(name(.),'Choice')] | *[name(.)='associableHotspot']";
$choiceNodes = $this->queryXPath($exp, $data);
foreach($choiceNodes as $choiceNode){
$choice = $this->buildChoice($choiceNode);
if(!is_null($choice)){
$myInteraction->addChoice($choice);
}
unset($choiceNode);
}
break;
}
if($myInteraction instanceof ObjectInteraction){
$objectNodes = $this->queryXPath("*[name(.)='object']", $data); //object
foreach($objectNodes as $objectNode){
$object = $this->buildObject($objectNode);
if(!is_null($object)){
$myInteraction->setObject($object);
}
}
}
$returnValue = $myInteraction;
}catch(InvalidArgumentException $iae){
throw new ParsingException($iae);
}
}
return $returnValue;
} | php | protected function buildInteraction(DOMElement $data){
$returnValue = null;
if($data->nodeName === 'customInteraction'){
$returnValue = $this->buildCustomInteraction($data);
}else{
//build one of the standard interaction
try{
$type = ucfirst($data->nodeName);
$interactionClass = '\\oat\\taoQtiItem\\model\\qti\\interaction\\'.$type;
if(!class_exists($interactionClass)){
throw new ParsingException('The interaction class cannot be found: '.$interactionClass);
}
$myInteraction = new $interactionClass($this->extractAttributes($data), $this->item);
if($myInteraction instanceof BlockInteraction){
//extract prompt:
$promptNodes = $this->queryXPath("*[name(.) = 'prompt']", $data); //prompt
foreach($promptNodes as $promptNode){
//only block interactions have prompt
$this->parseContainerStatic($promptNode, $myInteraction->getPrompt());
$this->deleteNode($promptNode);
}
}
//build the interaction's choices regarding it's type
switch(strtolower($type)){
case 'matchinteraction':
//extract simpleMatchSet choices
$matchSetNodes = $this->queryXPath("*[name(.) = 'simpleMatchSet']", $data); //simpleMatchSet
$matchSetNumber = 0;
foreach($matchSetNodes as $matchSetNode){
$choiceNodes = $this->queryXPath("*[name(.) = 'simpleAssociableChoice']", $matchSetNode); //simpleAssociableChoice
foreach($choiceNodes as $choiceNode){
$choice = $this->buildChoice($choiceNode);
if(!is_null($choice)){
$myInteraction->addChoice($choice, $matchSetNumber);
}
}
if(++$matchSetNumber === 2){
//matchSet is limited to 2 maximum
break;
}
}
break;
case 'gapmatchinteraction':
//create choices with the gapText nodes
$choiceNodes = $this->queryXPath("*[name(.)='gapText']", $data); //or gapImg!!
$choices = array();
foreach($choiceNodes as $choiceNode){
$choice = $this->buildChoice($choiceNode);
if(!is_null($choice)){
$myInteraction->addChoice($choice);
$this->deleteNode($choiceNode);
}
//remove node so it does not pollute subsequent parsing data
unset($choiceNode);
}
$this->parseContainerGap($data, $myInteraction->getBody());
break;
case 'hottextinteraction':
$this->parseContainerHottext($data, $myInteraction->getBody());
break;
case 'graphicgapmatchinteraction':
//create choices with the gapImg nodes
$choiceNodes = $this->queryXPath("*[name(.)='gapImg']", $data);
$choices = array();
foreach($choiceNodes as $choiceNode){
$choice = $this->buildChoice($choiceNode);
if(!is_null($choice)){
$myInteraction->addGapImg($choice);
}
}
default :
//parse, extract and build the choice nodes contained in the interaction
$exp = "*[contains(name(.),'Choice')] | *[name(.)='associableHotspot']";
$choiceNodes = $this->queryXPath($exp, $data);
foreach($choiceNodes as $choiceNode){
$choice = $this->buildChoice($choiceNode);
if(!is_null($choice)){
$myInteraction->addChoice($choice);
}
unset($choiceNode);
}
break;
}
if($myInteraction instanceof ObjectInteraction){
$objectNodes = $this->queryXPath("*[name(.)='object']", $data); //object
foreach($objectNodes as $objectNode){
$object = $this->buildObject($objectNode);
if(!is_null($object)){
$myInteraction->setObject($object);
}
}
}
$returnValue = $myInteraction;
}catch(InvalidArgumentException $iae){
throw new ParsingException($iae);
}
}
return $returnValue;
} | [
"protected",
"function",
"buildInteraction",
"(",
"DOMElement",
"$",
"data",
")",
"{",
"$",
"returnValue",
"=",
"null",
";",
"if",
"(",
"$",
"data",
"->",
"nodeName",
"===",
"'customInteraction'",
")",
"{",
"$",
"returnValue",
"=",
"$",
"this",
"->",
"buil... | Build a QTI_Interaction from a DOMElement (the root tag of this is an 'interaction' node)
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@param DOMElement $data
@return \oat\taoQtiItem\model\qti\interaction\Interaction
@throws ParsingException
@throws UnsupportedQtiElement
@throws interaction\InvalidArgumentException
@see http://www.imsglobal.org/question/qti_v2p0/imsqti_infov2p0.html#element10247 | [
"Build",
"a",
"QTI_Interaction",
"from",
"a",
"DOMElement",
"(",
"the",
"root",
"tag",
"of",
"this",
"is",
"an",
"interaction",
"node",
")"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/ParserFactory.php#L660-L778 |
oat-sa/extension-tao-itemqti | model/qti/ParserFactory.php | ParserFactory.buildChoice | protected function buildChoice(DOMElement $data){
$className = '\\oat\\taoQtiItem\\model\\qti\\choice\\'.ucfirst($data->nodeName);
if(!class_exists($className)){
throw new ParsingException("The choice class does not exist ".$className);
}
$myChoice = new $className($this->extractAttributes($data));
if($myChoice instanceof ContainerChoice){
$this->parseContainerStatic($data, $myChoice->getBody());
}elseif($myChoice instanceof TextVariableChoice){
//use getBodyData() instead of $data->nodeValue() to preserve xml entities
$myChoice->setContent($this->getBodyData($data));
}elseif($myChoice instanceof GapImg){
//extract the media object tag
$objectNodes = $this->queryXPath("*[name(.)='object']", $data);
foreach($objectNodes as $objectNode){
$object = $this->buildObject($objectNode);
$myChoice->setContent($object);
break;
}
}
return $myChoice;
} | php | protected function buildChoice(DOMElement $data){
$className = '\\oat\\taoQtiItem\\model\\qti\\choice\\'.ucfirst($data->nodeName);
if(!class_exists($className)){
throw new ParsingException("The choice class does not exist ".$className);
}
$myChoice = new $className($this->extractAttributes($data));
if($myChoice instanceof ContainerChoice){
$this->parseContainerStatic($data, $myChoice->getBody());
}elseif($myChoice instanceof TextVariableChoice){
//use getBodyData() instead of $data->nodeValue() to preserve xml entities
$myChoice->setContent($this->getBodyData($data));
}elseif($myChoice instanceof GapImg){
//extract the media object tag
$objectNodes = $this->queryXPath("*[name(.)='object']", $data);
foreach($objectNodes as $objectNode){
$object = $this->buildObject($objectNode);
$myChoice->setContent($object);
break;
}
}
return $myChoice;
} | [
"protected",
"function",
"buildChoice",
"(",
"DOMElement",
"$",
"data",
")",
"{",
"$",
"className",
"=",
"'\\\\oat\\\\taoQtiItem\\\\model\\\\qti\\\\choice\\\\'",
".",
"ucfirst",
"(",
"$",
"data",
"->",
"nodeName",
")",
";",
"if",
"(",
"!",
"class_exists",
"(",
"... | Build a QTI_Choice from a DOMElement (the root tag of this element
an 'choice' node)
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@param DOMElement $data
@return \oat\taoQtiItem\model\qti\choice\Choice
@throws ParsingException
@throws UnsupportedQtiElement
@throws choice\InvalidArgumentException
@see http://www.imsglobal.org/question/qti_v2p0/imsqti_infov2p0.html#element10254 | [
"Build",
"a",
"QTI_Choice",
"from",
"a",
"DOMElement",
"(",
"the",
"root",
"tag",
"of",
"this",
"element",
"an",
"choice",
"node",
")"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/ParserFactory.php#L793-L818 |
oat-sa/extension-tao-itemqti | model/qti/ParserFactory.php | ParserFactory.buildResponseDeclaration | protected function buildResponseDeclaration(DOMElement $data){
$myResponse = new ResponseDeclaration($this->extractAttributes($data), $this->item);
$data = simplexml_import_dom($data);
//set the correct responses
$correctResponseNodes = $data->xpath("*[name(.) = 'correctResponse']");
$responses = array();
foreach($correctResponseNodes as $correctResponseNode){
foreach($correctResponseNode->value as $value){
$correct = (string) $value;
$response = new Value();
foreach($value->attributes() as $attrName => $attrValue){
$response->setAttribute($attrName, strval($attrValue));
}
$response->setValue($correct);
$responses[] = $response;
}
break;
}
$myResponse->setCorrectResponses($responses);
//set the correct responses
$defaultValueNodes = $data->xpath("*[name(.) = 'defaultValue']");
$defaultValues = array();
foreach($defaultValueNodes as $defaultValueNode){
foreach($defaultValueNode->value as $value){
$default = (string) $value;
$defaultValue = new Value();
foreach($value->attributes() as $attrName => $attrValue){
$defaultValue->setAttribute($attrName, strval($attrValue));
}
$defaultValue->setValue($default);
$defaultValues[] = $defaultValue;
}
break;
}
$myResponse->setDefaultValue($defaultValues);
//set the mapping if defined
$mappingNodes = $data->xpath("*[name(.) = 'mapping']");
foreach($mappingNodes as $mappingNode){
if(isset($mappingNode['defaultValue'])){
$myResponse->setMappingDefaultValue(floatval((string) $mappingNode['defaultValue']));
}
$mappingOptions = array();
foreach($mappingNode->attributes() as $key => $value){
if($key != 'defaultValue'){
$mappingOptions[$key] = (string) $value;
}
}
$myResponse->setAttribute('mapping', $mappingOptions);
$mapping = array();
foreach($mappingNode->mapEntry as $mapEntry){
$mapping[(string) $mapEntry['mapKey']] = (string) $mapEntry['mappedValue'];
}
$myResponse->setMapping($mapping);
break;
}
//set the areaMapping if defined
$mappingNodes = $data->xpath("*[name(.) = 'areaMapping']");
foreach($mappingNodes as $mappingNode){
if(isset($mappingNode['defaultValue'])){
$myResponse->setMappingDefaultValue(floatval((string) $mappingNode['defaultValue']));
}
$mappingOptions = array();
foreach($mappingNode->attributes() as $key => $value){
if($key != 'defaultValue'){
$mappingOptions[$key] = (string) $value;
}
}
$myResponse->setAttribute('areaMapping', $mappingOptions);
$mapping = array();
foreach($mappingNode->areaMapEntry as $mapEntry){
$mappingAttributes = array();
foreach($mapEntry->attributes() as $key => $value){
$mappingAttributes[(string) $key] = (string) $value;
}
$mapping[] = $mappingAttributes;
}
$myResponse->setMapping($mapping, 'area');
break;
}
return $myResponse;
} | php | protected function buildResponseDeclaration(DOMElement $data){
$myResponse = new ResponseDeclaration($this->extractAttributes($data), $this->item);
$data = simplexml_import_dom($data);
//set the correct responses
$correctResponseNodes = $data->xpath("*[name(.) = 'correctResponse']");
$responses = array();
foreach($correctResponseNodes as $correctResponseNode){
foreach($correctResponseNode->value as $value){
$correct = (string) $value;
$response = new Value();
foreach($value->attributes() as $attrName => $attrValue){
$response->setAttribute($attrName, strval($attrValue));
}
$response->setValue($correct);
$responses[] = $response;
}
break;
}
$myResponse->setCorrectResponses($responses);
//set the correct responses
$defaultValueNodes = $data->xpath("*[name(.) = 'defaultValue']");
$defaultValues = array();
foreach($defaultValueNodes as $defaultValueNode){
foreach($defaultValueNode->value as $value){
$default = (string) $value;
$defaultValue = new Value();
foreach($value->attributes() as $attrName => $attrValue){
$defaultValue->setAttribute($attrName, strval($attrValue));
}
$defaultValue->setValue($default);
$defaultValues[] = $defaultValue;
}
break;
}
$myResponse->setDefaultValue($defaultValues);
//set the mapping if defined
$mappingNodes = $data->xpath("*[name(.) = 'mapping']");
foreach($mappingNodes as $mappingNode){
if(isset($mappingNode['defaultValue'])){
$myResponse->setMappingDefaultValue(floatval((string) $mappingNode['defaultValue']));
}
$mappingOptions = array();
foreach($mappingNode->attributes() as $key => $value){
if($key != 'defaultValue'){
$mappingOptions[$key] = (string) $value;
}
}
$myResponse->setAttribute('mapping', $mappingOptions);
$mapping = array();
foreach($mappingNode->mapEntry as $mapEntry){
$mapping[(string) $mapEntry['mapKey']] = (string) $mapEntry['mappedValue'];
}
$myResponse->setMapping($mapping);
break;
}
//set the areaMapping if defined
$mappingNodes = $data->xpath("*[name(.) = 'areaMapping']");
foreach($mappingNodes as $mappingNode){
if(isset($mappingNode['defaultValue'])){
$myResponse->setMappingDefaultValue(floatval((string) $mappingNode['defaultValue']));
}
$mappingOptions = array();
foreach($mappingNode->attributes() as $key => $value){
if($key != 'defaultValue'){
$mappingOptions[$key] = (string) $value;
}
}
$myResponse->setAttribute('areaMapping', $mappingOptions);
$mapping = array();
foreach($mappingNode->areaMapEntry as $mapEntry){
$mappingAttributes = array();
foreach($mapEntry->attributes() as $key => $value){
$mappingAttributes[(string) $key] = (string) $value;
}
$mapping[] = $mappingAttributes;
}
$myResponse->setMapping($mapping, 'area');
break;
}
return $myResponse;
} | [
"protected",
"function",
"buildResponseDeclaration",
"(",
"DOMElement",
"$",
"data",
")",
"{",
"$",
"myResponse",
"=",
"new",
"ResponseDeclaration",
"(",
"$",
"this",
"->",
"extractAttributes",
"(",
"$",
"data",
")",
",",
"$",
"this",
"->",
"item",
")",
";",... | Short description of method buildResponseDeclaration
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@param DOMElement $data
@return \oat\taoQtiItem\model\qti\ResponseDeclaration
@see http://www.imsglobal.org/question/qti_v2p0/imsqti_infov2p0.html#element10074 | [
"Short",
"description",
"of",
"method",
"buildResponseDeclaration"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/ParserFactory.php#L829-L921 |
oat-sa/extension-tao-itemqti | model/qti/ParserFactory.php | ParserFactory.buildOutcomeDeclaration | protected function buildOutcomeDeclaration(DOMElement $data){
$outcome = new OutcomeDeclaration($this->extractAttributes($data));
$data = simplexml_import_dom($data);
if(isset($data->defaultValue)){
if(!is_null($data->defaultValue->value)){
$outcome->setDefaultValue((string) $data->defaultValue->value);
}
}
return $outcome;
} | php | protected function buildOutcomeDeclaration(DOMElement $data){
$outcome = new OutcomeDeclaration($this->extractAttributes($data));
$data = simplexml_import_dom($data);
if(isset($data->defaultValue)){
if(!is_null($data->defaultValue->value)){
$outcome->setDefaultValue((string) $data->defaultValue->value);
}
}
return $outcome;
} | [
"protected",
"function",
"buildOutcomeDeclaration",
"(",
"DOMElement",
"$",
"data",
")",
"{",
"$",
"outcome",
"=",
"new",
"OutcomeDeclaration",
"(",
"$",
"this",
"->",
"extractAttributes",
"(",
"$",
"data",
")",
")",
";",
"$",
"data",
"=",
"simplexml_import_do... | Short description of method buildOutcomeDeclaration
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@param DOMElement data
@return oat\taoQtiItem\model\qti\OutcomeDeclaration | [
"Short",
"description",
"of",
"method",
"buildOutcomeDeclaration"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/ParserFactory.php#L931-L943 |
oat-sa/extension-tao-itemqti | model/qti/ParserFactory.php | ParserFactory.buildTemplateResponseProcessing | protected function buildTemplateResponseProcessing(DOMElement $data){
$returnValue = null;
if($data->hasAttribute('template') && $data->childNodes->length === 0){
$templateUri = (string) $data->getAttribute('template');
$returnValue = new Template($templateUri);
}elseif($data->childNodes->length === 1){
//check response declaration identifier, which must be RESPONSE in standard rp
$responses = $this->item->getResponses();
if(count($responses) == 1){
$response = reset($responses);
if($response->getIdentifier() !== 'RESPONSE'){
throw new UnexpectedResponseProcessing('the response declaration identifier must be RESPONSE');
}
}else{
//invalid number of response declaration
throw new UnexpectedResponseProcessing('the item must have exactly one response declaration');
}
$patternCorrectIMS = 'responseCondition [count(./*) = 2 ] [name(./*[1]) = "responseIf" ] [count(./responseIf/*) = 2 ] [name(./responseIf/*[1]) = "match" ] [name(./responseIf/match/*[1]) = "variable" ] [name(./responseIf/match/*[2]) = "correct" ] [name(./responseIf/*[2]) = "setOutcomeValue" ] [name(./responseIf/setOutcomeValue/*[1]) = "baseValue" ] [name(./*[2]) = "responseElse" ] [count(./responseElse/*) = 1 ] [name(./responseElse/*[1]) = "setOutcomeValue" ] [name(./responseElse/setOutcomeValue/*[1]) = "baseValue"]';
$patternMappingIMS = 'responseCondition [count(./*) = 2] [name(./*[1]) = "responseIf"] [count(./responseIf/*) = 2] [name(./responseIf/*[1]) = "isNull"] [name(./responseIf/isNull/*[1]) = "variable"] [name(./responseIf/*[2]) = "setOutcomeValue"] [name(./responseIf/setOutcomeValue/*[1]) = "variable"] [name(./*[2]) = "responseElse"] [count(./responseElse/*) = 1] [name(./responseElse/*[1]) = "setOutcomeValue"] [name(./responseElse/setOutcomeValue/*[1]) = "mapResponse"]';
$patternMappingPointIMS = 'responseCondition [count(./*) = 2] [name(./*[1]) = "responseIf"] [count(./responseIf/*) = 2] [name(./responseIf/*[1]) = "isNull"] [name(./responseIf/isNull/*[1]) = "variable"] [name(./responseIf/*[2]) = "setOutcomeValue"] [name(./responseIf/setOutcomeValue/*[1]) = "variable"] [name(./*[2]) = "responseElse"] [count(./responseElse/*) = 1] [name(./responseElse/*[1]) = "setOutcomeValue"] [name(./responseElse/setOutcomeValue/*[1]) = "mapResponsePoint"]';
if(count($this->queryXPath($patternCorrectIMS)) == 1){
$returnValue = new Template(Template::MATCH_CORRECT);
}elseif(count($this->queryXPath($patternMappingIMS)) == 1){
$returnValue = new Template(Template::MAP_RESPONSE);
}elseif(count($this->queryXPath($patternMappingPointIMS)) == 1){
$returnValue = new Template(Template::MAP_RESPONSE_POINT);
}else{
throw new UnexpectedResponseProcessing('not Template, wrong rule');
}
$returnValue->setRelatedItem($this->item);
}else{
throw new UnexpectedResponseProcessing('not Template');
}
return $returnValue;
} | php | protected function buildTemplateResponseProcessing(DOMElement $data){
$returnValue = null;
if($data->hasAttribute('template') && $data->childNodes->length === 0){
$templateUri = (string) $data->getAttribute('template');
$returnValue = new Template($templateUri);
}elseif($data->childNodes->length === 1){
//check response declaration identifier, which must be RESPONSE in standard rp
$responses = $this->item->getResponses();
if(count($responses) == 1){
$response = reset($responses);
if($response->getIdentifier() !== 'RESPONSE'){
throw new UnexpectedResponseProcessing('the response declaration identifier must be RESPONSE');
}
}else{
//invalid number of response declaration
throw new UnexpectedResponseProcessing('the item must have exactly one response declaration');
}
$patternCorrectIMS = 'responseCondition [count(./*) = 2 ] [name(./*[1]) = "responseIf" ] [count(./responseIf/*) = 2 ] [name(./responseIf/*[1]) = "match" ] [name(./responseIf/match/*[1]) = "variable" ] [name(./responseIf/match/*[2]) = "correct" ] [name(./responseIf/*[2]) = "setOutcomeValue" ] [name(./responseIf/setOutcomeValue/*[1]) = "baseValue" ] [name(./*[2]) = "responseElse" ] [count(./responseElse/*) = 1 ] [name(./responseElse/*[1]) = "setOutcomeValue" ] [name(./responseElse/setOutcomeValue/*[1]) = "baseValue"]';
$patternMappingIMS = 'responseCondition [count(./*) = 2] [name(./*[1]) = "responseIf"] [count(./responseIf/*) = 2] [name(./responseIf/*[1]) = "isNull"] [name(./responseIf/isNull/*[1]) = "variable"] [name(./responseIf/*[2]) = "setOutcomeValue"] [name(./responseIf/setOutcomeValue/*[1]) = "variable"] [name(./*[2]) = "responseElse"] [count(./responseElse/*) = 1] [name(./responseElse/*[1]) = "setOutcomeValue"] [name(./responseElse/setOutcomeValue/*[1]) = "mapResponse"]';
$patternMappingPointIMS = 'responseCondition [count(./*) = 2] [name(./*[1]) = "responseIf"] [count(./responseIf/*) = 2] [name(./responseIf/*[1]) = "isNull"] [name(./responseIf/isNull/*[1]) = "variable"] [name(./responseIf/*[2]) = "setOutcomeValue"] [name(./responseIf/setOutcomeValue/*[1]) = "variable"] [name(./*[2]) = "responseElse"] [count(./responseElse/*) = 1] [name(./responseElse/*[1]) = "setOutcomeValue"] [name(./responseElse/setOutcomeValue/*[1]) = "mapResponsePoint"]';
if(count($this->queryXPath($patternCorrectIMS)) == 1){
$returnValue = new Template(Template::MATCH_CORRECT);
}elseif(count($this->queryXPath($patternMappingIMS)) == 1){
$returnValue = new Template(Template::MAP_RESPONSE);
}elseif(count($this->queryXPath($patternMappingPointIMS)) == 1){
$returnValue = new Template(Template::MAP_RESPONSE_POINT);
}else{
throw new UnexpectedResponseProcessing('not Template, wrong rule');
}
$returnValue->setRelatedItem($this->item);
}else{
throw new UnexpectedResponseProcessing('not Template');
}
return $returnValue;
} | [
"protected",
"function",
"buildTemplateResponseProcessing",
"(",
"DOMElement",
"$",
"data",
")",
"{",
"$",
"returnValue",
"=",
"null",
";",
"if",
"(",
"$",
"data",
"->",
"hasAttribute",
"(",
"'template'",
")",
"&&",
"$",
"data",
"->",
"childNodes",
"->",
"le... | Short description of method buildTemplateResponseProcessing
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@param DOMElement data
@return oat\taoQtiItem\model\qti\response\ResponseProcessing | [
"Short",
"description",
"of",
"method",
"buildTemplateResponseProcessing"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/ParserFactory.php#L953-L991 |
oat-sa/extension-tao-itemqti | model/qti/ParserFactory.php | ParserFactory.buildResponseProcessing | protected function buildResponseProcessing(DOMElement $data, Item $item){
$returnValue = null;
// try template
try{
$returnValue = $this->buildTemplateResponseProcessing($data);
try{
//warning: require to add interactions to the item to make it work
$returnValue = TemplatesDriven::takeOverFrom($returnValue, $item);
}catch(TakeoverFailedException $e){}
}catch(UnexpectedResponseProcessing $e){
}
//try templatedriven
if(is_null($returnValue)){
try{
$returnValue = $this->buildTemplatedrivenResponse($data, $item->getInteractions());
}catch(UnexpectedResponseProcessing $e){}
}
// build custom
if(is_null($returnValue)){
try{
$returnValue = $this->buildCustomResponseProcessing($data);
}catch(UnexpectedResponseProcessing $e){
// not a Template
common_Logger::e('custom response processing failed', array('TAOITEMS', 'QTI'));
}
}
if(is_null($returnValue)){
common_Logger::w('failed to determine ResponseProcessing');
}
return $returnValue;
} | php | protected function buildResponseProcessing(DOMElement $data, Item $item){
$returnValue = null;
// try template
try{
$returnValue = $this->buildTemplateResponseProcessing($data);
try{
//warning: require to add interactions to the item to make it work
$returnValue = TemplatesDriven::takeOverFrom($returnValue, $item);
}catch(TakeoverFailedException $e){}
}catch(UnexpectedResponseProcessing $e){
}
//try templatedriven
if(is_null($returnValue)){
try{
$returnValue = $this->buildTemplatedrivenResponse($data, $item->getInteractions());
}catch(UnexpectedResponseProcessing $e){}
}
// build custom
if(is_null($returnValue)){
try{
$returnValue = $this->buildCustomResponseProcessing($data);
}catch(UnexpectedResponseProcessing $e){
// not a Template
common_Logger::e('custom response processing failed', array('TAOITEMS', 'QTI'));
}
}
if(is_null($returnValue)){
common_Logger::w('failed to determine ResponseProcessing');
}
return $returnValue;
} | [
"protected",
"function",
"buildResponseProcessing",
"(",
"DOMElement",
"$",
"data",
",",
"Item",
"$",
"item",
")",
"{",
"$",
"returnValue",
"=",
"null",
";",
"// try template",
"try",
"{",
"$",
"returnValue",
"=",
"$",
"this",
"->",
"buildTemplateResponseProcess... | Short description of method buildResponseProcessing
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@param DOMElement data
@param Item item
@return oat\taoQtiItem\model\qti\response\ResponseProcessing | [
"Short",
"description",
"of",
"method",
"buildResponseProcessing"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/ParserFactory.php#L1002-L1039 |
oat-sa/extension-tao-itemqti | model/qti/ParserFactory.php | ParserFactory.buildCompositeResponseProcessing | protected function buildCompositeResponseProcessing(DOMElement $data, Item $item){
$returnValue = null;
// STRONGLY simplified summation detection
$patternCorrectTAO = '/responseCondition [count(./*) = 1 ] [name(./*[1]) = "responseIf" ] [count(./responseIf/*) = 2 ] [name(./responseIf/*[1]) = "match" ] [name(./responseIf/match/*[1]) = "variable" ] [name(./responseIf/match/*[2]) = "correct" ] [name(./responseIf/*[2]) = "setOutcomeValue" ] [count(./responseIf/setOutcomeValue/*) = 1 ] [name(./responseIf/setOutcomeValue/*[1]) = "baseValue"]';
$patternMapTAO = '/responseCondition [count(./*) = 1 ] [name(./*[1]) = "responseIf" ] [count(./responseIf/*) = 2 ] [name(./responseIf/*[1]) = "not" ] [count(./responseIf/not/*) = 1 ] [name(./responseIf/not/*[1]) = "isNull" ] [count(./responseIf/not/isNull/*) = 1 ] [name(./responseIf/not/isNull/*[1]) = "variable" ] [name(./responseIf/*[2]) = "setOutcomeValue" ] [count(./responseIf/setOutcomeValue/*) = 1 ] [name(./responseIf/setOutcomeValue/*[1]) = "mapResponse"]';
$patternMapPointTAO = '/responseCondition [count(./*) = 1 ] [name(./*[1]) = "responseIf" ] [count(./responseIf/*) = 2 ] [name(./responseIf/*[1]) = "not" ] [count(./responseIf/not/*) = 1 ] [name(./responseIf/not/*[1]) = "isNull" ] [count(./responseIf/not/isNull/*) = 1 ] [name(./responseIf/not/isNull/*[1]) = "variable" ] [name(./responseIf/*[2]) = "setOutcomeValue" ] [count(./responseIf/setOutcomeValue/*) = 1 ] [name(./responseIf/setOutcomeValue/*[1]) = "mapResponsePoint"]';
$patternNoneTAO = '/responseCondition [count(./*) = 1 ] [name(./*[1]) = "responseIf" ] [count(./responseIf/*) = 2 ] [name(./responseIf/*[1]) = "isNull" ] [count(./responseIf/isNull/*) = 1 ] [name(./responseIf/isNull/*[1]) = "variable" ] [name(./responseIf/*[2]) = "setOutcomeValue" ] [count(./responseIf/setOutcomeValue/*) = 1 ] [name(./responseIf/setOutcomeValue/*[1]) = "baseValue"]';
$possibleSummation = '/setOutcomeValue [count(./*) = 1 ] [name(./*[1]) = "sum" ]';
$irps = array();
$composition = null;
$data = simplexml_import_dom($data);
foreach($data as $responseRule){
if(!is_null($composition)){
throw new UnexpectedResponseProcessing('Not composite, rules after composition');
}
$subtree = new SimpleXMLElement($responseRule->asXML());
if(count($subtree->xpath($patternCorrectTAO)) > 0){
$responseIdentifier = (string) $subtree->responseIf->match->variable[0]['identifier'];
$irps[$responseIdentifier] = array(
'class' => 'MatchCorrectTemplate',
'outcome' => (string) $subtree->responseIf->setOutcomeValue[0]['identifier']
);
}elseif(count($subtree->xpath($patternMapTAO)) > 0){
$responseIdentifier = (string) $subtree->responseIf->not->isNull->variable[0]['identifier'];
$irps[$responseIdentifier] = array(
'class' => 'MapResponseTemplate',
'outcome' => (string) $subtree->responseIf->setOutcomeValue[0]['identifier']
);
}elseif(count($subtree->xpath($patternMapPointTAO)) > 0){
$responseIdentifier = (string) $subtree->responseIf->not->isNull->variable[0]['identifier'];
$irps[$responseIdentifier] = array(
'class' => 'MapResponsePointTemplate',
'outcome' => (string) $subtree->responseIf->setOutcomeValue[0]['identifier']
);
}elseif(count($subtree->xpath($patternNoneTAO)) > 0){
$responseIdentifier = (string) $subtree->responseIf->isNull->variable[0]['identifier'];
$irps[$responseIdentifier] = array(
'class' => 'None',
'outcome' => (string) $subtree->responseIf->setOutcomeValue[0]['identifier'],
'default' => (string) $subtree->responseIf->setOutcomeValue[0]->baseValue[0]
);
}elseif(count($subtree->xpath($possibleSummation)) > 0){
$composition = 'Summation';
$outcomesUsed = array();
foreach($subtree->xpath('/setOutcomeValue/sum/variable') as $var){
$outcomesUsed[] = (string) $var[0]['identifier'];
}
}else{
throw new UnexpectedResponseProcessing('Not composite, unknown rule');
}
}
if(is_null($composition)){
throw new UnexpectedResponseProcessing('Not composit, Composition rule missing');
}
$responses = array();
foreach($item->getInteractions() as $interaction){
$responses[$interaction->getResponse()->getIdentifier()] = $interaction->getResponse();
}
if(count(array_diff(array_keys($irps), array_keys($responses))) > 0){
throw new UnexpectedResponseProcessing('Not composite, no responses for rules: '.implode(',', array_diff(array_keys($irps), array_keys($responses))));
}
if(count(array_diff(array_keys($responses), array_keys($irps))) > 0){
throw new UnexpectedResponseProcessing('Not composite, no support for unmatched variables yet');
}
//assuming sum is correct
$compositonRP = new Summation($item);
foreach($responses as $id => $response){
$outcome = null;
foreach($item->getOutcomes() as $possibleOutcome){
if($possibleOutcome->getIdentifier() == $irps[$id]['outcome']){
$outcome = $possibleOutcome;
break;
}
}
if(is_null($outcome)){
throw new ParsingException('Undeclared Outcome in ResponseProcessing');
}
$classname = '\\oat\\taoQtiItem\\model\\qti\\response\\interactionResponseProcessing\\'.$irps[$id]['class'];
$irp = new $classname($response, $outcome);
if($irp instanceof \oat\taoQtiItem\model\qti\response\interactionResponseProcessing\None && isset($irps[$id]['default'])){
$irp->setDefaultValue($irps[$id]['default']);
}
$compositonRP->add($irp);
}
$returnValue = $compositonRP;
return $returnValue;
} | php | protected function buildCompositeResponseProcessing(DOMElement $data, Item $item){
$returnValue = null;
// STRONGLY simplified summation detection
$patternCorrectTAO = '/responseCondition [count(./*) = 1 ] [name(./*[1]) = "responseIf" ] [count(./responseIf/*) = 2 ] [name(./responseIf/*[1]) = "match" ] [name(./responseIf/match/*[1]) = "variable" ] [name(./responseIf/match/*[2]) = "correct" ] [name(./responseIf/*[2]) = "setOutcomeValue" ] [count(./responseIf/setOutcomeValue/*) = 1 ] [name(./responseIf/setOutcomeValue/*[1]) = "baseValue"]';
$patternMapTAO = '/responseCondition [count(./*) = 1 ] [name(./*[1]) = "responseIf" ] [count(./responseIf/*) = 2 ] [name(./responseIf/*[1]) = "not" ] [count(./responseIf/not/*) = 1 ] [name(./responseIf/not/*[1]) = "isNull" ] [count(./responseIf/not/isNull/*) = 1 ] [name(./responseIf/not/isNull/*[1]) = "variable" ] [name(./responseIf/*[2]) = "setOutcomeValue" ] [count(./responseIf/setOutcomeValue/*) = 1 ] [name(./responseIf/setOutcomeValue/*[1]) = "mapResponse"]';
$patternMapPointTAO = '/responseCondition [count(./*) = 1 ] [name(./*[1]) = "responseIf" ] [count(./responseIf/*) = 2 ] [name(./responseIf/*[1]) = "not" ] [count(./responseIf/not/*) = 1 ] [name(./responseIf/not/*[1]) = "isNull" ] [count(./responseIf/not/isNull/*) = 1 ] [name(./responseIf/not/isNull/*[1]) = "variable" ] [name(./responseIf/*[2]) = "setOutcomeValue" ] [count(./responseIf/setOutcomeValue/*) = 1 ] [name(./responseIf/setOutcomeValue/*[1]) = "mapResponsePoint"]';
$patternNoneTAO = '/responseCondition [count(./*) = 1 ] [name(./*[1]) = "responseIf" ] [count(./responseIf/*) = 2 ] [name(./responseIf/*[1]) = "isNull" ] [count(./responseIf/isNull/*) = 1 ] [name(./responseIf/isNull/*[1]) = "variable" ] [name(./responseIf/*[2]) = "setOutcomeValue" ] [count(./responseIf/setOutcomeValue/*) = 1 ] [name(./responseIf/setOutcomeValue/*[1]) = "baseValue"]';
$possibleSummation = '/setOutcomeValue [count(./*) = 1 ] [name(./*[1]) = "sum" ]';
$irps = array();
$composition = null;
$data = simplexml_import_dom($data);
foreach($data as $responseRule){
if(!is_null($composition)){
throw new UnexpectedResponseProcessing('Not composite, rules after composition');
}
$subtree = new SimpleXMLElement($responseRule->asXML());
if(count($subtree->xpath($patternCorrectTAO)) > 0){
$responseIdentifier = (string) $subtree->responseIf->match->variable[0]['identifier'];
$irps[$responseIdentifier] = array(
'class' => 'MatchCorrectTemplate',
'outcome' => (string) $subtree->responseIf->setOutcomeValue[0]['identifier']
);
}elseif(count($subtree->xpath($patternMapTAO)) > 0){
$responseIdentifier = (string) $subtree->responseIf->not->isNull->variable[0]['identifier'];
$irps[$responseIdentifier] = array(
'class' => 'MapResponseTemplate',
'outcome' => (string) $subtree->responseIf->setOutcomeValue[0]['identifier']
);
}elseif(count($subtree->xpath($patternMapPointTAO)) > 0){
$responseIdentifier = (string) $subtree->responseIf->not->isNull->variable[0]['identifier'];
$irps[$responseIdentifier] = array(
'class' => 'MapResponsePointTemplate',
'outcome' => (string) $subtree->responseIf->setOutcomeValue[0]['identifier']
);
}elseif(count($subtree->xpath($patternNoneTAO)) > 0){
$responseIdentifier = (string) $subtree->responseIf->isNull->variable[0]['identifier'];
$irps[$responseIdentifier] = array(
'class' => 'None',
'outcome' => (string) $subtree->responseIf->setOutcomeValue[0]['identifier'],
'default' => (string) $subtree->responseIf->setOutcomeValue[0]->baseValue[0]
);
}elseif(count($subtree->xpath($possibleSummation)) > 0){
$composition = 'Summation';
$outcomesUsed = array();
foreach($subtree->xpath('/setOutcomeValue/sum/variable') as $var){
$outcomesUsed[] = (string) $var[0]['identifier'];
}
}else{
throw new UnexpectedResponseProcessing('Not composite, unknown rule');
}
}
if(is_null($composition)){
throw new UnexpectedResponseProcessing('Not composit, Composition rule missing');
}
$responses = array();
foreach($item->getInteractions() as $interaction){
$responses[$interaction->getResponse()->getIdentifier()] = $interaction->getResponse();
}
if(count(array_diff(array_keys($irps), array_keys($responses))) > 0){
throw new UnexpectedResponseProcessing('Not composite, no responses for rules: '.implode(',', array_diff(array_keys($irps), array_keys($responses))));
}
if(count(array_diff(array_keys($responses), array_keys($irps))) > 0){
throw new UnexpectedResponseProcessing('Not composite, no support for unmatched variables yet');
}
//assuming sum is correct
$compositonRP = new Summation($item);
foreach($responses as $id => $response){
$outcome = null;
foreach($item->getOutcomes() as $possibleOutcome){
if($possibleOutcome->getIdentifier() == $irps[$id]['outcome']){
$outcome = $possibleOutcome;
break;
}
}
if(is_null($outcome)){
throw new ParsingException('Undeclared Outcome in ResponseProcessing');
}
$classname = '\\oat\\taoQtiItem\\model\\qti\\response\\interactionResponseProcessing\\'.$irps[$id]['class'];
$irp = new $classname($response, $outcome);
if($irp instanceof \oat\taoQtiItem\model\qti\response\interactionResponseProcessing\None && isset($irps[$id]['default'])){
$irp->setDefaultValue($irps[$id]['default']);
}
$compositonRP->add($irp);
}
$returnValue = $compositonRP;
return $returnValue;
} | [
"protected",
"function",
"buildCompositeResponseProcessing",
"(",
"DOMElement",
"$",
"data",
",",
"Item",
"$",
"item",
")",
"{",
"$",
"returnValue",
"=",
"null",
";",
"// STRONGLY simplified summation detection",
"$",
"patternCorrectTAO",
"=",
"'/responseCondition [count(... | Short description of method buildCompositeResponseProcessing
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@param DOMElement data
@param Item item
@return oat\taoQtiItem\model\qti\response\ResponseProcessing | [
"Short",
"description",
"of",
"method",
"buildCompositeResponseProcessing"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/ParserFactory.php#L1050-L1147 |
oat-sa/extension-tao-itemqti | model/qti/ParserFactory.php | ParserFactory.buildCustomResponseProcessing | protected function buildCustomResponseProcessing(DOMElement $data){
// Parse to find the different response rules
$responseRules = array();
$data = simplexml_import_dom($data);
$returnValue = new Custom($responseRules, $data->asXml());
return $returnValue;
} | php | protected function buildCustomResponseProcessing(DOMElement $data){
// Parse to find the different response rules
$responseRules = array();
$data = simplexml_import_dom($data);
$returnValue = new Custom($responseRules, $data->asXml());
return $returnValue;
} | [
"protected",
"function",
"buildCustomResponseProcessing",
"(",
"DOMElement",
"$",
"data",
")",
"{",
"// Parse to find the different response rules",
"$",
"responseRules",
"=",
"array",
"(",
")",
";",
"$",
"data",
"=",
"simplexml_import_dom",
"(",
"$",
"data",
")",
"... | Short description of method buildCustomResponseProcessing
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@param DOMElement data
@return oat\taoQtiItem\model\qti\response\ResponseProcessing | [
"Short",
"description",
"of",
"method",
"buildCustomResponseProcessing"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/ParserFactory.php#L1157-L1167 |
oat-sa/extension-tao-itemqti | model/qti/ParserFactory.php | ParserFactory.buildTemplatedrivenResponse | protected function buildTemplatedrivenResponse(DOMElement $data, $interactions){
$patternCorrectTAO = '/responseCondition [count(./*) = 1 ] [name(./*[1]) = "responseIf" ] [count(./responseIf/*) = 2 ] [name(./responseIf/*[1]) = "match" ] [name(./responseIf/match/*[1]) = "variable" ] [name(./responseIf/match/*[2]) = "correct" ] [name(./responseIf/*[2]) = "setOutcomeValue" ] [name(./responseIf/setOutcomeValue/*[1]) = "sum" ] [name(./responseIf/setOutcomeValue/sum/*[1]) = "variable" ] [name(./responseIf/setOutcomeValue/sum/*[2]) = "baseValue"]';
$patternMappingTAO = '/responseCondition [count(./*) = 1] [name(./*[1]) = "responseIf"] [count(./responseIf/*) = 2] [name(./responseIf/*[1]) = "not"] [name(./responseIf/not/*[1]) = "isNull"] [name(./responseIf/not/isNull/*[1]) = "variable"] [name(./responseIf/*[2]) = "setOutcomeValue"] [name(./responseIf/setOutcomeValue/*[1]) = "sum"] [name(./responseIf/setOutcomeValue/sum/*[1]) = "variable"] [name(./responseIf/setOutcomeValue/sum/*[2]) = "mapResponse"]';
$patternMappingPointTAO = '/responseCondition [count(./*) = 1] [name(./*[1]) = "responseIf"] [count(./responseIf/*) = 2] [name(./responseIf/*[1]) = "not"] [name(./responseIf/not/*[1]) = "isNull"] [name(./responseIf/not/isNull/*[1]) = "variable"] [name(./responseIf/*[2]) = "setOutcomeValue"] [name(./responseIf/setOutcomeValue/*[1]) = "sum"] [name(./responseIf/setOutcomeValue/sum/*[1]) = "variable"] [name(./responseIf/setOutcomeValue/sum/*[2]) = "mapResponsePoint"]';
$subPatternFeedbackOperatorIf = '[name(./*[1]) = "responseIf" ] [count(./responseIf/*) = 2 ] [contains(name(./responseIf/*[1]/*[1]), "map")] [name(./responseIf/*[1]/*[2]) = "baseValue" ] [name(./responseIf/*[2]) = "setOutcomeValue" ] [name(./responseIf/setOutcomeValue/*[1]) = "baseValue" ]';
$subPatternFeedbackElse = '[name(./*[2]) = "responseElse"] [count(./responseElse/*) = 1 ] [name(./responseElse/*[1]) = "setOutcomeValue"] [name(./responseElse/setOutcomeValue/*[1]) = "baseValue"]';
$subPatternFeedbackCorrect = '[name(./*[1]) = "responseIf" ] [count(./responseIf/*) = 2 ] [name(./responseIf/*[1]) = "match" ] [name(./responseIf/*[1]/*[1]) = "variable" ] [name(./responseIf/*[1]/*[2]) = "correct" ] [name(./responseIf/*[2]) = "setOutcomeValue" ] [name(./responseIf/setOutcomeValue/*[1]) = "baseValue" ]';
$subPatternFeedbackIncorrect = '[name(./*[1]) = "responseIf" ] [count(./responseIf/*) = 2 ] [name(./responseIf/*[1]) = "not" ] [count(./responseIf/not) = 1 ] [name(./responseIf/not/*[1]) = "match" ] [name(./responseIf/not/*[1]/*[1]) = "variable" ] [name(./responseIf/not/*[1]/*[2]) = "correct" ] [name(./responseIf/*[2]) = "setOutcomeValue" ] [name(./responseIf/setOutcomeValue/*[1]) = "baseValue" ]';
$subPatternFeedbackMatchChoices = '[name(./*[1]) = "responseIf" ] [count(./responseIf/*) = 2 ] [name(./responseIf/*[1]) = "match" ] [name(./responseIf/*[1]/*[2]) = "multiple" ] [name(./responseIf/*[1]/*[2]/*) = "baseValue" ] [name(./responseIf/*[2]) = "setOutcomeValue" ] [name(./responseIf/setOutcomeValue/*[1]) = "baseValue" ] ';
$subPatternFeedbackMatchChoicesEmpty = '[name(./*[1]) = "responseIf" ] [count(./responseIf/*) = 2 ] [name(./responseIf/*[1]) = "match" ] [name(./responseIf/*[1]/*[2]) = "multiple" ] [count(./responseIf/*[1]/*[2]/*) = 0 ] [name(./responseIf/*[2]) = "setOutcomeValue" ] [name(./responseIf/setOutcomeValue/*[1]) = "baseValue" ] ';
$subPatternFeedbackMatchChoice = '[name(./*[1]) = "responseIf" ] [count(./responseIf/*) = 2 ] [name(./responseIf/*[1]) = "match" ] [name(./responseIf/*[1]/*[2]) = "baseValue" ] [name(./responseIf/*[2]) = "setOutcomeValue" ] [name(./responseIf/setOutcomeValue/*[1]) = "baseValue" ] ';
$patternFeedbackOperator = '/responseCondition [count(./*) = 1 ]'.$subPatternFeedbackOperatorIf;
$patternFeedbackOperatorWithElse = '/responseCondition [count(./*) = 2 ]'.$subPatternFeedbackOperatorIf.$subPatternFeedbackElse;
$patternFeedbackCorrect = '/responseCondition [count(./*) = 1 ]'.$subPatternFeedbackCorrect;
$patternFeedbackCorrectWithElse = '/responseCondition [count(./*) = 2 ]'.$subPatternFeedbackCorrect.$subPatternFeedbackElse;
$patternFeedbackIncorrect = '/responseCondition [count(./*) = 1 ]'.$subPatternFeedbackIncorrect;
$patternFeedbackIncorrectWithElse = '/responseCondition [count(./*) = 2 ]'.$subPatternFeedbackIncorrect.$subPatternFeedbackElse;
$patternFeedbackMatchChoices = '/responseCondition [count(./*) = 1 ]'.$subPatternFeedbackMatchChoices;
$patternFeedbackMatchChoicesWithElse = '/responseCondition [count(./*) = 2 ]'.$subPatternFeedbackMatchChoices.$subPatternFeedbackElse;
$patternFeedbackMatchChoice = '/responseCondition [count(./*) = 1 ]'.$subPatternFeedbackMatchChoice;
$patternFeedbackMatchChoicesEmpty = '/responseCondition [count(./*) = 1 ]'.$subPatternFeedbackMatchChoicesEmpty;
$patternFeedbackMatchChoicesEmptyWithElse = '/responseCondition [count(./*) = 2 ]'.$subPatternFeedbackMatchChoicesEmpty.$subPatternFeedbackElse;
$patternFeedbackMatchChoice = '/responseCondition [count(./*) = 1 ]'.$subPatternFeedbackMatchChoice;
$patternFeedbackMatchChoiceWithElse = '/responseCondition [count(./*) = 2 ]'.$subPatternFeedbackMatchChoice.$subPatternFeedbackElse;
$rules = array();
$simpleFeedbackRules = array();
$data = simplexml_import_dom($data);
foreach($data as $responseRule){
$feedbackRule = null;
$subtree = new SimpleXMLElement($responseRule->asXML());
if(count($subtree->xpath($patternCorrectTAO)) > 0){
$responseIdentifier = (string) $subtree->responseIf->match->variable['identifier'];
$rules[$responseIdentifier] = Template::MATCH_CORRECT;
}elseif(count($subtree->xpath($patternMappingTAO)) > 0){
$responseIdentifier = (string) $subtree->responseIf->not->isNull->variable['identifier'];
$rules[$responseIdentifier] = Template::MAP_RESPONSE;
}elseif(count($subtree->xpath($patternMappingPointTAO)) > 0){
$responseIdentifier = (string) $subtree->responseIf->not->isNull->variable['identifier'];
$rules[$responseIdentifier] = Template::MAP_RESPONSE_POINT;
}elseif(count($subtree->xpath($patternFeedbackCorrect)) > 0 || count($subtree->xpath($patternFeedbackCorrectWithElse)) > 0){
$feedbackRule = $this->buildSimpleFeedbackRule($subtree, 'correct');
}elseif(count($subtree->xpath($patternFeedbackIncorrect)) > 0 || count($subtree->xpath($patternFeedbackIncorrectWithElse)) > 0){
$responseIdentifier = (string) $subtree->responseIf->not->match->variable['identifier'];
$feedbackRule = $this->buildSimpleFeedbackRule($subtree, 'incorrect', null, $responseIdentifier);
}elseif(count($subtree->xpath($patternFeedbackOperator)) > 0 || count($subtree->xpath($patternFeedbackOperatorWithElse)) > 0){
$operator = '';
$responseIdentifier = '';
$value = '';
foreach($subtree->responseIf->children() as $child){
$operator = $child->getName();
$map = null;
foreach($child->children() as $granChild){
$map = $granChild->getName();
$responseIdentifier = (string) $granChild['identifier'];
break;
}
$value = (string) $child->baseValue;
break;
}
$feedbackRule = $this->buildSimpleFeedbackRule($subtree, $operator, $value);
}elseif(count($subtree->xpath($patternFeedbackMatchChoices)) > 0 || count($subtree->xpath($patternFeedbackMatchChoicesWithElse)) > 0 ||
count($subtree->xpath($patternFeedbackMatchChoicesEmpty)) > 0 || count($subtree->xpath($patternFeedbackMatchChoicesEmptyWithElse)) > 0
){
$choices = array();
foreach($subtree->responseIf->match->multiple->baseValue as $choice){
$choices[] = (string)$choice;
}
$feedbackRule = $this->buildSimpleFeedbackRule($subtree, 'choices', $choices);
}elseif(count($subtree->xpath($patternFeedbackMatchChoice)) > 0 || count($subtree->xpath($patternFeedbackMatchChoiceWithElse)) > 0){
$choices = array((string)$subtree->responseIf->match->baseValue);
$feedbackRule = $this->buildSimpleFeedbackRule($subtree, 'choices', $choices);
}else{
throw new UnexpectedResponseProcessing('Not template driven, unknown rule');
}
if(!is_null($feedbackRule)){
$responseIdentifier = $feedbackRule->comparedOutcome()->getIdentifier();
if(!isset($simpleFeedbackRules[$responseIdentifier])){
$simpleFeedbackRules[$responseIdentifier] = array();
}
$simpleFeedbackRules[$responseIdentifier][] = $feedbackRule;
}
}
$responseIdentifiers = array();
foreach($interactions as $interaction){
$interactionResponse = $interaction->getResponse();
$responseIdentifier = $interactionResponse->getIdentifier();
$responseIdentifiers[] = $responseIdentifier;
//create and set simple feedback rule here
if(isset($simpleFeedbackRules[$responseIdentifier])){
foreach($simpleFeedbackRules[$responseIdentifier] as $rule){
$interactionResponse->addFeedbackRule($rule);
}
}
}
//all rules must have been previously identified as belonging to one interaction
if(count(array_diff(array_keys($rules), $responseIdentifiers)) > 0){
throw new UnexpectedResponseProcessing('Not template driven, responseIdentifiers are '.implode(',', $responseIdentifiers).' while rules are '.implode(',', array_keys($rules)));
}
$templatesDrivenRP = new TemplatesDriven();
foreach($interactions as $interaction){
//if a rule has been found for an interaction, apply it. Default to the template NONE otherwise
$pattern = isset($rules[$interaction->getResponse()->getIdentifier()]) ? $rules[$interaction->getResponse()->getIdentifier()] : Template::NONE;
$templatesDrivenRP->setTemplate($interaction->getResponse(), $pattern);
}
$templatesDrivenRP->setRelatedItem($this->item);
$returnValue = $templatesDrivenRP;
return $returnValue;
} | php | protected function buildTemplatedrivenResponse(DOMElement $data, $interactions){
$patternCorrectTAO = '/responseCondition [count(./*) = 1 ] [name(./*[1]) = "responseIf" ] [count(./responseIf/*) = 2 ] [name(./responseIf/*[1]) = "match" ] [name(./responseIf/match/*[1]) = "variable" ] [name(./responseIf/match/*[2]) = "correct" ] [name(./responseIf/*[2]) = "setOutcomeValue" ] [name(./responseIf/setOutcomeValue/*[1]) = "sum" ] [name(./responseIf/setOutcomeValue/sum/*[1]) = "variable" ] [name(./responseIf/setOutcomeValue/sum/*[2]) = "baseValue"]';
$patternMappingTAO = '/responseCondition [count(./*) = 1] [name(./*[1]) = "responseIf"] [count(./responseIf/*) = 2] [name(./responseIf/*[1]) = "not"] [name(./responseIf/not/*[1]) = "isNull"] [name(./responseIf/not/isNull/*[1]) = "variable"] [name(./responseIf/*[2]) = "setOutcomeValue"] [name(./responseIf/setOutcomeValue/*[1]) = "sum"] [name(./responseIf/setOutcomeValue/sum/*[1]) = "variable"] [name(./responseIf/setOutcomeValue/sum/*[2]) = "mapResponse"]';
$patternMappingPointTAO = '/responseCondition [count(./*) = 1] [name(./*[1]) = "responseIf"] [count(./responseIf/*) = 2] [name(./responseIf/*[1]) = "not"] [name(./responseIf/not/*[1]) = "isNull"] [name(./responseIf/not/isNull/*[1]) = "variable"] [name(./responseIf/*[2]) = "setOutcomeValue"] [name(./responseIf/setOutcomeValue/*[1]) = "sum"] [name(./responseIf/setOutcomeValue/sum/*[1]) = "variable"] [name(./responseIf/setOutcomeValue/sum/*[2]) = "mapResponsePoint"]';
$subPatternFeedbackOperatorIf = '[name(./*[1]) = "responseIf" ] [count(./responseIf/*) = 2 ] [contains(name(./responseIf/*[1]/*[1]), "map")] [name(./responseIf/*[1]/*[2]) = "baseValue" ] [name(./responseIf/*[2]) = "setOutcomeValue" ] [name(./responseIf/setOutcomeValue/*[1]) = "baseValue" ]';
$subPatternFeedbackElse = '[name(./*[2]) = "responseElse"] [count(./responseElse/*) = 1 ] [name(./responseElse/*[1]) = "setOutcomeValue"] [name(./responseElse/setOutcomeValue/*[1]) = "baseValue"]';
$subPatternFeedbackCorrect = '[name(./*[1]) = "responseIf" ] [count(./responseIf/*) = 2 ] [name(./responseIf/*[1]) = "match" ] [name(./responseIf/*[1]/*[1]) = "variable" ] [name(./responseIf/*[1]/*[2]) = "correct" ] [name(./responseIf/*[2]) = "setOutcomeValue" ] [name(./responseIf/setOutcomeValue/*[1]) = "baseValue" ]';
$subPatternFeedbackIncorrect = '[name(./*[1]) = "responseIf" ] [count(./responseIf/*) = 2 ] [name(./responseIf/*[1]) = "not" ] [count(./responseIf/not) = 1 ] [name(./responseIf/not/*[1]) = "match" ] [name(./responseIf/not/*[1]/*[1]) = "variable" ] [name(./responseIf/not/*[1]/*[2]) = "correct" ] [name(./responseIf/*[2]) = "setOutcomeValue" ] [name(./responseIf/setOutcomeValue/*[1]) = "baseValue" ]';
$subPatternFeedbackMatchChoices = '[name(./*[1]) = "responseIf" ] [count(./responseIf/*) = 2 ] [name(./responseIf/*[1]) = "match" ] [name(./responseIf/*[1]/*[2]) = "multiple" ] [name(./responseIf/*[1]/*[2]/*) = "baseValue" ] [name(./responseIf/*[2]) = "setOutcomeValue" ] [name(./responseIf/setOutcomeValue/*[1]) = "baseValue" ] ';
$subPatternFeedbackMatchChoicesEmpty = '[name(./*[1]) = "responseIf" ] [count(./responseIf/*) = 2 ] [name(./responseIf/*[1]) = "match" ] [name(./responseIf/*[1]/*[2]) = "multiple" ] [count(./responseIf/*[1]/*[2]/*) = 0 ] [name(./responseIf/*[2]) = "setOutcomeValue" ] [name(./responseIf/setOutcomeValue/*[1]) = "baseValue" ] ';
$subPatternFeedbackMatchChoice = '[name(./*[1]) = "responseIf" ] [count(./responseIf/*) = 2 ] [name(./responseIf/*[1]) = "match" ] [name(./responseIf/*[1]/*[2]) = "baseValue" ] [name(./responseIf/*[2]) = "setOutcomeValue" ] [name(./responseIf/setOutcomeValue/*[1]) = "baseValue" ] ';
$patternFeedbackOperator = '/responseCondition [count(./*) = 1 ]'.$subPatternFeedbackOperatorIf;
$patternFeedbackOperatorWithElse = '/responseCondition [count(./*) = 2 ]'.$subPatternFeedbackOperatorIf.$subPatternFeedbackElse;
$patternFeedbackCorrect = '/responseCondition [count(./*) = 1 ]'.$subPatternFeedbackCorrect;
$patternFeedbackCorrectWithElse = '/responseCondition [count(./*) = 2 ]'.$subPatternFeedbackCorrect.$subPatternFeedbackElse;
$patternFeedbackIncorrect = '/responseCondition [count(./*) = 1 ]'.$subPatternFeedbackIncorrect;
$patternFeedbackIncorrectWithElse = '/responseCondition [count(./*) = 2 ]'.$subPatternFeedbackIncorrect.$subPatternFeedbackElse;
$patternFeedbackMatchChoices = '/responseCondition [count(./*) = 1 ]'.$subPatternFeedbackMatchChoices;
$patternFeedbackMatchChoicesWithElse = '/responseCondition [count(./*) = 2 ]'.$subPatternFeedbackMatchChoices.$subPatternFeedbackElse;
$patternFeedbackMatchChoice = '/responseCondition [count(./*) = 1 ]'.$subPatternFeedbackMatchChoice;
$patternFeedbackMatchChoicesEmpty = '/responseCondition [count(./*) = 1 ]'.$subPatternFeedbackMatchChoicesEmpty;
$patternFeedbackMatchChoicesEmptyWithElse = '/responseCondition [count(./*) = 2 ]'.$subPatternFeedbackMatchChoicesEmpty.$subPatternFeedbackElse;
$patternFeedbackMatchChoice = '/responseCondition [count(./*) = 1 ]'.$subPatternFeedbackMatchChoice;
$patternFeedbackMatchChoiceWithElse = '/responseCondition [count(./*) = 2 ]'.$subPatternFeedbackMatchChoice.$subPatternFeedbackElse;
$rules = array();
$simpleFeedbackRules = array();
$data = simplexml_import_dom($data);
foreach($data as $responseRule){
$feedbackRule = null;
$subtree = new SimpleXMLElement($responseRule->asXML());
if(count($subtree->xpath($patternCorrectTAO)) > 0){
$responseIdentifier = (string) $subtree->responseIf->match->variable['identifier'];
$rules[$responseIdentifier] = Template::MATCH_CORRECT;
}elseif(count($subtree->xpath($patternMappingTAO)) > 0){
$responseIdentifier = (string) $subtree->responseIf->not->isNull->variable['identifier'];
$rules[$responseIdentifier] = Template::MAP_RESPONSE;
}elseif(count($subtree->xpath($patternMappingPointTAO)) > 0){
$responseIdentifier = (string) $subtree->responseIf->not->isNull->variable['identifier'];
$rules[$responseIdentifier] = Template::MAP_RESPONSE_POINT;
}elseif(count($subtree->xpath($patternFeedbackCorrect)) > 0 || count($subtree->xpath($patternFeedbackCorrectWithElse)) > 0){
$feedbackRule = $this->buildSimpleFeedbackRule($subtree, 'correct');
}elseif(count($subtree->xpath($patternFeedbackIncorrect)) > 0 || count($subtree->xpath($patternFeedbackIncorrectWithElse)) > 0){
$responseIdentifier = (string) $subtree->responseIf->not->match->variable['identifier'];
$feedbackRule = $this->buildSimpleFeedbackRule($subtree, 'incorrect', null, $responseIdentifier);
}elseif(count($subtree->xpath($patternFeedbackOperator)) > 0 || count($subtree->xpath($patternFeedbackOperatorWithElse)) > 0){
$operator = '';
$responseIdentifier = '';
$value = '';
foreach($subtree->responseIf->children() as $child){
$operator = $child->getName();
$map = null;
foreach($child->children() as $granChild){
$map = $granChild->getName();
$responseIdentifier = (string) $granChild['identifier'];
break;
}
$value = (string) $child->baseValue;
break;
}
$feedbackRule = $this->buildSimpleFeedbackRule($subtree, $operator, $value);
}elseif(count($subtree->xpath($patternFeedbackMatchChoices)) > 0 || count($subtree->xpath($patternFeedbackMatchChoicesWithElse)) > 0 ||
count($subtree->xpath($patternFeedbackMatchChoicesEmpty)) > 0 || count($subtree->xpath($patternFeedbackMatchChoicesEmptyWithElse)) > 0
){
$choices = array();
foreach($subtree->responseIf->match->multiple->baseValue as $choice){
$choices[] = (string)$choice;
}
$feedbackRule = $this->buildSimpleFeedbackRule($subtree, 'choices', $choices);
}elseif(count($subtree->xpath($patternFeedbackMatchChoice)) > 0 || count($subtree->xpath($patternFeedbackMatchChoiceWithElse)) > 0){
$choices = array((string)$subtree->responseIf->match->baseValue);
$feedbackRule = $this->buildSimpleFeedbackRule($subtree, 'choices', $choices);
}else{
throw new UnexpectedResponseProcessing('Not template driven, unknown rule');
}
if(!is_null($feedbackRule)){
$responseIdentifier = $feedbackRule->comparedOutcome()->getIdentifier();
if(!isset($simpleFeedbackRules[$responseIdentifier])){
$simpleFeedbackRules[$responseIdentifier] = array();
}
$simpleFeedbackRules[$responseIdentifier][] = $feedbackRule;
}
}
$responseIdentifiers = array();
foreach($interactions as $interaction){
$interactionResponse = $interaction->getResponse();
$responseIdentifier = $interactionResponse->getIdentifier();
$responseIdentifiers[] = $responseIdentifier;
//create and set simple feedback rule here
if(isset($simpleFeedbackRules[$responseIdentifier])){
foreach($simpleFeedbackRules[$responseIdentifier] as $rule){
$interactionResponse->addFeedbackRule($rule);
}
}
}
//all rules must have been previously identified as belonging to one interaction
if(count(array_diff(array_keys($rules), $responseIdentifiers)) > 0){
throw new UnexpectedResponseProcessing('Not template driven, responseIdentifiers are '.implode(',', $responseIdentifiers).' while rules are '.implode(',', array_keys($rules)));
}
$templatesDrivenRP = new TemplatesDriven();
foreach($interactions as $interaction){
//if a rule has been found for an interaction, apply it. Default to the template NONE otherwise
$pattern = isset($rules[$interaction->getResponse()->getIdentifier()]) ? $rules[$interaction->getResponse()->getIdentifier()] : Template::NONE;
$templatesDrivenRP->setTemplate($interaction->getResponse(), $pattern);
}
$templatesDrivenRP->setRelatedItem($this->item);
$returnValue = $templatesDrivenRP;
return $returnValue;
} | [
"protected",
"function",
"buildTemplatedrivenResponse",
"(",
"DOMElement",
"$",
"data",
",",
"$",
"interactions",
")",
"{",
"$",
"patternCorrectTAO",
"=",
"'/responseCondition [count(./*) = 1 ] [name(./*[1]) = \"responseIf\" ] [count(./responseIf/*) = 2 ] [name(./responseIf/*[1]) = \"m... | Short description of method buildTemplatedrivenResponse
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@param DOMElement $data
@param $interactions
@return TemplatesDriven
@throws UnexpectedResponseProcessing
@throws exception\QtiModelException
@throws response\InvalidArgumentException | [
"Short",
"description",
"of",
"method",
"buildTemplatedrivenResponse"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/ParserFactory.php#L1221-L1357 |
oat-sa/extension-tao-itemqti | model/qti/ParserFactory.php | ParserFactory.buildObject | private function buildObject(DOMElement $data){
$attributes = $this->extractAttributes($data);
$returnValue = new QtiObject($attributes);
if($data->hasChildNodes()){
$nonEmptyChild = $this->getNonEmptyChildren($data);
if(count($nonEmptyChild) == 1 && reset($nonEmptyChild)->nodeName == 'object'){
$alt = $this->buildObject(reset($nonEmptyChild));
$returnValue->setAlt($alt);
}else{
//get the node xml content
$pattern = array("/^<{$data->nodeName}([^>]*)?>/i", "/<\/{$data->nodeName}([^>]*)?>$/i");
$content = preg_replace($pattern, '', trim($this->saveXML($data)));
$returnValue->setAlt($content);
}
}else{
$alt = trim($data->nodeValue);
if(!empty($alt)){
$returnValue->setAlt($alt);
}
}
return $returnValue;
} | php | private function buildObject(DOMElement $data){
$attributes = $this->extractAttributes($data);
$returnValue = new QtiObject($attributes);
if($data->hasChildNodes()){
$nonEmptyChild = $this->getNonEmptyChildren($data);
if(count($nonEmptyChild) == 1 && reset($nonEmptyChild)->nodeName == 'object'){
$alt = $this->buildObject(reset($nonEmptyChild));
$returnValue->setAlt($alt);
}else{
//get the node xml content
$pattern = array("/^<{$data->nodeName}([^>]*)?>/i", "/<\/{$data->nodeName}([^>]*)?>$/i");
$content = preg_replace($pattern, '', trim($this->saveXML($data)));
$returnValue->setAlt($content);
}
}else{
$alt = trim($data->nodeValue);
if(!empty($alt)){
$returnValue->setAlt($alt);
}
}
return $returnValue;
} | [
"private",
"function",
"buildObject",
"(",
"DOMElement",
"$",
"data",
")",
"{",
"$",
"attributes",
"=",
"$",
"this",
"->",
"extractAttributes",
"(",
"$",
"data",
")",
";",
"$",
"returnValue",
"=",
"new",
"QtiObject",
"(",
"$",
"attributes",
")",
";",
"if... | Short description of method buildObject
@access private
@author Joel Bout, <joel.bout@tudor.lu>
@param DOMElement $data
@return \oat\taoQtiItem\model\qti\QtiObject | [
"Short",
"description",
"of",
"method",
"buildObject"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/ParserFactory.php#L1392-L1416 |
oat-sa/extension-tao-itemqti | model/qti/ParserFactory.php | ParserFactory.getPortableElementSubclasses | private function getPortableElementSubclasses($superClassName){
$subClasses = [];
foreach(PortableModelRegistry::getRegistry()->getModels() as $model){
$portableElementClass = $model->getQtiElementClassName();
if(is_subclass_of($portableElementClass, $superClassName)){
$subClasses[] = $portableElementClass;
}
}
return $subClasses;
} | php | private function getPortableElementSubclasses($superClassName){
$subClasses = [];
foreach(PortableModelRegistry::getRegistry()->getModels() as $model){
$portableElementClass = $model->getQtiElementClassName();
if(is_subclass_of($portableElementClass, $superClassName)){
$subClasses[] = $portableElementClass;
}
}
return $subClasses;
} | [
"private",
"function",
"getPortableElementSubclasses",
"(",
"$",
"superClassName",
")",
"{",
"$",
"subClasses",
"=",
"[",
"]",
";",
"foreach",
"(",
"PortableModelRegistry",
"::",
"getRegistry",
"(",
")",
"->",
"getModels",
"(",
")",
"as",
"$",
"model",
")",
... | Return the list of registered php portable element subclasses
@return array | [
"Return",
"the",
"list",
"of",
"registered",
"php",
"portable",
"element",
"subclasses"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/ParserFactory.php#L1559-L1568 |
oat-sa/extension-tao-itemqti | model/qti/ParserFactory.php | ParserFactory.getPortableElementClass | private function getPortableElementClass(DOMElement $data, $superClassName, $portableElementNodeName){
$portableElementClasses = $this->getPortableElementSubclasses($superClassName);
//start searching from globally declared namespace
foreach($this->item->getNamespaces() as $name => $uri){
foreach($portableElementClasses as $class){
if($uri === $class::NS_URI
&& $this->queryXPathChildren(array($portableElementNodeName), $data, $name)->length){
return $class;
}
}
}
//not found as a global namespace definition, try local namespace
if($this->queryXPathChildren(array($portableElementNodeName), $data)->length){
$pciNode = $this->queryXPathChildren(array($portableElementNodeName), $data)[0];
$xmlns = $pciNode->getAttribute('xmlns');
foreach($portableElementClasses as $phpClass){
if($phpClass::NS_URI === $xmlns){
return $phpClass;
}
}
}
//not a known portable element type
return null;
} | php | private function getPortableElementClass(DOMElement $data, $superClassName, $portableElementNodeName){
$portableElementClasses = $this->getPortableElementSubclasses($superClassName);
//start searching from globally declared namespace
foreach($this->item->getNamespaces() as $name => $uri){
foreach($portableElementClasses as $class){
if($uri === $class::NS_URI
&& $this->queryXPathChildren(array($portableElementNodeName), $data, $name)->length){
return $class;
}
}
}
//not found as a global namespace definition, try local namespace
if($this->queryXPathChildren(array($portableElementNodeName), $data)->length){
$pciNode = $this->queryXPathChildren(array($portableElementNodeName), $data)[0];
$xmlns = $pciNode->getAttribute('xmlns');
foreach($portableElementClasses as $phpClass){
if($phpClass::NS_URI === $xmlns){
return $phpClass;
}
}
}
//not a known portable element type
return null;
} | [
"private",
"function",
"getPortableElementClass",
"(",
"DOMElement",
"$",
"data",
",",
"$",
"superClassName",
",",
"$",
"portableElementNodeName",
")",
"{",
"$",
"portableElementClasses",
"=",
"$",
"this",
"->",
"getPortableElementSubclasses",
"(",
"$",
"superClassNam... | Get the PCI class associated to a dom node based on its namespace
Returns null if not a known PCI model
@param DOMElement $data
@return null | [
"Get",
"the",
"PCI",
"class",
"associated",
"to",
"a",
"dom",
"node",
"based",
"on",
"its",
"namespace",
"Returns",
"null",
"if",
"not",
"a",
"known",
"PCI",
"model"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/ParserFactory.php#L1577-L1604 |
oat-sa/extension-tao-itemqti | model/qti/ParserFactory.php | ParserFactory.buildCustomInteraction | private function buildCustomInteraction(DOMElement $data){
$interaction = null;
$pciClass = $this->getPciClass($data);
if (!empty($pciClass)) {
$ns = null;
foreach($this->item->getNamespaces() as $name => $uri){
if($pciClass::NS_URI === $uri){
$ns = new QtiNamespace($uri, $name);
}
}
if(is_null($ns)){
$pciNodes = $this->queryXPathChildren(array('portableCustomInteraction'), $data);
if($pciNodes->length){
$ns = new QtiNamespace($pciNodes->item(0)->getAttribute('xmlns'));
}
}
//use tao's implementation of portable custom interaction
$interaction = new $pciClass($this->extractAttributes($data), $this->item);
$interaction->feed($this, $data, $ns);
}else{
$ciClass = '';
$classes = $data->getAttribute('class');
$classeNames = preg_split('/\s+/', $classes);
foreach($classeNames as $classeName){
$ciClass = CustomInteractionRegistry::getCustomInteractionByName($classeName);
if($ciClass){
$interaction = new $ciClass($this->extractAttributes($data), $this->item);
$interaction->feed($this, $data);
break;
}
}
if(!$ciClass){
throw new ParsingException('unknown custom interaction to be build');
}
}
return $interaction;
} | php | private function buildCustomInteraction(DOMElement $data){
$interaction = null;
$pciClass = $this->getPciClass($data);
if (!empty($pciClass)) {
$ns = null;
foreach($this->item->getNamespaces() as $name => $uri){
if($pciClass::NS_URI === $uri){
$ns = new QtiNamespace($uri, $name);
}
}
if(is_null($ns)){
$pciNodes = $this->queryXPathChildren(array('portableCustomInteraction'), $data);
if($pciNodes->length){
$ns = new QtiNamespace($pciNodes->item(0)->getAttribute('xmlns'));
}
}
//use tao's implementation of portable custom interaction
$interaction = new $pciClass($this->extractAttributes($data), $this->item);
$interaction->feed($this, $data, $ns);
}else{
$ciClass = '';
$classes = $data->getAttribute('class');
$classeNames = preg_split('/\s+/', $classes);
foreach($classeNames as $classeName){
$ciClass = CustomInteractionRegistry::getCustomInteractionByName($classeName);
if($ciClass){
$interaction = new $ciClass($this->extractAttributes($data), $this->item);
$interaction->feed($this, $data);
break;
}
}
if(!$ciClass){
throw new ParsingException('unknown custom interaction to be build');
}
}
return $interaction;
} | [
"private",
"function",
"buildCustomInteraction",
"(",
"DOMElement",
"$",
"data",
")",
"{",
"$",
"interaction",
"=",
"null",
";",
"$",
"pciClass",
"=",
"$",
"this",
"->",
"getPciClass",
"(",
"$",
"data",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"pci... | Parse and build a custom interaction object
@param DOMElement $data
@return CustomInteraction
@throws ParsingException | [
"Parse",
"and",
"build",
"a",
"custom",
"interaction",
"object"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/ParserFactory.php#L1621-L1665 |
oat-sa/extension-tao-itemqti | model/qti/ParserFactory.php | ParserFactory.buildInfoControl | private function buildInfoControl(DOMElement $data){
$infoControl = null;
$picClass = $this->getPicClass($data);
if(!empty($picClass)){
$ns = null;
foreach($this->item->getNamespaces() as $name => $uri){
if($picClass::NS_URI === $uri){
$ns = new QtiNamespace($uri, $name);
}
}
if(is_null($ns)){
$pciNodes = $this->queryXPathChildren(array('portableInfoControl'), $data);
if($pciNodes->length){
$ns = new QtiNamespace($pciNodes->item(0)->getAttribute('xmlns'));
}
}
//use tao's implementation of portable custom interaction
$infoControl = new PortableInfoControl($this->extractAttributes($data), $this->item);
$infoControl->feed($this, $data, $ns);
}else{
$ciClass = '';
$classes = $data->getAttribute('class');
$classeNames = preg_split('/\s+/', $classes);
foreach($classeNames as $classeName){
$ciClass = InfoControlRegistry::getInfoControlByName($classeName);
if($ciClass){
$infoControl = new $ciClass($this->extractAttributes($data), $this->item);
$infoControl->feed($this, $data);
break;
}
}
if(!$ciClass){
throw new UnsupportedQtiElement($data);
}
}
return $infoControl;
} | php | private function buildInfoControl(DOMElement $data){
$infoControl = null;
$picClass = $this->getPicClass($data);
if(!empty($picClass)){
$ns = null;
foreach($this->item->getNamespaces() as $name => $uri){
if($picClass::NS_URI === $uri){
$ns = new QtiNamespace($uri, $name);
}
}
if(is_null($ns)){
$pciNodes = $this->queryXPathChildren(array('portableInfoControl'), $data);
if($pciNodes->length){
$ns = new QtiNamespace($pciNodes->item(0)->getAttribute('xmlns'));
}
}
//use tao's implementation of portable custom interaction
$infoControl = new PortableInfoControl($this->extractAttributes($data), $this->item);
$infoControl->feed($this, $data, $ns);
}else{
$ciClass = '';
$classes = $data->getAttribute('class');
$classeNames = preg_split('/\s+/', $classes);
foreach($classeNames as $classeName){
$ciClass = InfoControlRegistry::getInfoControlByName($classeName);
if($ciClass){
$infoControl = new $ciClass($this->extractAttributes($data), $this->item);
$infoControl->feed($this, $data);
break;
}
}
if(!$ciClass){
throw new UnsupportedQtiElement($data);
}
}
return $infoControl;
} | [
"private",
"function",
"buildInfoControl",
"(",
"DOMElement",
"$",
"data",
")",
"{",
"$",
"infoControl",
"=",
"null",
";",
"$",
"picClass",
"=",
"$",
"this",
"->",
"getPicClass",
"(",
"$",
"data",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"picClass"... | Parse and build a info control
@param DOMElement $data
@return InfoControl
@throws ParsingException | [
"Parse",
"and",
"build",
"a",
"info",
"control"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/ParserFactory.php#L1674-L1718 |
oat-sa/extension-tao-itemqti | model/qti/metadata/imsManifest/classificationMetadata/ImsManifestClassificationMetadataExtractor.php | ImsManifestClassificationMetadataExtractor.setClassificationMapping | public function setClassificationMapping($propertyUri, $classificationValue)
{
if (empty($propertyUri) || ! is_string($propertyUri)) {
throw new MetadataExtractionException(__('PropertyUri to map has to a valid uri'));
}
if (empty($classificationValue) || ! is_string($classificationValue)) {
throw new MetadataExtractionException(__('Classification value to map has to a string'));
}
$this->classification[$propertyUri] = $classificationValue;
} | php | public function setClassificationMapping($propertyUri, $classificationValue)
{
if (empty($propertyUri) || ! is_string($propertyUri)) {
throw new MetadataExtractionException(__('PropertyUri to map has to a valid uri'));
}
if (empty($classificationValue) || ! is_string($classificationValue)) {
throw new MetadataExtractionException(__('Classification value to map has to a string'));
}
$this->classification[$propertyUri] = $classificationValue;
} | [
"public",
"function",
"setClassificationMapping",
"(",
"$",
"propertyUri",
",",
"$",
"classificationValue",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"propertyUri",
")",
"||",
"!",
"is_string",
"(",
"$",
"propertyUri",
")",
")",
"{",
"throw",
"new",
"MetadataE... | Set the association between property uri and value to find into classification metadata source
@param $propertyUri
@param $classificationValue
@throws MetadataExtractionException | [
"Set",
"the",
"association",
"between",
"property",
"uri",
"and",
"value",
"to",
"find",
"into",
"classification",
"metadata",
"source"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/imsManifest/classificationMetadata/ImsManifestClassificationMetadataExtractor.php#L43-L52 |
oat-sa/extension-tao-itemqti | model/qti/response/interactionResponseProcessing/MapResponseTemplate.php | MapResponseTemplate.getRule | public function getRule()
{
$returnValue = (string) '';
$returnValue = 'if(isNull(null, getResponse("'.$this->getResponse()->getIdentifier().'"))) { '.
'setOutcomeValue("'.$this->getOutcome()->getIdentifier().'", 0); } else { '.
'setOutcomeValue("'.$this->getOutcome()->getIdentifier().'", '.
'mapResponse(null, getMap("'.$this->getResponse()->getIdentifier().'"), getResponse("'.$this->getResponse()->getIdentifier().'"))); };';
return (string) $returnValue;
} | php | public function getRule()
{
$returnValue = (string) '';
$returnValue = 'if(isNull(null, getResponse("'.$this->getResponse()->getIdentifier().'"))) { '.
'setOutcomeValue("'.$this->getOutcome()->getIdentifier().'", 0); } else { '.
'setOutcomeValue("'.$this->getOutcome()->getIdentifier().'", '.
'mapResponse(null, getMap("'.$this->getResponse()->getIdentifier().'"), getResponse("'.$this->getResponse()->getIdentifier().'"))); };';
return (string) $returnValue;
} | [
"public",
"function",
"getRule",
"(",
")",
"{",
"$",
"returnValue",
"=",
"(",
"string",
")",
"''",
";",
"$",
"returnValue",
"=",
"'if(isNull(null, getResponse(\"'",
".",
"$",
"this",
"->",
"getResponse",
"(",
")",
"->",
"getIdentifier",
"(",
")",
".",
"'\"... | Short description of method getRule
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@return string | [
"Short",
"description",
"of",
"method",
"getRule"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/response/interactionResponseProcessing/MapResponseTemplate.php#L59-L71 |
oat-sa/extension-tao-itemqti | model/flyExporter/extractor/QtiExtractor.php | QtiExtractor.setItem | public function setItem(\core_kernel_classes_Resource $item)
{
$this->item = $item;
$this->loadXml($item);
return $this;
} | php | public function setItem(\core_kernel_classes_Resource $item)
{
$this->item = $item;
$this->loadXml($item);
return $this;
} | [
"public",
"function",
"setItem",
"(",
"\\",
"core_kernel_classes_Resource",
"$",
"item",
")",
"{",
"$",
"this",
"->",
"item",
"=",
"$",
"item",
";",
"$",
"this",
"->",
"loadXml",
"(",
"$",
"item",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set item to extract
@param \core_kernel_classes_Resource $item
@return $this
@throws ExtractorException | [
"Set",
"item",
"to",
"extract"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/flyExporter/extractor/QtiExtractor.php#L83-L89 |
oat-sa/extension-tao-itemqti | model/flyExporter/extractor/QtiExtractor.php | QtiExtractor.loadXml | private function loadXml(\core_kernel_classes_Resource $item)
{
$itemService = Service::singleton();
try {
$xml = $itemService->getXmlByRdfItem($item);
if (empty($xml)) {
throw new ExtractorException('No content found for item ' . $item->getUri());
}
} catch (FileNotFoundException $e) {
throw new ExtractorException('qti.xml file was not found for item '. $item->getUri() .'; The item might be empty.');
}
$this->dom = new \DOMDocument();
$this->dom->loadXml($xml);
$this->xpath = new \DOMXpath($this->dom);
$this->xpath->registerNamespace('qti', $this->dom->documentElement->namespaceURI);
return $this;
} | php | private function loadXml(\core_kernel_classes_Resource $item)
{
$itemService = Service::singleton();
try {
$xml = $itemService->getXmlByRdfItem($item);
if (empty($xml)) {
throw new ExtractorException('No content found for item ' . $item->getUri());
}
} catch (FileNotFoundException $e) {
throw new ExtractorException('qti.xml file was not found for item '. $item->getUri() .'; The item might be empty.');
}
$this->dom = new \DOMDocument();
$this->dom->loadXml($xml);
$this->xpath = new \DOMXpath($this->dom);
$this->xpath->registerNamespace('qti', $this->dom->documentElement->namespaceURI);
return $this;
} | [
"private",
"function",
"loadXml",
"(",
"\\",
"core_kernel_classes_Resource",
"$",
"item",
")",
"{",
"$",
"itemService",
"=",
"Service",
"::",
"singleton",
"(",
")",
";",
"try",
"{",
"$",
"xml",
"=",
"$",
"itemService",
"->",
"getXmlByRdfItem",
"(",
"$",
"i... | Load Dom & Xpath of xml item content & register xpath namespace
@param \core_kernel_classes_Resource $item
@return $this
@throws ExtractorException | [
"Load",
"Dom",
"&",
"Xpath",
"of",
"xml",
"item",
"content",
"&",
"register",
"xpath",
"namespace"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/flyExporter/extractor/QtiExtractor.php#L98-L117 |
oat-sa/extension-tao-itemqti | model/flyExporter/extractor/QtiExtractor.php | QtiExtractor.run | public function run()
{
$this->extractInteractions();
$this->data = $line = [];
foreach ($this->interactions as $interaction) {
foreach ($this->columns as $column => $config) {
if (isset($config['callback'])
&& method_exists($this, $config['callback']))
{
$params = [];
if (isset($config['callbackParameters'])) {
$params = $config['callbackParameters'];
}
$functionCall = $config['callback'];
$callbackValue = call_user_func(array($this, $functionCall), $interaction, $params);
if (isset($config['valuesAsColumns'])) {
$line[$interaction['id']] = array_merge($line[$interaction['id']], $callbackValue);
} else {
$line[$interaction['id']][$column] = $callbackValue;
}
}
}
}
$this->data = $line;
$this->columns = $this->interactions = [];
return $this;
} | php | public function run()
{
$this->extractInteractions();
$this->data = $line = [];
foreach ($this->interactions as $interaction) {
foreach ($this->columns as $column => $config) {
if (isset($config['callback'])
&& method_exists($this, $config['callback']))
{
$params = [];
if (isset($config['callbackParameters'])) {
$params = $config['callbackParameters'];
}
$functionCall = $config['callback'];
$callbackValue = call_user_func(array($this, $functionCall), $interaction, $params);
if (isset($config['valuesAsColumns'])) {
$line[$interaction['id']] = array_merge($line[$interaction['id']], $callbackValue);
} else {
$line[$interaction['id']][$column] = $callbackValue;
}
}
}
}
$this->data = $line;
$this->columns = $this->interactions = [];
return $this;
} | [
"public",
"function",
"run",
"(",
")",
"{",
"$",
"this",
"->",
"extractInteractions",
"(",
")",
";",
"$",
"this",
"->",
"data",
"=",
"$",
"line",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"interactions",
"as",
"$",
"interaction",
")",
... | Launch interactions extraction
Transform interactions array to output data
Use callback & valuesAsColumns
@return $this | [
"Launch",
"interactions",
"extraction",
"Transform",
"interactions",
"array",
"to",
"output",
"data",
"Use",
"callback",
"&",
"valuesAsColumns"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/flyExporter/extractor/QtiExtractor.php#L140-L168 |
oat-sa/extension-tao-itemqti | model/flyExporter/extractor/QtiExtractor.php | QtiExtractor.extractInteractions | protected function extractInteractions()
{
$elements = [
// Multiple choice
'Choice' => ['domInteraction' => 'choiceInteraction', 'xpathChoice' => './/qti:simpleChoice'],
'Order' => ['domInteraction' => 'orderInteraction', 'xpathChoice' => './/qti:simpleChoice'],
'Match' => ['domInteraction' => 'matchInteraction','xpathChoice' => './/qti:simpleAssociableChoice'],
'Associate' => ['domInteraction' => 'associateInteraction','xpathChoice' => './/qti:simpleAssociableChoice'],
'Gap Match' => ['domInteraction' => 'gapMatchInteraction', 'xpathChoice' => './/qti:gapText'],
'Hot text' => ['domInteraction' => 'hottextInteraction', 'xpathChoice' => './/qti:hottext'],
'Inline choice' => ['domInteraction' => 'inlineChoiceInteraction', 'xpathChoice' => './/qti:inlineChoice'],
'Graphic hotspot' => ['domInteraction' => 'hotspotInteraction', 'xpathChoice' => './/qti:hotspotChoice'],
'Graphic order' => ['domInteraction' => 'graphicOrderInteraction', 'xpathChoice' => './/qti:hotspotChoice'],
'Graphic associate' => ['domInteraction' => 'graphicAssociateInteraction', 'xpathChoice' => './/qti:associableHotspot'],
'Graphic gap match' => ['domInteraction' => 'graphicGapMatchInteraction', 'xpathChoice' => './/qti:gapImg'],
//Scaffholding
'ScaffHolding' => [
'xpathInteraction' => '//*[@customInteractionTypeIdentifier="adaptiveChoiceInteraction"]',
'xpathChoice' => 'descendant::*[@class="qti-choice"]'
],
// Custom PCI interactions; Proper interaction type name will be determined by an xpath query
'Custom Interaction' => [
'domInteraction' => 'customInteraction'
],
// Simple interaction
'Extended text' => ['domInteraction' => 'extendedTextInteraction'],
'Slider' => ['domInteraction' => 'sliderInteraction'],
'Upload file' => ['domInteraction' => 'uploadInteraction'],
'Text entry' => ['domInteraction' => 'textEntryInteraction'],
'End attempt' => ['domInteraction' => 'endAttemptInteraction'],
];
/**
* foreach all interactions type
*/
foreach ($elements as $element => $parser) {
if (isset($parser['domInteraction'])) {
$interactionNode = $this->dom->getElementsByTagName($parser['domInteraction']);
} elseif (isset($parser['xpathInteraction'])) {
$interactionNode = $this->xpath->query($parser['xpathInteraction']);
} else {
continue;
}
if ($interactionNode->length == 0) {
continue;
}
/**
* foreach all real interactions
*/
for ($i=0; $i < $interactionNode->length ; $i++) {
$interaction = [];
$interaction['id'] = uniqid();
$interaction['type'] = $element;
$interaction['choices'] = [];
$interaction['responses'] = [];
if ($parser['domInteraction'] == 'customInteraction') {
// figure out the proper type name of a custom interaction
$portableCustomNode = $this->xpath->query('./pci:portableCustomInteraction', $interactionNode->item($i));
if ($portableCustomNode->length) {
$interaction['type'] = ucfirst(str_replace('Interaction', '', $portableCustomNode->item(0)->getAttribute('customInteractionTypeIdentifier')));
}
}
/**
* Interaction right answers
*/
$interaction['responseIdentifier'] = $interactionNode->item($i)->getAttribute('responseIdentifier');
$rightAnswer = $this->xpath->query('./qti:responseDeclaration[@identifier="' . $interaction['responseIdentifier'] . '"]');
if ($rightAnswer->length > 0) {
$answers = $rightAnswer->item(0)->textContent;
if (!empty($answers)) {
foreach(explode(PHP_EOL, $answers) as $answer) {
if (trim($answer)!=='') {
$interaction['responses'][] = $answer;
}
}
}
}
/**
* Interaction choices
*/
$choiceNode = '';
if (!empty($parser['domChoice'])) {
$choiceNode = $this->dom->getElementsByTagName($parser['domChoice']);
} elseif (!empty($parser['xpathChoice'])) {
$choiceNode = $this->xpath->query($parser['xpathChoice'], $interactionNode->item($i));
}
if (!empty($choiceNode) && $choiceNode->length > 0) {
for($j=0 ; $j < $choiceNode->length ; $j++) {
$identifier = $choiceNode->item($j)->getAttribute('identifier');
$value = $this->sanitizeNodeToValue($this->dom->saveHtml($choiceNode->item($j)));
//Image
if ($value==='') {
$imgNode = $this->xpath->query('./qti:img/@src', $choiceNode->item($j));
if ($imgNode->length > 0) {
$value = 'image' . $j . '_' . $imgNode->item(0)->value;
}
}
$interaction['choices'][$identifier] = $value;
}
}
$this->interactions[] = $interaction;
}
}
return $this;
} | php | protected function extractInteractions()
{
$elements = [
// Multiple choice
'Choice' => ['domInteraction' => 'choiceInteraction', 'xpathChoice' => './/qti:simpleChoice'],
'Order' => ['domInteraction' => 'orderInteraction', 'xpathChoice' => './/qti:simpleChoice'],
'Match' => ['domInteraction' => 'matchInteraction','xpathChoice' => './/qti:simpleAssociableChoice'],
'Associate' => ['domInteraction' => 'associateInteraction','xpathChoice' => './/qti:simpleAssociableChoice'],
'Gap Match' => ['domInteraction' => 'gapMatchInteraction', 'xpathChoice' => './/qti:gapText'],
'Hot text' => ['domInteraction' => 'hottextInteraction', 'xpathChoice' => './/qti:hottext'],
'Inline choice' => ['domInteraction' => 'inlineChoiceInteraction', 'xpathChoice' => './/qti:inlineChoice'],
'Graphic hotspot' => ['domInteraction' => 'hotspotInteraction', 'xpathChoice' => './/qti:hotspotChoice'],
'Graphic order' => ['domInteraction' => 'graphicOrderInteraction', 'xpathChoice' => './/qti:hotspotChoice'],
'Graphic associate' => ['domInteraction' => 'graphicAssociateInteraction', 'xpathChoice' => './/qti:associableHotspot'],
'Graphic gap match' => ['domInteraction' => 'graphicGapMatchInteraction', 'xpathChoice' => './/qti:gapImg'],
//Scaffholding
'ScaffHolding' => [
'xpathInteraction' => '//*[@customInteractionTypeIdentifier="adaptiveChoiceInteraction"]',
'xpathChoice' => 'descendant::*[@class="qti-choice"]'
],
// Custom PCI interactions; Proper interaction type name will be determined by an xpath query
'Custom Interaction' => [
'domInteraction' => 'customInteraction'
],
// Simple interaction
'Extended text' => ['domInteraction' => 'extendedTextInteraction'],
'Slider' => ['domInteraction' => 'sliderInteraction'],
'Upload file' => ['domInteraction' => 'uploadInteraction'],
'Text entry' => ['domInteraction' => 'textEntryInteraction'],
'End attempt' => ['domInteraction' => 'endAttemptInteraction'],
];
/**
* foreach all interactions type
*/
foreach ($elements as $element => $parser) {
if (isset($parser['domInteraction'])) {
$interactionNode = $this->dom->getElementsByTagName($parser['domInteraction']);
} elseif (isset($parser['xpathInteraction'])) {
$interactionNode = $this->xpath->query($parser['xpathInteraction']);
} else {
continue;
}
if ($interactionNode->length == 0) {
continue;
}
/**
* foreach all real interactions
*/
for ($i=0; $i < $interactionNode->length ; $i++) {
$interaction = [];
$interaction['id'] = uniqid();
$interaction['type'] = $element;
$interaction['choices'] = [];
$interaction['responses'] = [];
if ($parser['domInteraction'] == 'customInteraction') {
// figure out the proper type name of a custom interaction
$portableCustomNode = $this->xpath->query('./pci:portableCustomInteraction', $interactionNode->item($i));
if ($portableCustomNode->length) {
$interaction['type'] = ucfirst(str_replace('Interaction', '', $portableCustomNode->item(0)->getAttribute('customInteractionTypeIdentifier')));
}
}
/**
* Interaction right answers
*/
$interaction['responseIdentifier'] = $interactionNode->item($i)->getAttribute('responseIdentifier');
$rightAnswer = $this->xpath->query('./qti:responseDeclaration[@identifier="' . $interaction['responseIdentifier'] . '"]');
if ($rightAnswer->length > 0) {
$answers = $rightAnswer->item(0)->textContent;
if (!empty($answers)) {
foreach(explode(PHP_EOL, $answers) as $answer) {
if (trim($answer)!=='') {
$interaction['responses'][] = $answer;
}
}
}
}
/**
* Interaction choices
*/
$choiceNode = '';
if (!empty($parser['domChoice'])) {
$choiceNode = $this->dom->getElementsByTagName($parser['domChoice']);
} elseif (!empty($parser['xpathChoice'])) {
$choiceNode = $this->xpath->query($parser['xpathChoice'], $interactionNode->item($i));
}
if (!empty($choiceNode) && $choiceNode->length > 0) {
for($j=0 ; $j < $choiceNode->length ; $j++) {
$identifier = $choiceNode->item($j)->getAttribute('identifier');
$value = $this->sanitizeNodeToValue($this->dom->saveHtml($choiceNode->item($j)));
//Image
if ($value==='') {
$imgNode = $this->xpath->query('./qti:img/@src', $choiceNode->item($j));
if ($imgNode->length > 0) {
$value = 'image' . $j . '_' . $imgNode->item(0)->value;
}
}
$interaction['choices'][$identifier] = $value;
}
}
$this->interactions[] = $interaction;
}
}
return $this;
} | [
"protected",
"function",
"extractInteractions",
"(",
")",
"{",
"$",
"elements",
"=",
"[",
"// Multiple choice",
"'Choice'",
"=>",
"[",
"'domInteraction'",
"=>",
"'choiceInteraction'",
",",
"'xpathChoice'",
"=>",
"'.//qti:simpleChoice'",
"]",
",",
"'Order'",
"=>",
"[... | Extract all interaction by find interaction node & relative choices
Find right answer & resolve identifier to choice name
Output example of item interactions:
array (
[...],
array(
"id" => "56e7d1397ad57",
"type" => "Match",
"choices" => array (
"M" => "Mouse",
"S" => "Soda",
"W" => "Wheel",
"D" => "DarthVader",
"A" => "Astronaut",
"C" => "Computer",
"P" => "Plane",
"N" => "Number",
),
"responses" => array (
0 => "M C"
),
"responseIdentifier" => "RESPONSE"
)
)
@return $this | [
"Extract",
"all",
"interaction",
"by",
"find",
"interaction",
"node",
"&",
"relative",
"choices",
"Find",
"right",
"answer",
"&",
"resolve",
"identifier",
"to",
"choice",
"name",
"Output",
"example",
"of",
"item",
"interactions",
":",
"array",
"(",
"[",
"...",... | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/flyExporter/extractor/QtiExtractor.php#L208-L325 |
oat-sa/extension-tao-itemqti | model/flyExporter/extractor/QtiExtractor.php | QtiExtractor.sanitizeNodeToValue | protected function sanitizeNodeToValue($value)
{
$first = strpos($value, '>')+1;
$last = strrpos($value, '<')-$first;
$value = substr($value, $first, $last);
$value = str_replace('"', "'", $value);
return trim($value);
} | php | protected function sanitizeNodeToValue($value)
{
$first = strpos($value, '>')+1;
$last = strrpos($value, '<')-$first;
$value = substr($value, $first, $last);
$value = str_replace('"', "'", $value);
return trim($value);
} | [
"protected",
"function",
"sanitizeNodeToValue",
"(",
"$",
"value",
")",
"{",
"$",
"first",
"=",
"strpos",
"(",
"$",
"value",
",",
"'>'",
")",
"+",
"1",
";",
"$",
"last",
"=",
"strrpos",
"(",
"$",
"value",
",",
"'<'",
")",
"-",
"$",
"first",
";",
... | Remove first and last xml tag from string
Transform variable to string value
@param $value
@return string | [
"Remove",
"first",
"and",
"last",
"xml",
"tag",
"from",
"string",
"Transform",
"variable",
"to",
"string",
"value"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/flyExporter/extractor/QtiExtractor.php#L334-L341 |
oat-sa/extension-tao-itemqti | model/flyExporter/extractor/QtiExtractor.php | QtiExtractor.getRightAnswer | public function getRightAnswer($interaction, $params)
{
$return = ['BR_identifier' => [], 'BR_label'=>[]];
if (isset($interaction['responses'])) {
foreach ($interaction['responses'] as $response) {
$allResponses = explode(' ', trim($response));
$returnLabel = [];
$returnIdentifier = [];
foreach ($allResponses as $partialResponse) {
if (isset($interaction['choices'][$partialResponse])
&& $interaction['choices'][$partialResponse]!=='') {
$returnLabel[] = $interaction['choices'][$partialResponse];
} else {
$returnLabel[] = '';
}
$returnIdentifier[] = $partialResponse;
}
$return['BR_identifier'][] = implode(' ', $returnIdentifier);
$return['BR_label'][] = implode(' ', $returnLabel);
}
}
if (isset($params['delimiter'])) {
$delimiter = $params['delimiter'];
} else {
$delimiter = self::DEFAULT_PROPERTY_DELIMITER;
}
$return['BR_identifier'] = implode($delimiter, $return['BR_identifier']);
$return['BR_label'] = implode($delimiter, $return['BR_label']);
return $return;
} | php | public function getRightAnswer($interaction, $params)
{
$return = ['BR_identifier' => [], 'BR_label'=>[]];
if (isset($interaction['responses'])) {
foreach ($interaction['responses'] as $response) {
$allResponses = explode(' ', trim($response));
$returnLabel = [];
$returnIdentifier = [];
foreach ($allResponses as $partialResponse) {
if (isset($interaction['choices'][$partialResponse])
&& $interaction['choices'][$partialResponse]!=='') {
$returnLabel[] = $interaction['choices'][$partialResponse];
} else {
$returnLabel[] = '';
}
$returnIdentifier[] = $partialResponse;
}
$return['BR_identifier'][] = implode(' ', $returnIdentifier);
$return['BR_label'][] = implode(' ', $returnLabel);
}
}
if (isset($params['delimiter'])) {
$delimiter = $params['delimiter'];
} else {
$delimiter = self::DEFAULT_PROPERTY_DELIMITER;
}
$return['BR_identifier'] = implode($delimiter, $return['BR_identifier']);
$return['BR_label'] = implode($delimiter, $return['BR_label']);
return $return;
} | [
"public",
"function",
"getRightAnswer",
"(",
"$",
"interaction",
",",
"$",
"params",
")",
"{",
"$",
"return",
"=",
"[",
"'BR_identifier'",
"=>",
"[",
"]",
",",
"'BR_label'",
"=>",
"[",
"]",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"interaction",
"[",
... | Callback to retrieve right answers
Find $responses & resolve identifier with $choices
@param $interaction
@return string | [
"Callback",
"to",
"retrieve",
"right",
"answers",
"Find",
"$responses",
"&",
"resolve",
"identifier",
"with",
"$choices"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/flyExporter/extractor/QtiExtractor.php#L350-L384 |
oat-sa/extension-tao-itemqti | model/flyExporter/extractor/QtiExtractor.php | QtiExtractor.getChoices | public function getChoices($interaction)
{
$return = [];
if (isset($interaction['choices'])) {
$i = 1;
foreach ($interaction['choices'] as $identifier => $choice) {
$return['choice_identifier_' . $i] = $identifier;
$return['choice_label_' . $i] = ($choice) ?: '';
$i++;
}
if ($this->headerChoice > count($return)) {
while ($this->headerChoice > count($return)) {
$return['choice_identifier_' . $i] = '';
$return['choice_label_' . $i] = '';
$i++;
}
} else {
$this->headerChoice = count($return);
}
}
return $return;
} | php | public function getChoices($interaction)
{
$return = [];
if (isset($interaction['choices'])) {
$i = 1;
foreach ($interaction['choices'] as $identifier => $choice) {
$return['choice_identifier_' . $i] = $identifier;
$return['choice_label_' . $i] = ($choice) ?: '';
$i++;
}
if ($this->headerChoice > count($return)) {
while ($this->headerChoice > count($return)) {
$return['choice_identifier_' . $i] = '';
$return['choice_label_' . $i] = '';
$i++;
}
} else {
$this->headerChoice = count($return);
}
}
return $return;
} | [
"public",
"function",
"getChoices",
"(",
"$",
"interaction",
")",
"{",
"$",
"return",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"interaction",
"[",
"'choices'",
"]",
")",
")",
"{",
"$",
"i",
"=",
"1",
";",
"foreach",
"(",
"$",
"interaction"... | Callback to retrieve all choices
Add dynamic column to have same columns number as other
@param $interaction
@return array | [
"Callback",
"to",
"retrieve",
"all",
"choices",
"Add",
"dynamic",
"column",
"to",
"have",
"same",
"columns",
"number",
"as",
"other"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/flyExporter/extractor/QtiExtractor.php#L408-L429 |
oat-sa/extension-tao-itemqti | model/qti/response/Composite.php | Composite.getRule | public function getRule(){
$returnValue = (string) '';
foreach($this->components as $irp){
$returnValue .= $irp->getRule();
}
foreach($this->getCompositionRules() as $rule){
$returnValue .= $rule->getRule();
}
return (string) $returnValue;
} | php | public function getRule(){
$returnValue = (string) '';
foreach($this->components as $irp){
$returnValue .= $irp->getRule();
}
foreach($this->getCompositionRules() as $rule){
$returnValue .= $rule->getRule();
}
return (string) $returnValue;
} | [
"public",
"function",
"getRule",
"(",
")",
"{",
"$",
"returnValue",
"=",
"(",
"string",
")",
"''",
";",
"foreach",
"(",
"$",
"this",
"->",
"components",
"as",
"$",
"irp",
")",
"{",
"$",
"returnValue",
".=",
"$",
"irp",
"->",
"getRule",
"(",
")",
";... | Short description of method getRule
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@return string | [
"Short",
"description",
"of",
"method",
"getRule"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/response/Composite.php#L79-L90 |
oat-sa/extension-tao-itemqti | model/qti/response/Composite.php | Composite.create | public static function create(Item $item){
$returnValue = new Summation($item);
foreach($item->getInteractions() as $interaction){
$irp = InteractionResponseProcessing::create(
None::CLASS_ID
, $interaction->getResponse()
, $item
);
$returnValue->add($irp, $item);
}
return $returnValue;
} | php | public static function create(Item $item){
$returnValue = new Summation($item);
foreach($item->getInteractions() as $interaction){
$irp = InteractionResponseProcessing::create(
None::CLASS_ID
, $interaction->getResponse()
, $item
);
$returnValue->add($irp, $item);
}
return $returnValue;
} | [
"public",
"static",
"function",
"create",
"(",
"Item",
"$",
"item",
")",
"{",
"$",
"returnValue",
"=",
"new",
"Summation",
"(",
"$",
"item",
")",
";",
"foreach",
"(",
"$",
"item",
"->",
"getInteractions",
"(",
")",
"as",
"$",
"interaction",
")",
"{",
... | Short description of method create
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@param Item item
@return oat\taoQtiItem\model\qti\response\ResponseProcessing | [
"Short",
"description",
"of",
"method",
"create"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/response/Composite.php#L126-L138 |
oat-sa/extension-tao-itemqti | model/qti/response/Composite.php | Composite.takeOverFrom | public static function takeOverFrom(ResponseProcessing $responseProcessing, Item $item){
$returnValue = null;
if($responseProcessing instanceof static){
// already good
$returnValue = $responseProcessing;
}elseif($responseProcessing instanceof Template){
// IMS Template
$rp = new Summation($item, 'SCORE');
foreach($item->getInteractions() as $interaction){
$response = $interaction->getResponse();
try{
$irp = IrpTemplate::createByTemplate(
$responseProcessing->getUri(), $response, $item);
}catch(Exception $e){
throw new TakeoverFailedException();
}
$rp->add($irp, $item);
}
$returnValue = $rp;
}elseif($responseProcessing instanceof TemplatesDriven){
// TemplateDriven
$rp = new Summation($item, 'SCORE');
foreach($item->getInteractions() as $interaction){
$response = $interaction->getResponse();
try{
$irp = IrpTemplate::createByTemplate(
$responseProcessing->getTemplate($response)
, $response
, $item
);
}catch(Exception $e){
throw new TakeoverFailedException();
}
$rp->add($irp, $item);
}
$returnValue = $rp;
}else{
common_Logger::d('Composite ResponseProcessing can not takeover from '.get_class($responseProcessing).' yet');
throw new TakeoverFailedException();
}
common_Logger::i('Converted to Composite', array('TAOITEMS', 'QTI'));
return $returnValue;
} | php | public static function takeOverFrom(ResponseProcessing $responseProcessing, Item $item){
$returnValue = null;
if($responseProcessing instanceof static){
// already good
$returnValue = $responseProcessing;
}elseif($responseProcessing instanceof Template){
// IMS Template
$rp = new Summation($item, 'SCORE');
foreach($item->getInteractions() as $interaction){
$response = $interaction->getResponse();
try{
$irp = IrpTemplate::createByTemplate(
$responseProcessing->getUri(), $response, $item);
}catch(Exception $e){
throw new TakeoverFailedException();
}
$rp->add($irp, $item);
}
$returnValue = $rp;
}elseif($responseProcessing instanceof TemplatesDriven){
// TemplateDriven
$rp = new Summation($item, 'SCORE');
foreach($item->getInteractions() as $interaction){
$response = $interaction->getResponse();
try{
$irp = IrpTemplate::createByTemplate(
$responseProcessing->getTemplate($response)
, $response
, $item
);
}catch(Exception $e){
throw new TakeoverFailedException();
}
$rp->add($irp, $item);
}
$returnValue = $rp;
}else{
common_Logger::d('Composite ResponseProcessing can not takeover from '.get_class($responseProcessing).' yet');
throw new TakeoverFailedException();
}
common_Logger::i('Converted to Composite', array('TAOITEMS', 'QTI'));
return $returnValue;
} | [
"public",
"static",
"function",
"takeOverFrom",
"(",
"ResponseProcessing",
"$",
"responseProcessing",
",",
"Item",
"$",
"item",
")",
"{",
"$",
"returnValue",
"=",
"null",
";",
"if",
"(",
"$",
"responseProcessing",
"instanceof",
"static",
")",
"{",
"// already go... | Short description of method takeOverFrom
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@param ResponseProcessing responseProcessing
@param Item item
@return oat\taoQtiItem\model\qti\response\Composite | [
"Short",
"description",
"of",
"method",
"takeOverFrom"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/response/Composite.php#L149-L194 |
oat-sa/extension-tao-itemqti | model/qti/response/Composite.php | Composite.getInteractionResponseProcessing | public function getInteractionResponseProcessing(ResponseDeclaration $response){
foreach($this->components as $irp){
if($irp->getResponse() == $response){
$returnValue = $irp;
break;
}
}
if(is_null($returnValue)){
throw new common_Exception('No interactionResponseProcessing defined for '.$response->getIdentifier());
}
return $returnValue;
} | php | public function getInteractionResponseProcessing(ResponseDeclaration $response){
foreach($this->components as $irp){
if($irp->getResponse() == $response){
$returnValue = $irp;
break;
}
}
if(is_null($returnValue)){
throw new common_Exception('No interactionResponseProcessing defined for '.$response->getIdentifier());
}
return $returnValue;
} | [
"public",
"function",
"getInteractionResponseProcessing",
"(",
"ResponseDeclaration",
"$",
"response",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"components",
"as",
"$",
"irp",
")",
"{",
"if",
"(",
"$",
"irp",
"->",
"getResponse",
"(",
")",
"==",
"$",
"... | Short description of method getInteractionResponseProcessing
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@param Response response
@return oat\taoQtiItem\model\qti\response\interactionResponseProcessing\InteractionResponseProcessing | [
"Short",
"description",
"of",
"method",
"getInteractionResponseProcessing"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/response/Composite.php#L216-L227 |
oat-sa/extension-tao-itemqti | model/qti/response/Composite.php | Composite.getIRPByOutcome | public function getIRPByOutcome(OutcomeDeclaration $outcome){
foreach($this->components as $irp){
if($irp->getOutcome() == $outcome){
$returnValue = $irp;
break;
}
}
return $returnValue;
} | php | public function getIRPByOutcome(OutcomeDeclaration $outcome){
foreach($this->components as $irp){
if($irp->getOutcome() == $outcome){
$returnValue = $irp;
break;
}
}
return $returnValue;
} | [
"public",
"function",
"getIRPByOutcome",
"(",
"OutcomeDeclaration",
"$",
"outcome",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"components",
"as",
"$",
"irp",
")",
"{",
"if",
"(",
"$",
"irp",
"->",
"getOutcome",
"(",
")",
"==",
"$",
"outcome",
")",
"... | Short description of method getIRPByOutcome
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@param Outcome outcome
@return oat\taoQtiItem\model\qti\response\interactionResponseProcessing\InteractionResponseProcessing | [
"Short",
"description",
"of",
"method",
"getIRPByOutcome"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/response/Composite.php#L237-L246 |
oat-sa/extension-tao-itemqti | model/qti/response/Composite.php | Composite.replace | public function replace(InteractionResponseProcessing $newInteractionResponseProcessing){
$oldkey = null;
foreach($this->components as $key => $component){
if($component->getResponse() == $newInteractionResponseProcessing->getResponse()){
$oldkey = $key;
break;
}
}
if(!is_null($oldkey)){
unset($this->components[$oldkey]);
}else{
common_Logger::w('Component to be replaced not found', array('TAOITEMS', 'QTI'));
}
$this->add($newInteractionResponseProcessing);
} | php | public function replace(InteractionResponseProcessing $newInteractionResponseProcessing){
$oldkey = null;
foreach($this->components as $key => $component){
if($component->getResponse() == $newInteractionResponseProcessing->getResponse()){
$oldkey = $key;
break;
}
}
if(!is_null($oldkey)){
unset($this->components[$oldkey]);
}else{
common_Logger::w('Component to be replaced not found', array('TAOITEMS', 'QTI'));
}
$this->add($newInteractionResponseProcessing);
} | [
"public",
"function",
"replace",
"(",
"InteractionResponseProcessing",
"$",
"newInteractionResponseProcessing",
")",
"{",
"$",
"oldkey",
"=",
"null",
";",
"foreach",
"(",
"$",
"this",
"->",
"components",
"as",
"$",
"key",
"=>",
"$",
"component",
")",
"{",
"if"... | Short description of method replace
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@param InteractionResponseProcessing newInteractionResponseProcessing
@return mixed | [
"Short",
"description",
"of",
"method",
"replace"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/response/Composite.php#L256-L270 |
oat-sa/extension-tao-itemqti | model/qti/response/Composite.php | Composite.toQTI | public function toQTI(){
$returnValue = "<responseProcessing>";
foreach($this->components as $irp){
$returnValue .= $irp->toQTI();
}
$returnValue .= $this->getCompositionQTI();
$returnValue .= "</responseProcessing>";
return (string) $returnValue;
} | php | public function toQTI(){
$returnValue = "<responseProcessing>";
foreach($this->components as $irp){
$returnValue .= $irp->toQTI();
}
$returnValue .= $this->getCompositionQTI();
$returnValue .= "</responseProcessing>";
return (string) $returnValue;
} | [
"public",
"function",
"toQTI",
"(",
")",
"{",
"$",
"returnValue",
"=",
"\"<responseProcessing>\"",
";",
"foreach",
"(",
"$",
"this",
"->",
"components",
"as",
"$",
"irp",
")",
"{",
"$",
"returnValue",
".=",
"$",
"irp",
"->",
"toQTI",
"(",
")",
";",
"}"... | Short description of method toQTI
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@return string | [
"Short",
"description",
"of",
"method",
"toQTI"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/response/Composite.php#L279-L288 |
oat-sa/extension-tao-itemqti | model/qti/response/Composite.php | Composite.takeNoticeOfAddedInteraction | public function takeNoticeOfAddedInteraction(Interaction $interaction, Item $item){
$irp = InteractionResponseProcessing::create(
MatchCorrectTemplate::CLASS_ID, $interaction->getResponse(), $item
);
$this->add($irp);
} | php | public function takeNoticeOfAddedInteraction(Interaction $interaction, Item $item){
$irp = InteractionResponseProcessing::create(
MatchCorrectTemplate::CLASS_ID, $interaction->getResponse(), $item
);
$this->add($irp);
} | [
"public",
"function",
"takeNoticeOfAddedInteraction",
"(",
"Interaction",
"$",
"interaction",
",",
"Item",
"$",
"item",
")",
"{",
"$",
"irp",
"=",
"InteractionResponseProcessing",
"::",
"create",
"(",
"MatchCorrectTemplate",
"::",
"CLASS_ID",
",",
"$",
"interaction"... | Short description of method takeNoticeOfAddedInteraction
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@param Interaction interaction
@param Item item
@return mixed | [
"Short",
"description",
"of",
"method",
"takeNoticeOfAddedInteraction"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/response/Composite.php#L299-L304 |
oat-sa/extension-tao-itemqti | model/qti/response/Composite.php | Composite.takeNoticeOfRemovedInteraction | public function takeNoticeOfRemovedInteraction(Interaction $interaction, Item $item){
$irpExisted = false;
foreach($this->components as $key => $irp){
if($irp->getResponse() === $interaction->getResponse()){
unset($this->components[$key]);
$irpExisted = true;
break;
}
}
if(!$irpExisted){
common_Logger::w('InstanceResponseProcessing not found for removed interaction '.$interaction->getIdentifier(), array('TAOITEMS', 'QTI'));
}
} | php | public function takeNoticeOfRemovedInteraction(Interaction $interaction, Item $item){
$irpExisted = false;
foreach($this->components as $key => $irp){
if($irp->getResponse() === $interaction->getResponse()){
unset($this->components[$key]);
$irpExisted = true;
break;
}
}
if(!$irpExisted){
common_Logger::w('InstanceResponseProcessing not found for removed interaction '.$interaction->getIdentifier(), array('TAOITEMS', 'QTI'));
}
} | [
"public",
"function",
"takeNoticeOfRemovedInteraction",
"(",
"Interaction",
"$",
"interaction",
",",
"Item",
"$",
"item",
")",
"{",
"$",
"irpExisted",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"components",
"as",
"$",
"key",
"=>",
"$",
"irp",
"... | Short description of method takeNoticeOfRemovedInteraction
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@param Interaction interaction
@param Item item
@return mixed | [
"Short",
"description",
"of",
"method",
"takeNoticeOfRemovedInteraction"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/response/Composite.php#L315-L327 |
oat-sa/extension-tao-itemqti | model/qti/response/Composite.php | Composite.getForm | public function getForm(ResponseDeclaration $response){
$formContainer = new CompositeResponseOptions($this, $response);
$returnValue = $formContainer->getForm();
return $returnValue;
} | php | public function getForm(ResponseDeclaration $response){
$formContainer = new CompositeResponseOptions($this, $response);
$returnValue = $formContainer->getForm();
return $returnValue;
} | [
"public",
"function",
"getForm",
"(",
"ResponseDeclaration",
"$",
"response",
")",
"{",
"$",
"formContainer",
"=",
"new",
"CompositeResponseOptions",
"(",
"$",
"this",
",",
"$",
"response",
")",
";",
"$",
"returnValue",
"=",
"$",
"formContainer",
"->",
"getFor... | Short description of method getForm
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@param Response response
@return tao_helpers_form_Form | [
"Short",
"description",
"of",
"method",
"getForm"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/response/Composite.php#L337-L342 |
oat-sa/extension-tao-itemqti | model/qti/interaction/ImsPortableCustomInteraction.php | ImsPortableCustomInteraction.feed | public function feed(ParserFactory $parser, DOMElement $data, QtiNamespace $xmlns = null){
$this->setNamespace($xmlns);
$xmlnsName = $xmlns->getName();
$pciNodes = $parser->queryXPathChildren(array('portableCustomInteraction'), $data, $xmlnsName);
if(!$pciNodes->length) {
$xmlnsName = '';//even if a namespace has been defined, it may not be used
$pciNodes = $parser->queryXPathChildren(array('portableCustomInteraction'), $data, $xmlnsName);
}
if(!$pciNodes->length) {
throw new QtiModelException('no ims portableCustomInteraction node found');
}
$typeIdentifier = $pciNodes->item(0)->getAttribute('customInteractionTypeIdentifier');
if(empty($typeIdentifier)){
throw new QtiModelException('the type identifier of the pci is missing');
}else{
$this->setTypeIdentifier($typeIdentifier);
}
$version = $pciNodes->item(0)->getAttribute('data-version');
if($version){
$this->setVersion($version);
}
$rootModulesNodes = $parser->queryXPathChildren(array('portableCustomInteraction', 'modules'), $data, $xmlnsName);
foreach($rootModulesNodes as $rootModulesNode){
$config = [];
if($rootModulesNode->getAttribute('primaryConfiguration')){
$config[] = $rootModulesNode->getAttribute('primaryConfiguration');
}
if($rootModulesNode->getAttribute('fallbackConfiguration')){
$config[] = $rootModulesNode->getAttribute('fallbackConfiguration');
}
$this->setConfig($config);
}
$moduleNodes = $parser->queryXPathChildren(array('portableCustomInteraction', 'modules', 'module'), $data, $xmlnsName);
foreach($moduleNodes as $libNode){
$id = $libNode->getAttribute('id');
$paths = [];
if($libNode->getAttribute('primaryPath')){
$paths[] = $libNode->getAttribute('primaryPath');
}
if($libNode->getAttribute('fallbackPath')){
$paths[] = $libNode->getAttribute('fallbackPath');
}
$this->addModule($id, $paths);
}
$propertyNodes = $parser->queryXPathChildren(array('portableCustomInteraction', 'properties'), $data, $xmlnsName);
if($propertyNodes->length){
$properties = $this->extractProperties($propertyNodes->item(0), $xmlnsName);
$this->setProperties($properties);
}
$markupNodes = $parser->queryXPathChildren(array('portableCustomInteraction', 'markup'), $data, $xmlnsName);
if($markupNodes->length){
$markup = $parser->getBodyData($markupNodes->item(0), true, true);
$this->setMarkup($markup);
}
} | php | public function feed(ParserFactory $parser, DOMElement $data, QtiNamespace $xmlns = null){
$this->setNamespace($xmlns);
$xmlnsName = $xmlns->getName();
$pciNodes = $parser->queryXPathChildren(array('portableCustomInteraction'), $data, $xmlnsName);
if(!$pciNodes->length) {
$xmlnsName = '';//even if a namespace has been defined, it may not be used
$pciNodes = $parser->queryXPathChildren(array('portableCustomInteraction'), $data, $xmlnsName);
}
if(!$pciNodes->length) {
throw new QtiModelException('no ims portableCustomInteraction node found');
}
$typeIdentifier = $pciNodes->item(0)->getAttribute('customInteractionTypeIdentifier');
if(empty($typeIdentifier)){
throw new QtiModelException('the type identifier of the pci is missing');
}else{
$this->setTypeIdentifier($typeIdentifier);
}
$version = $pciNodes->item(0)->getAttribute('data-version');
if($version){
$this->setVersion($version);
}
$rootModulesNodes = $parser->queryXPathChildren(array('portableCustomInteraction', 'modules'), $data, $xmlnsName);
foreach($rootModulesNodes as $rootModulesNode){
$config = [];
if($rootModulesNode->getAttribute('primaryConfiguration')){
$config[] = $rootModulesNode->getAttribute('primaryConfiguration');
}
if($rootModulesNode->getAttribute('fallbackConfiguration')){
$config[] = $rootModulesNode->getAttribute('fallbackConfiguration');
}
$this->setConfig($config);
}
$moduleNodes = $parser->queryXPathChildren(array('portableCustomInteraction', 'modules', 'module'), $data, $xmlnsName);
foreach($moduleNodes as $libNode){
$id = $libNode->getAttribute('id');
$paths = [];
if($libNode->getAttribute('primaryPath')){
$paths[] = $libNode->getAttribute('primaryPath');
}
if($libNode->getAttribute('fallbackPath')){
$paths[] = $libNode->getAttribute('fallbackPath');
}
$this->addModule($id, $paths);
}
$propertyNodes = $parser->queryXPathChildren(array('portableCustomInteraction', 'properties'), $data, $xmlnsName);
if($propertyNodes->length){
$properties = $this->extractProperties($propertyNodes->item(0), $xmlnsName);
$this->setProperties($properties);
}
$markupNodes = $parser->queryXPathChildren(array('portableCustomInteraction', 'markup'), $data, $xmlnsName);
if($markupNodes->length){
$markup = $parser->getBodyData($markupNodes->item(0), true, true);
$this->setMarkup($markup);
}
} | [
"public",
"function",
"feed",
"(",
"ParserFactory",
"$",
"parser",
",",
"DOMElement",
"$",
"data",
",",
"QtiNamespace",
"$",
"xmlns",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"setNamespace",
"(",
"$",
"xmlns",
")",
";",
"$",
"xmlnsName",
"=",
"$",
"xm... | Feed the pci instance with data provided in the pci dom node
@param ParserFactory $parser
@param DOMElement $data
@throws InvalidArgumentException
@throws QtiModelException | [
"Feed",
"the",
"pci",
"instance",
"with",
"data",
"provided",
"in",
"the",
"pci",
"dom",
"node"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/interaction/ImsPortableCustomInteraction.php#L155-L217 |
oat-sa/extension-tao-itemqti | model/search/QtiItemContentTokenizer.php | QtiItemContentTokenizer.getStrings | public function getStrings(\core_kernel_classes_Resource $resource)
{
try {
$ontologyFiles = $resource->getPropertyValues($this->getProperty(taoItems_models_classes_ItemsService::PROPERTY_ITEM_CONTENT));
if (empty($ontologyFiles)) {
return [];
}
} catch (\core_kernel_classes_EmptyProperty $e) {
return [];
}
$file = $this->getFileReferenceSerializer()
->unserializeDirectory(reset($ontologyFiles))
->getFile(Service::QTI_ITEM_FILE);
if (! $file->exists()) {
return [];
}
$content = $file->read();
if (empty($content)) {
return [];
}
$dom = new \DOMDocument();
$dom->loadXML($content);
$xpath = new \DOMXPath($dom);
$textNodes = $xpath->query('//text()');
unset($xpath);
$contentStrings = array();
foreach ($textNodes as $textNode) {
if (ctype_space($textNode->wholeText) === false) {
$contentStrings[] = trim($textNode->wholeText);
}
}
return $contentStrings;
} | php | public function getStrings(\core_kernel_classes_Resource $resource)
{
try {
$ontologyFiles = $resource->getPropertyValues($this->getProperty(taoItems_models_classes_ItemsService::PROPERTY_ITEM_CONTENT));
if (empty($ontologyFiles)) {
return [];
}
} catch (\core_kernel_classes_EmptyProperty $e) {
return [];
}
$file = $this->getFileReferenceSerializer()
->unserializeDirectory(reset($ontologyFiles))
->getFile(Service::QTI_ITEM_FILE);
if (! $file->exists()) {
return [];
}
$content = $file->read();
if (empty($content)) {
return [];
}
$dom = new \DOMDocument();
$dom->loadXML($content);
$xpath = new \DOMXPath($dom);
$textNodes = $xpath->query('//text()');
unset($xpath);
$contentStrings = array();
foreach ($textNodes as $textNode) {
if (ctype_space($textNode->wholeText) === false) {
$contentStrings[] = trim($textNode->wholeText);
}
}
return $contentStrings;
} | [
"public",
"function",
"getStrings",
"(",
"\\",
"core_kernel_classes_Resource",
"$",
"resource",
")",
"{",
"try",
"{",
"$",
"ontologyFiles",
"=",
"$",
"resource",
"->",
"getPropertyValues",
"(",
"$",
"this",
"->",
"getProperty",
"(",
"taoItems_models_classes_ItemsSer... | Get tokens as string[] extracted from a QTI file
XML inside qti.xml is parsed and all text is tokenized
@param \core_kernel_classes_Resource $resource
@return array | [
"Get",
"tokens",
"as",
"string",
"[]",
"extracted",
"from",
"a",
"QTI",
"file",
"XML",
"inside",
"qti",
".",
"xml",
"is",
"parsed",
"and",
"all",
"text",
"is",
"tokenized"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/search/QtiItemContentTokenizer.php#L42-L81 |
oat-sa/extension-tao-itemqti | model/qti/PortableElementTrait.php | PortableElementTrait.serializePortableProperties | private function serializePortableProperties($properties, $ns = '', $nsUri = '', $name = null, $element = null){
$document = null;
$result = '';
if ($element === null) {
$document = new \DomDocument();
$element = $ns ?
$document->createElementNS($nsUri, $ns . ':properties') :
$document->createElement('properties');
$document->appendChild($element);
} else {
$newElement = $ns ?
$element->ownerDocument->createElementNS($nsUri, $ns . ':properties') :
$element->ownerDocument->createElement('properties');
$element->appendChild($newElement);
$element = $newElement;
}
if ($name !== null) {
$element->setAttribute('key', $name);
}
foreach ($properties as $name => $value) {
if(is_array($value)){
$this->serializePortableProperties($value, $ns, $nsUri, $name, $element);
} else {
$entryElement = $ns ?
$element->ownerDocument->createElementNS($nsUri, $ns . ':property') :
$element->ownerDocument->createElement('property');
$entryElement->setAttribute('key', $name);
$entryElement->appendChild(new \DOMText($value));
$element->appendChild($entryElement);
}
}
if ($document !== null) {
foreach ($document->childNodes as $node) {
$result .= $document->saveXML($node);
}
}
return $result;
} | php | private function serializePortableProperties($properties, $ns = '', $nsUri = '', $name = null, $element = null){
$document = null;
$result = '';
if ($element === null) {
$document = new \DomDocument();
$element = $ns ?
$document->createElementNS($nsUri, $ns . ':properties') :
$document->createElement('properties');
$document->appendChild($element);
} else {
$newElement = $ns ?
$element->ownerDocument->createElementNS($nsUri, $ns . ':properties') :
$element->ownerDocument->createElement('properties');
$element->appendChild($newElement);
$element = $newElement;
}
if ($name !== null) {
$element->setAttribute('key', $name);
}
foreach ($properties as $name => $value) {
if(is_array($value)){
$this->serializePortableProperties($value, $ns, $nsUri, $name, $element);
} else {
$entryElement = $ns ?
$element->ownerDocument->createElementNS($nsUri, $ns . ':property') :
$element->ownerDocument->createElement('property');
$entryElement->setAttribute('key', $name);
$entryElement->appendChild(new \DOMText($value));
$element->appendChild($entryElement);
}
}
if ($document !== null) {
foreach ($document->childNodes as $node) {
$result .= $document->saveXML($node);
}
}
return $result;
} | [
"private",
"function",
"serializePortableProperties",
"(",
"$",
"properties",
",",
"$",
"ns",
"=",
"''",
",",
"$",
"nsUri",
"=",
"''",
",",
"$",
"name",
"=",
"null",
",",
"$",
"element",
"=",
"null",
")",
"{",
"$",
"document",
"=",
"null",
";",
"$",
... | Serialize an associative array of pci properties into a pci xml
@param array $properties
@param string $ns
@return string | [
"Serialize",
"an",
"associative",
"array",
"of",
"pci",
"properties",
"into",
"a",
"pci",
"xml"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/PortableElementTrait.php#L81-L126 |
oat-sa/extension-tao-itemqti | model/qti/PortableElementTrait.php | PortableElementTrait.extractProperties | private function extractProperties(DOMElement $propertiesNode, $ns = ''){
$properties = array();
$ns = $ns ? trim( $ns, ':' ) . ':' : '';
foreach($propertiesNode->childNodes as $prop){
if($prop instanceof DOMElement){
switch($prop->tagName){
case $ns.'entry'://OAT PCI uses entry as property node
case $ns.'property'://IMS PCI uses entry as property node
$key = $prop->getAttribute('key');
$properties[$key] = $prop->nodeValue;
break;
case $ns.'properties':
$key = $prop->getAttribute('key');
$properties[$key] = $this->extractProperties($prop, $ns);
break;
}
}
}
return $properties;
} | php | private function extractProperties(DOMElement $propertiesNode, $ns = ''){
$properties = array();
$ns = $ns ? trim( $ns, ':' ) . ':' : '';
foreach($propertiesNode->childNodes as $prop){
if($prop instanceof DOMElement){
switch($prop->tagName){
case $ns.'entry'://OAT PCI uses entry as property node
case $ns.'property'://IMS PCI uses entry as property node
$key = $prop->getAttribute('key');
$properties[$key] = $prop->nodeValue;
break;
case $ns.'properties':
$key = $prop->getAttribute('key');
$properties[$key] = $this->extractProperties($prop, $ns);
break;
}
}
}
return $properties;
} | [
"private",
"function",
"extractProperties",
"(",
"DOMElement",
"$",
"propertiesNode",
",",
"$",
"ns",
"=",
"''",
")",
"{",
"$",
"properties",
"=",
"array",
"(",
")",
";",
"$",
"ns",
"=",
"$",
"ns",
"?",
"trim",
"(",
"$",
"ns",
",",
"':'",
")",
".",... | Parse a pci properties dom node into an associative array
@param DOMElement $propertiesNode
@param string $ns
@return array | [
"Parse",
"a",
"pci",
"properties",
"dom",
"node",
"into",
"an",
"associative",
"array"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/PortableElementTrait.php#L135-L158 |
oat-sa/extension-tao-itemqti | model/qti/response/ConditionalExpression.php | ConditionalExpression.getRule | public function getRule()
{
$returnValue = (string) '';
$returnValue = 'if('.$this->getCondition()->getRule().') {';
foreach ($this->getActions() as $actions) {
$returnValue .= $actions->getRule();
}
$returnValue .= '}';
return (string) $returnValue;
} | php | public function getRule()
{
$returnValue = (string) '';
$returnValue = 'if('.$this->getCondition()->getRule().') {';
foreach ($this->getActions() as $actions) {
$returnValue .= $actions->getRule();
}
$returnValue .= '}';
return (string) $returnValue;
} | [
"public",
"function",
"getRule",
"(",
")",
"{",
"$",
"returnValue",
"=",
"(",
"string",
")",
"''",
";",
"$",
"returnValue",
"=",
"'if('",
".",
"$",
"this",
"->",
"getCondition",
"(",
")",
"->",
"getRule",
"(",
")",
".",
"') {'",
";",
"foreach",
"(",
... | Short description of method getRule
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@return string | [
"Short",
"description",
"of",
"method",
"getRule"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/response/ConditionalExpression.php#L68-L83 |
oat-sa/extension-tao-itemqti | model/qti/metadata/imsManifest/ImsManifestMetadataInjector.php | ImsManifestMetadataInjector.setMappings | protected function setMappings(array $mappings = array())
{
foreach ($mappings as $mapping) {
if (!$mapping instanceof ImsManifestMapping) {
$msg = "The mappings argument must be an array composed of ImsManifestMapping objects";
throw new InvalidArgumentException($msg);
}
}
$this->mappings = $mappings;
} | php | protected function setMappings(array $mappings = array())
{
foreach ($mappings as $mapping) {
if (!$mapping instanceof ImsManifestMapping) {
$msg = "The mappings argument must be an array composed of ImsManifestMapping objects";
throw new InvalidArgumentException($msg);
}
}
$this->mappings = $mappings;
} | [
"protected",
"function",
"setMappings",
"(",
"array",
"$",
"mappings",
"=",
"array",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"mappings",
"as",
"$",
"mapping",
")",
"{",
"if",
"(",
"!",
"$",
"mapping",
"instanceof",
"ImsManifestMapping",
")",
"{",
"$",
... | Set the ImsManifestMapping objects of this injector.
@param ImsManifestMapping[] $mappings An array of ImsManifestMapping objects.
@throws InvalidArgumentException If $mappings contains objects/values different from ImsManifestMapping. | [
"Set",
"the",
"ImsManifestMapping",
"objects",
"of",
"this",
"injector",
"."
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/imsManifest/ImsManifestMetadataInjector.php#L65-L75 |
oat-sa/extension-tao-itemqti | model/qti/metadata/imsManifest/ImsManifestMetadataInjector.php | ImsManifestMetadataInjector.addMapping | public function addMapping(ImsManifestMapping $mapping)
{
$mappings = $this->getMappings();
$ns = $mapping->getNamespace();
if (isset($mappings[$ns]) === false) {
$mappings[$ns] = $mapping;
}
$this->setMappings($mappings);
} | php | public function addMapping(ImsManifestMapping $mapping)
{
$mappings = $this->getMappings();
$ns = $mapping->getNamespace();
if (isset($mappings[$ns]) === false) {
$mappings[$ns] = $mapping;
}
$this->setMappings($mappings);
} | [
"public",
"function",
"addMapping",
"(",
"ImsManifestMapping",
"$",
"mapping",
")",
"{",
"$",
"mappings",
"=",
"$",
"this",
"->",
"getMappings",
"(",
")",
";",
"$",
"ns",
"=",
"$",
"mapping",
"->",
"getNamespace",
"(",
")",
";",
"if",
"(",
"isset",
"("... | Add an XML mapping to this Manifest Extractor.
If a mapping with an already registered XML namespace is given as
a $mapping, it is simply ignored.
@param ImsManifestMapping $mapping An XML mapping. | [
"Add",
"an",
"XML",
"mapping",
"to",
"this",
"Manifest",
"Extractor",
"."
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/imsManifest/ImsManifestMetadataInjector.php#L96-L107 |
oat-sa/extension-tao-itemqti | model/qti/metadata/imsManifest/ImsManifestMetadataInjector.php | ImsManifestMetadataInjector.removeMapping | public function removeMapping(ImsManifestMapping $mapping)
{
$mappings = $this->getMappings();
if (($key = array_search($mapping, $mappings, true)) !== false) {
unset($mappings[$key]);
}
} | php | public function removeMapping(ImsManifestMapping $mapping)
{
$mappings = $this->getMappings();
if (($key = array_search($mapping, $mappings, true)) !== false) {
unset($mappings[$key]);
}
} | [
"public",
"function",
"removeMapping",
"(",
"ImsManifestMapping",
"$",
"mapping",
")",
"{",
"$",
"mappings",
"=",
"$",
"this",
"->",
"getMappings",
"(",
")",
";",
"if",
"(",
"(",
"$",
"key",
"=",
"array_search",
"(",
"$",
"mapping",
",",
"$",
"mappings",... | Remove an already registered ImsManifestMapping.
If $mapping cannot be found as a previously registered mapping, nothing happens.
@param ImsManifestMapping $mapping An ImsManifestMapping object. | [
"Remove",
"an",
"already",
"registered",
"ImsManifestMapping",
"."
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/imsManifest/ImsManifestMetadataInjector.php#L116-L123 |
oat-sa/extension-tao-itemqti | model/qti/metadata/imsManifest/ImsManifestMetadataInjector.php | ImsManifestMetadataInjector.inject | public function inject($target, array $values)
{
/** @var $target DOMDocument */
if(! $target instanceof DOMDocument){
throw new MetadataInjectionException(__('The target must be an instance of DOMDocument'));
}
$map = [];
// Inject the mapping in the root node
foreach($this->getMappings() as $mapping){
/** @var $root DOMElement */
$root = $target->getElementsByTagName('manifest')->item(0);
$root->setAttribute('xmlns:'.$mapping->getPrefix(), $mapping->getNamespace());
$root->setAttribute(
'xsi:schemaLocation',
$root->getAttribute('xsi:schemaLocation') . ' ' . $mapping->getNamespace(
) . ' ' . $mapping->getSchemaLocation());
$map[$mapping->getNamespace()] = $mapping->getPrefix();
}
// Get all resource nodes
$resources = $target->getElementsByTagName('resource');
// Iterate through values to inject them in the DOMElement
foreach($values as $identifier => $metadataValues){
$metadataNode = null;
// Search the node that has the given identifier
/** @var $resource DOMElement */
foreach($resources as $resource){
if($resource->getAttribute('identifier') === $identifier){
// If metadata already exists we take it
if($resource->getElementsByTagName('metadata')->length !== 0){
$metadataNode = $resource->getElementsByTagName('metadata')->item(0);
}
else{
$metadataNode = $target->createElement('metadata');
}
if($resource->getElementsByTagName('file')->length !== 0){
$fileNode = $resource->getElementsByTagName('file')->item(0);
$resource->insertBefore($metadataNode, $fileNode);
}
else{
$resource->appendChild($metadataNode);
}
break;
}
}
if (is_null($metadataNode) || empty($map)) {
continue;
}
// Add the metadata values into the right path
/** @var $metadata MetaDataValue */
foreach($metadataValues as $metadata){
$this->createMetadataElement($metadata, $metadataNode, $map, $target);
}
}
} | php | public function inject($target, array $values)
{
/** @var $target DOMDocument */
if(! $target instanceof DOMDocument){
throw new MetadataInjectionException(__('The target must be an instance of DOMDocument'));
}
$map = [];
// Inject the mapping in the root node
foreach($this->getMappings() as $mapping){
/** @var $root DOMElement */
$root = $target->getElementsByTagName('manifest')->item(0);
$root->setAttribute('xmlns:'.$mapping->getPrefix(), $mapping->getNamespace());
$root->setAttribute(
'xsi:schemaLocation',
$root->getAttribute('xsi:schemaLocation') . ' ' . $mapping->getNamespace(
) . ' ' . $mapping->getSchemaLocation());
$map[$mapping->getNamespace()] = $mapping->getPrefix();
}
// Get all resource nodes
$resources = $target->getElementsByTagName('resource');
// Iterate through values to inject them in the DOMElement
foreach($values as $identifier => $metadataValues){
$metadataNode = null;
// Search the node that has the given identifier
/** @var $resource DOMElement */
foreach($resources as $resource){
if($resource->getAttribute('identifier') === $identifier){
// If metadata already exists we take it
if($resource->getElementsByTagName('metadata')->length !== 0){
$metadataNode = $resource->getElementsByTagName('metadata')->item(0);
}
else{
$metadataNode = $target->createElement('metadata');
}
if($resource->getElementsByTagName('file')->length !== 0){
$fileNode = $resource->getElementsByTagName('file')->item(0);
$resource->insertBefore($metadataNode, $fileNode);
}
else{
$resource->appendChild($metadataNode);
}
break;
}
}
if (is_null($metadataNode) || empty($map)) {
continue;
}
// Add the metadata values into the right path
/** @var $metadata MetaDataValue */
foreach($metadataValues as $metadata){
$this->createMetadataElement($metadata, $metadataNode, $map, $target);
}
}
} | [
"public",
"function",
"inject",
"(",
"$",
"target",
",",
"array",
"$",
"values",
")",
"{",
"/** @var $target DOMDocument */",
"if",
"(",
"!",
"$",
"target",
"instanceof",
"DOMDocument",
")",
"{",
"throw",
"new",
"MetadataInjectionException",
"(",
"__",
"(",
"'... | Inject some MetadataValue objects into the $target DOMElement object.
The injection will take care of serializing the MetadataValue objects into the correct sections of the
the IMS Manifest File, by looking at previously registered IMSManifestMapping objects.
@throws MetadataInjectionException If $target is not a DOMDocument object or something goes wrong during the injection process. | [
"Inject",
"some",
"MetadataValue",
"objects",
"into",
"the",
"$target",
"DOMElement",
"object",
"."
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/imsManifest/ImsManifestMetadataInjector.php#L159-L222 |
oat-sa/extension-tao-itemqti | model/qti/metadata/imsManifest/ImsManifestMetadataInjector.php | ImsManifestMetadataInjector.createMetadataElement | protected function createMetadataElement(MetadataValue $metadata, DOMElement $metadataNode, $map, DOMDocument $imsManifest)
{
$path = $metadata->getPath();
$path = array_reverse($path);
$uniqNodes = [];
if ($metadata instanceof ClassificationValue) {
$uniqNodes = array('taxonPath', 'source');
}
$oldChildNode = null;
foreach($path as $index => $element) {
$name = substr($element,(strpos($element,'#') + 1));
$base = substr($element,0,(strpos($element,'#')));
if (in_array($name, $uniqNodes) || is_null($oldChildNode) || $metadataNode->getElementsByTagName($map[$base].':'.$name)->length === 0) {
$node = $imsManifest->createElement($map[$base].':'.$name);
} else {
$node = $metadataNode->getElementsByTagName($map[$base].':'.$name)->item(0);
}
if($name == 'string' || $name == 'langstring'){
$node->setAttribute('xml:lang', $metadata->getLanguage());
}
if(isset($oldChildNode)){
$node->appendChild($oldChildNode);
if ($name == 'taxonPath' && $metadata instanceof ClassificationMetadataValue) {
foreach ($metadata->getEntries() as $entry) {
$this->createMetadataElement($entry, $node, $map, $imsManifest);
}
}
} else{
$node->nodeValue = $metadata->getValue();
}
$oldChildNode = $node;
}
$metadataNode->appendChild($oldChildNode);
} | php | protected function createMetadataElement(MetadataValue $metadata, DOMElement $metadataNode, $map, DOMDocument $imsManifest)
{
$path = $metadata->getPath();
$path = array_reverse($path);
$uniqNodes = [];
if ($metadata instanceof ClassificationValue) {
$uniqNodes = array('taxonPath', 'source');
}
$oldChildNode = null;
foreach($path as $index => $element) {
$name = substr($element,(strpos($element,'#') + 1));
$base = substr($element,0,(strpos($element,'#')));
if (in_array($name, $uniqNodes) || is_null($oldChildNode) || $metadataNode->getElementsByTagName($map[$base].':'.$name)->length === 0) {
$node = $imsManifest->createElement($map[$base].':'.$name);
} else {
$node = $metadataNode->getElementsByTagName($map[$base].':'.$name)->item(0);
}
if($name == 'string' || $name == 'langstring'){
$node->setAttribute('xml:lang', $metadata->getLanguage());
}
if(isset($oldChildNode)){
$node->appendChild($oldChildNode);
if ($name == 'taxonPath' && $metadata instanceof ClassificationMetadataValue) {
foreach ($metadata->getEntries() as $entry) {
$this->createMetadataElement($entry, $node, $map, $imsManifest);
}
}
} else{
$node->nodeValue = $metadata->getValue();
}
$oldChildNode = $node;
}
$metadataNode->appendChild($oldChildNode);
} | [
"protected",
"function",
"createMetadataElement",
"(",
"MetadataValue",
"$",
"metadata",
",",
"DOMElement",
"$",
"metadataNode",
",",
"$",
"map",
",",
"DOMDocument",
"$",
"imsManifest",
")",
"{",
"$",
"path",
"=",
"$",
"metadata",
"->",
"getPath",
"(",
")",
... | Add an element based on MetadataValue object to DomDocument
@param MetadataValue $metadata
@param DOMElement $metadataNode
@param $map
@param DOMDocument $imsManifest | [
"Add",
"an",
"element",
"based",
"on",
"MetadataValue",
"object",
"to",
"DomDocument"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/imsManifest/ImsManifestMetadataInjector.php#L232-L271 |
oat-sa/extension-tao-itemqti | model/compile/QtiItemCompilerAssetBlacklist.php | QtiItemCompilerAssetBlacklist.isBlacklisted | public function isBlacklisted($assetPath)
{
foreach ($this->blacklist as $pattern){
if(preg_match($pattern, $assetPath) === 1){
return true;
}
}
return false;
} | php | public function isBlacklisted($assetPath)
{
foreach ($this->blacklist as $pattern){
if(preg_match($pattern, $assetPath) === 1){
return true;
}
}
return false;
} | [
"public",
"function",
"isBlacklisted",
"(",
"$",
"assetPath",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"blacklist",
"as",
"$",
"pattern",
")",
"{",
"if",
"(",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"assetPath",
")",
"===",
"1",
")",
"{",
"r... | Allow to know if a path is blacklisted or not
@param string $assetPath
@return bool | [
"Allow",
"to",
"know",
"if",
"a",
"path",
"is",
"blacklisted",
"or",
"not"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/compile/QtiItemCompilerAssetBlacklist.php#L57-L66 |
oat-sa/extension-tao-itemqti | model/qti/Parser.php | Parser.validate | public function validate($schema = ''){
if (empty($schema)) {
// Let's detect NS in use...
$dom = new DOMDocument('1.0', 'UTF-8');
switch($this->sourceType){
case self::SOURCE_FLYFILE:
if ($this->source->exists()) {
$dom->load($this->source->read());
}
break;
case self::SOURCE_FILE:
$dom->load($this->source);
break;
case self::SOURCE_URL:
$xmlContent = tao_helpers_Request::load($this->source, true);
$dom->loadXML($xmlContent);
break;
case self::SOURCE_STRING:
$dom->loadXML($this->source);
break;
}
// Retrieve Root's namespace.
if( $dom->documentElement == null ){
$this->addError('dom is null and could not be validate');
$returnValue = false;
} else {
$ns = $dom->documentElement->lookupNamespaceUri(null);
$servicemanager = $this->getServiceManager();
$validationService = $servicemanager->get(ValidationService::SERVICE_ID);
$schemas = $validationService->getContentValidationSchema($ns);
$this->logDebug("The following schema will be used to validate: '" . $schemas[0] . "'.");
$validSchema = $this->validateMultiple($schemas);
$returnValue = $validSchema !== '';
}
} elseif(!file_exists($schema)) {
throw new \common_Exception('no schema found in the location '.$schema);
} else {
$returnValue = parent::validate($schema);
}
return (bool) $returnValue;
} | php | public function validate($schema = ''){
if (empty($schema)) {
// Let's detect NS in use...
$dom = new DOMDocument('1.0', 'UTF-8');
switch($this->sourceType){
case self::SOURCE_FLYFILE:
if ($this->source->exists()) {
$dom->load($this->source->read());
}
break;
case self::SOURCE_FILE:
$dom->load($this->source);
break;
case self::SOURCE_URL:
$xmlContent = tao_helpers_Request::load($this->source, true);
$dom->loadXML($xmlContent);
break;
case self::SOURCE_STRING:
$dom->loadXML($this->source);
break;
}
// Retrieve Root's namespace.
if( $dom->documentElement == null ){
$this->addError('dom is null and could not be validate');
$returnValue = false;
} else {
$ns = $dom->documentElement->lookupNamespaceUri(null);
$servicemanager = $this->getServiceManager();
$validationService = $servicemanager->get(ValidationService::SERVICE_ID);
$schemas = $validationService->getContentValidationSchema($ns);
$this->logDebug("The following schema will be used to validate: '" . $schemas[0] . "'.");
$validSchema = $this->validateMultiple($schemas);
$returnValue = $validSchema !== '';
}
} elseif(!file_exists($schema)) {
throw new \common_Exception('no schema found in the location '.$schema);
} else {
$returnValue = parent::validate($schema);
}
return (bool) $returnValue;
} | [
"public",
"function",
"validate",
"(",
"$",
"schema",
"=",
"''",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"schema",
")",
")",
"{",
"// Let's detect NS in use...",
"$",
"dom",
"=",
"new",
"DOMDocument",
"(",
"'1.0'",
",",
"'UTF-8'",
")",
";",
"switch",
"... | Run the validation process
@access public
@author Jerome Bogaerts, <jerome.bogaerts@tudor.lu>
@param string $schema
@return bool
@throws \Exception
@throws \common_Exception | [
"Run",
"the",
"validation",
"process"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/Parser.php#L60-L106 |
oat-sa/extension-tao-itemqti | model/qti/Parser.php | Parser.load | public function load($resolveXInclude = false){
$returnValue = null;
if(!$this->valid){
libxml_use_internal_errors(true); //retrieve errors if no validation has been done previously
}
//load it using the DOMDocument library
$xml = new DOMDocument();
switch($this->sourceType){
case self::SOURCE_FLYFILE:
if ($this->source->exists()) {
$xml->load($this->source->read());
}
break;
case self::SOURCE_FILE:
$xml->load($this->source);
break;
case self::SOURCE_URL:
$xmlContent = tao_helpers_Request::load($this->source, true);
$xml->loadXML($xmlContent);
break;
case self::SOURCE_STRING:
$xml->loadXML($this->source);
break;
}
if($xml !== false){
$basePath = '';
if($this->sourceType == self::SOURCE_FILE || $this->sourceType == self::SOURCE_URL){
$basePath = dirname($this->source).'/';
}
//build the item from the xml
$parserFactory = new ParserFactory($xml, $basePath);
try{
$returnValue = $parserFactory->load();
}catch(UnsupportedQtiElement $e){
$this->addError($e);
}
if(!$this->valid){
$this->valid = true;
libxml_clear_errors();
}
}else if(!$this->valid){
$this->addErrors(libxml_get_errors());
libxml_clear_errors();
}
return $returnValue;
} | php | public function load($resolveXInclude = false){
$returnValue = null;
if(!$this->valid){
libxml_use_internal_errors(true); //retrieve errors if no validation has been done previously
}
//load it using the DOMDocument library
$xml = new DOMDocument();
switch($this->sourceType){
case self::SOURCE_FLYFILE:
if ($this->source->exists()) {
$xml->load($this->source->read());
}
break;
case self::SOURCE_FILE:
$xml->load($this->source);
break;
case self::SOURCE_URL:
$xmlContent = tao_helpers_Request::load($this->source, true);
$xml->loadXML($xmlContent);
break;
case self::SOURCE_STRING:
$xml->loadXML($this->source);
break;
}
if($xml !== false){
$basePath = '';
if($this->sourceType == self::SOURCE_FILE || $this->sourceType == self::SOURCE_URL){
$basePath = dirname($this->source).'/';
}
//build the item from the xml
$parserFactory = new ParserFactory($xml, $basePath);
try{
$returnValue = $parserFactory->load();
}catch(UnsupportedQtiElement $e){
$this->addError($e);
}
if(!$this->valid){
$this->valid = true;
libxml_clear_errors();
}
}else if(!$this->valid){
$this->addErrors(libxml_get_errors());
libxml_clear_errors();
}
return $returnValue;
} | [
"public",
"function",
"load",
"(",
"$",
"resolveXInclude",
"=",
"false",
")",
"{",
"$",
"returnValue",
"=",
"null",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"valid",
")",
"{",
"libxml_use_internal_errors",
"(",
"true",
")",
";",
"//retrieve errors if no valid... | load the file content, parse it and build the a QTI_Item instance
@access public
@author Jerome Bogaerts, <jerome.bogaerts@tudor.lu>
@param boolean resolveXInclude
@return \oat\taoQtiItem\model\qti\Item | [
"load",
"the",
"file",
"content",
"parse",
"it",
"and",
"build",
"the",
"a",
"QTI_Item",
"instance"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/Parser.php#L116-L169 |
oat-sa/extension-tao-itemqti | model/portableElement/exception/PortableElementException.php | PortableElementException.getReportMessages | public function getReportMessages()
{
$messages = array();
/** @var \common_report_Report $subReport */
foreach ($this->report as $subReport) {
$errors = [];
if ($subReport->containsError()) {
$errors = $subReport->getErrors();
}
$messages[] = array(
'message' => $subReport->getMessage(),
'details' => $errors
);
}
return $messages;
} | php | public function getReportMessages()
{
$messages = array();
/** @var \common_report_Report $subReport */
foreach ($this->report as $subReport) {
$errors = [];
if ($subReport->containsError()) {
$errors = $subReport->getErrors();
}
$messages[] = array(
'message' => $subReport->getMessage(),
'details' => $errors
);
}
return $messages;
} | [
"public",
"function",
"getReportMessages",
"(",
")",
"{",
"$",
"messages",
"=",
"array",
"(",
")",
";",
"/** @var \\common_report_Report $subReport */",
"foreach",
"(",
"$",
"this",
"->",
"report",
"as",
"$",
"subReport",
")",
"{",
"$",
"errors",
"=",
"[",
"... | Extract all report messages to simple array
@return array | [
"Extract",
"all",
"report",
"messages",
"to",
"simple",
"array"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/exception/PortableElementException.php#L68-L83 |
oat-sa/extension-tao-itemqti | model/AbstractInteractionRegistry.php | AbstractInteractionRegistry.set | public function set($qtiClass, $phpClass)
{
if (! class_exists($phpClass)) {
throw new common_exception_Error('Custom interaction class ' . $phpClass . ' not found');
}
if (! is_subclass_of($phpClass, $this->getInteractionClass())) {
throw new common_exception_Error('Class ' . $phpClass . ' not a subclass of ' . $this->getInteractionClass());
}
parent::set($qtiClass,$phpClass);
} | php | public function set($qtiClass, $phpClass)
{
if (! class_exists($phpClass)) {
throw new common_exception_Error('Custom interaction class ' . $phpClass . ' not found');
}
if (! is_subclass_of($phpClass, $this->getInteractionClass())) {
throw new common_exception_Error('Class ' . $phpClass . ' not a subclass of ' . $this->getInteractionClass());
}
parent::set($qtiClass,$phpClass);
} | [
"public",
"function",
"set",
"(",
"$",
"qtiClass",
",",
"$",
"phpClass",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"phpClass",
")",
")",
"{",
"throw",
"new",
"common_exception_Error",
"(",
"'Custom interaction class '",
".",
"$",
"phpClass",
".",
... | Register a new custom interaction
@param string $qtiClass
@param string $phpClass
@throws common_exception_Error | [
"Register",
"a",
"new",
"custom",
"interaction"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/AbstractInteractionRegistry.php#L47-L57 |
oat-sa/extension-tao-itemqti | model/qti/asset/handler/LocalAssetHandler.php | LocalAssetHandler.handle | public function handle($absolutePath, $relativePath)
{
if (!$this->itemSource) {
throw new \common_Exception('Missing required parameter: item source');
}
// store locally, in a safe directory
$safePath = '';
if (dirname($relativePath) !== '.') {
$safePath = str_replace('../', '', dirname($relativePath)) . '/';
}
$info = $this->itemSource->add($absolutePath, basename($absolutePath), $safePath);
\common_Logger::i('Asset file \'' . $absolutePath . '\' copied.');
return $info;
} | php | public function handle($absolutePath, $relativePath)
{
if (!$this->itemSource) {
throw new \common_Exception('Missing required parameter: item source');
}
// store locally, in a safe directory
$safePath = '';
if (dirname($relativePath) !== '.') {
$safePath = str_replace('../', '', dirname($relativePath)) . '/';
}
$info = $this->itemSource->add($absolutePath, basename($absolutePath), $safePath);
\common_Logger::i('Asset file \'' . $absolutePath . '\' copied.');
return $info;
} | [
"public",
"function",
"handle",
"(",
"$",
"absolutePath",
",",
"$",
"relativePath",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"itemSource",
")",
"{",
"throw",
"new",
"\\",
"common_Exception",
"(",
"'Missing required parameter: item source'",
")",
";",
"}",
... | Handle the process to add file from $itemSource->add()
@param $absolutePath
@param $relativePath
@return array
@throws \common_Exception
@throws \common_exception_Error | [
"Handle",
"the",
"process",
"to",
"add",
"file",
"from",
"$itemSource",
"-",
">",
"add",
"()"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/asset/handler/LocalAssetHandler.php#L53-L68 |
oat-sa/extension-tao-itemqti | model/QtiJsonItemCompiler.php | QtiJsonItemCompiler.compileJson | public function compileJson()
{
$report = $this->internalCompile();
if ($report->getType() == common_report_Report::TYPE_SUCCESS) {
// replace instances with strign identifiers
list($item, $publicDirectory, $privateDirectory) = $report->getData();
$report->setData([$item->getUri(), $publicDirectory->getId(), $privateDirectory->getId()]);
}
return $report;
} | php | public function compileJson()
{
$report = $this->internalCompile();
if ($report->getType() == common_report_Report::TYPE_SUCCESS) {
// replace instances with strign identifiers
list($item, $publicDirectory, $privateDirectory) = $report->getData();
$report->setData([$item->getUri(), $publicDirectory->getId(), $privateDirectory->getId()]);
}
return $report;
} | [
"public",
"function",
"compileJson",
"(",
")",
"{",
"$",
"report",
"=",
"$",
"this",
"->",
"internalCompile",
"(",
")",
";",
"if",
"(",
"$",
"report",
"->",
"getType",
"(",
")",
"==",
"common_report_Report",
"::",
"TYPE_SUCCESS",
")",
"{",
"// replace inst... | Generate JSON version of item
@return array consists of item URI, public directory id and private directory id | [
"Generate",
"JSON",
"version",
"of",
"item"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/QtiJsonItemCompiler.php#L56-L65 |
oat-sa/extension-tao-itemqti | model/QtiJsonItemCompiler.php | QtiJsonItemCompiler.deployQtiItem | protected function deployQtiItem(
core_kernel_classes_Resource $item,
$language,
tao_models_classes_service_StorageDirectory $publicDirectory,
tao_models_classes_service_StorageDirectory $privateDirectory
)
{
$qtiService = Service::singleton();
// retrieve the media assets
try {
$qtiItem = $this->retrieveAssets($item, $language, $publicDirectory);
$this->compileItemIndex($item->getUri(), $qtiItem, $language);
//store variable qti elements data into the private directory
$variableElements = $qtiService->getVariableElements($qtiItem);
$privateDirectory->write($language.DIRECTORY_SEPARATOR.self::VAR_ELT_FILE_NAME, json_encode($variableElements));
//create the item.json file in private directory
$itemPacker = new QtiItemPacker();
$itemPacker->setReplaceXinclude(false);
$itemPack = $itemPacker->packQtiItem($item, $language, $qtiItem, $publicDirectory);
$this->itemJson = $itemPack->JsonSerialize();
//get the filtered data to avoid cheat
$data = $qtiItem->getDataForDelivery();
$this->itemJson['data'] = $data['core'];
$metadata = $this->getMetadataProperties();
$privateDirectory->write($language.DIRECTORY_SEPARATOR.self::ITEM_FILE_NAME, json_encode($this->itemJson));
$privateDirectory->write($language.DIRECTORY_SEPARATOR.self::METADATA_FILE_NAME, json_encode($metadata));
$privateDirectory->write($language.DIRECTORY_SEPARATOR.self::PORTABLE_ELEMENT_FILE_NAME, json_encode($this->getItemPortableElements($qtiItem)));
return new common_report_Report(
common_report_Report::TYPE_SUCCESS, __('Successfully compiled "%s"', $language)
);
} catch (\tao_models_classes_FileNotFoundException $e) {
return new common_report_Report(
common_report_Report::TYPE_ERROR, __('Unable to retrieve asset "%s"', $e->getFilePath())
);
} catch (XIncludeException $e) {
return new common_report_Report(
common_report_Report::TYPE_ERROR, $e->getUserMessage()
);
} catch (\Exception $e) {
return new common_report_Report(
common_report_Report::TYPE_ERROR, $e->getMessage()
);
}
} | php | protected function deployQtiItem(
core_kernel_classes_Resource $item,
$language,
tao_models_classes_service_StorageDirectory $publicDirectory,
tao_models_classes_service_StorageDirectory $privateDirectory
)
{
$qtiService = Service::singleton();
// retrieve the media assets
try {
$qtiItem = $this->retrieveAssets($item, $language, $publicDirectory);
$this->compileItemIndex($item->getUri(), $qtiItem, $language);
//store variable qti elements data into the private directory
$variableElements = $qtiService->getVariableElements($qtiItem);
$privateDirectory->write($language.DIRECTORY_SEPARATOR.self::VAR_ELT_FILE_NAME, json_encode($variableElements));
//create the item.json file in private directory
$itemPacker = new QtiItemPacker();
$itemPacker->setReplaceXinclude(false);
$itemPack = $itemPacker->packQtiItem($item, $language, $qtiItem, $publicDirectory);
$this->itemJson = $itemPack->JsonSerialize();
//get the filtered data to avoid cheat
$data = $qtiItem->getDataForDelivery();
$this->itemJson['data'] = $data['core'];
$metadata = $this->getMetadataProperties();
$privateDirectory->write($language.DIRECTORY_SEPARATOR.self::ITEM_FILE_NAME, json_encode($this->itemJson));
$privateDirectory->write($language.DIRECTORY_SEPARATOR.self::METADATA_FILE_NAME, json_encode($metadata));
$privateDirectory->write($language.DIRECTORY_SEPARATOR.self::PORTABLE_ELEMENT_FILE_NAME, json_encode($this->getItemPortableElements($qtiItem)));
return new common_report_Report(
common_report_Report::TYPE_SUCCESS, __('Successfully compiled "%s"', $language)
);
} catch (\tao_models_classes_FileNotFoundException $e) {
return new common_report_Report(
common_report_Report::TYPE_ERROR, __('Unable to retrieve asset "%s"', $e->getFilePath())
);
} catch (XIncludeException $e) {
return new common_report_Report(
common_report_Report::TYPE_ERROR, $e->getUserMessage()
);
} catch (\Exception $e) {
return new common_report_Report(
common_report_Report::TYPE_ERROR, $e->getMessage()
);
}
} | [
"protected",
"function",
"deployQtiItem",
"(",
"core_kernel_classes_Resource",
"$",
"item",
",",
"$",
"language",
",",
"tao_models_classes_service_StorageDirectory",
"$",
"publicDirectory",
",",
"tao_models_classes_service_StorageDirectory",
"$",
"privateDirectory",
")",
"{",
... | Desploy all the required files into the provided directories
@param core_kernel_classes_Resource $item
@param string $language
@param tao_models_classes_service_StorageDirectory $publicDirectory
@param tao_models_classes_service_StorageDirectory $privateDirectory
@return common_report_Report | [
"Desploy",
"all",
"the",
"required",
"files",
"into",
"the",
"provided",
"directories"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/QtiJsonItemCompiler.php#L76-L126 |
oat-sa/extension-tao-itemqti | model/QtiJsonItemCompiler.php | QtiJsonItemCompiler.getItemPortableElements | private function getItemPortableElements(Element $qtiItem){
$portableElementService = new PortableElementService();
$portableElementService->setServiceLocator($this->getServiceLocator());
return [
'pci' => $portableElementService->getPortableElementByClass(PortableElementService::PORTABLE_CLASS_INTERACTION, $qtiItem, true),
'pic' => $portableElementService->getPortableElementByClass(PortableElementService::PORTABLE_CLASS_INFOCONTROL, $qtiItem, true)
];
} | php | private function getItemPortableElements(Element $qtiItem){
$portableElementService = new PortableElementService();
$portableElementService->setServiceLocator($this->getServiceLocator());
return [
'pci' => $portableElementService->getPortableElementByClass(PortableElementService::PORTABLE_CLASS_INTERACTION, $qtiItem, true),
'pic' => $portableElementService->getPortableElementByClass(PortableElementService::PORTABLE_CLASS_INFOCONTROL, $qtiItem, true)
];
} | [
"private",
"function",
"getItemPortableElements",
"(",
"Element",
"$",
"qtiItem",
")",
"{",
"$",
"portableElementService",
"=",
"new",
"PortableElementService",
"(",
")",
";",
"$",
"portableElementService",
"->",
"setServiceLocator",
"(",
"$",
"this",
"->",
"getServ... | Get the portable elements data in use in the item
@param Element $qtiItem
@return array | [
"Get",
"the",
"portable",
"elements",
"data",
"in",
"use",
"in",
"the",
"item"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/QtiJsonItemCompiler.php#L133-L140 |
oat-sa/extension-tao-itemqti | model/QtiJsonItemCompiler.php | QtiJsonItemCompiler.getMetadataProperties | private function getMetadataProperties()
{
$triples = $this->getResource()->getRdfTriples();
$properties = [];
foreach ($triples as $triple){
$properties[$triple->predicate] = $triple->object;
}
//we also include a shortcut to the item URI
$properties['@uri'] = $this->getResource()->getUri();
return $properties;
} | php | private function getMetadataProperties()
{
$triples = $this->getResource()->getRdfTriples();
$properties = [];
foreach ($triples as $triple){
$properties[$triple->predicate] = $triple->object;
}
//we also include a shortcut to the item URI
$properties['@uri'] = $this->getResource()->getUri();
return $properties;
} | [
"private",
"function",
"getMetadataProperties",
"(",
")",
"{",
"$",
"triples",
"=",
"$",
"this",
"->",
"getResource",
"(",
")",
"->",
"getRdfTriples",
"(",
")",
";",
"$",
"properties",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"triples",
"as",
"$",
"tri... | Get the item properties as compiled metadata
@return array | [
"Get",
"the",
"item",
"properties",
"as",
"compiled",
"metadata"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/QtiJsonItemCompiler.php#L146-L156 |
oat-sa/extension-tao-itemqti | model/Export/MetadataExporterForm.php | MetadataExporterForm.initForm | public function initForm()
{
$this->form = new \tao_helpers_form_xhtml_Form('export');
$this->form->setDecorators(array(
'element' => new \tao_helpers_form_xhtml_TagWrapper(array('tag' => 'div')),
'group' => new \tao_helpers_form_xhtml_TagWrapper(array('tag' => 'div', 'cssClass' => 'form-group')),
'error' => new \tao_helpers_form_xhtml_TagWrapper(array('tag' => 'div', 'cssClass' => 'form-error ui-state-error ui-corner-all')),
'actions-bottom' => new \tao_helpers_form_xhtml_TagWrapper(array('tag' => 'div', 'cssClass' => 'form-toolbar')),
'actions-top' => new \tao_helpers_form_xhtml_TagWrapper(array('tag' => 'div', 'cssClass' => 'form-toolbar'))
));
$hiddenClassElt = \tao_helpers_form_FormFactory::getElement('xml_desc', 'Hidden');
$hiddenClassElt->setValue(null);
$this->form->addElement($hiddenClassElt);
$hiddenClassElt = \tao_helpers_form_FormFactory::getElement('exportInstance', 'Hidden');
$hiddenClassElt->setValue(null);
$this->form->addElement($hiddenClassElt);
$exportElt = \tao_helpers_form_FormFactory::getElement('export', 'Free');
$exportElt->setValue('<a href="#" class="form-submitter btn-success small"><span class="icon-export"></span> ' .__('Export metadata').'</a>');
$this->form->setActions(array($exportElt), 'bottom');
} | php | public function initForm()
{
$this->form = new \tao_helpers_form_xhtml_Form('export');
$this->form->setDecorators(array(
'element' => new \tao_helpers_form_xhtml_TagWrapper(array('tag' => 'div')),
'group' => new \tao_helpers_form_xhtml_TagWrapper(array('tag' => 'div', 'cssClass' => 'form-group')),
'error' => new \tao_helpers_form_xhtml_TagWrapper(array('tag' => 'div', 'cssClass' => 'form-error ui-state-error ui-corner-all')),
'actions-bottom' => new \tao_helpers_form_xhtml_TagWrapper(array('tag' => 'div', 'cssClass' => 'form-toolbar')),
'actions-top' => new \tao_helpers_form_xhtml_TagWrapper(array('tag' => 'div', 'cssClass' => 'form-toolbar'))
));
$hiddenClassElt = \tao_helpers_form_FormFactory::getElement('xml_desc', 'Hidden');
$hiddenClassElt->setValue(null);
$this->form->addElement($hiddenClassElt);
$hiddenClassElt = \tao_helpers_form_FormFactory::getElement('exportInstance', 'Hidden');
$hiddenClassElt->setValue(null);
$this->form->addElement($hiddenClassElt);
$exportElt = \tao_helpers_form_FormFactory::getElement('export', 'Free');
$exportElt->setValue('<a href="#" class="form-submitter btn-success small"><span class="icon-export"></span> ' .__('Export metadata').'</a>');
$this->form->setActions(array($exportElt), 'bottom');
} | [
"public",
"function",
"initForm",
"(",
")",
"{",
"$",
"this",
"->",
"form",
"=",
"new",
"\\",
"tao_helpers_form_xhtml_Form",
"(",
"'export'",
")",
";",
"$",
"this",
"->",
"form",
"->",
"setDecorators",
"(",
"array",
"(",
"'element'",
"=>",
"new",
"\\",
"... | Create a form
@throws \Exception
@throws \common_Exception | [
"Create",
"a",
"form"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/Export/MetadataExporterForm.php#L31-L54 |
oat-sa/extension-tao-itemqti | model/Export/MetadataExporterForm.php | MetadataExporterForm.initElements | public function initElements()
{
$date = new \DateTime();
$filename = 'metadata-' . $date->format('ymd');
$nameElt = \tao_helpers_form_FormFactory::getElement('filename', 'Textbox');
$nameElt->setDescription(__('File name'));
$nameElt->setValue($filename);
$nameElt->setUnit(".csv");
$nameElt->addValidator(\tao_helpers_form_FormFactory::getValidator('NotEmpty'));
$this->form->addElement($nameElt);
$this->form->createGroup('options', __('Export metadata item'), array('xml_desc', 'filename', 'exportInstance'));
} | php | public function initElements()
{
$date = new \DateTime();
$filename = 'metadata-' . $date->format('ymd');
$nameElt = \tao_helpers_form_FormFactory::getElement('filename', 'Textbox');
$nameElt->setDescription(__('File name'));
$nameElt->setValue($filename);
$nameElt->setUnit(".csv");
$nameElt->addValidator(\tao_helpers_form_FormFactory::getValidator('NotEmpty'));
$this->form->addElement($nameElt);
$this->form->createGroup('options', __('Export metadata item'), array('xml_desc', 'filename', 'exportInstance'));
} | [
"public",
"function",
"initElements",
"(",
")",
"{",
"$",
"date",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"$",
"filename",
"=",
"'metadata-'",
".",
"$",
"date",
"->",
"format",
"(",
"'ymd'",
")",
";",
"$",
"nameElt",
"=",
"\\",
"tao_helpers_form_F... | Init filename field
@throws \common_Exception | [
"Init",
"filename",
"field"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/Export/MetadataExporterForm.php#L61-L74 |
oat-sa/extension-tao-itemqti | model/portableElement/storage/PortableElementRegistry.php | PortableElementRegistry.fetch | public function fetch($identifier, $version=null)
{
$portableElements = $this->getAllVersions($identifier);
// No version, return latest version
if (is_null($version)) {
$this->krsortByVersion($portableElements);
return $this->getModel()->createDataObject(reset($portableElements));
}
// Version is set, return associated record
if (isset($portableElements[$version])) {
return $this->getModel()->createDataObject($portableElements[$version]);
}
// Version is set, no record found
throw new PortableElementNotFoundException(
$this->getModel()->getId() . ' with identifier ' . $identifier. ' found, '
. 'but version "' . $version . '" does not exist.'
);
} | php | public function fetch($identifier, $version=null)
{
$portableElements = $this->getAllVersions($identifier);
// No version, return latest version
if (is_null($version)) {
$this->krsortByVersion($portableElements);
return $this->getModel()->createDataObject(reset($portableElements));
}
// Version is set, return associated record
if (isset($portableElements[$version])) {
return $this->getModel()->createDataObject($portableElements[$version]);
}
// Version is set, no record found
throw new PortableElementNotFoundException(
$this->getModel()->getId() . ' with identifier ' . $identifier. ' found, '
. 'but version "' . $version . '" does not exist.'
);
} | [
"public",
"function",
"fetch",
"(",
"$",
"identifier",
",",
"$",
"version",
"=",
"null",
")",
"{",
"$",
"portableElements",
"=",
"$",
"this",
"->",
"getAllVersions",
"(",
"$",
"identifier",
")",
";",
"// No version, return latest version",
"if",
"(",
"is_null"... | Fetch a portable element with identifier & version
@param $identifier
@param null $version
@return PortableElementObject
@throws PortableElementNotFoundException | [
"Fetch",
"a",
"portable",
"element",
"with",
"identifier",
"&",
"version"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/storage/PortableElementRegistry.php#L79-L99 |
oat-sa/extension-tao-itemqti | model/portableElement/storage/PortableElementRegistry.php | PortableElementRegistry.getAllVersions | protected function getAllVersions($identifier)
{
$portableElements = $this->get($identifier);
// No portable element found
if ($portableElements == '') {
throw new PortableElementNotFoundException(
$this->getModel()->getId() . ' with identifier "' . $identifier . '" not found.'
);
}
return $portableElements;
} | php | protected function getAllVersions($identifier)
{
$portableElements = $this->get($identifier);
// No portable element found
if ($portableElements == '') {
throw new PortableElementNotFoundException(
$this->getModel()->getId() . ' with identifier "' . $identifier . '" not found.'
);
}
return $portableElements;
} | [
"protected",
"function",
"getAllVersions",
"(",
"$",
"identifier",
")",
"{",
"$",
"portableElements",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"identifier",
")",
";",
"// No portable element found",
"if",
"(",
"$",
"portableElements",
"==",
"''",
")",
"{",
"... | Get all record versions regarding $model->getTypeIdentifier()
@param string $identifier
@return array
@throws PortableElementNotFoundException
@throws PortableElementInconsistencyModelException | [
"Get",
"all",
"record",
"versions",
"regarding",
"$model",
"-",
">",
"getTypeIdentifier",
"()"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/storage/PortableElementRegistry.php#L109-L121 |
oat-sa/extension-tao-itemqti | model/portableElement/storage/PortableElementRegistry.php | PortableElementRegistry.get | private function get($identifier)
{
$fileSystem= $this->getConfigFileSystem();
if($fileSystem->has($identifier)){
return json_decode($fileSystem->read($identifier),true);
}
return false;
} | php | private function get($identifier)
{
$fileSystem= $this->getConfigFileSystem();
if($fileSystem->has($identifier)){
return json_decode($fileSystem->read($identifier),true);
}
return false;
} | [
"private",
"function",
"get",
"(",
"$",
"identifier",
")",
"{",
"$",
"fileSystem",
"=",
"$",
"this",
"->",
"getConfigFileSystem",
"(",
")",
";",
"if",
"(",
"$",
"fileSystem",
"->",
"has",
"(",
"$",
"identifier",
")",
")",
"{",
"return",
"json_decode",
... | Retrieve the given element from list of portable element
@param string $identifier
@return string | [
"Retrieve",
"the",
"given",
"element",
"from",
"list",
"of",
"portable",
"element"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/storage/PortableElementRegistry.php#L128-L137 |
oat-sa/extension-tao-itemqti | model/portableElement/storage/PortableElementRegistry.php | PortableElementRegistry.removeAll | public function removeAll()
{
$portableElements = $this->getAll();
foreach ($portableElements as $identifier => $versions) {
$this->removeAllVersions($identifier);
}
} | php | public function removeAll()
{
$portableElements = $this->getAll();
foreach ($portableElements as $identifier => $versions) {
$this->removeAllVersions($identifier);
}
} | [
"public",
"function",
"removeAll",
"(",
")",
"{",
"$",
"portableElements",
"=",
"$",
"this",
"->",
"getAll",
"(",
")",
";",
"foreach",
"(",
"$",
"portableElements",
"as",
"$",
"identifier",
"=>",
"$",
"versions",
")",
"{",
"$",
"this",
"->",
"removeAllVe... | Unregister all previously registered pci, in all version
Remove all assets | [
"Unregister",
"all",
"previously",
"registered",
"pci",
"in",
"all",
"version",
"Remove",
"all",
"assets"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/storage/PortableElementRegistry.php#L260-L266 |
oat-sa/extension-tao-itemqti | model/portableElement/storage/PortableElementRegistry.php | PortableElementRegistry.unregister | public function unregister(PortableElementObject $object)
{
$object = $this->fetch($object->getTypeIdentifier(), $object->getVersion());
if (! $object->hasVersion()) {
$this->removeAllVersions($object);
} else {
$this->removeAssets($object);
$this->delete($object);
}
} | php | public function unregister(PortableElementObject $object)
{
$object = $this->fetch($object->getTypeIdentifier(), $object->getVersion());
if (! $object->hasVersion()) {
$this->removeAllVersions($object);
} else {
$this->removeAssets($object);
$this->delete($object);
}
} | [
"public",
"function",
"unregister",
"(",
"PortableElementObject",
"$",
"object",
")",
"{",
"$",
"object",
"=",
"$",
"this",
"->",
"fetch",
"(",
"$",
"object",
"->",
"getTypeIdentifier",
"(",
")",
",",
"$",
"object",
"->",
"getVersion",
"(",
")",
")",
";"... | Unregister portable element by removing the given version data & asset files
If $model doesn't have version, all versions will be removed
@param PortableElementObject $object
@throws PortableElementNotFoundException
@throws PortableElementVersionIncompatibilityException
@throws \common_Exception | [
"Unregister",
"portable",
"element",
"by",
"removing",
"the",
"given",
"version",
"data",
"&",
"asset",
"files",
"If",
"$model",
"doesn",
"t",
"have",
"version",
"all",
"versions",
"will",
"be",
"removed"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/storage/PortableElementRegistry.php#L277-L287 |
oat-sa/extension-tao-itemqti | model/portableElement/storage/PortableElementRegistry.php | PortableElementRegistry.getFilesFromPortableElement | protected function getFilesFromPortableElement(PortableElementObject $object)
{
$validator = $object->getModel()->getValidator();
return $validator->getAssets($object);
} | php | protected function getFilesFromPortableElement(PortableElementObject $object)
{
$validator = $object->getModel()->getValidator();
return $validator->getAssets($object);
} | [
"protected",
"function",
"getFilesFromPortableElement",
"(",
"PortableElementObject",
"$",
"object",
")",
"{",
"$",
"validator",
"=",
"$",
"object",
"->",
"getModel",
"(",
")",
"->",
"getValidator",
"(",
")",
";",
"return",
"$",
"validator",
"->",
"getAssets",
... | Get list of files following Pci Model
@param PortableElementObject $object
@return array
@throws \common_Exception | [
"Get",
"list",
"of",
"files",
"following",
"Pci",
"Model"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/storage/PortableElementRegistry.php#L347-L351 |
oat-sa/extension-tao-itemqti | model/portableElement/storage/PortableElementRegistry.php | PortableElementRegistry.getRuntime | protected function getRuntime(PortableElementObject $object)
{
$object = $this->fetch($object->getTypeIdentifier(), $object->getVersion());
$runtime = $object->toArray();
$runtime['model'] = $object->getModelId();
$runtime['xmlns'] = $object->getNamespace();
$runtime['runtime'] = $object->getRuntimeAliases();
$runtime['creator'] = $object->getCreatorAliases();
$runtime['baseUrl'] = $this->getBaseUrl($object);
return $runtime;
} | php | protected function getRuntime(PortableElementObject $object)
{
$object = $this->fetch($object->getTypeIdentifier(), $object->getVersion());
$runtime = $object->toArray();
$runtime['model'] = $object->getModelId();
$runtime['xmlns'] = $object->getNamespace();
$runtime['runtime'] = $object->getRuntimeAliases();
$runtime['creator'] = $object->getCreatorAliases();
$runtime['baseUrl'] = $this->getBaseUrl($object);
return $runtime;
} | [
"protected",
"function",
"getRuntime",
"(",
"PortableElementObject",
"$",
"object",
")",
"{",
"$",
"object",
"=",
"$",
"this",
"->",
"fetch",
"(",
"$",
"object",
"->",
"getTypeIdentifier",
"(",
")",
",",
"$",
"object",
"->",
"getVersion",
"(",
")",
")",
... | Return the runtime of a portable element
@param PortableElementObject $object
@return PortableElementObject
@throws PortableElementNotFoundException | [
"Return",
"the",
"runtime",
"of",
"a",
"portable",
"element"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/storage/PortableElementRegistry.php#L360-L370 |
oat-sa/extension-tao-itemqti | model/portableElement/storage/PortableElementRegistry.php | PortableElementRegistry.getAliasVersion | private function getAliasVersion($versionString){
if(preg_match('/^[0-9]+\.[0-9]+\.\*$/', $versionString)){
//already an alias version string
return $versionString;
}else{
$version = SemVerParser::parse($versionString);
return $version->getMajor().'.'.$version->getMinor().'.*';
}
} | php | private function getAliasVersion($versionString){
if(preg_match('/^[0-9]+\.[0-9]+\.\*$/', $versionString)){
//already an alias version string
return $versionString;
}else{
$version = SemVerParser::parse($versionString);
return $version->getMajor().'.'.$version->getMinor().'.*';
}
} | [
"private",
"function",
"getAliasVersion",
"(",
"$",
"versionString",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/^[0-9]+\\.[0-9]+\\.\\*$/'",
",",
"$",
"versionString",
")",
")",
"{",
"//already an alias version string",
"return",
"$",
"versionString",
";",
"}",
"else... | Get the alias version for a given version number, e.g. 2.1.5 becomes 2.1.*
@param $versionString
@return mixed | [
"Get",
"the",
"alias",
"version",
"for",
"a",
"given",
"version",
"number",
"e",
".",
"g",
".",
"2",
".",
"1",
".",
"5",
"becomes",
"2",
".",
"1",
".",
"*"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/storage/PortableElementRegistry.php#L377-L385 |
oat-sa/extension-tao-itemqti | model/portableElement/storage/PortableElementRegistry.php | PortableElementRegistry.removeAssets | protected function removeAssets(PortableElementObject $object)
{
if (! $object->hasVersion()) {
throw new PortableElementVersionIncompatibilityException('Unable to delete asset files whitout model version.');
}
$object = $this->fetch($object->getTypeIdentifier(), $object->getVersion());
$files[] = array_merge($object->getRuntime(), $object->getCreator());
$filesToRemove = [];
foreach ($files as $key => $file) {
if (is_array($file)) {
array_merge($filesToRemove, $file);
} else {
$filesToRemove[] = $file;
}
}
if (empty($filesToRemove)) {
return true;
}
if (! $this->getFileSystem()->unregisterFiles($object, $filesToRemove)) {
throw new PortableElementFileStorageException(
'Unable to delete asset files for PCI "' . $object->getTypeIdentifier()
. '" at version "' . $object->getVersion() . '"'
);
}
return true;
} | php | protected function removeAssets(PortableElementObject $object)
{
if (! $object->hasVersion()) {
throw new PortableElementVersionIncompatibilityException('Unable to delete asset files whitout model version.');
}
$object = $this->fetch($object->getTypeIdentifier(), $object->getVersion());
$files[] = array_merge($object->getRuntime(), $object->getCreator());
$filesToRemove = [];
foreach ($files as $key => $file) {
if (is_array($file)) {
array_merge($filesToRemove, $file);
} else {
$filesToRemove[] = $file;
}
}
if (empty($filesToRemove)) {
return true;
}
if (! $this->getFileSystem()->unregisterFiles($object, $filesToRemove)) {
throw new PortableElementFileStorageException(
'Unable to delete asset files for PCI "' . $object->getTypeIdentifier()
. '" at version "' . $object->getVersion() . '"'
);
}
return true;
} | [
"protected",
"function",
"removeAssets",
"(",
"PortableElementObject",
"$",
"object",
")",
"{",
"if",
"(",
"!",
"$",
"object",
"->",
"hasVersion",
"(",
")",
")",
"{",
"throw",
"new",
"PortableElementVersionIncompatibilityException",
"(",
"'Unable to delete asset files... | Remove all registered files for a PCI identifier from FileSystem
If $targetedVersion is given, remove only assets for this version
@param PortableElementObject $object
@return bool
@throws \common_Exception | [
"Remove",
"all",
"registered",
"files",
"for",
"a",
"PCI",
"identifier",
"from",
"FileSystem",
"If",
"$targetedVersion",
"is",
"given",
"remove",
"only",
"assets",
"for",
"this",
"version"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/storage/PortableElementRegistry.php#L445-L474 |
oat-sa/extension-tao-itemqti | model/portableElement/storage/PortableElementRegistry.php | PortableElementRegistry.export | public function export(PortableElementObject $object)
{
$zip = new \ZipArchive();
$path = $this->getZipLocation($object);
if ($zip->open($path, \ZipArchive::CREATE) !== TRUE) {
throw new \common_Exception('Unable to create zipfile ' . $path);
}
$manifest = $this->getManifest($object);
$zip->addFromString($this->getModel()->getManifestName(), $manifest);
$files = $this->getFilesFromPortableElement($object);
$filesystem = $this->getFileSystem();
foreach ($files as $file) {
if(strpos($file, './') === 0){
//only export the files that are in the portable element package (exclude the shared libraries)
$zip->addFromString($file, $filesystem->getFileContentFromModelStorage($object, $file));
}
}
$zip->close();
return $path;
} | php | public function export(PortableElementObject $object)
{
$zip = new \ZipArchive();
$path = $this->getZipLocation($object);
if ($zip->open($path, \ZipArchive::CREATE) !== TRUE) {
throw new \common_Exception('Unable to create zipfile ' . $path);
}
$manifest = $this->getManifest($object);
$zip->addFromString($this->getModel()->getManifestName(), $manifest);
$files = $this->getFilesFromPortableElement($object);
$filesystem = $this->getFileSystem();
foreach ($files as $file) {
if(strpos($file, './') === 0){
//only export the files that are in the portable element package (exclude the shared libraries)
$zip->addFromString($file, $filesystem->getFileContentFromModelStorage($object, $file));
}
}
$zip->close();
return $path;
} | [
"public",
"function",
"export",
"(",
"PortableElementObject",
"$",
"object",
")",
"{",
"$",
"zip",
"=",
"new",
"\\",
"ZipArchive",
"(",
")",
";",
"$",
"path",
"=",
"$",
"this",
"->",
"getZipLocation",
"(",
"$",
"object",
")",
";",
"if",
"(",
"$",
"zi... | Export a portable element to a zip package
@param PortableElementObject $object
@return string
@throws \common_Exception | [
"Export",
"a",
"portable",
"element",
"to",
"a",
"zip",
"package"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/storage/PortableElementRegistry.php#L505-L529 |
oat-sa/extension-tao-itemqti | model/portableElement/storage/PortableElementRegistry.php | PortableElementRegistry.getFileSystem | public function getFileSystem()
{
if (! $this->storage) {
$this->storage = $this->getServiceLocator()->get(PortableElementFileStorage::SERVICE_ID);
$this->storage->setServiceLocator($this->getServiceLocator());
$this->storage->setModel($this->getModel());
}
return $this->storage;
} | php | public function getFileSystem()
{
if (! $this->storage) {
$this->storage = $this->getServiceLocator()->get(PortableElementFileStorage::SERVICE_ID);
$this->storage->setServiceLocator($this->getServiceLocator());
$this->storage->setModel($this->getModel());
}
return $this->storage;
} | [
"public",
"function",
"getFileSystem",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"storage",
")",
"{",
"$",
"this",
"->",
"storage",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"PortableElementFileStorage",
"::",
"SERV... | Get the fly filesystem based on OPTION_FS configuration
@return PortableElementFileStorage | [
"Get",
"the",
"fly",
"filesystem",
"based",
"on",
"OPTION_FS",
"configuration"
] | train | https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/storage/PortableElementRegistry.php#L536-L544 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.