Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| LabelClassLookup | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 1 |
| lookup | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
20 | |||
| 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) 2015 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\taoQtiItem\model\qti\metadata\classLookups; |
| 23 | |
| 24 | use oat\generis\model\OntologyRdfs; |
| 25 | use oat\taoQtiItem\model\qti\metadata\MetadataClassLookup; |
| 26 | |
| 27 | /** |
| 28 | * LabelClassLookup is an implementation of MetadataClassLookup. |
| 29 | * |
| 30 | * Will lookup for an Item class with a particular label depending |
| 31 | * on a metadata value with path array('http://www.w3.org/2000/01/rdf-schema#label'). |
| 32 | * |
| 33 | * @author Jérôme Bogaerts <jerome@taotesting.com> |
| 34 | * |
| 35 | */ |
| 36 | class LabelClassLookup implements MetadataClassLookup |
| 37 | { |
| 38 | public function lookup(array $metadataValues) |
| 39 | { |
| 40 | $lookup = false; |
| 41 | |
| 42 | foreach ($metadataValues as $metadataValue) { |
| 43 | $path = $metadataValue->getPath(); |
| 44 | $expectedPath = [ |
| 45 | OntologyRdfs::RDFS_LABEL |
| 46 | ]; |
| 47 | |
| 48 | if ($path === $expectedPath) { |
| 49 | // Check for such a value in database... |
| 50 | $prop = new \core_kernel_classes_Property(OntologyRdfs::RDFS_LABEL); |
| 51 | $class = new \core_kernel_classes_Class(OntologyRdfs::RDFS_CLASS); |
| 52 | $instances = $class->searchInstances( |
| 53 | [$prop->getUri() => $metadataValue->getValue()], |
| 54 | ['like' => false, 'recursive' => true] |
| 55 | ); |
| 56 | |
| 57 | if (count($instances) > 0) { |
| 58 | $lookup = new \core_kernel_classes_Class(reset($instances)); |
| 59 | break; |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | return $lookup; |
| 65 | } |
| 66 | } |