Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
88.89% |
8 / 9 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ResourceClasses | |
88.89% |
8 / 9 |
|
50.00% |
1 / 2 |
5.03 | |
0.00% |
0 / 1 |
| getStrings | |
87.50% |
7 / 8 |
|
0.00% |
0 / 1 |
4.03 | |||
| hasReachedRootClass | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 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) 2021 (original work) Open Assessment Technologies SA; * |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\tao\model\search\tokenizer; |
| 24 | |
| 25 | use core_kernel_classes_Class; |
| 26 | use core_kernel_classes_Resource; |
| 27 | |
| 28 | class ResourceClasses implements PropertyValueTokenizer |
| 29 | { |
| 30 | private const CLASSES_URIS_BLACK_LIST = [ |
| 31 | 'http://www.tao.lu/Ontologies/TAO.rdf#AssessmentContentObject', |
| 32 | 'http://www.tao.lu/Ontologies/TAO.rdf#TAOObject', |
| 33 | 'http://www.tao.lu/Ontologies/generis.rdf#generis_Ressource', |
| 34 | 'http://www.w3.org/2000/01/rdf-schema#Resource' |
| 35 | ]; |
| 36 | |
| 37 | /** |
| 38 | * @param core_kernel_classes_Resource $resource |
| 39 | * @return array |
| 40 | */ |
| 41 | public function getStrings($resource) |
| 42 | { |
| 43 | $classes = []; |
| 44 | |
| 45 | foreach ($resource->getTypes() as $typeClass) { |
| 46 | $classes[] = $typeClass->getLabel(); |
| 47 | |
| 48 | foreach ($typeClass->getParentClasses(true) as $parentClass) { |
| 49 | if ($this->hasReachedRootClass($parentClass)) { |
| 50 | return $classes; |
| 51 | } |
| 52 | |
| 53 | $classes[] = $parentClass->getLabel(); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | return $classes; |
| 58 | } |
| 59 | |
| 60 | private function hasReachedRootClass(core_kernel_classes_Class $class): bool |
| 61 | { |
| 62 | return in_array($class->getUri(), self::CLASSES_URIS_BLACK_LIST, true); |
| 63 | } |
| 64 | } |