Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 42 |
|
0.00% |
0 / 9 |
CRAP | |
0.00% |
0 / 1 |
| core_kernel_persistence_starsql_Property | |
0.00% |
0 / 42 |
|
0.00% |
0 / 9 |
210 | |
0.00% |
0 / 1 |
| isLgDependent | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
| isMultiple | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| getRange | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| delete | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
| setRange | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| setDependsOnProperty | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| setMultiple | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| setLgDependent | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| singleton | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| 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) 2023 (original work) Open Assessment Technologies SA ; |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | use oat\generis\model\GenerisRdf; |
| 24 | use oat\generis\model\OntologyRdfs; |
| 25 | |
| 26 | use function WikibaseSolutions\CypherDSL\node; |
| 27 | use function WikibaseSolutions\CypherDSL\query; |
| 28 | |
| 29 | class core_kernel_persistence_starsql_Property extends core_kernel_persistence_starsql_Resource implements |
| 30 | core_kernel_persistence_PropertyInterface |
| 31 | { |
| 32 | public static $instance = null; |
| 33 | |
| 34 | public function isLgDependent(core_kernel_classes_Resource $resource): bool |
| 35 | { |
| 36 | $lgDependentProperty = $this->getModel()->getProperty(GenerisRdf::PROPERTY_IS_LG_DEPENDENT); |
| 37 | $lgDependentResource = $resource->getOnePropertyValue($lgDependentProperty); |
| 38 | $lgDependent = !is_null($lgDependentResource) |
| 39 | && $lgDependentResource instanceof \core_kernel_classes_Resource |
| 40 | && $lgDependentResource->getUri() == GenerisRdf::GENERIS_TRUE; |
| 41 | |
| 42 | return (bool) $lgDependent; |
| 43 | } |
| 44 | |
| 45 | public function isMultiple(core_kernel_classes_Resource $resource): bool |
| 46 | { |
| 47 | throw new core_kernel_persistence_ProhibitedFunctionException( |
| 48 | "not implemented => The function (" . __METHOD__ |
| 49 | . ") is not available in this persistence implementation (" . __CLASS__ . ")" |
| 50 | ); |
| 51 | } |
| 52 | |
| 53 | public function getRange(core_kernel_classes_Resource $resource): core_kernel_classes_Class |
| 54 | { |
| 55 | throw new core_kernel_persistence_ProhibitedFunctionException( |
| 56 | "not implemented => The function (" . __METHOD__ |
| 57 | . ") is not available in this persistence implementation (" . __CLASS__ . ")" |
| 58 | ); |
| 59 | } |
| 60 | |
| 61 | public function delete(core_kernel_classes_Resource $resource, $deleteReference = false): bool |
| 62 | { |
| 63 | $propertyNode = node() |
| 64 | ->withProperties(['uri' => $resource->getUri()]) |
| 65 | ->withLabels(['Resource']); |
| 66 | $query = query() |
| 67 | ->match($propertyNode) |
| 68 | ->detachDelete($propertyNode) |
| 69 | ->build(); |
| 70 | |
| 71 | $result = $this->getPersistence()->run($query); |
| 72 | // @FIXME handle failure |
| 73 | |
| 74 | return true; |
| 75 | } |
| 76 | |
| 77 | public function setRange(core_kernel_classes_Resource $resource, core_kernel_classes_Class $class): ?bool |
| 78 | { |
| 79 | $rangeProp = new core_kernel_classes_Property(OntologyRdfs::RDFS_RANGE, __METHOD__); |
| 80 | $returnValue = $this->setPropertyValue($resource, $rangeProp, $class->getUri()); |
| 81 | return $returnValue; |
| 82 | } |
| 83 | |
| 84 | public function setDependsOnProperty( |
| 85 | core_kernel_classes_Resource $resource, |
| 86 | core_kernel_classes_Property $property |
| 87 | ): void { |
| 88 | $dependsOnProperty = new core_kernel_classes_Property( |
| 89 | GenerisRdf::PROPERTY_DEPENDS_ON_PROPERTY, |
| 90 | __METHOD__ |
| 91 | ); |
| 92 | |
| 93 | $this->setPropertyValue($resource, $dependsOnProperty, $property->getUri()); |
| 94 | } |
| 95 | |
| 96 | public function setMultiple(core_kernel_classes_Resource $resource, $isMultiple) |
| 97 | { |
| 98 | $multipleProperty = new core_kernel_classes_Property(GenerisRdf::PROPERTY_MULTIPLE); |
| 99 | $value = ((bool)$isMultiple) ? GenerisRdf::GENERIS_TRUE : GenerisRdf::GENERIS_FALSE ; |
| 100 | $this->setPropertyValue($resource, $multipleProperty, $value); |
| 101 | } |
| 102 | |
| 103 | public function setLgDependent(core_kernel_classes_Resource $resource, $isLgDependent) |
| 104 | { |
| 105 | $lgDependentProperty = new core_kernel_classes_Property(GenerisRdf::PROPERTY_IS_LG_DEPENDENT, __METHOD__); |
| 106 | $value = ((bool)$isLgDependent) ? GenerisRdf::GENERIS_TRUE : GenerisRdf::GENERIS_FALSE ; |
| 107 | $this->setPropertyValue($resource, $lgDependentProperty, $value); |
| 108 | } |
| 109 | |
| 110 | public static function singleton() |
| 111 | { |
| 112 | $returnValue = null; |
| 113 | if (core_kernel_persistence_starsql_Property::$instance == null) { |
| 114 | core_kernel_persistence_starsql_Property::$instance = new core_kernel_persistence_starsql_Property(); |
| 115 | } |
| 116 | $returnValue = core_kernel_persistence_starsql_Property::$instance; |
| 117 | return $returnValue; |
| 118 | } |
| 119 | } |