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
27 {
29 $ilias =
$DIC[
'ilias'];
30
31 include_once "./Services/Math/classes/class.EvalMath.php";
33 $eval->suppress_errors = true;
34 include_once("./Services/Xml/classes/class.ilXmlWriter.php");
36
38 $a_xml_writer->xmlStartTag("questestinterop");
39 $attrs = array(
40 "ident" =>
"il_" .
IL_INST_ID .
"_qst_" . $this->object->getId(),
41 "title" => $this->object->getTitle(),
42 "maxattempts" => $this->object->getNrOfTries()
43 );
44 $a_xml_writer->xmlStartTag("item", $attrs);
45
46 $a_xml_writer->xmlElement("qticomment", null, $this->object->getComment());
47
48 $workingtime = $this->object->getEstimatedWorkingTime();
49 $duration = sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]);
50 $a_xml_writer->xmlElement("duration", null, $duration);
51
52 $a_xml_writer->xmlStartTag("itemmetadata");
53 $a_xml_writer->xmlStartTag("qtimetadata");
54 $a_xml_writer->xmlStartTag("qtimetadatafield");
55 $a_xml_writer->xmlElement("fieldlabel", null, "ILIAS_VERSION");
56 $a_xml_writer->xmlElement("fieldentry", null, $ilias->getSetting("ilias_version"));
57 $a_xml_writer->xmlEndTag("qtimetadatafield");
58 $a_xml_writer->xmlStartTag("qtimetadatafield");
59 $a_xml_writer->xmlElement("fieldlabel", null, "QUESTIONTYPE");
61 $a_xml_writer->xmlEndTag("qtimetadatafield");
62 $a_xml_writer->xmlStartTag("qtimetadatafield");
63 $a_xml_writer->xmlElement("fieldlabel", null, "AUTHOR");
64 $a_xml_writer->xmlElement("fieldentry", null, $this->object->getAuthor());
65 $a_xml_writer->xmlEndTag("qtimetadatafield");
66
67
70
71 $a_xml_writer->xmlStartTag("qtimetadatafield");
72 $a_xml_writer->xmlElement("fieldlabel", null, "textgaprating");
73 $a_xml_writer->xmlElement("fieldentry", null, $this->object->getTextgapRating());
74 $a_xml_writer->xmlEndTag("qtimetadatafield");
75
76 $a_xml_writer->xmlStartTag("qtimetadatafield");
77 $a_xml_writer->xmlElement("fieldlabel", null, "fixedTextLength");
78 $a_xml_writer->xmlElement("fieldentry", null, $this->object->getFixedTextLength());
79 $a_xml_writer->xmlEndTag("qtimetadatafield");
80
81 $a_xml_writer->xmlStartTag("qtimetadatafield");
82 $a_xml_writer->xmlElement("fieldlabel", null, "identicalScoring");
83 $a_xml_writer->xmlElement("fieldentry", null, $this->object->getIdenticalScoring());
84 $a_xml_writer->xmlEndTag("qtimetadatafield");
85
86 $a_xml_writer->xmlStartTag("qtimetadatafield");
87 $a_xml_writer->xmlElement("fieldlabel", null, "feedback_mode");
88 $a_xml_writer->xmlElement("fieldentry", null, $this->object->getFeedbackMode());
89 $a_xml_writer->xmlEndTag("qtimetadatafield");
90
91 $a_xml_writer->xmlStartTag("qtimetadatafield");
92 $a_xml_writer->xmlElement("fieldlabel", null, "combinations");
93 $a_xml_writer->xmlElement("fieldentry", null, base64_encode(json_encode($this->object->getGapCombinations())));
94 $a_xml_writer->xmlEndTag("qtimetadatafield");
95
96 $a_xml_writer->xmlEndTag("qtimetadata");
97 $a_xml_writer->xmlEndTag("itemmetadata");
98
99
100 $attrs = array(
101 "label" => $this->object->getTitle()
102 );
103 $a_xml_writer->xmlStartTag("presentation", $attrs);
104
105 $a_xml_writer->xmlStartTag("flow");
106
107 $questionText = $this->object->getQuestion() ? $this->object->getQuestion() : ' ';
108 $this->object->addQTIMaterial($a_xml_writer, $questionText);
109
110 $text_parts = preg_split("/\[gap.*?\[\/gap\]/", $this->object->getClozeText());
111
112
113 for (
$i = 0;
$i <= $this->
object->getGapCount();
$i++) {
114 $this->
object->addQTIMaterial($a_xml_writer, $text_parts[
$i]);
115
116 if ($i < $this->object->getGapCount()) {
117
118 $gap = $this->object->getGap($i);
119 switch ($gap->getType()) {
121
122 $attrs = array(
123 "ident" => "gap_$i",
124 "rcardinality" => "Single"
125 );
126 $a_xml_writer->xmlStartTag("response_str", $attrs);
127 $solution = $this->object->getSuggestedSolution($i);
128 if (count($solution)) {
129 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches)) {
130 $attrs = array(
131 "label" => "suggested_solution"
132 );
133 $a_xml_writer->xmlStartTag("material", $attrs);
134 $intlink =
"il_" .
IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
135 if (strcmp($matches[1], "") != 0) {
136 $intlink = $solution["internal_link"];
137 }
138 $a_xml_writer->xmlElement("mattext", null, $intlink);
139 $a_xml_writer->xmlEndTag("material");
140 }
141 }
142
143 $attrs = array("shuffle" => ($gap->getShuffle() ? "Yes" : "No"));
144 $a_xml_writer->xmlStartTag("render_choice", $attrs);
145
146
148 $attrs = array(
149 "ident" => $answeritem->getOrder()
150 );
151 $a_xml_writer->xmlStartTag("response_label", $attrs);
152 $a_xml_writer->xmlStartTag("material");
153 $a_xml_writer->xmlElement("mattext", null, $answeritem->getAnswertext());
154 $a_xml_writer->xmlEndTag("material");
155 $a_xml_writer->xmlEndTag("response_label");
156 }
157 $a_xml_writer->xmlEndTag("render_choice");
158 $a_xml_writer->xmlEndTag("response_str");
159 break;
161
162 $attrs = array(
163 "ident" => "gap_$i",
164 "rcardinality" => "Single"
165 );
166 $a_xml_writer->xmlStartTag("response_str", $attrs);
167 $solution = $this->object->getSuggestedSolution($i);
168 if (count($solution)) {
169 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches)) {
170 $attrs = array(
171 "label" => "suggested_solution"
172 );
173 $a_xml_writer->xmlStartTag("material", $attrs);
174 $intlink =
"il_" .
IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
175 if (strcmp($matches[1], "") != 0) {
176 $intlink = $solution["internal_link"];
177 }
178 $a_xml_writer->xmlElement("mattext", null, $intlink);
179 $a_xml_writer->xmlEndTag("material");
180 }
181 }
182 $attrs = array(
183 "fibtype" => "String",
184 "prompt" => "Box",
185 "columns" => $gap->getMaxWidth(),
186 "maxchars" => $gap->getGapSize()
187 );
188 $a_xml_writer->xmlStartTag("render_fib", $attrs);
189 $a_xml_writer->xmlEndTag("render_fib");
190 $a_xml_writer->xmlEndTag("response_str");
191 break;
193
194 $attrs = array(
195 "ident" => "gap_$i",
196 "numtype" => "Decimal",
197 "rcardinality" => "Single"
198 );
199 $a_xml_writer->xmlStartTag("response_num", $attrs);
200 $solution = $this->object->getSuggestedSolution($i);
201 if (count($solution)) {
202 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches)) {
203 $attrs = array(
204 "label" => "suggested_solution"
205 );
206 $a_xml_writer->xmlStartTag("material", $attrs);
207 $intlink =
"il_" .
IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
208 if (strcmp($matches[1], "") != 0) {
209 $intlink = $solution["internal_link"];
210 }
211 $a_xml_writer->xmlElement("mattext", null, $intlink);
212 $a_xml_writer->xmlEndTag("material");
213 }
214 }
215 $answeritem = $gap->getItem(0);
216 $attrs = array(
217 "fibtype" => "Decimal",
218 "prompt" => "Box",
219 "columns" => $gap->getMaxWidth(),
220 "maxchars" => $gap->getGapSize()
221 );
222 if (is_object($answeritem)) {
223 if ($eval->e($answeritem->getLowerBound()) !== false) {
224 $attrs["minnumber"] = $answeritem->getLowerBound();
225 }
226 if ($eval->e($answeritem->getUpperBound()) !== false) {
227 $attrs["maxnumber"] = $answeritem->getUpperBound();
228 }
229 }
230 $a_xml_writer->xmlStartTag("render_fib", $attrs);
231 $a_xml_writer->xmlEndTag("render_fib");
232 $a_xml_writer->xmlEndTag("response_num");
233 break;
234 }
235 }
236 }
237 $a_xml_writer->xmlEndTag("flow");
238 $a_xml_writer->xmlEndTag("presentation");
239
240
241 $a_xml_writer->xmlStartTag("resprocessing");
242 $a_xml_writer->xmlStartTag("outcomes");
243 $a_xml_writer->xmlStartTag("decvar");
244 $a_xml_writer->xmlEndTag("decvar");
245 $a_xml_writer->xmlEndTag("outcomes");
246
247
248 for (
$i = 0;
$i < $this->
object->getGapCount(); $i++) {
249 $gap = $this->object->getGap($i);
250 switch ($gap->getType()) {
253 $attrs = array(
254 "continue" => "Yes"
255 );
256 $a_xml_writer->xmlStartTag("respcondition", $attrs);
257
258 $a_xml_writer->xmlStartTag("conditionvar");
259
260 $attrs = array(
261 "respident" => "gap_$i"
262 );
263 $a_xml_writer->xmlElement("varequal", $attrs, $answer->getAnswertext());
264 $a_xml_writer->xmlEndTag("conditionvar");
265
266 $attrs = array(
267 "action" => "Add"
268 );
269 $a_xml_writer->xmlElement("setvar", $attrs, $answer->getPoints());
270
271 $linkrefid = "";
272 $linkrefid = "$i" . "_Response_" . $answer->getOrder();
273 $attrs = array(
274 "feedbacktype" => "Response",
275 "linkrefid" => $linkrefid
276 );
277 $a_xml_writer->xmlElement("displayfeedback", $attrs);
278 $a_xml_writer->xmlEndTag("respcondition");
279 }
280 break;
283 $attrs = array(
284 "continue" => "Yes"
285 );
286 $a_xml_writer->xmlStartTag("respcondition", $attrs);
287
288 $a_xml_writer->xmlStartTag("conditionvar");
289 $attrs = array(
290 "respident" => "gap_$i"
291 );
292 $a_xml_writer->xmlElement("varequal", $attrs, $answer->getAnswertext());
293 $a_xml_writer->xmlEndTag("conditionvar");
294
295 $attrs = array(
296 "action" => "Add"
297 );
298 $a_xml_writer->xmlElement("setvar", $attrs, $answer->getPoints());
299
300 $linkrefid = "$i" . "_Response_" . $answer->getOrder();
301 $attrs = array(
302 "feedbacktype" => "Response",
303 "linkrefid" => $linkrefid
304 );
305 $a_xml_writer->xmlElement("displayfeedback", $attrs);
306 $a_xml_writer->xmlEndTag("respcondition");
307 }
308 break;
311 $attrs = array(
312 "continue" => "Yes"
313 );
314 $a_xml_writer->xmlStartTag("respcondition", $attrs);
315
316 $a_xml_writer->xmlStartTag("conditionvar");
317 $attrs = array(
318 "respident" => "gap_$i"
319 );
320 $a_xml_writer->xmlElement("varequal", $attrs, $answer->getAnswertext());
321 $a_xml_writer->xmlEndTag("conditionvar");
322
323 $attrs = array(
324 "action" => "Add"
325 );
326 $a_xml_writer->xmlElement("setvar", $attrs, $answer->getPoints());
327
328 $linkrefid = "$i" . "_Response_" . $answer->getOrder();
329 $attrs = array(
330 "feedbacktype" => "Response",
331 "linkrefid" => $linkrefid
332 );
333 $a_xml_writer->xmlElement("displayfeedback", $attrs);
334 $a_xml_writer->xmlEndTag("respcondition");
335 }
336 break;
337 }
338 }
339
340 $feedback_allcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
341 $this->object->getId(),
342 true
343 );
344 if (strlen($feedback_allcorrect)) {
345 $attrs = array(
346 "continue" => "Yes"
347 );
348 $a_xml_writer->xmlStartTag("respcondition", $attrs);
349
350 $a_xml_writer->xmlStartTag("conditionvar");
351
352 for (
$i = 0;
$i < $this->
object->getGapCount(); $i++) {
353 $gap = $this->object->getGap($i);
354 $indexes = $gap->getBestSolutionIndexes();
356 $a_xml_writer->xmlStartTag("and");
357 }
358 switch ($gap->getType()) {
360 $k = 0;
361 foreach ($indexes as $key) {
362 if ($k > 0) {
363 $a_xml_writer->xmlStartTag("or");
364 }
365 $attrs = array(
366 "respident" => "gap_$i"
367 );
368 $answer = $gap->getItem($key);
369 $a_xml_writer->xmlElement("varequal", $attrs, $answer->getAnswertext());
370 if ($k > 0) {
371 $a_xml_writer->xmlEndTag("or");
372 }
373 $k++;
374 }
375 break;
377 $k = 0;
378 foreach ($indexes as $key) {
379 if ($k > 0) {
380 $a_xml_writer->xmlStartTag("or");
381 }
382 $attrs = array(
383 "respident" => "gap_$i"
384 );
385 $answer = $gap->getItem($key);
386 $a_xml_writer->xmlElement("varequal", $attrs, $answer->getAnswertext());
387 if ($k > 0) {
388 $a_xml_writer->xmlEndTag("or");
389 }
390 $k++;
391 }
392 break;
394 $k = 0;
395 foreach ($indexes as $key) {
396 if ($k > 0) {
397 $a_xml_writer->xmlStartTag("or");
398 }
399 $attrs = array(
400 "respident" => "gap_$i"
401 );
402 $answer = $gap->getItem($key);
403 $a_xml_writer->xmlElement("varequal", $attrs, $answer->getAnswertext());
404 if ($k > 0) {
405 $a_xml_writer->xmlEndTag("or");
406 }
407 $k++;
408 }
409 break;
410 }
412 $a_xml_writer->xmlEndTag("and");
413 }
414 }
415 $a_xml_writer->xmlEndTag("conditionvar");
416
417 $attrs = array(
418 "feedbacktype" => "Response",
419 "linkrefid" => "response_allcorrect"
420 );
421 $a_xml_writer->xmlElement("displayfeedback", $attrs);
422 $a_xml_writer->xmlEndTag("respcondition");
423 }
424 $feedback_onenotcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
425 $this->object->getId(),
426 false
427 );
428 if (strlen($feedback_onenotcorrect)) {
429 $attrs = array(
430 "continue" => "Yes"
431 );
432 $a_xml_writer->xmlStartTag("respcondition", $attrs);
433
434 $a_xml_writer->xmlStartTag("conditionvar");
435
436 $a_xml_writer->xmlStartTag("not");
437 for (
$i = 0;
$i < $this->
object->getGapCount(); $i++) {
438 $gap = $this->object->getGap($i);
439 $indexes = $gap->getBestSolutionIndexes();
441 $a_xml_writer->xmlStartTag("and");
442 }
443 switch ($gap->getType()) {
445 $k = 0;
446 foreach ($indexes as $key) {
447 if ($k > 0) {
448 $a_xml_writer->xmlStartTag("or");
449 }
450 $attrs = array(
451 "respident" => "gap_$i"
452 );
453 $answer = $gap->getItem($key);
454 $a_xml_writer->xmlElement("varequal", $attrs, $answer->getAnswertext());
455 if ($k > 0) {
456 $a_xml_writer->xmlEndTag("or");
457 }
458 $k++;
459 }
460 break;
462 $k = 0;
463 foreach ($indexes as $key) {
464 if ($k > 0) {
465 $a_xml_writer->xmlStartTag("or");
466 }
467 $attrs = array(
468 "respident" => "gap_$i"
469 );
470 $answer = $gap->getItem($key);
471 $a_xml_writer->xmlElement("varequal", $attrs, $answer->getAnswertext());
472 if ($k > 0) {
473 $a_xml_writer->xmlEndTag("or");
474 }
475 $k++;
476 }
477 break;
479 $k = 0;
480 foreach ($indexes as $key) {
481 if ($k > 0) {
482 $a_xml_writer->xmlStartTag("or");
483 }
484 $attrs = array(
485 "respident" => "gap_$i"
486 );
487 $answer = $gap->getItem($key);
488 $a_xml_writer->xmlElement("varequal", $attrs, $answer->getAnswertext());
489 if ($k > 0) {
490 $a_xml_writer->xmlEndTag("or");
491 }
492 $k++;
493 }
494 break;
495 }
497 $a_xml_writer->xmlEndTag("and");
498 }
499 }
500 $a_xml_writer->xmlEndTag("not");
501 $a_xml_writer->xmlEndTag("conditionvar");
502
503 $attrs = array(
504 "feedbacktype" => "Response",
505 "linkrefid" => "response_onenotcorrect"
506 );
507 $a_xml_writer->xmlElement("displayfeedback", $attrs);
508 $a_xml_writer->xmlEndTag("respcondition");
509 }
510
511 $a_xml_writer->xmlEndTag("resprocessing");
512
513
514 for (
$i = 0;
$i < $this->
object->getGapCount(); $i++) {
515 $gap = $this->object->getGap($i);
516 switch ($gap->getType()) {
518 break;
520 break;
522 break;
523 }
524 }
526
527 if (strlen($feedback_allcorrect)) {
528 $attrs = array(
529 "ident" => "response_allcorrect",
530 "view" => "All"
531 );
532 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
533
534 $a_xml_writer->xmlStartTag("flow_mat");
535 $this->object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
536 $a_xml_writer->xmlEndTag("flow_mat");
537 $a_xml_writer->xmlEndTag("itemfeedback");
538 }
539 if (strlen($feedback_onenotcorrect)) {
540 $attrs = array(
541 "ident" => "response_onenotcorrect",
542 "view" => "All"
543 );
544 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
545
546 $a_xml_writer->xmlStartTag("flow_mat");
547 $this->object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
548 $a_xml_writer->xmlEndTag("flow_mat");
549 $a_xml_writer->xmlEndTag("itemfeedback");
550 }
551
553
554 $a_xml_writer->xmlEndTag("item");
555 $a_xml_writer->xmlEndTag("questestinterop");
556
557 $xml = $a_xml_writer->xmlDumpMem(
false);
558 if (!$a_include_header) {
559 $pos = strpos(
$xml,
"?>");
561 }
563 }
exportAnswerSpecificFeedbacks(ilXmlWriter $xmlWriter)
addGeneralMetadata(ilXmlWriter $xmlwriter)
addSolutionHints(ilXmlWriter $writer)
addAdditionalContentEditingModeInformation(ilXmlWriter $a_xml_writer)
adds a qti meta data field for ilias specific information of "additional content editing mode" (xml w...
xmlHeader()
Writes xml header @access public.
const CLOZE_TEST_IDENTIFIER
Question identifier constants.
const CLOZE_TEXT
Cloze question constants.