Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| LiteralPropertyExtractor | |
0.00% |
0 / 15 |
|
0.00% |
0 / 3 |
56 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
| getPath | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| extract | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
12 | |||
| 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\extractors\ontology; |
| 23 | |
| 24 | use oat\generis\model\OntologyAwareTrait; |
| 25 | use oat\taoQtiItem\model\qti\metadata\extractors\LomMetadataExtractor; |
| 26 | use oat\taoQtiItem\model\qti\metadata\MetadataExtractionException; |
| 27 | use oat\taoQtiItem\model\qti\metadata\simple\SimpleMetadataValue; |
| 28 | |
| 29 | class LiteralPropertyExtractor extends LomMetadataExtractor |
| 30 | { |
| 31 | use OntologyAwareTrait; |
| 32 | |
| 33 | protected $path; |
| 34 | protected $property; |
| 35 | |
| 36 | public function __construct(array $path, $property) |
| 37 | { |
| 38 | if (count($path) === 0) { |
| 39 | throw new \InvalidArgumentException(__('The path argument for extractor must be a non-empty array.')); |
| 40 | } |
| 41 | $this->path = $path; |
| 42 | $this->property = is_string($property) ? $this->getProperty($property) : $property; |
| 43 | } |
| 44 | |
| 45 | public function getPath() |
| 46 | { |
| 47 | return $this->path; |
| 48 | } |
| 49 | |
| 50 | public function extract($resource) |
| 51 | { |
| 52 | if (! $resource instanceof \core_kernel_classes_Resource) { |
| 53 | throw new MetadataExtractionException( |
| 54 | __('The given target is not an instance of core_kernel_classes_Resource') |
| 55 | ); |
| 56 | } |
| 57 | |
| 58 | $value = $resource->getOnePropertyValue($this->property)->literal; |
| 59 | if (is_null($value)) { |
| 60 | return []; |
| 61 | } |
| 62 | |
| 63 | return [ |
| 64 | new SimpleMetadataValue($resource->getUri(), $this->path, $value) |
| 65 | ]; |
| 66 | } |
| 67 | } |