Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| OntologyMetadataExtractor | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
42 | |
0.00% |
0 / 1 |
| extract | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
42 | |||
| 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 |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\taoQtiItem\model\qti\metadata\ontology; |
| 23 | |
| 24 | use oat\taoQtiItem\model\qti\metadata\extractors\LomMetadataExtractor; |
| 25 | use oat\taoQtiItem\model\qti\metadata\MetadataExtractionException; |
| 26 | use oat\taoQtiItem\model\qti\metadata\MetadataExtractor; |
| 27 | use core_kernel_classes_Resource; |
| 28 | |
| 29 | class OntologyMetadataExtractor extends OntologyMetadataRules implements MetadataExtractor |
| 30 | { |
| 31 | public function extract($resource) |
| 32 | { |
| 33 | if (! $resource instanceof core_kernel_classes_Resource) { |
| 34 | throw new MetadataExtractionException( |
| 35 | __('The given target is not an instance of core_kernel_classes_Resource') |
| 36 | ); |
| 37 | } |
| 38 | |
| 39 | $metadataValues = []; |
| 40 | |
| 41 | /** @var LomMetadataExtractor $rule */ |
| 42 | foreach ($this->rules as $rules) { |
| 43 | foreach ($rules as $rule) { |
| 44 | $values = $rule->extract($resource); |
| 45 | |
| 46 | if (empty($values)) { |
| 47 | continue; |
| 48 | } |
| 49 | $identifier = \tao_helpers_Uri::getUniqueId($resource->getUri()); |
| 50 | $path = $this->serializePath($rule->getPath()); |
| 51 | if (! isset($metadataValues[$path])) { |
| 52 | $metadataValues[$identifier] = $values; |
| 53 | } else { |
| 54 | $metadataValues[$identifier] = array_merge($metadataValues[$identifier], $values); |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | return $metadataValues; |
| 60 | } |
| 61 | } |