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/parser/itemParser/PortableElementItemParser.php
PortableElementItemParser.parsePortableElement
protected function parsePortableElement(PortableElementModel $model, Element $portableElement) { $typeId = $portableElement->getTypeIdentifier(); $libs = []; $librariesFiles = []; $entryPoint = []; //Adjust file resource entries where {QTI_NS}/xxx/yyy is equivalent to {QTI_NS}/xxx/yyy.js foreach($portableElement->getLibraries() as $lib){ if(preg_match('/^'.$typeId.'/', $lib) && substr($lib, -3) != '.js') {//filter shared stimulus $librariesFiles[] = $lib.'.js';//amd modules $libs[] = $lib.'.js'; }else{ $libs[] = $lib;//shared libs } } $moduleFiles = []; $emptyModules = [];//list of modules that are referenced directly in the module node $adjustedModules = []; foreach($portableElement->getModules() as $id => $paths){ $adjustedPaths = []; if(empty($paths)){ $emptyModules[] = $id; continue; } foreach($paths as $path){ if($this->isRelativePath($path)){ //only copy into data the relative files $moduleFiles[] = $path; $adjustedPaths[] = $this->getSourceAdjustedNodulePath($path); }else{ $adjustedPaths[] = $path; } } $adjustedModules[$id] = $adjustedPaths; } /** * Parse the standard portable configuration if applicable. * Local config files will be preloaded into the registry itself and the registered modules will be included as required dependency files. * Per standard, every config file have the following structure: * { * "waitSeconds": 15, * "paths": { * "graph": "https://example.com/js/modules/graph1.01/graph.js", * "foo": "foo/bar1.2/foo.js" * } * } */ $configDataArray = []; $configFiles = []; foreach($portableElement->getConfig() as $configFile){ //only read local config file if($this->isRelativePath($configFile)){ //save the content and file config data in registry, to allow later retrieval $configFiles[] = $configFile; //read the config file content $configData = json_decode(file_get_contents($this->itemDir . DIRECTORY_SEPARATOR . $configFile), true); if(!empty($configData)){ if(isset($configData['paths'])){ foreach($configData['paths'] as $id => $path){ //only copy the relative files to local portable element filesystem, absolute ones are loaded dynamically if($this->isRelativePath($path)){ //resolution of path, relative to the current config file it has been defined in $path = dirname($configFile) . DIRECTORY_SEPARATOR . $path; if(file_exists($this->itemDir . DIRECTORY_SEPARATOR . $path)){ $moduleFiles[] = $path; $configData['paths'][$id] = $this->getSourceAdjustedNodulePath($path);; }else{ throw new FileNotFoundException("The portable config {$configFile} references a missing module file {$id} => {$path}"); } } } } $configDataArray[] =[ 'file' => $this->getSourceAdjustedNodulePath($configFile), 'data' => $configData ]; } }else{ $configDataArray[] = ['file' => $configFile]; } } /** * In the standard IMS PCI, entry points become optionnal */ if(!empty($portableElement->getEntryPoint())){ $entryPoint[] = $portableElement->getEntryPoint(); } //register the files here $data = [ 'typeIdentifier' => $typeId, 'version' => $portableElement->getVersion(), 'label' => $typeId, 'short' => $typeId, 'runtime' => [ 'hook' => $portableElement->getEntryPoint(), 'libraries' => $libs, 'stylesheets' => $portableElement->getStylesheets(), 'mediaFiles' => $portableElement->getMediaFiles(), 'config' => $configDataArray, 'modules' => $adjustedModules ] ]; /** @var PortableElementObject $portableObject */ $portableObject = $model->createDataObject($data); $lastVersionModel = $this->getService()->getPortableElementByIdentifier( $portableObject->getModel()->getId(), $portableObject->getTypeIdentifier() ); if (!is_null($lastVersionModel) && (intval($lastVersionModel->getVersion()) != intVal($portableObject->getVersion())) ) { //@todo return a user exception to inform user of incompatible pci version found and that an item update is required throw new \common_Exception('Unable to import pci asset because pci is not compatible. ' . 'Current version is ' . $lastVersionModel->getVersion() . ' and imported is ' . $portableObject->getVersion()); } $this->portableObjects[$typeId] = $portableObject; $files = array_merge( $entryPoint, $librariesFiles, $configFiles, $moduleFiles, $portableObject->getRuntimeKey('stylesheets'), $portableObject->getRuntimeKey('mediaFiles') ); $this->requiredFiles = array_merge($this->requiredFiles, array_fill_keys($files, $typeId)); }
php
protected function parsePortableElement(PortableElementModel $model, Element $portableElement) { $typeId = $portableElement->getTypeIdentifier(); $libs = []; $librariesFiles = []; $entryPoint = []; //Adjust file resource entries where {QTI_NS}/xxx/yyy is equivalent to {QTI_NS}/xxx/yyy.js foreach($portableElement->getLibraries() as $lib){ if(preg_match('/^'.$typeId.'/', $lib) && substr($lib, -3) != '.js') {//filter shared stimulus $librariesFiles[] = $lib.'.js';//amd modules $libs[] = $lib.'.js'; }else{ $libs[] = $lib;//shared libs } } $moduleFiles = []; $emptyModules = [];//list of modules that are referenced directly in the module node $adjustedModules = []; foreach($portableElement->getModules() as $id => $paths){ $adjustedPaths = []; if(empty($paths)){ $emptyModules[] = $id; continue; } foreach($paths as $path){ if($this->isRelativePath($path)){ //only copy into data the relative files $moduleFiles[] = $path; $adjustedPaths[] = $this->getSourceAdjustedNodulePath($path); }else{ $adjustedPaths[] = $path; } } $adjustedModules[$id] = $adjustedPaths; } /** * Parse the standard portable configuration if applicable. * Local config files will be preloaded into the registry itself and the registered modules will be included as required dependency files. * Per standard, every config file have the following structure: * { * "waitSeconds": 15, * "paths": { * "graph": "https://example.com/js/modules/graph1.01/graph.js", * "foo": "foo/bar1.2/foo.js" * } * } */ $configDataArray = []; $configFiles = []; foreach($portableElement->getConfig() as $configFile){ //only read local config file if($this->isRelativePath($configFile)){ //save the content and file config data in registry, to allow later retrieval $configFiles[] = $configFile; //read the config file content $configData = json_decode(file_get_contents($this->itemDir . DIRECTORY_SEPARATOR . $configFile), true); if(!empty($configData)){ if(isset($configData['paths'])){ foreach($configData['paths'] as $id => $path){ //only copy the relative files to local portable element filesystem, absolute ones are loaded dynamically if($this->isRelativePath($path)){ //resolution of path, relative to the current config file it has been defined in $path = dirname($configFile) . DIRECTORY_SEPARATOR . $path; if(file_exists($this->itemDir . DIRECTORY_SEPARATOR . $path)){ $moduleFiles[] = $path; $configData['paths'][$id] = $this->getSourceAdjustedNodulePath($path);; }else{ throw new FileNotFoundException("The portable config {$configFile} references a missing module file {$id} => {$path}"); } } } } $configDataArray[] =[ 'file' => $this->getSourceAdjustedNodulePath($configFile), 'data' => $configData ]; } }else{ $configDataArray[] = ['file' => $configFile]; } } /** * In the standard IMS PCI, entry points become optionnal */ if(!empty($portableElement->getEntryPoint())){ $entryPoint[] = $portableElement->getEntryPoint(); } //register the files here $data = [ 'typeIdentifier' => $typeId, 'version' => $portableElement->getVersion(), 'label' => $typeId, 'short' => $typeId, 'runtime' => [ 'hook' => $portableElement->getEntryPoint(), 'libraries' => $libs, 'stylesheets' => $portableElement->getStylesheets(), 'mediaFiles' => $portableElement->getMediaFiles(), 'config' => $configDataArray, 'modules' => $adjustedModules ] ]; /** @var PortableElementObject $portableObject */ $portableObject = $model->createDataObject($data); $lastVersionModel = $this->getService()->getPortableElementByIdentifier( $portableObject->getModel()->getId(), $portableObject->getTypeIdentifier() ); if (!is_null($lastVersionModel) && (intval($lastVersionModel->getVersion()) != intVal($portableObject->getVersion())) ) { //@todo return a user exception to inform user of incompatible pci version found and that an item update is required throw new \common_Exception('Unable to import pci asset because pci is not compatible. ' . 'Current version is ' . $lastVersionModel->getVersion() . ' and imported is ' . $portableObject->getVersion()); } $this->portableObjects[$typeId] = $portableObject; $files = array_merge( $entryPoint, $librariesFiles, $configFiles, $moduleFiles, $portableObject->getRuntimeKey('stylesheets'), $portableObject->getRuntimeKey('mediaFiles') ); $this->requiredFiles = array_merge($this->requiredFiles, array_fill_keys($files, $typeId)); }
[ "protected", "function", "parsePortableElement", "(", "PortableElementModel", "$", "model", ",", "Element", "$", "portableElement", ")", "{", "$", "typeId", "=", "$", "portableElement", "->", "getTypeIdentifier", "(", ")", ";", "$", "libs", "=", "[", "]", ";",...
Parse individual portable element into the given portable model @param PortableElementModel $model @param Element $portableElement @throws \common_Exception @throws PortableElementInconsistencyModelException
[ "Parse", "individual", "portable", "element", "into", "the", "given", "portable", "model" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/parser/itemParser/PortableElementItemParser.php#L200-L338
oat-sa/extension-tao-itemqti
model/portableElement/parser/itemParser/PortableElementItemParser.php
PortableElementItemParser.importPortableElements
public function importPortableElements() { if (count($this->importingFiles) != count($this->requiredFiles)) { throw new \common_Exception('Needed files are missing during Portable Element asset files '.print_r($this->requiredFiles, true). ' '.print_r($this->importingFiles, true)); } /** @var PortableElementObject $object */ foreach ($this->portableObjects as $object) { $lastVersionModel = $this->getService()->getPortableElementByIdentifier( $object->getModel()->getId(), $object->getTypeIdentifier() ); //only register a pci that has not been register yet, subsequent update must be done through pci package import if (is_null($lastVersionModel)){ $this->getService()->registerModel( $object, $object->getRegistrationSourcePath($this->source, $this->itemDir) ); } else { \common_Logger::i('The imported item contains the portable element '.$object->getTypeIdentifier() .' in a version '.$object->getVersion().' compatible with the current '.$lastVersionModel->getVersion()); } } return true; }
php
public function importPortableElements() { if (count($this->importingFiles) != count($this->requiredFiles)) { throw new \common_Exception('Needed files are missing during Portable Element asset files '.print_r($this->requiredFiles, true). ' '.print_r($this->importingFiles, true)); } /** @var PortableElementObject $object */ foreach ($this->portableObjects as $object) { $lastVersionModel = $this->getService()->getPortableElementByIdentifier( $object->getModel()->getId(), $object->getTypeIdentifier() ); //only register a pci that has not been register yet, subsequent update must be done through pci package import if (is_null($lastVersionModel)){ $this->getService()->registerModel( $object, $object->getRegistrationSourcePath($this->source, $this->itemDir) ); } else { \common_Logger::i('The imported item contains the portable element '.$object->getTypeIdentifier() .' in a version '.$object->getVersion().' compatible with the current '.$lastVersionModel->getVersion()); } } return true; }
[ "public", "function", "importPortableElements", "(", ")", "{", "if", "(", "count", "(", "$", "this", "->", "importingFiles", ")", "!=", "count", "(", "$", "this", "->", "requiredFiles", ")", ")", "{", "throw", "new", "\\", "common_Exception", "(", "'Needed...
Do the import of portable elements
[ "Do", "the", "import", "of", "portable", "elements" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/parser/itemParser/PortableElementItemParser.php#L376-L400
oat-sa/extension-tao-itemqti
model/portableElement/parser/itemParser/PortableElementItemParser.php
PortableElementItemParser.replaceLibAliases
private function replaceLibAliases(PortableElementObject $object){ $id = $object->getTypeIdentifier(); $object->setRuntimeKey('libraries', array_map(function($lib) use ($id) { if(preg_match('/^'.$id.'/', $lib)){ return $lib.'.js'; } return $lib; }, $object->getRuntimeKey('libraries'))); return $object; }
php
private function replaceLibAliases(PortableElementObject $object){ $id = $object->getTypeIdentifier(); $object->setRuntimeKey('libraries', array_map(function($lib) use ($id) { if(preg_match('/^'.$id.'/', $lib)){ return $lib.'.js'; } return $lib; }, $object->getRuntimeKey('libraries'))); return $object; }
[ "private", "function", "replaceLibAliases", "(", "PortableElementObject", "$", "object", ")", "{", "$", "id", "=", "$", "object", "->", "getTypeIdentifier", "(", ")", ";", "$", "object", "->", "setRuntimeKey", "(", "'libraries'", ",", "array_map", "(", "functi...
Replace the libs aliases with their relative url before saving into the registry This format is consistent with the format of TAO portable package manifest @param PortableElementObject $object @return PortableElementObject
[ "Replace", "the", "libs", "aliases", "with", "their", "relative", "url", "before", "saving", "into", "the", "registry", "This", "format", "is", "consistent", "with", "the", "format", "of", "TAO", "portable", "package", "manifest" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/parser/itemParser/PortableElementItemParser.php#L409-L420
oat-sa/extension-tao-itemqti
model/Listener/ItemUpdater.php
ItemUpdater.catchItemRdfUpdatedEvent
public static function catchItemRdfUpdatedEvent(ItemRdfUpdatedEvent $event) { $rdfItem = new core_kernel_classes_Resource($event->getItemUri()); $type = $rdfItem->getProperty(taoItems_models_classes_ItemsService::PROPERTY_ITEM_MODEL); /*@var $directory \oat\oatbox\filesystem\Directory */ $directory = taoItems_models_classes_ItemsService::singleton()->getItemDirectory($rdfItem); $itemModel = $rdfItem->getPropertyValues($type); if($directory->exists() && in_array(taoItems_models_classes_itemModel::CLASS_URI_QTI, $itemModel) ) { /* @var $file File */ $file = $directory->getFile(Service::QTI_ITEM_FILE); $qtiParser = new Parser($file->read()); $qtiItem = $qtiParser->load(); $label = mb_substr($rdfItem->getLabel(), 0, 256, 'UTF-8'); $qtiItem->setAttribute('label', $label); $file->put($qtiItem->toXML()); } }
php
public static function catchItemRdfUpdatedEvent(ItemRdfUpdatedEvent $event) { $rdfItem = new core_kernel_classes_Resource($event->getItemUri()); $type = $rdfItem->getProperty(taoItems_models_classes_ItemsService::PROPERTY_ITEM_MODEL); /*@var $directory \oat\oatbox\filesystem\Directory */ $directory = taoItems_models_classes_ItemsService::singleton()->getItemDirectory($rdfItem); $itemModel = $rdfItem->getPropertyValues($type); if($directory->exists() && in_array(taoItems_models_classes_itemModel::CLASS_URI_QTI, $itemModel) ) { /* @var $file File */ $file = $directory->getFile(Service::QTI_ITEM_FILE); $qtiParser = new Parser($file->read()); $qtiItem = $qtiParser->load(); $label = mb_substr($rdfItem->getLabel(), 0, 256, 'UTF-8'); $qtiItem->setAttribute('label', $label); $file->put($qtiItem->toXML()); } }
[ "public", "static", "function", "catchItemRdfUpdatedEvent", "(", "ItemRdfUpdatedEvent", "$", "event", ")", "{", "$", "rdfItem", "=", "new", "core_kernel_classes_Resource", "(", "$", "event", "->", "getItemUri", "(", ")", ")", ";", "$", "type", "=", "$", "rdfIt...
synchronise item label @param ItemRdfUpdatedEvent $event
[ "synchronise", "item", "label" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/Listener/ItemUpdater.php#L40-L57
oat-sa/extension-tao-itemqti
model/qti/metadata/imsManifest/ImsManifestMapping.php
ImsManifestMapping.setNamespace
public function setNamespace($namespace) { if (is_string($namespace) === false) { $msg = "The namespace argument must be a string."; throw new InvalidArgumentException($msg); } elseif ($namespace === '') { $msg = "The namespace argument must be a non-empty string."; throw new InvalidArgumentException($msg); } else { $this->namespace = $namespace; } }
php
public function setNamespace($namespace) { if (is_string($namespace) === false) { $msg = "The namespace argument must be a string."; throw new InvalidArgumentException($msg); } elseif ($namespace === '') { $msg = "The namespace argument must be a non-empty string."; throw new InvalidArgumentException($msg); } else { $this->namespace = $namespace; } }
[ "public", "function", "setNamespace", "(", "$", "namespace", ")", "{", "if", "(", "is_string", "(", "$", "namespace", ")", "===", "false", ")", "{", "$", "msg", "=", "\"The namespace argument must be a string.\"", ";", "throw", "new", "InvalidArgumentException", ...
Set the XML namespace of the mapping. @param string $namespace An XML namespace e.g. "http://www.imsglobal.org/xsd/imsmd_v1p2p2". @throws InvalidArgumentException If $namespace is not a string or an empty string.
[ "Set", "the", "XML", "namespace", "of", "the", "mapping", "." ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/imsManifest/ImsManifestMapping.php#L82-L93
oat-sa/extension-tao-itemqti
model/qti/metadata/imsManifest/ImsManifestMapping.php
ImsManifestMapping.setPrefix
public function setPrefix($prefix) { if (is_string($prefix) === false) { $msg = "The prefix argument must be a string."; throw new InvalidArgumentException($msg); } elseif ($prefix === '') { $msg = "The prefix argument must be a non-empty string."; throw new InvalidArgumentException($msg); } else { $this->prefix = $prefix; } }
php
public function setPrefix($prefix) { if (is_string($prefix) === false) { $msg = "The prefix argument must be a string."; throw new InvalidArgumentException($msg); } elseif ($prefix === '') { $msg = "The prefix argument must be a non-empty string."; throw new InvalidArgumentException($msg); } else { $this->prefix = $prefix; } }
[ "public", "function", "setPrefix", "(", "$", "prefix", ")", "{", "if", "(", "is_string", "(", "$", "prefix", ")", "===", "false", ")", "{", "$", "msg", "=", "\"The prefix argument must be a string.\"", ";", "throw", "new", "InvalidArgumentException", "(", "$",...
Set the XML prefix of the mapping. @param string $prefix An XML prefix e.g. "imsmd". @throws InvalidArgumentException If $prefix is not a string or an empty string.
[ "Set", "the", "XML", "prefix", "of", "the", "mapping", "." ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/imsManifest/ImsManifestMapping.php#L111-L122
oat-sa/extension-tao-itemqti
model/qti/metadata/imsManifest/ImsManifestMapping.php
ImsManifestMapping.setSchemaLocation
public function setSchemaLocation($schemaLocation) { if (is_string($schemaLocation) === false) { $msg = "The schemaLocation argument must be a string."; throw new InvalidArgumentException($msg); } elseif ($schemaLocation === '') { $msg = "The schemaLocation argument cannot be empty."; throw new InvalidArgumentException($msg); } else { $this->schemaLocation = $schemaLocation; } }
php
public function setSchemaLocation($schemaLocation) { if (is_string($schemaLocation) === false) { $msg = "The schemaLocation argument must be a string."; throw new InvalidArgumentException($msg); } elseif ($schemaLocation === '') { $msg = "The schemaLocation argument cannot be empty."; throw new InvalidArgumentException($msg); } else { $this->schemaLocation = $schemaLocation; } }
[ "public", "function", "setSchemaLocation", "(", "$", "schemaLocation", ")", "{", "if", "(", "is_string", "(", "$", "schemaLocation", ")", "===", "false", ")", "{", "$", "msg", "=", "\"The schemaLocation argument must be a string.\"", ";", "throw", "new", "InvalidA...
Set the XSD (XML Schema Definition) schema location of the mapping. @param string $schemaLocation A schema location e.g. "http://www.imsglobal.org/xsd/imsmd_v1p2p2.xsd". @throws InvalidArgumentException If $schemaLocatuion is not a string or an empty string.
[ "Set", "the", "XSD", "(", "XML", "Schema", "Definition", ")", "schema", "location", "of", "the", "mapping", "." ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/imsManifest/ImsManifestMapping.php#L140-L151
oat-sa/extension-tao-itemqti
model/flyExporter/simpleExporter/ItemExporter.php
ItemExporter.export
public function export(array $items = null) { if (empty($items)) { $items = $this->getItems(); } $data = $this->getDataByItems($items); return $this->save($this->headers, $data); }
php
public function export(array $items = null) { if (empty($items)) { $items = $this->getItems(); } $data = $this->getDataByItems($items); return $this->save($this->headers, $data); }
[ "public", "function", "export", "(", "array", "$", "items", "=", "null", ")", "{", "if", "(", "empty", "(", "$", "items", ")", ")", "{", "$", "items", "=", "$", "this", "->", "getItems", "(", ")", ";", "}", "$", "data", "=", "$", "this", "->", ...
@inheritdoc @throws ExtractorException @param \core_kernel_classes_Resource[] $items @return string
[ "@inheritdoc" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/flyExporter/simpleExporter/ItemExporter.php#L111-L120
oat-sa/extension-tao-itemqti
model/flyExporter/simpleExporter/ItemExporter.php
ItemExporter.getDataByItems
public function getDataByItems(array $items) { $output = []; foreach ($items as $item) { try { $output[] = $this->getDataByItem($item); } catch (ExtractorException $e) { \common_Logger::e('ERROR on item ' . $item->getUri() . ' : ' . $e->getMessage()); } } if (empty($output)) { throw new ExtractorException('No data item to export.'); } return $output; }
php
public function getDataByItems(array $items) { $output = []; foreach ($items as $item) { try { $output[] = $this->getDataByItem($item); } catch (ExtractorException $e) { \common_Logger::e('ERROR on item ' . $item->getUri() . ' : ' . $e->getMessage()); } } if (empty($output)) { throw new ExtractorException('No data item to export.'); } return $output; }
[ "public", "function", "getDataByItems", "(", "array", "$", "items", ")", "{", "$", "output", "=", "[", "]", ";", "foreach", "(", "$", "items", "as", "$", "item", ")", "{", "try", "{", "$", "output", "[", "]", "=", "$", "this", "->", "getDataByItem"...
Loop all items and call extract function @param array $items @return array @throws ExtractorException
[ "Loop", "all", "items", "and", "call", "extract", "function" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/flyExporter/simpleExporter/ItemExporter.php#L129-L145
oat-sa/extension-tao-itemqti
model/flyExporter/simpleExporter/ItemExporter.php
ItemExporter.getDataByItem
public function getDataByItem(\core_kernel_classes_Resource $item) { foreach ($this->columns as $column => $config) { /** @var Extractor $extractor */ $extractor = $this->extractors[$config['extractor']]; if (isset($config['parameters'])) { $parameters = $config['parameters']; } else { $parameters = []; } $extractor->addColumn($column, $parameters); } $data = ['0' => []]; foreach ($this->extractors as $extractor) { $extractor->setItem($item); $extractor->run(); $values = $extractor->getData(); foreach ($values as $key => $value) { $interactionData = is_array($value) && count($value) > 1 ? $value : $values; if (array_values(array_intersect(array_keys($data[0]), array_keys($interactionData))) == array_keys($interactionData)) { $line = array_intersect_key($data[0], array_flip($this->headers)); $data[] = array_merge($line, $interactionData); } else { $data[0] = array_merge($data[0], $interactionData); } $this->headers = array_unique(array_merge($this->headers, array_keys($interactionData))); } } return $data; }
php
public function getDataByItem(\core_kernel_classes_Resource $item) { foreach ($this->columns as $column => $config) { /** @var Extractor $extractor */ $extractor = $this->extractors[$config['extractor']]; if (isset($config['parameters'])) { $parameters = $config['parameters']; } else { $parameters = []; } $extractor->addColumn($column, $parameters); } $data = ['0' => []]; foreach ($this->extractors as $extractor) { $extractor->setItem($item); $extractor->run(); $values = $extractor->getData(); foreach ($values as $key => $value) { $interactionData = is_array($value) && count($value) > 1 ? $value : $values; if (array_values(array_intersect(array_keys($data[0]), array_keys($interactionData))) == array_keys($interactionData)) { $line = array_intersect_key($data[0], array_flip($this->headers)); $data[] = array_merge($line, $interactionData); } else { $data[0] = array_merge($data[0], $interactionData); } $this->headers = array_unique(array_merge($this->headers, array_keys($interactionData))); } } return $data; }
[ "public", "function", "getDataByItem", "(", "\\", "core_kernel_classes_Resource", "$", "item", ")", "{", "foreach", "(", "$", "this", "->", "columns", "as", "$", "column", "=>", "$", "config", ")", "{", "/** @var Extractor $extractor */", "$", "extractor", "=", ...
Loop foreach columns and extract data thought extractors @param \core_kernel_classes_Resource $item @return array
[ "Loop", "foreach", "columns", "and", "extract", "data", "thought", "extractors" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/flyExporter/simpleExporter/ItemExporter.php#L153-L189
oat-sa/extension-tao-itemqti
model/flyExporter/simpleExporter/ItemExporter.php
ItemExporter.save
public function save(array $headers, array $data) { $output = $contents = []; $enclosure = $this->getCsvEnclosure(); $delimiter = $this->getCsvDelimiter(); $contents[] = $enclosure . implode($enclosure . $delimiter . $enclosure, $headers) . $enclosure; if (!empty($data)) { foreach ($data as $item) { foreach ($item as $line) { foreach ($headers as $index => $value) { if (isset($line[$value]) && $line[$value] !== '') { $output[$value] = $enclosure . (string)$line[$value] . $enclosure; unset($line[$value]); } else { $output[$value] = ''; } } $contents[] = implode($delimiter, array_merge($output, $line)); } } } $filePath = $this->getFilePath(); if (file_put_contents($filePath, chr(239) . chr(187) . chr(191) . implode("\n", $contents))) { return $filePath; } return ''; }
php
public function save(array $headers, array $data) { $output = $contents = []; $enclosure = $this->getCsvEnclosure(); $delimiter = $this->getCsvDelimiter(); $contents[] = $enclosure . implode($enclosure . $delimiter . $enclosure, $headers) . $enclosure; if (!empty($data)) { foreach ($data as $item) { foreach ($item as $line) { foreach ($headers as $index => $value) { if (isset($line[$value]) && $line[$value] !== '') { $output[$value] = $enclosure . (string)$line[$value] . $enclosure; unset($line[$value]); } else { $output[$value] = ''; } } $contents[] = implode($delimiter, array_merge($output, $line)); } } } $filePath = $this->getFilePath(); if (file_put_contents($filePath, chr(239) . chr(187) . chr(191) . implode("\n", $contents))) { return $filePath; } return ''; }
[ "public", "function", "save", "(", "array", "$", "headers", ",", "array", "$", "data", ")", "{", "$", "output", "=", "$", "contents", "=", "[", "]", ";", "$", "enclosure", "=", "$", "this", "->", "getCsvEnclosure", "(", ")", ";", "$", "delimiter", ...
Save data to file @param array $headers @param array $data @return string
[ "Save", "data", "to", "file" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/flyExporter/simpleExporter/ItemExporter.php#L198-L232
oat-sa/extension-tao-itemqti
model/flyExporter/simpleExporter/ItemExporter.php
ItemExporter.getCsvEnclosure
protected function getCsvEnclosure() { if ($this->hasOption(self::CSV_ENCLOSURE_OPTION)) { return $this->getOption(self::CSV_ENCLOSURE_OPTION); } return self::CSV_ENCLOSURE; }
php
protected function getCsvEnclosure() { if ($this->hasOption(self::CSV_ENCLOSURE_OPTION)) { return $this->getOption(self::CSV_ENCLOSURE_OPTION); } return self::CSV_ENCLOSURE; }
[ "protected", "function", "getCsvEnclosure", "(", ")", "{", "if", "(", "$", "this", "->", "hasOption", "(", "self", "::", "CSV_ENCLOSURE_OPTION", ")", ")", "{", "return", "$", "this", "->", "getOption", "(", "self", "::", "CSV_ENCLOSURE_OPTION", ")", ";", "...
Get the CSV enclosure from config, if not set use default value @return string
[ "Get", "the", "CSV", "enclosure", "from", "config", "if", "not", "set", "use", "default", "value" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/flyExporter/simpleExporter/ItemExporter.php#L285-L292
oat-sa/extension-tao-itemqti
model/flyExporter/simpleExporter/ItemExporter.php
ItemExporter.getCsvDelimiter
protected function getCsvDelimiter() { if ($this->hasOption(self::CSV_DELIMITER_OPTION)) { return $this->getOption(self::CSV_DELIMITER_OPTION); } return self::CSV_DELIMITER; }
php
protected function getCsvDelimiter() { if ($this->hasOption(self::CSV_DELIMITER_OPTION)) { return $this->getOption(self::CSV_DELIMITER_OPTION); } return self::CSV_DELIMITER; }
[ "protected", "function", "getCsvDelimiter", "(", ")", "{", "if", "(", "$", "this", "->", "hasOption", "(", "self", "::", "CSV_DELIMITER_OPTION", ")", ")", "{", "return", "$", "this", "->", "getOption", "(", "self", "::", "CSV_DELIMITER_OPTION", ")", ";", "...
Get the CSV delimiter from config, if not set use default value @return string
[ "Get", "the", "CSV", "delimiter", "from", "config", "if", "not", "set", "use", "default", "value" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/flyExporter/simpleExporter/ItemExporter.php#L299-L306
oat-sa/extension-tao-itemqti
model/qti/metadata/imsManifest/classificationMetadata/ClassificationSourceMetadataValue.php
ClassificationSourceMetadataValue.getSourcePath
static public function getSourcePath() { return [ LomMetadata::LOM_NAMESPACE . '#lom', LomMetadata::LOM_NAMESPACE . '#classification', LomMetadata::LOM_NAMESPACE . '#taxonPath', LomMetadata::LOM_NAMESPACE . '#source', LomMetadata::LOM_NAMESPACE . '#string' ]; }
php
static public function getSourcePath() { return [ LomMetadata::LOM_NAMESPACE . '#lom', LomMetadata::LOM_NAMESPACE . '#classification', LomMetadata::LOM_NAMESPACE . '#taxonPath', LomMetadata::LOM_NAMESPACE . '#source', LomMetadata::LOM_NAMESPACE . '#string' ]; }
[ "static", "public", "function", "getSourcePath", "(", ")", "{", "return", "[", "LomMetadata", "::", "LOM_NAMESPACE", ".", "'#lom'", ",", "LomMetadata", "::", "LOM_NAMESPACE", ".", "'#classification'", ",", "LomMetadata", "::", "LOM_NAMESPACE", ".", "'#taxonPath'", ...
Get the default classification source path
[ "Get", "the", "default", "classification", "source", "path" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/imsManifest/classificationMetadata/ClassificationSourceMetadataValue.php#L43-L52
oat-sa/extension-tao-itemqti
model/pack/QtiItemPacker.php
QtiItemPacker.packItem
public function packItem(core_kernel_classes_Resource $item, $lang, Directory $directory) { //use the QtiParser to transform the QTI XML into an assoc array representation $content = $this->getXmlByItem($item, $lang); //load content $qtiParser = new QtiParser($content); //validate it $qtiParser->validate(); if (!$qtiParser->isValid()) { throw new common_Exception('Invalid QTI content : ' . $qtiParser->displayErrors(false)); } //parse $qtiItem = $qtiParser->load(); return $this->packQtiItem($item, $lang, $qtiItem, $directory); }
php
public function packItem(core_kernel_classes_Resource $item, $lang, Directory $directory) { //use the QtiParser to transform the QTI XML into an assoc array representation $content = $this->getXmlByItem($item, $lang); //load content $qtiParser = new QtiParser($content); //validate it $qtiParser->validate(); if (!$qtiParser->isValid()) { throw new common_Exception('Invalid QTI content : ' . $qtiParser->displayErrors(false)); } //parse $qtiItem = $qtiParser->load(); return $this->packQtiItem($item, $lang, $qtiItem, $directory); }
[ "public", "function", "packItem", "(", "core_kernel_classes_Resource", "$", "item", ",", "$", "lang", ",", "Directory", "$", "directory", ")", "{", "//use the QtiParser to transform the QTI XML into an assoc array representation", "$", "content", "=", "$", "this", "->", ...
packItem implementation for QTI @inheritdoc @see {@link ItemPacker} @throws InvalidArgumentException @throws common_Exception
[ "packItem", "implementation", "for", "QTI" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/pack/QtiItemPacker.php#L67-L84
oat-sa/extension-tao-itemqti
model/QtiItemCompiler.php
QtiItemCompiler.compile
public function compile() { $report = $this->internalCompile(); if ($report->getType() == common_report_Report::TYPE_SUCCESS) { // replace instances with service list($item, $publicDirectory, $privateDirectory) = $report->getData(); $report->setData($this->createQtiService($item, $publicDirectory, $privateDirectory)); } return $report; }
php
public function compile() { $report = $this->internalCompile(); if ($report->getType() == common_report_Report::TYPE_SUCCESS) { // replace instances with service list($item, $publicDirectory, $privateDirectory) = $report->getData(); $report->setData($this->createQtiService($item, $publicDirectory, $privateDirectory)); } return $report; }
[ "public", "function", "compile", "(", ")", "{", "$", "report", "=", "$", "this", "->", "internalCompile", "(", ")", ";", "if", "(", "$", "report", "->", "getType", "(", ")", "==", "common_report_Report", "::", "TYPE_SUCCESS", ")", "{", "// replace instance...
{@inheritDoc} @see \tao_models_classes_Compiler::compile()
[ "{" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/QtiItemCompiler.php#L61-L70
oat-sa/extension-tao-itemqti
model/QtiItemCompiler.php
QtiItemCompiler.internalCompile
protected function internalCompile() { $item = $this->getResource(); $publicDirectory = $this->spawnPublicDirectory(); $privateDirectory = $this->spawnPrivateDirectory(); $report = new common_report_Report(common_report_Report::TYPE_SUCCESS, __('Published %s', $item->getLabel())); $report->setData([$item, $publicDirectory, $privateDirectory]); $langs = $this->getContentUsedLanguages(); if (empty($langs)) { $report->setType(common_report_Report::TYPE_ERROR); $report->setMessage(__('Item "%s" is not available in any language', $item->getLabel())); } foreach ($langs as $compilationLanguage) { $langReport = $this->deployQtiItem($item, $compilationLanguage, $publicDirectory, $privateDirectory); $report->add($langReport); if ($langReport->getType() == common_report_Report::TYPE_ERROR) { $report->setType(common_report_Report::TYPE_ERROR); $report->setMessage(__('Failed to publish %1$s in %2$s', $item->getLabel(), $compilationLanguage)); break; } } return $report; }
php
protected function internalCompile() { $item = $this->getResource(); $publicDirectory = $this->spawnPublicDirectory(); $privateDirectory = $this->spawnPrivateDirectory(); $report = new common_report_Report(common_report_Report::TYPE_SUCCESS, __('Published %s', $item->getLabel())); $report->setData([$item, $publicDirectory, $privateDirectory]); $langs = $this->getContentUsedLanguages(); if (empty($langs)) { $report->setType(common_report_Report::TYPE_ERROR); $report->setMessage(__('Item "%s" is not available in any language', $item->getLabel())); } foreach ($langs as $compilationLanguage) { $langReport = $this->deployQtiItem($item, $compilationLanguage, $publicDirectory, $privateDirectory); $report->add($langReport); if ($langReport->getType() == common_report_Report::TYPE_ERROR) { $report->setType(common_report_Report::TYPE_ERROR); $report->setMessage(__('Failed to publish %1$s in %2$s', $item->getLabel(), $compilationLanguage)); break; } } return $report; }
[ "protected", "function", "internalCompile", "(", ")", "{", "$", "item", "=", "$", "this", "->", "getResource", "(", ")", ";", "$", "publicDirectory", "=", "$", "this", "->", "spawnPublicDirectory", "(", ")", ";", "$", "privateDirectory", "=", "$", "this", ...
Compile qti item @throws taoItems_models_classes_CompilationFailedException @return common_report_Report
[ "Compile", "qti", "item" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/QtiItemCompiler.php#L78-L101
oat-sa/extension-tao-itemqti
model/QtiItemCompiler.php
QtiItemCompiler.createQtiService
protected function createQtiService( core_kernel_classes_Resource $item, tao_models_classes_service_StorageDirectory $publicDirectory, tao_models_classes_service_StorageDirectory $privateDirectory ) { $service = new tao_models_classes_service_ServiceCall(new core_kernel_classes_Resource(self::INSTANCE_ITEMRUNNER)); $service->addInParameter(new tao_models_classes_service_ConstantParameter( new core_kernel_classes_Resource(taoItems_models_classes_ItemsService::INSTANCE_FORMAL_PARAM_ITEM_PATH), $publicDirectory->getId() ) ); $service->addInParameter( new tao_models_classes_service_ConstantParameter( new core_kernel_classes_Resource(taoItems_models_classes_ItemsService::INSTANCE_FORMAL_PARAM_ITEM_DATA_PATH), $privateDirectory->getId() ) ); $service->addInParameter( new tao_models_classes_service_ConstantParameter( new core_kernel_classes_Resource(taoItems_models_classes_ItemsService::INSTANCE_FORMAL_PARAM_ITEM_URI), $item ) ); return $service; }
php
protected function createQtiService( core_kernel_classes_Resource $item, tao_models_classes_service_StorageDirectory $publicDirectory, tao_models_classes_service_StorageDirectory $privateDirectory ) { $service = new tao_models_classes_service_ServiceCall(new core_kernel_classes_Resource(self::INSTANCE_ITEMRUNNER)); $service->addInParameter(new tao_models_classes_service_ConstantParameter( new core_kernel_classes_Resource(taoItems_models_classes_ItemsService::INSTANCE_FORMAL_PARAM_ITEM_PATH), $publicDirectory->getId() ) ); $service->addInParameter( new tao_models_classes_service_ConstantParameter( new core_kernel_classes_Resource(taoItems_models_classes_ItemsService::INSTANCE_FORMAL_PARAM_ITEM_DATA_PATH), $privateDirectory->getId() ) ); $service->addInParameter( new tao_models_classes_service_ConstantParameter( new core_kernel_classes_Resource(taoItems_models_classes_ItemsService::INSTANCE_FORMAL_PARAM_ITEM_URI), $item ) ); return $service; }
[ "protected", "function", "createQtiService", "(", "core_kernel_classes_Resource", "$", "item", ",", "tao_models_classes_service_StorageDirectory", "$", "publicDirectory", ",", "tao_models_classes_service_StorageDirectory", "$", "privateDirectory", ")", "{", "$", "service", "=",...
Create a servicecall that runs the prepared qti item @param core_kernel_classes_Resource $item @param tao_models_classes_service_StorageDirectory $publicDirectory @param tao_models_classes_service_StorageDirectory $privateDirectory @return tao_models_classes_service_ServiceCall
[ "Create", "a", "servicecall", "that", "runs", "the", "prepared", "qti", "item" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/QtiItemCompiler.php#L111-L134
oat-sa/extension-tao-itemqti
model/QtiItemCompiler.php
QtiItemCompiler.deployQtiItem
protected function deployQtiItem( core_kernel_classes_Resource $item, $language, tao_models_classes_service_StorageDirectory $publicDirectory, tao_models_classes_service_StorageDirectory $privateDirectory ) { $itemService = taoItems_models_classes_ItemsService::singleton(); $qtiService = Service::singleton(); //copy item.xml file to private directory $itemDir = $itemService->getItemDirectory($item, $language); $sourceItem = $itemDir->getFile('qti.xml'); $privateDirectory->writeStream($language . '/qti.xml', $sourceItem->readStream()); //copy client side resources (javascript loader) $qtiItemDir = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiItem')->getDir(); $taoDir = \common_ext_ExtensionsManager::singleton()->getExtensionById('tao')->getDir(); $assetPath = $qtiItemDir . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR; $assetLibPath = $taoDir . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR; if (\tao_helpers_Mode::is('production')) { $fh = fopen($assetPath . 'loader' . DIRECTORY_SEPARATOR . 'qtiLoader.min.js','r'); $publicDirectory->writeStream($language.'/qtiLoader.min.js', $fh); fclose($fh); } else { $fh = fopen($assetPath . 'runtime' . DIRECTORY_SEPARATOR . 'qtiLoader.js','r'); $publicDirectory->writeStream($language.'/qtiLoader.js', $fh); fclose($fh); $fh = fopen($assetLibPath . 'require.js','r'); $publicDirectory->writeStream($language.'/require.js', $fh); fclose($fh); } // retrieve the media assets try { $qtiItem = $this->retrieveAssets($item, $language, $publicDirectory); $this->compileItemIndex($item->getUri(), $qtiItem, $language); //store variable qti elements data into the private directory $variableElements = $qtiService->getVariableElements($qtiItem); $stream = \GuzzleHttp\Psr7\stream_for(json_encode($variableElements)); $privateDirectory->writePsrStream($language.'/variableElements.json', $stream); $stream->close(); // render item based on the modified QtiItem $xhtml = $qtiService->renderQTIItem($qtiItem, $language); //note : no need to manually copy qti or other third party lib files, all dependencies are managed by requirejs // write index.html $stream = \GuzzleHttp\Psr7\stream_for($xhtml); $publicDirectory->writePsrStream($language.'/index.html', $stream, 'text/html'); $stream->close(); return new common_report_Report( common_report_Report::TYPE_SUCCESS, __('Successfully compiled "%s"', $language) ); } catch (\tao_models_classes_FileNotFoundException $e) { return new common_report_Report( common_report_Report::TYPE_ERROR, __('Unable to retrieve asset "%s"', $e->getFilePath()) ); } catch (XIncludeException $e){ return new common_report_Report( common_report_Report::TYPE_ERROR, $e->getUserMessage() ); } catch (\Exception $e){ return new common_report_Report( common_report_Report::TYPE_ERROR, $e->getMessage() ); } }
php
protected function deployQtiItem( core_kernel_classes_Resource $item, $language, tao_models_classes_service_StorageDirectory $publicDirectory, tao_models_classes_service_StorageDirectory $privateDirectory ) { $itemService = taoItems_models_classes_ItemsService::singleton(); $qtiService = Service::singleton(); //copy item.xml file to private directory $itemDir = $itemService->getItemDirectory($item, $language); $sourceItem = $itemDir->getFile('qti.xml'); $privateDirectory->writeStream($language . '/qti.xml', $sourceItem->readStream()); //copy client side resources (javascript loader) $qtiItemDir = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoQtiItem')->getDir(); $taoDir = \common_ext_ExtensionsManager::singleton()->getExtensionById('tao')->getDir(); $assetPath = $qtiItemDir . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR; $assetLibPath = $taoDir . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR; if (\tao_helpers_Mode::is('production')) { $fh = fopen($assetPath . 'loader' . DIRECTORY_SEPARATOR . 'qtiLoader.min.js','r'); $publicDirectory->writeStream($language.'/qtiLoader.min.js', $fh); fclose($fh); } else { $fh = fopen($assetPath . 'runtime' . DIRECTORY_SEPARATOR . 'qtiLoader.js','r'); $publicDirectory->writeStream($language.'/qtiLoader.js', $fh); fclose($fh); $fh = fopen($assetLibPath . 'require.js','r'); $publicDirectory->writeStream($language.'/require.js', $fh); fclose($fh); } // retrieve the media assets try { $qtiItem = $this->retrieveAssets($item, $language, $publicDirectory); $this->compileItemIndex($item->getUri(), $qtiItem, $language); //store variable qti elements data into the private directory $variableElements = $qtiService->getVariableElements($qtiItem); $stream = \GuzzleHttp\Psr7\stream_for(json_encode($variableElements)); $privateDirectory->writePsrStream($language.'/variableElements.json', $stream); $stream->close(); // render item based on the modified QtiItem $xhtml = $qtiService->renderQTIItem($qtiItem, $language); //note : no need to manually copy qti or other third party lib files, all dependencies are managed by requirejs // write index.html $stream = \GuzzleHttp\Psr7\stream_for($xhtml); $publicDirectory->writePsrStream($language.'/index.html', $stream, 'text/html'); $stream->close(); return new common_report_Report( common_report_Report::TYPE_SUCCESS, __('Successfully compiled "%s"', $language) ); } catch (\tao_models_classes_FileNotFoundException $e) { return new common_report_Report( common_report_Report::TYPE_ERROR, __('Unable to retrieve asset "%s"', $e->getFilePath()) ); } catch (XIncludeException $e){ return new common_report_Report( common_report_Report::TYPE_ERROR, $e->getUserMessage() ); } catch (\Exception $e){ return new common_report_Report( common_report_Report::TYPE_ERROR, $e->getMessage() ); } }
[ "protected", "function", "deployQtiItem", "(", "core_kernel_classes_Resource", "$", "item", ",", "$", "language", ",", "tao_models_classes_service_StorageDirectory", "$", "publicDirectory", ",", "tao_models_classes_service_StorageDirectory", "$", "privateDirectory", ")", "{", ...
Desploy all the required files into the provided directories @param core_kernel_classes_Resource $item @param string $language @param tao_models_classes_service_StorageDirectory $publicDirectory @param tao_models_classes_service_StorageDirectory $privateDirectory @return common_report_Report
[ "Desploy", "all", "the", "required", "files", "into", "the", "provided", "directories" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/QtiItemCompiler.php#L145-L216
oat-sa/extension-tao-itemqti
controller/QtiCssAuthoring.php
QtiCssAuthoring.save
public function save() { if (!tao_helpers_Request::isAjax()) { throw new common_exception_IsAjaxAction(__METHOD__); } if (!$this->hasRequestParameter('uri')) { throw new common_exception_MissingParameter('uri', __METHOD__); } if (!$this->hasRequestParameter('stylesheetUri')) { throw new common_exception_MissingParameter('stylesheetUri', __METHOD__); } if (!$this->hasRequestParameter('lang')) { throw new common_exception_MissingParameter('lang', __METHOD__); } $item = new \core_kernel_classes_Resource($this->getRequestParameter('uri')); $lang = $this->getRequestParameter('lang'); $styleSheet = $this->getRequestParameter('stylesheetUri'); if (!\tao_helpers_File::securityCheck($styleSheet, true)) { throw new \common_exception_Error('invalid stylesheet path "'.$styleSheet.'"'); } $css = $this->getCssArray(); CssHelper::saveCssFile($item, $lang, $styleSheet, $css); }
php
public function save() { if (!tao_helpers_Request::isAjax()) { throw new common_exception_IsAjaxAction(__METHOD__); } if (!$this->hasRequestParameter('uri')) { throw new common_exception_MissingParameter('uri', __METHOD__); } if (!$this->hasRequestParameter('stylesheetUri')) { throw new common_exception_MissingParameter('stylesheetUri', __METHOD__); } if (!$this->hasRequestParameter('lang')) { throw new common_exception_MissingParameter('lang', __METHOD__); } $item = new \core_kernel_classes_Resource($this->getRequestParameter('uri')); $lang = $this->getRequestParameter('lang'); $styleSheet = $this->getRequestParameter('stylesheetUri'); if (!\tao_helpers_File::securityCheck($styleSheet, true)) { throw new \common_exception_Error('invalid stylesheet path "'.$styleSheet.'"'); } $css = $this->getCssArray(); CssHelper::saveCssFile($item, $lang, $styleSheet, $css); }
[ "public", "function", "save", "(", ")", "{", "if", "(", "!", "tao_helpers_Request", "::", "isAjax", "(", ")", ")", "{", "throw", "new", "common_exception_IsAjaxAction", "(", "__METHOD__", ")", ";", "}", "if", "(", "!", "$", "this", "->", "hasRequestParamet...
Save custom CSS as file @throws \common_exception_IsAjaxAction
[ "Save", "custom", "CSS", "as", "file" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/controller/QtiCssAuthoring.php#L46-L69
oat-sa/extension-tao-itemqti
controller/QtiCssAuthoring.php
QtiCssAuthoring.load
public function load() { if (!$this->hasRequestParameter('uri')) { throw new common_exception_MissingParameter('uri', __METHOD__); } if (!$this->hasRequestParameter('stylesheetUri')) { throw new common_exception_MissingParameter('stylesheetUri', __METHOD__); } if (!$this->hasRequestParameter('lang')) { throw new common_exception_MissingParameter('lang', __METHOD__); } $item = new \core_kernel_classes_Resource($this->getRequestParameter('uri')); $lang = $this->getRequestParameter('lang'); $styleSheet = $this->getRequestParameter('stylesheetUri'); if (!\tao_helpers_File::securityCheck($styleSheet, true)) { throw new \common_exception_Error('invalid stylesheet path "'.$styleSheet.'"'); } $cssArray = CssHelper::loadCssFile($item, $lang, $styleSheet); echo json_encode($cssArray); }
php
public function load() { if (!$this->hasRequestParameter('uri')) { throw new common_exception_MissingParameter('uri', __METHOD__); } if (!$this->hasRequestParameter('stylesheetUri')) { throw new common_exception_MissingParameter('stylesheetUri', __METHOD__); } if (!$this->hasRequestParameter('lang')) { throw new common_exception_MissingParameter('lang', __METHOD__); } $item = new \core_kernel_classes_Resource($this->getRequestParameter('uri')); $lang = $this->getRequestParameter('lang'); $styleSheet = $this->getRequestParameter('stylesheetUri'); if (!\tao_helpers_File::securityCheck($styleSheet, true)) { throw new \common_exception_Error('invalid stylesheet path "'.$styleSheet.'"'); } $cssArray = CssHelper::loadCssFile($item, $lang, $styleSheet); echo json_encode($cssArray); }
[ "public", "function", "load", "(", ")", "{", "if", "(", "!", "$", "this", "->", "hasRequestParameter", "(", "'uri'", ")", ")", "{", "throw", "new", "common_exception_MissingParameter", "(", "'uri'", ",", "__METHOD__", ")", ";", "}", "if", "(", "!", "$", ...
Load the custom styles as JSON @throws \common_exception_IsAjaxAction @throws \common_exception_MissingParameter
[ "Load", "the", "custom", "styles", "as", "JSON" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/controller/QtiCssAuthoring.php#L77-L100
oat-sa/extension-tao-itemqti
controller/QtiCssAuthoring.php
QtiCssAuthoring.getCssArray
private function getCssArray() { if (!$this->hasRequestParameter('cssJson')) { throw new common_exception_MissingParameter('cssJson', __CLASS__.'::'.\Context::getInstance()->getActionName()); } $cssArr = json_decode($_POST['cssJson'], true); if(!is_array($cssArr)) { throw new common_exception_InvalidArgumentType(__CLASS__,\Context::getInstance()->getActionName(), 0, 'json encoded array'); } return $cssArr; }
php
private function getCssArray() { if (!$this->hasRequestParameter('cssJson')) { throw new common_exception_MissingParameter('cssJson', __CLASS__.'::'.\Context::getInstance()->getActionName()); } $cssArr = json_decode($_POST['cssJson'], true); if(!is_array($cssArr)) { throw new common_exception_InvalidArgumentType(__CLASS__,\Context::getInstance()->getActionName(), 0, 'json encoded array'); } return $cssArr; }
[ "private", "function", "getCssArray", "(", ")", "{", "if", "(", "!", "$", "this", "->", "hasRequestParameter", "(", "'cssJson'", ")", ")", "{", "throw", "new", "common_exception_MissingParameter", "(", "'cssJson'", ",", "__CLASS__", ".", "'::'", ".", "\\", "...
Convert CSS JSON to array @return mixed @throws \common_exception_MissingParameter @throws \common_exception_InvalidArgumentType
[ "Convert", "CSS", "JSON", "to", "array" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/controller/QtiCssAuthoring.php#L109-L119
oat-sa/extension-tao-itemqti
controller/QtiCssAuthoring.php
QtiCssAuthoring.download
public function download(){ if (!$this->hasRequestParameter('uri')) { throw new common_exception_MissingParameter('uri', __METHOD__); } if (!$this->hasRequestParameter('stylesheetUri')) { throw new common_exception_MissingParameter('stylesheetUri', __METHOD__); } if (!$this->hasRequestParameter('lang')) { throw new common_exception_MissingParameter('lang', __METHOD__); } $item = new \core_kernel_classes_Resource($this->getRequestParameter('uri')); $lang = $this->getRequestParameter('lang'); $styleSheet = $this->getRequestParameter('stylesheetUri'); if (!\tao_helpers_File::securityCheck($styleSheet, true)) { throw new \common_exception_Error('invalid stylesheet path "'.$styleSheet.'"'); } header('Set-Cookie: fileDownload=true'); setcookie('fileDownload','true', 0, '/'); header('Content-type: application/octet-stream'); header(sprintf('Content-Disposition: attachment; filename=%s', basename($styleSheet))); echo CssHelper::downloadCssFile($item, $lang, $styleSheet); }
php
public function download(){ if (!$this->hasRequestParameter('uri')) { throw new common_exception_MissingParameter('uri', __METHOD__); } if (!$this->hasRequestParameter('stylesheetUri')) { throw new common_exception_MissingParameter('stylesheetUri', __METHOD__); } if (!$this->hasRequestParameter('lang')) { throw new common_exception_MissingParameter('lang', __METHOD__); } $item = new \core_kernel_classes_Resource($this->getRequestParameter('uri')); $lang = $this->getRequestParameter('lang'); $styleSheet = $this->getRequestParameter('stylesheetUri'); if (!\tao_helpers_File::securityCheck($styleSheet, true)) { throw new \common_exception_Error('invalid stylesheet path "'.$styleSheet.'"'); } header('Set-Cookie: fileDownload=true'); setcookie('fileDownload','true', 0, '/'); header('Content-type: application/octet-stream'); header(sprintf('Content-Disposition: attachment; filename=%s', basename($styleSheet))); echo CssHelper::downloadCssFile($item, $lang, $styleSheet); }
[ "public", "function", "download", "(", ")", "{", "if", "(", "!", "$", "this", "->", "hasRequestParameter", "(", "'uri'", ")", ")", "{", "throw", "new", "common_exception_MissingParameter", "(", "'uri'", ",", "__METHOD__", ")", ";", "}", "if", "(", "!", "...
Download custom styles
[ "Download", "custom", "styles" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/controller/QtiCssAuthoring.php#L124-L150
oat-sa/extension-tao-itemqti
model/qti/metadata/simple/SimpleMetadataValue.php
SimpleMetadataValue.setResourceIdentifier
public function setResourceIdentifier($resourceIdentifier) { if (is_string($resourceIdentifier) === false) { $msg = "The resourceIdentifier argument must be a string."; throw new InvalidArgumentException($msg); } elseif ($resourceIdentifier === '') { $msg = "The resourceIdentifier argument must be a non-empty string."; throw new InvalidArgumentException($msg); } else { $this->resourceIdentifier = $resourceIdentifier; } }
php
public function setResourceIdentifier($resourceIdentifier) { if (is_string($resourceIdentifier) === false) { $msg = "The resourceIdentifier argument must be a string."; throw new InvalidArgumentException($msg); } elseif ($resourceIdentifier === '') { $msg = "The resourceIdentifier argument must be a non-empty string."; throw new InvalidArgumentException($msg); } else { $this->resourceIdentifier = $resourceIdentifier; } }
[ "public", "function", "setResourceIdentifier", "(", "$", "resourceIdentifier", ")", "{", "if", "(", "is_string", "(", "$", "resourceIdentifier", ")", "===", "false", ")", "{", "$", "msg", "=", "\"The resourceIdentifier argument must be a string.\"", ";", "throw", "n...
Set the identifier of the resource the MetadataValue describes. @param string $resourceIdentifier An identifier. @throws InvalidArgumentException If $resourceIdentifier is not a string or an empty string.
[ "Set", "the", "identifier", "of", "the", "resource", "the", "MetadataValue", "describes", "." ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/simple/SimpleMetadataValue.php#L84-L95
oat-sa/extension-tao-itemqti
model/qti/metadata/simple/SimpleMetadataValue.php
SimpleMetadataValue.setPath
public function setPath(array $path) { if (count($path) === 0) { $msg = "The path argument must be a non-empty array."; throw new InvalidArgumentException($msg); } else { $this->path = $path; } }
php
public function setPath(array $path) { if (count($path) === 0) { $msg = "The path argument must be a non-empty array."; throw new InvalidArgumentException($msg); } else { $this->path = $path; } }
[ "public", "function", "setPath", "(", "array", "$", "path", ")", "{", "if", "(", "count", "(", "$", "path", ")", "===", "0", ")", "{", "$", "msg", "=", "\"The path argument must be a non-empty array.\"", ";", "throw", "new", "InvalidArgumentException", "(", ...
Set the descriptive path of the MetadataValue. @param array $path An array of Path Components. @throws InvalidArgumentException If $path is an empty array.
[ "Set", "the", "descriptive", "path", "of", "the", "MetadataValue", "." ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/simple/SimpleMetadataValue.php#L111-L119
oat-sa/extension-tao-itemqti
model/qti/metadata/AbstractMetadataService.php
AbstractMetadataService.extract
public function extract($source) { $metadata = [[]]; foreach ($this->getExtractors() as $extractor) { $metadata[] = $extractor->extract($source); } $metadata = array_merge_recursive(...$metadata); \common_Logger::d(__('%s metadata values found in source by extractor(s).', count($metadata))); return $metadata; }
php
public function extract($source) { $metadata = [[]]; foreach ($this->getExtractors() as $extractor) { $metadata[] = $extractor->extract($source); } $metadata = array_merge_recursive(...$metadata); \common_Logger::d(__('%s metadata values found in source by extractor(s).', count($metadata))); return $metadata; }
[ "public", "function", "extract", "(", "$", "source", ")", "{", "$", "metadata", "=", "[", "[", "]", "]", ";", "foreach", "(", "$", "this", "->", "getExtractors", "(", ")", "as", "$", "extractor", ")", "{", "$", "metadata", "[", "]", "=", "$", "ex...
Extract metadata value of a given $source Extract metadata values by calling each extractors @param $source @return array
[ "Extract", "metadata", "value", "of", "a", "given", "$source" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/AbstractMetadataService.php#L67-L77
oat-sa/extension-tao-itemqti
model/qti/metadata/AbstractMetadataService.php
AbstractMetadataService.inject
public function inject($identifier, $target) { if ($this->hasMetadataValue($identifier)) { \common_Logger::i(__('Preparing Metadata Values for target "%s"...', $identifier)); $values = $this->getMetadataValue($identifier); foreach ($this->getInjectors() as $injector) { \common_Logger::i(__('Attempting to inject "%s" metadata values for target "%s" with metadata Injector "%s".', count($values), $identifier, get_class($injector))); $injector->inject($target, array($identifier => $values)); } } }
php
public function inject($identifier, $target) { if ($this->hasMetadataValue($identifier)) { \common_Logger::i(__('Preparing Metadata Values for target "%s"...', $identifier)); $values = $this->getMetadataValue($identifier); foreach ($this->getInjectors() as $injector) { \common_Logger::i(__('Attempting to inject "%s" metadata values for target "%s" with metadata Injector "%s".', count($values), $identifier, get_class($injector))); $injector->inject($target, array($identifier => $values)); } } }
[ "public", "function", "inject", "(", "$", "identifier", ",", "$", "target", ")", "{", "if", "(", "$", "this", "->", "hasMetadataValue", "(", "$", "identifier", ")", ")", "{", "\\", "common_Logger", "::", "i", "(", "__", "(", "'Preparing Metadata Values for...
Inject metadata value for an identifier through injectors Inject metadata value for an identifier by calling each injectors Injectors need $target for injection @param $identifier @param $target
[ "Inject", "metadata", "value", "for", "an", "identifier", "through", "injectors" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/AbstractMetadataService.php#L88-L100
oat-sa/extension-tao-itemqti
model/qti/metadata/AbstractMetadataService.php
AbstractMetadataService.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::EXTRACTOR_KEY: $this->registerInstance(self::EXTRACTOR_KEY, $name, MetadataExtractor::class); break; case self::INJECTOR_KEY: $this->registerInstance(self::INJECTOR_KEY, $name, MetadataInjector::class); break; default: throw new \common_Exception(__('Unknown $key to register MetadataService instance')); } return true; }
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::EXTRACTOR_KEY: $this->registerInstance(self::EXTRACTOR_KEY, $name, MetadataExtractor::class); break; case self::INJECTOR_KEY: $this->registerInstance(self::INJECTOR_KEY, $name, MetadataInjector::class); break; default: throw new \common_Exception(__('Unknown $key to register MetadataService instance')); } return true; }
[ "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 @throws \common_Exception
[ "Register", "an", "importer", "instance" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/AbstractMetadataService.php#L115-L137
oat-sa/extension-tao-itemqti
model/qti/metadata/AbstractMetadataService.php
AbstractMetadataService.unregister
public function unregister($key, $name) { if (empty($key) || empty($name)) { throw new \common_Exception(); } if (is_object($name)) { $name = get_class($name); } switch ($key) { case self::EXTRACTOR_KEY: $this->unregisterInstance(self::EXTRACTOR_KEY, $name); break; case self::INJECTOR_KEY: $this->unregisterInstance(self::INJECTOR_KEY, $name); break; } return; }
php
public function unregister($key, $name) { if (empty($key) || empty($name)) { throw new \common_Exception(); } if (is_object($name)) { $name = get_class($name); } switch ($key) { case self::EXTRACTOR_KEY: $this->unregisterInstance(self::EXTRACTOR_KEY, $name); break; case self::INJECTOR_KEY: $this->unregisterInstance(self::INJECTOR_KEY, $name); break; } return; }
[ "public", "function", "unregister", "(", "$", "key", ",", "$", "name", ")", "{", "if", "(", "empty", "(", "$", "key", ")", "||", "empty", "(", "$", "name", ")", ")", "{", "throw", "new", "\\", "common_Exception", "(", ")", ";", "}", "if", "(", ...
Unregister a instance of metadataService config Unregister an instance with helper method unregisterInstance @param string $key The config key where unregister instance @param string $name The instance name to unregister @throws \common_Exception If method is call with empty argument
[ "Unregister", "a", "instance", "of", "metadataService", "config" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/AbstractMetadataService.php#L148-L167
oat-sa/extension-tao-itemqti
model/qti/metadata/AbstractMetadataService.php
AbstractMetadataService.registerInstance
protected function registerInstance($key, $name, $interface) { if (is_a($name, $interface, true)) { $instances = $this->getOption($key); if ($instances === null || array_search($name, $instances) === false) { $instances[] = $name; $this->setOption($key, $instances); $this->registerMetadataService(); } } }
php
protected function registerInstance($key, $name, $interface) { if (is_a($name, $interface, true)) { $instances = $this->getOption($key); if ($instances === null || array_search($name, $instances) === false) { $instances[] = $name; $this->setOption($key, $instances); $this->registerMetadataService(); } } }
[ "protected", "function", "registerInstance", "(", "$", "key", ",", "$", "name", ",", "$", "interface", ")", "{", "if", "(", "is_a", "(", "$", "name", ",", "$", "interface", ",", "true", ")", ")", "{", "$", "instances", "=", "$", "this", "->", "getO...
Register an instance Register a $name instance into $key config $key class has to implements $interface @param $key @param $name @param $interface
[ "Register", "an", "instance" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/AbstractMetadataService.php#L208-L218
oat-sa/extension-tao-itemqti
model/qti/metadata/AbstractMetadataService.php
AbstractMetadataService.unregisterInstance
protected function unregisterInstance($key, $name) { if ($this->hasOption($key)) { $instances = $this->getOption($key); if (($index = array_search($name, $instances)) !== false) { unset($instances[$index]); $this->setOption($key, $instances); $this->registerMetadataService(); } } }
php
protected function unregisterInstance($key, $name) { if ($this->hasOption($key)) { $instances = $this->getOption($key); if (($index = array_search($name, $instances)) !== false) { unset($instances[$index]); $this->setOption($key, $instances); $this->registerMetadataService(); } } }
[ "protected", "function", "unregisterInstance", "(", "$", "key", ",", "$", "name", ")", "{", "if", "(", "$", "this", "->", "hasOption", "(", "$", "key", ")", ")", "{", "$", "instances", "=", "$", "this", "->", "getOption", "(", "$", "key", ")", ";",...
Unregister an instance Unregister a $name instance into $key config @param $key @param $name
[ "Unregister", "an", "instance" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/AbstractMetadataService.php#L228-L239
oat-sa/extension-tao-itemqti
model/qti/metadata/AbstractMetadataService.php
AbstractMetadataService.getMetadataValue
public function getMetadataValue($identifier) { $metadata = $this->getMetadataValues(); return isset($metadata[$identifier]) ? $metadata[$identifier] : null; }
php
public function getMetadataValue($identifier) { $metadata = $this->getMetadataValues(); return isset($metadata[$identifier]) ? $metadata[$identifier] : null; }
[ "public", "function", "getMetadataValue", "(", "$", "identifier", ")", "{", "$", "metadata", "=", "$", "this", "->", "getMetadataValues", "(", ")", ";", "return", "isset", "(", "$", "metadata", "[", "$", "identifier", "]", ")", "?", "$", "metadata", "[",...
Return the associated value of metadata $identifier or null if not exists @param $identifier @return mixed|null
[ "Return", "the", "associated", "value", "of", "metadata", "$identifier", "or", "null", "if", "not", "exists" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/AbstractMetadataService.php#L258-L262
oat-sa/extension-tao-itemqti
model/qti/metadata/AbstractMetadataService.php
AbstractMetadataService.getInstances
protected function getInstances($id, $interface) { if (isset($this->instances[$id])) { return $this->instances[$id]; } $this->instances[$id] = []; if (! $this->hasOption($id)) { return $this->instances[$id]; } else { foreach ($this->getOption($id) as $instance) { if (is_a($instance, $interface, true)) { $this->instances[$id][] = new $instance(); } } } return $this->instances[$id]; }
php
protected function getInstances($id, $interface) { if (isset($this->instances[$id])) { return $this->instances[$id]; } $this->instances[$id] = []; if (! $this->hasOption($id)) { return $this->instances[$id]; } else { foreach ($this->getOption($id) as $instance) { if (is_a($instance, $interface, true)) { $this->instances[$id][] = new $instance(); } } } return $this->instances[$id]; }
[ "protected", "function", "getInstances", "(", "$", "id", ",", "$", "interface", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "instances", "[", "$", "id", "]", ")", ")", "{", "return", "$", "this", "->", "instances", "[", "$", "id", "]", ...
Return config instances Retrieve instances stored into config Config $key is scan to take only instances with given $interface @param $id @param $interface @return mixed
[ "Return", "config", "instances" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/AbstractMetadataService.php#L283-L301
oat-sa/extension-tao-itemqti
model/portableElement/model/PortableModelRegistry.php
PortableModelRegistry.getModel
public function getModel($modelId) { if (!$this->isRegistered($modelId)) { throw new PortableModelMissing($modelId); } return $this->getModelFromConfig($this->get($modelId)); }
php
public function getModel($modelId) { if (!$this->isRegistered($modelId)) { throw new PortableModelMissing($modelId); } return $this->getModelFromConfig($this->get($modelId)); }
[ "public", "function", "getModel", "(", "$", "modelId", ")", "{", "if", "(", "!", "$", "this", "->", "isRegistered", "(", "$", "modelId", ")", ")", "{", "throw", "new", "PortableModelMissing", "(", "$", "modelId", ")", ";", "}", "return", "$", "this", ...
Return model associated to the given string value @param string $modelId @return PortableElementModel @throws PortableElementInconsistencyModelException
[ "Return", "model", "associated", "to", "the", "given", "string", "value" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/model/PortableModelRegistry.php#L59-L65
oat-sa/extension-tao-itemqti
model/portableElement/model/PortableModelRegistry.php
PortableModelRegistry.getModels
public function getModels() { $models = $this->getMap(); foreach ($models as $key => $config) { $models[$key] = $this->getModelFromConfig($config); } return $models; }
php
public function getModels() { $models = $this->getMap(); foreach ($models as $key => $config) { $models[$key] = $this->getModelFromConfig($config); } return $models; }
[ "public", "function", "getModels", "(", ")", "{", "$", "models", "=", "$", "this", "->", "getMap", "(", ")", ";", "foreach", "(", "$", "models", "as", "$", "key", "=>", "$", "config", ")", "{", "$", "models", "[", "$", "key", "]", "=", "$", "th...
Return all configured models @return PortableElementModel[] @throws PortableElementInconsistencyModelException
[ "Return", "all", "configured", "models" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/model/PortableModelRegistry.php#L85-L92
oat-sa/extension-tao-itemqti
model/Export/ExportForm.php
ExportForm.initForm
public function initForm() { $this->form = new tao_helpers_form_xhtml_Form('export'); $this->form->setDecorators(array( 'element' => new tao_helpers_form_xhtml_TagWrapper(array('tag' => 'div')), 'group' => new tao_helpers_form_xhtml_TagWrapper(array('tag' => 'div', 'cssClass' => 'form-group')), 'error' => new tao_helpers_form_xhtml_TagWrapper(array('tag' => 'div', 'cssClass' => 'form-error ui-state-error ui-corner-all')), 'actions-bottom' => new tao_helpers_form_xhtml_TagWrapper(array('tag' => 'div', 'cssClass' => 'form-toolbar')), 'actions-top' => new tao_helpers_form_xhtml_TagWrapper(array('tag' => 'div', 'cssClass' => 'form-toolbar')) )); $exportElt = tao_helpers_form_FormFactory::getElement('export', 'Free'); $exportElt->setValue('<a href="#" class="form-submitter btn-success small"><span class="icon-export"></span> ' .__('Export').'</a>'); $this->form->setActions(array($exportElt), 'bottom'); }
php
public function initForm() { $this->form = new tao_helpers_form_xhtml_Form('export'); $this->form->setDecorators(array( 'element' => new tao_helpers_form_xhtml_TagWrapper(array('tag' => 'div')), 'group' => new tao_helpers_form_xhtml_TagWrapper(array('tag' => 'div', 'cssClass' => 'form-group')), 'error' => new tao_helpers_form_xhtml_TagWrapper(array('tag' => 'div', 'cssClass' => 'form-error ui-state-error ui-corner-all')), 'actions-bottom' => new tao_helpers_form_xhtml_TagWrapper(array('tag' => 'div', 'cssClass' => 'form-toolbar')), 'actions-top' => new tao_helpers_form_xhtml_TagWrapper(array('tag' => 'div', 'cssClass' => 'form-toolbar')) )); $exportElt = tao_helpers_form_FormFactory::getElement('export', 'Free'); $exportElt->setValue('<a href="#" class="form-submitter btn-success small"><span class="icon-export"></span> ' .__('Export').'</a>'); $this->form->setActions(array($exportElt), 'bottom'); }
[ "public", "function", "initForm", "(", ")", "{", "$", "this", "->", "form", "=", "new", "tao_helpers_form_xhtml_Form", "(", "'export'", ")", ";", "$", "this", "->", "form", "->", "setDecorators", "(", "array", "(", "'element'", "=>", "new", "tao_helpers_form...
Short description of method initForm @access public @author Joel Bout, <joel.bout@tudor.lu> @return mixed
[ "Short", "description", "of", "method", "initForm" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/Export/ExportForm.php#L61-L80
oat-sa/extension-tao-itemqti
model/Export/ExportForm.php
ExportForm.initElements
public function initElements() { $itemService = taoItems_models_classes_ItemsService::singleton(); $fileName = ''; $options = array(); $disabledOptions = array(); if(isset($this->data['instance'])){ $item = $this->data['instance']; if($item instanceof core_kernel_classes_Resource){ if($itemService->hasItemModel($item, array(ItemModel::MODEL_URI))){ $fileName = strtolower(tao_helpers_Display::textCleaner($item->getLabel())); try{ $this->isInstanceValid($item); }catch(\common_exception_UserReadableException $e){ $disabledOptions[$item->getUri()] = $e->getUserMessage(); } $options[$item->getUri()] = $item->getLabel(); } } } else { if(isset($this->data['class'])){ $class = $this->data['class']; } else{ $class = $itemService->getRootClass(); } if($class instanceof core_kernel_classes_Class){ $fileName = strtolower(tao_helpers_Display::textCleaner($class->getLabel(), '*')); foreach($class->getInstances(true) as $instance){ if($itemService->hasItemModel($instance, array(ItemModel::MODEL_URI))){ try{ $this->isInstanceValid($instance); }catch(\common_exception_UserReadableException $e){ $disabledOptions[$instance->getUri()] = $e->getUserMessage(); } $options[$instance->getUri()] = $instance->getLabel(); } } } } $nameElt = tao_helpers_form_FormFactory::getElement('filename', 'Textbox'); $nameElt->setDescription(__('File name')); $nameElt->setValue($fileName); $nameElt->setUnit(".zip"); $nameElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty')); $this->form->addElement($nameElt); $instanceElt = tao_helpers_form_FormFactory::getElement('instances', 'Checkbox'); $instanceElt->setDescription(__('Items')); if(count($options) > 1){ $instanceElt->setAttribute('checkAll', true); } $instanceElt->setOptions(tao_helpers_Uri::encodeArray($options, tao_helpers_Uri::ENCODE_ARRAY_KEYS)); $instanceElt->setReadOnly(tao_helpers_Uri::encodeArray($disabledOptions, tao_helpers_Uri::ENCODE_ARRAY_KEYS)); foreach(array_keys($options) as $value){ if(!isset($disabledOptions[$value])){ $instanceElt->setValue($value); } } $this->form->addElement($instanceElt); $this->form->createGroup('options', '<h3>'.$this->getFormGroupName().'</h3>', array('filename', 'instances')); }
php
public function initElements() { $itemService = taoItems_models_classes_ItemsService::singleton(); $fileName = ''; $options = array(); $disabledOptions = array(); if(isset($this->data['instance'])){ $item = $this->data['instance']; if($item instanceof core_kernel_classes_Resource){ if($itemService->hasItemModel($item, array(ItemModel::MODEL_URI))){ $fileName = strtolower(tao_helpers_Display::textCleaner($item->getLabel())); try{ $this->isInstanceValid($item); }catch(\common_exception_UserReadableException $e){ $disabledOptions[$item->getUri()] = $e->getUserMessage(); } $options[$item->getUri()] = $item->getLabel(); } } } else { if(isset($this->data['class'])){ $class = $this->data['class']; } else{ $class = $itemService->getRootClass(); } if($class instanceof core_kernel_classes_Class){ $fileName = strtolower(tao_helpers_Display::textCleaner($class->getLabel(), '*')); foreach($class->getInstances(true) as $instance){ if($itemService->hasItemModel($instance, array(ItemModel::MODEL_URI))){ try{ $this->isInstanceValid($instance); }catch(\common_exception_UserReadableException $e){ $disabledOptions[$instance->getUri()] = $e->getUserMessage(); } $options[$instance->getUri()] = $instance->getLabel(); } } } } $nameElt = tao_helpers_form_FormFactory::getElement('filename', 'Textbox'); $nameElt->setDescription(__('File name')); $nameElt->setValue($fileName); $nameElt->setUnit(".zip"); $nameElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty')); $this->form->addElement($nameElt); $instanceElt = tao_helpers_form_FormFactory::getElement('instances', 'Checkbox'); $instanceElt->setDescription(__('Items')); if(count($options) > 1){ $instanceElt->setAttribute('checkAll', true); } $instanceElt->setOptions(tao_helpers_Uri::encodeArray($options, tao_helpers_Uri::ENCODE_ARRAY_KEYS)); $instanceElt->setReadOnly(tao_helpers_Uri::encodeArray($disabledOptions, tao_helpers_Uri::ENCODE_ARRAY_KEYS)); foreach(array_keys($options) as $value){ if(!isset($disabledOptions[$value])){ $instanceElt->setValue($value); } } $this->form->addElement($instanceElt); $this->form->createGroup('options', '<h3>'.$this->getFormGroupName().'</h3>', array('filename', 'instances')); }
[ "public", "function", "initElements", "(", ")", "{", "$", "itemService", "=", "taoItems_models_classes_ItemsService", "::", "singleton", "(", ")", ";", "$", "fileName", "=", "''", ";", "$", "options", "=", "array", "(", ")", ";", "$", "disabledOptions", "=",...
overriden @access public @author Joel Bout, <joel.bout@tudor.lu> @return mixed
[ "overriden" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/Export/ExportForm.php#L89-L158
oat-sa/extension-tao-itemqti
model/portableElement/element/PortableElementObject.php
PortableElementObject.exchangeArray
public function exchangeArray(array $data) { $attributes = array_keys($this->toArray()); foreach ($attributes as $field) { if (isset($data[$field])) { $this->$field = $data[$field]; } } return $this; }
php
public function exchangeArray(array $data) { $attributes = array_keys($this->toArray()); foreach ($attributes as $field) { if (isset($data[$field])) { $this->$field = $data[$field]; } } return $this; }
[ "public", "function", "exchangeArray", "(", "array", "$", "data", ")", "{", "$", "attributes", "=", "array_keys", "(", "$", "this", "->", "toArray", "(", ")", ")", ";", "foreach", "(", "$", "attributes", "as", "$", "field", ")", "{", "if", "(", "isse...
Populate $this object from array @param array $data @return $this
[ "Populate", "$this", "object", "from", "array" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/element/PortableElementObject.php#L72-L81
oat-sa/extension-tao-itemqti
model/portableElement/element/PortableElementObject.php
PortableElementObject.toArray
public function toArray($selectionGroup=false) { $array = get_object_vars($this); if (is_array($selectionGroup)) { return array_intersect_key($array, array_flip($selectionGroup)); } unset($array['model']); return $array; }
php
public function toArray($selectionGroup=false) { $array = get_object_vars($this); if (is_array($selectionGroup)) { return array_intersect_key($array, array_flip($selectionGroup)); } unset($array['model']); return $array; }
[ "public", "function", "toArray", "(", "$", "selectionGroup", "=", "false", ")", "{", "$", "array", "=", "get_object_vars", "(", "$", "this", ")", ";", "if", "(", "is_array", "(", "$", "selectionGroup", ")", ")", "{", "return", "array_intersect_key", "(", ...
Return an array representation of $this object Should be filtered by $selectionGroup @param bool $selectionGroup @return array
[ "Return", "an", "array", "representation", "of", "$this", "object", "Should", "be", "filtered", "by", "$selectionGroup" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/element/PortableElementObject.php#L90-L98
oat-sa/extension-tao-itemqti
model/portableElement/element/PortableElementObject.php
PortableElementObject.getRuntimePath
public function getRuntimePath() { $paths = []; foreach ($this->getRuntime() as $key => $value) { if (in_array($key, ['hook', 'libraries', 'stylesheets', 'mediaFiles', 'icon', 'src'])) { $paths[$key] = preg_replace('/^' . $this->getTypeIdentifier() . '/', '.', $value); } } return $paths; }
php
public function getRuntimePath() { $paths = []; foreach ($this->getRuntime() as $key => $value) { if (in_array($key, ['hook', 'libraries', 'stylesheets', 'mediaFiles', 'icon', 'src'])) { $paths[$key] = preg_replace('/^' . $this->getTypeIdentifier() . '/', '.', $value); } } return $paths; }
[ "public", "function", "getRuntimePath", "(", ")", "{", "$", "paths", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "getRuntime", "(", ")", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "in_array", "(", "$", "key", ",", "[", ...
Return runtime files with relative path @return array
[ "Return", "runtime", "files", "with", "relative", "path" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/element/PortableElementObject.php#L283-L292
oat-sa/extension-tao-itemqti
model/portableElement/element/PortableElementObject.php
PortableElementObject.getRuntimeAliases
public function getRuntimeAliases() { $paths = []; foreach ($this->getRuntime() as $key => $value) { if (in_array($key, ['hook', 'libraries', 'stylesheets', 'mediaFiles', 'icon', 'src'])) { $paths[$key] = preg_replace('/^(.\/)(.*)/', $this->getTypeIdentifier() . "/$2", $this->getRuntimeKey($key)); } } return $paths; }
php
public function getRuntimeAliases() { $paths = []; foreach ($this->getRuntime() as $key => $value) { if (in_array($key, ['hook', 'libraries', 'stylesheets', 'mediaFiles', 'icon', 'src'])) { $paths[$key] = preg_replace('/^(.\/)(.*)/', $this->getTypeIdentifier() . "/$2", $this->getRuntimeKey($key)); } } return $paths; }
[ "public", "function", "getRuntimeAliases", "(", ")", "{", "$", "paths", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "getRuntime", "(", ")", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "in_array", "(", "$", "key", ",", "[...
Return creator files with relative aliases @return array
[ "Return", "creator", "files", "with", "relative", "aliases" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/element/PortableElementObject.php#L299-L308
oat-sa/extension-tao-itemqti
model/portableElement/element/PortableElementObject.php
PortableElementObject.getCreatorPath
public function getCreatorPath() { $paths = []; foreach ($this->getCreator() as $key => $value) { if (in_array($key, ['hook', 'libraries', 'stylesheets', 'mediaFiles', 'icon', 'src'])) { $paths[$key] = preg_replace('/^' . $this->getTypeIdentifier() . '/', '.', $value); } } return $paths; }
php
public function getCreatorPath() { $paths = []; foreach ($this->getCreator() as $key => $value) { if (in_array($key, ['hook', 'libraries', 'stylesheets', 'mediaFiles', 'icon', 'src'])) { $paths[$key] = preg_replace('/^' . $this->getTypeIdentifier() . '/', '.', $value); } } return $paths; }
[ "public", "function", "getCreatorPath", "(", ")", "{", "$", "paths", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "getCreator", "(", ")", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "in_array", "(", "$", "key", ",", "[", ...
Return creator files with relative path @return array
[ "Return", "creator", "files", "with", "relative", "path" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/element/PortableElementObject.php#L315-L324
oat-sa/extension-tao-itemqti
model/portableElement/element/PortableElementObject.php
PortableElementObject.getCreatorAliases
public function getCreatorAliases() { $paths = []; foreach ($this->getCreator() as $key => $value) { if (in_array($key, ['hook', 'libraries', 'stylesheets', 'mediaFiles', 'icon', 'src'])) { $paths[$key] = preg_replace('/^(.\/)(.*)/', $this->getTypeIdentifier() . "/$2", $this->getCreatorKey($key)); } } return $paths; }
php
public function getCreatorAliases() { $paths = []; foreach ($this->getCreator() as $key => $value) { if (in_array($key, ['hook', 'libraries', 'stylesheets', 'mediaFiles', 'icon', 'src'])) { $paths[$key] = preg_replace('/^(.\/)(.*)/', $this->getTypeIdentifier() . "/$2", $this->getCreatorKey($key)); } } return $paths; }
[ "public", "function", "getCreatorAliases", "(", ")", "{", "$", "paths", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "getCreator", "(", ")", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "in_array", "(", "$", "key", ",", "[...
Return creator files with relative aliases @return array
[ "Return", "creator", "files", "with", "relative", "aliases" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/portableElement/element/PortableElementObject.php#L331-L340
oat-sa/extension-tao-itemqti
model/qti/metadata/MetadataRegistry.php
MetadataRegistry.getMapping
public function getMapping() { $instances = $this->getServiceManager() ->get(MetadataService::SERVICE_ID) ->getImporter() ->getOptions(); $mapping = []; foreach ($instances as $key => $helpers) { if (! isset($mapping[$key])) { $mapping[$key] = []; } foreach ($helpers as $instance) { $mapping[$key][] = get_class($instance); } } return $mapping; }
php
public function getMapping() { $instances = $this->getServiceManager() ->get(MetadataService::SERVICE_ID) ->getImporter() ->getOptions(); $mapping = []; foreach ($instances as $key => $helpers) { if (! isset($mapping[$key])) { $mapping[$key] = []; } foreach ($helpers as $instance) { $mapping[$key][] = get_class($instance); } } return $mapping; }
[ "public", "function", "getMapping", "(", ")", "{", "$", "instances", "=", "$", "this", "->", "getServiceManager", "(", ")", "->", "get", "(", "MetadataService", "::", "SERVICE_ID", ")", "->", "getImporter", "(", ")", "->", "getOptions", "(", ")", ";", "$...
@deprecated Use MetadataService->getImporter() instead to have access to specific instance of metadataImporter Get the class mapping of Extractor/Injector classes. @return array An associative array with two main keys. The 'injectors' and 'extractors' and 'guardians' keys refer to sub-arrays containing respectively classnames of MetadataInjector and MetadataExtractor implementations.
[ "@deprecated", "Use", "MetadataService", "-", ">", "getImporter", "()", "instead", "to", "have", "access", "to", "specific", "instance", "of", "metadataImporter" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/MetadataRegistry.php#L93-L111
oat-sa/extension-tao-itemqti
model/qti/metadata/MetadataRegistry.php
MetadataRegistry.setMapping
protected function setMapping(array $mapping) { /** @var MetadataService $metadataService */ $metadataService = $this->getServiceManager()->get(MetadataService::SERVICE_ID); $importer = $metadataService->getImporter(); $importer->setOptions($mapping); $metadataService->setOption(MetadataService::IMPORTER_KEY, $importer); $this->getServiceManager()->register(MetadataService::SERVICE_ID, $metadataService); }
php
protected function setMapping(array $mapping) { /** @var MetadataService $metadataService */ $metadataService = $this->getServiceManager()->get(MetadataService::SERVICE_ID); $importer = $metadataService->getImporter(); $importer->setOptions($mapping); $metadataService->setOption(MetadataService::IMPORTER_KEY, $importer); $this->getServiceManager()->register(MetadataService::SERVICE_ID, $metadataService); }
[ "protected", "function", "setMapping", "(", "array", "$", "mapping", ")", "{", "/** @var MetadataService $metadataService */", "$", "metadataService", "=", "$", "this", "->", "getServiceManager", "(", ")", "->", "get", "(", "MetadataService", "::", "SERVICE_ID", ")"...
@deprecated use MetadataService->getImporter()->registerService() instead Set the class mapping of Extractor/Injector classes. @param array $mapping An associative array with two main keys. The 'injectors' and 'extractors' keys refer to sub-arrays containing respectively classnames of MetadataInjector and MetadataExtractor implementations.
[ "@deprecated", "use", "MetadataService", "-", ">", "getImporter", "()", "-", ">", "registerService", "()", "instead" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/MetadataRegistry.php#L120-L130
oat-sa/extension-tao-itemqti
model/qti/metadata/MetadataRegistry.php
MetadataRegistry.registerMetadataInjector
public function registerMetadataInjector($fqcn) { $this->getServiceManager() ->get(MetadataService::SERVICE_ID) ->getImporter() ->register(MetadataImporter::INJECTOR_KEY, $fqcn); }
php
public function registerMetadataInjector($fqcn) { $this->getServiceManager() ->get(MetadataService::SERVICE_ID) ->getImporter() ->register(MetadataImporter::INJECTOR_KEY, $fqcn); }
[ "public", "function", "registerMetadataInjector", "(", "$", "fqcn", ")", "{", "$", "this", "->", "getServiceManager", "(", ")", "->", "get", "(", "MetadataService", "::", "SERVICE_ID", ")", "->", "getImporter", "(", ")", "->", "register", "(", "MetadataImporte...
@deprecated use MetadataService->getImporter()->register(MetadataImport::INJECTOR_KEY, $fqcn) Register a MetadataInjector implementation by $fqcn (Fully Qualified Class Name). @param string $fqcn A Fully Qualified Class Name. @throws InvalidArgumentException If the given $fqcn does not correspond to an implementation of the MetadataInjector interface. @see oat\taoQtiItem\model\qti\metadata\MetadataInjector The MetadataInjector interface.
[ "@deprecated", "use", "MetadataService", "-", ">", "getImporter", "()", "-", ">", "register", "(", "MetadataImport", "::", "INJECTOR_KEY", "$fqcn", ")" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/MetadataRegistry.php#L141-L147
oat-sa/extension-tao-itemqti
model/qti/metadata/MetadataRegistry.php
MetadataRegistry.unregisterMetadataInjector
public function unregisterMetadataInjector($fqcn) { $this->getServiceManager() ->get(MetadataService::SERVICE_ID) ->getImporter() ->unregister(MetadataImporter::INJECTOR_KEY, $fqcn); }
php
public function unregisterMetadataInjector($fqcn) { $this->getServiceManager() ->get(MetadataService::SERVICE_ID) ->getImporter() ->unregister(MetadataImporter::INJECTOR_KEY, $fqcn); }
[ "public", "function", "unregisterMetadataInjector", "(", "$", "fqcn", ")", "{", "$", "this", "->", "getServiceManager", "(", ")", "->", "get", "(", "MetadataService", "::", "SERVICE_ID", ")", "->", "getImporter", "(", ")", "->", "unregister", "(", "MetadataImp...
@deprecated use MetadataService->getImporter()->unregister(MetadataImport::INJECTOR_KEY, $fqcn) Unregister a MetadataInjector implementation by $fqcn (Fully Qualified Class Name). @param string $fqcn A Fully Qualified Class Name. @see oat\taoQtiItem\model\qti\metadata\MetadataInjector The MetadataInjector interface.
[ "@deprecated", "use", "MetadataService", "-", ">", "getImporter", "()", "-", ">", "unregister", "(", "MetadataImport", "::", "INJECTOR_KEY", "$fqcn", ")" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/MetadataRegistry.php#L157-L163
oat-sa/extension-tao-itemqti
model/qti/metadata/MetadataRegistry.php
MetadataRegistry.registerMetadataExtractor
public function registerMetadataExtractor($fqcn) { $this->getServiceManager() ->get(MetadataService::SERVICE_ID) ->getImporter() ->register(MetadataImporter::EXTRACTOR_KEY, $fqcn); }
php
public function registerMetadataExtractor($fqcn) { $this->getServiceManager() ->get(MetadataService::SERVICE_ID) ->getImporter() ->register(MetadataImporter::EXTRACTOR_KEY, $fqcn); }
[ "public", "function", "registerMetadataExtractor", "(", "$", "fqcn", ")", "{", "$", "this", "->", "getServiceManager", "(", ")", "->", "get", "(", "MetadataService", "::", "SERVICE_ID", ")", "->", "getImporter", "(", ")", "->", "register", "(", "MetadataImport...
@deprecated use MetadataService->getImporter()->register(MetadataImport::EXTRACTOR_KEY, $fqcn) Register a MetadataExtractor implementation by $fqcn (Fully Qualified Class Name). @param string $fqcn A Fully Qualified Class Name. @throws InvalidArgumentException If the given $fqcn does not correspond to an implementation of the MetadataExtractor interface. @see oat\taoQtiItem\model\qti\metadata\MetadataExtractor The MetadataExtractor interface.
[ "@deprecated", "use", "MetadataService", "-", ">", "getImporter", "()", "-", ">", "register", "(", "MetadataImport", "::", "EXTRACTOR_KEY", "$fqcn", ")" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/MetadataRegistry.php#L174-L180
oat-sa/extension-tao-itemqti
model/qti/metadata/MetadataRegistry.php
MetadataRegistry.unregisterMetadataExtractor
public function unregisterMetadataExtractor($fqcn) { $this->getServiceManager() ->get(MetadataService::SERVICE_ID) ->getImporter() ->unregister(MetadataImporter::EXTRACTOR_KEY, $fqcn); }
php
public function unregisterMetadataExtractor($fqcn) { $this->getServiceManager() ->get(MetadataService::SERVICE_ID) ->getImporter() ->unregister(MetadataImporter::EXTRACTOR_KEY, $fqcn); }
[ "public", "function", "unregisterMetadataExtractor", "(", "$", "fqcn", ")", "{", "$", "this", "->", "getServiceManager", "(", ")", "->", "get", "(", "MetadataService", "::", "SERVICE_ID", ")", "->", "getImporter", "(", ")", "->", "unregister", "(", "MetadataIm...
@deprecated use MetadataService->getImporter()->unregister(MetadataImport::EXTRACTOR_KEY, $fqcn) Unregister a MetadataExtractor implementation by $fqcn (Fully Qualified Class Name). @param string $fqcn A Fully Qualified Class Name. @see oat\taoQtiItem\model\qti\metadata\MetadataExtractor The MetadataExtractor interface.
[ "@deprecated", "use", "MetadataService", "-", ">", "getImporter", "()", "-", ">", "unregister", "(", "MetadataImport", "::", "EXTRACTOR_KEY", "$fqcn", ")" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/MetadataRegistry.php#L190-L196
oat-sa/extension-tao-itemqti
model/qti/metadata/MetadataRegistry.php
MetadataRegistry.registerMetadataGuardian
public function registerMetadataGuardian($fqcn) { $this->getServiceManager() ->get(MetadataService::SERVICE_ID) ->getImporter() ->register(MetadataImporter::GUARDIAN_KEY, $fqcn); }
php
public function registerMetadataGuardian($fqcn) { $this->getServiceManager() ->get(MetadataService::SERVICE_ID) ->getImporter() ->register(MetadataImporter::GUARDIAN_KEY, $fqcn); }
[ "public", "function", "registerMetadataGuardian", "(", "$", "fqcn", ")", "{", "$", "this", "->", "getServiceManager", "(", ")", "->", "get", "(", "MetadataService", "::", "SERVICE_ID", ")", "->", "getImporter", "(", ")", "->", "register", "(", "MetadataImporte...
@deprecated use MetadataService->getImporter()->register(MetadataImport::GUARDIAN_KEY, $fqcn) Register a MetadataGuardian implementation by $fqcn (Fully Qualified Class Name). @param string $fqcn A Fully Qualified Class Name. @throws InvalidArgumentException If the given $fqcn does not correspond to an implementation of the MetadataGuardian interface. @see oat\taoQtiItem\model\qti\metadata\MetadataGuardian The MetadataExtractor interface.
[ "@deprecated", "use", "MetadataService", "-", ">", "getImporter", "()", "-", ">", "register", "(", "MetadataImport", "::", "GUARDIAN_KEY", "$fqcn", ")" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/MetadataRegistry.php#L207-L213
oat-sa/extension-tao-itemqti
model/qti/metadata/MetadataRegistry.php
MetadataRegistry.unregisterMetadataGuardian
public function unregisterMetadataGuardian($fqcn) { $this->getServiceManager() ->get(MetadataService::SERVICE_ID) ->getImporter() ->unregister(MetadataImporter::GUARDIAN_KEY, $fqcn); }
php
public function unregisterMetadataGuardian($fqcn) { $this->getServiceManager() ->get(MetadataService::SERVICE_ID) ->getImporter() ->unregister(MetadataImporter::GUARDIAN_KEY, $fqcn); }
[ "public", "function", "unregisterMetadataGuardian", "(", "$", "fqcn", ")", "{", "$", "this", "->", "getServiceManager", "(", ")", "->", "get", "(", "MetadataService", "::", "SERVICE_ID", ")", "->", "getImporter", "(", ")", "->", "unregister", "(", "MetadataImp...
@deprecated use MetadataService->getImporter()->unregister(MetadataImport::GUARDIAN_KEY, $fqcn) Unregister a MetadataGuardian implementation by $fqcn (Fully Qualified Class Name). @param string $fqcn A Fully Qualified Class Name. @see oat\taoQtiItem\model\qti\metadata\MetadataGuardian The MetadataGuardian interface.
[ "@deprecated", "use", "MetadataService", "-", ">", "getImporter", "()", "-", ">", "unregister", "(", "MetadataImport", "::", "GUARDIAN_KEY", "$fqcn", ")" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/MetadataRegistry.php#L223-L229
oat-sa/extension-tao-itemqti
model/qti/metadata/MetadataRegistry.php
MetadataRegistry.registerMetadataClassLookup
public function registerMetadataClassLookup($fqcn) { $this->getServiceManager() ->get(MetadataService::SERVICE_ID) ->getImporter() ->register(MetadataImporter::CLASS_LOOKUP_KEY, $fqcn); }
php
public function registerMetadataClassLookup($fqcn) { $this->getServiceManager() ->get(MetadataService::SERVICE_ID) ->getImporter() ->register(MetadataImporter::CLASS_LOOKUP_KEY, $fqcn); }
[ "public", "function", "registerMetadataClassLookup", "(", "$", "fqcn", ")", "{", "$", "this", "->", "getServiceManager", "(", ")", "->", "get", "(", "MetadataService", "::", "SERVICE_ID", ")", "->", "getImporter", "(", ")", "->", "register", "(", "MetadataImpo...
@deprecated use MetadataService->getImporter()->register(MetadataImport::CLASS_LOOKUP_KEY, $fqcn) Register a MetadataClassLookup implementation by $fqcn (Fully Qualified Class Name). @param string $fqcn A Fully Qualified Class Name. @throws InvalidArgumentException If the given $fqcn does not correspond to an implementation of the MetadataClassLookup interface. @see oat\taoQtiItem\model\qti\metadata\MetadataClassLookup The MetadataClassLookup interface.
[ "@deprecated", "use", "MetadataService", "-", ">", "getImporter", "()", "-", ">", "register", "(", "MetadataImport", "::", "CLASS_LOOKUP_KEY", "$fqcn", ")" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/MetadataRegistry.php#L240-L246
oat-sa/extension-tao-itemqti
model/qti/metadata/MetadataRegistry.php
MetadataRegistry.unregisterMetadataClassLookup
public function unregisterMetadataClassLookup($fqcn) { $this->getServiceManager() ->get(MetadataService::SERVICE_ID) ->getImporter() ->unregister(MetadataImporter::CLASS_LOOKUP_KEY, $fqcn); }
php
public function unregisterMetadataClassLookup($fqcn) { $this->getServiceManager() ->get(MetadataService::SERVICE_ID) ->getImporter() ->unregister(MetadataImporter::CLASS_LOOKUP_KEY, $fqcn); }
[ "public", "function", "unregisterMetadataClassLookup", "(", "$", "fqcn", ")", "{", "$", "this", "->", "getServiceManager", "(", ")", "->", "get", "(", "MetadataService", "::", "SERVICE_ID", ")", "->", "getImporter", "(", ")", "->", "unregister", "(", "Metadata...
@deprecated use MetadataService->getImporter()->unregister(MetadataImport::CLASS_LOOKUP_KEY, $fqcn) Unregister a MetadataClassLookup implementation by $fqcn (Fully Qualified Class Name). @param string $fqcn A Fully Qualified Class Name. @see oat\taoQtiItem\model\qti\metadata\MetadataClassLookup The MetadataClassLookup interface.
[ "@deprecated", "use", "MetadataService", "-", ">", "getImporter", "()", "-", ">", "unregister", "(", "MetadataImport", "::", "CLASS_LOOKUP_KEY", "$fqcn", ")" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/metadata/MetadataRegistry.php#L256-L262
oat-sa/extension-tao-itemqti
controller/QtiItemRunner.php
QtiItemRunner.submitResponses
public function submitResponses() { $success = false; $itemUri = $this->getItemUri(); if(!empty($itemUri)){ $this->processResponses(new core_kernel_classes_Resource($itemUri)); $success = true; }else{ throw new common_Exception('missing required itemId'); } }
php
public function submitResponses() { $success = false; $itemUri = $this->getItemUri(); if(!empty($itemUri)){ $this->processResponses(new core_kernel_classes_Resource($itemUri)); $success = true; }else{ throw new common_Exception('missing required itemId'); } }
[ "public", "function", "submitResponses", "(", ")", "{", "$", "success", "=", "false", ";", "$", "itemUri", "=", "$", "this", "->", "getItemUri", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "itemUri", ")", ")", "{", "$", "this", "->", "process...
The main entry poin for respon evaluation @throws common_Exception
[ "The", "main", "entry", "poin", "for", "respon", "evaluation" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/controller/QtiItemRunner.php#L93-L105
oat-sa/extension-tao-itemqti
controller/QtiItemRunner.php
QtiItemRunner.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 occured while loading QTI-XML file at expected location '${qtiXmlFilePath}'."; throw new \RuntimeException($msg, 0, $e); } $itemSession = new AssessmentItemSession($qtiXmlDoc->getDocumentComponent(), new SessionManager()); $itemSession->beginItemSession(); $variables = array(); // Convert client-side data as QtiSm Runtime Variables. foreach($jsonPayload as $identifier => $response) { $filler = new taoQtiCommon_helpers_PciVariableFiller($qtiXmlDoc->getDocumentComponent()); try { $var = $filler->fill($identifier, $response); // Do not take into account QTI File placeholders. if (taoQtiCommon_helpers_Utils::isQtiFilePlaceHolder($var) === false) { $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 '${identifier}' is ignored due to data malformation."); } catch(\OutOfBoundsException $e) { // The response identifier does not match any response declaration. common_Logger::d("Uknown item variable declaration '${identifier}."); } } try { $itemSession->beginAttempt(); $itemSession->endAttempt(new State($variables)); // Transmit results to the Result Server. $this->transmitResults($item, $itemSession); // Return the item session state to the client-side. echo json_encode(array( 'success' => true, 'displayFeedback' => true, 'itemSession' => self::buildOutcomeResponse($itemSession), 'feedbacks' => $this->getFeedbacks($itemSession) )); } catch(AssessmentItemSessionException $e) { $msg = "An error occured while processing the responses."; throw new \RuntimeException($msg, 0, $e); } catch(taoQtiCommon_helpers_ResultTransmissionException $e) { $msg = "An error occured while transmitting variable '${identifier}' 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 occured while loading QTI-XML file at expected location '${qtiXmlFilePath}'."; throw new \RuntimeException($msg, 0, $e); } $itemSession = new AssessmentItemSession($qtiXmlDoc->getDocumentComponent(), new SessionManager()); $itemSession->beginItemSession(); $variables = array(); // Convert client-side data as QtiSm Runtime Variables. foreach($jsonPayload as $identifier => $response) { $filler = new taoQtiCommon_helpers_PciVariableFiller($qtiXmlDoc->getDocumentComponent()); try { $var = $filler->fill($identifier, $response); // Do not take into account QTI File placeholders. if (taoQtiCommon_helpers_Utils::isQtiFilePlaceHolder($var) === false) { $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 '${identifier}' is ignored due to data malformation."); } catch(\OutOfBoundsException $e) { // The response identifier does not match any response declaration. common_Logger::d("Uknown item variable declaration '${identifier}."); } } try { $itemSession->beginAttempt(); $itemSession->endAttempt(new State($variables)); // Transmit results to the Result Server. $this->transmitResults($item, $itemSession); // Return the item session state to the client-side. echo json_encode(array( 'success' => true, 'displayFeedback' => true, 'itemSession' => self::buildOutcomeResponse($itemSession), 'feedbacks' => $this->getFeedbacks($itemSession) )); } catch(AssessmentItemSessionException $e) { $msg = "An error occured while processing the responses."; throw new \RuntimeException($msg, 0, $e); } catch(taoQtiCommon_helpers_ResultTransmissionException $e) { $msg = "An error occured while transmitting variable '${identifier}' 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. @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/QtiItemRunner.php#L112-L178
oat-sa/extension-tao-itemqti
controller/QtiItemRunner.php
QtiItemRunner.transmitResults
protected function transmitResults(core_kernel_classes_Resource $item, AssessmentItemSession $itemSession) { $resultTransmitter = new taoQtiCommon_helpers_ResultTransmitter(taoResultServer_models_classes_ResultServerStateFull::singleton()); foreach ($itemSession->getKeys() as $identifier) { // QTI built-in variables not suitable for this standalone QTI item execution case. if (!in_array($identifier, array('completionStatus', 'numAttempts', 'duration'))) { // Transmit to Result Server. $resultTransmitter->transmitItemVariable($itemSession->getVariable($identifier), $this->getServiceCallId(), $item->getUri()); } } }
php
protected function transmitResults(core_kernel_classes_Resource $item, AssessmentItemSession $itemSession) { $resultTransmitter = new taoQtiCommon_helpers_ResultTransmitter(taoResultServer_models_classes_ResultServerStateFull::singleton()); foreach ($itemSession->getKeys() as $identifier) { // QTI built-in variables not suitable for this standalone QTI item execution case. if (!in_array($identifier, array('completionStatus', 'numAttempts', 'duration'))) { // Transmit to Result Server. $resultTransmitter->transmitItemVariable($itemSession->getVariable($identifier), $this->getServiceCallId(), $item->getUri()); } } }
[ "protected", "function", "transmitResults", "(", "core_kernel_classes_Resource", "$", "item", ",", "AssessmentItemSession", "$", "itemSession", ")", "{", "$", "resultTransmitter", "=", "new", "taoQtiCommon_helpers_ResultTransmitter", "(", "taoResultServer_models_classes_ResultS...
Transmit the variables contained in the AssessmentTestSession $itemSession as item results to the Result Server. @param core_kernel_classes_Resource $item The item definition in database. @param AssessmentItemSession $itemSession The AssessmentItemSession objects from where the results must be extracted. @throws taoQtiCommon_helpers_ResultTransmissionException If an error occurs while transmitting results to the ResultServer.
[ "Transmit", "the", "variables", "contained", "in", "the", "AssessmentTestSession", "$itemSession", "as", "item", "results", "to", "the", "Result", "Server", "." ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/controller/QtiItemRunner.php#L188-L198
oat-sa/extension-tao-itemqti
model/qti/response/Custom.php
Custom.getRule
public function getRule(){ $returnValue = (string) ''; foreach($this->responseRules as $responseRule){ $returnValue .= $responseRule->getRule(); } return (string) $returnValue; }
php
public function getRule(){ $returnValue = (string) ''; foreach($this->responseRules as $responseRule){ $returnValue .= $responseRule->getRule(); } return (string) $returnValue; }
[ "public", "function", "getRule", "(", ")", "{", "$", "returnValue", "=", "(", "string", ")", "''", ";", "foreach", "(", "$", "this", "->", "responseRules", "as", "$", "responseRule", ")", "{", "$", "returnValue", ".=", "$", "responseRule", "->", "getRule...
Short description of method getRule @access public @author Joel Bout, <joel.bout@tudor.lu> @return string
[ "Short", "description", "of", "method", "getRule" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/qti/response/Custom.php#L62-L70
oat-sa/extension-tao-itemqti
model/update/ItemUpdateInlineFeedback.php
ItemUpdateInlineFeedback.updateItem
protected function updateItem(\oat\taoQtiItem\model\qti\Item $item, $itemFile) { $changed = false; $responses = $item->getResponses(); foreach ($responses as $response) { $responseIdentifier = $response->attr('identifier'); $rules = $response->getFeedbackRules(); foreach ($rules as $rule) { $modalFeedbacks = array(); if ($rule->getFeedbackThen()) { $modalFeedbacks[] = $rule->getFeedbackThen(); } if ($rule->getFeedbackElse()) { $modalFeedbacks[] = $rule->getFeedbackElse(); } foreach ($modalFeedbacks as $modalFeedback) { $feedbackXml = simplexml_load_string($modalFeedback->toQti()); if ($feedbackXml->div[0] && $feedbackXml->div[0]['class'] && preg_match('/^x-tao-wrapper/', $feedbackXml->div[0]['class'])) { //the item body has not already been wrapped by the new wrapper <div class="x-tao-wrapper w-tao-relatedOutcome-{{response.identifier}}"> continue; } $message = $modalFeedback->getBody()->getBody(); $modalFeedback->getBody()->edit('<div class="x-tao-wrapper x-tao-relatedOutcome-'.$responseIdentifier.'">'.$message.'</div>', true); $changed = true; } } } return $changed; }
php
protected function updateItem(\oat\taoQtiItem\model\qti\Item $item, $itemFile) { $changed = false; $responses = $item->getResponses(); foreach ($responses as $response) { $responseIdentifier = $response->attr('identifier'); $rules = $response->getFeedbackRules(); foreach ($rules as $rule) { $modalFeedbacks = array(); if ($rule->getFeedbackThen()) { $modalFeedbacks[] = $rule->getFeedbackThen(); } if ($rule->getFeedbackElse()) { $modalFeedbacks[] = $rule->getFeedbackElse(); } foreach ($modalFeedbacks as $modalFeedback) { $feedbackXml = simplexml_load_string($modalFeedback->toQti()); if ($feedbackXml->div[0] && $feedbackXml->div[0]['class'] && preg_match('/^x-tao-wrapper/', $feedbackXml->div[0]['class'])) { //the item body has not already been wrapped by the new wrapper <div class="x-tao-wrapper w-tao-relatedOutcome-{{response.identifier}}"> continue; } $message = $modalFeedback->getBody()->getBody(); $modalFeedback->getBody()->edit('<div class="x-tao-wrapper x-tao-relatedOutcome-'.$responseIdentifier.'">'.$message.'</div>', true); $changed = true; } } } return $changed; }
[ "protected", "function", "updateItem", "(", "\\", "oat", "\\", "taoQtiItem", "\\", "model", "\\", "qti", "\\", "Item", "$", "item", ",", "$", "itemFile", ")", "{", "$", "changed", "=", "false", ";", "$", "responses", "=", "$", "item", "->", "getRespons...
Update the item content by wrapping the modalfeedback body into a new wrapper @param oat\taoQtiItem\modal\Item $item @param string $itemFile @return boolean
[ "Update", "the", "item", "content", "by", "wrapping", "the", "modalfeedback", "body", "into", "a", "new", "wrapper" ]
train
https://github.com/oat-sa/extension-tao-itemqti/blob/a55b73c7894523bde169ba520d5001ce7b5bb88c/model/update/ItemUpdateInlineFeedback.php#L38-L72
webmozart/glob
src/Iterator/RegexFilterIterator.php
RegexFilterIterator.key
public function key() { if (!$this->valid()) { return null; } if ($this->mode & self::KEY_AS_KEY) { return parent::key(); } return $this->cursor; }
php
public function key() { if (!$this->valid()) { return null; } if ($this->mode & self::KEY_AS_KEY) { return parent::key(); } return $this->cursor; }
[ "public", "function", "key", "(", ")", "{", "if", "(", "!", "$", "this", "->", "valid", "(", ")", ")", "{", "return", "null", ";", "}", "if", "(", "$", "this", "->", "mode", "&", "self", "::", "KEY_AS_KEY", ")", "{", "return", "parent", "::", "...
Returns the current position. @return int The current position.
[ "Returns", "the", "current", "position", "." ]
train
https://github.com/webmozart/glob/blob/8da14867b709e8776d9f6272faaf844aefc695e3/src/Iterator/RegexFilterIterator.php#L109-L120
webmozart/glob
src/Iterator/RegexFilterIterator.php
RegexFilterIterator.accept
public function accept() { $path = ($this->mode & self::FILTER_VALUE) ? $this->current() : parent::key(); if (0 !== strpos($path, $this->staticPrefix)) { return false; } $result = (bool) preg_match($this->regExp, $path); return $result; }
php
public function accept() { $path = ($this->mode & self::FILTER_VALUE) ? $this->current() : parent::key(); if (0 !== strpos($path, $this->staticPrefix)) { return false; } $result = (bool) preg_match($this->regExp, $path); return $result; }
[ "public", "function", "accept", "(", ")", "{", "$", "path", "=", "(", "$", "this", "->", "mode", "&", "self", "::", "FILTER_VALUE", ")", "?", "$", "this", "->", "current", "(", ")", ":", "parent", "::", "key", "(", ")", ";", "if", "(", "0", "!=...
Accepts paths matching the glob. @return bool Whether the path is accepted.
[ "Accepts", "paths", "matching", "the", "glob", "." ]
train
https://github.com/webmozart/glob/blob/8da14867b709e8776d9f6272faaf844aefc695e3/src/Iterator/RegexFilterIterator.php#L140-L151
webmozart/glob
src/Glob.php
Glob.glob
public static function glob($glob, $flags = 0) { $results = iterator_to_array(new GlobIterator($glob, $flags)); sort($results); return $results; }
php
public static function glob($glob, $flags = 0) { $results = iterator_to_array(new GlobIterator($glob, $flags)); sort($results); return $results; }
[ "public", "static", "function", "glob", "(", "$", "glob", ",", "$", "flags", "=", "0", ")", "{", "$", "results", "=", "iterator_to_array", "(", "new", "GlobIterator", "(", "$", "glob", ",", "$", "flags", ")", ")", ";", "sort", "(", "$", "results", ...
Globs the file system paths matching the glob. The glob may contain the wildcard "*". This wildcard matches any number of characters, *including* directory separators. ```php foreach (Glob::glob('/project/**.twig') as $path) { // do something... } ``` @param string $glob The canonical glob. The glob should contain forward slashes as directory separators only. It must not contain any "." or ".." segments. Use the "webmozart/path-util" utility to canonicalize globs prior to calling this method. @param int $flags A bitwise combination of the flag constants in this class. @return string[] The matching paths. The keys of the array are incrementing integers.
[ "Globs", "the", "file", "system", "paths", "matching", "the", "glob", "." ]
train
https://github.com/webmozart/glob/blob/8da14867b709e8776d9f6272faaf844aefc695e3/src/Glob.php#L110-L117
webmozart/glob
src/Glob.php
Glob.match
public static function match($path, $glob, $flags = 0) { if (!self::isDynamic($glob)) { return $glob === $path; } if (0 !== strpos($path, self::getStaticPrefix($glob, $flags))) { return false; } if (!preg_match(self::toRegEx($glob, $flags), $path)) { return false; } return true; }
php
public static function match($path, $glob, $flags = 0) { if (!self::isDynamic($glob)) { return $glob === $path; } if (0 !== strpos($path, self::getStaticPrefix($glob, $flags))) { return false; } if (!preg_match(self::toRegEx($glob, $flags), $path)) { return false; } return true; }
[ "public", "static", "function", "match", "(", "$", "path", ",", "$", "glob", ",", "$", "flags", "=", "0", ")", "{", "if", "(", "!", "self", "::", "isDynamic", "(", "$", "glob", ")", ")", "{", "return", "$", "glob", "===", "$", "path", ";", "}",...
Matches a path against a glob. ```php if (Glob::match('/project/views/index.html.twig', '/project/**.twig')) { // path matches } ``` @param string $path The path to match. @param string $glob The canonical glob. The glob should contain forward slashes as directory separators only. It must not contain any "." or ".." segments. Use the "webmozart/path-util" utility to canonicalize globs prior to calling this method. @param int $flags A bitwise combination of the flag constants in this class. @return bool Returns `true` if the path is matched by the glob.
[ "Matches", "a", "path", "against", "a", "glob", "." ]
train
https://github.com/webmozart/glob/blob/8da14867b709e8776d9f6272faaf844aefc695e3/src/Glob.php#L139-L154
webmozart/glob
src/Glob.php
Glob.filter
public static function filter(array $paths, $glob, $flags = self::FILTER_VALUE) { if (($flags & self::FILTER_VALUE) && ($flags & self::FILTER_KEY)) { throw new InvalidArgumentException('The flags Glob::FILTER_VALUE and Glob::FILTER_KEY cannot be passed at the same time.'); } if (!self::isDynamic($glob)) { if ($flags & self::FILTER_KEY) { return isset($paths[$glob]) ? array($glob => $paths[$glob]) : array(); } $key = array_search($glob, $paths); return false !== $key ? array($key => $glob) : array(); } $staticPrefix = self::getStaticPrefix($glob, $flags); $regExp = self::toRegEx($glob, $flags); $filter = function ($path) use ($staticPrefix, $regExp) { return 0 === strpos($path, $staticPrefix) && preg_match($regExp, $path); }; if (PHP_VERSION_ID >= 50600) { $filterFlags = ($flags & self::FILTER_KEY) ? ARRAY_FILTER_USE_KEY : 0; return array_filter($paths, $filter, $filterFlags); } // No support yet for the third argument of array_filter() if ($flags & self::FILTER_KEY) { $result = array(); foreach ($paths as $path => $value) { if ($filter($path)) { $result[$path] = $value; } } return $result; } return array_filter($paths, $filter); }
php
public static function filter(array $paths, $glob, $flags = self::FILTER_VALUE) { if (($flags & self::FILTER_VALUE) && ($flags & self::FILTER_KEY)) { throw new InvalidArgumentException('The flags Glob::FILTER_VALUE and Glob::FILTER_KEY cannot be passed at the same time.'); } if (!self::isDynamic($glob)) { if ($flags & self::FILTER_KEY) { return isset($paths[$glob]) ? array($glob => $paths[$glob]) : array(); } $key = array_search($glob, $paths); return false !== $key ? array($key => $glob) : array(); } $staticPrefix = self::getStaticPrefix($glob, $flags); $regExp = self::toRegEx($glob, $flags); $filter = function ($path) use ($staticPrefix, $regExp) { return 0 === strpos($path, $staticPrefix) && preg_match($regExp, $path); }; if (PHP_VERSION_ID >= 50600) { $filterFlags = ($flags & self::FILTER_KEY) ? ARRAY_FILTER_USE_KEY : 0; return array_filter($paths, $filter, $filterFlags); } // No support yet for the third argument of array_filter() if ($flags & self::FILTER_KEY) { $result = array(); foreach ($paths as $path => $value) { if ($filter($path)) { $result[$path] = $value; } } return $result; } return array_filter($paths, $filter); }
[ "public", "static", "function", "filter", "(", "array", "$", "paths", ",", "$", "glob", ",", "$", "flags", "=", "self", "::", "FILTER_VALUE", ")", "{", "if", "(", "(", "$", "flags", "&", "self", "::", "FILTER_VALUE", ")", "&&", "(", "$", "flags", "...
Filters an array for paths matching a glob. The filtered array is returned. This array preserves the keys of the passed array. ```php $filteredPaths = Glob::filter($paths, '/project/**.twig'); ``` @param string[] $paths A list of paths. @param string $glob The canonical glob. The glob should contain forward slashes as directory separators only. It must not contain any "." or ".." segments. Use the "webmozart/path-util" utility to canonicalize globs prior to calling this method. @param int $flags A bitwise combination of the flag constants in this class. @return string[] The paths matching the glob indexed by their original keys.
[ "Filters", "an", "array", "for", "paths", "matching", "a", "glob", "." ]
train
https://github.com/webmozart/glob/blob/8da14867b709e8776d9f6272faaf844aefc695e3/src/Glob.php#L178-L220
webmozart/glob
src/Glob.php
Glob.getBasePath
public static function getBasePath($glob, $flags = 0) { // Search the static prefix for the last "/" $staticPrefix = self::getStaticPrefix($glob, $flags); if (false !== ($pos = strrpos($staticPrefix, '/'))) { // Special case: Return "/" if the only slash is at the beginning // of the glob if (0 === $pos) { return '/'; } // Special case: Include trailing slash of "scheme:///foo" if ($pos - 3 === strpos($glob, '://')) { return substr($staticPrefix, 0, $pos + 1); } return substr($staticPrefix, 0, $pos); } // Glob contains no slashes on the left of the wildcard // Return an empty string return ''; }
php
public static function getBasePath($glob, $flags = 0) { // Search the static prefix for the last "/" $staticPrefix = self::getStaticPrefix($glob, $flags); if (false !== ($pos = strrpos($staticPrefix, '/'))) { // Special case: Return "/" if the only slash is at the beginning // of the glob if (0 === $pos) { return '/'; } // Special case: Include trailing slash of "scheme:///foo" if ($pos - 3 === strpos($glob, '://')) { return substr($staticPrefix, 0, $pos + 1); } return substr($staticPrefix, 0, $pos); } // Glob contains no slashes on the left of the wildcard // Return an empty string return ''; }
[ "public", "static", "function", "getBasePath", "(", "$", "glob", ",", "$", "flags", "=", "0", ")", "{", "// Search the static prefix for the last \"/\"", "$", "staticPrefix", "=", "self", "::", "getStaticPrefix", "(", "$", "glob", ",", "$", "flags", ")", ";", ...
Returns the base path of a glob. This method returns the most specific directory that contains all files matched by the glob. If this directory does not exist on the file system, it's not necessary to execute the glob algorithm. More specifically, the "base path" is the longest path trailed by a "/" on the left of the first wildcard "*". If the glob does not contain wildcards, the directory name of the glob is returned. ```php Glob::getBasePath('/css/*.css'); // => /css Glob::getBasePath('/css/style.css'); // => /css Glob::getBasePath('/css/st*.css'); // => /css Glob::getBasePath('/*.css'); // => / ``` @param string $glob The canonical glob. The glob should contain forward slashes as directory separators only. It must not contain any "." or ".." segments. Use the "webmozart/path-util" utility to canonicalize globs prior to calling this method. @param int $flags A bitwise combination of the flag constants in this class. @return string The base path of the glob.
[ "Returns", "the", "base", "path", "of", "a", "glob", "." ]
train
https://github.com/webmozart/glob/blob/8da14867b709e8776d9f6272faaf844aefc695e3/src/Glob.php#L257-L280
webmozart/glob
src/Glob.php
Glob.toRegEx
public static function toRegEx($glob, $flags = 0, $delimiter = '~') { if (!Path::isAbsolute($glob) && false === strpos($glob, '://')) { throw new InvalidArgumentException(sprintf( 'The glob "%s" is not absolute and not a URI.', $glob )); } $inSquare = false; $curlyLevels = 0; $regex = ''; $length = strlen($glob); for ($i = 0; $i < $length; ++$i) { $c = $glob[$i]; switch ($c) { case '.': case '(': case ')': case '|': case '+': case '^': case '$': case $delimiter: $regex .= "\\$c"; break; case '/': if (isset($glob[$i + 3]) && '**/' === $glob[$i + 1].$glob[$i + 2].$glob[$i + 3]) { $regex .= '/([^/]+/)*'; $i += 3; } else { $regex .= '/'; } break; case '*': $regex .= '[^/]*'; break; case '?': $regex .= '.'; break; case '{': $regex .= '('; ++$curlyLevels; break; case '}': if ($curlyLevels > 0) { $regex .= ')'; --$curlyLevels; } else { $regex .= '}'; } break; case ',': $regex .= $curlyLevels > 0 ? '|' : ','; break; case '[': $regex .= '['; $inSquare = true; if (isset($glob[$i + 1]) && '^' === $glob[$i + 1]) { $regex .= '^'; ++$i; } break; case ']': $regex .= $inSquare ? ']' : '\\]'; $inSquare = false; break; case '-': $regex .= $inSquare ? '-' : '\\-'; break; case '\\': if (isset($glob[$i + 1])) { switch ($glob[$i + 1]) { case '*': case '?': case '{': case '}': case '[': case ']': case '-': case '^': case '\\': $regex .= '\\'.$glob[$i + 1]; ++$i; break; default: $regex .= '\\\\'; } } else { $regex .= '\\\\'; } break; default: $regex .= $c; break; } } if ($inSquare) { throw new InvalidArgumentException(sprintf( 'Invalid glob: missing ] in %s', $glob )); } if ($curlyLevels > 0) { throw new InvalidArgumentException(sprintf( 'Invalid glob: missing } in %s', $glob )); } return $delimiter.'^'.$regex.'$'.$delimiter; }
php
public static function toRegEx($glob, $flags = 0, $delimiter = '~') { if (!Path::isAbsolute($glob) && false === strpos($glob, '://')) { throw new InvalidArgumentException(sprintf( 'The glob "%s" is not absolute and not a URI.', $glob )); } $inSquare = false; $curlyLevels = 0; $regex = ''; $length = strlen($glob); for ($i = 0; $i < $length; ++$i) { $c = $glob[$i]; switch ($c) { case '.': case '(': case ')': case '|': case '+': case '^': case '$': case $delimiter: $regex .= "\\$c"; break; case '/': if (isset($glob[$i + 3]) && '**/' === $glob[$i + 1].$glob[$i + 2].$glob[$i + 3]) { $regex .= '/([^/]+/)*'; $i += 3; } else { $regex .= '/'; } break; case '*': $regex .= '[^/]*'; break; case '?': $regex .= '.'; break; case '{': $regex .= '('; ++$curlyLevels; break; case '}': if ($curlyLevels > 0) { $regex .= ')'; --$curlyLevels; } else { $regex .= '}'; } break; case ',': $regex .= $curlyLevels > 0 ? '|' : ','; break; case '[': $regex .= '['; $inSquare = true; if (isset($glob[$i + 1]) && '^' === $glob[$i + 1]) { $regex .= '^'; ++$i; } break; case ']': $regex .= $inSquare ? ']' : '\\]'; $inSquare = false; break; case '-': $regex .= $inSquare ? '-' : '\\-'; break; case '\\': if (isset($glob[$i + 1])) { switch ($glob[$i + 1]) { case '*': case '?': case '{': case '}': case '[': case ']': case '-': case '^': case '\\': $regex .= '\\'.$glob[$i + 1]; ++$i; break; default: $regex .= '\\\\'; } } else { $regex .= '\\\\'; } break; default: $regex .= $c; break; } } if ($inSquare) { throw new InvalidArgumentException(sprintf( 'Invalid glob: missing ] in %s', $glob )); } if ($curlyLevels > 0) { throw new InvalidArgumentException(sprintf( 'Invalid glob: missing } in %s', $glob )); } return $delimiter.'^'.$regex.'$'.$delimiter; }
[ "public", "static", "function", "toRegEx", "(", "$", "glob", ",", "$", "flags", "=", "0", ",", "$", "delimiter", "=", "'~'", ")", "{", "if", "(", "!", "Path", "::", "isAbsolute", "(", "$", "glob", ")", "&&", "false", "===", "strpos", "(", "$", "g...
Converts a glob to a regular expression. Use this method if you need to match many paths against a glob: ```php $staticPrefix = Glob::getStaticPrefix('/project/**.twig'); $regEx = Glob::toRegEx('/project/**.twig'); if (0 !== strpos($path, $staticPrefix)) { // no match } if (!preg_match($regEx, $path)) { // no match } ``` You should always test whether a path contains the static prefix of the glob returned by {@link getStaticPrefix()} to reduce the number of calls to the expensive {@link preg_match()}. @param string $glob The canonical glob. The glob should contain forward slashes as directory separators only. It must not contain any "." or ".." segments. Use the "webmozart/path-util" utility to canonicalize globs prior to calling this method. @param int $flags A bitwise combination of the flag constants in this class. @return string The regular expression for matching the glob.
[ "Converts", "a", "glob", "to", "a", "regular", "expression", "." ]
train
https://github.com/webmozart/glob/blob/8da14867b709e8776d9f6272faaf844aefc695e3/src/Glob.php#L314-L441
webmozart/glob
src/Glob.php
Glob.getStaticPrefix
public static function getStaticPrefix($glob, $flags = 0) { if (!Path::isAbsolute($glob) && false === strpos($glob, '://')) { throw new InvalidArgumentException(sprintf( 'The glob "%s" is not absolute and not a URI.', $glob )); } $prefix = ''; $length = strlen($glob); for ($i = 0; $i < $length; ++$i) { $c = $glob[$i]; switch ($c) { case '/': $prefix .= '/'; if (isset($glob[$i + 3]) && '**/' === $glob[$i + 1].$glob[$i + 2].$glob[$i + 3]) { break 2; } break; case '*': case '?': case '{': case '[': break 2; case '\\': if (isset($glob[$i + 1])) { switch ($glob[$i + 1]) { case '*': case '?': case '{': case '[': case '\\': $prefix .= $glob[$i + 1]; ++$i; break; default: $prefix .= '\\'; } } else { $prefix .= '\\'; } break; default: $prefix .= $c; break; } } return $prefix; }
php
public static function getStaticPrefix($glob, $flags = 0) { if (!Path::isAbsolute($glob) && false === strpos($glob, '://')) { throw new InvalidArgumentException(sprintf( 'The glob "%s" is not absolute and not a URI.', $glob )); } $prefix = ''; $length = strlen($glob); for ($i = 0; $i < $length; ++$i) { $c = $glob[$i]; switch ($c) { case '/': $prefix .= '/'; if (isset($glob[$i + 3]) && '**/' === $glob[$i + 1].$glob[$i + 2].$glob[$i + 3]) { break 2; } break; case '*': case '?': case '{': case '[': break 2; case '\\': if (isset($glob[$i + 1])) { switch ($glob[$i + 1]) { case '*': case '?': case '{': case '[': case '\\': $prefix .= $glob[$i + 1]; ++$i; break; default: $prefix .= '\\'; } } else { $prefix .= '\\'; } break; default: $prefix .= $c; break; } } return $prefix; }
[ "public", "static", "function", "getStaticPrefix", "(", "$", "glob", ",", "$", "flags", "=", "0", ")", "{", "if", "(", "!", "Path", "::", "isAbsolute", "(", "$", "glob", ")", "&&", "false", "===", "strpos", "(", "$", "glob", ",", "'://'", ")", ")",...
Returns the static prefix of a glob. The "static prefix" is the part of the glob up to the first wildcard "*". If the glob does not contain wildcards, the full glob is returned. @param string $glob The canonical glob. The glob should contain forward slashes as directory separators only. It must not contain any "." or ".." segments. Use the "webmozart/path-util" utility to canonicalize globs prior to calling this method. @param int $flags A bitwise combination of the flag constants in this class. @return string The static prefix of the glob.
[ "Returns", "the", "static", "prefix", "of", "a", "glob", "." ]
train
https://github.com/webmozart/glob/blob/8da14867b709e8776d9f6272faaf844aefc695e3/src/Glob.php#L459-L515
webmozart/glob
src/Glob.php
Glob.isDynamic
public static function isDynamic($glob) { return false !== strpos($glob, '*') || false !== strpos($glob, '{') || false !== strpos($glob, '?') || false !== strpos($glob, '['); }
php
public static function isDynamic($glob) { return false !== strpos($glob, '*') || false !== strpos($glob, '{') || false !== strpos($glob, '?') || false !== strpos($glob, '['); }
[ "public", "static", "function", "isDynamic", "(", "$", "glob", ")", "{", "return", "false", "!==", "strpos", "(", "$", "glob", ",", "'*'", ")", "||", "false", "!==", "strpos", "(", "$", "glob", ",", "'{'", ")", "||", "false", "!==", "strpos", "(", ...
Returns whether the glob contains a dynamic part. The glob contains a dynamic part if it contains an unescaped "*" or "{" character. @param string $glob The glob to test. @return bool Returns `true` if the glob contains a dynamic part and `false` otherwise.
[ "Returns", "whether", "the", "glob", "contains", "a", "dynamic", "part", "." ]
train
https://github.com/webmozart/glob/blob/8da14867b709e8776d9f6272faaf844aefc695e3/src/Glob.php#L528-L531
webmozart/glob
src/Iterator/RecursiveDirectoryIterator.php
RecursiveDirectoryIterator.key
public function key() { $key = parent::key(); if ($this->normalizeKey) { $key = str_replace('\\', '/', $key); } return $key; }
php
public function key() { $key = parent::key(); if ($this->normalizeKey) { $key = str_replace('\\', '/', $key); } return $key; }
[ "public", "function", "key", "(", ")", "{", "$", "key", "=", "parent", "::", "key", "(", ")", ";", "if", "(", "$", "this", "->", "normalizeKey", ")", "{", "$", "key", "=", "str_replace", "(", "'\\\\'", ",", "'/'", ",", "$", "key", ")", ";", "}"...
{@inheritdoc}
[ "{" ]
train
https://github.com/webmozart/glob/blob/8da14867b709e8776d9f6272faaf844aefc695e3/src/Iterator/RecursiveDirectoryIterator.php#L61-L70
webmozart/glob
src/Iterator/RecursiveDirectoryIterator.php
RecursiveDirectoryIterator.current
public function current() { $current = parent::current(); if ($this->normalizeCurrent) { $current = str_replace('\\', '/', $current); } return $current; }
php
public function current() { $current = parent::current(); if ($this->normalizeCurrent) { $current = str_replace('\\', '/', $current); } return $current; }
[ "public", "function", "current", "(", ")", "{", "$", "current", "=", "parent", "::", "current", "(", ")", ";", "if", "(", "$", "this", "->", "normalizeCurrent", ")", "{", "$", "current", "=", "str_replace", "(", "'\\\\'", ",", "'/'", ",", "$", "curre...
{@inheritdoc}
[ "{" ]
train
https://github.com/webmozart/glob/blob/8da14867b709e8776d9f6272faaf844aefc695e3/src/Iterator/RecursiveDirectoryIterator.php#L75-L84
sonata-project/SonataClassificationBundle
src/Block/Service/AbstractClassificationBlockService.php
AbstractClassificationBlockService.getFormAdminType
final protected function getFormAdminType(FormMapper $formMapper, AdminInterface $admin, $formField, $field, $fieldOptions = [], $adminOptions = []) { $adminOptions = array_merge([ 'edit' => 'list', 'translation_domain' => 'SonataClassificationBundle', ], $adminOptions); $fieldDescription = $admin->getModelManager()->getNewFieldDescriptionInstance($admin->getClass(), $field, $adminOptions); $fieldDescription->setAssociationAdmin($admin); $fieldDescription->setAdmin($formMapper->getAdmin()); $fieldDescription->setAssociationMapping([ 'fieldName' => $field, 'type' => ClassMetadataInfo::MANY_TO_ONE, ]); $fieldOptions = array_merge([ 'sonata_field_description' => $fieldDescription, 'class' => $admin->getClass(), 'model_manager' => $admin->getModelManager(), 'required' => false, ], $fieldOptions); return $formMapper->create($formField, ModelTypeList::class, $fieldOptions); }
php
final protected function getFormAdminType(FormMapper $formMapper, AdminInterface $admin, $formField, $field, $fieldOptions = [], $adminOptions = []) { $adminOptions = array_merge([ 'edit' => 'list', 'translation_domain' => 'SonataClassificationBundle', ], $adminOptions); $fieldDescription = $admin->getModelManager()->getNewFieldDescriptionInstance($admin->getClass(), $field, $adminOptions); $fieldDescription->setAssociationAdmin($admin); $fieldDescription->setAdmin($formMapper->getAdmin()); $fieldDescription->setAssociationMapping([ 'fieldName' => $field, 'type' => ClassMetadataInfo::MANY_TO_ONE, ]); $fieldOptions = array_merge([ 'sonata_field_description' => $fieldDescription, 'class' => $admin->getClass(), 'model_manager' => $admin->getModelManager(), 'required' => false, ], $fieldOptions); return $formMapper->create($formField, ModelTypeList::class, $fieldOptions); }
[ "final", "protected", "function", "getFormAdminType", "(", "FormMapper", "$", "formMapper", ",", "AdminInterface", "$", "admin", ",", "$", "formField", ",", "$", "field", ",", "$", "fieldOptions", "=", "[", "]", ",", "$", "adminOptions", "=", "[", "]", ")"...
@param FormMapper $formMapper @param AdminInterface $admin @param string $formField @param string $field @param array $fieldOptions @param array $adminOptions @return FormBuilder
[ "@param", "FormMapper", "$formMapper", "@param", "AdminInterface", "$admin", "@param", "string", "$formField", "@param", "string", "$field", "@param", "array", "$fieldOptions", "@param", "array", "$adminOptions" ]
train
https://github.com/sonata-project/SonataClassificationBundle/blob/f75add739dc0f79e02933fb87aca0ea8355a1a4b/src/Block/Service/AbstractClassificationBlockService.php#L58-L81
sonata-project/SonataClassificationBundle
src/Block/Service/AbstractClassificationBlockService.php
AbstractClassificationBlockService.getContextChoices
final protected function getContextChoices() { $contextChoices = []; /* @var ContextInterface $context */ foreach ($this->contextManager->findAll() as $context) { $contextChoices[$context->getId()] = $context->getName(); } return $contextChoices; }
php
final protected function getContextChoices() { $contextChoices = []; /* @var ContextInterface $context */ foreach ($this->contextManager->findAll() as $context) { $contextChoices[$context->getId()] = $context->getName(); } return $contextChoices; }
[ "final", "protected", "function", "getContextChoices", "(", ")", "{", "$", "contextChoices", "=", "[", "]", ";", "/* @var ContextInterface $context */", "foreach", "(", "$", "this", "->", "contextManager", "->", "findAll", "(", ")", "as", "$", "context", ")", ...
Returns a context choice array. @return string[]
[ "Returns", "a", "context", "choice", "array", "." ]
train
https://github.com/sonata-project/SonataClassificationBundle/blob/f75add739dc0f79e02933fb87aca0ea8355a1a4b/src/Block/Service/AbstractClassificationBlockService.php#L88-L97
sonata-project/SonataClassificationBundle
src/Admin/TagAdmin.php
TagAdmin.configureFormFields
protected function configureFormFields(FormMapper $formMapper) { $formMapper ->add('name') ->add('context') ; if ($this->hasSubject() && $this->getSubject()->getId()) { $formMapper->add('slug'); } $formMapper->add('enabled', CheckboxType::class, [ 'required' => false, ]); }
php
protected function configureFormFields(FormMapper $formMapper) { $formMapper ->add('name') ->add('context') ; if ($this->hasSubject() && $this->getSubject()->getId()) { $formMapper->add('slug'); } $formMapper->add('enabled', CheckboxType::class, [ 'required' => false, ]); }
[ "protected", "function", "configureFormFields", "(", "FormMapper", "$", "formMapper", ")", "{", "$", "formMapper", "->", "add", "(", "'name'", ")", "->", "add", "(", "'context'", ")", ";", "if", "(", "$", "this", "->", "hasSubject", "(", ")", "&&", "$", ...
{@inheritdoc}
[ "{" ]
train
https://github.com/sonata-project/SonataClassificationBundle/blob/f75add739dc0f79e02933fb87aca0ea8355a1a4b/src/Admin/TagAdmin.php#L28-L42
sonata-project/SonataClassificationBundle
src/Admin/CategoryAdmin.php
CategoryAdmin.getFormBuilder
public function getFormBuilder() { // NEXT_MAJOR: set constraints unconditionally if (isset($this->formOptions['cascade_validation'])) { unset($this->formOptions['cascade_validation']); $this->formOptions['constraints'][] = new Valid(); } else { @trigger_error(<<<'EOT' Unsetting cascade_validation is deprecated since 3.2, and will give an error in 4.0. Override getFormBuilder() and remove the "Valid" constraint instead. EOT , E_USER_DEPRECATED); } return parent::getFormBuilder(); }
php
public function getFormBuilder() { // NEXT_MAJOR: set constraints unconditionally if (isset($this->formOptions['cascade_validation'])) { unset($this->formOptions['cascade_validation']); $this->formOptions['constraints'][] = new Valid(); } else { @trigger_error(<<<'EOT' Unsetting cascade_validation is deprecated since 3.2, and will give an error in 4.0. Override getFormBuilder() and remove the "Valid" constraint instead. EOT , E_USER_DEPRECATED); } return parent::getFormBuilder(); }
[ "public", "function", "getFormBuilder", "(", ")", "{", "// NEXT_MAJOR: set constraints unconditionally", "if", "(", "isset", "(", "$", "this", "->", "formOptions", "[", "'cascade_validation'", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "formOptions", "...
{@inheritdoc}
[ "{" ]
train
https://github.com/sonata-project/SonataClassificationBundle/blob/f75add739dc0f79e02933fb87aca0ea8355a1a4b/src/Admin/CategoryAdmin.php#L48-L63
sonata-project/SonataClassificationBundle
src/Admin/CategoryAdmin.php
CategoryAdmin.configureFormFields
protected function configureFormFields(FormMapper $formMapper) { $formMapper ->with('group_general', ['class' => 'col-md-6']) ->add('name') ->add('description', TextareaType::class, [ 'required' => false, ]) ; if ($this->hasSubject()) { if (null !== $this->getSubject()->getParent() || null === $this->getSubject()->getId()) { // root category cannot have a parent $formMapper ->add('parent', CategorySelectorType::class, [ 'category' => $this->getSubject() ?: null, 'model_manager' => $this->getModelManager(), 'class' => $this->getClass(), 'required' => true, 'context' => $this->getSubject()->getContext(), ]) ; } } $position = $this->hasSubject() && null !== $this->getSubject()->getPosition() ? $this->getSubject()->getPosition() : 0; $formMapper ->end() ->with('group_options', ['class' => 'col-md-6']) ->add('enabled', CheckboxType::class, [ 'required' => false, ]) ->add('position', IntegerType::class, [ 'required' => false, 'data' => $position, ]) ->end() ; if (interface_exists(MediaInterface::class)) { $formMapper ->with('group_general') ->add('media', ModelListType::class, [ 'required' => false, ], [ 'link_parameters' => [ 'provider' => 'sonata.media.provider.image', 'context' => 'sonata_category', ], ]) ->end(); } }
php
protected function configureFormFields(FormMapper $formMapper) { $formMapper ->with('group_general', ['class' => 'col-md-6']) ->add('name') ->add('description', TextareaType::class, [ 'required' => false, ]) ; if ($this->hasSubject()) { if (null !== $this->getSubject()->getParent() || null === $this->getSubject()->getId()) { // root category cannot have a parent $formMapper ->add('parent', CategorySelectorType::class, [ 'category' => $this->getSubject() ?: null, 'model_manager' => $this->getModelManager(), 'class' => $this->getClass(), 'required' => true, 'context' => $this->getSubject()->getContext(), ]) ; } } $position = $this->hasSubject() && null !== $this->getSubject()->getPosition() ? $this->getSubject()->getPosition() : 0; $formMapper ->end() ->with('group_options', ['class' => 'col-md-6']) ->add('enabled', CheckboxType::class, [ 'required' => false, ]) ->add('position', IntegerType::class, [ 'required' => false, 'data' => $position, ]) ->end() ; if (interface_exists(MediaInterface::class)) { $formMapper ->with('group_general') ->add('media', ModelListType::class, [ 'required' => false, ], [ 'link_parameters' => [ 'provider' => 'sonata.media.provider.image', 'context' => 'sonata_category', ], ]) ->end(); } }
[ "protected", "function", "configureFormFields", "(", "FormMapper", "$", "formMapper", ")", "{", "$", "formMapper", "->", "with", "(", "'group_general'", ",", "[", "'class'", "=>", "'col-md-6'", "]", ")", "->", "add", "(", "'name'", ")", "->", "add", "(", "...
{@inheritdoc}
[ "{" ]
train
https://github.com/sonata-project/SonataClassificationBundle/blob/f75add739dc0f79e02933fb87aca0ea8355a1a4b/src/Admin/CategoryAdmin.php#L68-L120
sonata-project/SonataClassificationBundle
src/Block/Service/AbstractCategoriesBlockService.php
AbstractCategoriesBlockService.execute
public function execute(BlockContextInterface $blockContext, Response $response = null) { $category = $this->getCategory($blockContext->getSetting('categoryId'), $blockContext->getSetting('category')); $root = $this->categoryManager->getRootCategory($blockContext->getSetting('context')); return $this->renderResponse($blockContext->getTemplate(), [ 'context' => $blockContext, 'settings' => $blockContext->getSettings(), 'block' => $blockContext->getBlock(), 'category' => $category, 'root' => $root, ], $response); }
php
public function execute(BlockContextInterface $blockContext, Response $response = null) { $category = $this->getCategory($blockContext->getSetting('categoryId'), $blockContext->getSetting('category')); $root = $this->categoryManager->getRootCategory($blockContext->getSetting('context')); return $this->renderResponse($blockContext->getTemplate(), [ 'context' => $blockContext, 'settings' => $blockContext->getSettings(), 'block' => $blockContext->getBlock(), 'category' => $category, 'root' => $root, ], $response); }
[ "public", "function", "execute", "(", "BlockContextInterface", "$", "blockContext", ",", "Response", "$", "response", "=", "null", ")", "{", "$", "category", "=", "$", "this", "->", "getCategory", "(", "$", "blockContext", "->", "getSetting", "(", "'categoryId...
{@inheritdoc}
[ "{" ]
train
https://github.com/sonata-project/SonataClassificationBundle/blob/f75add739dc0f79e02933fb87aca0ea8355a1a4b/src/Block/Service/AbstractCategoriesBlockService.php#L64-L76
sonata-project/SonataClassificationBundle
src/Block/Service/AbstractCategoriesBlockService.php
AbstractCategoriesBlockService.load
public function load(BlockInterface $block) { if (is_numeric($block->getSetting('categoryId'))) { $block->setSetting('categoryId', $this->getCategory($block->getSetting('categoryId'))); } }
php
public function load(BlockInterface $block) { if (is_numeric($block->getSetting('categoryId'))) { $block->setSetting('categoryId', $this->getCategory($block->getSetting('categoryId'))); } }
[ "public", "function", "load", "(", "BlockInterface", "$", "block", ")", "{", "if", "(", "is_numeric", "(", "$", "block", "->", "getSetting", "(", "'categoryId'", ")", ")", ")", "{", "$", "block", "->", "setSetting", "(", "'categoryId'", ",", "$", "this",...
{@inheritdoc}
[ "{" ]
train
https://github.com/sonata-project/SonataClassificationBundle/blob/f75add739dc0f79e02933fb87aca0ea8355a1a4b/src/Block/Service/AbstractCategoriesBlockService.php#L146-L151
sonata-project/SonataClassificationBundle
src/Block/Service/AbstractCategoriesBlockService.php
AbstractCategoriesBlockService.getBlockMetadata
public function getBlockMetadata($code = null) { $description = (null !== $code ? $code : $this->getName()); return new Metadata($this->getName(), $description, false, 'SonataClassificationBundle', [ 'class' => 'fa fa-folder-open-o', ]); }
php
public function getBlockMetadata($code = null) { $description = (null !== $code ? $code : $this->getName()); return new Metadata($this->getName(), $description, false, 'SonataClassificationBundle', [ 'class' => 'fa fa-folder-open-o', ]); }
[ "public", "function", "getBlockMetadata", "(", "$", "code", "=", "null", ")", "{", "$", "description", "=", "(", "null", "!==", "$", "code", "?", "$", "code", ":", "$", "this", "->", "getName", "(", ")", ")", ";", "return", "new", "Metadata", "(", ...
{@inheritdoc}
[ "{" ]
train
https://github.com/sonata-project/SonataClassificationBundle/blob/f75add739dc0f79e02933fb87aca0ea8355a1a4b/src/Block/Service/AbstractCategoriesBlockService.php#L172-L179
sonata-project/SonataClassificationBundle
src/Block/Service/AbstractCategoriesBlockService.php
AbstractCategoriesBlockService.getCategory
final protected function getCategory($id, $default = null) { if ($id instanceof CategoryInterface) { return $id; } if (is_numeric($id)) { return $this->categoryManager->find($id); } if ($default instanceof CategoryInterface) { return $default; } return null; }
php
final protected function getCategory($id, $default = null) { if ($id instanceof CategoryInterface) { return $id; } if (is_numeric($id)) { return $this->categoryManager->find($id); } if ($default instanceof CategoryInterface) { return $default; } return null; }
[ "final", "protected", "function", "getCategory", "(", "$", "id", ",", "$", "default", "=", "null", ")", "{", "if", "(", "$", "id", "instanceof", "CategoryInterface", ")", "{", "return", "$", "id", ";", "}", "if", "(", "is_numeric", "(", "$", "id", ")...
@param CategoryInterface|int $id @param mixed $default @return CategoryInterface
[ "@param", "CategoryInterface|int", "$id", "@param", "mixed", "$default" ]
train
https://github.com/sonata-project/SonataClassificationBundle/blob/f75add739dc0f79e02933fb87aca0ea8355a1a4b/src/Block/Service/AbstractCategoriesBlockService.php#L187-L202
sonata-project/SonataClassificationBundle
src/Controller/Api/TagController.php
TagController.getTagsAction
public function getTagsAction(ParamFetcherInterface $paramFetcher) { $page = $paramFetcher->get('page'); $count = $paramFetcher->get('count'); /** @var PagerInterface $tagsPager */ $tagsPager = $this->tagManager->getPager($this->filterCriteria($paramFetcher), $page, $count); return $tagsPager; }
php
public function getTagsAction(ParamFetcherInterface $paramFetcher) { $page = $paramFetcher->get('page'); $count = $paramFetcher->get('count'); /** @var PagerInterface $tagsPager */ $tagsPager = $this->tagManager->getPager($this->filterCriteria($paramFetcher), $page, $count); return $tagsPager; }
[ "public", "function", "getTagsAction", "(", "ParamFetcherInterface", "$", "paramFetcher", ")", "{", "$", "page", "=", "$", "paramFetcher", "->", "get", "(", "'page'", ")", ";", "$", "count", "=", "$", "paramFetcher", "->", "get", "(", "'count'", ")", ";", ...
Retrieves the list of tags (paginated) based on criteria. @ApiDoc( resource=true, output={"class"="Sonata\DatagridBundle\Pager\PagerInterface", "groups"={"sonata_api_read"}} ) @QueryParam(name="page", requirements="\d+", default="1", description="Page for tag list pagination") @QueryParam(name="count", requirements="\d+", default="10", description="Number of tags by page") @QueryParam(name="enabled", requirements="0|1", nullable=true, strict=true, description="Enabled/Disabled tags filter") @View(serializerGroups={"sonata_api_read"}, serializerEnableMaxDepthChecks=true) @param ParamFetcherInterface $paramFetcher @return PagerInterface
[ "Retrieves", "the", "list", "of", "tags", "(", "paginated", ")", "based", "on", "criteria", "." ]
train
https://github.com/sonata-project/SonataClassificationBundle/blob/f75add739dc0f79e02933fb87aca0ea8355a1a4b/src/Controller/Api/TagController.php#L74-L83
sonata-project/SonataClassificationBundle
src/Controller/Api/TagController.php
TagController.deleteTagAction
public function deleteTagAction($id) { $tag = $this->getTag($id); $this->tagManager->delete($tag); return ['deleted' => true]; }
php
public function deleteTagAction($id) { $tag = $this->getTag($id); $this->tagManager->delete($tag); return ['deleted' => true]; }
[ "public", "function", "deleteTagAction", "(", "$", "id", ")", "{", "$", "tag", "=", "$", "this", "->", "getTag", "(", "$", "id", ")", ";", "$", "this", "->", "tagManager", "->", "delete", "(", "$", "tag", ")", ";", "return", "[", "'deleted'", "=>",...
Deletes a tag. @ApiDoc( requirements={ {"name"="id", "dataType"="integer", "requirement"="\d+", "description"="tag identifier"} }, statusCodes={ 200="Returned when tag is successfully deleted", 400="Returned when an error has occurred while tag deletion", 404="Returned when unable to find tag" } ) @param int $id A Tag identifier @throws NotFoundHttpException @return View
[ "Deletes", "a", "tag", "." ]
train
https://github.com/sonata-project/SonataClassificationBundle/blob/f75add739dc0f79e02933fb87aca0ea8355a1a4b/src/Controller/Api/TagController.php#L182-L189
sonata-project/SonataClassificationBundle
src/Controller/Api/TagController.php
TagController.filterCriteria
protected function filterCriteria(ParamFetcherInterface $paramFetcher) { $criteria = $paramFetcher->all(); unset($criteria['page'], $criteria['count']); foreach ($criteria as $key => $value) { if (null === $value) { unset($criteria[$key]); } } return $criteria; }
php
protected function filterCriteria(ParamFetcherInterface $paramFetcher) { $criteria = $paramFetcher->all(); unset($criteria['page'], $criteria['count']); foreach ($criteria as $key => $value) { if (null === $value) { unset($criteria[$key]); } } return $criteria; }
[ "protected", "function", "filterCriteria", "(", "ParamFetcherInterface", "$", "paramFetcher", ")", "{", "$", "criteria", "=", "$", "paramFetcher", "->", "all", "(", ")", ";", "unset", "(", "$", "criteria", "[", "'page'", "]", ",", "$", "criteria", "[", "'c...
Filters criteria from $paramFetcher to be compatible with the Pager criteria. @param ParamFetcherInterface $paramFetcher @return array The filtered criteria
[ "Filters", "criteria", "from", "$paramFetcher", "to", "be", "compatible", "with", "the", "Pager", "criteria", "." ]
train
https://github.com/sonata-project/SonataClassificationBundle/blob/f75add739dc0f79e02933fb87aca0ea8355a1a4b/src/Controller/Api/TagController.php#L198-L211
sonata-project/SonataClassificationBundle
src/Controller/Api/TagController.php
TagController.getTag
protected function getTag($id) { $tag = $this->tagManager->find($id); if (null === $tag) { throw new NotFoundHttpException(sprintf('Tag (%d) not found', $id)); } return $tag; }
php
protected function getTag($id) { $tag = $this->tagManager->find($id); if (null === $tag) { throw new NotFoundHttpException(sprintf('Tag (%d) not found', $id)); } return $tag; }
[ "protected", "function", "getTag", "(", "$", "id", ")", "{", "$", "tag", "=", "$", "this", "->", "tagManager", "->", "find", "(", "$", "id", ")", ";", "if", "(", "null", "===", "$", "tag", ")", "{", "throw", "new", "NotFoundHttpException", "(", "sp...
Retrieves tag with id $id or throws an exception if it doesn't exist. @param int $id A Tag identifier @throws NotFoundHttpException @return TagInterface
[ "Retrieves", "tag", "with", "id", "$id", "or", "throws", "an", "exception", "if", "it", "doesn", "t", "exist", "." ]
train
https://github.com/sonata-project/SonataClassificationBundle/blob/f75add739dc0f79e02933fb87aca0ea8355a1a4b/src/Controller/Api/TagController.php#L222-L231
sonata-project/SonataClassificationBundle
src/Controller/Api/TagController.php
TagController.handleWriteTag
protected function handleWriteTag($request, $id = null) { $tag = $id ? $this->getTag($id) : null; $form = $this->formFactory->createNamed(null, 'sonata_classification_api_form_tag', $tag, [ 'csrf_protection' => false, ]); FormHelper::removeFields($request->request->all(), $form); $form->handleRequest($request); if ($form->isValid()) { $tag = $form->getData(); $this->tagManager->save($tag); $context = new Context(); $context->setGroups(['sonata_api_read']); $view = FOSRestView::create($tag); $view->setContext($context); return $view; } return $form; }
php
protected function handleWriteTag($request, $id = null) { $tag = $id ? $this->getTag($id) : null; $form = $this->formFactory->createNamed(null, 'sonata_classification_api_form_tag', $tag, [ 'csrf_protection' => false, ]); FormHelper::removeFields($request->request->all(), $form); $form->handleRequest($request); if ($form->isValid()) { $tag = $form->getData(); $this->tagManager->save($tag); $context = new Context(); $context->setGroups(['sonata_api_read']); $view = FOSRestView::create($tag); $view->setContext($context); return $view; } return $form; }
[ "protected", "function", "handleWriteTag", "(", "$", "request", ",", "$", "id", "=", "null", ")", "{", "$", "tag", "=", "$", "id", "?", "$", "this", "->", "getTag", "(", "$", "id", ")", ":", "null", ";", "$", "form", "=", "$", "this", "->", "fo...
Write a tag, this method is used by both POST and PUT action methods. @param Request $request Symfony request @param int|null $id A tag identifier @return FormInterface
[ "Write", "a", "tag", "this", "method", "is", "used", "by", "both", "POST", "and", "PUT", "action", "methods", "." ]
train
https://github.com/sonata-project/SonataClassificationBundle/blob/f75add739dc0f79e02933fb87aca0ea8355a1a4b/src/Controller/Api/TagController.php#L241-L267
sonata-project/SonataClassificationBundle
src/Admin/ContextAwareAdmin.php
ContextAwareAdmin.getNewInstance
public function getNewInstance() { $instance = parent::getNewInstance(); if ($contextId = $this->getPersistentParameter('context')) { $context = $this->contextManager->find($contextId); if (!$context) { /** @var ContextInterface $context */ $context = $this->contextManager->create(); $context->setEnabled(true); $context->setId($contextId); $context->setName($contextId); $this->contextManager->save($context); } $instance->setContext($context); } return $instance; }
php
public function getNewInstance() { $instance = parent::getNewInstance(); if ($contextId = $this->getPersistentParameter('context')) { $context = $this->contextManager->find($contextId); if (!$context) { /** @var ContextInterface $context */ $context = $this->contextManager->create(); $context->setEnabled(true); $context->setId($contextId); $context->setName($contextId); $this->contextManager->save($context); } $instance->setContext($context); } return $instance; }
[ "public", "function", "getNewInstance", "(", ")", "{", "$", "instance", "=", "parent", "::", "getNewInstance", "(", ")", ";", "if", "(", "$", "contextId", "=", "$", "this", "->", "getPersistentParameter", "(", "'context'", ")", ")", "{", "$", "context", ...
{@inheritdoc}
[ "{" ]
train
https://github.com/sonata-project/SonataClassificationBundle/blob/f75add739dc0f79e02933fb87aca0ea8355a1a4b/src/Admin/ContextAwareAdmin.php#L44-L65
sonata-project/SonataClassificationBundle
src/Admin/ContextAwareAdmin.php
ContextAwareAdmin.getPersistentParameters
public function getPersistentParameters() { $parameters = array_merge( parent::getPersistentParameters(), [ 'context' => '', 'hide_context' => $this->hasRequest() ? (int) $this->getRequest()->get('hide_context', 0) : 0, ] ); if ($this->getSubject()) { $parameters['context'] = $this->getSubject()->getContext() ? $this->getSubject()->getContext()->getId() : ''; return $parameters; } if ($this->hasRequest()) { $parameters['context'] = $this->getRequest()->get('context'); return $parameters; } return $parameters; }
php
public function getPersistentParameters() { $parameters = array_merge( parent::getPersistentParameters(), [ 'context' => '', 'hide_context' => $this->hasRequest() ? (int) $this->getRequest()->get('hide_context', 0) : 0, ] ); if ($this->getSubject()) { $parameters['context'] = $this->getSubject()->getContext() ? $this->getSubject()->getContext()->getId() : ''; return $parameters; } if ($this->hasRequest()) { $parameters['context'] = $this->getRequest()->get('context'); return $parameters; } return $parameters; }
[ "public", "function", "getPersistentParameters", "(", ")", "{", "$", "parameters", "=", "array_merge", "(", "parent", "::", "getPersistentParameters", "(", ")", ",", "[", "'context'", "=>", "''", ",", "'hide_context'", "=>", "$", "this", "->", "hasRequest", "(...
{@inheritdoc}
[ "{" ]
train
https://github.com/sonata-project/SonataClassificationBundle/blob/f75add739dc0f79e02933fb87aca0ea8355a1a4b/src/Admin/ContextAwareAdmin.php#L70-L93
sonata-project/SonataClassificationBundle
src/Admin/ContextAwareAdmin.php
ContextAwareAdmin.configureDatagridFilters
protected function configureDatagridFilters(DatagridMapper $datagridMapper) { $options = []; if (1 === $this->getPersistentParameter('hide_context')) { $options['disabled'] = true; } $datagridMapper ->add('context', null, [], null, $options) ; }
php
protected function configureDatagridFilters(DatagridMapper $datagridMapper) { $options = []; if (1 === $this->getPersistentParameter('hide_context')) { $options['disabled'] = true; } $datagridMapper ->add('context', null, [], null, $options) ; }
[ "protected", "function", "configureDatagridFilters", "(", "DatagridMapper", "$", "datagridMapper", ")", "{", "$", "options", "=", "[", "]", ";", "if", "(", "1", "===", "$", "this", "->", "getPersistentParameter", "(", "'hide_context'", ")", ")", "{", "$", "o...
{@inheritdoc}
[ "{" ]
train
https://github.com/sonata-project/SonataClassificationBundle/blob/f75add739dc0f79e02933fb87aca0ea8355a1a4b/src/Admin/ContextAwareAdmin.php#L98-L109
sonata-project/SonataClassificationBundle
src/Controller/Api/CategoryController.php
CategoryController.getCategoriesAction
public function getCategoriesAction(ParamFetcherInterface $paramFetcher) { $page = $paramFetcher->get('page'); $count = $paramFetcher->get('count'); /** @var PagerInterface $categoriesPager */ $categoriesPager = $this->categoryManager->getPager($this->filterCriteria($paramFetcher), $page, $count); return $categoriesPager; }
php
public function getCategoriesAction(ParamFetcherInterface $paramFetcher) { $page = $paramFetcher->get('page'); $count = $paramFetcher->get('count'); /** @var PagerInterface $categoriesPager */ $categoriesPager = $this->categoryManager->getPager($this->filterCriteria($paramFetcher), $page, $count); return $categoriesPager; }
[ "public", "function", "getCategoriesAction", "(", "ParamFetcherInterface", "$", "paramFetcher", ")", "{", "$", "page", "=", "$", "paramFetcher", "->", "get", "(", "'page'", ")", ";", "$", "count", "=", "$", "paramFetcher", "->", "get", "(", "'count'", ")", ...
Retrieves the list of categories (paginated) based on criteria. @ApiDoc( resource=true, output={"class"="Sonata\DatagridBundle\Pager\PagerInterface", "groups"={"sonata_api_read"}} ) @QueryParam(name="page", requirements="\d+", default="1", description="Page for category list pagination") @QueryParam(name="count", requirements="\d+", default="10", description="Number of categories by page") @QueryParam(name="enabled", requirements="0|1", nullable=true, strict=true, description="Enabled/Disabled categories filter") @QueryParam(name="context", requirements="\S+", nullable=true, strict=true, description="Context of categories") @View(serializerGroups={"sonata_api_read"}, serializerEnableMaxDepthChecks=true) @param ParamFetcherInterface $paramFetcher @return PagerInterface
[ "Retrieves", "the", "list", "of", "categories", "(", "paginated", ")", "based", "on", "criteria", "." ]
train
https://github.com/sonata-project/SonataClassificationBundle/blob/f75add739dc0f79e02933fb87aca0ea8355a1a4b/src/Controller/Api/CategoryController.php#L75-L84
sonata-project/SonataClassificationBundle
src/Controller/Api/CategoryController.php
CategoryController.deleteCategoryAction
public function deleteCategoryAction($id) { $category = $this->getCategory($id); $this->categoryManager->delete($category); return ['deleted' => true]; }
php
public function deleteCategoryAction($id) { $category = $this->getCategory($id); $this->categoryManager->delete($category); return ['deleted' => true]; }
[ "public", "function", "deleteCategoryAction", "(", "$", "id", ")", "{", "$", "category", "=", "$", "this", "->", "getCategory", "(", "$", "id", ")", ";", "$", "this", "->", "categoryManager", "->", "delete", "(", "$", "category", ")", ";", "return", "[...
Deletes a category. @ApiDoc( requirements={ {"name"="id", "dataType"="integer", "requirement"="\d+", "description"="category identifier"} }, statusCodes={ 200="Returned when category is successfully deleted", 400="Returned when an error has occurred while category deletion", 404="Returned when unable to find category" } ) @param int $id A Category identifier @throws NotFoundHttpException @return View
[ "Deletes", "a", "category", "." ]
train
https://github.com/sonata-project/SonataClassificationBundle/blob/f75add739dc0f79e02933fb87aca0ea8355a1a4b/src/Controller/Api/CategoryController.php#L183-L190
sonata-project/SonataClassificationBundle
src/Controller/Api/CategoryController.php
CategoryController.getCategory
protected function getCategory($id) { $category = $this->categoryManager->find($id); if (null === $category) { throw new NotFoundHttpException(sprintf('Category (%d) not found', $id)); } return $category; }
php
protected function getCategory($id) { $category = $this->categoryManager->find($id); if (null === $category) { throw new NotFoundHttpException(sprintf('Category (%d) not found', $id)); } return $category; }
[ "protected", "function", "getCategory", "(", "$", "id", ")", "{", "$", "category", "=", "$", "this", "->", "categoryManager", "->", "find", "(", "$", "id", ")", ";", "if", "(", "null", "===", "$", "category", ")", "{", "throw", "new", "NotFoundHttpExce...
Retrieves category with id $id or throws an exception if it doesn't exist. @param int $id A Category identifier @throws NotFoundHttpException @return CategoryInterface
[ "Retrieves", "category", "with", "id", "$id", "or", "throws", "an", "exception", "if", "it", "doesn", "t", "exist", "." ]
train
https://github.com/sonata-project/SonataClassificationBundle/blob/f75add739dc0f79e02933fb87aca0ea8355a1a4b/src/Controller/Api/CategoryController.php#L223-L232
sonata-project/SonataClassificationBundle
src/Controller/Api/CategoryController.php
CategoryController.handleWriteCategory
protected function handleWriteCategory($request, $id = null) { $category = $id ? $this->getCategory($id) : null; $form = $this->formFactory->createNamed(null, 'sonata_classification_api_form_category', $category, [ 'csrf_protection' => false, ]); FormHelper::removeFields($request->request->all(), $form); $form->handleRequest($request); if ($form->isValid()) { $category = $form->getData(); $this->categoryManager->save($category); $context = new Context(); $context->setGroups(['sonata_api_read']); $view = FOSRestView::create($category); $view->setContext($context); return $view; } return $form; }
php
protected function handleWriteCategory($request, $id = null) { $category = $id ? $this->getCategory($id) : null; $form = $this->formFactory->createNamed(null, 'sonata_classification_api_form_category', $category, [ 'csrf_protection' => false, ]); FormHelper::removeFields($request->request->all(), $form); $form->handleRequest($request); if ($form->isValid()) { $category = $form->getData(); $this->categoryManager->save($category); $context = new Context(); $context->setGroups(['sonata_api_read']); $view = FOSRestView::create($category); $view->setContext($context); return $view; } return $form; }
[ "protected", "function", "handleWriteCategory", "(", "$", "request", ",", "$", "id", "=", "null", ")", "{", "$", "category", "=", "$", "id", "?", "$", "this", "->", "getCategory", "(", "$", "id", ")", ":", "null", ";", "$", "form", "=", "$", "this"...
Write a category, this method is used by both POST and PUT action methods. @param Request $request Symfony request @param int|null $id A category identifier @return View|FormInterface
[ "Write", "a", "category", "this", "method", "is", "used", "by", "both", "POST", "and", "PUT", "action", "methods", "." ]
train
https://github.com/sonata-project/SonataClassificationBundle/blob/f75add739dc0f79e02933fb87aca0ea8355a1a4b/src/Controller/Api/CategoryController.php#L242-L268
sonata-project/SonataClassificationBundle
src/DependencyInjection/Configuration.php
Configuration.getConfigTreeBuilder
public function getConfigTreeBuilder() { $treeBuilder = new TreeBuilder('sonata_classification'); // Keep compatibility with symfony/config < 4.2 if (!method_exists($treeBuilder, 'getRootNode')) { $rootNode = $treeBuilder->root('sonata_classification'); } else { $rootNode = $treeBuilder->getRootNode(); } $rootNode ->children() ->arrayNode('class') ->addDefaultsIfNotSet() ->children() ->scalarNode('tag')->defaultValue('Application\\Sonata\\ClassificationBundle\\Entity\\Tag')->end() ->scalarNode('category')->defaultValue('Application\\Sonata\\ClassificationBundle\\Entity\\Category')->end() ->scalarNode('collection')->defaultValue('Application\\Sonata\\ClassificationBundle\\Entity\\Collection')->end() ->scalarNode('context')->defaultValue('Application\\Sonata\\ClassificationBundle\\Entity\\Context')->end() ->scalarNode('media')->defaultValue('Application\\Sonata\\MediaBundle\\Entity\\Media')->end() ->end() ->end() ->arrayNode('admin') ->addDefaultsIfNotSet() ->children() ->arrayNode('category') ->addDefaultsIfNotSet() ->children() ->scalarNode('class')->cannotBeEmpty()->defaultValue('Sonata\\ClassificationBundle\\Admin\\CategoryAdmin')->end() ->scalarNode('controller')->cannotBeEmpty()->defaultValue('SonataClassificationBundle:CategoryAdmin')->end() ->scalarNode('translation')->cannotBeEmpty()->defaultValue('SonataClassificationBundle')->end() ->end() ->end() ->arrayNode('tag') ->addDefaultsIfNotSet() ->children() ->scalarNode('class')->cannotBeEmpty()->defaultValue('Sonata\\ClassificationBundle\\Admin\\TagAdmin')->end() ->scalarNode('controller')->cannotBeEmpty()->defaultValue('SonataAdminBundle:CRUD')->end() ->scalarNode('translation')->cannotBeEmpty()->defaultValue('SonataClassificationBundle')->end() ->end() ->end() ->arrayNode('collection') ->addDefaultsIfNotSet() ->children() ->scalarNode('class')->cannotBeEmpty()->defaultValue('Sonata\\ClassificationBundle\\Admin\\CollectionAdmin')->end() ->scalarNode('controller')->cannotBeEmpty()->defaultValue('SonataAdminBundle:CRUD')->end() ->scalarNode('translation')->cannotBeEmpty()->defaultValue('SonataClassificationBundle')->end() ->end() ->end() ->arrayNode('context') ->addDefaultsIfNotSet() ->children() ->scalarNode('class')->cannotBeEmpty()->defaultValue('Sonata\\ClassificationBundle\\Admin\\ContextAdmin')->end() ->scalarNode('controller')->cannotBeEmpty()->defaultValue('SonataAdminBundle:CRUD')->end() ->scalarNode('translation')->cannotBeEmpty()->defaultValue('SonataClassificationBundle')->end() ->end() ->end() ->end() ->end() ->end() ; return $treeBuilder; }
php
public function getConfigTreeBuilder() { $treeBuilder = new TreeBuilder('sonata_classification'); // Keep compatibility with symfony/config < 4.2 if (!method_exists($treeBuilder, 'getRootNode')) { $rootNode = $treeBuilder->root('sonata_classification'); } else { $rootNode = $treeBuilder->getRootNode(); } $rootNode ->children() ->arrayNode('class') ->addDefaultsIfNotSet() ->children() ->scalarNode('tag')->defaultValue('Application\\Sonata\\ClassificationBundle\\Entity\\Tag')->end() ->scalarNode('category')->defaultValue('Application\\Sonata\\ClassificationBundle\\Entity\\Category')->end() ->scalarNode('collection')->defaultValue('Application\\Sonata\\ClassificationBundle\\Entity\\Collection')->end() ->scalarNode('context')->defaultValue('Application\\Sonata\\ClassificationBundle\\Entity\\Context')->end() ->scalarNode('media')->defaultValue('Application\\Sonata\\MediaBundle\\Entity\\Media')->end() ->end() ->end() ->arrayNode('admin') ->addDefaultsIfNotSet() ->children() ->arrayNode('category') ->addDefaultsIfNotSet() ->children() ->scalarNode('class')->cannotBeEmpty()->defaultValue('Sonata\\ClassificationBundle\\Admin\\CategoryAdmin')->end() ->scalarNode('controller')->cannotBeEmpty()->defaultValue('SonataClassificationBundle:CategoryAdmin')->end() ->scalarNode('translation')->cannotBeEmpty()->defaultValue('SonataClassificationBundle')->end() ->end() ->end() ->arrayNode('tag') ->addDefaultsIfNotSet() ->children() ->scalarNode('class')->cannotBeEmpty()->defaultValue('Sonata\\ClassificationBundle\\Admin\\TagAdmin')->end() ->scalarNode('controller')->cannotBeEmpty()->defaultValue('SonataAdminBundle:CRUD')->end() ->scalarNode('translation')->cannotBeEmpty()->defaultValue('SonataClassificationBundle')->end() ->end() ->end() ->arrayNode('collection') ->addDefaultsIfNotSet() ->children() ->scalarNode('class')->cannotBeEmpty()->defaultValue('Sonata\\ClassificationBundle\\Admin\\CollectionAdmin')->end() ->scalarNode('controller')->cannotBeEmpty()->defaultValue('SonataAdminBundle:CRUD')->end() ->scalarNode('translation')->cannotBeEmpty()->defaultValue('SonataClassificationBundle')->end() ->end() ->end() ->arrayNode('context') ->addDefaultsIfNotSet() ->children() ->scalarNode('class')->cannotBeEmpty()->defaultValue('Sonata\\ClassificationBundle\\Admin\\ContextAdmin')->end() ->scalarNode('controller')->cannotBeEmpty()->defaultValue('SonataAdminBundle:CRUD')->end() ->scalarNode('translation')->cannotBeEmpty()->defaultValue('SonataClassificationBundle')->end() ->end() ->end() ->end() ->end() ->end() ; return $treeBuilder; }
[ "public", "function", "getConfigTreeBuilder", "(", ")", "{", "$", "treeBuilder", "=", "new", "TreeBuilder", "(", "'sonata_classification'", ")", ";", "// Keep compatibility with symfony/config < 4.2", "if", "(", "!", "method_exists", "(", "$", "treeBuilder", ",", "'ge...
{@inheritdoc}
[ "{" ]
train
https://github.com/sonata-project/SonataClassificationBundle/blob/f75add739dc0f79e02933fb87aca0ea8355a1a4b/src/DependencyInjection/Configuration.php#L29-L94
sonata-project/SonataClassificationBundle
src/Model/Tag.php
Tag.slugify
public static function slugify($text) { $text = Slugify::create()->slugify($text); if (empty($text)) { return 'n-a'; } return $text; }
php
public static function slugify($text) { $text = Slugify::create()->slugify($text); if (empty($text)) { return 'n-a'; } return $text; }
[ "public", "static", "function", "slugify", "(", "$", "text", ")", "{", "$", "text", "=", "Slugify", "::", "create", "(", ")", "->", "slugify", "(", "$", "text", ")", ";", "if", "(", "empty", "(", "$", "text", ")", ")", "{", "return", "'n-a'", ";"...
source : http://snipplr.com/view/22741/slugify-a-string-in-php/. @static @param string $text @return mixed|string
[ "source", ":", "http", ":", "//", "snipplr", ".", "com", "/", "view", "/", "22741", "/", "slugify", "-", "a", "-", "string", "-", "in", "-", "php", "/", "." ]
train
https://github.com/sonata-project/SonataClassificationBundle/blob/f75add739dc0f79e02933fb87aca0ea8355a1a4b/src/Model/Tag.php#L154-L163
sonata-project/SonataClassificationBundle
src/Block/Service/AbstractCollectionsBlockService.php
AbstractCollectionsBlockService.execute
public function execute(BlockContextInterface $blockContext, Response $response = null) { $collection = $this->getCollection($blockContext->getSetting('collectionId'), $blockContext->getSetting('collection')); $collections = $this->contextManager->findBy([ 'enabled' => true, 'context' => $blockContext->getSetting('context'), ]); return $this->renderResponse($blockContext->getTemplate(), [ 'context' => $blockContext, 'settings' => $blockContext->getSettings(), 'block' => $blockContext->getBlock(), 'collection' => $collection, 'collections' => $collections, ], $response); }
php
public function execute(BlockContextInterface $blockContext, Response $response = null) { $collection = $this->getCollection($blockContext->getSetting('collectionId'), $blockContext->getSetting('collection')); $collections = $this->contextManager->findBy([ 'enabled' => true, 'context' => $blockContext->getSetting('context'), ]); return $this->renderResponse($blockContext->getTemplate(), [ 'context' => $blockContext, 'settings' => $blockContext->getSettings(), 'block' => $blockContext->getBlock(), 'collection' => $collection, 'collections' => $collections, ], $response); }
[ "public", "function", "execute", "(", "BlockContextInterface", "$", "blockContext", ",", "Response", "$", "response", "=", "null", ")", "{", "$", "collection", "=", "$", "this", "->", "getCollection", "(", "$", "blockContext", "->", "getSetting", "(", "'collec...
{@inheritdoc}
[ "{" ]
train
https://github.com/sonata-project/SonataClassificationBundle/blob/f75add739dc0f79e02933fb87aca0ea8355a1a4b/src/Block/Service/AbstractCollectionsBlockService.php#L64-L79
sonata-project/SonataClassificationBundle
src/Block/Service/AbstractCollectionsBlockService.php
AbstractCollectionsBlockService.load
public function load(BlockInterface $block) { if (is_numeric($block->getSetting('collectionId'))) { $block->setSetting('collectionId', $this->getCollection($block->getSetting('collectionId'))); } }
php
public function load(BlockInterface $block) { if (is_numeric($block->getSetting('collectionId'))) { $block->setSetting('collectionId', $this->getCollection($block->getSetting('collectionId'))); } }
[ "public", "function", "load", "(", "BlockInterface", "$", "block", ")", "{", "if", "(", "is_numeric", "(", "$", "block", "->", "getSetting", "(", "'collectionId'", ")", ")", ")", "{", "$", "block", "->", "setSetting", "(", "'collectionId'", ",", "$", "th...
{@inheritdoc}
[ "{" ]
train
https://github.com/sonata-project/SonataClassificationBundle/blob/f75add739dc0f79e02933fb87aca0ea8355a1a4b/src/Block/Service/AbstractCollectionsBlockService.php#L149-L154
sonata-project/SonataClassificationBundle
src/Block/Service/AbstractCollectionsBlockService.php
AbstractCollectionsBlockService.getCollection
final protected function getCollection($id, $default = null) { if ($id instanceof CollectionInterface) { return $id; } if (is_numeric($id)) { return $this->collectionManager->find($id); } if ($default instanceof CollectionInterface) { return $default; } return null; }
php
final protected function getCollection($id, $default = null) { if ($id instanceof CollectionInterface) { return $id; } if (is_numeric($id)) { return $this->collectionManager->find($id); } if ($default instanceof CollectionInterface) { return $default; } return null; }
[ "final", "protected", "function", "getCollection", "(", "$", "id", ",", "$", "default", "=", "null", ")", "{", "if", "(", "$", "id", "instanceof", "CollectionInterface", ")", "{", "return", "$", "id", ";", "}", "if", "(", "is_numeric", "(", "$", "id", ...
@param CollectionInterface|int $id @param mixed $default @return CollectionInterface|null
[ "@param", "CollectionInterface|int", "$id", "@param", "mixed", "$default" ]
train
https://github.com/sonata-project/SonataClassificationBundle/blob/f75add739dc0f79e02933fb87aca0ea8355a1a4b/src/Block/Service/AbstractCollectionsBlockService.php#L190-L205
sonata-project/SonataClassificationBundle
src/Form/Type/CategorySelectorType.php
CategorySelectorType.configureOptions
public function configureOptions(OptionsResolver $resolver) { $that = $this; if (!interface_exists(ChoiceLoaderInterface::class)) { $resolver->setDefaults([ 'context' => null, 'category' => null, 'choice_list' => static function (Options $opts, $previousValue) use ($that) { return new SimpleChoiceList($that->getChoices($opts)); }, ]); return; } $resolver->setDefaults([ 'context' => null, 'category' => null, 'choice_loader' => static function (Options $opts, $previousValue) use ($that) { return new CategoryChoiceLoader(array_flip($that->getChoices($opts))); }, ]); }
php
public function configureOptions(OptionsResolver $resolver) { $that = $this; if (!interface_exists(ChoiceLoaderInterface::class)) { $resolver->setDefaults([ 'context' => null, 'category' => null, 'choice_list' => static function (Options $opts, $previousValue) use ($that) { return new SimpleChoiceList($that->getChoices($opts)); }, ]); return; } $resolver->setDefaults([ 'context' => null, 'category' => null, 'choice_loader' => static function (Options $opts, $previousValue) use ($that) { return new CategoryChoiceLoader(array_flip($that->getChoices($opts))); }, ]); }
[ "public", "function", "configureOptions", "(", "OptionsResolver", "$", "resolver", ")", "{", "$", "that", "=", "$", "this", ";", "if", "(", "!", "interface_exists", "(", "ChoiceLoaderInterface", "::", "class", ")", ")", "{", "$", "resolver", "->", "setDefaul...
NEXT_MAJOR: replace usage of deprecated 'choice_list' option, when bumping requirements to SF 2.7+. {@inheritdoc}
[ "NEXT_MAJOR", ":", "replace", "usage", "of", "deprecated", "choice_list", "option", "when", "bumping", "requirements", "to", "SF", "2", ".", "7", "+", "." ]
train
https://github.com/sonata-project/SonataClassificationBundle/blob/f75add739dc0f79e02933fb87aca0ea8355a1a4b/src/Form/Type/CategorySelectorType.php#L63-L85
sonata-project/SonataClassificationBundle
src/Form/Type/CategorySelectorType.php
CategorySelectorType.getChoices
public function getChoices(Options $options) { if (!$options['category'] instanceof CategoryInterface) { return []; } if (null === $options['context']) { $categories = $this->manager->getAllRootCategories(); } else { $categories = $this->manager->getRootCategoriesForContext($options['context']); } $choices = []; foreach ($categories as $category) { $choices[$category->getId()] = sprintf('%s (%s)', $category->getName(), $category->getContext()->getId()); $this->childWalker($category, $options, $choices); } return $choices; }
php
public function getChoices(Options $options) { if (!$options['category'] instanceof CategoryInterface) { return []; } if (null === $options['context']) { $categories = $this->manager->getAllRootCategories(); } else { $categories = $this->manager->getRootCategoriesForContext($options['context']); } $choices = []; foreach ($categories as $category) { $choices[$category->getId()] = sprintf('%s (%s)', $category->getName(), $category->getContext()->getId()); $this->childWalker($category, $options, $choices); } return $choices; }
[ "public", "function", "getChoices", "(", "Options", "$", "options", ")", "{", "if", "(", "!", "$", "options", "[", "'category'", "]", "instanceof", "CategoryInterface", ")", "{", "return", "[", "]", ";", "}", "if", "(", "null", "===", "$", "options", "...
@param Options $options @return array
[ "@param", "Options", "$options" ]
train
https://github.com/sonata-project/SonataClassificationBundle/blob/f75add739dc0f79e02933fb87aca0ea8355a1a4b/src/Form/Type/CategorySelectorType.php#L92-L113
sonata-project/SonataClassificationBundle
src/Command/FixContextCommand.php
FixContextCommand.execute
public function execute(InputInterface $input, OutputInterface $output) { $contextManager = $this->getContainer()->get('sonata.classification.manager.context'); $tagManager = $this->getContainer()->get('sonata.classification.manager.tag'); $collectionManager = $this->getContainer()->get('sonata.classification.manager.collection'); $categoryManager = $this->getContainer()->get('sonata.classification.manager.category'); $output->writeln('1. Checking default context'); $defaultContext = $contextManager->findOneBy([ 'id' => ContextInterface::DEFAULT_CONTEXT, ]); if (!$defaultContext) { $output->writeln(' > default context is missing, creating one'); $defaultContext = $contextManager->create(); $defaultContext->setId(ContextInterface::DEFAULT_CONTEXT); $defaultContext->setName('Default'); $defaultContext->setEnabled(true); $contextManager->save($defaultContext); } else { $output->writeln(' > default context exists'); } $output->writeln('2. Find tag without default context'); foreach ($tagManager->findBy([]) as $tag) { if ($tag->getContext()) { continue; } $output->writeln(sprintf(' > attach default context to tag: %s (%s)', $tag->getSlug(), $tag->getId())); $tag->setContext($defaultContext); $tagManager->save($tag); } $output->writeln('3. Find collection without default context'); foreach ($collectionManager->findBy([]) as $collection) { if ($collection->getContext()) { continue; } $output->writeln(sprintf(' > attach default context to collection: %s (%s)', $collection->getSlug(), $collection->getId())); $collection->setContext($defaultContext); $collectionManager->save($collection); } $output->writeln('3. Find category without default context'); foreach ($categoryManager->findBy([]) as $category) { if ($category->getContext()) { continue; } $output->writeln(sprintf(' > attach default context to collection: %s (%s)', $category->getSlug(), $category->getId())); $category->setContext($defaultContext); $categoryManager->save($category); } $output->writeln('Done!'); }
php
public function execute(InputInterface $input, OutputInterface $output) { $contextManager = $this->getContainer()->get('sonata.classification.manager.context'); $tagManager = $this->getContainer()->get('sonata.classification.manager.tag'); $collectionManager = $this->getContainer()->get('sonata.classification.manager.collection'); $categoryManager = $this->getContainer()->get('sonata.classification.manager.category'); $output->writeln('1. Checking default context'); $defaultContext = $contextManager->findOneBy([ 'id' => ContextInterface::DEFAULT_CONTEXT, ]); if (!$defaultContext) { $output->writeln(' > default context is missing, creating one'); $defaultContext = $contextManager->create(); $defaultContext->setId(ContextInterface::DEFAULT_CONTEXT); $defaultContext->setName('Default'); $defaultContext->setEnabled(true); $contextManager->save($defaultContext); } else { $output->writeln(' > default context exists'); } $output->writeln('2. Find tag without default context'); foreach ($tagManager->findBy([]) as $tag) { if ($tag->getContext()) { continue; } $output->writeln(sprintf(' > attach default context to tag: %s (%s)', $tag->getSlug(), $tag->getId())); $tag->setContext($defaultContext); $tagManager->save($tag); } $output->writeln('3. Find collection without default context'); foreach ($collectionManager->findBy([]) as $collection) { if ($collection->getContext()) { continue; } $output->writeln(sprintf(' > attach default context to collection: %s (%s)', $collection->getSlug(), $collection->getId())); $collection->setContext($defaultContext); $collectionManager->save($collection); } $output->writeln('3. Find category without default context'); foreach ($categoryManager->findBy([]) as $category) { if ($category->getContext()) { continue; } $output->writeln(sprintf(' > attach default context to collection: %s (%s)', $category->getSlug(), $category->getId())); $category->setContext($defaultContext); $categoryManager->save($category); } $output->writeln('Done!'); }
[ "public", "function", "execute", "(", "InputInterface", "$", "input", ",", "OutputInterface", "$", "output", ")", "{", "$", "contextManager", "=", "$", "this", "->", "getContainer", "(", ")", "->", "get", "(", "'sonata.classification.manager.context'", ")", ";",...
{@inheritdoc}
[ "{" ]
train
https://github.com/sonata-project/SonataClassificationBundle/blob/f75add739dc0f79e02933fb87aca0ea8355a1a4b/src/Command/FixContextCommand.php#L35-L100
sonata-project/SonataClassificationBundle
src/Admin/ContextAdmin.php
ContextAdmin.configureFormFields
protected function configureFormFields(FormMapper $formMapper) { $formMapper ->ifTrue(!($this->hasSubject() && null !== $this->getSubject()->getId())) ->add('id') ->ifEnd() ->add('name') ->add('enabled', CheckboxType::class, [ 'required' => false, ]) ; }
php
protected function configureFormFields(FormMapper $formMapper) { $formMapper ->ifTrue(!($this->hasSubject() && null !== $this->getSubject()->getId())) ->add('id') ->ifEnd() ->add('name') ->add('enabled', CheckboxType::class, [ 'required' => false, ]) ; }
[ "protected", "function", "configureFormFields", "(", "FormMapper", "$", "formMapper", ")", "{", "$", "formMapper", "->", "ifTrue", "(", "!", "(", "$", "this", "->", "hasSubject", "(", ")", "&&", "null", "!==", "$", "this", "->", "getSubject", "(", ")", "...
{@inheritdoc}
[ "{" ]
train
https://github.com/sonata-project/SonataClassificationBundle/blob/f75add739dc0f79e02933fb87aca0ea8355a1a4b/src/Admin/ContextAdmin.php#L29-L40
sonata-project/SonataClassificationBundle
src/Model/Category.php
Category.addChild
public function addChild(CategoryInterface $child, $nested = false) { $this->children[] = $child; if ($this->getContext()) { $child->setContext($this->getContext()); } if (!$nested) { $child->setParent($this, true); } }
php
public function addChild(CategoryInterface $child, $nested = false) { $this->children[] = $child; if ($this->getContext()) { $child->setContext($this->getContext()); } if (!$nested) { $child->setParent($this, true); } }
[ "public", "function", "addChild", "(", "CategoryInterface", "$", "child", ",", "$", "nested", "=", "false", ")", "{", "$", "this", "->", "children", "[", "]", "=", "$", "child", ";", "if", "(", "$", "this", "->", "getContext", "(", ")", ")", "{", "...
{@inheritdoc}
[ "{" ]
train
https://github.com/sonata-project/SonataClassificationBundle/blob/f75add739dc0f79e02933fb87aca0ea8355a1a4b/src/Model/Category.php#L228-L239