Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
79.31% |
23 / 29 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
| ExclusionListService | |
79.31% |
23 / 29 |
|
75.00% |
3 / 4 |
9.72 | |
0.00% |
0 / 1 |
| getNameProperty | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| getNamePropertyUri | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| getVersionProperty | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| getVersionPropertyUri | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| getListClass | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| getListNames | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
| getExclusionsList | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
4 | |||
| getExclusionsByName | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| getListDefinitionByName | |
100.00% |
5 / 5 |
|
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\taoClientDiagnostic\model\exclusionList; |
| 24 | |
| 25 | use core_kernel_classes_Class; |
| 26 | use core_kernel_classes_Property; |
| 27 | use core_kernel_classes_Resource; |
| 28 | use oat\generis\model\OntologyRdfs; |
| 29 | use oat\tao\model\OntologyClassService; |
| 30 | |
| 31 | abstract class ExclusionListService extends OntologyClassService |
| 32 | { |
| 33 | /** @var array */ |
| 34 | private $names; |
| 35 | |
| 36 | /** @var array */ |
| 37 | private $excluded; |
| 38 | |
| 39 | abstract public function getNameProperty(): core_kernel_classes_Property; |
| 40 | |
| 41 | abstract public function getNamePropertyUri(): string; |
| 42 | |
| 43 | abstract public function getVersionProperty(): core_kernel_classes_Property; |
| 44 | |
| 45 | abstract public function getVersionPropertyUri(): string; |
| 46 | |
| 47 | abstract protected function getListClass(): core_kernel_classes_Class; |
| 48 | |
| 49 | public function getListNames(): array |
| 50 | { |
| 51 | if ($this->names === null) { |
| 52 | $nameInstances = $this->getNameProperty()->getRange()->getInstances(); |
| 53 | $this->names = []; |
| 54 | foreach ($nameInstances as $nameInstance) { |
| 55 | $this->names[strtolower($nameInstance->getLabel())] = $nameInstance->getUri(); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | return $this->names; |
| 60 | } |
| 61 | |
| 62 | public function getExclusionsList(): array |
| 63 | { |
| 64 | if ($this->excluded === null) { |
| 65 | $instances = $this->getRootClass()->getInstances(true); |
| 66 | $this->excluded = []; |
| 67 | foreach ($instances as $instance) { |
| 68 | $properties = $instance->getPropertiesValues([ |
| 69 | $this->getNameProperty(), |
| 70 | $this->getVersionProperty() |
| 71 | ]); |
| 72 | |
| 73 | $excludedNameProperty = current($properties[$this->getNamePropertyUri()]); |
| 74 | if ($excludedNameProperty) { |
| 75 | $excludedName = strtolower($excludedNameProperty->getLabel()); |
| 76 | $excludedVersion = (string)current($properties[$this->getVersionPropertyUri()]); |
| 77 | |
| 78 | $this->excluded[$excludedName][] = $excludedVersion; |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | return $this->excluded; |
| 84 | } |
| 85 | |
| 86 | public function getExclusionsByName($name): array |
| 87 | { |
| 88 | return $this->getRootClass()->searchInstances( |
| 89 | [OntologyRdfs::RDFS_LABEL => $name], |
| 90 | ['like' => false] |
| 91 | ); |
| 92 | } |
| 93 | |
| 94 | public function getListDefinitionByName($name): ?core_kernel_classes_Resource |
| 95 | { |
| 96 | $results = $this->getListClass()->searchInstances( |
| 97 | [OntologyRdfs::RDFS_LABEL => $name], |
| 98 | ['like' => false] |
| 99 | ); |
| 100 | |
| 101 | return array_pop($results); |
| 102 | } |
| 103 | } |