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)
52 include_once(
"./Services/Xml/classes/class.ilXmlWriter.php");
56 $a_xml_writer->xmlStartTag(
"questestinterop");
58 "ident" =>
"il_".IL_INST_ID.
"_qst_".$this->object->getId(),
59 "title" => $this->
object->getTitle(),
60 "maxattempts" => $this->
object->getNrOfTries()
62 $a_xml_writer->xmlStartTag(
"item", $attrs);
64 $a_xml_writer->xmlElement(
"qticomment", NULL, $this->object->getComment());
66 $workingtime = $this->
object->getEstimatedWorkingTime();
67 $duration = sprintf(
"P0Y0M0DT%dH%dM%dS", $workingtime[
"h"], $workingtime[
"m"], $workingtime[
"s"]);
68 $a_xml_writer->xmlElement(
"duration", NULL, $duration);
70 $a_xml_writer->xmlStartTag(
"itemmetadata");
71 $a_xml_writer->xmlStartTag(
"qtimetadata");
72 $a_xml_writer->xmlStartTag(
"qtimetadatafield");
73 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"ILIAS_VERSION");
74 $a_xml_writer->xmlElement(
"fieldentry", NULL, $ilias->getSetting(
"ilias_version"));
75 $a_xml_writer->xmlEndTag(
"qtimetadatafield");
76 $a_xml_writer->xmlStartTag(
"qtimetadatafield");
77 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"QUESTIONTYPE");
79 $a_xml_writer->xmlEndTag(
"qtimetadatafield");
80 $a_xml_writer->xmlStartTag(
"qtimetadatafield");
81 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"AUTHOR");
82 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->object->getAuthor());
83 $a_xml_writer->xmlEndTag(
"qtimetadatafield");
84 $a_xml_writer->xmlStartTag(
"qtimetadatafield");
85 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"thumb_geometry");
86 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->object->getThumbGeometry());
87 $a_xml_writer->xmlEndTag(
"qtimetadatafield");
88 $a_xml_writer->xmlStartTag(
"qtimetadatafield");
89 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"element_height");
90 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->object->getElementHeight());
91 $a_xml_writer->xmlEndTag(
"qtimetadatafield");
92 $a_xml_writer->xmlStartTag(
"qtimetadatafield");
93 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"points");
94 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->object->getPoints());
95 $a_xml_writer->xmlEndTag(
"qtimetadatafield");
96 $a_xml_writer->xmlEndTag(
"qtimetadata");
97 $a_xml_writer->xmlEndTag(
"itemmetadata");
101 "label" => $this->object->getTitle()
103 $a_xml_writer->xmlStartTag(
"presentation", $attrs);
105 $a_xml_writer->xmlStartTag(
"flow");
107 $this->
object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
110 if ($this->object->getOrderingType() ==
OQ_PICTURES)
114 "rcardinality" =>
"Ordered"
121 "rcardinality" =>
"Ordered"
126 $attrs[
"output"] =
"javascript";
128 $a_xml_writer->xmlStartTag(
"response_lid", $attrs);
129 $solution = $this->
object->getSuggestedSolution(0);
130 if (count($solution))
132 if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $solution[
"internal_link"], $matches))
134 $a_xml_writer->xmlStartTag(
"material");
135 $intlink =
"il_" . IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
136 if (strcmp($matches[1],
"") != 0)
138 $intlink = $solution[
"internal_link"];
141 "label" =>
"suggested_solution"
143 $a_xml_writer->xmlElement(
"mattext", $attrs, $intlink);
144 $a_xml_writer->xmlEndTag(
"material");
149 if ($this->object->getShuffle())
161 $a_xml_writer->xmlStartTag(
"render_choice", $attrs);
163 $akeys = array_keys($this->object->getAnswers());
164 if ($this->object->getShuffle() && $a_shuffle)
166 $akeys = $this->
object->pcArrayShuffle($akeys);
170 foreach ($akeys as $index)
172 $answer = $this->
object->getAnswer($index);
176 $a_xml_writer->xmlStartTag(
"response_label", $attrs);
177 if ($this->object->getOrderingType() ==
OQ_PICTURES)
179 $a_xml_writer->xmlStartTag(
"material");
180 if ($force_image_references)
183 "imagtype" => $imagetype,
184 "label" => $answer->getAnswertext(),
185 "uri" => $this->
object->getImagePathWeb() . $answer->getAnswertext()
187 $a_xml_writer->xmlElement(
"matimage", $attrs);
191 $imagepath = $this->
object->getImagePath() . $answer->getAnswertext();
192 $fh = @fopen($imagepath,
"rb");
195 $imagefile = fread($fh, filesize($imagepath));
197 $base64 = base64_encode($imagefile);
198 $imagetype =
"image/jpeg";
199 if (preg_match(
"/.*\.(png|gif)$/", $answer->getAnswertext(), $matches))
201 $imagetype =
"image/".$matches[1];
204 "imagtype" => $imagetype,
205 "label" => $answer->getAnswertext(),
206 "embedded" =>
"base64"
208 $a_xml_writer->xmlElement(
"matimage", $attrs, $base64, FALSE, FALSE);
211 $a_xml_writer->xmlEndTag(
"material");
215 $a_xml_writer->xmlStartTag(
"material");
216 $this->
object->addQTIMaterial($a_xml_writer, $answer->getAnswertext(), TRUE, FALSE);
217 $a_xml_writer->xmlEndTag(
"material");
219 $a_xml_writer->xmlEndTag(
"response_label");
221 $a_xml_writer->xmlEndTag(
"render_choice");
222 $a_xml_writer->xmlEndTag(
"response_lid");
223 $a_xml_writer->xmlEndTag(
"flow");
224 $a_xml_writer->xmlEndTag(
"presentation");
227 $a_xml_writer->xmlStartTag(
"resprocessing");
228 $a_xml_writer->xmlStartTag(
"outcomes");
229 $a_xml_writer->xmlStartTag(
"decvar");
230 $a_xml_writer->xmlEndTag(
"decvar");
231 $a_xml_writer->xmlEndTag(
"outcomes");
233 foreach ($this->object->getAnswers() as $index => $answer)
238 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
240 $a_xml_writer->xmlStartTag(
"conditionvar");
242 if ($this->object->getOrderingType() ==
OQ_PICTURES)
254 $attrs[
"index"] = $index;
255 $a_xml_writer->xmlElement(
"varequal", $attrs, $index);
256 $a_xml_writer->xmlEndTag(
"conditionvar");
261 $a_xml_writer->xmlElement(
"setvar", $attrs, $this->object->getPoints() / count($this->object->getAnswers()));
264 "feedbacktype" =>
"Response",
265 "linkrefid" =>
"link_$index"
267 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
268 $a_xml_writer->xmlEndTag(
"respcondition");
271 $feedback_allcorrect = $this->
object->getFeedbackGeneric(1);
272 if (strlen($feedback_allcorrect))
277 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
279 $a_xml_writer->xmlStartTag(
"conditionvar");
281 foreach ($this->object->getAnswers() as $index => $answer)
284 if ($this->object->getOrderingType() ==
OQ_PICTURES)
296 $attrs[
"index"] = $index;
297 $a_xml_writer->xmlElement(
"varequal", $attrs, $index);
300 $a_xml_writer->xmlEndTag(
"conditionvar");
303 "feedbacktype" =>
"Response",
304 "linkrefid" =>
"response_allcorrect"
306 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
307 $a_xml_writer->xmlEndTag(
"respcondition");
310 $feedback_onenotcorrect = $this->
object->getFeedbackGeneric(0);
311 if (strlen($feedback_onenotcorrect))
316 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
318 $a_xml_writer->xmlStartTag(
"conditionvar");
319 $a_xml_writer->xmlStartTag(
"not");
321 foreach ($this->object->getAnswers() as $index => $answer)
324 if ($this->object->getOrderingType() ==
OQ_PICTURES)
336 $attrs[
"index"] = $index;
337 $a_xml_writer->xmlElement(
"varequal", $attrs, $index);
340 $a_xml_writer->xmlEndTag(
"not");
341 $a_xml_writer->xmlEndTag(
"conditionvar");
344 "feedbacktype" =>
"Response",
345 "linkrefid" =>
"response_onenotcorrect"
347 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
348 $a_xml_writer->xmlEndTag(
"respcondition");
351 $a_xml_writer->xmlEndTag(
"resprocessing");
354 foreach ($this->object->getAnswers() as $index => $answer)
357 "ident" =>
"link_$index",
360 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
362 $a_xml_writer->xmlStartTag(
"flow_mat");
363 $a_xml_writer->xmlStartTag(
"material");
364 $a_xml_writer->xmlElement(
"mattext");
365 $a_xml_writer->xmlEndTag(
"material");
366 $a_xml_writer->xmlEndTag(
"flow_mat");
367 $a_xml_writer->xmlEndTag(
"itemfeedback");
370 if (strlen($feedback_allcorrect))
373 "ident" =>
"response_allcorrect",
376 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
378 $a_xml_writer->xmlStartTag(
"flow_mat");
379 $this->
object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
380 $a_xml_writer->xmlEndTag(
"flow_mat");
381 $a_xml_writer->xmlEndTag(
"itemfeedback");
383 if (strlen($feedback_onenotcorrect))
386 "ident" =>
"response_onenotcorrect",
389 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
391 $a_xml_writer->xmlStartTag(
"flow_mat");
392 $this->
object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
393 $a_xml_writer->xmlEndTag(
"flow_mat");
394 $a_xml_writer->xmlEndTag(
"itemfeedback");
397 $a_xml_writer->xmlEndTag(
"item");
398 $a_xml_writer->xmlEndTag(
"questestinterop");
400 $xml = $a_xml_writer->xmlDumpMem(FALSE);
401 if (!$a_include_header)
403 $pos = strpos($xml,
"?>");
404 $xml = substr($xml, $pos + 2);