24 include_once
"./Modules/TestQuestionPool/classes/export/qti12/class.assQuestionExport.php";
46 function toXML($a_include_header =
true, $a_include_binary =
true, $a_shuffle =
false, $test_output =
false, $force_image_references =
false)
50 include_once
"./Services/Math/classes/class.EvalMath.php";
52 $eval->suppress_errors = TRUE;
53 include_once(
"./Services/Xml/classes/class.ilXmlWriter.php");
57 $a_xml_writer->xmlStartTag(
"questestinterop");
59 "ident" =>
"il_".IL_INST_ID.
"_qst_".$this->object->getId(),
60 "title" => $this->
object->getTitle(),
61 "maxattempts" => $this->
object->getNrOfTries()
63 $a_xml_writer->xmlStartTag(
"item", $attrs);
65 $a_xml_writer->xmlElement(
"qticomment", NULL, $this->object->getComment());
67 $workingtime = $this->
object->getEstimatedWorkingTime();
68 $duration = sprintf(
"P0Y0M0DT%dH%dM%dS", $workingtime[
"h"], $workingtime[
"m"], $workingtime[
"s"]);
69 $a_xml_writer->xmlElement(
"duration", NULL, $duration);
71 $a_xml_writer->xmlStartTag(
"itemmetadata");
72 $a_xml_writer->xmlStartTag(
"qtimetadata");
73 $a_xml_writer->xmlStartTag(
"qtimetadatafield");
74 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"ILIAS_VERSION");
75 $a_xml_writer->xmlElement(
"fieldentry", NULL, $ilias->getSetting(
"ilias_version"));
76 $a_xml_writer->xmlEndTag(
"qtimetadatafield");
77 $a_xml_writer->xmlStartTag(
"qtimetadatafield");
78 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"QUESTIONTYPE");
80 $a_xml_writer->xmlEndTag(
"qtimetadatafield");
81 $a_xml_writer->xmlStartTag(
"qtimetadatafield");
82 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"AUTHOR");
83 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->object->getAuthor());
84 $a_xml_writer->xmlEndTag(
"qtimetadatafield");
85 $a_xml_writer->xmlStartTag(
"qtimetadatafield");
86 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"textgaprating");
87 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->object->getTextgapRating());
88 $a_xml_writer->xmlEndTag(
"qtimetadatafield");
89 $a_xml_writer->xmlStartTag(
"qtimetadatafield");
90 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"fixedTextLength");
91 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->object->getFixedTextLength());
92 $a_xml_writer->xmlEndTag(
"qtimetadatafield");
93 $a_xml_writer->xmlStartTag(
"qtimetadatafield");
94 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"identicalScoring");
95 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->object->getIdenticalScoring());
96 $a_xml_writer->xmlEndTag(
"qtimetadatafield");
97 $a_xml_writer->xmlStartTag(
"qtimetadatafield");
98 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"externalID");
99 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->object->getExternalID());
100 $a_xml_writer->xmlEndTag(
"qtimetadatafield");
101 $a_xml_writer->xmlEndTag(
"qtimetadata");
102 $a_xml_writer->xmlEndTag(
"itemmetadata");
106 "label" => $this->object->getTitle()
108 $a_xml_writer->xmlStartTag(
"presentation", $attrs);
110 $a_xml_writer->xmlStartTag(
"flow");
111 $text_parts = preg_split(
"/\[gap.*?\[\/gap\]/", $this->object->getClozeText());
113 for ($i = 0; $i <= $this->
object->getGapCount(); $i++)
118 $this->
object->addQTIMaterial($a_xml_writer, $text_parts[$i]);
122 $this->
object->addQTIMaterial($a_xml_writer, $text_parts[$i], TRUE, FALSE);
125 if ($i < $this->object->getGapCount())
128 $gap = $this->
object->getGap($i);
129 switch ($gap->getType())
135 "rcardinality" =>
"Single"
137 $a_xml_writer->xmlStartTag(
"response_str", $attrs);
138 $solution = $this->
object->getSuggestedSolution($i);
139 if (count($solution))
141 if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $solution[
"internal_link"], $matches))
144 "label" =>
"suggested_solution"
146 $a_xml_writer->xmlStartTag(
"material", $attrs);
147 $intlink =
"il_" . IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
148 if (strcmp($matches[1],
"") != 0)
150 $intlink = $solution[
"internal_link"];
152 $a_xml_writer->xmlElement(
"mattext", NULL, $intlink);
153 $a_xml_writer->xmlEndTag(
"material");
157 $attrs = array(
"shuffle" => ($gap->getShuffle() ?
"Yes" :
"No"));
158 $a_xml_writer->xmlStartTag(
"render_choice", $attrs);
161 foreach ($gap->getItems() as $answeritem)
164 "ident" => $answeritem->getOrder()
166 $a_xml_writer->xmlStartTag(
"response_label", $attrs);
167 $a_xml_writer->xmlStartTag(
"material");
168 $a_xml_writer->xmlElement(
"mattext", NULL, $answeritem->getAnswertext());
169 $a_xml_writer->xmlEndTag(
"material");
170 $a_xml_writer->xmlEndTag(
"response_label");
172 $a_xml_writer->xmlEndTag(
"render_choice");
173 $a_xml_writer->xmlEndTag(
"response_str");
179 "rcardinality" =>
"Single"
181 $a_xml_writer->xmlStartTag(
"response_str", $attrs);
182 $solution = $this->
object->getSuggestedSolution($i);
183 if (count($solution))
185 if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $solution[
"internal_link"], $matches))
188 "label" =>
"suggested_solution"
190 $a_xml_writer->xmlStartTag(
"material", $attrs);
191 $intlink =
"il_" . IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
192 if (strcmp($matches[1],
"") != 0)
194 $intlink = $solution[
"internal_link"];
196 $a_xml_writer->xmlElement(
"mattext", NULL, $intlink);
197 $a_xml_writer->xmlEndTag(
"material");
201 "fibtype" =>
"String",
203 "columns" => $gap->getMaxWidth()
205 $a_xml_writer->xmlStartTag(
"render_fib", $attrs);
206 $a_xml_writer->xmlEndTag(
"render_fib");
207 $a_xml_writer->xmlEndTag(
"response_str");
213 "numtype" =>
"Decimal",
214 "rcardinality" =>
"Single"
216 $a_xml_writer->xmlStartTag(
"response_num", $attrs);
217 $solution = $this->
object->getSuggestedSolution($i);
218 if (count($solution))
220 if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $solution[
"internal_link"], $matches))
223 "label" =>
"suggested_solution"
225 $a_xml_writer->xmlStartTag(
"material", $attrs);
226 $intlink =
"il_" . IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
227 if (strcmp($matches[1],
"") != 0)
229 $intlink = $solution[
"internal_link"];
231 $a_xml_writer->xmlElement(
"mattext", NULL, $intlink);
232 $a_xml_writer->xmlEndTag(
"material");
235 $answeritem = $gap->getItem(0);
237 "fibtype" =>
"Decimal",
239 "columns" => $gap->getMaxWidth()
241 if (is_object($answeritem))
243 if ($eval->e($answeritem->getLowerBound()) !== FALSE)
245 $attrs[
"minnumber"] = $answeritem->getLowerBound();
247 if ($eval->e($answeritem->getUpperBound()) !== FALSE)
249 $attrs[
"maxnumber"] = $answeritem->getUpperBound();
252 $a_xml_writer->xmlStartTag(
"render_fib", $attrs);
253 $a_xml_writer->xmlEndTag(
"render_fib");
254 $a_xml_writer->xmlEndTag(
"response_num");
259 $a_xml_writer->xmlEndTag(
"flow");
260 $a_xml_writer->xmlEndTag(
"presentation");
263 $a_xml_writer->xmlStartTag(
"resprocessing");
264 $a_xml_writer->xmlStartTag(
"outcomes");
265 $a_xml_writer->xmlStartTag(
"decvar");
266 $a_xml_writer->xmlEndTag(
"decvar");
267 $a_xml_writer->xmlEndTag(
"outcomes");
270 for ($i = 0; $i < $this->
object->getGapCount(); $i++)
272 $gap = $this->
object->getGap($i);
273 switch ($gap->getType())
276 foreach ($gap->getItems() as $answer)
281 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
283 $a_xml_writer->xmlStartTag(
"conditionvar");
286 "respident" =>
"gap_$i"
288 $a_xml_writer->xmlElement(
"varequal", $attrs, $answer->getAnswertext());
289 $a_xml_writer->xmlEndTag(
"conditionvar");
294 $a_xml_writer->xmlElement(
"setvar", $attrs, $answer->getPoints());
297 $linkrefid =
"$i" .
"_Response_" . $answer->getOrder();
299 "feedbacktype" =>
"Response",
300 "linkrefid" => $linkrefid
302 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
303 $a_xml_writer->xmlEndTag(
"respcondition");
307 foreach ($gap->getItems() as $answer)
312 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
314 $a_xml_writer->xmlStartTag(
"conditionvar");
316 "respident" =>
"gap_$i"
318 $a_xml_writer->xmlElement(
"varequal", $attrs, $answer->getAnswertext());
319 $a_xml_writer->xmlEndTag(
"conditionvar");
324 $a_xml_writer->xmlElement(
"setvar", $attrs, $answer->getPoints());
326 $linkrefid =
"$i" .
"_Response_" . $answer->getOrder();
328 "feedbacktype" =>
"Response",
329 "linkrefid" => $linkrefid
331 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
332 $a_xml_writer->xmlEndTag(
"respcondition");
336 foreach ($gap->getItems() as $answer)
341 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
343 $a_xml_writer->xmlStartTag(
"conditionvar");
345 "respident" =>
"gap_$i"
347 $a_xml_writer->xmlElement(
"varequal", $attrs, $answer->getAnswertext());
348 $a_xml_writer->xmlEndTag(
"conditionvar");
353 $a_xml_writer->xmlElement(
"setvar", $attrs, $answer->getPoints());
355 $linkrefid =
"$i" .
"_Response_" . $answer->getOrder();
357 "feedbacktype" =>
"Response",
358 "linkrefid" => $linkrefid
360 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
361 $a_xml_writer->xmlEndTag(
"respcondition");
367 $feedback_allcorrect = $this->
object->getFeedbackGeneric(1);
368 if (strlen($feedback_allcorrect))
373 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
375 $a_xml_writer->xmlStartTag(
"conditionvar");
377 for ($i = 0; $i < $this->
object->getGapCount(); $i++)
379 $gap = $this->
object->getGap($i);
380 $indexes = $gap->getBestSolutionIndexes();
383 $a_xml_writer->xmlStartTag(
"and");
385 switch ($gap->getType())
389 foreach ($indexes as $key)
393 $a_xml_writer->xmlStartTag(
"or");
396 "respident" =>
"gap_$i"
398 $answer = $gap->getItem($key);
399 $a_xml_writer->xmlElement(
"varequal", $attrs, $answer->getAnswertext());
402 $a_xml_writer->xmlEndTag(
"or");
409 foreach ($indexes as $key)
413 $a_xml_writer->xmlStartTag(
"or");
416 "respident" =>
"gap_$i"
418 $answer = $gap->getItem($key);
419 $a_xml_writer->xmlElement(
"varequal", $attrs, $answer->getAnswertext());
422 $a_xml_writer->xmlEndTag(
"or");
429 foreach ($indexes as $key)
433 $a_xml_writer->xmlStartTag(
"or");
436 "respident" =>
"gap_$i"
438 $answer = $gap->getItem($key);
439 $a_xml_writer->xmlElement(
"varequal", $attrs, $answer->getAnswertext());
442 $a_xml_writer->xmlEndTag(
"or");
450 $a_xml_writer->xmlEndTag(
"and");
453 $a_xml_writer->xmlEndTag(
"conditionvar");
456 "feedbacktype" =>
"Response",
457 "linkrefid" =>
"response_allcorrect"
459 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
460 $a_xml_writer->xmlEndTag(
"respcondition");
462 $feedback_onenotcorrect = $this->
object->getFeedbackGeneric(0);
463 if (strlen($feedback_onenotcorrect))
468 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
470 $a_xml_writer->xmlStartTag(
"conditionvar");
472 $a_xml_writer->xmlStartTag(
"not");
473 for ($i = 0; $i < $this->
object->getGapCount(); $i++)
475 $gap = $this->
object->getGap($i);
476 $indexes = $gap->getBestSolutionIndexes();
479 $a_xml_writer->xmlStartTag(
"and");
481 switch ($gap->getType())
485 foreach ($indexes as $key)
489 $a_xml_writer->xmlStartTag(
"or");
492 "respident" =>
"gap_$i"
494 $answer = $gap->getItem($key);
495 $a_xml_writer->xmlElement(
"varequal", $attrs, $answer->getAnswertext());
498 $a_xml_writer->xmlEndTag(
"or");
505 foreach ($indexes as $key)
509 $a_xml_writer->xmlStartTag(
"or");
512 "respident" =>
"gap_$i"
514 $answer = $gap->getItem($key);
515 $a_xml_writer->xmlElement(
"varequal", $attrs, $answer->getAnswertext());
518 $a_xml_writer->xmlEndTag(
"or");
525 foreach ($indexes as $key)
529 $a_xml_writer->xmlStartTag(
"or");
532 "respident" =>
"gap_$i"
534 $answer = $gap->getItem($key);
535 $a_xml_writer->xmlElement(
"varequal", $attrs, $answer->getAnswertext());
538 $a_xml_writer->xmlEndTag(
"or");
546 $a_xml_writer->xmlEndTag(
"and");
549 $a_xml_writer->xmlEndTag(
"not");
550 $a_xml_writer->xmlEndTag(
"conditionvar");
553 "feedbacktype" =>
"Response",
554 "linkrefid" =>
"response_onenotcorrect"
556 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
557 $a_xml_writer->xmlEndTag(
"respcondition");
560 $a_xml_writer->xmlEndTag(
"resprocessing");
563 for ($i = 0; $i < $this->
object->getGapCount(); $i++)
565 $gap = $this->
object->getGap($i);
566 switch ($gap->getType())
569 foreach ($gap->getItems() as $answer)
571 $linkrefid =
"$i" .
"_Response_" . $answer->getOrder();
573 "ident" => $linkrefid,
576 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
578 $a_xml_writer->xmlStartTag(
"flow_mat");
579 $a_xml_writer->xmlStartTag(
"material");
580 $a_xml_writer->xmlElement(
"mattext");
581 $a_xml_writer->xmlEndTag(
"material");
582 $a_xml_writer->xmlEndTag(
"flow_mat");
583 $a_xml_writer->xmlEndTag(
"itemfeedback");
587 foreach ($gap->getItems() as $answer)
589 $linkrefid =
"$i" .
"_Response_" . $answer->getOrder();
591 "ident" => $linkrefid,
594 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
596 $a_xml_writer->xmlStartTag(
"flow_mat");
597 $a_xml_writer->xmlStartTag(
"material");
598 $a_xml_writer->xmlElement(
"mattext");
599 $a_xml_writer->xmlEndTag(
"material");
600 $a_xml_writer->xmlEndTag(
"flow_mat");
601 $a_xml_writer->xmlEndTag(
"itemfeedback");
605 foreach ($gap->getItems() as $answer)
607 $linkrefid =
"$i" .
"_Response_" . $answer->getOrder();
609 "ident" => $linkrefid,
612 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
614 $a_xml_writer->xmlStartTag(
"flow_mat");
615 $a_xml_writer->xmlStartTag(
"material");
616 $a_xml_writer->xmlElement(
"mattext");
617 $a_xml_writer->xmlEndTag(
"material");
618 $a_xml_writer->xmlEndTag(
"flow_mat");
619 $a_xml_writer->xmlEndTag(
"itemfeedback");
625 if (strlen($feedback_allcorrect))
628 "ident" =>
"response_allcorrect",
631 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
633 $a_xml_writer->xmlStartTag(
"flow_mat");
634 $this->
object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
635 $a_xml_writer->xmlEndTag(
"flow_mat");
636 $a_xml_writer->xmlEndTag(
"itemfeedback");
638 if (strlen($feedback_onenotcorrect))
641 "ident" =>
"response_onenotcorrect",
644 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
646 $a_xml_writer->xmlStartTag(
"flow_mat");
647 $this->
object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
648 $a_xml_writer->xmlEndTag(
"flow_mat");
649 $a_xml_writer->xmlEndTag(
"itemfeedback");
652 $a_xml_writer->xmlEndTag(
"item");
653 $a_xml_writer->xmlEndTag(
"questestinterop");
655 $xml = $a_xml_writer->xmlDumpMem(FALSE);
656 if (!$a_include_header)
658 $pos = strpos($xml,
"?>");
659 $xml = substr($xml,
$pos + 2);