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,
"externalID");
86 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->object->getExternalID());
87 $a_xml_writer->xmlEndTag(
"qtimetadatafield");
88 $a_xml_writer->xmlStartTag(
"qtimetadatafield");
89 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"thumb_geometry");
90 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->object->getThumbGeometry());
91 $a_xml_writer->xmlEndTag(
"qtimetadatafield");
92 $a_xml_writer->xmlStartTag(
"qtimetadatafield");
93 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"element_height");
94 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->object->getElementHeight());
95 $a_xml_writer->xmlEndTag(
"qtimetadatafield");
96 $a_xml_writer->xmlStartTag(
"qtimetadatafield");
97 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"points");
98 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->object->getPoints());
99 $a_xml_writer->xmlEndTag(
"qtimetadatafield");
100 $a_xml_writer->xmlEndTag(
"qtimetadata");
101 $a_xml_writer->xmlEndTag(
"itemmetadata");
105 "label" => $this->object->getTitle()
107 $a_xml_writer->xmlStartTag(
"presentation", $attrs);
109 $a_xml_writer->xmlStartTag(
"flow");
111 $this->
object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
114 if ($this->object->getOrderingType() ==
OQ_PICTURES)
118 "rcardinality" =>
"Ordered"
125 "rcardinality" =>
"Ordered"
130 $attrs[
"output"] =
"javascript";
132 $a_xml_writer->xmlStartTag(
"response_lid", $attrs);
133 $solution = $this->
object->getSuggestedSolution(0);
134 if (count($solution))
136 if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $solution[
"internal_link"], $matches))
138 $a_xml_writer->xmlStartTag(
"material");
139 $intlink =
"il_" . IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
140 if (strcmp($matches[1],
"") != 0)
142 $intlink = $solution[
"internal_link"];
145 "label" =>
"suggested_solution"
147 $a_xml_writer->xmlElement(
"mattext", $attrs, $intlink);
148 $a_xml_writer->xmlEndTag(
"material");
153 if ($this->object->getShuffle())
165 $a_xml_writer->xmlStartTag(
"render_choice", $attrs);
167 $akeys = array_keys($this->object->getAnswers());
168 if ($this->object->getShuffle() && $a_shuffle)
170 $akeys = $this->
object->pcArrayShuffle($akeys);
174 foreach ($akeys as $index)
176 $answer = $this->
object->getAnswer($index);
180 $a_xml_writer->xmlStartTag(
"response_label", $attrs);
181 if ($this->object->getOrderingType() ==
OQ_PICTURES)
183 $a_xml_writer->xmlStartTag(
"material");
184 if ($force_image_references)
187 "imagtype" => $imagetype,
188 "label" => $answer->getAnswertext(),
189 "uri" => $this->
object->getImagePathWeb() . $answer->getAnswertext()
191 $a_xml_writer->xmlElement(
"matimage", $attrs);
195 $imagepath = $this->
object->getImagePath() . $answer->getAnswertext();
196 $fh = @fopen($imagepath,
"rb");
199 $imagefile = fread($fh, filesize($imagepath));
201 $base64 = base64_encode($imagefile);
202 $imagetype =
"image/jpeg";
203 if (preg_match(
"/.*\.(png|gif)$/", $answer->getAnswertext(), $matches))
205 $imagetype =
"image/".$matches[1];
208 "imagtype" => $imagetype,
209 "label" => $answer->getAnswertext(),
210 "embedded" =>
"base64"
212 $a_xml_writer->xmlElement(
"matimage", $attrs, $base64, FALSE, FALSE);
215 $a_xml_writer->xmlEndTag(
"material");
219 $a_xml_writer->xmlStartTag(
"material");
220 $this->
object->addQTIMaterial($a_xml_writer, $answer->getAnswertext(), TRUE, FALSE);
221 $a_xml_writer->xmlEndTag(
"material");
223 $a_xml_writer->xmlEndTag(
"response_label");
225 $a_xml_writer->xmlEndTag(
"render_choice");
226 $a_xml_writer->xmlEndTag(
"response_lid");
227 $a_xml_writer->xmlEndTag(
"flow");
228 $a_xml_writer->xmlEndTag(
"presentation");
231 $a_xml_writer->xmlStartTag(
"resprocessing");
232 $a_xml_writer->xmlStartTag(
"outcomes");
233 $a_xml_writer->xmlStartTag(
"decvar");
234 $a_xml_writer->xmlEndTag(
"decvar");
235 $a_xml_writer->xmlEndTag(
"outcomes");
237 foreach ($this->object->getAnswers() as $index => $answer)
242 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
244 $a_xml_writer->xmlStartTag(
"conditionvar");
246 if ($this->object->getOrderingType() ==
OQ_PICTURES)
258 $attrs[
"index"] = $index;
259 $a_xml_writer->xmlElement(
"varequal", $attrs, $index);
260 $a_xml_writer->xmlEndTag(
"conditionvar");
265 $a_xml_writer->xmlElement(
"setvar", $attrs, $this->object->getPoints() / count($this->object->getAnswers()));
268 "feedbacktype" =>
"Response",
269 "linkrefid" =>
"link_$index"
271 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
272 $a_xml_writer->xmlEndTag(
"respcondition");
275 $feedback_allcorrect = $this->
object->getFeedbackGeneric(1);
276 if (strlen($feedback_allcorrect))
281 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
283 $a_xml_writer->xmlStartTag(
"conditionvar");
285 foreach ($this->object->getAnswers() as $index => $answer)
288 if ($this->object->getOrderingType() ==
OQ_PICTURES)
300 $attrs[
"index"] = $index;
301 $a_xml_writer->xmlElement(
"varequal", $attrs, $index);
304 $a_xml_writer->xmlEndTag(
"conditionvar");
307 "feedbacktype" =>
"Response",
308 "linkrefid" =>
"response_allcorrect"
310 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
311 $a_xml_writer->xmlEndTag(
"respcondition");
314 $feedback_onenotcorrect = $this->
object->getFeedbackGeneric(0);
315 if (strlen($feedback_onenotcorrect))
320 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
322 $a_xml_writer->xmlStartTag(
"conditionvar");
323 $a_xml_writer->xmlStartTag(
"not");
325 foreach ($this->object->getAnswers() as $index => $answer)
328 if ($this->object->getOrderingType() ==
OQ_PICTURES)
340 $attrs[
"index"] = $index;
341 $a_xml_writer->xmlElement(
"varequal", $attrs, $index);
344 $a_xml_writer->xmlEndTag(
"not");
345 $a_xml_writer->xmlEndTag(
"conditionvar");
348 "feedbacktype" =>
"Response",
349 "linkrefid" =>
"response_onenotcorrect"
351 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
352 $a_xml_writer->xmlEndTag(
"respcondition");
355 $a_xml_writer->xmlEndTag(
"resprocessing");
358 foreach ($this->object->getAnswers() as $index => $answer)
361 "ident" =>
"link_$index",
364 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
366 $a_xml_writer->xmlStartTag(
"flow_mat");
367 $a_xml_writer->xmlStartTag(
"material");
368 $a_xml_writer->xmlElement(
"mattext");
369 $a_xml_writer->xmlEndTag(
"material");
370 $a_xml_writer->xmlEndTag(
"flow_mat");
371 $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);