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/Xml/classes/class.ilXmlWriter.php");
54 $a_xml_writer->xmlStartTag(
"questestinterop");
56 "ident" =>
"il_".IL_INST_ID.
"_qst_".$this->object->getId(),
57 "title" => $this->
object->getTitle(),
58 "maxattempts" => $this->
object->getNrOfTries()
60 $a_xml_writer->xmlStartTag(
"item", $attrs);
62 $a_xml_writer->xmlElement(
"qticomment", NULL, $this->object->getComment());
64 $workingtime = $this->
object->getEstimatedWorkingTime();
65 $duration = sprintf(
"P0Y0M0DT%dH%dM%dS", $workingtime[
"h"], $workingtime[
"m"], $workingtime[
"s"]);
66 $a_xml_writer->xmlElement(
"duration", NULL, $duration);
68 $a_xml_writer->xmlStartTag(
"itemmetadata");
69 $a_xml_writer->xmlStartTag(
"qtimetadata");
70 $a_xml_writer->xmlStartTag(
"qtimetadatafield");
71 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"ILIAS_VERSION");
72 $a_xml_writer->xmlElement(
"fieldentry", NULL, $ilias->getSetting(
"ilias_version"));
73 $a_xml_writer->xmlEndTag(
"qtimetadatafield");
74 $a_xml_writer->xmlStartTag(
"qtimetadatafield");
75 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"QUESTIONTYPE");
77 $a_xml_writer->xmlEndTag(
"qtimetadatafield");
78 $a_xml_writer->xmlStartTag(
"qtimetadatafield");
79 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"AUTHOR");
80 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->object->getAuthor());
81 $a_xml_writer->xmlEndTag(
"qtimetadatafield");
82 $a_xml_writer->xmlStartTag(
"qtimetadatafield");
83 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"externalID");
84 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->object->getExternalID());
85 $a_xml_writer->xmlEndTag(
"qtimetadatafield");
86 $a_xml_writer->xmlEndTag(
"qtimetadata");
87 $a_xml_writer->xmlEndTag(
"itemmetadata");
91 "label" => $this->object->getTitle()
93 $a_xml_writer->xmlStartTag(
"presentation", $attrs);
95 $a_xml_writer->xmlStartTag(
"flow");
97 $this->
object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
101 "rcardinality" =>
"Single"
103 $a_xml_writer->xmlStartTag(
"response_xy", $attrs);
104 $solution = $this->
object->getSuggestedSolution(0);
105 if (count($solution))
107 if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $solution[
"internal_link"], $matches))
109 $a_xml_writer->xmlStartTag(
"material");
110 $intlink =
"il_" . IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
111 if (strcmp($matches[1],
"") != 0)
113 $intlink = $solution[
"internal_link"];
116 "label" =>
"suggested_solution"
118 $a_xml_writer->xmlElement(
"mattext", $attrs, $intlink);
119 $a_xml_writer->xmlEndTag(
"material");
122 $a_xml_writer->xmlStartTag(
"render_hotspot");
123 $a_xml_writer->xmlStartTag(
"material");
124 $imagetype =
"image/jpeg";
125 if (preg_match(
"/.*\.(png|gif)$/", $this->object->getImageFilename(), $matches))
127 $imagetype =
"image/" . $matches[1];
130 "imagtype" => $imagetype,
131 "label" => $this->object->getImageFilename()
133 if ($a_include_binary)
135 if ($force_image_references)
137 $attrs[
"uri"] = $this->
object->getImagePathWeb() . $this->
object->getImageFilename();
138 $a_xml_writer->xmlElement(
"matimage", $attrs);
142 $attrs[
"embedded"] =
"base64";
143 $imagepath = $this->
object->getImagePath() . $this->
object->getImageFilename();
144 $fh = fopen($imagepath,
"rb");
148 $ilErr->raiseError($this->object->lng->txt(
"error_open_image_file"), $ilErr->MESSAGE);
151 $imagefile = fread($fh, filesize($imagepath));
153 $base64 = base64_encode($imagefile);
154 $a_xml_writer->xmlElement(
"matimage", $attrs, $base64, FALSE, FALSE);
159 $a_xml_writer->xmlElement(
"matimage", $attrs);
161 $a_xml_writer->xmlEndTag(
"material");
164 foreach ($this->object->getAnswers() as $index => $answer)
167 switch ($answer->getArea())
170 $rarea =
"Rectangle";
183 $a_xml_writer->xmlStartTag(
"response_label", $attrs);
184 $a_xml_writer->xmlData($answer->getCoords());
185 $a_xml_writer->xmlStartTag(
"material");
186 $a_xml_writer->xmlElement(
"mattext", NULL, $answer->getAnswertext());
187 $a_xml_writer->xmlEndTag(
"material");
188 $a_xml_writer->xmlEndTag(
"response_label");
190 $a_xml_writer->xmlEndTag(
"render_hotspot");
191 $a_xml_writer->xmlEndTag(
"response_xy");
192 $a_xml_writer->xmlEndTag(
"flow");
193 $a_xml_writer->xmlEndTag(
"presentation");
196 $a_xml_writer->xmlStartTag(
"resprocessing");
197 $a_xml_writer->xmlStartTag(
"outcomes");
198 $a_xml_writer->xmlStartTag(
"decvar");
199 $a_xml_writer->xmlEndTag(
"decvar");
200 $a_xml_writer->xmlEndTag(
"outcomes");
202 foreach ($this->object->getAnswers() as $index => $answer)
207 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
209 $a_xml_writer->xmlStartTag(
"conditionvar");
210 if (!$answer->isStateSet())
212 $a_xml_writer->xmlStartTag(
"not");
215 switch ($answer->getArea())
218 $areatype =
"Rectangle";
221 $areatype =
"Ellipse";
224 $areatype =
"Bounded";
229 "areatype" => $areatype
231 $a_xml_writer->xmlElement(
"varinside", $attrs, $answer->getCoords());
232 if (!$answer->isStateSet())
234 $a_xml_writer->xmlEndTag(
"not");
236 $a_xml_writer->xmlEndTag(
"conditionvar");
241 $a_xml_writer->xmlElement(
"setvar", $attrs, $answer->getPoints());
242 $linkrefid =
"response_$index";
244 "feedbacktype" =>
"Response",
245 "linkrefid" => $linkrefid
247 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
248 $a_xml_writer->xmlEndTag(
"respcondition");
251 $answers = $this->
object->getAnswers();
252 $feedback_allcorrect = $this->
object->getFeedbackGeneric(1);
253 if (strlen($feedback_allcorrect))
258 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
260 $a_xml_writer->xmlStartTag(
"conditionvar");
263 foreach ($answers as $index => $answer)
265 if ($answer->getPoints() > $maxpoints)
267 $maxpoints = $answer->getPoints();
276 $answer = $answers[$bestindex];
277 switch ($answer->getArea())
280 $areatype =
"Rectangle";
283 $areatype =
"Ellipse";
286 $areatype =
"Bounded";
291 "areatype" => $areatype
293 $a_xml_writer->xmlElement(
"varinside", $attrs, $answer->getCoords());
295 $a_xml_writer->xmlEndTag(
"conditionvar");
298 "feedbacktype" =>
"Response",
299 "linkrefid" =>
"response_allcorrect"
301 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
302 $a_xml_writer->xmlEndTag(
"respcondition");
305 $feedback_onenotcorrect = $this->
object->getFeedbackGeneric(0);
306 if (strlen($feedback_onenotcorrect))
311 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
313 $a_xml_writer->xmlStartTag(
"conditionvar");
316 foreach ($answers as $index => $answer)
318 if ($answer->getPoints() > $maxpoints)
320 $maxpoints = $answer->getPoints();
327 $a_xml_writer->xmlStartTag(
"not");
330 $answer = $answers[$bestindex];
331 switch ($answer->getArea())
334 $areatype =
"Rectangle";
337 $areatype =
"Ellipse";
340 $areatype =
"Bounded";
345 "areatype" => $areatype
347 $a_xml_writer->xmlElement(
"varinside", $attrs, $answer->getCoords());
349 $a_xml_writer->xmlEndTag(
"not");
350 $a_xml_writer->xmlEndTag(
"conditionvar");
353 "feedbacktype" =>
"Response",
354 "linkrefid" =>
"response_onenotcorrect"
356 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
357 $a_xml_writer->xmlEndTag(
"respcondition");
360 $a_xml_writer->xmlEndTag(
"resprocessing");
363 foreach ($this->object->getAnswers() as $index => $answer)
366 $linkrefid =
"response_$index";
368 "ident" => $linkrefid,
371 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
373 $a_xml_writer->xmlStartTag(
"flow_mat");
374 $this->
object->addQTIMaterial($a_xml_writer, $this->object->getFeedbackSingleAnswer($index));
375 $a_xml_writer->xmlEndTag(
"flow_mat");
376 $a_xml_writer->xmlEndTag(
"itemfeedback");
378 if (strlen($feedback_allcorrect))
381 "ident" =>
"response_allcorrect",
384 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
386 $a_xml_writer->xmlStartTag(
"flow_mat");
387 $this->
object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
388 $a_xml_writer->xmlEndTag(
"flow_mat");
389 $a_xml_writer->xmlEndTag(
"itemfeedback");
391 if (strlen($feedback_onenotcorrect))
394 "ident" =>
"response_onenotcorrect",
397 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
399 $a_xml_writer->xmlStartTag(
"flow_mat");
400 $this->
object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
401 $a_xml_writer->xmlEndTag(
"flow_mat");
402 $a_xml_writer->xmlEndTag(
"itemfeedback");
405 $a_xml_writer->xmlEndTag(
"item");
406 $a_xml_writer->xmlEndTag(
"questestinterop");
408 $xml = $a_xml_writer->xmlDumpMem(FALSE);
409 if (!$a_include_header)
411 $pos = strpos($xml,
"?>");
412 $xml = substr($xml,
$pos + 2);