Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
5.56% |
1 / 18 |
|
14.29% |
1 / 7 |
CRAP | |
0.00% |
0 / 1 |
| ClassServiceTrait | |
5.56% |
1 / 18 |
|
14.29% |
1 / 7 |
112.93 | |
0.00% |
0 / 1 |
| getRootClass | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| deleteResource | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| deleteClass | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| deleteClassProperty | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
| deletePropertyIndex | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getServiceManager | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getClassDeleter | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getResourceDeleter | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 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) 2018-2021 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\tao\model; |
| 24 | |
| 25 | use Throwable; |
| 26 | use core_kernel_classes_Class; |
| 27 | use core_kernel_classes_Resource; |
| 28 | use oat\oatbox\service\ServiceManager; |
| 29 | use oat\tao\model\search\index\OntologyIndex; |
| 30 | use oat\tao\model\resources\Service\ClassDeleter; |
| 31 | use oat\generis\model\resource\Service\ResourceDeleter; |
| 32 | use oat\tao\model\resources\Contract\ClassDeleterInterface; |
| 33 | use oat\generis\model\resource\Contract\ResourceDeleterInterface; |
| 34 | |
| 35 | trait ClassServiceTrait |
| 36 | { |
| 37 | /** |
| 38 | * Returns the root class of this service |
| 39 | * |
| 40 | * @return \core_kernel_classes_Class |
| 41 | */ |
| 42 | abstract public function getRootClass(); |
| 43 | |
| 44 | /** |
| 45 | * @deprecated Use \oat\generis\model\resource\Service\ResourceDeleter::delete() |
| 46 | * |
| 47 | * @return bool |
| 48 | */ |
| 49 | public function deleteResource(core_kernel_classes_Resource $resource) |
| 50 | { |
| 51 | try { |
| 52 | $this->getResourceDeleter()->delete($resource); |
| 53 | |
| 54 | return true; |
| 55 | } catch (Throwable $exception) { |
| 56 | return false; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * @deprecated Use \oat\tao\model\resources\Service\ClassDeleter::delete() |
| 62 | * |
| 63 | * @return bool |
| 64 | */ |
| 65 | public function deleteClass(core_kernel_classes_Class $class) |
| 66 | { |
| 67 | try { |
| 68 | $this->getClassDeleter()->delete($class); |
| 69 | |
| 70 | return true; |
| 71 | } catch (Throwable $exception) { |
| 72 | return false; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * remove a class property |
| 78 | * |
| 79 | * @param \core_kernel_classes_Property $property |
| 80 | * @return bool |
| 81 | * @throws \common_exception_Error |
| 82 | */ |
| 83 | public function deleteClassProperty(\core_kernel_classes_Property $property) |
| 84 | { |
| 85 | $indexes = $property->getPropertyValues(new \core_kernel_classes_Property(OntologyIndex::PROPERTY_INDEX)); |
| 86 | |
| 87 | //delete property and the existing values of this property |
| 88 | if ($returnValue = $property->delete(true)) { |
| 89 | //delete index linked to the property |
| 90 | foreach ($indexes as $indexUri) { |
| 91 | $index = new core_kernel_classes_Resource($indexUri); |
| 92 | $returnValue = $this->deletePropertyIndex($index); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | return $returnValue; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * remove an index property |
| 101 | * @param \core_kernel_classes_Resource $index |
| 102 | * @return bool |
| 103 | */ |
| 104 | public function deletePropertyIndex(core_kernel_classes_Resource $index) |
| 105 | { |
| 106 | return $index->delete(true); |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * @return ServiceManager |
| 111 | */ |
| 112 | public function getServiceManager() |
| 113 | { |
| 114 | return ServiceManager::getServiceManager(); |
| 115 | } |
| 116 | |
| 117 | private function getClassDeleter(): ClassDeleterInterface |
| 118 | { |
| 119 | return $this->getServiceManager()->getContainer()->get(ClassDeleter::class); |
| 120 | } |
| 121 | |
| 122 | private function getResourceDeleter(): ResourceDeleterInterface |
| 123 | { |
| 124 | return $this->getServiceManager()->getContainer()->get(ResourceDeleter::class); |
| 125 | } |
| 126 | } |