Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 28 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| CreatorItems | |
0.00% |
0 / 28 |
|
0.00% |
0 / 4 |
462 | |
0.00% |
0 / 1 |
| getItemClasses | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getQtiItems | |
0.00% |
0 / 24 |
|
0.00% |
0 / 1 |
342 | |||
| getResourceService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getFeatureFlagChecker | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2017 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\taoQtiTest\models\creator; |
| 23 | |
| 24 | use oat\generis\model\OntologyAwareTrait; |
| 25 | use oat\oatbox\service\ConfigurableService; |
| 26 | use oat\tao\model\featureFlag\FeatureFlagChecker; |
| 27 | use oat\tao\model\featureFlag\FeatureFlagCheckerInterface; |
| 28 | use oat\tao\model\resources\ResourceService; |
| 29 | use oat\tao\model\TaoOntology; |
| 30 | |
| 31 | /** |
| 32 | * This service let's you access the test creator's items |
| 33 | * |
| 34 | * @author Bertrand Chevrier <bertrand@taotesting.com> |
| 35 | */ |
| 36 | class CreatorItems extends ConfigurableService |
| 37 | { |
| 38 | use OntologyAwareTrait; |
| 39 | |
| 40 | public const SERVICE_ID = 'taoQtiTest/CreatorItems'; |
| 41 | |
| 42 | public const ITEM_ROOT_CLASS_URI = 'http://www.tao.lu/Ontologies/TAOItem.rdf#Item'; |
| 43 | public const PROPERTY_ITEM_CONTENT_URI = 'http://www.tao.lu/Ontologies/TAOItem.rdf#ItemContent'; |
| 44 | public const PROPERTY_ITEM_MODEL_URI = 'http://www.tao.lu/Ontologies/TAOItem.rdf#ItemModel'; |
| 45 | public const ITEM_MODEL_QTI_URI = 'http://www.tao.lu/Ontologies/TAOItem.rdf#QTI'; |
| 46 | public const LABEL_URI = 'http://www.w3.org/2000/01/rdf-schema#label'; |
| 47 | |
| 48 | public const ITEM_MODEL_SEARCH_OPTION = 'itemModel'; |
| 49 | public const ITEM_CONTENT_SEARCH_OPTION = 'itemContent'; |
| 50 | |
| 51 | /** |
| 52 | * The different lookup formats |
| 53 | */ |
| 54 | private static $formats = ['list', 'tree']; |
| 55 | |
| 56 | /** |
| 57 | * Get the list of items classes |
| 58 | * @return array the classes hierarchy |
| 59 | */ |
| 60 | public function getItemClasses() |
| 61 | { |
| 62 | $itemClass = $this->getClass(self::ITEM_ROOT_CLASS_URI); |
| 63 | return $this->getResourceService()->getAllClasses($itemClass); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Retrieve QTI Items for the given parameters |
| 68 | * @param \core_kernel_classes_Class $itemClass the item class |
| 69 | * @param string $format the lookup format |
| 70 | * @param string|array $search to filter by label if a string or provides the search filters |
| 71 | * @param int $offset for paging |
| 72 | * @param int $limit for paging |
| 73 | * @return array the items |
| 74 | */ |
| 75 | public function getQtiItems( |
| 76 | \core_kernel_classes_Class $itemClass, |
| 77 | $format = 'list', |
| 78 | $search = '', |
| 79 | $offset = 0, |
| 80 | $limit = 30 |
| 81 | ) { |
| 82 | $propertyFilters = []; |
| 83 | |
| 84 | if ($this->getFeatureFlagChecker()->isEnabled('FEATURE_FLAG_TRANSLATION_ENABLED')) { |
| 85 | $propertyFilters[TaoOntology::PROPERTY_TRANSLATION_TYPE] = |
| 86 | TaoOntology::PROPERTY_VALUE_TRANSLATION_TYPE_ORIGINAL; |
| 87 | } |
| 88 | |
| 89 | if ( |
| 90 | $this->hasOption(self::ITEM_MODEL_SEARCH_OPTION) |
| 91 | && $this->getOption(self::ITEM_MODEL_SEARCH_OPTION) !== false |
| 92 | ) { |
| 93 | $propertyFilters[self::PROPERTY_ITEM_MODEL_URI] = $this->getOption(self::ITEM_MODEL_SEARCH_OPTION); |
| 94 | } |
| 95 | |
| 96 | if ( |
| 97 | $this->hasOption(self::ITEM_CONTENT_SEARCH_OPTION) |
| 98 | && $this->getOption(self::ITEM_MODEL_SEARCH_OPTION) !== false |
| 99 | ) { |
| 100 | $propertyFilters[self::PROPERTY_ITEM_CONTENT_URI] = '*'; |
| 101 | } |
| 102 | |
| 103 | if (is_string($search) && strlen(trim($search)) > 0) { |
| 104 | $propertyFilters[self::LABEL_URI] = $search; |
| 105 | } |
| 106 | if (is_array($search)) { |
| 107 | foreach ($search as $uri => $value) { |
| 108 | if ( |
| 109 | is_string($uri) && |
| 110 | (is_string($value) && strlen(trim($value)) > 0) || |
| 111 | (is_array($value) && count($value) > 0) |
| 112 | ) { |
| 113 | $propertyFilters[$uri] = $value; |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | $result = []; |
| 119 | |
| 120 | //whitelisting's mandatory to prevent hijacking the dependency injection |
| 121 | if (in_array($format, self::$formats)) { |
| 122 | //load the lookup dynamically using the format |
| 123 | $itemLookup = $this->getServiceLocator()->get(self::SERVICE_ID . '/' . $format); |
| 124 | if (!is_null($itemLookup) && $itemLookup instanceof ItemLookup) { |
| 125 | $result = $itemLookup->getItems($itemClass, $propertyFilters, $offset, $limit); |
| 126 | } |
| 127 | } |
| 128 | return $result; |
| 129 | } |
| 130 | |
| 131 | protected function getResourceService() |
| 132 | { |
| 133 | return $this->getServiceLocator()->get(ResourceService::SERVICE_ID); |
| 134 | } |
| 135 | |
| 136 | private function getFeatureFlagChecker(): FeatureFlagCheckerInterface |
| 137 | { |
| 138 | return $this->getServiceManager()->get(FeatureFlagChecker::class); |
| 139 | } |
| 140 | } |