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->xmlEndTag(
"qtimetadata");
83 $a_xml_writer->xmlEndTag(
"itemmetadata");
87 "label" => $this->object->getTitle()
89 $a_xml_writer->xmlStartTag(
"presentation", $attrs);
91 $a_xml_writer->xmlStartTag(
"flow");
93 $this->
object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
97 "rcardinality" =>
"Single"
99 $a_xml_writer->xmlStartTag(
"response_xy", $attrs);
100 $solution = $this->
object->getSuggestedSolution(0);
101 if (count($solution))
103 if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $solution[
"internal_link"], $matches))
105 $a_xml_writer->xmlStartTag(
"material");
106 $intlink =
"il_" . IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
107 if (strcmp($matches[1],
"") != 0)
109 $intlink = $solution[
"internal_link"];
112 "label" =>
"suggested_solution"
114 $a_xml_writer->xmlElement(
"mattext", $attrs, $intlink);
115 $a_xml_writer->xmlEndTag(
"material");
118 $a_xml_writer->xmlStartTag(
"render_hotspot");
119 $a_xml_writer->xmlStartTag(
"material");
120 $imagetype =
"image/jpeg";
121 if (preg_match(
"/.*\.(png|gif)$/", $this->object->getImageFilename(), $matches))
123 $imagetype =
"image/" . $matches[1];
126 "imagtype" => $imagetype,
127 "label" => $this->object->getImageFilename()
129 if ($a_include_binary)
131 if ($force_image_references)
133 $attrs[
"uri"] = $this->
object->getImagePathWeb() . $this->
object->getImageFilename();
134 $a_xml_writer->xmlElement(
"matimage", $attrs);
138 $attrs[
"embedded"] =
"base64";
139 $imagepath = $this->
object->getImagePath() . $this->
object->getImageFilename();
140 $fh = fopen($imagepath,
"rb");
144 $ilErr->raiseError(
$GLOBALS[
'lng']->txt(
"error_open_image_file"), $ilErr->MESSAGE);
147 $imagefile = fread($fh, filesize($imagepath));
149 $base64 = base64_encode($imagefile);
150 $a_xml_writer->xmlElement(
"matimage", $attrs, $base64, FALSE, FALSE);
155 $a_xml_writer->xmlElement(
"matimage", $attrs);
157 $a_xml_writer->xmlEndTag(
"material");
160 foreach ($this->object->getAnswers() as $index => $answer)
163 switch ($answer->getArea())
166 $rarea =
"Rectangle";
179 $a_xml_writer->xmlStartTag(
"response_label", $attrs);
180 $a_xml_writer->xmlData($answer->getCoords());
181 $a_xml_writer->xmlStartTag(
"material");
182 $a_xml_writer->xmlElement(
"mattext", NULL, $answer->getAnswertext());
183 $a_xml_writer->xmlEndTag(
"material");
184 $a_xml_writer->xmlEndTag(
"response_label");
186 $a_xml_writer->xmlEndTag(
"render_hotspot");
187 $a_xml_writer->xmlEndTag(
"response_xy");
188 $a_xml_writer->xmlEndTag(
"flow");
189 $a_xml_writer->xmlEndTag(
"presentation");
192 $a_xml_writer->xmlStartTag(
"resprocessing");
193 $a_xml_writer->xmlStartTag(
"outcomes");
194 $a_xml_writer->xmlStartTag(
"decvar");
195 $a_xml_writer->xmlEndTag(
"decvar");
196 $a_xml_writer->xmlEndTag(
"outcomes");
198 foreach ($this->object->getAnswers() as $index => $answer)
203 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
205 $a_xml_writer->xmlStartTag(
"conditionvar");
206 if (!$answer->isStateSet())
208 $a_xml_writer->xmlStartTag(
"not");
211 switch ($answer->getArea())
214 $areatype =
"Rectangle";
217 $areatype =
"Ellipse";
220 $areatype =
"Bounded";
225 "areatype" => $areatype
227 $a_xml_writer->xmlElement(
"varinside", $attrs, $answer->getCoords());
228 if (!$answer->isStateSet())
230 $a_xml_writer->xmlEndTag(
"not");
232 $a_xml_writer->xmlEndTag(
"conditionvar");
237 $a_xml_writer->xmlElement(
"setvar", $attrs, $answer->getPoints());
238 $linkrefid =
"response_$index";
240 "feedbacktype" =>
"Response",
241 "linkrefid" => $linkrefid
243 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
244 $a_xml_writer->xmlEndTag(
"respcondition");
247 $answers = $this->
object->getAnswers();
248 $feedback_allcorrect = $this->
object->getFeedbackGeneric(1);
249 if (strlen($feedback_allcorrect))
254 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
256 $a_xml_writer->xmlStartTag(
"conditionvar");
259 foreach ($answers as $index => $answer)
261 if ($answer->getPoints() > $maxpoints)
263 $maxpoints = $answer->getPoints();
272 $answer = $answers[$bestindex];
273 switch ($answer->getArea())
276 $areatype =
"Rectangle";
279 $areatype =
"Ellipse";
282 $areatype =
"Bounded";
287 "areatype" => $areatype
289 $a_xml_writer->xmlElement(
"varinside", $attrs, $answer->getCoords());
291 $a_xml_writer->xmlEndTag(
"conditionvar");
294 "feedbacktype" =>
"Response",
295 "linkrefid" =>
"response_allcorrect"
297 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
298 $a_xml_writer->xmlEndTag(
"respcondition");
301 $feedback_onenotcorrect = $this->
object->getFeedbackGeneric(0);
302 if (strlen($feedback_onenotcorrect))
307 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
309 $a_xml_writer->xmlStartTag(
"conditionvar");
312 foreach ($answers as $index => $answer)
314 if ($answer->getPoints() > $maxpoints)
316 $maxpoints = $answer->getPoints();
323 $a_xml_writer->xmlStartTag(
"not");
326 $answer = $answers[$bestindex];
327 switch ($answer->getArea())
330 $areatype =
"Rectangle";
333 $areatype =
"Ellipse";
336 $areatype =
"Bounded";
341 "areatype" => $areatype
343 $a_xml_writer->xmlElement(
"varinside", $attrs, $answer->getCoords());
345 $a_xml_writer->xmlEndTag(
"not");
346 $a_xml_writer->xmlEndTag(
"conditionvar");
349 "feedbacktype" =>
"Response",
350 "linkrefid" =>
"response_onenotcorrect"
352 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
353 $a_xml_writer->xmlEndTag(
"respcondition");
356 $a_xml_writer->xmlEndTag(
"resprocessing");
359 foreach ($this->object->getAnswers() as $index => $answer)
362 $linkrefid =
"response_$index";
364 "ident" => $linkrefid,
367 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
369 $a_xml_writer->xmlStartTag(
"flow_mat");
370 $this->
object->addQTIMaterial($a_xml_writer, $this->object->getFeedbackSingleAnswer($index));
371 $a_xml_writer->xmlEndTag(
"flow_mat");
372 $a_xml_writer->xmlEndTag(
"itemfeedback");
374 if (strlen($feedback_allcorrect))
377 "ident" =>
"response_allcorrect",
380 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
382 $a_xml_writer->xmlStartTag(
"flow_mat");
383 $this->
object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
384 $a_xml_writer->xmlEndTag(
"flow_mat");
385 $a_xml_writer->xmlEndTag(
"itemfeedback");
387 if (strlen($feedback_onenotcorrect))
390 "ident" =>
"response_onenotcorrect",
393 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
395 $a_xml_writer->xmlStartTag(
"flow_mat");
396 $this->
object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
397 $a_xml_writer->xmlEndTag(
"flow_mat");
398 $a_xml_writer->xmlEndTag(
"itemfeedback");
401 $a_xml_writer->xmlEndTag(
"item");
402 $a_xml_writer->xmlEndTag(
"questestinterop");
404 $xml = $a_xml_writer->xmlDumpMem(FALSE);
405 if (!$a_include_header)
407 $pos = strpos($xml,
"?>");
408 $xml = substr($xml, $pos + 2);