Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 36 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
core_kernel_classes_ClassFactory | |
0.00% |
0 / 36 |
|
0.00% |
0 / 4 |
132 | |
0.00% |
0 / 1 |
createInstance | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
30 | |||
createProperty | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
createSubClass | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
checkProvidedUri | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 |
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) 2002-2008 (original work) Public Research Centre Henri Tudor & University of Luxembourg |
19 | * (under the project TAO & TAO2); |
20 | * 2008-2010 (update and modification) Deutsche Institut für Internationale Pädagogische Forschung |
21 | * (under the project TAO-TRANSFER); |
22 | * 2009-2012 (update and modification) Public Research Centre Henri Tudor |
23 | * (under the project TAO-SUSTAIN & TAO-DEV); |
24 | * 2017 (update and modification) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
25 | */ |
26 | |
27 | use oat\generis\model\OntologyRdf; |
28 | use oat\generis\model\OntologyRdfs; |
29 | |
30 | /** |
31 | * Short description of class core_kernel_classes_ClassFactory |
32 | * |
33 | * @access public |
34 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
35 | * @package generis |
36 | |
37 | */ |
38 | class core_kernel_classes_ClassFactory |
39 | { |
40 | // --- ASSOCIATIONS --- |
41 | |
42 | |
43 | // --- ATTRIBUTES --- |
44 | |
45 | // --- OPERATIONS --- |
46 | |
47 | /** |
48 | * Short description of method createInstance |
49 | * |
50 | * @access public |
51 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
52 | * @param Class clazz |
53 | * @param string label |
54 | * @param string comment |
55 | * @param string uri |
56 | * @return core_kernel_classes_Resource |
57 | */ |
58 | public static function createInstance(core_kernel_classes_Class $clazz, $label = '', $comment = '', $uri = '') |
59 | { |
60 | $returnValue = null; |
61 | $newUri = (!empty($uri)) ? self::checkProvidedUri($uri) : common_Utils::getNewUri(); |
62 | $newResource = new core_kernel_classes_Class($newUri); |
63 | $propertiesValues = [OntologyRdf::RDF_TYPE => $clazz->getUri()]; |
64 | |
65 | if (!empty($label)) { |
66 | $propertiesValues[OntologyRdfs::RDFS_LABEL] = $label; |
67 | } |
68 | |
69 | if (!empty($comment)) { |
70 | $propertiesValues[OntologyRdfs::RDFS_COMMENT] = $comment; |
71 | } |
72 | |
73 | $check = $newResource->setPropertiesValues($propertiesValues); |
74 | if ($check) { |
75 | $returnValue = $newResource; |
76 | } else { |
77 | $msg = "Failed to create an instance of class '" . $clazz->getUri() . "'."; |
78 | throw new common_Exception($msg); |
79 | common_Logger::e($msg); |
80 | } |
81 | |
82 | |
83 | return $returnValue; |
84 | } |
85 | |
86 | /** |
87 | * Short description of method createProperty |
88 | * |
89 | * @access public |
90 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
91 | * @param Class clazz |
92 | * @param string label |
93 | * @param string comment |
94 | * @param boolean isLgDependent |
95 | * @param string uri |
96 | * @return core_kernel_classes_Property |
97 | */ |
98 | public static function createProperty( |
99 | core_kernel_classes_Class $clazz, |
100 | $label = '', |
101 | $comment = '', |
102 | $isLgDependent = false, |
103 | $uri = '' |
104 | ) { |
105 | $returnValue = null; |
106 | $property = new core_kernel_classes_Class(OntologyRdf::RDF_PROPERTY); |
107 | $propertyInstance = self::createInstance($property, $label, $comment, $uri); |
108 | $returnValue = new core_kernel_classes_Property($propertyInstance->getUri()); |
109 | if (!$returnValue->setDomain($clazz)) { |
110 | throw new common_Exception('An error occured during Property creation.'); |
111 | } else { |
112 | $returnValue->setLgDependent($isLgDependent); |
113 | } |
114 | |
115 | |
116 | |
117 | return $returnValue; |
118 | } |
119 | |
120 | /** |
121 | * Short description of method createSubClass |
122 | * |
123 | * @access public |
124 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
125 | * @param Class clazz |
126 | * @param string label |
127 | * @param string comment |
128 | * @param string uri |
129 | * @return core_kernel_classes_Class |
130 | */ |
131 | public static function createSubClass(core_kernel_classes_Class $clazz, $label = '', $comment = '', $uri = '') |
132 | { |
133 | $returnValue = null; |
134 | $class = new core_kernel_classes_Class(OntologyRdfs::RDFS_CLASS); |
135 | $instance = self::createInstance($class, $label, $comment, $uri); |
136 | $returnValue = new core_kernel_classes_Class($instance->getUri()); |
137 | $returnValue->setSubClassOf($clazz); |
138 | return $returnValue; |
139 | } |
140 | |
141 | /** |
142 | * Short description of method checkProvidedUri |
143 | * |
144 | * @access private |
145 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
146 | * @param string uri |
147 | * @return string |
148 | */ |
149 | private static function checkProvidedUri($uri) |
150 | { |
151 | $returnValue = (string) ''; |
152 | if ($uri != '') { |
153 | if (common_Utils::isUri($uri)) { |
154 | $returnValue = $uri; |
155 | } else { |
156 | throw new common_Exception("Could not create new Resource, malformed URI provided: '" . $uri . "'."); |
157 | } |
158 | } else { |
159 | $returnValue = common_Utils::getNewUri(); |
160 | } |
161 | |
162 | |
163 | return (string) $returnValue; |
164 | } |
165 | } |