Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 74 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
Template | |
0.00% |
0 / 74 |
|
0.00% |
0 / 7 |
1260 | |
0.00% |
0 / 1 |
getRule | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
20 | |||
getTemplateContent | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
42 | |||
__construct | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
380 | |||
toQTI | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
getUri | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
toArray | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
6 | |||
getUsedAttributes | |
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) 2013-2018 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
19 | * |
20 | * |
21 | */ |
22 | |
23 | namespace oat\taoQtiItem\model\qti\response; |
24 | |
25 | use oat\taoQtiItem\model\qti\exception\QtiModelException; |
26 | use oat\taoQtiItem\model\qti\exception\TemplateException; |
27 | use oat\taoQtiItem\helpers\QtiSerializer; |
28 | use taoItems_models_classes_TemplateRenderer; |
29 | |
30 | /** |
31 | * Short description of class oat\taoQtiItem\model\qti\response\Template |
32 | * |
33 | * @access public |
34 | * @author Cedric Alfonsi, <cedric.alfonsi@tudor.lu> |
35 | * @package taoQTI |
36 | |
37 | */ |
38 | class Template extends ResponseProcessing implements Rule |
39 | { |
40 | /** |
41 | * QTI 2.1 Match Correct RP Template URL. |
42 | * |
43 | * @var string |
44 | */ |
45 | public const MATCH_CORRECT = 'http://www.imsglobal.org/question/qti_v2p1/rptemplates/match_correct'; |
46 | |
47 | /** |
48 | * QTI 2.1 Map Response RP Template URL. |
49 | * |
50 | * @var string |
51 | */ |
52 | public const MAP_RESPONSE = 'http://www.imsglobal.org/question/qti_v2p1/rptemplates/map_response'; |
53 | |
54 | /** |
55 | * QTI 2.1 Map Response Point RP Template URL. |
56 | * |
57 | * @var string |
58 | */ |
59 | public const MAP_RESPONSE_POINT = 'http://www.imsglobal.org/question/qti_v2p1/rptemplates/map_response_point'; |
60 | |
61 | // phpcs:disable Generic.NamingConventions.UpperCaseConstantName,Generic.Files.LineLength |
62 | /** |
63 | * QTI 2.0 Match Correct RP Template URL. |
64 | * |
65 | * @var string |
66 | */ |
67 | public const MATCH_CORRECT_qtiv2p0 = 'http://www.imsglobal.org/question/qti_v2p0/rptemplates/match_correct'; |
68 | |
69 | /** |
70 | * QTI 2.0 Map Response RP Template URL. |
71 | * |
72 | * @var string |
73 | */ |
74 | public const MAP_RESPONSE_qtiv2p0 = 'http://www.imsglobal.org/question/qti_v2p0/rptemplates/map_response'; |
75 | |
76 | /** |
77 | * QTI 2.0 Map Response Point RP Template URL. |
78 | * |
79 | * @var string |
80 | */ |
81 | public const MAP_RESPONSE_POINT_qtiv2p0 = 'http://www.imsglobal.org/question/qti_v2p0/rptemplates/map_response_point'; |
82 | |
83 | /** |
84 | * QTI 2.2 Match Correct RP Template URL. |
85 | * |
86 | * @var string |
87 | */ |
88 | public const MATCH_CORRECT_qtiv2p2 = 'http://www.imsglobal.org/question/qti_v2p2/rptemplates/match_correct'; |
89 | |
90 | /** |
91 | * QTI 2.2 Map Response RP Template URL. |
92 | * |
93 | * @var string |
94 | */ |
95 | public const MAP_RESPONSE_qtiv2p2 = 'http://www.imsglobal.org/question/qti_v2p2/rptemplates/map_response'; |
96 | |
97 | /** |
98 | * QTI 2.2 Map Response Point RP Template URL. |
99 | * |
100 | * @var string |
101 | */ |
102 | public const MAP_RESPONSE_POINT_qtiv2p2 = 'http://www.imsglobal.org/question/qti_v2p2/rptemplates/map_response_point'; |
103 | |
104 | /** |
105 | * QTI 3.0 |
106 | */ |
107 | public const MAP_RESPONSE_POINT_QTI_V3 = 'https://www.imsglobal.org/question/qti_v3p0/rptemplates/map_response_point'; |
108 | public const MATCH_CORRECT_QTI_V3 = 'https://www.imsglobal.org/question/qti_v3p0/rptemplates/match_correct.xml'; |
109 | public const MAP_RESPONSE_QTI_V3 = 'https://www.imsglobal.org/question/qti_v3p0/rptemplates//map_response'; |
110 | public const SPEC_MAP_RESPONSE_POINT_QTI_V3 = 'https://purl.imsglobal.org/spec/qti/v3p0/rptemplates/map_response_point'; |
111 | public const SPEC_RESPONSE_QTI_V3 = 'https://purl.imsglobal.org/spec/qti/v3p0/rptemplates/match_correct.xml'; |
112 | public const SPEC_MAP_RESPONSE_QTI_V3 = 'https://purl.imsglobal.org/spec/qti/v3p0/rptemplates/map_response.xml'; |
113 | public const SPEC_MATCH_CORRECT_QTI_V3 = 'http://purl.imsglobal.org/spec/qti/v3p0/rptemplates/match_correct.xml'; |
114 | |
115 | // phpcs:enable Generic.NamingConventions.UpperCaseConstantName,Generic.Files.LineLength |
116 | |
117 | /** |
118 | * Template to apply when no response processing should take place |
119 | */ |
120 | public const NONE = 'no_response_processing'; |
121 | |
122 | /** |
123 | * Short description of attribute uri |
124 | * |
125 | * @access protected |
126 | * @var string |
127 | */ |
128 | protected $uri = ''; |
129 | |
130 | /** |
131 | * Short description of attribute file |
132 | * |
133 | * @access protected |
134 | * @var string |
135 | */ |
136 | protected $file = ''; |
137 | |
138 | /** |
139 | * Short description of method getRule |
140 | * |
141 | * @access public |
142 | * @author Cedric Alfonsi, <cedric.alfonsi@tudor.lu> |
143 | * @return string |
144 | */ |
145 | public function getRule() |
146 | { |
147 | $returnValue = (string) ''; |
148 | |
149 | |
150 | if ($this->uri == self::MATCH_CORRECT) { |
151 | $returnValue = taoQTI_models_classes_Matching_Matching::MATCH_CORRECT; |
152 | } elseif ($this->uri == self::MAP_RESPONSE) { |
153 | $returnValue = taoQTI_models_classes_Matching_Matching::MAP_RESPONSE; |
154 | } elseif ($this->uri == self::MAP_RESPONSE_POINT) { |
155 | $returnValue = taoQTI_models_classes_Matching_Matching::MAP_RESPONSE_POINT; |
156 | } |
157 | |
158 | |
159 | |
160 | return (string) $returnValue; |
161 | } |
162 | |
163 | /** |
164 | * Get the content of the response processing template identified by its uri |
165 | * |
166 | * @todo make it dynamic in the future |
167 | * @return string |
168 | * @throws \oat\taoQtiItem\model\qti\exception\QtiModelException |
169 | */ |
170 | public function getTemplateContent() |
171 | { |
172 | |
173 | $standardRpTemplateFolder = dirname(__FILE__) . '/../data/qtiv2p1/rptemplates/'; |
174 | switch ($this->uri) { |
175 | case self::MATCH_CORRECT: |
176 | $returnValue = file_get_contents($standardRpTemplateFolder . 'match_correct.xml'); |
177 | break; |
178 | case self::MAP_RESPONSE: |
179 | $returnValue = file_get_contents($standardRpTemplateFolder . 'map_response.xml'); |
180 | break; |
181 | case self::MAP_RESPONSE_POINT: |
182 | $returnValue = file_get_contents($standardRpTemplateFolder . 'map_response_point.xml'); |
183 | break; |
184 | case self::NONE: |
185 | $returnValue = ''; |
186 | break; |
187 | default: |
188 | throw new QtiModelException('unknown rp template'); |
189 | } |
190 | return $returnValue; |
191 | } |
192 | |
193 | /** |
194 | * Short description of method __construct |
195 | * |
196 | * @access public |
197 | * @author Cedric Alfonsi, <cedric.alfonsi@tudor.lu> |
198 | * @param string uri |
199 | * @throws QtiModelException |
200 | * @throws TemplateException |
201 | */ |
202 | public function __construct($uri) |
203 | { |
204 | //automatically transform to qti 2.1 templates: |
205 | switch ($uri) { |
206 | case self::MATCH_CORRECT: |
207 | case self::MATCH_CORRECT_qtiv2p0: |
208 | case self::MATCH_CORRECT_qtiv2p2: |
209 | case self::MATCH_CORRECT_QTI_V3: |
210 | case self::SPEC_MATCH_CORRECT_QTI_V3: |
211 | $this->uri = self::MATCH_CORRECT; |
212 | break; |
213 | case self::MAP_RESPONSE: |
214 | case self::MAP_RESPONSE_qtiv2p0: |
215 | case self::MAP_RESPONSE_qtiv2p2: |
216 | case self::MAP_RESPONSE_QTI_V3: |
217 | case self::SPEC_MAP_RESPONSE_QTI_V3: |
218 | case self::SPEC_RESPONSE_QTI_V3: |
219 | $this->uri = self::MAP_RESPONSE; |
220 | break; |
221 | case self::MAP_RESPONSE_POINT: |
222 | case self::MAP_RESPONSE_POINT_qtiv2p0: |
223 | case self::MAP_RESPONSE_POINT_qtiv2p2: |
224 | case self::MAP_RESPONSE_POINT_QTI_V3: |
225 | case self::SPEC_MAP_RESPONSE_POINT_QTI_V3: |
226 | $this->uri = self::MAP_RESPONSE_POINT; |
227 | break; |
228 | case self::NONE: |
229 | $this->uri = self::NONE; |
230 | break; |
231 | default: |
232 | throw new TemplateException("Unknown response processing template '$uri'"); |
233 | } |
234 | |
235 | parent::__construct(); |
236 | } |
237 | |
238 | /** |
239 | * Short description of method toQTI |
240 | * |
241 | * @access public |
242 | * @author Cedric Alfonsi, <cedric.alfonsi@tudor.lu> |
243 | * @return string |
244 | */ |
245 | public function toQTI() |
246 | { |
247 | |
248 | $returnValue = ''; |
249 | |
250 | if ($this->uri != self::NONE) { |
251 | //if there is actually a real response template involved, render the template |
252 | $tplRenderer = new taoItems_models_classes_TemplateRenderer( |
253 | static::getTemplatePath() . '/qti.rptemplate.tpl.php', |
254 | ['uri' => $this->uri] |
255 | ); |
256 | $returnValue = $tplRenderer->render(); |
257 | } |
258 | |
259 | return (string) $returnValue; |
260 | } |
261 | |
262 | /** |
263 | * Short description of method getUri |
264 | * |
265 | * @access public |
266 | * @author Cedric Alfonsi, <cedric.alfonsi@tudor.lu> |
267 | * @return string |
268 | */ |
269 | public function getUri() |
270 | { |
271 | return (string) $this->uri; |
272 | } |
273 | |
274 | public function toArray($filterVariableContent = false, &$filtered = []) |
275 | { |
276 | |
277 | $returnValue = parent::toArray($filterVariableContent, $filtered); |
278 | $rp = $this->getTemplateContent(); |
279 | $rpSerialized = QtiSerializer::parseResponseProcessingXml(simplexml_load_string($rp)); |
280 | $protectedData = [ |
281 | 'processingType' => 'template', |
282 | 'data' => $this->uri, |
283 | 'responseRules' => $rpSerialized['responseRules'] |
284 | ]; |
285 | |
286 | if ($filterVariableContent) { |
287 | $filtered[$this->getSerial()] = $protectedData; |
288 | } else { |
289 | $returnValue = array_merge($returnValue, $protectedData); |
290 | } |
291 | |
292 | return $returnValue; |
293 | } |
294 | |
295 | protected function getUsedAttributes() |
296 | { |
297 | return []; |
298 | } |
299 | } |