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->xmlEndTag(
"qtimetadata");
98 $a_xml_writer->xmlEndTag(
"itemmetadata");
102 "label" => $this->object->getTitle()
104 $a_xml_writer->xmlStartTag(
"presentation", $attrs);
106 $a_xml_writer->xmlStartTag(
"flow");
107 $text_parts = preg_split(
"/\[gap.*?\[\/gap\]/", $this->object->getClozeText());
109 for ($i = 0; $i <= $this->
object->getGapCount(); $i++)
114 $this->
object->addQTIMaterial($a_xml_writer, $text_parts[$i]);
118 $this->
object->addQTIMaterial($a_xml_writer, $text_parts[$i], TRUE, FALSE);
121 if ($i < $this->object->getGapCount())
124 $gap = $this->
object->getGap($i);
125 switch ($gap->getType())
131 "rcardinality" =>
"Single"
133 $a_xml_writer->xmlStartTag(
"response_str", $attrs);
134 $solution = $this->
object->getSuggestedSolution($i);
135 if (count($solution))
137 if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $solution[
"internal_link"], $matches))
140 "label" =>
"suggested_solution"
142 $a_xml_writer->xmlStartTag(
"material", $attrs);
143 $intlink =
"il_" . IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
144 if (strcmp($matches[1],
"") != 0)
146 $intlink = $solution[
"internal_link"];
148 $a_xml_writer->xmlElement(
"mattext", NULL, $intlink);
149 $a_xml_writer->xmlEndTag(
"material");
153 $attrs = array(
"shuffle" => ($gap->getShuffle() ?
"Yes" :
"No"));
154 $a_xml_writer->xmlStartTag(
"render_choice", $attrs);
157 foreach ($gap->getItems() as $answeritem)
160 "ident" => $answeritem->getOrder()
162 $a_xml_writer->xmlStartTag(
"response_label", $attrs);
163 $a_xml_writer->xmlStartTag(
"material");
164 $a_xml_writer->xmlElement(
"mattext", NULL, $answeritem->getAnswertext());
165 $a_xml_writer->xmlEndTag(
"material");
166 $a_xml_writer->xmlEndTag(
"response_label");
168 $a_xml_writer->xmlEndTag(
"render_choice");
169 $a_xml_writer->xmlEndTag(
"response_str");
175 "rcardinality" =>
"Single"
177 $a_xml_writer->xmlStartTag(
"response_str", $attrs);
178 $solution = $this->
object->getSuggestedSolution($i);
179 if (count($solution))
181 if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $solution[
"internal_link"], $matches))
184 "label" =>
"suggested_solution"
186 $a_xml_writer->xmlStartTag(
"material", $attrs);
187 $intlink =
"il_" . IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
188 if (strcmp($matches[1],
"") != 0)
190 $intlink = $solution[
"internal_link"];
192 $a_xml_writer->xmlElement(
"mattext", NULL, $intlink);
193 $a_xml_writer->xmlEndTag(
"material");
197 "fibtype" =>
"String",
199 "columns" => $gap->getMaxWidth()
201 $a_xml_writer->xmlStartTag(
"render_fib", $attrs);
202 $a_xml_writer->xmlEndTag(
"render_fib");
203 $a_xml_writer->xmlEndTag(
"response_str");
209 "numtype" =>
"Decimal",
210 "rcardinality" =>
"Single"
212 $a_xml_writer->xmlStartTag(
"response_num", $attrs);
213 $solution = $this->
object->getSuggestedSolution($i);
214 if (count($solution))
216 if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $solution[
"internal_link"], $matches))
219 "label" =>
"suggested_solution"
221 $a_xml_writer->xmlStartTag(
"material", $attrs);
222 $intlink =
"il_" . IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
223 if (strcmp($matches[1],
"") != 0)
225 $intlink = $solution[
"internal_link"];
227 $a_xml_writer->xmlElement(
"mattext", NULL, $intlink);
228 $a_xml_writer->xmlEndTag(
"material");
231 $answeritem = $gap->getItem(0);
233 "fibtype" =>
"Decimal",
235 "columns" => $gap->getMaxWidth()
237 if (is_object($answeritem))
239 if ($eval->e($answeritem->getLowerBound()) !== FALSE)
241 $attrs[
"minnumber"] = $answeritem->getLowerBound();
243 if ($eval->e($answeritem->getUpperBound()) !== FALSE)
245 $attrs[
"maxnumber"] = $answeritem->getUpperBound();
248 $a_xml_writer->xmlStartTag(
"render_fib", $attrs);
249 $a_xml_writer->xmlEndTag(
"render_fib");
250 $a_xml_writer->xmlEndTag(
"response_num");
255 $a_xml_writer->xmlEndTag(
"flow");
256 $a_xml_writer->xmlEndTag(
"presentation");
259 $a_xml_writer->xmlStartTag(
"resprocessing");
260 $a_xml_writer->xmlStartTag(
"outcomes");
261 $a_xml_writer->xmlStartTag(
"decvar");
262 $a_xml_writer->xmlEndTag(
"decvar");
263 $a_xml_writer->xmlEndTag(
"outcomes");
266 for ($i = 0; $i < $this->
object->getGapCount(); $i++)
268 $gap = $this->
object->getGap($i);
269 switch ($gap->getType())
272 foreach ($gap->getItems() as $answer)
277 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
279 $a_xml_writer->xmlStartTag(
"conditionvar");
282 "respident" =>
"gap_$i"
284 $a_xml_writer->xmlElement(
"varequal", $attrs, $answer->getAnswertext());
285 $a_xml_writer->xmlEndTag(
"conditionvar");
290 $a_xml_writer->xmlElement(
"setvar", $attrs, $answer->getPoints());
293 $linkrefid =
"$i" .
"_Response_" . $answer->getOrder();
295 "feedbacktype" =>
"Response",
296 "linkrefid" => $linkrefid
298 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
299 $a_xml_writer->xmlEndTag(
"respcondition");
303 foreach ($gap->getItems() as $answer)
308 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
310 $a_xml_writer->xmlStartTag(
"conditionvar");
312 "respident" =>
"gap_$i"
314 $a_xml_writer->xmlElement(
"varequal", $attrs, $answer->getAnswertext());
315 $a_xml_writer->xmlEndTag(
"conditionvar");
320 $a_xml_writer->xmlElement(
"setvar", $attrs, $answer->getPoints());
322 $linkrefid =
"$i" .
"_Response_" . $answer->getOrder();
324 "feedbacktype" =>
"Response",
325 "linkrefid" => $linkrefid
327 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
328 $a_xml_writer->xmlEndTag(
"respcondition");
332 foreach ($gap->getItems() as $answer)
337 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
339 $a_xml_writer->xmlStartTag(
"conditionvar");
341 "respident" =>
"gap_$i"
343 $a_xml_writer->xmlElement(
"varequal", $attrs, $answer->getAnswertext());
344 $a_xml_writer->xmlEndTag(
"conditionvar");
349 $a_xml_writer->xmlElement(
"setvar", $attrs, $answer->getPoints());
351 $linkrefid =
"$i" .
"_Response_" . $answer->getOrder();
353 "feedbacktype" =>
"Response",
354 "linkrefid" => $linkrefid
356 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
357 $a_xml_writer->xmlEndTag(
"respcondition");
363 $feedback_allcorrect = $this->
object->getFeedbackGeneric(1);
364 if (strlen($feedback_allcorrect))
369 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
371 $a_xml_writer->xmlStartTag(
"conditionvar");
373 for ($i = 0; $i < $this->
object->getGapCount(); $i++)
375 $gap = $this->
object->getGap($i);
376 $indexes = $gap->getBestSolutionIndexes();
379 $a_xml_writer->xmlStartTag(
"and");
381 switch ($gap->getType())
385 foreach ($indexes as $key)
389 $a_xml_writer->xmlStartTag(
"or");
392 "respident" =>
"gap_$i"
394 $answer = $gap->getItem($key);
395 $a_xml_writer->xmlElement(
"varequal", $attrs, $answer->getAnswertext());
398 $a_xml_writer->xmlEndTag(
"or");
405 foreach ($indexes as $key)
409 $a_xml_writer->xmlStartTag(
"or");
412 "respident" =>
"gap_$i"
414 $answer = $gap->getItem($key);
415 $a_xml_writer->xmlElement(
"varequal", $attrs, $answer->getAnswertext());
418 $a_xml_writer->xmlEndTag(
"or");
425 foreach ($indexes as $key)
429 $a_xml_writer->xmlStartTag(
"or");
432 "respident" =>
"gap_$i"
434 $answer = $gap->getItem($key);
435 $a_xml_writer->xmlElement(
"varequal", $attrs, $answer->getAnswertext());
438 $a_xml_writer->xmlEndTag(
"or");
446 $a_xml_writer->xmlEndTag(
"and");
449 $a_xml_writer->xmlEndTag(
"conditionvar");
452 "feedbacktype" =>
"Response",
453 "linkrefid" =>
"response_allcorrect"
455 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
456 $a_xml_writer->xmlEndTag(
"respcondition");
458 $feedback_onenotcorrect = $this->
object->getFeedbackGeneric(0);
459 if (strlen($feedback_onenotcorrect))
464 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
466 $a_xml_writer->xmlStartTag(
"conditionvar");
468 $a_xml_writer->xmlStartTag(
"not");
469 for ($i = 0; $i < $this->
object->getGapCount(); $i++)
471 $gap = $this->
object->getGap($i);
472 $indexes = $gap->getBestSolutionIndexes();
475 $a_xml_writer->xmlStartTag(
"and");
477 switch ($gap->getType())
481 foreach ($indexes as $key)
485 $a_xml_writer->xmlStartTag(
"or");
488 "respident" =>
"gap_$i"
490 $answer = $gap->getItem($key);
491 $a_xml_writer->xmlElement(
"varequal", $attrs, $answer->getAnswertext());
494 $a_xml_writer->xmlEndTag(
"or");
501 foreach ($indexes as $key)
505 $a_xml_writer->xmlStartTag(
"or");
508 "respident" =>
"gap_$i"
510 $answer = $gap->getItem($key);
511 $a_xml_writer->xmlElement(
"varequal", $attrs, $answer->getAnswertext());
514 $a_xml_writer->xmlEndTag(
"or");
521 foreach ($indexes as $key)
525 $a_xml_writer->xmlStartTag(
"or");
528 "respident" =>
"gap_$i"
530 $answer = $gap->getItem($key);
531 $a_xml_writer->xmlElement(
"varequal", $attrs, $answer->getAnswertext());
534 $a_xml_writer->xmlEndTag(
"or");
542 $a_xml_writer->xmlEndTag(
"and");
545 $a_xml_writer->xmlEndTag(
"not");
546 $a_xml_writer->xmlEndTag(
"conditionvar");
549 "feedbacktype" =>
"Response",
550 "linkrefid" =>
"response_onenotcorrect"
552 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
553 $a_xml_writer->xmlEndTag(
"respcondition");
556 $a_xml_writer->xmlEndTag(
"resprocessing");
559 for ($i = 0; $i < $this->
object->getGapCount(); $i++)
561 $gap = $this->
object->getGap($i);
562 switch ($gap->getType())
565 foreach ($gap->getItems() as $answer)
567 $linkrefid =
"$i" .
"_Response_" . $answer->getOrder();
569 "ident" => $linkrefid,
572 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
574 $a_xml_writer->xmlStartTag(
"flow_mat");
575 $a_xml_writer->xmlStartTag(
"material");
576 $a_xml_writer->xmlElement(
"mattext");
577 $a_xml_writer->xmlEndTag(
"material");
578 $a_xml_writer->xmlEndTag(
"flow_mat");
579 $a_xml_writer->xmlEndTag(
"itemfeedback");
583 foreach ($gap->getItems() as $answer)
585 $linkrefid =
"$i" .
"_Response_" . $answer->getOrder();
587 "ident" => $linkrefid,
590 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
592 $a_xml_writer->xmlStartTag(
"flow_mat");
593 $a_xml_writer->xmlStartTag(
"material");
594 $a_xml_writer->xmlElement(
"mattext");
595 $a_xml_writer->xmlEndTag(
"material");
596 $a_xml_writer->xmlEndTag(
"flow_mat");
597 $a_xml_writer->xmlEndTag(
"itemfeedback");
601 foreach ($gap->getItems() as $answer)
603 $linkrefid =
"$i" .
"_Response_" . $answer->getOrder();
605 "ident" => $linkrefid,
608 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
610 $a_xml_writer->xmlStartTag(
"flow_mat");
611 $a_xml_writer->xmlStartTag(
"material");
612 $a_xml_writer->xmlElement(
"mattext");
613 $a_xml_writer->xmlEndTag(
"material");
614 $a_xml_writer->xmlEndTag(
"flow_mat");
615 $a_xml_writer->xmlEndTag(
"itemfeedback");
621 if (strlen($feedback_allcorrect))
624 "ident" =>
"response_allcorrect",
627 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
629 $a_xml_writer->xmlStartTag(
"flow_mat");
630 $this->
object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
631 $a_xml_writer->xmlEndTag(
"flow_mat");
632 $a_xml_writer->xmlEndTag(
"itemfeedback");
634 if (strlen($feedback_onenotcorrect))
637 "ident" =>
"response_onenotcorrect",
640 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
642 $a_xml_writer->xmlStartTag(
"flow_mat");
643 $this->
object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
644 $a_xml_writer->xmlEndTag(
"flow_mat");
645 $a_xml_writer->xmlEndTag(
"itemfeedback");
648 $a_xml_writer->xmlEndTag(
"item");
649 $a_xml_writer->xmlEndTag(
"questestinterop");
651 $xml = $a_xml_writer->xmlDumpMem(FALSE);
652 if (!$a_include_header)
654 $pos = strpos($xml,
"?>");
655 $xml = substr($xml, $pos + 2);