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/portableElement/storage/PortableElementRegistry.php
PortableElementRegistry.getBaseUrl
public function getBaseUrl(PortableElementObject $object) { $object = $this->fetch($object->getTypeIdentifier(), $object->getVersion()); return $this->getFileSystem()->getFileUrl($object); }
php
public function getBaseUrl(PortableElementObject $object) { $object = $this->fetch($object->getTypeIdentifier(), $object->getVersion()); return $this->getFileSystem()->getFileUrl($object); }
[ "public", "function", "getBaseUrl", "(", "PortableElementObject", "$", "object", ")", "{", "$", "object", "=", "$", "this", "->", "fetch", "(", "$", "object", "->", "getTypeIdentifier", "(", ")", ",", "$", "object", "->", "getVersion", "(", ")", ")", ";"...
Return the absolute url of PCI storage @param PortableElementObject $object @return string @throws PortableElementNotFoundException
[ "Return", "the", "absolute", "url", "of", "PCI", "storage" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/storage/PortableElementRegistry.php#L553-L557
oat-sa/extension-tao-itemqti
model/Export/Extractor/MetaDataOntologyExtractor.php
MetaDataOntologyExtractor.setMetaDataProperties
protected function setMetaDataProperties(array $config) { if (empty($this->metaDataProperties)) { $itemTypes = $this->item->getTypes(); $classType = reset($itemTypes); if (!$classType->isClass()) { throw new ExtractorException('Item class type do not exists'); } $this->metaDataProperties = $this->getAvailableMetaDataProperties($classType, $config['excludedProperties']); } }
php
protected function setMetaDataProperties(array $config) { if (empty($this->metaDataProperties)) { $itemTypes = $this->item->getTypes(); $classType = reset($itemTypes); if (!$classType->isClass()) { throw new ExtractorException('Item class type do not exists'); } $this->metaDataProperties = $this->getAvailableMetaDataProperties($classType, $config['excludedProperties']); } }
[ "protected", "function", "setMetaDataProperties", "(", "array", "$", "config", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "metaDataProperties", ")", ")", "{", "$", "itemTypes", "=", "$", "this", "->", "item", "->", "getTypes", "(", ")", ";", ...
Setting the meta data properties available for export. @param array $config @throws ExtractorException
[ "Setting", "the", "meta", "data", "properties", "available", "for", "export", "." ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/Export/Extractor/MetaDataOntologyExtractor.php#L145-L157
oat-sa/extension-tao-itemqti
model/Export/Extractor/MetaDataOntologyExtractor.php
MetaDataOntologyExtractor.getAvailableMetaDataProperties
protected function getAvailableMetaDataProperties($classToExport, array $excludedProperties) { $props = tao_helpers_form_GenerisFormFactory::getClassProperties($classToExport); return array_filter($props, function ($prop) use ($excludedProperties) { /**@var $prop core_kernel_classes_Resource */ return !in_array($prop->getUri(), $excludedProperties); }); }
php
protected function getAvailableMetaDataProperties($classToExport, array $excludedProperties) { $props = tao_helpers_form_GenerisFormFactory::getClassProperties($classToExport); return array_filter($props, function ($prop) use ($excludedProperties) { /**@var $prop core_kernel_classes_Resource */ return !in_array($prop->getUri(), $excludedProperties); }); }
[ "protected", "function", "getAvailableMetaDataProperties", "(", "$", "classToExport", ",", "array", "$", "excludedProperties", ")", "{", "$", "props", "=", "tao_helpers_form_GenerisFormFactory", "::", "getClassProperties", "(", "$", "classToExport", ")", ";", "return", ...
@param core_kernel_classes_Class $classToExport @param array $excludedProperties @return array
[ "@param", "core_kernel_classes_Class", "$classToExport" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/Export/Extractor/MetaDataOntologyExtractor.php#L165-L173
oat-sa/extension-tao-itemqti
model/qti/metadata/importer/MetadataImporter.php
MetadataImporter.inject
public function inject($identifier, $resource) { if (! $resource instanceof \core_kernel_classes_Resource) { throw new MetadataImportException(__('Metadata import requires an instance of core_kernel_classes_Resource to inject metadata')); } parent::inject($identifier, $resource); }
php
public function inject($identifier, $resource) { if (! $resource instanceof \core_kernel_classes_Resource) { throw new MetadataImportException(__('Metadata import requires an instance of core_kernel_classes_Resource to inject metadata')); } parent::inject($identifier, $resource); }
[ "public", "function", "inject", "(", "$", "identifier", ",", "$", "resource", ")", "{", "if", "(", "!", "$", "resource", "instanceof", "\\", "core_kernel_classes_Resource", ")", "{", "throw", "new", "MetadataImportException", "(", "__", "(", "'Metadata import re...
Inject an identified metadata value to a resource {@inheritdoc}
[ "Inject", "an", "identified", "metadata", "value", "to", "a", "resource" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/importer/MetadataImporter.php#L67-L73
oat-sa/extension-tao-itemqti
model/qti/metadata/importer/MetadataImporter.php
MetadataImporter.guard
public function guard($identifier, $context = '') { foreach ($this->getGuardians() as $guardian) { if ($guardian instanceof ContextualMetadataGuardian && $guardian->getContext() !== $context) { continue; } if ($this->hasMetadataValue($identifier)) { \common_Logger::i(__('Guard for resource "%s"...', $identifier)); if (($guard = $guardian->guard($this->getMetadataValue($identifier))) !== false) { return $guard; } } } return false; }
php
public function guard($identifier, $context = '') { foreach ($this->getGuardians() as $guardian) { if ($guardian instanceof ContextualMetadataGuardian && $guardian->getContext() !== $context) { continue; } if ($this->hasMetadataValue($identifier)) { \common_Logger::i(__('Guard for resource "%s"...', $identifier)); if (($guard = $guardian->guard($this->getMetadataValue($identifier))) !== false) { return $guard; } } } return false; }
[ "public", "function", "guard", "(", "$", "identifier", ",", "$", "context", "=", "''", ")", "{", "foreach", "(", "$", "this", "->", "getGuardians", "(", ")", "as", "$", "guardian", ")", "{", "if", "(", "$", "guardian", "instanceof", "ContextualMetadataGu...
Guard a metadata identifier at import Guard a metadata identifier by calling guard method of each guardians If guardians have no reason to stop process, true is returned If a guardian does not allow the import, the target guardian is returned @param $identifier @return bool
[ "Guard", "a", "metadata", "identifier", "at", "import" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/importer/MetadataImporter.php#L85-L101
oat-sa/extension-tao-itemqti
model/qti/metadata/importer/MetadataImporter.php
MetadataImporter.classLookUp
public function classLookUp($identifier, &$createdClasses) { $targetClass = false; foreach ($this->getClassLookUp() as $classLookup) { if ($this->hasMetadataValue($identifier)) { \common_Logger::i(__('Target Class Lookup for resource "%s"...', $identifier)); if (($targetClass = $classLookup->lookup($this->getMetadataValue($identifier))) !== false) { \common_Logger::i(__('Class Lookup Successful. Resource "%s" will be stored in RDFS Class "%s".', $identifier, $targetClass->getUri())); if ($classLookup instanceof MetadataClassLookupClassCreator) { $createdClasses = $classLookup->createdClasses(); } break; } } } return $targetClass; }
php
public function classLookUp($identifier, &$createdClasses) { $targetClass = false; foreach ($this->getClassLookUp() as $classLookup) { if ($this->hasMetadataValue($identifier)) { \common_Logger::i(__('Target Class Lookup for resource "%s"...', $identifier)); if (($targetClass = $classLookup->lookup($this->getMetadataValue($identifier))) !== false) { \common_Logger::i(__('Class Lookup Successful. Resource "%s" will be stored in RDFS Class "%s".', $identifier, $targetClass->getUri())); if ($classLookup instanceof MetadataClassLookupClassCreator) { $createdClasses = $classLookup->createdClasses(); } break; } } } return $targetClass; }
[ "public", "function", "classLookUp", "(", "$", "identifier", ",", "&", "$", "createdClasses", ")", "{", "$", "targetClass", "=", "false", ";", "foreach", "(", "$", "this", "->", "getClassLookUp", "(", ")", "as", "$", "classLookup", ")", "{", "if", "(", ...
Lookup classes for a metadata identifier at import Lookup classes for a metadata identifier by calling lookup method of each classLookup If no lookup has been triggered, false is returned If a lookup has been triggered, classLookup could apply his own process Specific should be applied here, like get created classes CreatedClasses params could be updated @param $identifier @param $createdClasses @return bool
[ "Lookup", "classes", "for", "a", "metadata", "identifier", "at", "import" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/importer/MetadataImporter.php#L116-L135
oat-sa/extension-tao-itemqti
model/qti/metadata/importer/MetadataImporter.php
MetadataImporter.register
public function register($key, $name) { if (empty($key) || empty($name)) { throw new \InvalidArgumentException(__('Register method expects $key and $name parameters.')); } if (is_object($name)) { $name = get_class($name); } switch ($key) { case self::GUARDIAN_KEY: $this->registerInstance(self::GUARDIAN_KEY, $name, MetadataGuardian::class); return true; break; case self::CLASS_LOOKUP_KEY: $this->registerInstance(self::CLASS_LOOKUP_KEY, $name, MetadataClassLookup::class); return true; break; case self::VALIDATOR_KEY: $this->registerInstance(self::VALIDATOR_KEY, $name, MetadataValidator::class); return true; break; } return parent::register($key, $name); }
php
public function register($key, $name) { if (empty($key) || empty($name)) { throw new \InvalidArgumentException(__('Register method expects $key and $name parameters.')); } if (is_object($name)) { $name = get_class($name); } switch ($key) { case self::GUARDIAN_KEY: $this->registerInstance(self::GUARDIAN_KEY, $name, MetadataGuardian::class); return true; break; case self::CLASS_LOOKUP_KEY: $this->registerInstance(self::CLASS_LOOKUP_KEY, $name, MetadataClassLookup::class); return true; break; case self::VALIDATOR_KEY: $this->registerInstance(self::VALIDATOR_KEY, $name, MetadataValidator::class); return true; break; } return parent::register($key, $name); }
[ "public", "function", "register", "(", "$", "key", ",", "$", "name", ")", "{", "if", "(", "empty", "(", "$", "key", ")", "||", "empty", "(", "$", "name", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "__", "(", "'Register meth...
Register an importer instance Register an instance e.q. Injectors, Extractors, Guardians or LooUpClass Respective interface is checked Throw exception if call if not correctly formed @param $key @param $name @return bool @throws \InvalidArgumentException
[ "Register", "an", "importer", "instance" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/importer/MetadataImporter.php#L167-L192
oat-sa/extension-tao-itemqti
model/qti/metadata/importer/MetadataImporter.php
MetadataImporter.unregister
public function unregister($key, $name) { if (empty($key) || empty($name)) { throw new \common_Exception(__('Unregister method expects $key and $name parameters.')); } if (is_object($name)) { $name = get_class($name); } switch ($key) { case self::GUARDIAN_KEY: $this->unregisterInstance(self::GUARDIAN_KEY, $name); return true; break; case self::CLASS_LOOKUP_KEY: $this->unregisterInstance(self::CLASS_LOOKUP_KEY, $name); return true; break; } return parent::unregister($key, $name); }
php
public function unregister($key, $name) { if (empty($key) || empty($name)) { throw new \common_Exception(__('Unregister method expects $key and $name parameters.')); } if (is_object($name)) { $name = get_class($name); } switch ($key) { case self::GUARDIAN_KEY: $this->unregisterInstance(self::GUARDIAN_KEY, $name); return true; break; case self::CLASS_LOOKUP_KEY: $this->unregisterInstance(self::CLASS_LOOKUP_KEY, $name); return true; break; } return parent::unregister($key, $name); }
[ "public", "function", "unregister", "(", "$", "key", ",", "$", "name", ")", "{", "if", "(", "empty", "(", "$", "key", ")", "||", "empty", "(", "$", "name", ")", ")", "{", "throw", "new", "\\", "common_Exception", "(", "__", "(", "'Unregister method e...
Unregister an instances Look for GUARDIAN OR CLASS_LOOKUP key, otherwise fallback to parent @param string $key @param string $name @return bool @throws \common_Exception
[ "Unregister", "an", "instances" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/importer/MetadataImporter.php#L204-L225
oat-sa/extension-tao-itemqti
model/qti/metadata/importer/MetadataImporter.php
MetadataImporter.registerMetadataService
protected function registerMetadataService() { if ($this->getServiceLocator()->has(MetadataService::SERVICE_ID)) { $metadataService = $this->getServiceLocator()->get(MetadataService::SERVICE_ID); } else { $metadataService = $this->getServiceManager()->build(MetadataService::class); } $metadataService->setOption(MetadataService::IMPORTER_KEY, $this); $this->getServiceManager()->register(MetadataService::SERVICE_ID, $metadataService); }
php
protected function registerMetadataService() { if ($this->getServiceLocator()->has(MetadataService::SERVICE_ID)) { $metadataService = $this->getServiceLocator()->get(MetadataService::SERVICE_ID); } else { $metadataService = $this->getServiceManager()->build(MetadataService::class); } $metadataService->setOption(MetadataService::IMPORTER_KEY, $this); $this->getServiceManager()->register(MetadataService::SERVICE_ID, $metadataService); }
[ "protected", "function", "registerMetadataService", "(", ")", "{", "if", "(", "$", "this", "->", "getServiceLocator", "(", ")", "->", "has", "(", "MetadataService", "::", "SERVICE_ID", ")", ")", "{", "$", "metadataService", "=", "$", "this", "->", "getServic...
Allow to register, into the config, the current importer service
[ "Allow", "to", "register", "into", "the", "config", "the", "current", "importer", "service" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/importer/MetadataImporter.php#L230-L239
oat-sa/extension-tao-itemqti
model/qti/container/ContainerTable.php
ContainerTable.getValidElementTypes
public function getValidElementTypes(){ return array( 'oat\\taoQtiItem\\model\\qti\\Img', 'oat\\taoQtiItem\\model\\qti\\Math', 'oat\\taoQtiItem\\model\\qti\\feedback\\Feedback', \oat\taoQtiItem\model\qti\QtiObject::class, 'oat\\taoQtiItem\\model\\qti\\Tooltip', 'oat\\taoQtiItem\\model\\qti\\interaction\\Interaction', 'oat\\taoQtiItem\\model\\qti\\RubricBlock', 'oat\\taoQtiItem\\model\\qti\\InfoControl', 'oat\\taoQtiItem\\model\\qti\\XInclude', \oat\taoQtiItem\model\qti\Table::class, ); }
php
public function getValidElementTypes(){ return array( 'oat\\taoQtiItem\\model\\qti\\Img', 'oat\\taoQtiItem\\model\\qti\\Math', 'oat\\taoQtiItem\\model\\qti\\feedback\\Feedback', \oat\taoQtiItem\model\qti\QtiObject::class, 'oat\\taoQtiItem\\model\\qti\\Tooltip', 'oat\\taoQtiItem\\model\\qti\\interaction\\Interaction', 'oat\\taoQtiItem\\model\\qti\\RubricBlock', 'oat\\taoQtiItem\\model\\qti\\InfoControl', 'oat\\taoQtiItem\\model\\qti\\XInclude', \oat\taoQtiItem\model\qti\Table::class, ); }
[ "public", "function", "getValidElementTypes", "(", ")", "{", "return", "array", "(", "'oat\\\\taoQtiItem\\\\model\\\\qti\\\\Img'", ",", "'oat\\\\taoQtiItem\\\\model\\\\qti\\\\Math'", ",", "'oat\\\\taoQtiItem\\\\model\\\\qti\\\\feedback\\\\Feedback'", ",", "\\", "oat", "\\", "taoQ...
return the list of available element classes @access public @return array
[ "return", "the", "list", "of", "available", "element", "classes" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/container/ContainerTable.php#L40-L53
oat-sa/extension-tao-itemqti
controller/QtiPreview.php
QtiPreview.processResponses
protected function processResponses(core_kernel_classes_Resource $item){ $jsonPayload = taoQtiCommon_helpers_Utils::readJsonPayload(); try { $qtiXmlFileContent = QtiFile::getQtiFileContent($item); $qtiXmlDoc = new XmlDocument(); $qtiXmlDoc->loadFromString($qtiXmlFileContent); } catch(StorageException $e) { $msg = "An error occurred while loading QTI-XML file at expected location '${qtiXmlFilePath}'."; common_Logger::e(($e->getPrevious() !== null) ? $e->getPrevious()->getMessage() : $e->getMessage()); throw new \RuntimeException($msg, 0, $e); } $itemSession = new AssessmentItemSession($qtiXmlDoc->getDocumentComponent(), new SessionManager()); $itemSession->beginItemSession(); $variables = array(); $filler = new taoQtiCommon_helpers_PciVariableFiller($qtiXmlDoc->getDocumentComponent()); // Convert client-side data as QtiSm Runtime Variables. foreach ($jsonPayload as $id => $response) { try { $var = $filler->fill($id, $response); // Do not take into account QTI Files at preview time. // Simply delete the created file. if (taoQtiCommon_helpers_Utils::isQtiFile($var, false) === true) { $fileManager = new FileSystemFileManager(); $fileManager->delete($var->getValue()); } else { $variables[] = $var; } } catch (OutOfRangeException $e) { // A variable value could not be converted, ignore it. // Developer's note: QTI Pairs with a single identifier (missing second identifier of the pair) are transmitted as an array of length 1, // this might cause problem. Such "broken" pairs are simply ignored. common_Logger::d("Client-side value for variable '${id}' is ignored due to data malformation."); } catch (OutOfBoundsException $e) { // No such identifier found in item. common_Logger::d("The variable with identifier '${id}' is not declared in the item definition."); } } try { $itemSession->beginAttempt(); $itemSession->endAttempt(new State($variables)); // Return the item session state to the client-side. echo json_encode(array('success' => true, 'displayFeedback' => true, 'itemSession' => self::buildOutcomeResponse($itemSession))); } catch(AssessmentItemSessionException $e) { $msg = "An error occurred while processing the responses."; throw new \RuntimeException($msg, 0, $e); } catch(taoQtiCommon_helpers_ResultTransmissionException $e) { $msg = "An error occurred while transmitting a result to the target Result Server."; throw new \RuntimeException($msg, 0, $e); } }
php
protected function processResponses(core_kernel_classes_Resource $item){ $jsonPayload = taoQtiCommon_helpers_Utils::readJsonPayload(); try { $qtiXmlFileContent = QtiFile::getQtiFileContent($item); $qtiXmlDoc = new XmlDocument(); $qtiXmlDoc->loadFromString($qtiXmlFileContent); } catch(StorageException $e) { $msg = "An error occurred while loading QTI-XML file at expected location '${qtiXmlFilePath}'."; common_Logger::e(($e->getPrevious() !== null) ? $e->getPrevious()->getMessage() : $e->getMessage()); throw new \RuntimeException($msg, 0, $e); } $itemSession = new AssessmentItemSession($qtiXmlDoc->getDocumentComponent(), new SessionManager()); $itemSession->beginItemSession(); $variables = array(); $filler = new taoQtiCommon_helpers_PciVariableFiller($qtiXmlDoc->getDocumentComponent()); // Convert client-side data as QtiSm Runtime Variables. foreach ($jsonPayload as $id => $response) { try { $var = $filler->fill($id, $response); // Do not take into account QTI Files at preview time. // Simply delete the created file. if (taoQtiCommon_helpers_Utils::isQtiFile($var, false) === true) { $fileManager = new FileSystemFileManager(); $fileManager->delete($var->getValue()); } else { $variables[] = $var; } } catch (OutOfRangeException $e) { // A variable value could not be converted, ignore it. // Developer's note: QTI Pairs with a single identifier (missing second identifier of the pair) are transmitted as an array of length 1, // this might cause problem. Such "broken" pairs are simply ignored. common_Logger::d("Client-side value for variable '${id}' is ignored due to data malformation."); } catch (OutOfBoundsException $e) { // No such identifier found in item. common_Logger::d("The variable with identifier '${id}' is not declared in the item definition."); } } try { $itemSession->beginAttempt(); $itemSession->endAttempt(new State($variables)); // Return the item session state to the client-side. echo json_encode(array('success' => true, 'displayFeedback' => true, 'itemSession' => self::buildOutcomeResponse($itemSession))); } catch(AssessmentItemSessionException $e) { $msg = "An error occurred while processing the responses."; throw new \RuntimeException($msg, 0, $e); } catch(taoQtiCommon_helpers_ResultTransmissionException $e) { $msg = "An error occurred while transmitting a result to the target Result Server."; throw new \RuntimeException($msg, 0, $e); } }
[ "protected", "function", "processResponses", "(", "core_kernel_classes_Resource", "$", "item", ")", "{", "$", "jsonPayload", "=", "taoQtiCommon_helpers_Utils", "::", "readJsonPayload", "(", ")", ";", "try", "{", "$", "qtiXmlFileContent", "=", "QtiFile", "::", "getQt...
Item's ResponseProcessing. @param core_kernel_classes_Resource $item The Item you want to apply ResponseProcessing. @throws \RuntimeException If an error occurs while processing responses or transmitting results
[ "Item", "s", "ResponseProcessing", "." ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/controller/QtiPreview.php#L84-L147
oat-sa/extension-tao-itemqti
controller/QtiPreview.php
QtiPreview.getRenderedItem
protected function getRenderedItem($item) { //@todo make getRenderedItem language dependent $lang = \common_session_SessionManager::getSession()->getDataLanguage(); $qtiItem = Service::singleton()->getDataItemByRdfItem($item, $lang, true); if ($qtiItem) { $contentVariableElements = array_merge($this->getModalFeedbacks($qtiItem), $this->getRubricBlocks($qtiItem)); /** @var AssetService $assetService */ $assetService = ServiceManager::getServiceManager()->get(AssetService::SERVICE_ID); $taoBaseUrl = $assetService->getJsBaseWww( 'tao' ); $qtiBaseUrl = $assetService->getJsBaseWww( 'taoQtiItem' ); $taoLibUrl = $taoBaseUrl.'js/'; $taoQtiItemLibUrl = $qtiBaseUrl.'js/'; $xhtml = $qtiItem->toXHTML(array( 'contentVariableElements' => $contentVariableElements, // 'js' => array($qtiBaseUrl.'js/preview/qtiViewSelector.js'), 'js_var' => array('view' => $this->getRequestView()), // 'css' => array($qtiBaseUrl.'css/preview/qtiViewSelector.css'), 'path' => array( 'tao' => $taoLibUrl, 'taoQtiItem' => $taoQtiItemLibUrl ), 'client_config_url' => $this->getClientConfigUrl() )); } else { \common_Logger::i('Try to preview an empty item', [$item->getUri()]); $xhtml = ''; } return $xhtml; }
php
protected function getRenderedItem($item) { //@todo make getRenderedItem language dependent $lang = \common_session_SessionManager::getSession()->getDataLanguage(); $qtiItem = Service::singleton()->getDataItemByRdfItem($item, $lang, true); if ($qtiItem) { $contentVariableElements = array_merge($this->getModalFeedbacks($qtiItem), $this->getRubricBlocks($qtiItem)); /** @var AssetService $assetService */ $assetService = ServiceManager::getServiceManager()->get(AssetService::SERVICE_ID); $taoBaseUrl = $assetService->getJsBaseWww( 'tao' ); $qtiBaseUrl = $assetService->getJsBaseWww( 'taoQtiItem' ); $taoLibUrl = $taoBaseUrl.'js/'; $taoQtiItemLibUrl = $qtiBaseUrl.'js/'; $xhtml = $qtiItem->toXHTML(array( 'contentVariableElements' => $contentVariableElements, // 'js' => array($qtiBaseUrl.'js/preview/qtiViewSelector.js'), 'js_var' => array('view' => $this->getRequestView()), // 'css' => array($qtiBaseUrl.'css/preview/qtiViewSelector.css'), 'path' => array( 'tao' => $taoLibUrl, 'taoQtiItem' => $taoQtiItemLibUrl ), 'client_config_url' => $this->getClientConfigUrl() )); } else { \common_Logger::i('Try to preview an empty item', [$item->getUri()]); $xhtml = ''; } return $xhtml; }
[ "protected", "function", "getRenderedItem", "(", "$", "item", ")", "{", "//@todo make getRenderedItem language dependent", "$", "lang", "=", "\\", "common_session_SessionManager", "::", "getSession", "(", ")", "->", "getDataLanguage", "(", ")", ";", "$", "qtiItem", ...
(non-PHPdoc) @see taoItems_actions_ItemPreview::getRenderedItem()
[ "(", "non", "-", "PHPdoc", ")" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/controller/QtiPreview.php#L179-L214
oat-sa/extension-tao-itemqti
model/qti/ManifestParser.php
ManifestParser.load
public function load() { $returnValue = array(); //load it using the SimpleXml library $xml = false; switch($this->sourceType){ case self::SOURCE_FILE: $xml = simplexml_load_file($this->source); break; case self::SOURCE_URL: $xmlContent = tao_helpers_Request::load($this->source, true); $xml = simplexml_load_string($xmlContent); break; case self::SOURCE_STRING: $xml = simplexml_load_string($this->source); break; } if ($xml !== false) { //get the QTI Item's resources from the imsmanifest.xml $returnValue = ManifestParserFactory::getResourcesFromManifest($xml); if (!$this->valid) { $this->valid = true; libxml_clear_errors(); } } else if (!$this->valid) { $this->addErrors(libxml_get_errors()); libxml_clear_errors(); } return (array) $returnValue; }
php
public function load() { $returnValue = array(); //load it using the SimpleXml library $xml = false; switch($this->sourceType){ case self::SOURCE_FILE: $xml = simplexml_load_file($this->source); break; case self::SOURCE_URL: $xmlContent = tao_helpers_Request::load($this->source, true); $xml = simplexml_load_string($xmlContent); break; case self::SOURCE_STRING: $xml = simplexml_load_string($this->source); break; } if ($xml !== false) { //get the QTI Item's resources from the imsmanifest.xml $returnValue = ManifestParserFactory::getResourcesFromManifest($xml); if (!$this->valid) { $this->valid = true; libxml_clear_errors(); } } else if (!$this->valid) { $this->addErrors(libxml_get_errors()); libxml_clear_errors(); } return (array) $returnValue; }
[ "public", "function", "load", "(", ")", "{", "$", "returnValue", "=", "array", "(", ")", ";", "//load it using the SimpleXml library", "$", "xml", "=", "false", ";", "switch", "(", "$", "this", "->", "sourceType", ")", "{", "case", "self", "::", "SOURCE_FI...
Extract the resources informations about the items and build a list a QTI_Resource @access public @return array
[ "Extract", "the", "resources", "informations", "about", "the", "items", "and", "build", "a", "list", "a", "QTI_Resource" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/ManifestParser.php#L104-L142
oat-sa/extension-tao-itemqti
model/qti/attribute/Attribute.php
Attribute.getValue
public function getValue($returnObject = false){ $returnValue = null; if(!is_null($this->value)){ $returnValue = ($returnObject) ? $this->value : $this->value->getValue(); //return mixed } return $returnValue; }
php
public function getValue($returnObject = false){ $returnValue = null; if(!is_null($this->value)){ $returnValue = ($returnObject) ? $this->value : $this->value->getValue(); //return mixed } return $returnValue; }
[ "public", "function", "getValue", "(", "$", "returnObject", "=", "false", ")", "{", "$", "returnValue", "=", "null", ";", "if", "(", "!", "is_null", "(", "$", "this", "->", "value", ")", ")", "{", "$", "returnValue", "=", "(", "$", "returnObject", ")...
Return the value of the attribute in base type int, string, null @return mixed
[ "Return", "the", "value", "of", "the", "attribute", "in", "base", "type", "int", "string", "null" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/attribute/Attribute.php#L192-L201
oat-sa/extension-tao-itemqti
model/qti/attribute/Attribute.php
Attribute.setValue
public function setValue($value){ $returnValue = false; if(!is_null($value)){ try{ $value = new static::$type($value); if(!is_null($value)){ $this->value = $value; $returnValue = true; } }catch(DatatypeException $de){ $type = '('.gettype($value).')'; if($type == 'object'){ $type .= '('.get_class($value).')'; } throw new AttributeException('Cannot assign the value to attribute: '.static::$name.' -> '.$type.' '.$value); } } return $returnValue; }
php
public function setValue($value){ $returnValue = false; if(!is_null($value)){ try{ $value = new static::$type($value); if(!is_null($value)){ $this->value = $value; $returnValue = true; } }catch(DatatypeException $de){ $type = '('.gettype($value).')'; if($type == 'object'){ $type .= '('.get_class($value).')'; } throw new AttributeException('Cannot assign the value to attribute: '.static::$name.' -> '.$type.' '.$value); } } return $returnValue; }
[ "public", "function", "setValue", "(", "$", "value", ")", "{", "$", "returnValue", "=", "false", ";", "if", "(", "!", "is_null", "(", "$", "value", ")", ")", "{", "try", "{", "$", "value", "=", "new", "static", "::", "$", "type", "(", "$", "value...
Set the attribute value @param mixed $value @return boolean @throws \oat\taoQtiItem\model\qti\attribute\AttributeException
[ "Set", "the", "attribute", "value" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/attribute/Attribute.php#L210-L231
oat-sa/extension-tao-itemqti
model/qti/asset/handler/SharedStimulusAssetHandler.php
SharedStimulusAssetHandler.isApplicable
public function isApplicable($relativePath) { $xincluded = array(); /** @var Element $xincludeElement */ foreach ($this->getQtiModel()->getComposingElements('oat\taoQtiItem\model\qti\Xinclude') as $xincludeElement) { $xincluded[] = $xincludeElement->attr('href'); \common_Logger::i("Xinclude component found in resource '" . $this->getQtiModel()->getIdentifier() . "' with href '" . $xincludeElement->attr('href') . "'."); } return (!empty($this->sharedStorage) && in_array($relativePath, $xincluded)); }
php
public function isApplicable($relativePath) { $xincluded = array(); /** @var Element $xincludeElement */ foreach ($this->getQtiModel()->getComposingElements('oat\taoQtiItem\model\qti\Xinclude') as $xincludeElement) { $xincluded[] = $xincludeElement->attr('href'); \common_Logger::i("Xinclude component found in resource '" . $this->getQtiModel()->getIdentifier() . "' with href '" . $xincludeElement->attr('href') . "'."); } return (!empty($this->sharedStorage) && in_array($relativePath, $xincluded)); }
[ "public", "function", "isApplicable", "(", "$", "relativePath", ")", "{", "$", "xincluded", "=", "array", "(", ")", ";", "/** @var Element $xincludeElement */", "foreach", "(", "$", "this", "->", "getQtiModel", "(", ")", "->", "getComposingElements", "(", "'oat\...
Check if current file.xml is shared stimulus @param $relativePath @return bool @throws FileUploadException
[ "Check", "if", "current", "file", ".", "xml", "is", "shared", "stimulus" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/asset/handler/SharedStimulusAssetHandler.php#L63-L74
oat-sa/extension-tao-itemqti
model/qti/asset/handler/SharedStimulusAssetHandler.php
SharedStimulusAssetHandler.handle
public function handle($absolutePath, $relativePath) { $sharedFiles = $this->getSharedFiles(); $md5 = md5_file($absolutePath); if (isset($sharedFiles[$md5])) { \common_Logger::i('Auxiliary file \'' . $absolutePath . '\' linked to shared storage.'); return $sharedFiles[$md5]; } SharedStimulusImporter::isValidSharedStimulus($absolutePath); $newXmlFile = SharedStimulusPackageImporter::embedAssets($absolutePath); $itemContent = $this->sharedStorage->add($newXmlFile, basename($relativePath), $this->parentPath); if (method_exists($this->sharedStorage, 'forceMimeType')) { $asset = $this->itemSource->resolve($itemContent['uri']); $this->sharedStorage->forceMimeType($asset->getMediaIdentifier(), 'application/qti+xml'); } $this->addSharedFile($md5, $itemContent); \common_Logger::i('Auxiliary file \'' . $absolutePath . '\' added to shared storage.'); return $itemContent; }
php
public function handle($absolutePath, $relativePath) { $sharedFiles = $this->getSharedFiles(); $md5 = md5_file($absolutePath); if (isset($sharedFiles[$md5])) { \common_Logger::i('Auxiliary file \'' . $absolutePath . '\' linked to shared storage.'); return $sharedFiles[$md5]; } SharedStimulusImporter::isValidSharedStimulus($absolutePath); $newXmlFile = SharedStimulusPackageImporter::embedAssets($absolutePath); $itemContent = $this->sharedStorage->add($newXmlFile, basename($relativePath), $this->parentPath); if (method_exists($this->sharedStorage, 'forceMimeType')) { $asset = $this->itemSource->resolve($itemContent['uri']); $this->sharedStorage->forceMimeType($asset->getMediaIdentifier(), 'application/qti+xml'); } $this->addSharedFile($md5, $itemContent); \common_Logger::i('Auxiliary file \'' . $absolutePath . '\' added to shared storage.'); return $itemContent; }
[ "public", "function", "handle", "(", "$", "absolutePath", ",", "$", "relativePath", ")", "{", "$", "sharedFiles", "=", "$", "this", "->", "getSharedFiles", "(", ")", ";", "$", "md5", "=", "md5_file", "(", "$", "absolutePath", ")", ";", "if", "(", "isse...
Handle the process to manage shared stimulus files @param $absolutePath @param $relativePath @return array @throws \qtism\data\storage\xml\XmlStorageException
[ "Handle", "the", "process", "to", "manage", "shared", "stimulus", "files" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/asset/handler/SharedStimulusAssetHandler.php#L84-L107
oat-sa/extension-tao-itemqti
model/qti/asset/handler/SharedStimulusAssetHandler.php
SharedStimulusAssetHandler.addSharedFile
public function addSharedFile($key, $value) { $sharedFiles = $this->getSharedFiles(); $sharedFiles[$key] = $value; $this->setSharedFiles($sharedFiles); return $this; }
php
public function addSharedFile($key, $value) { $sharedFiles = $this->getSharedFiles(); $sharedFiles[$key] = $value; $this->setSharedFiles($sharedFiles); return $this; }
[ "public", "function", "addSharedFile", "(", "$", "key", ",", "$", "value", ")", "{", "$", "sharedFiles", "=", "$", "this", "->", "getSharedFiles", "(", ")", ";", "$", "sharedFiles", "[", "$", "key", "]", "=", "$", "value", ";", "$", "this", "->", "...
Add a shared file @param $key @param $value @return $this
[ "Add", "a", "shared", "file" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/asset/handler/SharedStimulusAssetHandler.php#L158-L164
oat-sa/extension-tao-itemqti
model/CreatorRegistry.php
CreatorRegistry.getDevImplementations
public function getDevImplementations(){ $returnValue = array(); $hookFileName = $this->getHookFileName(); foreach(glob($this->getBaseDevDir().'*/'.$hookFileName.'.js') as $file){ $dir = str_replace($hookFileName.'.js', '', $file); $manifestFile = $dir.$hookFileName.'.json'; if(file_exists($manifestFile)){ $typeIdentifier = basename($dir); $baseUrl = $this->getBaseDevUrl().$typeIdentifier.'/'; $manifest = json_decode(file_get_contents($manifestFile), true); $returnValue[] = array( 'typeIdentifier' => $typeIdentifier, 'label' => $manifest['label'], 'directory' => $dir, 'baseUrl' => $baseUrl, 'file' => $this->getEntryPointFile($typeIdentifier), 'manifest' => $manifest, 'dev' => true, 'debug' => (isset($manifest['debug']) && $manifest['debug']), 'registry' => get_class($this) ); } } return $returnValue; }
php
public function getDevImplementations(){ $returnValue = array(); $hookFileName = $this->getHookFileName(); foreach(glob($this->getBaseDevDir().'*/'.$hookFileName.'.js') as $file){ $dir = str_replace($hookFileName.'.js', '', $file); $manifestFile = $dir.$hookFileName.'.json'; if(file_exists($manifestFile)){ $typeIdentifier = basename($dir); $baseUrl = $this->getBaseDevUrl().$typeIdentifier.'/'; $manifest = json_decode(file_get_contents($manifestFile), true); $returnValue[] = array( 'typeIdentifier' => $typeIdentifier, 'label' => $manifest['label'], 'directory' => $dir, 'baseUrl' => $baseUrl, 'file' => $this->getEntryPointFile($typeIdentifier), 'manifest' => $manifest, 'dev' => true, 'debug' => (isset($manifest['debug']) && $manifest['debug']), 'registry' => get_class($this) ); } } return $returnValue; }
[ "public", "function", "getDevImplementations", "(", ")", "{", "$", "returnValue", "=", "array", "(", ")", ";", "$", "hookFileName", "=", "$", "this", "->", "getHookFileName", "(", ")", ";", "foreach", "(", "glob", "(", "$", "this", "->", "getBaseDevDir", ...
Get PCI Creator hooks directly located at views/js/pciCreator/myCustomInteraction: @return array
[ "Get", "PCI", "Creator", "hooks", "directly", "located", "at", "views", "/", "js", "/", "pciCreator", "/", "myCustomInteraction", ":" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/CreatorRegistry.php#L68-L100
oat-sa/extension-tao-itemqti
model/CreatorRegistry.php
CreatorRegistry.getDevImplementation
public function getDevImplementation($typeIdentifier){ //@todo : re-implement it to be more optimal $devImplementations = $this->getDevImplementations(); foreach($devImplementations as $impl){ if($impl['typeIdentifier'] == $typeIdentifier){ return $impl; } } return null; }
php
public function getDevImplementation($typeIdentifier){ //@todo : re-implement it to be more optimal $devImplementations = $this->getDevImplementations(); foreach($devImplementations as $impl){ if($impl['typeIdentifier'] == $typeIdentifier){ return $impl; } } return null; }
[ "public", "function", "getDevImplementation", "(", "$", "typeIdentifier", ")", "{", "//@todo : re-implement it to be more optimal", "$", "devImplementations", "=", "$", "this", "->", "getDevImplementations", "(", ")", ";", "foreach", "(", "$", "devImplementations", "as"...
Get PCI Creator hook located at views/js/{{hookFileName}}/$typeIdentifier @param string $typeIdentifier @return array
[ "Get", "PCI", "Creator", "hook", "located", "at", "views", "/", "js", "/", "{{", "hookFileName", "}}", "/", "$typeIdentifier" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/CreatorRegistry.php#L108-L118
oat-sa/extension-tao-itemqti
model/CreatorRegistry.php
CreatorRegistry.getDevImplementationDirectory
public function getDevImplementationDirectory($typeIdentifier){ $dir = $this->getBaseDevDir().$typeIdentifier; if(file_exists($dir)){ return $dir; }else{ throw new \common_Exception('the type identifier cannot be found'); } }
php
public function getDevImplementationDirectory($typeIdentifier){ $dir = $this->getBaseDevDir().$typeIdentifier; if(file_exists($dir)){ return $dir; }else{ throw new \common_Exception('the type identifier cannot be found'); } }
[ "public", "function", "getDevImplementationDirectory", "(", "$", "typeIdentifier", ")", "{", "$", "dir", "=", "$", "this", "->", "getBaseDevDir", "(", ")", ".", "$", "typeIdentifier", ";", "if", "(", "file_exists", "(", "$", "dir", ")", ")", "{", "return",...
Get the path to the directory of a the Creator located at views/js/{{hookFileName}}/ @param string $typeIdentifier @return string @throws \common_Exception
[ "Get", "the", "path", "to", "the", "directory", "of", "a", "the", "Creator", "located", "at", "views", "/", "js", "/", "{{", "hookFileName", "}}", "/" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/CreatorRegistry.php#L127-L134
oat-sa/extension-tao-itemqti
model/CreatorRegistry.php
CreatorRegistry.addRequiredResources
public function addRequiredResources($typeIdentifier, core_kernel_classes_Resource $item){ //find the interaction in the registry $implementationData = $this->getImplementatioByTypeIdentifier($typeIdentifier); if(is_null($implementationData)){ throw new common_exception_Error('no implementation found with the type identifier '.$typeIdentifier); } //get the root directory of the interaction $directory = $implementationData['directory']; //get the lists of all required resources $manifest = $implementationData['manifest']; $required = array($manifest['entryPoint']); //include libraries remotely only, so this block is temporarily disabled foreach($manifest['libraries'] as $lib){ if(!ClientLibRegistry::getRegistry()->isRegistered($lib)){ $lib = preg_replace('/^.\//', '', $lib); $lib .= '.js'; //add js extension $required[] = $lib; } } //include custom interaction specific css in the item if(isset($manifest['css'])){ $required = array_merge($required, array_values($manifest['css'])); } //include media in the item if(isset($manifest['media'])){ $required = array_merge($required, array_values($manifest['media'])); } //add them to the rdf item $resources = Authoring::addRequiredResources($directory, $required, $typeIdentifier, $item, ''); return $resources; }
php
public function addRequiredResources($typeIdentifier, core_kernel_classes_Resource $item){ //find the interaction in the registry $implementationData = $this->getImplementatioByTypeIdentifier($typeIdentifier); if(is_null($implementationData)){ throw new common_exception_Error('no implementation found with the type identifier '.$typeIdentifier); } //get the root directory of the interaction $directory = $implementationData['directory']; //get the lists of all required resources $manifest = $implementationData['manifest']; $required = array($manifest['entryPoint']); //include libraries remotely only, so this block is temporarily disabled foreach($manifest['libraries'] as $lib){ if(!ClientLibRegistry::getRegistry()->isRegistered($lib)){ $lib = preg_replace('/^.\//', '', $lib); $lib .= '.js'; //add js extension $required[] = $lib; } } //include custom interaction specific css in the item if(isset($manifest['css'])){ $required = array_merge($required, array_values($manifest['css'])); } //include media in the item if(isset($manifest['media'])){ $required = array_merge($required, array_values($manifest['media'])); } //add them to the rdf item $resources = Authoring::addRequiredResources($directory, $required, $typeIdentifier, $item, ''); return $resources; }
[ "public", "function", "addRequiredResources", "(", "$", "typeIdentifier", ",", "core_kernel_classes_Resource", "$", "item", ")", "{", "//find the interaction in the registry", "$", "implementationData", "=", "$", "this", "->", "getImplementatioByTypeIdentifier", "(", "$", ...
Add required resources for a custom interaction (css, js) in the item directory @param string $typeIdentifier @param \core_kernel_classes_Resource $item @throws common_exception_Error
[ "Add", "required", "resources", "for", "a", "custom", "interaction", "(", "css", "js", ")", "in", "the", "item", "directory" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/CreatorRegistry.php#L153-L191
oat-sa/extension-tao-itemqti
model/portableElement/PortableElementService.php
PortableElementService.validate
public function validate(PortableElementObject $object, $source=null, $validationGroup=array()) { $validator = $object->getModel()->getValidator(); Validator::validate($object, $validator, $validationGroup); if ($source) { $validator->validateAssets($object, $source); } }
php
public function validate(PortableElementObject $object, $source=null, $validationGroup=array()) { $validator = $object->getModel()->getValidator(); Validator::validate($object, $validator, $validationGroup); if ($source) { $validator->validateAssets($object, $source); } }
[ "public", "function", "validate", "(", "PortableElementObject", "$", "object", ",", "$", "source", "=", "null", ",", "$", "validationGroup", "=", "array", "(", ")", ")", "{", "$", "validator", "=", "$", "object", "->", "getModel", "(", ")", "->", "getVal...
Validate a model using associated validator @param PortableElementObject $object @param null $source Directory of portable element, if not null it will be checked @param array $validationGroup Fields to be checked, empty=$validator->getConstraints() @return bool @throws PortableElementInconsistencyModelException
[ "Validate", "a", "model", "using", "associated", "validator" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/PortableElementService.php#L60-L67
oat-sa/extension-tao-itemqti
model/portableElement/PortableElementService.php
PortableElementService.registerModel
public function registerModel(PortableElementObject $object, $source) { $validationGroup = array('typeIdentifier', 'version', 'runtime'); $this->validate($object, $source, $validationGroup); $registry = $object->getModel()->getRegistry(); //enable portable element immediately when registering it $object->enable(); $registry->register($object, $source); return true; }
php
public function registerModel(PortableElementObject $object, $source) { $validationGroup = array('typeIdentifier', 'version', 'runtime'); $this->validate($object, $source, $validationGroup); $registry = $object->getModel()->getRegistry(); //enable portable element immediately when registering it $object->enable(); $registry->register($object, $source); return true; }
[ "public", "function", "registerModel", "(", "PortableElementObject", "$", "object", ",", "$", "source", ")", "{", "$", "validationGroup", "=", "array", "(", "'typeIdentifier'", ",", "'version'", ",", "'runtime'", ")", ";", "$", "this", "->", "validate", "(", ...
Register a $model with $source into registryEntries & filesystem @param PortableElementObject $object @param $source @return bool @throws PortableElementInvalidModelException @throws PortableElementVersionIncompatibilityException
[ "Register", "a", "$model", "with", "$source", "into", "registryEntries", "&", "filesystem" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/PortableElementService.php#L78-L91
oat-sa/extension-tao-itemqti
model/portableElement/PortableElementService.php
PortableElementService.unregisterModel
public function unregisterModel(PortableElementObject $object){ $registry = $object->getModel()->getRegistry(); $registry->delete($object); return true; }
php
public function unregisterModel(PortableElementObject $object){ $registry = $object->getModel()->getRegistry(); $registry->delete($object); return true; }
[ "public", "function", "unregisterModel", "(", "PortableElementObject", "$", "object", ")", "{", "$", "registry", "=", "$", "object", "->", "getModel", "(", ")", "->", "getRegistry", "(", ")", ";", "$", "registry", "->", "delete", "(", "$", "object", ")", ...
Unregister the portable element @param PortableElementObject $object @return bool @throws PortableElementVersionIncompatibilityException
[ "Unregister", "the", "portable", "element" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/PortableElementService.php#L100-L104
oat-sa/extension-tao-itemqti
model/portableElement/PortableElementService.php
PortableElementService.export
public function export($type, $identifier, $version=null) { $model = $this->getPortableModelRegistry()->getModel($type); $object = $model->getRegistry()->fetch($identifier, $version); if (is_null($object)) { throw new PortableElementNotFoundException( 'Unable to find a PCI associated to identifier: ' . $identifier ); } $this->validate($object); return $model->getRegistry()->export($object); }
php
public function export($type, $identifier, $version=null) { $model = $this->getPortableModelRegistry()->getModel($type); $object = $model->getRegistry()->fetch($identifier, $version); if (is_null($object)) { throw new PortableElementNotFoundException( 'Unable to find a PCI associated to identifier: ' . $identifier ); } $this->validate($object); return $model->getRegistry()->export($object); }
[ "public", "function", "export", "(", "$", "type", ",", "$", "identifier", ",", "$", "version", "=", "null", ")", "{", "$", "model", "=", "$", "this", "->", "getPortableModelRegistry", "(", ")", "->", "getModel", "(", "$", "type", ")", ";", "$", "obje...
Export a model with files into a ZIP @param $type @param $identifier @param null $version @return string @throws PortableElementNotFoundException @throws \common_Exception @throws PortableElementInconsistencyModelException
[ "Export", "a", "model", "with", "files", "into", "a", "ZIP" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/PortableElementService.php#L117-L129
oat-sa/extension-tao-itemqti
model/portableElement/PortableElementService.php
PortableElementService.import
public function import($type, $zipFile) { /** @var PortableElementPackageParser $parser */ $parser = $this->getPortableModelRegistry()->getModel($type)->getPackageParser(); $source = $parser->extract($zipFile); $object = $parser->getModel()->createDataObject($parser->getManifestContent($zipFile)); $this->registerModel($object, $source); \tao_helpers_File::delTree($source); return $object; }
php
public function import($type, $zipFile) { /** @var PortableElementPackageParser $parser */ $parser = $this->getPortableModelRegistry()->getModel($type)->getPackageParser(); $source = $parser->extract($zipFile); $object = $parser->getModel()->createDataObject($parser->getManifestContent($zipFile)); $this->registerModel($object, $source); \tao_helpers_File::delTree($source); return $object; }
[ "public", "function", "import", "(", "$", "type", ",", "$", "zipFile", ")", "{", "/** @var PortableElementPackageParser $parser */", "$", "parser", "=", "$", "this", "->", "getPortableModelRegistry", "(", ")", "->", "getModel", "(", "$", "type", ")", "->", "ge...
Import a Portable element from an uploaded zip file @param $type @param $zipFile @return mixed @throws PortableElementInconsistencyModelException
[ "Import", "a", "Portable", "element", "from", "an", "uploaded", "zip", "file" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/PortableElementService.php#L139-L151
oat-sa/extension-tao-itemqti
model/portableElement/PortableElementService.php
PortableElementService.getValidPortableElementFromZipSource
public function getValidPortableElementFromZipSource($type, $zipFile) { /** @var PortableElementPackageParser $parser */ $parser = $this->getPortableModelRegistry()->getModel($type)->getPackageParser(); $source = $parser->extract($zipFile); $object = $parser->getModel()->createDataObject($parser->getManifestContent($zipFile)); $this->validate($object, $source); return $object; }
php
public function getValidPortableElementFromZipSource($type, $zipFile) { /** @var PortableElementPackageParser $parser */ $parser = $this->getPortableModelRegistry()->getModel($type)->getPackageParser(); $source = $parser->extract($zipFile); $object = $parser->getModel()->createDataObject($parser->getManifestContent($zipFile)); $this->validate($object, $source); return $object; }
[ "public", "function", "getValidPortableElementFromZipSource", "(", "$", "type", ",", "$", "zipFile", ")", "{", "/** @var PortableElementPackageParser $parser */", "$", "parser", "=", "$", "this", "->", "getPortableModelRegistry", "(", ")", "->", "getModel", "(", "$", ...
Extract a valid model from a zip @param $type @param $zipFile @return mixed @throws PortableElementInconsistencyModelException
[ "Extract", "a", "valid", "model", "from", "a", "zip" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/PortableElementService.php#L161-L170
oat-sa/extension-tao-itemqti
model/portableElement/PortableElementService.php
PortableElementService.getDirectoryParsers
protected function getDirectoryParsers() { $parsers = array(); $models = $this->getPortableModelRegistry()->getModels(); foreach ($models as $key => $model) { if ($model->getDirectoryParser() instanceof PortableElementDirectoryParser) { $parsers[] = $model->getDirectoryParser(); } else { \common_Logger::w('Invalid DirectoryParser for model '.$key); } } return $parsers; }
php
protected function getDirectoryParsers() { $parsers = array(); $models = $this->getPortableModelRegistry()->getModels(); foreach ($models as $key => $model) { if ($model->getDirectoryParser() instanceof PortableElementDirectoryParser) { $parsers[] = $model->getDirectoryParser(); } else { \common_Logger::w('Invalid DirectoryParser for model '.$key); } } return $parsers; }
[ "protected", "function", "getDirectoryParsers", "(", ")", "{", "$", "parsers", "=", "array", "(", ")", ";", "$", "models", "=", "$", "this", "->", "getPortableModelRegistry", "(", ")", "->", "getModels", "(", ")", ";", "foreach", "(", "$", "models", "as"...
Return all directory parsers from configuration @return PortableElementDirectoryParser[]
[ "Return", "all", "directory", "parsers", "from", "configuration" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/PortableElementService.php#L177-L189
oat-sa/extension-tao-itemqti
model/portableElement/PortableElementService.php
PortableElementService.getValidPortableElementFromDirectorySource
public function getValidPortableElementFromDirectorySource($directory) { $parserMatched = null; $parsers = $this->getDirectoryParsers(); /** @var PortableElementDirectoryParser $parser */ foreach ($parsers as $parser) { if ($parser->hasValidPortableElement($directory)) { $parserMatched = $parser; } } if (is_null($parserMatched)) { throw new PortableElementParserException( 'This zip source is not compatible with any portable element. Manifest and/or engine file are missing ' . ' or related extensions are not installed.' ); } $source = $parserMatched->extract($directory); $object = $parserMatched->getModel()->createDataObject($parserMatched->getManifestContent($directory)); // Validate Portable Element Model try { $this->validate($object, $source); } catch (PortableElementInvalidModelException $e) { \common_Logger::w($e->getMessage()); return null; } return $object; }
php
public function getValidPortableElementFromDirectorySource($directory) { $parserMatched = null; $parsers = $this->getDirectoryParsers(); /** @var PortableElementDirectoryParser $parser */ foreach ($parsers as $parser) { if ($parser->hasValidPortableElement($directory)) { $parserMatched = $parser; } } if (is_null($parserMatched)) { throw new PortableElementParserException( 'This zip source is not compatible with any portable element. Manifest and/or engine file are missing ' . ' or related extensions are not installed.' ); } $source = $parserMatched->extract($directory); $object = $parserMatched->getModel()->createDataObject($parserMatched->getManifestContent($directory)); // Validate Portable Element Model try { $this->validate($object, $source); } catch (PortableElementInvalidModelException $e) { \common_Logger::w($e->getMessage()); return null; } return $object; }
[ "public", "function", "getValidPortableElementFromDirectorySource", "(", "$", "directory", ")", "{", "$", "parserMatched", "=", "null", ";", "$", "parsers", "=", "$", "this", "->", "getDirectoryParsers", "(", ")", ";", "/** @var PortableElementDirectoryParser $parser */...
Extract a valid model from a directory @param $directory @return null|PortableElementObject @throws PortableElementParserException @throws \common_Exception
[ "Extract", "a", "valid", "model", "from", "a", "directory" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/PortableElementService.php#L199-L229
oat-sa/extension-tao-itemqti
model/portableElement/PortableElementService.php
PortableElementService.getPortableElementByIdentifier
public function getPortableElementByIdentifier($type, $identifier, $version=null) { $model = $this->getPortableModelRegistry()->getModel($type); $registry = $model->getRegistry(); if($registry->has($identifier, $version)){ return $registry->fetch($identifier, $version); } return null; }
php
public function getPortableElementByIdentifier($type, $identifier, $version=null) { $model = $this->getPortableModelRegistry()->getModel($type); $registry = $model->getRegistry(); if($registry->has($identifier, $version)){ return $registry->fetch($identifier, $version); } return null; }
[ "public", "function", "getPortableElementByIdentifier", "(", "$", "type", ",", "$", "identifier", ",", "$", "version", "=", "null", ")", "{", "$", "model", "=", "$", "this", "->", "getPortableModelRegistry", "(", ")", "->", "getModel", "(", "$", "type", ")...
Get model from identifier & version @param $type @param $identifier @param null $version @return null|PortableElementObject @throws PortableElementNotFoundException @throws PortableElementInconsistencyModelException
[ "Get", "model", "from", "identifier", "&", "version" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/PortableElementService.php#L241-L250
oat-sa/extension-tao-itemqti
model/portableElement/PortableElementService.php
PortableElementService.registerFromDirectorySource
public function registerFromDirectorySource($directory) { $object = $this->getValidPortableElementFromDirectorySource($directory); if (is_null($object)) { throw new PortableElementNotFoundException('No valid portable element model found in the directory '.$directory); } return $this->registerModel($object, $directory); }
php
public function registerFromDirectorySource($directory) { $object = $this->getValidPortableElementFromDirectorySource($directory); if (is_null($object)) { throw new PortableElementNotFoundException('No valid portable element model found in the directory '.$directory); } return $this->registerModel($object, $directory); }
[ "public", "function", "registerFromDirectorySource", "(", "$", "directory", ")", "{", "$", "object", "=", "$", "this", "->", "getValidPortableElementFromDirectorySource", "(", "$", "directory", ")", ";", "if", "(", "is_null", "(", "$", "object", ")", ")", "{",...
Register a model from a directory based on manifest.json @param $directory @return bool @throws \common_Exception
[ "Register", "a", "model", "from", "a", "directory", "based", "on", "manifest", ".", "json" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/PortableElementService.php#L259-L267
oat-sa/extension-tao-itemqti
model/portableElement/PortableElementService.php
PortableElementService.retrieve
public function retrieve($type, $identifier, $version=null) { $model = $this->getPortableModelRegistry()->getModel($type); return $model->getRegistry()->fetch($identifier, $version); }
php
public function retrieve($type, $identifier, $version=null) { $model = $this->getPortableModelRegistry()->getModel($type); return $model->getRegistry()->fetch($identifier, $version); }
[ "public", "function", "retrieve", "(", "$", "type", ",", "$", "identifier", ",", "$", "version", "=", "null", ")", "{", "$", "model", "=", "$", "this", "->", "getPortableModelRegistry", "(", ")", "->", "getModel", "(", "$", "type", ")", ";", "return", ...
Fill all values of a model based on $object->getTypeIdentifier, $object->getVersion @param $type @param $identifier @param null $version @return PortableElementObject @throws PortableElementNotFoundException @throws PortableElementInconsistencyModelException
[ "Fill", "all", "values", "of", "a", "model", "based", "on", "$object", "-", ">", "getTypeIdentifier", "$object", "-", ">", "getVersion" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/PortableElementService.php#L279-L283
oat-sa/extension-tao-itemqti
model/portableElement/PortableElementService.php
PortableElementService.getFileStream
public function getFileStream(PortableElementObject $object, $file) { return $object->getModel()->getRegistry()->getFileStream($object, $file); }
php
public function getFileStream(PortableElementObject $object, $file) { return $object->getModel()->getRegistry()->getFileStream($object, $file); }
[ "public", "function", "getFileStream", "(", "PortableElementObject", "$", "object", ",", "$", "file", ")", "{", "return", "$", "object", "->", "getModel", "(", ")", "->", "getRegistry", "(", ")", "->", "getFileStream", "(", "$", "object", ",", "$", "file",...
Return the stream of a file model @param PortableElementObject $object @param $file @return bool|false|resource @throws \tao_models_classes_FileNotFoundException
[ "Return", "the", "stream", "of", "a", "file", "model" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/PortableElementService.php#L293-L296
oat-sa/extension-tao-itemqti
model/portableElement/PortableElementService.php
PortableElementService.getPortableElementByClass
public function getPortableElementByClass($portableElementClass, Element $qtiItem, $useVersionAlias = false){ $portableElements = []; $identifiers = array_map(function($portableElement){ return $portableElement->getTypeIdentifier(); }, $qtiItem->getComposingElements($portableElementClass)); foreach($this->getPortableModelRegistry()->getModels() as $model){ $phpClass = $model->getQtiElementClassName(); if(is_subclass_of($phpClass, $portableElementClass)){ $portableElements = array_merge($portableElements, array_filter($model->getRegistry()->getLatestRuntimes($useVersionAlias), function($data) use ($identifiers){ $portableElement = reset($data); if(!empty($portableElement) && in_array($portableElement['typeIdentifier'], $identifiers)){ return true; } return false; })); } } /** * @deprecated do not use the returned baseUrl */ return $portableElements; }
php
public function getPortableElementByClass($portableElementClass, Element $qtiItem, $useVersionAlias = false){ $portableElements = []; $identifiers = array_map(function($portableElement){ return $portableElement->getTypeIdentifier(); }, $qtiItem->getComposingElements($portableElementClass)); foreach($this->getPortableModelRegistry()->getModels() as $model){ $phpClass = $model->getQtiElementClassName(); if(is_subclass_of($phpClass, $portableElementClass)){ $portableElements = array_merge($portableElements, array_filter($model->getRegistry()->getLatestRuntimes($useVersionAlias), function($data) use ($identifiers){ $portableElement = reset($data); if(!empty($portableElement) && in_array($portableElement['typeIdentifier'], $identifiers)){ return true; } return false; })); } } /** * @deprecated do not use the returned baseUrl */ return $portableElements; }
[ "public", "function", "getPortableElementByClass", "(", "$", "portableElementClass", ",", "Element", "$", "qtiItem", ",", "$", "useVersionAlias", "=", "false", ")", "{", "$", "portableElements", "=", "[", "]", ";", "$", "identifiers", "=", "array_map", "(", "f...
Get the array of portable elements used in qti item object by its php class @param string $portableElementClass - PORTABLE_CLASS_INTERACTION or PORTABLE_CLASS_INFOCONTROL @param Element $qtiItem @return array
[ "Get", "the", "array", "of", "portable", "elements", "used", "in", "qti", "item", "object", "by", "its", "php", "class" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/PortableElementService.php#L318-L342
oat-sa/extension-tao-itemqti
model/portableElement/PortableElementService.php
PortableElementService.setBaseUrlToPortableData
public function setBaseUrlToPortableData(&$data){ $model = $this->getPortableModelRegistry()->getModel($data['model']); $portableObject = $model->createDataObject($data); $data['baseUrl'] = $model->getRegistry()->getBaseUrl($portableObject); return $data; }
php
public function setBaseUrlToPortableData(&$data){ $model = $this->getPortableModelRegistry()->getModel($data['model']); $portableObject = $model->createDataObject($data); $data['baseUrl'] = $model->getRegistry()->getBaseUrl($portableObject); return $data; }
[ "public", "function", "setBaseUrlToPortableData", "(", "&", "$", "data", ")", "{", "$", "model", "=", "$", "this", "->", "getPortableModelRegistry", "(", ")", "->", "getModel", "(", "$", "data", "[", "'model'", "]", ")", ";", "$", "portableObject", "=", ...
Set the base url to a portable element data array @param $data @return mixed
[ "Set", "the", "base", "url", "to", "a", "portable", "element", "data", "array" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/PortableElementService.php#L349-L354
oat-sa/extension-tao-itemqti
model/qti/expression/CommonExpression.php
CommonExpression.getRule
public function getRule() { $returnValue = (string) ''; // Get subExpressions $subExpressionsRules = array(); foreach ($this->subExpressions as $subExpression){ $subExpressionsRules[] = $subExpression->getRule(); } $subExpressionsJSON = implode(',', $subExpressionsRules); // Format options $optionsJSON = count($this->attributes) ? '"'.addslashes(json_encode($this->attributes)).'"' : 'null'; // Format rule function of the expression operator switch ($this->name) { case 'correct': $returnValue = 'getCorrect("'.$this->attributes['identifier'].'")'; break; case 'mapResponse': $identifier = $this->attributes['identifier']; $returnValue = 'mapResponse(' . $optionsJSON .', getMap("'.$identifier.'"), getResponse("'.$identifier.'"))'; break; // Multiple is a Creation of List from parameters case 'multiple': $returnValue = 'createVariable("{\"type\":\"list\"}", '.$subExpressionsJSON.')'; break; // Null is a Creation of empty BaseTypeVariable case 'null': $returnValue = 'createVariable(null, null)'; break; // Ordered is a Creation of Tuple from parameters case 'ordered': $returnValue = 'createVariable("{\"type\":\"tuple\"}", '.$subExpressionsJSON.')'; break; case 'outcome': $returnValue = 'getOutcome("'.$this->attributes['identifier'].'")'; break; case 'setOutcomeValue': //@todo remove this throw new common_Exception('setOutcomeValue is not a valid expression'); break; case 'variable': $returnValue = 'getVariable("'.$this->attributes['identifier'].'")'; break; default: $returnValue = $this->name.'(' . $optionsJSON . ($subExpressionsJSON!="" ? ', '.$subExpressionsJSON : '') .')'; } return (string) $returnValue; }
php
public function getRule() { $returnValue = (string) ''; // Get subExpressions $subExpressionsRules = array(); foreach ($this->subExpressions as $subExpression){ $subExpressionsRules[] = $subExpression->getRule(); } $subExpressionsJSON = implode(',', $subExpressionsRules); // Format options $optionsJSON = count($this->attributes) ? '"'.addslashes(json_encode($this->attributes)).'"' : 'null'; // Format rule function of the expression operator switch ($this->name) { case 'correct': $returnValue = 'getCorrect("'.$this->attributes['identifier'].'")'; break; case 'mapResponse': $identifier = $this->attributes['identifier']; $returnValue = 'mapResponse(' . $optionsJSON .', getMap("'.$identifier.'"), getResponse("'.$identifier.'"))'; break; // Multiple is a Creation of List from parameters case 'multiple': $returnValue = 'createVariable("{\"type\":\"list\"}", '.$subExpressionsJSON.')'; break; // Null is a Creation of empty BaseTypeVariable case 'null': $returnValue = 'createVariable(null, null)'; break; // Ordered is a Creation of Tuple from parameters case 'ordered': $returnValue = 'createVariable("{\"type\":\"tuple\"}", '.$subExpressionsJSON.')'; break; case 'outcome': $returnValue = 'getOutcome("'.$this->attributes['identifier'].'")'; break; case 'setOutcomeValue': //@todo remove this throw new common_Exception('setOutcomeValue is not a valid expression'); break; case 'variable': $returnValue = 'getVariable("'.$this->attributes['identifier'].'")'; break; default: $returnValue = $this->name.'(' . $optionsJSON . ($subExpressionsJSON!="" ? ', '.$subExpressionsJSON : '') .')'; } return (string) $returnValue; }
[ "public", "function", "getRule", "(", ")", "{", "$", "returnValue", "=", "(", "string", ")", "''", ";", "// Get subExpressions", "$", "subExpressionsRules", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "subExpressions", "as", "$", "subEx...
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/CommonExpression.php#L86-L145
oat-sa/extension-tao-itemqti
model/qti/expression/CommonExpression.php
CommonExpression.setValue
public function setValue( $value) { // Set the value of the expression and cast it function of the (defined) base type of the variable if ($this->attributes['baseType']){ switch ($this->attributes['baseType']){ case 'boolean': if (is_string ($value)){ $this->value = (bool)($value=='true'||$value=='1'?1:0); }else if (is_bool ($value)){ $this->value = $value; }else if ($value == null){ $this->value = null; }else{ throw new Exception ('taoQTI_models_classes_QTI_response_ExpressionOperator::setValue : an error occured, the value ['.$value.'] is not a well formed boolean'); } break; case 'float': $this->value = (float)$value; break; case 'integer': $this->value = (int)$value; break; case 'identifier': case 'string': $this->value = (string)$value; break; case 'pair': $this->value = taoQTI_models_classes_Matching_VariableFactory::createJSONValueFromQTIData($value, 'pair'); break; case 'directedPair': $this->value = taoQTI_models_classes_Matching_VariableFactory::createJSONValueFromQTIData($value, 'directedPair'); break; } } }
php
public function setValue( $value) { // Set the value of the expression and cast it function of the (defined) base type of the variable if ($this->attributes['baseType']){ switch ($this->attributes['baseType']){ case 'boolean': if (is_string ($value)){ $this->value = (bool)($value=='true'||$value=='1'?1:0); }else if (is_bool ($value)){ $this->value = $value; }else if ($value == null){ $this->value = null; }else{ throw new Exception ('taoQTI_models_classes_QTI_response_ExpressionOperator::setValue : an error occured, the value ['.$value.'] is not a well formed boolean'); } break; case 'float': $this->value = (float)$value; break; case 'integer': $this->value = (int)$value; break; case 'identifier': case 'string': $this->value = (string)$value; break; case 'pair': $this->value = taoQTI_models_classes_Matching_VariableFactory::createJSONValueFromQTIData($value, 'pair'); break; case 'directedPair': $this->value = taoQTI_models_classes_Matching_VariableFactory::createJSONValueFromQTIData($value, 'directedPair'); break; } } }
[ "public", "function", "setValue", "(", "$", "value", ")", "{", "// Set the value of the expression and cast it function of the (defined) base type of the variable", "if", "(", "$", "this", "->", "attributes", "[", "'baseType'", "]", ")", "{", "switch", "(", "$", "this",...
Short description of method setValue @access public @author Joel Bout, <joel.bout@tudor.lu> @param value @return mixed
[ "Short", "description", "of", "method", "setValue" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/expression/CommonExpression.php#L187-L224
oat-sa/extension-tao-itemqti
model/qti/metadata/ontology/GenericLomOntologyClassificationInjector.php
GenericLomOntologyClassificationInjector.inject
public function inject($target, array $values) { if (!$target instanceof \core_kernel_classes_Resource) { $msg = "The given target is not an instance of core_kernel_classes_Resource."; throw new MetadataInjectionException($msg); } /** @var \core_kernel_classes_Class $targetClass */ $types = $target->getTypes(); $targetClass = reset($types); $classProperties = $targetClass->getProperties(true); $properties = []; foreach ($classProperties as $property) { $properties[] = $property->getUri(); } $properties = array_diff($properties, GenericLomOntologyClassificationExtractor::$excludedProperties); foreach ($values as $metadataValues) { /** @var MetadataValue $metadataValue */ foreach ($metadataValues as $metadataValue) { $lang = $metadataValue->getLanguage() ?: DEFAULT_LANG; $path = $metadataValue->getPath(); $valuePath = end($path); if (in_array($valuePath, $properties)) { $prop = $this->getProperty($valuePath); if ($target->getPropertyValuesByLg($prop, $lang)->count() > 0) { $target->editPropertyValueByLg($prop, $metadataValue->getValue(), $lang); } else { $target->setPropertyValueByLg($prop, $metadataValue->getValue(), $lang); } } } } }
php
public function inject($target, array $values) { if (!$target instanceof \core_kernel_classes_Resource) { $msg = "The given target is not an instance of core_kernel_classes_Resource."; throw new MetadataInjectionException($msg); } /** @var \core_kernel_classes_Class $targetClass */ $types = $target->getTypes(); $targetClass = reset($types); $classProperties = $targetClass->getProperties(true); $properties = []; foreach ($classProperties as $property) { $properties[] = $property->getUri(); } $properties = array_diff($properties, GenericLomOntologyClassificationExtractor::$excludedProperties); foreach ($values as $metadataValues) { /** @var MetadataValue $metadataValue */ foreach ($metadataValues as $metadataValue) { $lang = $metadataValue->getLanguage() ?: DEFAULT_LANG; $path = $metadataValue->getPath(); $valuePath = end($path); if (in_array($valuePath, $properties)) { $prop = $this->getProperty($valuePath); if ($target->getPropertyValuesByLg($prop, $lang)->count() > 0) { $target->editPropertyValueByLg($prop, $metadataValue->getValue(), $lang); } else { $target->setPropertyValueByLg($prop, $metadataValue->getValue(), $lang); } } } } }
[ "public", "function", "inject", "(", "$", "target", ",", "array", "$", "values", ")", "{", "if", "(", "!", "$", "target", "instanceof", "\\", "core_kernel_classes_Resource", ")", "{", "$", "msg", "=", "\"The given target is not an instance of core_kernel_classes_Res...
Inject dynamically a metadata to an item property @param mixed $target @param array $values @throws MetadataInjectionException
[ "Inject", "dynamically", "a", "metadata", "to", "an", "item", "property" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/ontology/GenericLomOntologyClassificationInjector.php#L39-L73
oat-sa/extension-tao-itemqti
model/qti/XInclude.php
XInclude.getTemplateQtiVariables
protected function getTemplateQtiVariables(){ $variables = parent::getTemplateQtiVariables(); $tag = static::$qtiTagName; //search existing mathML ns declaration: $ns = $this->getXIncludeNamespace(); if(empty($ns)){ //add one! $relatedItem = $this->getRelatedItem(); if(!is_null($relatedItem)){ $ns = 'xi'; $relatedItem->addNamespace($ns, 'http://www.w3.org/2001/XInclude'); } } if(!empty($ns)){ //proceed to ns addition: $tag = $ns.':'.$tag; } $variables['tag'] = $tag; return $variables; }
php
protected function getTemplateQtiVariables(){ $variables = parent::getTemplateQtiVariables(); $tag = static::$qtiTagName; //search existing mathML ns declaration: $ns = $this->getXIncludeNamespace(); if(empty($ns)){ //add one! $relatedItem = $this->getRelatedItem(); if(!is_null($relatedItem)){ $ns = 'xi'; $relatedItem->addNamespace($ns, 'http://www.w3.org/2001/XInclude'); } } if(!empty($ns)){ //proceed to ns addition: $tag = $ns.':'.$tag; } $variables['tag'] = $tag; return $variables; }
[ "protected", "function", "getTemplateQtiVariables", "(", ")", "{", "$", "variables", "=", "parent", "::", "getTemplateQtiVariables", "(", ")", ";", "$", "tag", "=", "static", "::", "$", "qtiTagName", ";", "//search existing mathML ns declaration:", "$", "ns", "=",...
Get the variables for the qti template rendering @return array
[ "Get", "the", "variables", "for", "the", "qti", "template", "rendering" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/XInclude.php#L76-L100
oat-sa/extension-tao-itemqti
model/qti/XInclude.php
XInclude.getXIncludeNamespace
public function getXIncludeNamespace(){ $ns = ''; $relatedItem = $this->getRelatedItem(); if(!is_null($relatedItem)){ foreach($relatedItem->getNamespaces() as $name => $uri){ if(strpos($uri, 'XInclude') > 0){ $ns = $name; break; } } } return $ns; }
php
public function getXIncludeNamespace(){ $ns = ''; $relatedItem = $this->getRelatedItem(); if(!is_null($relatedItem)){ foreach($relatedItem->getNamespaces() as $name => $uri){ if(strpos($uri, 'XInclude') > 0){ $ns = $name; break; } } } return $ns; }
[ "public", "function", "getXIncludeNamespace", "(", ")", "{", "$", "ns", "=", "''", ";", "$", "relatedItem", "=", "$", "this", "->", "getRelatedItem", "(", ")", ";", "if", "(", "!", "is_null", "(", "$", "relatedItem", ")", ")", "{", "foreach", "(", "$...
Get the xml namespace of the xinclude @return string
[ "Get", "the", "xml", "namespace", "of", "the", "xinclude" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/XInclude.php#L107-L119
oat-sa/extension-tao-itemqti
model/qti/metadata/imsManifest/classificationMetadata/GenericLomManifestClassificationExtractor.php
GenericLomManifestClassificationExtractor.extract
public function extract($manifest) { $values = parent::extract($manifest); $newValues = array(); foreach ($values as $resourceIdentifier => $metadataValueCollection) { /** @var ImsManifestMetadataValue $metadataValue */ foreach ($metadataValueCollection as $key => $metadataValue) { // If metadata is not a source or is empty then skip if ($metadataValue->getValue() === '' || $metadataValue->getPath() !== ClassificationSourceMetadataValue::getSourcePath()) { continue; } // If next metadata does not exist then skip if (! isset($metadataValueCollection[$key + 1])) { continue; } /** @var MetadataValue $entryMetadata */ $entryMetadata = $metadataValueCollection[$key + 1]; // Handle metadata if it is an entry and is not empty if ($entryMetadata->getPath() === ClassificationEntryMetadataValue::getEntryPath() && $entryMetadata->getValue() !== '') { $newValues[$resourceIdentifier][] = new SimpleMetadataValue( $resourceIdentifier, array(LomMetadata::LOM_NAMESPACE . '#lom', $metadataValue->getValue()), $entryMetadata->getValue() ); } } } return $newValues; }
php
public function extract($manifest) { $values = parent::extract($manifest); $newValues = array(); foreach ($values as $resourceIdentifier => $metadataValueCollection) { /** @var ImsManifestMetadataValue $metadataValue */ foreach ($metadataValueCollection as $key => $metadataValue) { // If metadata is not a source or is empty then skip if ($metadataValue->getValue() === '' || $metadataValue->getPath() !== ClassificationSourceMetadataValue::getSourcePath()) { continue; } // If next metadata does not exist then skip if (! isset($metadataValueCollection[$key + 1])) { continue; } /** @var MetadataValue $entryMetadata */ $entryMetadata = $metadataValueCollection[$key + 1]; // Handle metadata if it is an entry and is not empty if ($entryMetadata->getPath() === ClassificationEntryMetadataValue::getEntryPath() && $entryMetadata->getValue() !== '') { $newValues[$resourceIdentifier][] = new SimpleMetadataValue( $resourceIdentifier, array(LomMetadata::LOM_NAMESPACE . '#lom', $metadataValue->getValue()), $entryMetadata->getValue() ); } } } return $newValues; }
[ "public", "function", "extract", "(", "$", "manifest", ")", "{", "$", "values", "=", "parent", "::", "extract", "(", "$", "manifest", ")", ";", "$", "newValues", "=", "array", "(", ")", ";", "foreach", "(", "$", "values", "as", "$", "resourceIdentifier...
@see ImsManifestDataExtractor::extract() @param mixed $manifest @return array
[ "@see", "ImsManifestDataExtractor", "::", "extract", "()" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/imsManifest/classificationMetadata/GenericLomManifestClassificationExtractor.php#L37-L72
oat-sa/extension-tao-itemqti
model/portableElement/parser/element/PortableElementDirectoryParser.php
PortableElementDirectoryParser.validate
public function validate($source) { $this->assertSourceAsDirectory($source); $definitionFiles = $this->getModel()->getDefinitionFiles(); foreach ($definitionFiles as $file) { if (! file_exists($source . DIRECTORY_SEPARATOR . $file)) { throw new PortableElementParserException('A portable element package must contains a "' . $file . '" file at the root of the directory: "' . $source . '"'); } } $this->getModel()->createDataObject($this->getManifestContent($source)); return true; }
php
public function validate($source) { $this->assertSourceAsDirectory($source); $definitionFiles = $this->getModel()->getDefinitionFiles(); foreach ($definitionFiles as $file) { if (! file_exists($source . DIRECTORY_SEPARATOR . $file)) { throw new PortableElementParserException('A portable element package must contains a "' . $file . '" file at the root of the directory: "' . $source . '"'); } } $this->getModel()->createDataObject($this->getManifestContent($source)); return true; }
[ "public", "function", "validate", "(", "$", "source", ")", "{", "$", "this", "->", "assertSourceAsDirectory", "(", "$", "source", ")", ";", "$", "definitionFiles", "=", "$", "this", "->", "getModel", "(", ")", "->", "getDefinitionFiles", "(", ")", ";", "...
Validate the source directory @param string $source Directory path to validate @return bool @throws ExtractException @throws PortableElementParserException @throws common_Exception
[ "Validate", "the", "source", "directory" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/parser/element/PortableElementDirectoryParser.php#L49-L63
oat-sa/extension-tao-itemqti
model/portableElement/parser/element/PortableElementDirectoryParser.php
PortableElementDirectoryParser.getManifestContent
public function getManifestContent($source) { $content = json_decode(file_get_contents($source . DIRECTORY_SEPARATOR . $this->getModel()->getManifestName()), true); if (json_last_error() === JSON_ERROR_NONE) { return $content; } throw new common_Exception('Portable element manifest is not a valid json file.'); }
php
public function getManifestContent($source) { $content = json_decode(file_get_contents($source . DIRECTORY_SEPARATOR . $this->getModel()->getManifestName()), true); if (json_last_error() === JSON_ERROR_NONE) { return $content; } throw new common_Exception('Portable element manifest is not a valid json file.'); }
[ "public", "function", "getManifestContent", "(", "$", "source", ")", "{", "$", "content", "=", "json_decode", "(", "file_get_contents", "(", "$", "source", ".", "DIRECTORY_SEPARATOR", ".", "$", "this", "->", "getModel", "(", ")", "->", "getManifestName", "(", ...
Return the manifest content found in the source directory as json array @param string $source Directory path @return array @throws PortableElementInconsistencyModelException @throws common_Exception
[ "Return", "the", "manifest", "content", "found", "in", "the", "source", "directory", "as", "json", "array" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/parser/element/PortableElementDirectoryParser.php#L86-L94
oat-sa/extension-tao-itemqti
model/tasks/ImportQtiItem.php
ImportQtiItem.createTask
public static function createTask($packageFile, \core_kernel_classes_Class $class, ServiceLocatorInterface $serviceManager, $enableMetadataGuardians = true, $enableMetadataValidators = true, $itemMustExist = false, $itemMustBeOverwritten = false) { $action = new self(); $action->setServiceLocator($serviceManager); $fileUri = $action->saveFile($packageFile, basename($packageFile)); /** @var QueueDispatcherInterface $queueDispatcher */ $queueDispatcher = $serviceManager->get(QueueDispatcherInterface::SERVICE_ID); return $queueDispatcher->createTask( $action, [ self::PARAM_FILE => $fileUri, self::PARAM_CLASS_URI => $class->getUri(), self::PARAM_GUARDIANS => $enableMetadataGuardians, self::PARAM_VALIDATORS => $enableMetadataValidators, self::PARAM_ITEM_MUST_EXIST => $itemMustExist, self::PARAM_ITEM_MUST_BE_OVERWRITTEN => $itemMustBeOverwritten ], __('Import QTI ITEM into "%s"', $class->getLabel()) ); }
php
public static function createTask($packageFile, \core_kernel_classes_Class $class, ServiceLocatorInterface $serviceManager, $enableMetadataGuardians = true, $enableMetadataValidators = true, $itemMustExist = false, $itemMustBeOverwritten = false) { $action = new self(); $action->setServiceLocator($serviceManager); $fileUri = $action->saveFile($packageFile, basename($packageFile)); /** @var QueueDispatcherInterface $queueDispatcher */ $queueDispatcher = $serviceManager->get(QueueDispatcherInterface::SERVICE_ID); return $queueDispatcher->createTask( $action, [ self::PARAM_FILE => $fileUri, self::PARAM_CLASS_URI => $class->getUri(), self::PARAM_GUARDIANS => $enableMetadataGuardians, self::PARAM_VALIDATORS => $enableMetadataValidators, self::PARAM_ITEM_MUST_EXIST => $itemMustExist, self::PARAM_ITEM_MUST_BE_OVERWRITTEN => $itemMustBeOverwritten ], __('Import QTI ITEM into "%s"', $class->getLabel()) ); }
[ "public", "static", "function", "createTask", "(", "$", "packageFile", ",", "\\", "core_kernel_classes_Class", "$", "class", ",", "ServiceLocatorInterface", "$", "serviceManager", ",", "$", "enableMetadataGuardians", "=", "true", ",", "$", "enableMetadataValidators", ...
Create task in queue @param string $packageFile uploaded file path @param \core_kernel_classes_Class $class uploaded file @param ServiceLocatorInterface $serviceManager @param boolean $enableMetadataGuardians @param boolean $enableMetadataValidators @param boolean $itemMustExist @param boolean $itemMustBeOverwritten @return TaskInterface
[ "Create", "task", "in", "queue" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/tasks/ImportQtiItem.php#L95-L117
oat-sa/extension-tao-itemqti
model/Export/AbstractQTIItemExporter.php
AbstractQTIItemExporter.export
public function export($options = array()) { $report = \common_report_Report::createSuccess(); $asApip = isset($options['apip']) && $options['apip'] === true; $lang = \common_session_SessionManager::getSession()->getDataLanguage(); $basePath = $this->buildBasePath(); if(is_null($this->getItemModel())){ $report->setMessage($this->getExportErrorMessage(__('not a QTI item'))); $report->setType(\common_report_Report::TYPE_ERROR); return $report; } $dataFile = (string) $this->getItemModel()->getOnePropertyValue(new core_kernel_classes_Property(\taoItems_models_classes_ItemsService::TAO_ITEM_MODEL_DATAFILE_PROPERTY)); $resolver = new ItemMediaResolver($this->getItem(), $lang); $replacementList = array(); $portableElements = $this->getPortableElementAssets($this->getItem(), $lang); $service = new PortableElementService(); $service->setServiceLocator(ServiceManager::getServiceManager()); $portableElementsToExport = []; $portableAssets = []; foreach($portableElements as $element) { if (! $element instanceof Element) { continue; } try { $object = $service->getPortableObjectFromInstance($element); } catch (PortableElementException $e) { $message = __('Fail to export item') . ' (' . $this->getItem()->getLabel() . '): ' . $e->getMessage(); return \common_report_Report::createFailure($message); } $portableElementExporter = $object->getModel()->getExporter($object, $this); $portableElementsToExport[$element->getTypeIdentifier()] = $portableElementExporter; try { $portableAssets = array_merge($portableAssets, $portableElementExporter->copyAssetFiles($replacementList)); } catch (\tao_models_classes_FileNotFoundException $e) { \common_Logger::i($e->getMessage()); $report->setMessage('Missing portable element asset for "' . $object->getTypeIdentifier() . '"": ' . $e->getMessage()); $report->setType(\common_report_Report::TYPE_ERROR); } } $assets = $this->getAssets($this->getItem(), $lang); foreach ($assets as $assetUrl) { try{ $mediaAsset = $resolver->resolve($assetUrl); $mediaSource = $mediaAsset->getMediaSource(); if (!$mediaSource instanceof HttpSource) { $link = $mediaAsset->getMediaIdentifier(); $stream = $mediaSource->getFileStream($link); $baseName = ($mediaSource instanceof LocalItemSource) ? $link : 'assets/' . $mediaSource->getBaseName($link); $replacement = $this->copyAssetFile($stream, $basePath, $baseName, $replacementList); $replacementList[$assetUrl] = $replacement; } } catch(\tao_models_classes_FileNotFoundException $e){ $replacementList[$assetUrl] = ''; $report->setMessage('Missing resource for ' . $assetUrl); $report->setType(\common_report_Report::TYPE_ERROR); } } try{ $xml = Service::singleton()->getXmlByRdfItem($this->getItem()); }catch(FileNotFoundException $e){ $report->setMessage($this->getExportErrorMessage(__('cannot find QTI XML'))); $report->setType(\common_report_Report::TYPE_ERROR); return $report; } $dom = new DOMDocument('1.0', 'UTF-8'); $dom->preserveWhiteSpace = false; $dom->formatOutput = true; if ($dom->loadXML($xml) === true) { $xpath = new \DOMXPath($dom); $attributeNodes = $xpath->query('//@*'); $portableEntryNodes = $xpath->query("//*[local-name()='entry']|//*[local-name()='property']") ?: []; unset($xpath); foreach ($attributeNodes as $node) { if (isset($replacementList[$node->value])) { $node->value = $replacementList[$node->value]; } } foreach ($portableEntryNodes as $node) { $node->nodeValue = strtr(htmlentities($node->nodeValue, ENT_XML1), $replacementList); } foreach ($portableElementsToExport as $portableElementExporter){ $portableElementExporter->exportDom($dom); } } else { $report->setMessage($this->getExportErrorMessage(__('cannot load QTI XML'))); $report->setType(\common_report_Report::TYPE_ERROR); return $report; } if(($content = $dom->saveXML()) === false){ $report->setMessage($this->getExportErrorMessage(__('invalid QTI XML'))); $report->setType(\common_report_Report::TYPE_ERROR); } // Possibility to delegate (if necessary) some item content post-processing to sub-classes. $content = $this->itemContentPostProcessing($content); // add xml file $this->getZip()->addFromString($basePath . '/' . $dataFile, $content); if (! $report->getMessage()) { $report->setMessage(__('Item "%s" is ready to be exported', $this->getItem()->getLabel())); } ///return some useful data to the export report $report->setData(['portableAssets' => $portableAssets]); return $report; }
php
public function export($options = array()) { $report = \common_report_Report::createSuccess(); $asApip = isset($options['apip']) && $options['apip'] === true; $lang = \common_session_SessionManager::getSession()->getDataLanguage(); $basePath = $this->buildBasePath(); if(is_null($this->getItemModel())){ $report->setMessage($this->getExportErrorMessage(__('not a QTI item'))); $report->setType(\common_report_Report::TYPE_ERROR); return $report; } $dataFile = (string) $this->getItemModel()->getOnePropertyValue(new core_kernel_classes_Property(\taoItems_models_classes_ItemsService::TAO_ITEM_MODEL_DATAFILE_PROPERTY)); $resolver = new ItemMediaResolver($this->getItem(), $lang); $replacementList = array(); $portableElements = $this->getPortableElementAssets($this->getItem(), $lang); $service = new PortableElementService(); $service->setServiceLocator(ServiceManager::getServiceManager()); $portableElementsToExport = []; $portableAssets = []; foreach($portableElements as $element) { if (! $element instanceof Element) { continue; } try { $object = $service->getPortableObjectFromInstance($element); } catch (PortableElementException $e) { $message = __('Fail to export item') . ' (' . $this->getItem()->getLabel() . '): ' . $e->getMessage(); return \common_report_Report::createFailure($message); } $portableElementExporter = $object->getModel()->getExporter($object, $this); $portableElementsToExport[$element->getTypeIdentifier()] = $portableElementExporter; try { $portableAssets = array_merge($portableAssets, $portableElementExporter->copyAssetFiles($replacementList)); } catch (\tao_models_classes_FileNotFoundException $e) { \common_Logger::i($e->getMessage()); $report->setMessage('Missing portable element asset for "' . $object->getTypeIdentifier() . '"": ' . $e->getMessage()); $report->setType(\common_report_Report::TYPE_ERROR); } } $assets = $this->getAssets($this->getItem(), $lang); foreach ($assets as $assetUrl) { try{ $mediaAsset = $resolver->resolve($assetUrl); $mediaSource = $mediaAsset->getMediaSource(); if (!$mediaSource instanceof HttpSource) { $link = $mediaAsset->getMediaIdentifier(); $stream = $mediaSource->getFileStream($link); $baseName = ($mediaSource instanceof LocalItemSource) ? $link : 'assets/' . $mediaSource->getBaseName($link); $replacement = $this->copyAssetFile($stream, $basePath, $baseName, $replacementList); $replacementList[$assetUrl] = $replacement; } } catch(\tao_models_classes_FileNotFoundException $e){ $replacementList[$assetUrl] = ''; $report->setMessage('Missing resource for ' . $assetUrl); $report->setType(\common_report_Report::TYPE_ERROR); } } try{ $xml = Service::singleton()->getXmlByRdfItem($this->getItem()); }catch(FileNotFoundException $e){ $report->setMessage($this->getExportErrorMessage(__('cannot find QTI XML'))); $report->setType(\common_report_Report::TYPE_ERROR); return $report; } $dom = new DOMDocument('1.0', 'UTF-8'); $dom->preserveWhiteSpace = false; $dom->formatOutput = true; if ($dom->loadXML($xml) === true) { $xpath = new \DOMXPath($dom); $attributeNodes = $xpath->query('//@*'); $portableEntryNodes = $xpath->query("//*[local-name()='entry']|//*[local-name()='property']") ?: []; unset($xpath); foreach ($attributeNodes as $node) { if (isset($replacementList[$node->value])) { $node->value = $replacementList[$node->value]; } } foreach ($portableEntryNodes as $node) { $node->nodeValue = strtr(htmlentities($node->nodeValue, ENT_XML1), $replacementList); } foreach ($portableElementsToExport as $portableElementExporter){ $portableElementExporter->exportDom($dom); } } else { $report->setMessage($this->getExportErrorMessage(__('cannot load QTI XML'))); $report->setType(\common_report_Report::TYPE_ERROR); return $report; } if(($content = $dom->saveXML()) === false){ $report->setMessage($this->getExportErrorMessage(__('invalid QTI XML'))); $report->setType(\common_report_Report::TYPE_ERROR); } // Possibility to delegate (if necessary) some item content post-processing to sub-classes. $content = $this->itemContentPostProcessing($content); // add xml file $this->getZip()->addFromString($basePath . '/' . $dataFile, $content); if (! $report->getMessage()) { $report->setMessage(__('Item "%s" is ready to be exported', $this->getItem()->getLabel())); } ///return some useful data to the export report $report->setData(['portableAssets' => $portableAssets]); return $report; }
[ "public", "function", "export", "(", "$", "options", "=", "array", "(", ")", ")", "{", "$", "report", "=", "\\", "common_report_Report", "::", "createSuccess", "(", ")", ";", "$", "asApip", "=", "isset", "(", "$", "options", "[", "'apip'", "]", ")", ...
Overriden export from QTI items. @see taoItems_models_classes_ItemExporter::export() @param array $options An array of options. @return \common_report_Report @throws ExportException @throws \common_Exception @throws \common_exception_Error @throws \core_kernel_persistence_Exception @throws PortableElementInvalidAssetException
[ "Overriden", "export", "from", "QTI", "items", "." ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/Export/AbstractQTIItemExporter.php#L80-L202
oat-sa/extension-tao-itemqti
model/Export/AbstractQTIItemExporter.php
AbstractQTIItemExporter.getAssets
protected function getAssets(\core_kernel_classes_Resource $item, $lang) { $qtiItem = Service::singleton()->getDataItemByRdfItem($item, $lang); if (is_null($qtiItem)) { return []; } $assetParser = new AssetParser($qtiItem, $this->getStorageDirectory($item, $lang)); $assetParser->setGetSharedLibraries(false); $returnValue = array(); foreach ($assetParser->extract() as $type => $assets) { foreach ($assets as $assetUrl) { foreach (self::$BLACKLIST as $blacklist) { if (preg_match($blacklist, $assetUrl) === 1) { continue(2); } } $returnValue[] = $assetUrl; } } return $returnValue; }
php
protected function getAssets(\core_kernel_classes_Resource $item, $lang) { $qtiItem = Service::singleton()->getDataItemByRdfItem($item, $lang); if (is_null($qtiItem)) { return []; } $assetParser = new AssetParser($qtiItem, $this->getStorageDirectory($item, $lang)); $assetParser->setGetSharedLibraries(false); $returnValue = array(); foreach ($assetParser->extract() as $type => $assets) { foreach ($assets as $assetUrl) { foreach (self::$BLACKLIST as $blacklist) { if (preg_match($blacklist, $assetUrl) === 1) { continue(2); } } $returnValue[] = $assetUrl; } } return $returnValue; }
[ "protected", "function", "getAssets", "(", "\\", "core_kernel_classes_Resource", "$", "item", ",", "$", "lang", ")", "{", "$", "qtiItem", "=", "Service", "::", "singleton", "(", ")", "->", "getDataItemByRdfItem", "(", "$", "item", ",", "$", "lang", ")", ";...
Get the item's assets @param \core_kernel_classes_Resource $item The item @param string $lang The item lang @return string[] The assets URLs
[ "Get", "the", "item", "s", "assets" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/Export/AbstractQTIItemExporter.php#L243-L263
oat-sa/extension-tao-itemqti
model/Export/AbstractQTIItemExporter.php
AbstractQTIItemExporter.getStorageDirectory
protected function getStorageDirectory(\core_kernel_classes_Resource $item, $lang) { $itemService = \taoItems_models_classes_ItemsService::singleton(); $directory = $itemService->getItemDirectory($item, $lang); //we should use be language unaware for storage manipulation $path = str_replace($lang, '', $directory->getPrefix()); return $itemService->getDefaultItemDirectory()->getDirectory($path); }
php
protected function getStorageDirectory(\core_kernel_classes_Resource $item, $lang) { $itemService = \taoItems_models_classes_ItemsService::singleton(); $directory = $itemService->getItemDirectory($item, $lang); //we should use be language unaware for storage manipulation $path = str_replace($lang, '', $directory->getPrefix()); return $itemService->getDefaultItemDirectory()->getDirectory($path); }
[ "protected", "function", "getStorageDirectory", "(", "\\", "core_kernel_classes_Resource", "$", "item", ",", "$", "lang", ")", "{", "$", "itemService", "=", "\\", "taoItems_models_classes_ItemsService", "::", "singleton", "(", ")", ";", "$", "directory", "=", "$",...
Get the item's directory @param \core_kernel_classes_Resource $item The item @param string $lang The item lang @return Directory The directory
[ "Get", "the", "item", "s", "directory" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/Export/AbstractQTIItemExporter.php#L285-L293
oat-sa/extension-tao-itemqti
model/Export/AbstractQTIItemExporter.php
AbstractQTIItemExporter.getMetadataExporter
protected function getMetadataExporter() { if (! $this->metadataExporter) { $this->metadataExporter = $this->getServiceManager()->get(MetadataService::SERVICE_ID)->getExporter(); } return $this->metadataExporter; }
php
protected function getMetadataExporter() { if (! $this->metadataExporter) { $this->metadataExporter = $this->getServiceManager()->get(MetadataService::SERVICE_ID)->getExporter(); } return $this->metadataExporter; }
[ "protected", "function", "getMetadataExporter", "(", ")", "{", "if", "(", "!", "$", "this", "->", "metadataExporter", ")", "{", "$", "this", "->", "metadataExporter", "=", "$", "this", "->", "getServiceManager", "(", ")", "->", "get", "(", "MetadataService",...
Get the service to export Metadata @return MetadataExporter
[ "Get", "the", "service", "to", "export", "Metadata" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/Export/AbstractQTIItemExporter.php#L305-L311
oat-sa/extension-tao-itemqti
model/qti/response/ResponseRuleParserFactory.php
ResponseRuleParserFactory.buildResponseRule
public static function buildResponseRule( SimpleXMLElement $data) { $returnValue = null; switch ($data->getName()) { case 'exitResponse' : $returnValue = new ExitResponse(); break; case 'setOutcomeValue' : $identifier = (string)$data['identifier']; $children = array(); foreach ($data->children() as $child){ $children[] = $child; } $expression = ExpressionParserFactory::build(array_shift($children)); $returnValue = new SetOutcomeVariable($identifier, $expression); break; case 'responseCondition' : $returnValue = self::buildResponseCondition($data); break; default : throw new ParsingException('unknwown element '.$data->getName().' in ResponseProcessing'); } return $returnValue; }
php
public static function buildResponseRule( SimpleXMLElement $data) { $returnValue = null; switch ($data->getName()) { case 'exitResponse' : $returnValue = new ExitResponse(); break; case 'setOutcomeValue' : $identifier = (string)$data['identifier']; $children = array(); foreach ($data->children() as $child){ $children[] = $child; } $expression = ExpressionParserFactory::build(array_shift($children)); $returnValue = new SetOutcomeVariable($identifier, $expression); break; case 'responseCondition' : $returnValue = self::buildResponseCondition($data); break; default : throw new ParsingException('unknwown element '.$data->getName().' in ResponseProcessing'); } return $returnValue; }
[ "public", "static", "function", "buildResponseRule", "(", "SimpleXMLElement", "$", "data", ")", "{", "$", "returnValue", "=", "null", ";", "switch", "(", "$", "data", "->", "getName", "(", ")", ")", "{", "case", "'exitResponse'", ":", "$", "returnValue", "...
Short description of method buildResponseRule @access public @author Joel Bout, <joel.bout@tudor.lu> @param SimpleXMLElement data @return oat\taoQtiItem\model\qti\response\ResponseRule
[ "Short", "description", "of", "method", "buildResponseRule" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/response/ResponseRuleParserFactory.php#L51-L75
oat-sa/extension-tao-itemqti
model/qti/response/ResponseRuleParserFactory.php
ResponseRuleParserFactory.buildResponseCondition
private static function buildResponseCondition( SimpleXMLElement $data) { $responseCondition = new ResponseCondition(); foreach ($data->children() as $child) { switch ($child->getName()) { case 'responseIf' : case 'responseElseIf' : $subchildren = null; foreach ($child->children() as $subchild){ $subchildren[] = $subchild; } // first node is condition $conditionNode = array_shift($subchildren); $condition = ExpressionParserFactory::build($conditionNode); // all the other nodes are action $responseRules = array(); foreach ($subchildren as $responseRule){ $responseRules[] = self::buildResponseRule($responseRule); } $responseCondition->addResponseIf($condition, $responseRules); break; case 'responseElse' : $responseRules = array(); foreach ($child->children() as $responseRule) { $responseRules[] = self::buildResponseRule($responseRule); } $responseCondition->setResponseElse($responseRules); break; default: throw new ParsingException('unknown node in ResponseCondition'); } } $returnValue = $responseCondition; return $returnValue; }
php
private static function buildResponseCondition( SimpleXMLElement $data) { $responseCondition = new ResponseCondition(); foreach ($data->children() as $child) { switch ($child->getName()) { case 'responseIf' : case 'responseElseIf' : $subchildren = null; foreach ($child->children() as $subchild){ $subchildren[] = $subchild; } // first node is condition $conditionNode = array_shift($subchildren); $condition = ExpressionParserFactory::build($conditionNode); // all the other nodes are action $responseRules = array(); foreach ($subchildren as $responseRule){ $responseRules[] = self::buildResponseRule($responseRule); } $responseCondition->addResponseIf($condition, $responseRules); break; case 'responseElse' : $responseRules = array(); foreach ($child->children() as $responseRule) { $responseRules[] = self::buildResponseRule($responseRule); } $responseCondition->setResponseElse($responseRules); break; default: throw new ParsingException('unknown node in ResponseCondition'); } } $returnValue = $responseCondition; return $returnValue; }
[ "private", "static", "function", "buildResponseCondition", "(", "SimpleXMLElement", "$", "data", ")", "{", "$", "responseCondition", "=", "new", "ResponseCondition", "(", ")", ";", "foreach", "(", "$", "data", "->", "children", "(", ")", "as", "$", "child", ...
Short description of method buildResponseCondition @access private @author Joel Bout, <joel.bout@tudor.lu> @param SimpleXMLElement data @return oat\taoQtiItem\model\qti\response\ResponseCondition
[ "Short", "description", "of", "method", "buildResponseCondition" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/response/ResponseRuleParserFactory.php#L85-L127
oat-sa/extension-tao-itemqti
model/Export/Extractor/OntologyExtractorRunner.php
OntologyExtractorRunner.run
public static function run(core_kernel_classes_Resource $item, core_kernel_classes_Property $classProperty) { $itemProperty = $item->getProperty($classProperty->getUri()); $labelItemProperty = $itemProperty->getLabel(); $extractor = new OntologyExtractor(); $extractor->addColumn($labelItemProperty, ['property' => $classProperty->getUri()]); $extractor->setItem($item); $extractor->run(); $data = $extractor->getData(); return new HashEntry($labelItemProperty, $data[$labelItemProperty]); }
php
public static function run(core_kernel_classes_Resource $item, core_kernel_classes_Property $classProperty) { $itemProperty = $item->getProperty($classProperty->getUri()); $labelItemProperty = $itemProperty->getLabel(); $extractor = new OntologyExtractor(); $extractor->addColumn($labelItemProperty, ['property' => $classProperty->getUri()]); $extractor->setItem($item); $extractor->run(); $data = $extractor->getData(); return new HashEntry($labelItemProperty, $data[$labelItemProperty]); }
[ "public", "static", "function", "run", "(", "core_kernel_classes_Resource", "$", "item", ",", "core_kernel_classes_Property", "$", "classProperty", ")", "{", "$", "itemProperty", "=", "$", "item", "->", "getProperty", "(", "$", "classProperty", "->", "getUri", "("...
@param core_kernel_classes_Resource $item @param core_kernel_classes_Property $classProperty @return HashEntry @throws \oat\taoQtiItem\model\flyExporter\extractor\ExtractorException @throws \Exception
[ "@param", "core_kernel_classes_Resource", "$item", "@param", "core_kernel_classes_Property", "$classProperty" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/Export/Extractor/OntologyExtractorRunner.php#L38-L50
oat-sa/extension-tao-itemqti
model/qti/response/interactionResponseProcessing/None.php
None.getRule
public function getRule() { $returnValue = (string) ''; $returnValue = 'if(isNull(null, getResponse("'.$this->getResponse()->getIdentifier().'"))) { '. 'setOutcomeValue("'.$this->getOutcome()->getIdentifier().'", '.$this->getDefaultValue().'); };'; return (string) $returnValue; }
php
public function getRule() { $returnValue = (string) ''; $returnValue = 'if(isNull(null, getResponse("'.$this->getResponse()->getIdentifier().'"))) { '. 'setOutcomeValue("'.$this->getOutcome()->getIdentifier().'", '.$this->getDefaultValue().'); };'; 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/None.php#L100-L110
oat-sa/extension-tao-itemqti
model/qti/response/interactionResponseProcessing/None.php
None.toQTI
public function toQTI() { $returnValue = (string) ''; $returnValue = '<responseCondition> <responseIf> <isNull> <variable identifier="'.$this->getResponse()->getIdentifier().'" /> </isNull> <setOutcomeValue identifier="'.$this->getOutcome()->getIdentifier().'"> <baseValue baseType="'.$this->getOutcome()->getAttributeValue('baseType').'">0</baseValue> </setOutcomeValue> </responseIf> </responseCondition>'; return (string) $returnValue; }
php
public function toQTI() { $returnValue = (string) ''; $returnValue = '<responseCondition> <responseIf> <isNull> <variable identifier="'.$this->getResponse()->getIdentifier().'" /> </isNull> <setOutcomeValue identifier="'.$this->getOutcome()->getIdentifier().'"> <baseValue baseType="'.$this->getOutcome()->getAttributeValue('baseType').'">0</baseValue> </setOutcomeValue> </responseIf> </responseCondition>'; return (string) $returnValue; }
[ "public", "function", "toQTI", "(", ")", "{", "$", "returnValue", "=", "(", "string", ")", "''", ";", "$", "returnValue", "=", "'<responseCondition>\n\t\t <responseIf>\n\t <isNull>\n\t <variable identifier=\"'", ".", "$", "this", "->", "getRes...
although no ResponseRules are nescessary to have no responseProcessing, add some rules to associate the interaction response with a sepcific @access public @author Joel Bout, <joel.bout@tudor.lu> @return string
[ "although", "no", "ResponseRules", "are", "nescessary", "to", "have", "no", "responseProcessing", "add", "some", "rules", "to", "associate", "the", "interaction", "response", "with", "a", "sepcific" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/response/interactionResponseProcessing/None.php#L120-L138
oat-sa/extension-tao-itemqti
model/QtiCreatorClientConfigRegistry.php
QtiCreatorClientConfigRegistry.getPlugins
public function getPlugins(){ $config = []; $registry = self::getRegistry(); if ($registry->isRegistered(self::CREATOR)) { $config = $registry->get(self::CREATOR); } if (!isset($config['plugins'])) { return []; } return $config['plugins']; }
php
public function getPlugins(){ $config = []; $registry = self::getRegistry(); if ($registry->isRegistered(self::CREATOR)) { $config = $registry->get(self::CREATOR); } if (!isset($config['plugins'])) { return []; } return $config['plugins']; }
[ "public", "function", "getPlugins", "(", ")", "{", "$", "config", "=", "[", "]", ";", "$", "registry", "=", "self", "::", "getRegistry", "(", ")", ";", "if", "(", "$", "registry", "->", "isRegistered", "(", "self", "::", "CREATOR", ")", ")", "{", "...
Quick access to the plugins @return array the registered plugins
[ "Quick", "access", "to", "the", "plugins" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/QtiCreatorClientConfigRegistry.php#L123-L136
oat-sa/extension-tao-itemqti
model/flyExporter/extractor/OntologyExtractor.php
OntologyExtractor.addColumn
public function addColumn($column, array $config) { if (!isset($config['property'])) { throw new ExtractorException('Property config is missing.'); } $property = new \core_kernel_classes_Property($config['property']); if (!$property->exists()) { throw new ExtractorException('Property config is not a valid property uri.'); } $config['property'] = $property; $this->columns[$column] = $config; return $this; }
php
public function addColumn($column, array $config) { if (!isset($config['property'])) { throw new ExtractorException('Property config is missing.'); } $property = new \core_kernel_classes_Property($config['property']); if (!$property->exists()) { throw new ExtractorException('Property config is not a valid property uri.'); } $config['property'] = $property; $this->columns[$column] = $config; return $this; }
[ "public", "function", "addColumn", "(", "$", "column", ",", "array", "$", "config", ")", "{", "if", "(", "!", "isset", "(", "$", "config", "[", "'property'", "]", ")", ")", "{", "throw", "new", "ExtractorException", "(", "'Property config is missing.'", ")...
Add column to export Check if core_kernel_classes_Property exists into $config @param $column @param array $config @throws ExtractorException @return Extractor $this
[ "Add", "column", "to", "export", "Check", "if", "core_kernel_classes_Property", "exists", "into", "$config" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/flyExporter/extractor/OntologyExtractor.php#L70-L84
oat-sa/extension-tao-itemqti
model/flyExporter/extractor/OntologyExtractor.php
OntologyExtractor.run
public function run() { $this->data = []; if (empty($this->item) || !($this->item instanceof \core_kernel_classes_Resource)) { throw new ExtractorException('Export item not set.'); } $properties = []; foreach ($this->columns as $config) { $properties[] = $config['property']; } $values = $this->item->getPropertiesValues($properties); foreach ($this->columns as $column => $config) { try { $data = []; foreach ($values[$config['property']->getUri()] as $itemValue) { if (is_array($itemValue)) { array_walk($itemValue, function (&$value) { $resource = new \core_kernel_classes_Resource($value); $value = $resource->getLabel(); }); if (isset($config['delimiter'])) { $delimiter = $config['delimiter']; } else { $delimiter = self::DEFAULT_PROPERTY_DELIMITER; } $data[] = explode($delimiter, $itemValue); continue; } $data[] = ($itemValue instanceof \core_kernel_classes_Resource)? $itemValue->getLabel() : (string)$itemValue; } } catch (\Exception $e) { \common_Logger::e('ERROR on column ' . $column . ' : ' . $e->getMessage()); $data = ['N/A']; } $this->data[$column] = implode(self::DEFAULT_PROPERTY_DELIMITER, $data); } $this->columns = []; return $this; }
php
public function run() { $this->data = []; if (empty($this->item) || !($this->item instanceof \core_kernel_classes_Resource)) { throw new ExtractorException('Export item not set.'); } $properties = []; foreach ($this->columns as $config) { $properties[] = $config['property']; } $values = $this->item->getPropertiesValues($properties); foreach ($this->columns as $column => $config) { try { $data = []; foreach ($values[$config['property']->getUri()] as $itemValue) { if (is_array($itemValue)) { array_walk($itemValue, function (&$value) { $resource = new \core_kernel_classes_Resource($value); $value = $resource->getLabel(); }); if (isset($config['delimiter'])) { $delimiter = $config['delimiter']; } else { $delimiter = self::DEFAULT_PROPERTY_DELIMITER; } $data[] = explode($delimiter, $itemValue); continue; } $data[] = ($itemValue instanceof \core_kernel_classes_Resource)? $itemValue->getLabel() : (string)$itemValue; } } catch (\Exception $e) { \common_Logger::e('ERROR on column ' . $column . ' : ' . $e->getMessage()); $data = ['N/A']; } $this->data[$column] = implode(self::DEFAULT_PROPERTY_DELIMITER, $data); } $this->columns = []; return $this; }
[ "public", "function", "run", "(", ")", "{", "$", "this", "->", "data", "=", "[", "]", ";", "if", "(", "empty", "(", "$", "this", "->", "item", ")", "||", "!", "(", "$", "this", "->", "item", "instanceof", "\\", "core_kernel_classes_Resource", ")", ...
Get ontology values of requested item properties @return $this @throws \Exception
[ "Get", "ontology", "values", "of", "requested", "item", "properties" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/flyExporter/extractor/OntologyExtractor.php#L92-L136
oat-sa/extension-tao-itemqti
model/portableElement/parser/element/PortableElementPackageParser.php
PortableElementPackageParser.validate
public function validate($source) { try { $this->assertSourceAsFile($source); if (! QtiPackage::isValidZip($source)) { throw new PortableElementParserException('Source package is not a valid zip.'); } } catch (common_Exception $e) { throw new PortableElementParserException('A problem has occured during package parsing.', 0, $e); } $zip = new ZipArchive(); $zip->open($source, ZIPARCHIVE::CHECKCONS); $definitionFiles = $this->getModel()->getDefinitionFiles(); foreach ($definitionFiles as $file) { if ($zip->locateName($file) === false) { throw new PortableElementParserException( 'The portable element package "' .$this->getModel()->getId(). '" must contains a "' . $file . '" file at the root of the archive.' ); } } $zip->close(); $this->getModel()->createDataObject($this->getManifestContent($source)); return true; }
php
public function validate($source) { try { $this->assertSourceAsFile($source); if (! QtiPackage::isValidZip($source)) { throw new PortableElementParserException('Source package is not a valid zip.'); } } catch (common_Exception $e) { throw new PortableElementParserException('A problem has occured during package parsing.', 0, $e); } $zip = new ZipArchive(); $zip->open($source, ZIPARCHIVE::CHECKCONS); $definitionFiles = $this->getModel()->getDefinitionFiles(); foreach ($definitionFiles as $file) { if ($zip->locateName($file) === false) { throw new PortableElementParserException( 'The portable element package "' .$this->getModel()->getId(). '" must contains a "' . $file . '" file at the root of the archive.' ); } } $zip->close(); $this->getModel()->createDataObject($this->getManifestContent($source)); return true; }
[ "public", "function", "validate", "(", "$", "source", ")", "{", "try", "{", "$", "this", "->", "assertSourceAsFile", "(", "$", "source", ")", ";", "if", "(", "!", "QtiPackage", "::", "isValidZip", "(", "$", "source", ")", ")", "{", "throw", "new", "P...
Validate the zip package @param string $source Zip package location to validate @return bool @throws PortableElementException @throws PortableElementParserException @throws PortableElementInconsistencyModelException
[ "Validate", "the", "zip", "package" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/parser/element/PortableElementPackageParser.php#L53-L81
oat-sa/extension-tao-itemqti
model/portableElement/parser/element/PortableElementPackageParser.php
PortableElementPackageParser.extract
public function extract($source) { $tmpDirectory = null; $this->assertSourceAsFile($source); $folder = \tao_helpers_File::createTempDir(); $zip = new ZipArchive(); if ($zip->open($source) === true) { if (\tao_helpers_File::checkWhetherArchiveIsBomb($zip)) { throw new PortableElementExtractException(sprintf('Source %s seems to be a ZIP bomb', $source)); } if($zip->extractTo($folder)){ $tmpDirectory = $folder; } $zip->close(); } if (! is_dir($tmpDirectory)) { throw new PortableElementExtractException('Unable to extract portable element.'); } return $tmpDirectory; }
php
public function extract($source) { $tmpDirectory = null; $this->assertSourceAsFile($source); $folder = \tao_helpers_File::createTempDir(); $zip = new ZipArchive(); if ($zip->open($source) === true) { if (\tao_helpers_File::checkWhetherArchiveIsBomb($zip)) { throw new PortableElementExtractException(sprintf('Source %s seems to be a ZIP bomb', $source)); } if($zip->extractTo($folder)){ $tmpDirectory = $folder; } $zip->close(); } if (! is_dir($tmpDirectory)) { throw new PortableElementExtractException('Unable to extract portable element.'); } return $tmpDirectory; }
[ "public", "function", "extract", "(", "$", "source", ")", "{", "$", "tmpDirectory", "=", "null", ";", "$", "this", "->", "assertSourceAsFile", "(", "$", "source", ")", ";", "$", "folder", "=", "\\", "tao_helpers_File", "::", "createTempDir", "(", ")", ";...
Extract zip package into temp directory @param string $source Zip path @return string Tmp directory to find extracted zip @throws PortableElementExtractException @throws common_Exception
[ "Extract", "zip", "package", "into", "temp", "directory" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/parser/element/PortableElementPackageParser.php#L91-L113
oat-sa/extension-tao-itemqti
model/portableElement/parser/element/PortableElementPackageParser.php
PortableElementPackageParser.getManifestContent
public function getManifestContent($source) { $zip = new ZipArchive(); if($zip->open($source) === false ) { throw new PortableElementParserException('Unable to open the ZIP file located at: ' . $source); } $manifestName = $this->getModel()->getManifestName(); if ($zip->locateName($manifestName) === false) { throw new PortableElementParserException( 'ZIP package does not have a manifest at root path: ' . $this->getModel()->getManifestName() ); } $content = $zip->getFromName($manifestName); if (! $content) { throw new PortableElementParserException('Manifest file "' . $manifestName. '" found but not readable.'); } $content = json_decode($content, true); if (json_last_error() === JSON_ERROR_NONE) { return $content; } throw new PortableElementException('Portable element manifest is not a valid json file.'); }
php
public function getManifestContent($source) { $zip = new ZipArchive(); if($zip->open($source) === false ) { throw new PortableElementParserException('Unable to open the ZIP file located at: ' . $source); } $manifestName = $this->getModel()->getManifestName(); if ($zip->locateName($manifestName) === false) { throw new PortableElementParserException( 'ZIP package does not have a manifest at root path: ' . $this->getModel()->getManifestName() ); } $content = $zip->getFromName($manifestName); if (! $content) { throw new PortableElementParserException('Manifest file "' . $manifestName. '" found but not readable.'); } $content = json_decode($content, true); if (json_last_error() === JSON_ERROR_NONE) { return $content; } throw new PortableElementException('Portable element manifest is not a valid json file.'); }
[ "public", "function", "getManifestContent", "(", "$", "source", ")", "{", "$", "zip", "=", "new", "ZipArchive", "(", ")", ";", "if", "(", "$", "zip", "->", "open", "(", "$", "source", ")", "===", "false", ")", "{", "throw", "new", "PortableElementParse...
Extract JSON representation of $source package e.q. Manifest @param string $source Zip path @return string JSON representation of $this->source @throws PortableElementException @throws PortableElementParserException
[ "Extract", "JSON", "representation", "of", "$source", "package", "e", ".", "q", ".", "Manifest" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/parser/element/PortableElementPackageParser.php#L123-L149
oat-sa/extension-tao-itemqti
model/qti/expression/ExpressionParserFactory.php
ExpressionParserFactory.build
public static function build( SimpleXMLElement $data) { $returnValue = null; $expression = null; $expressionName = $data->getName(); //retrieve the expression attributes $attributes = array(); foreach($data->attributes() as $key => $value){ $attributes[$key] = (string)$value; } // Create expression function of its type (If specialization has been done for the expression type) $expressionClass = 'oat\\taoQtiItem\\model\\qti\\expression\\'.ucfirst($expressionName); if (class_exists($expressionClass)){ $expression = new $expressionClass ($expressionName, $attributes); } else { $expression = new CommonExpression ($expressionName, $attributes); } // If the expression has a value $expressionValue = (string) trim($data); if ($expressionValue != ''){ $expression->setValue($expressionValue); } // All sub-expressions of an expression are embedded by this expression $subExpressions = array(); foreach ($data->children() as $subExpressionNode) { $subExpressions[] = self::build($subExpressionNode); } $expression->setSubExpressions($subExpressions); $returnValue = $expression; return $returnValue; }
php
public static function build( SimpleXMLElement $data) { $returnValue = null; $expression = null; $expressionName = $data->getName(); //retrieve the expression attributes $attributes = array(); foreach($data->attributes() as $key => $value){ $attributes[$key] = (string)$value; } // Create expression function of its type (If specialization has been done for the expression type) $expressionClass = 'oat\\taoQtiItem\\model\\qti\\expression\\'.ucfirst($expressionName); if (class_exists($expressionClass)){ $expression = new $expressionClass ($expressionName, $attributes); } else { $expression = new CommonExpression ($expressionName, $attributes); } // If the expression has a value $expressionValue = (string) trim($data); if ($expressionValue != ''){ $expression->setValue($expressionValue); } // All sub-expressions of an expression are embedded by this expression $subExpressions = array(); foreach ($data->children() as $subExpressionNode) { $subExpressions[] = self::build($subExpressionNode); } $expression->setSubExpressions($subExpressions); $returnValue = $expression; return $returnValue; }
[ "public", "static", "function", "build", "(", "SimpleXMLElement", "$", "data", ")", "{", "$", "returnValue", "=", "null", ";", "$", "expression", "=", "null", ";", "$", "expressionName", "=", "$", "data", "->", "getName", "(", ")", ";", "//retrieve the exp...
Short description of method build @access public @author Joel Bout, <joel.bout@tudor.lu> @param SimpleXMLElement data @return oat\taoQtiItem\model\qti\expression\Expression
[ "Short", "description", "of", "method", "build" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/expression/ExpressionParserFactory.php#L52-L94
oat-sa/extension-tao-itemqti
model/qti/Tooltip.php
Tooltip.getTemplateQtiVariables
protected function getTemplateQtiVariables(){ // this is necessary because the QTI template gets a serialized string for attributes and cannot address a specific attribute $tooltipId = $this->getAttributeValue('aria-describedby'); $variables = parent::getTemplateQtiVariables(); $variables['tooltipId'] = $tooltipId; $variables['content'] = (string) $this->getContent(); return $variables; }
php
protected function getTemplateQtiVariables(){ // this is necessary because the QTI template gets a serialized string for attributes and cannot address a specific attribute $tooltipId = $this->getAttributeValue('aria-describedby'); $variables = parent::getTemplateQtiVariables(); $variables['tooltipId'] = $tooltipId; $variables['content'] = (string) $this->getContent(); return $variables; }
[ "protected", "function", "getTemplateQtiVariables", "(", ")", "{", "// this is necessary because the QTI template gets a serialized string for attributes and cannot address a specific attribute", "$", "tooltipId", "=", "$", "this", "->", "getAttributeValue", "(", "'aria-describedby'", ...
Add tooltip id & content to template variables
[ "Add", "tooltip", "id", "&", "content", "to", "template", "variables" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/Tooltip.php#L69-L77
oat-sa/extension-tao-itemqti
model/qti/Value.php
Value.toArray
public function toArray($filterVariableContent = false, &$filtered = array()) { return [ 'value' => $this->value, 'fieldIdentifier' => (string) $this->getAttribute('fieldIdentifier'), 'baseType' => (string) $this->getAttribute('baseType'), 'cardinality' => 'single'//cardinality always single for value, put it here to make it compatible with the rule engine ]; }
php
public function toArray($filterVariableContent = false, &$filtered = array()) { return [ 'value' => $this->value, 'fieldIdentifier' => (string) $this->getAttribute('fieldIdentifier'), 'baseType' => (string) $this->getAttribute('baseType'), 'cardinality' => 'single'//cardinality always single for value, put it here to make it compatible with the rule engine ]; }
[ "public", "function", "toArray", "(", "$", "filterVariableContent", "=", "false", ",", "&", "$", "filtered", "=", "array", "(", ")", ")", "{", "return", "[", "'value'", "=>", "$", "this", "->", "value", ",", "'fieldIdentifier'", "=>", "(", "string", ")",...
Get the array representation of the Qti Element. Particularly helpful for data transformation, e.g. json @param bool $filterVariableContent @param array $filtered @return array
[ "Get", "the", "array", "representation", "of", "the", "Qti", "Element", ".", "Particularly", "helpful", "for", "data", "transformation", "e", ".", "g", ".", "json" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/Value.php#L88-L96
oat-sa/extension-tao-itemqti
controller/AbstractPortableElementManager.php
AbstractPortableElementManager.getFile
public function getFile() { if ($this->hasRequestParameter('file')) { $file = urldecode($this->getRequestParameter('file')); $filePathTokens = explode('/', $file); $typeIdentifier = array_shift($filePathTokens); $relPath = implode(DIRECTORY_SEPARATOR, $filePathTokens); $this->renderFile($typeIdentifier, $relPath); } }
php
public function getFile() { if ($this->hasRequestParameter('file')) { $file = urldecode($this->getRequestParameter('file')); $filePathTokens = explode('/', $file); $typeIdentifier = array_shift($filePathTokens); $relPath = implode(DIRECTORY_SEPARATOR, $filePathTokens); $this->renderFile($typeIdentifier, $relPath); } }
[ "public", "function", "getFile", "(", ")", "{", "if", "(", "$", "this", "->", "hasRequestParameter", "(", "'file'", ")", ")", "{", "$", "file", "=", "urldecode", "(", "$", "this", "->", "getRequestParameter", "(", "'file'", ")", ")", ";", "$", "filePat...
Get a file of a custom interaction
[ "Get", "a", "file", "of", "a", "custom", "interaction" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/controller/AbstractPortableElementManager.php#L57-L66
oat-sa/extension-tao-itemqti
controller/AbstractPortableElementManager.php
AbstractPortableElementManager.renderFile
private function renderFile($typeIdentifier, $relPath) { if (tao_helpers_File::securityCheck($relPath, true)) { $folder = $this->getImplementationDirectory($typeIdentifier); $filename = $folder.$relPath; //@todo : find better way to to this //load amd module if (! file_exists($filename) && file_exists($filename.'.js')) { $filename = $filename.'.js'; } tao_helpers_Http::returnFile($filename); } else { throw new common_exception_Error('invalid item preview file path'); } }
php
private function renderFile($typeIdentifier, $relPath) { if (tao_helpers_File::securityCheck($relPath, true)) { $folder = $this->getImplementationDirectory($typeIdentifier); $filename = $folder.$relPath; //@todo : find better way to to this //load amd module if (! file_exists($filename) && file_exists($filename.'.js')) { $filename = $filename.'.js'; } tao_helpers_Http::returnFile($filename); } else { throw new common_exception_Error('invalid item preview file path'); } }
[ "private", "function", "renderFile", "(", "$", "typeIdentifier", ",", "$", "relPath", ")", "{", "if", "(", "tao_helpers_File", "::", "securityCheck", "(", "$", "relPath", ",", "true", ")", ")", "{", "$", "folder", "=", "$", "this", "->", "getImplementation...
Render the file to the browser @param string $typeIdentifier @param string $relPath @throws common_exception_Error
[ "Render", "the", "file", "to", "the", "browser" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/controller/AbstractPortableElementManager.php#L86-L101
oat-sa/extension-tao-itemqti
model/qti/PackageParser.php
PackageParser.validate
public function validate($schema = '') { $forced = $this->valid; $this->valid = true; try{ switch($this->sourceType){ case self::SOURCE_FILE: //check file if(!file_exists($this->source)){ throw new Exception("File {$this->source} not found."); } if(!is_readable($this->source)){ throw new Exception("Unable to read file {$this->source}."); } if(!preg_match("/\.zip$/", basename($this->source))){ throw new Exception("Wrong file extension in {$this->source}, zip extension is expected"); } if(!tao_helpers_File::securityCheck($this->source)){ throw new Exception("{$this->source} seems to contain some security issues"); } break; case self::SOURCE_FLYFILE: //check file if (!$this->source->exists()) { throw new Exception("File {$this->source->getBasename()} not found."); } if (!preg_match("/\.zip$/", $this->source->getBasename())) { throw new Exception("Wrong file extension in {$this->source->getBasename()}, zip extension is expected"); } $this->extract(); break; default: throw new Exception("Only regular files are allowed as package source"); break; } } catch(Exception $e){ if($forced){ throw $e; } else{ $this->addError($e); } } if($this->valid && !$forced){ //valida can be true if forceValidation has been called $this->valid = false; try{ $zip = new ZipArchive(); //check the archive opening and the consistency $res = $zip->open($this->source, ZIPARCHIVE::CHECKCONS); if( $res !== true){ switch($res) { case ZipArchive::ER_NOZIP : $msg = 'not a zip archive'; break; case ZipArchive::ER_INCONS : $msg ='consistency check failed'; break; case ZipArchive::ER_CRC : $msg = 'checksum failed'; break; default: $msg ='Bad Zip file'; } throw new Exception($msg); } else{ //check if the manifest is there if($zip->locateName("imsmanifest.xml") === false){ throw new Exception("A QTI package must contains a imsmanifest.xml file at the root of the archive"); } $this->valid = true; } $zip->close(); } catch(Exception $e){ $this->addError($e); } } $returnValue = $this->valid; return (bool) $returnValue; }
php
public function validate($schema = '') { $forced = $this->valid; $this->valid = true; try{ switch($this->sourceType){ case self::SOURCE_FILE: //check file if(!file_exists($this->source)){ throw new Exception("File {$this->source} not found."); } if(!is_readable($this->source)){ throw new Exception("Unable to read file {$this->source}."); } if(!preg_match("/\.zip$/", basename($this->source))){ throw new Exception("Wrong file extension in {$this->source}, zip extension is expected"); } if(!tao_helpers_File::securityCheck($this->source)){ throw new Exception("{$this->source} seems to contain some security issues"); } break; case self::SOURCE_FLYFILE: //check file if (!$this->source->exists()) { throw new Exception("File {$this->source->getBasename()} not found."); } if (!preg_match("/\.zip$/", $this->source->getBasename())) { throw new Exception("Wrong file extension in {$this->source->getBasename()}, zip extension is expected"); } $this->extract(); break; default: throw new Exception("Only regular files are allowed as package source"); break; } } catch(Exception $e){ if($forced){ throw $e; } else{ $this->addError($e); } } if($this->valid && !$forced){ //valida can be true if forceValidation has been called $this->valid = false; try{ $zip = new ZipArchive(); //check the archive opening and the consistency $res = $zip->open($this->source, ZIPARCHIVE::CHECKCONS); if( $res !== true){ switch($res) { case ZipArchive::ER_NOZIP : $msg = 'not a zip archive'; break; case ZipArchive::ER_INCONS : $msg ='consistency check failed'; break; case ZipArchive::ER_CRC : $msg = 'checksum failed'; break; default: $msg ='Bad Zip file'; } throw new Exception($msg); } else{ //check if the manifest is there if($zip->locateName("imsmanifest.xml") === false){ throw new Exception("A QTI package must contains a imsmanifest.xml file at the root of the archive"); } $this->valid = true; } $zip->close(); } catch(Exception $e){ $this->addError($e); } } $returnValue = $this->valid; return (bool) $returnValue; }
[ "public", "function", "validate", "(", "$", "schema", "=", "''", ")", "{", "$", "forced", "=", "$", "this", "->", "valid", ";", "$", "this", "->", "valid", "=", "true", ";", "try", "{", "switch", "(", "$", "this", "->", "sourceType", ")", "{", "c...
Short description of method validate @access public @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> @param string schema @throws Exception if file or archive is not valid @return boolean
[ "Short", "description", "of", "method", "validate" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/PackageParser.php#L56-L146
oat-sa/extension-tao-itemqti
model/qti/PackageParser.php
PackageParser.extract
public function extract() { if ($this->extracted === null) { if ($this->source instanceof File) { $archiveFolder = tao_helpers_File::createTempDir(); if (!is_dir($archiveFolder)) { mkdir($archiveFolder); } $filename = $archiveFolder . basename($this->source->getPrefix()); file_put_contents($filename, $this->source->read()); $this->source = $filename; } if(!is_file($this->source)){ //ultimate verification throw new common_exception_Error("source ".$this->source." not a file"); } $folder = tao_helpers_File::createTempDir(); if (!is_dir($folder)) { mkdir($folder); } $zip = new ZipArchive(); if ($zip->open($this->source) === true) { if (tao_helpers_File::checkWhetherArchiveIsBomb($zip)) { throw new common_exception_Error(sprintf('Source %s seems to be a ZIP bomb', $this->source)); } if($zip->extractTo($folder)){ $this->extracted = $folder; } $zip->close(); } } return (string) $this->extracted; }
php
public function extract() { if ($this->extracted === null) { if ($this->source instanceof File) { $archiveFolder = tao_helpers_File::createTempDir(); if (!is_dir($archiveFolder)) { mkdir($archiveFolder); } $filename = $archiveFolder . basename($this->source->getPrefix()); file_put_contents($filename, $this->source->read()); $this->source = $filename; } if(!is_file($this->source)){ //ultimate verification throw new common_exception_Error("source ".$this->source." not a file"); } $folder = tao_helpers_File::createTempDir(); if (!is_dir($folder)) { mkdir($folder); } $zip = new ZipArchive(); if ($zip->open($this->source) === true) { if (tao_helpers_File::checkWhetherArchiveIsBomb($zip)) { throw new common_exception_Error(sprintf('Source %s seems to be a ZIP bomb', $this->source)); } if($zip->extractTo($folder)){ $this->extracted = $folder; } $zip->close(); } } return (string) $this->extracted; }
[ "public", "function", "extract", "(", ")", "{", "if", "(", "$", "this", "->", "extracted", "===", "null", ")", "{", "if", "(", "$", "this", "->", "source", "instanceof", "File", ")", "{", "$", "archiveFolder", "=", "tao_helpers_File", "::", "createTempDi...
Short description of method extract @access public @throws \common_exception_Error @throws \common_exception @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> @return string|null
[ "Short", "description", "of", "method", "extract" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/PackageParser.php#L157-L192
oat-sa/extension-tao-itemqti
model/update/ItemUpdater.php
ItemUpdater.update
public function update($changeItemContent = false) { $returnValue = array(); $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->itemPath), RecursiveIteratorIterator::SELF_FIRST); $i = 0; $fixed = 0; foreach ($objects as $itemFile => $cursor) { if (is_file($itemFile)) { $this->checkedFiles[$itemFile] = false; if (basename($itemFile) === 'qti.xml') { $i++; $xml = new \DOMDocument(); $xml->load($itemFile); $parser = new ParserFactory($xml); $item = $parser->load(); \common_Logger::i('checking item #'.$i.' id:'.$item->attr('identifier').' file:'.$itemFile); if ($this->updateItem($item, $itemFile)) { $this->checkedFiles[$itemFile] = true; $returnValue[$itemFile] = $item; \common_Logger::i('fixed required for #'.$i.' id:'.$item->attr('identifier').' file:'.$itemFile); if ($changeItemContent) { $fixed++; \common_Logger::i('item fixed #'.$i.' id:'.$item->attr('identifier').' file:'.$itemFile); file_put_contents($itemFile, $item->toXML()); } } } } } \common_Logger::i('total item fixed : '.$fixed); return $returnValue; }
php
public function update($changeItemContent = false) { $returnValue = array(); $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->itemPath), RecursiveIteratorIterator::SELF_FIRST); $i = 0; $fixed = 0; foreach ($objects as $itemFile => $cursor) { if (is_file($itemFile)) { $this->checkedFiles[$itemFile] = false; if (basename($itemFile) === 'qti.xml') { $i++; $xml = new \DOMDocument(); $xml->load($itemFile); $parser = new ParserFactory($xml); $item = $parser->load(); \common_Logger::i('checking item #'.$i.' id:'.$item->attr('identifier').' file:'.$itemFile); if ($this->updateItem($item, $itemFile)) { $this->checkedFiles[$itemFile] = true; $returnValue[$itemFile] = $item; \common_Logger::i('fixed required for #'.$i.' id:'.$item->attr('identifier').' file:'.$itemFile); if ($changeItemContent) { $fixed++; \common_Logger::i('item fixed #'.$i.' id:'.$item->attr('identifier').' file:'.$itemFile); file_put_contents($itemFile, $item->toXML()); } } } } } \common_Logger::i('total item fixed : '.$fixed); return $returnValue; }
[ "public", "function", "update", "(", "$", "changeItemContent", "=", "false", ")", "{", "$", "returnValue", "=", "array", "(", ")", ";", "$", "objects", "=", "new", "RecursiveIteratorIterator", "(", "new", "RecursiveDirectoryIterator", "(", "$", "this", "->", ...
Update all the item files found within the $itemRootPath @param boolean $changeItemContent - tells if the item files will be written with the updated content or not @return array of modified item instances
[ "Update", "all", "the", "item", "files", "found", "within", "the", "$itemRootPath" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/update/ItemUpdater.php#L52-L91
oat-sa/extension-tao-itemqti
model/qti/ResponseDeclaration.php
ResponseDeclaration.getMapping
public function getMapping($type = ''){ $returnValue = array(); if($type == 'area'){ $returnValue = $this->areaMapping; }else{ $returnValue = $this->mapping; } return (array) $returnValue; }
php
public function getMapping($type = ''){ $returnValue = array(); if($type == 'area'){ $returnValue = $this->areaMapping; }else{ $returnValue = $this->mapping; } return (array) $returnValue; }
[ "public", "function", "getMapping", "(", "$", "type", "=", "''", ")", "{", "$", "returnValue", "=", "array", "(", ")", ";", "if", "(", "$", "type", "==", "'area'", ")", "{", "$", "returnValue", "=", "$", "this", "->", "areaMapping", ";", "}", "else...
Short description of method getMapping @access public @author Joel Bout, <joel.bout@tudor.lu> @param string type @return array
[ "Short", "description", "of", "method", "getMapping" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/ResponseDeclaration.php#L238-L248
oat-sa/extension-tao-itemqti
model/qti/ResponseDeclaration.php
ResponseDeclaration.setMapping
public function setMapping($map, $type = ''){ if($type == 'area'){ $this->areaMapping = $map; }else{ $this->mapping = $map; } }
php
public function setMapping($map, $type = ''){ if($type == 'area'){ $this->areaMapping = $map; }else{ $this->mapping = $map; } }
[ "public", "function", "setMapping", "(", "$", "map", ",", "$", "type", "=", "''", ")", "{", "if", "(", "$", "type", "==", "'area'", ")", "{", "$", "this", "->", "areaMapping", "=", "$", "map", ";", "}", "else", "{", "$", "this", "->", "mapping", ...
Short description of method setMapping @access public @author Joel Bout, <joel.bout@tudor.lu> @param array map @param type @return mixed
[ "Short", "description", "of", "method", "setMapping" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/ResponseDeclaration.php#L259-L265
oat-sa/extension-tao-itemqti
model/qti/ResponseDeclaration.php
ResponseDeclaration.correctToJSON
public function correctToJSON(){ $returnValue = null; try{ $correctResponses = $this->getCorrectResponses(); if(count($correctResponses)){ $returnValue = taoQTI_models_classes_Matching_VariableFactory::createJSONVariableFromQTIData( $this->getIdentifier() , $this->getAttributeValue('cardinality') , $this->getAttributeValue('baseType') , $this->correctResponses ); } }catch(Exception $e){ } return $returnValue; }
php
public function correctToJSON(){ $returnValue = null; try{ $correctResponses = $this->getCorrectResponses(); if(count($correctResponses)){ $returnValue = taoQTI_models_classes_Matching_VariableFactory::createJSONVariableFromQTIData( $this->getIdentifier() , $this->getAttributeValue('cardinality') , $this->getAttributeValue('baseType') , $this->correctResponses ); } }catch(Exception $e){ } return $returnValue; }
[ "public", "function", "correctToJSON", "(", ")", "{", "$", "returnValue", "=", "null", ";", "try", "{", "$", "correctResponses", "=", "$", "this", "->", "getCorrectResponses", "(", ")", ";", "if", "(", "count", "(", "$", "correctResponses", ")", ")", "{"...
get the correct response in JSON format. If no correct response defined null. @deprecated now use the new qtism lib for response evaluation @access public @author Joel Bout, <joel.bout@tudor.lu>
[ "get", "the", "correct", "response", "in", "JSON", "format", ".", "If", "no", "correct", "response", "defined", "null", "." ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/ResponseDeclaration.php#L302-L320
oat-sa/extension-tao-itemqti
model/qti/ResponseDeclaration.php
ResponseDeclaration.areaMapToJson
public function areaMapToJson(){ $returnValue = null; // Get the stored area mapping $mapping = $this->getMapping('area'); if(count($mapping)){ $returnValue = Array(); $returnValue['identifier'] = $this->getIdentifier(); $returnValue['defaultValue'] = $this->mappingDefaultValue; if($this->hasAttribute('areaMapping')){ $returnValue = array_merge($returnValue, $this->getAttributeValue('areaMapping')); } $mappingValue = Array(); // If a mapping has been defined if(!empty($mapping)){ foreach($mapping as $mapKey => $mappedValue){ $areaMapEntryJSON = Array(); $areaMapEntryJSON['value'] = (float) $mappedValue["mappedValue"]; $areaMapEntryJSON['key'] = taoQTI_models_classes_Matching_VariableFactory::createJSONShapeFromQTIData($mappedValue); array_push($mappingValue, (object) $areaMapEntryJSON); } $returnValue['value'] = $mappingValue; } $returnValue = (object) $returnValue; } return $returnValue; }
php
public function areaMapToJson(){ $returnValue = null; // Get the stored area mapping $mapping = $this->getMapping('area'); if(count($mapping)){ $returnValue = Array(); $returnValue['identifier'] = $this->getIdentifier(); $returnValue['defaultValue'] = $this->mappingDefaultValue; if($this->hasAttribute('areaMapping')){ $returnValue = array_merge($returnValue, $this->getAttributeValue('areaMapping')); } $mappingValue = Array(); // If a mapping has been defined if(!empty($mapping)){ foreach($mapping as $mapKey => $mappedValue){ $areaMapEntryJSON = Array(); $areaMapEntryJSON['value'] = (float) $mappedValue["mappedValue"]; $areaMapEntryJSON['key'] = taoQTI_models_classes_Matching_VariableFactory::createJSONShapeFromQTIData($mappedValue); array_push($mappingValue, (object) $areaMapEntryJSON); } $returnValue['value'] = $mappingValue; } $returnValue = (object) $returnValue; } return $returnValue; }
[ "public", "function", "areaMapToJson", "(", ")", "{", "$", "returnValue", "=", "null", ";", "// Get the stored area mapping", "$", "mapping", "=", "$", "this", "->", "getMapping", "(", "'area'", ")", ";", "if", "(", "count", "(", "$", "mapping", ")", ")", ...
Short description of method areaMapToJson @deprecated now use the new qtism lib for response evaluation @access public @author Joel Bout, <joel.bout@tudor.lu>
[ "Short", "description", "of", "method", "areaMapToJson" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/ResponseDeclaration.php#L329-L359
oat-sa/extension-tao-itemqti
model/qti/ResponseDeclaration.php
ResponseDeclaration.mapToJSON
public function mapToJSON(){ $returnValue = null; $mapping = $this->getMapping(); if(count($mapping)){ $returnValue = Array(); $returnValue['identifier'] = $this->getIdentifier(); $returnValue['defaultValue'] = $this->mappingDefaultValue; if($this->hasAttribute('areaMapping')){ $returnValue = array_merge($returnValue, $this->getAttributeValue('areaMapping')); } $mappingValue = Array(); // If a mapping has been defined if(!empty($mapping)){ foreach($mapping as $mapKey => $mappedValue){ $mapEntryJSON = Array(); $mapEntryJSON['value'] = (float) $mappedValue; $mapEntryJSON['key'] = taoQTI_models_classes_Matching_VariableFactory::createJSONValueFromQTIData($mapKey, $this->getAttributeValue('baseType')); array_push($mappingValue, (object) $mapEntryJSON); } $returnValue['value'] = $mappingValue; } $returnValue = (object) $returnValue; } return $returnValue; }
php
public function mapToJSON(){ $returnValue = null; $mapping = $this->getMapping(); if(count($mapping)){ $returnValue = Array(); $returnValue['identifier'] = $this->getIdentifier(); $returnValue['defaultValue'] = $this->mappingDefaultValue; if($this->hasAttribute('areaMapping')){ $returnValue = array_merge($returnValue, $this->getAttributeValue('areaMapping')); } $mappingValue = Array(); // If a mapping has been defined if(!empty($mapping)){ foreach($mapping as $mapKey => $mappedValue){ $mapEntryJSON = Array(); $mapEntryJSON['value'] = (float) $mappedValue; $mapEntryJSON['key'] = taoQTI_models_classes_Matching_VariableFactory::createJSONValueFromQTIData($mapKey, $this->getAttributeValue('baseType')); array_push($mappingValue, (object) $mapEntryJSON); } $returnValue['value'] = $mappingValue; } $returnValue = (object) $returnValue; } return $returnValue; }
[ "public", "function", "mapToJSON", "(", ")", "{", "$", "returnValue", "=", "null", ";", "$", "mapping", "=", "$", "this", "->", "getMapping", "(", ")", ";", "if", "(", "count", "(", "$", "mapping", ")", ")", "{", "$", "returnValue", "=", "Array", "...
get the mapping in JSON format. If no mapping defined return null. @deprecated now use the new qtism lib for response evaluation @access public @author Joel Bout, <joel.bout@tudor.lu>
[ "get", "the", "mapping", "in", "JSON", "format", ".", "If", "no", "mapping", "defined", "return", "null", "." ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/ResponseDeclaration.php#L368-L397
oat-sa/extension-tao-itemqti
model/qti/ResponseDeclaration.php
ResponseDeclaration.toForm
public function toForm(){ $returnValue = null; $interaction = $this->getAssociatedInteraction(); if($interaction instanceof Interaction){ $responseFormClass = '\\oat\\taoQtiItem\\controller\\QTIform\\response\\'.ucfirst(strtolower($interaction->getType())).'Interaction'; if(class_exists($responseFormClass)){ $formContainer = new $responseFormClass($this); $myForm = $formContainer->getForm(); $returnValue = $myForm; } }else{ throw new Exception('cannot find the parent interaction of the current response'); } return $returnValue; }
php
public function toForm(){ $returnValue = null; $interaction = $this->getAssociatedInteraction(); if($interaction instanceof Interaction){ $responseFormClass = '\\oat\\taoQtiItem\\controller\\QTIform\\response\\'.ucfirst(strtolower($interaction->getType())).'Interaction'; if(class_exists($responseFormClass)){ $formContainer = new $responseFormClass($this); $myForm = $formContainer->getForm(); $returnValue = $myForm; } }else{ throw new Exception('cannot find the parent interaction of the current response'); } return $returnValue; }
[ "public", "function", "toForm", "(", ")", "{", "$", "returnValue", "=", "null", ";", "$", "interaction", "=", "$", "this", "->", "getAssociatedInteraction", "(", ")", ";", "if", "(", "$", "interaction", "instanceof", "Interaction", ")", "{", "$", "response...
Short description of method toForm @access public @author Joel Bout, <joel.bout@tudor.lu> @return tao_helpers_form_xhtml_Form
[ "Short", "description", "of", "method", "toForm" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/ResponseDeclaration.php#L455-L471
oat-sa/extension-tao-itemqti
helpers/Authoring.php
Authoring.validateQtiXml
public static function validateQtiXml($qti) { $dom = self::loadQtiXml($qti); $returnValue = $dom->saveXML(); $parserValidator = new Parser($returnValue); $parserValidator->validate(); if(!$parserValidator->isValid()) { common_Logger::w('Invalid QTI output: ' . PHP_EOL . ' ' . $parserValidator->displayErrors()); throw new QtiModelException('invalid QTI item XML ' . PHP_EOL . ' ' . $parserValidator->displayErrors()); } }
php
public static function validateQtiXml($qti) { $dom = self::loadQtiXml($qti); $returnValue = $dom->saveXML(); $parserValidator = new Parser($returnValue); $parserValidator->validate(); if(!$parserValidator->isValid()) { common_Logger::w('Invalid QTI output: ' . PHP_EOL . ' ' . $parserValidator->displayErrors()); throw new QtiModelException('invalid QTI item XML ' . PHP_EOL . ' ' . $parserValidator->displayErrors()); } }
[ "public", "static", "function", "validateQtiXml", "(", "$", "qti", ")", "{", "$", "dom", "=", "self", "::", "loadQtiXml", "(", "$", "qti", ")", ";", "$", "returnValue", "=", "$", "dom", "->", "saveXML", "(", ")", ";", "$", "parserValidator", "=", "ne...
Validate a QTI XML string. @param string $qti File path or XML string @throws QtiModelException
[ "Validate", "a", "QTI", "XML", "string", "." ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/helpers/Authoring.php#L51-L63
oat-sa/extension-tao-itemqti
helpers/Authoring.php
Authoring.checkEmptyMedia
public static function checkEmptyMedia($qti){ $doc = new DOMDocument(); $doc->loadHTML(self::loadQtiXml($qti)->saveXML()); $imgs = $doc->getElementsByTagName('img'); foreach ($imgs as $img) { if(empty($img->getAttribute('src'))){ throw new QtiModelException('image has no source'); } } $objects = $doc->getElementsByTagName('object'); foreach ($objects as $object) { if(empty($object->getAttribute('data'))){ throw new QtiModelException('object has no data source'); } } $objects = $doc->getElementsByTagName('include'); foreach ($objects as $object) { if(empty($object->getAttribute('href'))){ throw new QtiModelException('object has no data source'); } } }
php
public static function checkEmptyMedia($qti){ $doc = new DOMDocument(); $doc->loadHTML(self::loadQtiXml($qti)->saveXML()); $imgs = $doc->getElementsByTagName('img'); foreach ($imgs as $img) { if(empty($img->getAttribute('src'))){ throw new QtiModelException('image has no source'); } } $objects = $doc->getElementsByTagName('object'); foreach ($objects as $object) { if(empty($object->getAttribute('data'))){ throw new QtiModelException('object has no data source'); } } $objects = $doc->getElementsByTagName('include'); foreach ($objects as $object) { if(empty($object->getAttribute('href'))){ throw new QtiModelException('object has no data source'); } } }
[ "public", "static", "function", "checkEmptyMedia", "(", "$", "qti", ")", "{", "$", "doc", "=", "new", "DOMDocument", "(", ")", ";", "$", "doc", "->", "loadHTML", "(", "self", "::", "loadQtiXml", "(", "$", "qti", ")", "->", "saveXML", "(", ")", ")", ...
Simple function to check if the item is not missing any of the required asset configuration path @param string $qti @throws QtiModelException @throws common_exception_Error
[ "Simple", "function", "to", "check", "if", "the", "item", "is", "not", "missing", "any", "of", "the", "required", "asset", "configuration", "path" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/helpers/Authoring.php#L71-L95
oat-sa/extension-tao-itemqti
helpers/Authoring.php
Authoring.addRequiredResources
public static function addRequiredResources($sourceDirectory, $relativeSourceFiles, $prefix, core_kernel_classes_Resource $item, $lang) { $returnValue = array(); $directory = taoItems_models_classes_ItemsService::singleton()->getItemDirectory($item, $lang); foreach ($relativeSourceFiles as $relPath) { if(! tao_helpers_File::securityCheck($relPath, true)) { throw new common_exception_Error('Invalid resource file path'); } $relPath = preg_replace('/^\.\//', '', $relPath); $source = $sourceDirectory . $relPath; $fh = fopen($source, 'r'); if (! is_resource($fh)) { throw new common_exception_Error('The resource "' . $source . '" cannot be copied.'); } $path = tao_helpers_File::concat(array( $prefix ? $prefix : '', $relPath )); // cannot write as PCI do not get cleaned up if ($directory->getFile($path)->put($fh)) { $returnValue[] = $relPath; } fclose($fh); } return $returnValue; }
php
public static function addRequiredResources($sourceDirectory, $relativeSourceFiles, $prefix, core_kernel_classes_Resource $item, $lang) { $returnValue = array(); $directory = taoItems_models_classes_ItemsService::singleton()->getItemDirectory($item, $lang); foreach ($relativeSourceFiles as $relPath) { if(! tao_helpers_File::securityCheck($relPath, true)) { throw new common_exception_Error('Invalid resource file path'); } $relPath = preg_replace('/^\.\//', '', $relPath); $source = $sourceDirectory . $relPath; $fh = fopen($source, 'r'); if (! is_resource($fh)) { throw new common_exception_Error('The resource "' . $source . '" cannot be copied.'); } $path = tao_helpers_File::concat(array( $prefix ? $prefix : '', $relPath )); // cannot write as PCI do not get cleaned up if ($directory->getFile($path)->put($fh)) { $returnValue[] = $relPath; } fclose($fh); } return $returnValue; }
[ "public", "static", "function", "addRequiredResources", "(", "$", "sourceDirectory", ",", "$", "relativeSourceFiles", ",", "$", "prefix", ",", "core_kernel_classes_Resource", "$", "item", ",", "$", "lang", ")", "{", "$", "returnValue", "=", "array", "(", ")", ...
Add a list of required resources files to an RDF item and keeps the relative path structure For instances, required css, js etc. @param string $sourceDirectory @param array $relativeSourceFiles @param core_kernel_classes_Resource $item @param string $lang @return array @throws common_exception_Error
[ "Add", "a", "list", "of", "required", "resources", "files", "to", "an", "RDF", "item", "and", "keeps", "the", "relative", "path", "structure", "For", "instances", "required", "css", "js", "etc", "." ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/helpers/Authoring.php#L108-L142
oat-sa/extension-tao-itemqti
helpers/Authoring.php
Authoring.sanitizeQtiXml
public static function sanitizeQtiXml($qti) { $doc = self::loadQtiXml($qti); $xpath = new \DOMXpath($doc); foreach ($xpath->query("//*[local-name() = 'itemBody']//*[@style]") as $elementWithStyle) { $elementWithStyle->removeAttribute('style'); } $ids = array(); /** @var \DOMElement $elementWithId */ foreach ($xpath->query("//*[not(local-name()='lib') and not(local-name()='module') and @id]") as $elementWithId) { $id = $elementWithId->getAttribute('id'); if(in_array($id, $ids)){ $elementWithId->removeAttribute('id'); } else{ $ids[] = $id; } } return $doc->saveXML(); }
php
public static function sanitizeQtiXml($qti) { $doc = self::loadQtiXml($qti); $xpath = new \DOMXpath($doc); foreach ($xpath->query("//*[local-name() = 'itemBody']//*[@style]") as $elementWithStyle) { $elementWithStyle->removeAttribute('style'); } $ids = array(); /** @var \DOMElement $elementWithId */ foreach ($xpath->query("//*[not(local-name()='lib') and not(local-name()='module') and @id]") as $elementWithId) { $id = $elementWithId->getAttribute('id'); if(in_array($id, $ids)){ $elementWithId->removeAttribute('id'); } else{ $ids[] = $id; } } return $doc->saveXML(); }
[ "public", "static", "function", "sanitizeQtiXml", "(", "$", "qti", ")", "{", "$", "doc", "=", "self", "::", "loadQtiXml", "(", "$", "qti", ")", ";", "$", "xpath", "=", "new", "\\", "DOMXpath", "(", "$", "doc", ")", ";", "foreach", "(", "$", "xpath"...
Remove invalid elements and attributes from QTI XML. @param string $qti File path or XML string @return string sanitized XML
[ "Remove", "invalid", "elements", "and", "attributes", "from", "QTI", "XML", "." ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/helpers/Authoring.php#L149-L171
oat-sa/extension-tao-itemqti
helpers/Authoring.php
Authoring.loadQtiXml
public static function loadQtiXml($file) { if ($file instanceof File) { $qti = $file->read(); } else if (preg_match("/^<\?xml(.*)?/m", trim($file))) { $qti = $file; } else if (is_file($file)) { $qti = file_get_contents($file); } else { throw new \common_exception_Error("Wrong parameter. " . __CLASS__ . "::" . __METHOD__ . " accepts either XML content or the path to a file but got ".substr($file, 0, 500)); } $dom = new DOMDocument('1.0', 'UTF-8'); $domDocumentConfig = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiItem')->getConfig('XMLParser'); if (is_array($domDocumentConfig) && !empty($domDocumentConfig)) { foreach ($domDocumentConfig as $param => $value) { if (property_exists($dom, $param)) { $dom->$param = $value; } } } else { $dom->formatOutput = true; $dom->preserveWhiteSpace = false; $dom->validateOnParse = false; } libxml_use_internal_errors(true); if (!$dom->loadXML($qti)) { $errors = libxml_get_errors(); $errorsMsg = 'Wrong QTI item output format:' . PHP_EOL . array_reduce($errors, function ($carry, $item) { $carry .= $item->message . PHP_EOL; return $carry; }); common_Logger::w($errorsMsg); throw new QtiModelException($errorsMsg); } return $dom; }
php
public static function loadQtiXml($file) { if ($file instanceof File) { $qti = $file->read(); } else if (preg_match("/^<\?xml(.*)?/m", trim($file))) { $qti = $file; } else if (is_file($file)) { $qti = file_get_contents($file); } else { throw new \common_exception_Error("Wrong parameter. " . __CLASS__ . "::" . __METHOD__ . " accepts either XML content or the path to a file but got ".substr($file, 0, 500)); } $dom = new DOMDocument('1.0', 'UTF-8'); $domDocumentConfig = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiItem')->getConfig('XMLParser'); if (is_array($domDocumentConfig) && !empty($domDocumentConfig)) { foreach ($domDocumentConfig as $param => $value) { if (property_exists($dom, $param)) { $dom->$param = $value; } } } else { $dom->formatOutput = true; $dom->preserveWhiteSpace = false; $dom->validateOnParse = false; } libxml_use_internal_errors(true); if (!$dom->loadXML($qti)) { $errors = libxml_get_errors(); $errorsMsg = 'Wrong QTI item output format:' . PHP_EOL . array_reduce($errors, function ($carry, $item) { $carry .= $item->message . PHP_EOL; return $carry; }); common_Logger::w($errorsMsg); throw new QtiModelException($errorsMsg); } return $dom; }
[ "public", "static", "function", "loadQtiXml", "(", "$", "file", ")", "{", "if", "(", "$", "file", "instanceof", "File", ")", "{", "$", "qti", "=", "$", "file", "->", "read", "(", ")", ";", "}", "else", "if", "(", "preg_match", "(", "\"/^<\\?xml(.*)?/...
Load QTI xml and return DOMDocument instance. If string is not valid xml then QtiModelException will be thrown. @param string|File $file If it's a string it can be a file path or an XML string @throws QtiModelException @throws common_exception_Error @return DOMDocument
[ "Load", "QTI", "xml", "and", "return", "DOMDocument", "instance", ".", "If", "string", "is", "not", "valid", "xml", "then", "QtiModelException", "will", "be", "thrown", "." ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/helpers/Authoring.php#L182-L228
oat-sa/extension-tao-itemqti
model/qti/response/SetOutcomeVariable.php
SetOutcomeVariable.getRule
public function getRule() { $returnValue = (string) ''; $returnValue = 'setOutcomeValue("'.$this->outcomeVariableIdentifier.'", '.$this->expression->getRule().');'; return (string) $returnValue; }
php
public function getRule() { $returnValue = (string) ''; $returnValue = 'setOutcomeValue("'.$this->outcomeVariableIdentifier.'", '.$this->expression->getRule().');'; return (string) $returnValue; }
[ "public", "function", "getRule", "(", ")", "{", "$", "returnValue", "=", "(", "string", ")", "''", ";", "$", "returnValue", "=", "'setOutcomeValue(\"'", ".", "$", "this", "->", "outcomeVariableIdentifier", ".", "'\", '", ".", "$", "this", "->", "expression",...
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/SetOutcomeVariable.php#L85-L94
oat-sa/extension-tao-itemqti
model/qti/response/Summation.php
Summation.getCompositionRules
public function getCompositionRules() { $subExpressions = array(); foreach ($this->components as $irp) { $subExpressions[] = new CommonExpression('variable', array('identifier' => $irp->getOutcome()->getIdentifier())); } $sum = new CommonExpression('sum', array()); $sum->setSubExpressions($subExpressions); $summationRule = new SetOutcomeVariable($this->outcomeIdentifier, $sum); $returnValue = array($summationRule); return (array) $returnValue; }
php
public function getCompositionRules() { $subExpressions = array(); foreach ($this->components as $irp) { $subExpressions[] = new CommonExpression('variable', array('identifier' => $irp->getOutcome()->getIdentifier())); } $sum = new CommonExpression('sum', array()); $sum->setSubExpressions($subExpressions); $summationRule = new SetOutcomeVariable($this->outcomeIdentifier, $sum); $returnValue = array($summationRule); return (array) $returnValue; }
[ "public", "function", "getCompositionRules", "(", ")", "{", "$", "subExpressions", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "components", "as", "$", "irp", ")", "{", "$", "subExpressions", "[", "]", "=", "new", "CommonExpression", ...
Short description of method getCompositionRules @access public @author Joel Bout, <joel.bout@tudor.lu> @return array
[ "Short", "description", "of", "method", "getCompositionRules" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/response/Summation.php#L48-L61
oat-sa/extension-tao-itemqti
model/qti/response/Summation.php
Summation.getCompositionQTI
public function getCompositionQTI() { $returnValue = (string) ''; $returnValue .= '<setOutcomeValue identifier="'.$this->outcomeIdentifier.'"><sum>'; foreach ($this->components as $irp) { $returnValue .= '<variable identifier="'.$irp->getOutcome()->getIdentifier().'" />'; } $returnValue .= '</sum></setOutcomeValue>'; return (string) $returnValue; }
php
public function getCompositionQTI() { $returnValue = (string) ''; $returnValue .= '<setOutcomeValue identifier="'.$this->outcomeIdentifier.'"><sum>'; foreach ($this->components as $irp) { $returnValue .= '<variable identifier="'.$irp->getOutcome()->getIdentifier().'" />'; } $returnValue .= '</sum></setOutcomeValue>'; return (string) $returnValue; }
[ "public", "function", "getCompositionQTI", "(", ")", "{", "$", "returnValue", "=", "(", "string", ")", "''", ";", "$", "returnValue", ".=", "'<setOutcomeValue identifier=\"'", ".", "$", "this", "->", "outcomeIdentifier", ".", "'\"><sum>'", ";", "foreach", "(", ...
Short description of method getCompositionQTI @access public @author Joel Bout, <joel.bout@tudor.lu> @return string
[ "Short", "description", "of", "method", "getCompositionQTI" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/response/Summation.php#L70-L81
oat-sa/extension-tao-itemqti
model/qti/XIncludeLoader.php
XIncludeLoader.load
public function load($removeUnfoundHref = false){ $xincludes = $this->getXIncludes(); //load xincludes in standard element foreach($xincludes as $xinclude){ //retrive the xinclude from href $href = $xinclude->attr('href'); if(!empty($href)){ try { $asset = $this->resolver->resolve($href); $filePath = $asset->getMediaSource()->download($asset->getMediaIdentifier()); $this->loadXInclude($xinclude, $filePath); } catch (\tao_models_classes_FileNotFoundException $exception) { if ($removeUnfoundHref) { $xinclude->attr('href', ''); } else { throw new XIncludeException('The file referenced by href does not exist : '.$href, $xinclude); } } } } //load xinclude in portable element markup $customElements = $this->getCustomElements(); foreach($customElements as $customElement){ $xincludes = array_merge($xincludes, $this->parseCustomElementMarkup($customElement)); } return $xincludes; }
php
public function load($removeUnfoundHref = false){ $xincludes = $this->getXIncludes(); //load xincludes in standard element foreach($xincludes as $xinclude){ //retrive the xinclude from href $href = $xinclude->attr('href'); if(!empty($href)){ try { $asset = $this->resolver->resolve($href); $filePath = $asset->getMediaSource()->download($asset->getMediaIdentifier()); $this->loadXInclude($xinclude, $filePath); } catch (\tao_models_classes_FileNotFoundException $exception) { if ($removeUnfoundHref) { $xinclude->attr('href', ''); } else { throw new XIncludeException('The file referenced by href does not exist : '.$href, $xinclude); } } } } //load xinclude in portable element markup $customElements = $this->getCustomElements(); foreach($customElements as $customElement){ $xincludes = array_merge($xincludes, $this->parseCustomElementMarkup($customElement)); } return $xincludes; }
[ "public", "function", "load", "(", "$", "removeUnfoundHref", "=", "false", ")", "{", "$", "xincludes", "=", "$", "this", "->", "getXIncludes", "(", ")", ";", "//load xincludes in standard element", "foreach", "(", "$", "xincludes", "as", "$", "xinclude", ")", ...
Load parse the item and resolve all xinclude @param boolean $removeUnfoundHref @return array @throws XIncludeException when the href cannot be resolved
[ "Load", "parse", "the", "item", "and", "resolve", "all", "xinclude" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/XIncludeLoader.php#L58-L88
oat-sa/extension-tao-itemqti
model/qti/XIncludeLoader.php
XIncludeLoader.parseCustomElementMarkup
private function parseCustomElementMarkup(CustomInteraction $customElement){ $xincludes = array(); $xml = new DOMDocument(); $xml->formatOutput = true; $loadSuccess = $xml->loadXML($customElement->getMarkup()); $node = $xml->documentElement; if($loadSuccess && !is_null($node)){ $parser = new ParserFactory($xml); $xincludesNodes = $parser->queryXPath(".//*[name(.)='include']"); foreach($xincludesNodes as $xincludeNode){ $href = $xincludeNode->getAttribute('href'); $asset = $this->resolver->resolve($href); $filePath = $asset->getMediaSource()->download($asset->getMediaIdentifier()); if(file_exists($filePath)){ $fileContent = file_get_contents($filePath); $xmlInclude = new DOMDocument(); $xmlInclude->formatOutput = true; $xmlInclude->loadXML($fileContent); foreach($xmlInclude->documentElement->childNodes as $node){ $importNode = $xml->importNode($node, true); $xincludeNode->parentNode->insertBefore($importNode, $xincludeNode); } }else{ throw new XIncludeException('The file referenced by href does not exist : '.$href, $xincludeNode); } $xincludeNode->parentNode->removeChild($xincludeNode); $xincludes[] = $href; } }else{ throw new ParsingException('cannot parse pci markup'); } $customElement->setMarkup($xml->saveXML(null, LIBXML_NOEMPTYTAG)); return $xincludes; }
php
private function parseCustomElementMarkup(CustomInteraction $customElement){ $xincludes = array(); $xml = new DOMDocument(); $xml->formatOutput = true; $loadSuccess = $xml->loadXML($customElement->getMarkup()); $node = $xml->documentElement; if($loadSuccess && !is_null($node)){ $parser = new ParserFactory($xml); $xincludesNodes = $parser->queryXPath(".//*[name(.)='include']"); foreach($xincludesNodes as $xincludeNode){ $href = $xincludeNode->getAttribute('href'); $asset = $this->resolver->resolve($href); $filePath = $asset->getMediaSource()->download($asset->getMediaIdentifier()); if(file_exists($filePath)){ $fileContent = file_get_contents($filePath); $xmlInclude = new DOMDocument(); $xmlInclude->formatOutput = true; $xmlInclude->loadXML($fileContent); foreach($xmlInclude->documentElement->childNodes as $node){ $importNode = $xml->importNode($node, true); $xincludeNode->parentNode->insertBefore($importNode, $xincludeNode); } }else{ throw new XIncludeException('The file referenced by href does not exist : '.$href, $xincludeNode); } $xincludeNode->parentNode->removeChild($xincludeNode); $xincludes[] = $href; } }else{ throw new ParsingException('cannot parse pci markup'); } $customElement->setMarkup($xml->saveXML(null, LIBXML_NOEMPTYTAG)); return $xincludes; }
[ "private", "function", "parseCustomElementMarkup", "(", "CustomInteraction", "$", "customElement", ")", "{", "$", "xincludes", "=", "array", "(", ")", ";", "$", "xml", "=", "new", "DOMDocument", "(", ")", ";", "$", "xml", "->", "formatOutput", "=", "true", ...
Parse and load xinclude located in custom element markup @param CustomInteraction $customElement @return array @throws XIncludeException when the file in href cannot be resolved @throws ParsingException when the markup cannot be loaded as xml document
[ "Parse", "and", "load", "xinclude", "located", "in", "custom", "element", "markup" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/XIncludeLoader.php#L98-L135
oat-sa/extension-tao-itemqti
model/qti/XIncludeLoader.php
XIncludeLoader.loadXInclude
private function loadXInclude(XInclude $xinclude, $filePath){ //load DOMDocument $xml = new DOMDocument(); $loadSuccess = $xml->load($filePath); $node = $xml->documentElement; if($loadSuccess && !is_null($node)){ //parse the href content $parser = new ParserFactory($xml); $parser->loadContainerStatic($node, $xinclude->getBody()); }else{ throw new XIncludeException('Cannot load the XInclude DOM XML', $xinclude); } }
php
private function loadXInclude(XInclude $xinclude, $filePath){ //load DOMDocument $xml = new DOMDocument(); $loadSuccess = $xml->load($filePath); $node = $xml->documentElement; if($loadSuccess && !is_null($node)){ //parse the href content $parser = new ParserFactory($xml); $parser->loadContainerStatic($node, $xinclude->getBody()); }else{ throw new XIncludeException('Cannot load the XInclude DOM XML', $xinclude); } }
[ "private", "function", "loadXInclude", "(", "XInclude", "$", "xinclude", ",", "$", "filePath", ")", "{", "//load DOMDocument", "$", "xml", "=", "new", "DOMDocument", "(", ")", ";", "$", "loadSuccess", "=", "$", "xml", "->", "load", "(", "$", "filePath", ...
load an xml string into the body of the XInclude @param \oat\taoQtiItem\model\qti\XInclude $xinclude @param string $filePath @throws XIncludeException
[ "load", "an", "xml", "string", "into", "the", "body", "of", "the", "XInclude" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/XIncludeLoader.php#L144-L156
oat-sa/extension-tao-itemqti
model/qti/XIncludeLoader.php
XIncludeLoader.getXIncludes
private function getXIncludes(){ $xincludes = array(); foreach($this->qtiItem->getComposingElements() as $element){ if($element instanceof XInclude){ $xincludes[] = $element; } } return $xincludes; }
php
private function getXIncludes(){ $xincludes = array(); foreach($this->qtiItem->getComposingElements() as $element){ if($element instanceof XInclude){ $xincludes[] = $element; } } return $xincludes; }
[ "private", "function", "getXIncludes", "(", ")", "{", "$", "xincludes", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "qtiItem", "->", "getComposingElements", "(", ")", "as", "$", "element", ")", "{", "if", "(", "$", "element", "insta...
Find the xinclude elements in the qti item @return \oat\taoQtiItem\model\qti\XInclude[]
[ "Find", "the", "xinclude", "elements", "in", "the", "qti", "item" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/XIncludeLoader.php#L163-L171
oat-sa/extension-tao-itemqti
model/qti/XIncludeLoader.php
XIncludeLoader.getCustomElements
private function getCustomElements(){ $customElements = array(); foreach($this->qtiItem->getComposingElements() as $element){ if($element instanceof PortableCustomInteraction){ $customElements[] = $element; } } return $customElements; }
php
private function getCustomElements(){ $customElements = array(); foreach($this->qtiItem->getComposingElements() as $element){ if($element instanceof PortableCustomInteraction){ $customElements[] = $element; } } return $customElements; }
[ "private", "function", "getCustomElements", "(", ")", "{", "$", "customElements", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "qtiItem", "->", "getComposingElements", "(", ")", "as", "$", "element", ")", "{", "if", "(", "$", "element"...
Find the custom elements in the qti item @return \oat\taoQtiItem\model\qti\interaction\PortableCustomInteraction[]
[ "Find", "the", "custom", "elements", "in", "the", "qti", "item" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/XIncludeLoader.php#L178-L186
oat-sa/extension-tao-itemqti
model/qti/exception/UnsupportedQtiElement.php
UnsupportedQtiElement.getUserMessage
public function getUserMessage() { $name = $this->getElement()->localName; $line = $this->getElement()->getLineNo(); return sprintf(__('The QTI class "%1$s" located at line "%2$d" is currently not supported.'), $name, $line); }
php
public function getUserMessage() { $name = $this->getElement()->localName; $line = $this->getElement()->getLineNo(); return sprintf(__('The QTI class "%1$s" located at line "%2$d" is currently not supported.'), $name, $line); }
[ "public", "function", "getUserMessage", "(", ")", "{", "$", "name", "=", "$", "this", "->", "getElement", "(", ")", "->", "localName", ";", "$", "line", "=", "$", "this", "->", "getElement", "(", ")", "->", "getLineNo", "(", ")", ";", "return", "spri...
Returns a human-readable message describing the error that occurred. @return string
[ "Returns", "a", "human", "-", "readable", "message", "describing", "the", "error", "that", "occurred", "." ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/exception/UnsupportedQtiElement.php#L80-L84
oat-sa/extension-tao-itemqti
model/ItemCategoriesService.php
ItemCategoriesService.getCategories
public function getCategories(array $items) { $categories = array(); $lookupProperties = $this->getOption('properties'); if (!empty($lookupProperties)) { foreach ($items as $item) { $itemCategories = array(); if($item instanceof \core_kernel_classes_Resource){ $properties = $item->getPropertiesValues(array_keys($lookupProperties)); foreach ($properties as $property => $propertyValues) { foreach ($propertyValues as $value) { $propertyValue = ($value instanceof \core_kernel_classes_Resource) ? $value->getUri() : (string)$value; if(isset($lookupProperties[$property][$propertyValue])){ $itemCategories[] = $lookupProperties[$property][$propertyValue]; } } } $categories[$item->getUri()] = $itemCategories; } } } return $categories; }
php
public function getCategories(array $items) { $categories = array(); $lookupProperties = $this->getOption('properties'); if (!empty($lookupProperties)) { foreach ($items as $item) { $itemCategories = array(); if($item instanceof \core_kernel_classes_Resource){ $properties = $item->getPropertiesValues(array_keys($lookupProperties)); foreach ($properties as $property => $propertyValues) { foreach ($propertyValues as $value) { $propertyValue = ($value instanceof \core_kernel_classes_Resource) ? $value->getUri() : (string)$value; if(isset($lookupProperties[$property][$propertyValue])){ $itemCategories[] = $lookupProperties[$property][$propertyValue]; } } } $categories[$item->getUri()] = $itemCategories; } } } return $categories; }
[ "public", "function", "getCategories", "(", "array", "$", "items", ")", "{", "$", "categories", "=", "array", "(", ")", ";", "$", "lookupProperties", "=", "$", "this", "->", "getOption", "(", "'properties'", ")", ";", "if", "(", "!", "empty", "(", "$",...
Get the categories link to the list of items in parameter. Theses categories come from a configurable list of properties. The category label is also set in a configurable list @param \core_kernel_classes_Resource[] $items @return array of categories for specified items ['itemUri' => ['CATEGORY1', 'CATEGORY2']]
[ "Get", "the", "categories", "link", "to", "the", "list", "of", "items", "in", "parameter", ".", "Theses", "categories", "come", "from", "a", "configurable", "list", "of", "properties", ".", "The", "category", "label", "is", "also", "set", "in", "a", "confi...
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/ItemCategoriesService.php#L46-L69
oat-sa/extension-tao-itemqti
helpers/QtiSerializer.php
QtiSerializer.parseElementXml
public static function parseElementXml(SimpleXMLElement $xml){ $attributes = array(); foreach($xml->attributes() as $name => $value){ $attributes[$name] = (string) $value; } $returnValue = array( 'qtiClass' => $xml->getName() ); if(count($attributes)){ $returnValue['attributes'] = $attributes; } return $returnValue; }
php
public static function parseElementXml(SimpleXMLElement $xml){ $attributes = array(); foreach($xml->attributes() as $name => $value){ $attributes[$name] = (string) $value; } $returnValue = array( 'qtiClass' => $xml->getName() ); if(count($attributes)){ $returnValue['attributes'] = $attributes; } return $returnValue; }
[ "public", "static", "function", "parseElementXml", "(", "SimpleXMLElement", "$", "xml", ")", "{", "$", "attributes", "=", "array", "(", ")", ";", "foreach", "(", "$", "xml", "->", "attributes", "(", ")", "as", "$", "name", "=>", "$", "value", ")", "{",...
Parse a generic QTI element node into an array @param SimpleXMLElement $xml @return array
[ "Parse", "a", "generic", "QTI", "element", "node", "into", "an", "array" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/helpers/QtiSerializer.php#L38-L54
oat-sa/extension-tao-itemqti
helpers/QtiSerializer.php
QtiSerializer.parseExpressionXml
public static function parseExpressionXml(SimpleXMLElement $xml){ $returnValue = self::parseElementXml($xml); $value = trim($xml); $expressions = array(); foreach($xml->children() as $child){ $expressions[] = self::parseExpressionXml($child); } if(count($expressions)){ $returnValue['expressions'] = $expressions; } if(strlen($value)){ $returnValue['value'] = $value; } return $returnValue; }
php
public static function parseExpressionXml(SimpleXMLElement $xml){ $returnValue = self::parseElementXml($xml); $value = trim($xml); $expressions = array(); foreach($xml->children() as $child){ $expressions[] = self::parseExpressionXml($child); } if(count($expressions)){ $returnValue['expressions'] = $expressions; } if(strlen($value)){ $returnValue['value'] = $value; } return $returnValue; }
[ "public", "static", "function", "parseExpressionXml", "(", "SimpleXMLElement", "$", "xml", ")", "{", "$", "returnValue", "=", "self", "::", "parseElementXml", "(", "$", "xml", ")", ";", "$", "value", "=", "trim", "(", "$", "xml", ")", ";", "$", "expressi...
Parse a QTI expression node into an array @see http://www.imsglobal.org/question/qtiv2p1/imsqti_infov2p1.html#element10569 @param SimpleXMLElement $xml @return array
[ "Parse", "a", "QTI", "expression", "node", "into", "an", "array" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/helpers/QtiSerializer.php#L63-L77
oat-sa/extension-tao-itemqti
helpers/QtiSerializer.php
QtiSerializer.parseResponseRuleXml
public static function parseResponseRuleXml(SimpleXMLElement $xml){ $returnValue = self::parseElementXml($xml); foreach($xml->children() as $child){ $returnValue['expression'] = self::parseExpressionXml($child); break; } return $returnValue; }
php
public static function parseResponseRuleXml(SimpleXMLElement $xml){ $returnValue = self::parseElementXml($xml); foreach($xml->children() as $child){ $returnValue['expression'] = self::parseExpressionXml($child); break; } return $returnValue; }
[ "public", "static", "function", "parseResponseRuleXml", "(", "SimpleXMLElement", "$", "xml", ")", "{", "$", "returnValue", "=", "self", "::", "parseElementXml", "(", "$", "xml", ")", ";", "foreach", "(", "$", "xml", "->", "children", "(", ")", "as", "$", ...
Parse a QTI responseRule node into an array @see http://www.imsglobal.org/question/qtiv2p1/imsqti_infov2p1.html#element10408 @param SimpleXMLElement $xml @return array
[ "Parse", "a", "QTI", "responseRule", "node", "into", "an", "array" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/helpers/QtiSerializer.php#L86-L93
oat-sa/extension-tao-itemqti
helpers/QtiSerializer.php
QtiSerializer.parseResponseRulesContainerXml
private static function parseResponseRulesContainerXml(SimpleXMLElement $xml){ $returnValue = self::parseElementXml($xml); $responseRules = array(); foreach($xml->children() as $child){ $name = $child->getName(); $methodName = 'parse'.ucfirst($name).'Xml'; if(method_exists(__CLASS__, $methodName)){ $responseRules[] = self::$methodName($child); }else{ $responseRules[] = self::parseResponseRuleXml($child); } } $returnValue['responseRules'] = $responseRules; return $returnValue; }
php
private static function parseResponseRulesContainerXml(SimpleXMLElement $xml){ $returnValue = self::parseElementXml($xml); $responseRules = array(); foreach($xml->children() as $child){ $name = $child->getName(); $methodName = 'parse'.ucfirst($name).'Xml'; if(method_exists(__CLASS__, $methodName)){ $responseRules[] = self::$methodName($child); }else{ $responseRules[] = self::parseResponseRuleXml($child); } } $returnValue['responseRules'] = $responseRules; return $returnValue; }
[ "private", "static", "function", "parseResponseRulesContainerXml", "(", "SimpleXMLElement", "$", "xml", ")", "{", "$", "returnValue", "=", "self", "::", "parseElementXml", "(", "$", "xml", ")", ";", "$", "responseRules", "=", "array", "(", ")", ";", "foreach",...
Parse a generic QTI element node that contains responseRules as children into an array @param SimpleXMLElement $xml @return array
[ "Parse", "a", "generic", "QTI", "element", "node", "that", "contains", "responseRules", "as", "children", "into", "an", "array" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/helpers/QtiSerializer.php#L101-L116
oat-sa/extension-tao-itemqti
helpers/QtiSerializer.php
QtiSerializer.parseResponseIfXml
public static function parseResponseIfXml(SimpleXMLElement $xml){ $returnValue = self::parseElementXml($xml); $i = 0; $expression = null; $responseRules = array(); foreach($xml->children() as $child){ if($i){ $name = $child->getName(); $methodName = 'parse'.ucfirst($name).'Xml'; if(method_exists(__CLASS__, $methodName)){ $responseRules[] = self::$methodName($child); } else{ $responseRules[] = self::parseResponseRuleXml($child); } }else{ //the first child is the expression $expression = self::parseExpressionXml($child); } $i++; } $returnValue['expression'] = $expression; $returnValue['responseRules'] = $responseRules; return $returnValue; }
php
public static function parseResponseIfXml(SimpleXMLElement $xml){ $returnValue = self::parseElementXml($xml); $i = 0; $expression = null; $responseRules = array(); foreach($xml->children() as $child){ if($i){ $name = $child->getName(); $methodName = 'parse'.ucfirst($name).'Xml'; if(method_exists(__CLASS__, $methodName)){ $responseRules[] = self::$methodName($child); } else{ $responseRules[] = self::parseResponseRuleXml($child); } }else{ //the first child is the expression $expression = self::parseExpressionXml($child); } $i++; } $returnValue['expression'] = $expression; $returnValue['responseRules'] = $responseRules; return $returnValue; }
[ "public", "static", "function", "parseResponseIfXml", "(", "SimpleXMLElement", "$", "xml", ")", "{", "$", "returnValue", "=", "self", "::", "parseElementXml", "(", "$", "xml", ")", ";", "$", "i", "=", "0", ";", "$", "expression", "=", "null", ";", "$", ...
Parse a QTI responseProcessing node into an array @see http://www.imsglobal.org/question/qtiv2p1/imsqti_infov2p1.html#element10413 @param SimpleXMLElement $xml @return array
[ "Parse", "a", "QTI", "responseProcessing", "node", "into", "an", "array" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/helpers/QtiSerializer.php#L136-L159
oat-sa/extension-tao-itemqti
helpers/QtiSerializer.php
QtiSerializer.parseResponseConditionXml
public static function parseResponseConditionXml(SimpleXMLElement $xml){ $returnValue = self::parseElementXml($xml); foreach($xml->responseIf as $responseIfXml){ $returnValue['responseIf'] = self::parseResponseIfXml($responseIfXml); break; } foreach($xml->responseElseIf as $responseIfXml){ if(!isset($returnValue['responseElseIfs'])){ $returnValue['responseElseIfs'] = array(); } $returnValue['responseElseIfs'][] = self::parseResponseIfXml($responseIfXml); } foreach($xml->responseElse as $responseIfXml){ $returnValue['responseElse'] = self::parseResponseElseXml($responseIfXml); break; } return $returnValue; }
php
public static function parseResponseConditionXml(SimpleXMLElement $xml){ $returnValue = self::parseElementXml($xml); foreach($xml->responseIf as $responseIfXml){ $returnValue['responseIf'] = self::parseResponseIfXml($responseIfXml); break; } foreach($xml->responseElseIf as $responseIfXml){ if(!isset($returnValue['responseElseIfs'])){ $returnValue['responseElseIfs'] = array(); } $returnValue['responseElseIfs'][] = self::parseResponseIfXml($responseIfXml); } foreach($xml->responseElse as $responseIfXml){ $returnValue['responseElse'] = self::parseResponseElseXml($responseIfXml); break; } return $returnValue; }
[ "public", "static", "function", "parseResponseConditionXml", "(", "SimpleXMLElement", "$", "xml", ")", "{", "$", "returnValue", "=", "self", "::", "parseElementXml", "(", "$", "xml", ")", ";", "foreach", "(", "$", "xml", "->", "responseIf", "as", "$", "respo...
Parse a QTI responseProcessing node into an array @see http://www.imsglobal.org/question/qtiv2p1/imsqti_infov2p1.html#element10409 @param SimpleXMLElement $xml @return array
[ "Parse", "a", "QTI", "responseProcessing", "node", "into", "an", "array" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/helpers/QtiSerializer.php#L179-L196
oat-sa/extension-tao-itemqti
model/qti/response/interactionResponseProcessing/InteractionResponseProcessing.php
InteractionResponseProcessing.create
public static function create($classID, ResponseDeclaration $response, Item $item){ switch($classID){ case None::CLASS_ID : $className = 'oat\\taoQtiItem\\model\\qti\\response\\interactionResponseProcessing\\None'; break; case MatchCorrectTemplate::CLASS_ID : $className = 'oat\\taoQtiItem\\model\\qti\\response\\interactionResponseProcessing\\MatchCorrectTemplate'; break; case MapResponseTemplate::CLASS_ID : $className = 'oat\\taoQtiItem\\model\\qti\\response\\interactionResponseProcessing\\MapResponseTemplate'; break; case MapResponsePointTemplate::CLASS_ID : $className = 'oat\\taoQtiItem\\model\\qti\\response\\interactionResponseProcessing\\MapResponsePointTemplate'; break; case Custom::CLASS_ID : $className = 'oat\\taoQtiItem\\model\\qti\\response\\interactionResponseProcessing\\Custom'; break; default : throw new common_exception_Error('Unknown InteractionResponseProcessing Class ID "'.$classID.'"'); } $outcome = self::generateOutcomeDefinition(); $outcomes = $item->getOutcomes(); $outcomes[] = $outcome; $item->setOutcomes($outcomes); $returnValue = new $className($response, $outcome); return $returnValue; }
php
public static function create($classID, ResponseDeclaration $response, Item $item){ switch($classID){ case None::CLASS_ID : $className = 'oat\\taoQtiItem\\model\\qti\\response\\interactionResponseProcessing\\None'; break; case MatchCorrectTemplate::CLASS_ID : $className = 'oat\\taoQtiItem\\model\\qti\\response\\interactionResponseProcessing\\MatchCorrectTemplate'; break; case MapResponseTemplate::CLASS_ID : $className = 'oat\\taoQtiItem\\model\\qti\\response\\interactionResponseProcessing\\MapResponseTemplate'; break; case MapResponsePointTemplate::CLASS_ID : $className = 'oat\\taoQtiItem\\model\\qti\\response\\interactionResponseProcessing\\MapResponsePointTemplate'; break; case Custom::CLASS_ID : $className = 'oat\\taoQtiItem\\model\\qti\\response\\interactionResponseProcessing\\Custom'; break; default : throw new common_exception_Error('Unknown InteractionResponseProcessing Class ID "'.$classID.'"'); } $outcome = self::generateOutcomeDefinition(); $outcomes = $item->getOutcomes(); $outcomes[] = $outcome; $item->setOutcomes($outcomes); $returnValue = new $className($response, $outcome); return $returnValue; }
[ "public", "static", "function", "create", "(", "$", "classID", ",", "ResponseDeclaration", "$", "response", ",", "Item", "$", "item", ")", "{", "switch", "(", "$", "classID", ")", "{", "case", "None", "::", "CLASS_ID", ":", "$", "className", "=", "'oat\\...
Short description of method create @access public @author Joel Bout, <joel.bout@tudor.lu> @param int classID @param Response response @param Item item @return oat\taoQtiItem\model\qti\response\interactionResponseProcessing\InteractionResponseProcessing
[ "Short", "description", "of", "method", "create" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/response/interactionResponseProcessing/InteractionResponseProcessing.php#L99-L126
oat-sa/extension-tao-itemqti
model/update/ItemFixGhostResponse.php
ItemFixGhostResponse.updateItem
protected function updateItem(\oat\taoQtiItem\model\qti\Item $item, $itemFile) { $changed = false; $responses = $item->getResponses(); $interactions = $item->getInteractions(); $usedResponses = []; foreach($interactions as $interaction){ $usedResponses[] = $interaction->attr('responseIdentifier'); } foreach ($responses as $response) { $responseIdentifier = $response->attr('identifier'); if(!in_array($responseIdentifier, $usedResponses)){ $changed = true; $item->removeResponse($response); } } $xml = simplexml_load_file($itemFile); $rpTemplate = (string) $xml->responseProcessing['template']; //detect wrong usage for standard standard response declaration $rp = $item->getResponseProcessing(); if ($rp instanceof \oat\taoQtiItem\model\qti\response\TemplatesDriven && $rpTemplate) { if (count($interactions) > 1) { $changed = true; } else { $interaction = reset($interactions); if ($interaction && $interaction->attr('responseIdentifier') != 'RESPONSE') { $changed = true; } } } return $changed; }
php
protected function updateItem(\oat\taoQtiItem\model\qti\Item $item, $itemFile) { $changed = false; $responses = $item->getResponses(); $interactions = $item->getInteractions(); $usedResponses = []; foreach($interactions as $interaction){ $usedResponses[] = $interaction->attr('responseIdentifier'); } foreach ($responses as $response) { $responseIdentifier = $response->attr('identifier'); if(!in_array($responseIdentifier, $usedResponses)){ $changed = true; $item->removeResponse($response); } } $xml = simplexml_load_file($itemFile); $rpTemplate = (string) $xml->responseProcessing['template']; //detect wrong usage for standard standard response declaration $rp = $item->getResponseProcessing(); if ($rp instanceof \oat\taoQtiItem\model\qti\response\TemplatesDriven && $rpTemplate) { if (count($interactions) > 1) { $changed = true; } else { $interaction = reset($interactions); if ($interaction && $interaction->attr('responseIdentifier') != 'RESPONSE') { $changed = true; } } } return $changed; }
[ "protected", "function", "updateItem", "(", "\\", "oat", "\\", "taoQtiItem", "\\", "model", "\\", "qti", "\\", "Item", "$", "item", ",", "$", "itemFile", ")", "{", "$", "changed", "=", "false", ";", "$", "responses", "=", "$", "item", "->", "getRespons...
Remove unused response declaration from the items and rp template misuse @param oat\taoQtiItem\modal\Item $item @param string $itemFile @return boolean
[ "Remove", "unused", "response", "declaration", "from", "the", "items", "and", "rp", "template", "misuse" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/update/ItemFixGhostResponse.php#L44-L78
oat-sa/extension-tao-itemqti
model/qti/response/interactionResponseProcessing/Template.php
Template.createByTemplate
public static function createByTemplate($templateUri, ResponseDeclaration $response, Item $item) { $returnValue = null; switch ($templateUri) { case ResponseTemplate::MATCH_CORRECT : $returnValue = self::create(MatchCorrectTemplate::CLASS_ID, $response, $item); break; case ResponseTemplate::MAP_RESPONSE : $returnValue = self::create(MapResponseTemplate::CLASS_ID, $response, $item); break; case ResponseTemplate::MAP_RESPONSE_POINT : $returnValue = self::create(MapResponsePointTemplate::CLASS_ID, $response, $item); break; default : throw new ParsingException('Cannot create interactionResponseProcessing for unknown Template '.$templateUri); } return $returnValue; }
php
public static function createByTemplate($templateUri, ResponseDeclaration $response, Item $item) { $returnValue = null; switch ($templateUri) { case ResponseTemplate::MATCH_CORRECT : $returnValue = self::create(MatchCorrectTemplate::CLASS_ID, $response, $item); break; case ResponseTemplate::MAP_RESPONSE : $returnValue = self::create(MapResponseTemplate::CLASS_ID, $response, $item); break; case ResponseTemplate::MAP_RESPONSE_POINT : $returnValue = self::create(MapResponsePointTemplate::CLASS_ID, $response, $item); break; default : throw new ParsingException('Cannot create interactionResponseProcessing for unknown Template '.$templateUri); } return $returnValue; }
[ "public", "static", "function", "createByTemplate", "(", "$", "templateUri", ",", "ResponseDeclaration", "$", "response", ",", "Item", "$", "item", ")", "{", "$", "returnValue", "=", "null", ";", "switch", "(", "$", "templateUri", ")", "{", "case", "Response...
Short description of method createByTemplate @access public @author Joel Bout, <joel.bout@tudor.lu> @param string templateUri @param Response response @param Item item @return oat\taoQtiItem\model\qti\response\interactionResponseProcessing\InteractionResponseProcessing
[ "Short", "description", "of", "method", "createByTemplate" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/response/interactionResponseProcessing/Template.php#L57-L78
oat-sa/extension-tao-itemqti
model/qti/metadata/ontology/GenericLomOntologyClassificationExtractor.php
GenericLomOntologyClassificationExtractor.extract
public function extract($resource) { if (! $resource instanceof \core_kernel_classes_Resource) { throw new MetadataExtractionException(__('The given target is not an instance of core_kernel_classes_Resource')); } $identifier = \tao_helpers_Uri::getUniqueId($resource->getUri()); $metadata = array($identifier => []); $triples = $resource->getRdfTriples(); /** @var \core_kernel_classes_Triple $triple */ foreach ($triples->getIterator() as $triple) { /** @var \core_kernel_classes_Resource $property */ $property = $this->getResource($triple->predicate); $value = $triple->object; if (trim($value) != '' && $property->isProperty() && !in_array($property->getUri(), self::$excludedProperties) ) { $metadata[$identifier][] = new ClassificationMetadataValue( new ClassificationSourceMetadataValue($resource->getUri(), $property->getUri()), [new ClassificationEntryMetadataValue($resource->getUri(), $value)] ); } } if (empty($metadata[$identifier])) { return []; } return $metadata; }
php
public function extract($resource) { if (! $resource instanceof \core_kernel_classes_Resource) { throw new MetadataExtractionException(__('The given target is not an instance of core_kernel_classes_Resource')); } $identifier = \tao_helpers_Uri::getUniqueId($resource->getUri()); $metadata = array($identifier => []); $triples = $resource->getRdfTriples(); /** @var \core_kernel_classes_Triple $triple */ foreach ($triples->getIterator() as $triple) { /** @var \core_kernel_classes_Resource $property */ $property = $this->getResource($triple->predicate); $value = $triple->object; if (trim($value) != '' && $property->isProperty() && !in_array($property->getUri(), self::$excludedProperties) ) { $metadata[$identifier][] = new ClassificationMetadataValue( new ClassificationSourceMetadataValue($resource->getUri(), $property->getUri()), [new ClassificationEntryMetadataValue($resource->getUri(), $value)] ); } } if (empty($metadata[$identifier])) { return []; } return $metadata; }
[ "public", "function", "extract", "(", "$", "resource", ")", "{", "if", "(", "!", "$", "resource", "instanceof", "\\", "core_kernel_classes_Resource", ")", "{", "throw", "new", "MetadataExtractionException", "(", "__", "(", "'The given target is not an instance of core...
Extract resource metadata and transform it to ClassificationMetadataValue @param \core_kernel_classes_Resource $resource @return array @throws MetadataExtractionException @throws \oat\tao\model\metadata\exception\writer\MetadataWriterException
[ "Extract", "resource", "metadata", "and", "transform", "it", "to", "ClassificationMetadataValue" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/ontology/GenericLomOntologyClassificationExtractor.php#L56-L91
oat-sa/extension-tao-itemqti
helpers/CssHelper.php
CssHelper.saveCssFile
public static function saveCssFile(\core_kernel_classes_resource $item, $lang, $styleSheetPath, $cssArr) { $directory = \taoItems_models_classes_ItemsService::singleton()->getItemDirectory($item, $lang); $file = $directory->getFile($styleSheetPath); // make sure that 'no custom css' means exactly that if (empty($cssArr) && $file->exists()) { $file->delete(); } $css = self::_buildWarning() . self::arrayToCss($cssArr); return $file->put($css); }
php
public static function saveCssFile(\core_kernel_classes_resource $item, $lang, $styleSheetPath, $cssArr) { $directory = \taoItems_models_classes_ItemsService::singleton()->getItemDirectory($item, $lang); $file = $directory->getFile($styleSheetPath); // make sure that 'no custom css' means exactly that if (empty($cssArr) && $file->exists()) { $file->delete(); } $css = self::_buildWarning() . self::arrayToCss($cssArr); return $file->put($css); }
[ "public", "static", "function", "saveCssFile", "(", "\\", "core_kernel_classes_resource", "$", "item", ",", "$", "lang", ",", "$", "styleSheetPath", ",", "$", "cssArr", ")", "{", "$", "directory", "=", "\\", "taoItems_models_classes_ItemsService", "::", "singleton...
Stores an css array in the file @param \core_kernel_classes_resource $item @param string $lang @param string $styleSheetPath @param array $cssArr @return boolean true on success
[ "Stores", "an", "css", "array", "in", "the", "file" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/helpers/CssHelper.php#L40-L53