Returns a QTI xml representation of the question Returns a QTI xml representation of the question and sets the internal domxml variable with the DOM XML representation of the QTI xml representation.
39 : string
40 {
42 $ilias =
$DIC[
'ilias'];
43
45
46 $a_xml_writer->xmlHeader();
47 $a_xml_writer->xmlStartTag("questestinterop");
48 $attrs = [
49 "ident" =>
"il_" .
IL_INST_ID .
"_qst_" . $this->
object->getId(),
50 "title" => $this->object->getTitle(),
51 "maxattempts" => $this->object->getNrOfTries()
52 ];
53 $a_xml_writer->xmlStartTag("item", $attrs);
54
55 $a_xml_writer->xmlElement(
"qticomment",
null, $this->
object->getComment());
56 $a_xml_writer->xmlStartTag("itemmetadata");
57 $a_xml_writer->xmlStartTag("qtimetadata");
58 $a_xml_writer->xmlStartTag("qtimetadatafield");
59 $a_xml_writer->xmlElement("fieldlabel", null, "ILIAS_VERSION");
60 $a_xml_writer->xmlElement("fieldentry", null, $ilias->getSetting("ilias_version"));
61 $a_xml_writer->xmlEndTag("qtimetadatafield");
62 $a_xml_writer->xmlStartTag("qtimetadatafield");
63 $a_xml_writer->xmlElement("fieldlabel", null, "QUESTIONTYPE");
64 $a_xml_writer->xmlElement(
"fieldentry",
null, $this->
object->getQuestionType());
65 $a_xml_writer->xmlEndTag("qtimetadatafield");
66 $a_xml_writer->xmlStartTag("qtimetadatafield");
67 $a_xml_writer->xmlElement("fieldlabel", null, "IS_MULTIPLE_CHOICE");
68 $a_xml_writer->xmlElement(
"fieldentry",
null, ($this->
object->getIsMultipleChoice()) ?
"1" :
"0");
69 $a_xml_writer->xmlEndTag("qtimetadatafield");
70 $a_xml_writer->xmlStartTag("qtimetadatafield");
71 $a_xml_writer->xmlElement("fieldlabel", null, "AUTHOR");
72 $a_xml_writer->xmlElement(
"fieldentry",
null, $this->
object->getAuthor());
73 $a_xml_writer->xmlEndTag("qtimetadatafield");
74
75
78
79 $a_xml_writer->xmlEndTag("qtimetadata");
80 $a_xml_writer->xmlEndTag("itemmetadata");
81
82
83 $attrs = [
84 "label" => $this->object->getTitle()
85 ];
86 $a_xml_writer->xmlStartTag("presentation", $attrs);
87
88 $a_xml_writer->xmlStartTag("flow");
89
91
92 $attrs = [
93 "ident" => "IM",
94 "rcardinality" => "Single"
95 ];
96 $a_xml_writer->xmlStartTag("response_xy", $attrs);
98 $a_xml_writer->xmlStartTag("render_hotspot");
99 $a_xml_writer->xmlStartTag("material");
100 $imagetype = "image/jpeg";
101 if (preg_match(
"/.*\.(png|gif)$/i", $this->
object->getImageFilename(), $matches)) {
102 $imagetype = "image/" . strtolower($matches[1]);
103 }
104 $attrs = [
105 "imagtype" => $imagetype,
106 "label" => $this->object->getImageFilename()
107 ];
108 if ($a_include_binary) {
109 if ($force_image_references) {
110 $attrs["uri"] = $this->object->getImagePathWeb() . $this->object->getImageFilename();
111 $a_xml_writer->xmlElement("matimage", $attrs);
112 } else {
113 $attrs["embedded"] = "base64";
114 $imagepath = $this->object->getImagePath() . $this->object->getImageFilename();
115 $fh = fopen($imagepath, "rb");
116 if ($fh == false) {
118 $ilErr =
$DIC[
'ilErr'];
119 $ilErr->raiseError(
$GLOBALS[
'DIC'][
'lng']->txt(
"error_open_image_file"), $ilErr->MESSAGE);
120 }
121 $imagefile = fread($fh, filesize($imagepath));
122 fclose($fh);
123 $base64 = base64_encode($imagefile);
124 $a_xml_writer->xmlElement("matimage", $attrs, $base64, false, false);
125 }
126 } else {
127 $a_xml_writer->xmlElement("matimage", $attrs);
128 }
129 $a_xml_writer->xmlEndTag("material");
130
131
132 foreach ($this->
object->getAnswers() as $index => $answer) {
133 $rared = "";
134 switch ($answer->getArea()) {
135 case "rect":
136 $rarea = "Rectangle";
137 break;
138 case "circle":
139 $rarea = "Ellipse";
140 break;
141 case "poly":
142 $rarea = "Bounded";
143 break;
144 }
145 $attrs = [
146 "ident" => $index,
147 "rarea" => $rarea
148 ];
149 $a_xml_writer->xmlStartTag("response_label", $attrs);
150 $a_xml_writer->xmlData($answer->getCoords());
151 $a_xml_writer->xmlStartTag("material");
152 $a_xml_writer->xmlElement("mattext", null, $answer->getAnswertext());
153 $a_xml_writer->xmlEndTag("material");
154 $a_xml_writer->xmlEndTag("response_label");
155 }
156 $a_xml_writer->xmlEndTag("render_hotspot");
157 $a_xml_writer->xmlEndTag("response_xy");
158 $a_xml_writer->xmlEndTag("flow");
159 $a_xml_writer->xmlEndTag("presentation");
160
161
162 $a_xml_writer->xmlStartTag("resprocessing");
163 $a_xml_writer->xmlStartTag("outcomes");
164 $a_xml_writer->xmlStartTag("decvar");
165 $a_xml_writer->xmlEndTag("decvar");
166 $a_xml_writer->xmlEndTag("outcomes");
167
168 foreach ($this->
object->getAnswers() as $index => $answer) {
169 $attrs = [
170 "continue" => "Yes"
171 ];
172 $a_xml_writer->xmlStartTag("respcondition", $attrs);
173
174 $a_xml_writer->xmlStartTag("conditionvar");
175 if (!$answer->isStateSet()) {
176 $a_xml_writer->xmlStartTag("not");
177 }
178 $areatype = "";
179 switch ($answer->getArea()) {
180 case "rect":
181 $areatype = "Rectangle";
182 break;
183 case "circle":
184 $areatype = "Ellipse";
185 break;
186 case "poly":
187 $areatype = "Bounded";
188 break;
189 }
190 $attrs = [
191 "respident" => "IM",
192 "areatype" => $areatype
193 ];
194 $a_xml_writer->xmlElement("varequal", $attrs, $answer->getCoords());
195 if (!$answer->isStateSet()) {
196 $a_xml_writer->xmlEndTag("not");
197 }
198 $a_xml_writer->xmlEndTag("conditionvar");
199
200 $attrs = [
201 "action" => "Add"
202 ];
203 $a_xml_writer->xmlElement("setvar", $attrs, $answer->getPoints());
204 $linkrefid = "response_$index";
205 $attrs = [
206 "feedbacktype" => "Response",
207 "linkrefid" => $linkrefid
208 ];
209 $a_xml_writer->xmlElement("displayfeedback", $attrs);
210 $a_xml_writer->xmlEndTag("respcondition");
211 $attrs = [
212 "continue" => "Yes"
213 ];
214 $a_xml_writer->xmlStartTag("respcondition", $attrs);
215
216 $a_xml_writer->xmlStartTag("conditionvar");
217 $attrs = [
218 "respident" => "IM"
219 ];
220 $a_xml_writer->xmlStartTag("not");
221 $a_xml_writer->xmlElement("varequal", $attrs, $answer->getCoords());
222 $a_xml_writer->xmlEndTag("not");
223 $a_xml_writer->xmlEndTag("conditionvar");
224
225 $attrs = [
226 "action" => "Add"
227 ];
228 $a_xml_writer->xmlElement("setvar", $attrs, $answer->getPointsUnchecked());
229 $a_xml_writer->xmlEndTag("respcondition");
230 }
231
232 $answers = $this->object->getAnswers();
233 $feedback_allcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
235 true
236 );
237 if (strlen($feedback_allcorrect) && count($answers) > 0) {
238 $attrs = [
239 "continue" => "Yes"
240 ];
241 $a_xml_writer->xmlStartTag("respcondition", $attrs);
242
243 $a_xml_writer->xmlStartTag("conditionvar");
244 if (!$this->
object->getIsMultipleChoice()) {
245 $bestindex = 0;
246 $maxpoints = 0;
247 foreach ($answers as $index => $answer) {
248 if ($answer->getPoints() > $maxpoints) {
249 $maxpoints = $answer->getPoints();
250 $bestindex = $index;
251 }
252 }
253
254 $areatype = "";
255 $answer = $answers[$bestindex];
256 switch ($answer->getArea()) {
257 case "rect":
258 $areatype = "Rectangle";
259 break;
260 case "circle":
261 $areatype = "Ellipse";
262 break;
263 case "poly":
264 $areatype = "Bounded";
265 break;
266 }
267 $attrs = [
268 "respident" => "IM",
269 "areatype" => $areatype
270 ];
271 $a_xml_writer->xmlElement("varinside", $attrs, $answer->getCoords());
272 } else {
273 foreach ($answers as $index => $answer) {
274 if ($answer->getPoints() < $answer->getPointsUnchecked()) {
275 $a_xml_writer->xmlStartTag("not");
276 }
277 switch ($answer->getArea()) {
278 case "rect":
279 $areatype = "Rectangle";
280 break;
281 case "circle":
282 $areatype = "Ellipse";
283 break;
284 case "poly":
285 $areatype = "Bounded";
286 break;
287 }
288 $attrs = [
289 "respident" => "IM",
290 "areatype" => $areatype
291 ];
292 $a_xml_writer->xmlElement("varequal", $attrs, $index);
293 if ($answer->getPoints() < $answer->getPointsUnchecked()) {
294 $a_xml_writer->xmlEndTag("not");
295 }
296 }
297 }
298
299 $a_xml_writer->xmlEndTag("conditionvar");
300
301 $attrs = [
302 "feedbacktype" => "Response",
303 "linkrefid" => "response_allcorrect"
304 ];
305 $a_xml_writer->xmlElement("displayfeedback", $attrs);
306 $a_xml_writer->xmlEndTag("respcondition");
307 }
308
309 $feedback_onenotcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
311 false
312 );
313 if (strlen($feedback_onenotcorrect) && count($answers) > 0) {
314 $attrs = [
315 "continue" => "Yes"
316 ];
317 $a_xml_writer->xmlStartTag("respcondition", $attrs);
318
319 $a_xml_writer->xmlStartTag("conditionvar");
320 if (!$this->
object->getIsMultipleChoice()) {
321 $bestindex = 0;
322 $maxpoints = 0;
323 foreach ($answers as $index => $answer) {
324 if ($answer->getPoints() > $maxpoints) {
325 $maxpoints = $answer->getPoints();
326 $bestindex = $index;
327 }
328 }
329 $attrs = [
330 "respident" => "IM"
331 ];
332 $a_xml_writer->xmlStartTag("not");
333
334 $areatype = "";
335 $answer = $answers[$bestindex];
336 switch ($answer->getArea()) {
337 case "rect":
338 $areatype = "Rectangle";
339 break;
340 case "circle":
341 $areatype = "Ellipse";
342 break;
343 case "poly":
344 $areatype = "Bounded";
345 break;
346 }
347 $attrs = [
348 "respident" => "IM",
349 "areatype" => $areatype
350 ];
351 $a_xml_writer->xmlElement("varinside", $attrs, $answer->getCoords());
352
353 $a_xml_writer->xmlEndTag("not");
354 } else {
355 foreach ($answers as $index => $answer) {
356 if ($index > 0) {
357 $a_xml_writer->xmlStartTag("or");
358 }
359 if ($answer->getPoints() >= $answer->getPointsUnchecked()) {
360 $a_xml_writer->xmlStartTag("not");
361 }
362 switch ($answer->getArea()) {
363 case "rect":
364 $areatype = "Rectangle";
365 break;
366 case "circle":
367 $areatype = "Ellipse";
368 break;
369 case "poly":
370 $areatype = "Bounded";
371 break;
372 }
373 $attrs = [
374 "respident" => "IM",
375 "areatype" => $areatype
376 ];
377 $a_xml_writer->xmlElement("varequal", $attrs, $index);
378 if ($answer->getPoints() >= $answer->getPointsUnchecked()) {
379 $a_xml_writer->xmlEndTag("not");
380 }
381 if ($index > 0) {
382 $a_xml_writer->xmlEndTag("or");
383 }
384 }
385 }
386 $a_xml_writer->xmlEndTag("conditionvar");
387
388 $attrs = [
389 "feedbacktype" => "Response",
390 "linkrefid" => "response_onenotcorrect"
391 ];
392 $a_xml_writer->xmlElement("displayfeedback", $attrs);
393 $a_xml_writer->xmlEndTag("respcondition");
394 }
395
396 $a_xml_writer->xmlEndTag("resprocessing");
397
398
399 foreach ($this->
object->getAnswers() as $index => $answer) {
400 $linkrefid = "response_$index";
401 $attrs = [
402 "ident" => $linkrefid,
403 "view" => "All"
404 ];
405 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
406
407 $a_xml_writer->xmlStartTag("flow_mat");
408 $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation(
410 0,
411 $index
412 );
414 $a_xml_writer->xmlEndTag("flow_mat");
415 $a_xml_writer->xmlEndTag("itemfeedback");
416 }
417 if (strlen($feedback_allcorrect)) {
418 $attrs = [
419 "ident" => "response_allcorrect",
420 "view" => "All"
421 ];
422 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
423
424 $a_xml_writer->xmlStartTag("flow_mat");
426 $a_xml_writer->xmlEndTag("flow_mat");
427 $a_xml_writer->xmlEndTag("itemfeedback");
428 }
429 if (strlen($feedback_onenotcorrect)) {
430 $attrs = [
431 "ident" => "response_onenotcorrect",
432 "view" => "All"
433 ];
434 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
435
436 $a_xml_writer->xmlStartTag("flow_mat");
438 $a_xml_writer->xmlEndTag("flow_mat");
439 $a_xml_writer->xmlEndTag("itemfeedback");
440 }
441
442 $a_xml_writer->xmlEndTag("item");
443 $a_xml_writer->xmlEndTag("questestinterop");
444
445 $xml = $a_xml_writer->xmlDumpMem(false);
446 if (!$a_include_header) {
447 $pos = strpos($xml, "?>");
448 $xml = substr($xml, $pos + 2);
449 }
450 return $xml;
451 }
addGeneralMetadata(ilXmlWriter $xmlwriter)
addQTIMaterial(ilXmlWriter $a_xml_writer, string $a_material, bool $close_material_tag=true, bool $add_mobs=true)
addSuggestedSolution(ilXmlWriter $writer)
addAdditionalContentEditingModeInformation(ilXmlWriter $a_xml_writer)
adds a qti meta data field for ilias specific information of "additional content editing mode" (xml w...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...