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,
"thumb_size");
84 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->object->getThumbSize());
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());
102 "rcardinality" =>
"Single"
104 $a_xml_writer->xmlStartTag(
"response_lid", $attrs);
105 $solution = $this->
object->getSuggestedSolution(0);
106 if (count($solution))
108 if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $solution[
"internal_link"], $matches))
110 $a_xml_writer->xmlStartTag(
"material");
111 $intlink =
"il_" . IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
112 if (strcmp($matches[1],
"") != 0)
114 $intlink = $solution[
"internal_link"];
117 "label" =>
"suggested_solution"
119 $a_xml_writer->xmlElement(
"mattext", $attrs, $intlink);
120 $a_xml_writer->xmlEndTag(
"material");
125 if ($this->object->getShuffle())
137 $a_xml_writer->xmlStartTag(
"render_choice", $attrs);
138 $answers =& $this->
object->getAnswers();
139 $akeys = array_keys($answers);
140 if ($this->object->getShuffle() && $a_shuffle)
142 $akeys = $this->
object->pcArrayShuffle($akeys);
145 foreach ($akeys as $index)
147 $answer = $answers[$index];
151 $a_xml_writer->xmlStartTag(
"response_label", $attrs);
153 if (strlen($answer->getImage()))
155 $this->
object->addQTIMaterial($a_xml_writer, $answer->getAnswertext(), FALSE, FALSE);
156 $imagetype =
"image/jpeg";
157 if (preg_match(
"/.*\.(png|gif)$/", $answer->getImage(), $matches))
159 $imagetype =
"image/" . $matches[1];
161 if ($force_image_references)
164 "imagtype" => $imagetype,
165 "label" => $answer->getImage(),
166 "uri" => $this->
object->getImagePathWeb() . $answer->getImage()
168 $a_xml_writer->xmlElement(
"matimage", $attrs);
172 $imagepath = $this->
object->getImagePath() . $answer->getImage();
173 $fh = @fopen($imagepath,
"rb");
176 $imagefile = fread($fh, filesize($imagepath));
178 $base64 = base64_encode($imagefile);
180 "imagtype" => $imagetype,
181 "label" => $answer->getImage(),
182 "embedded" =>
"base64"
184 $a_xml_writer->xmlElement(
"matimage", $attrs, $base64, FALSE, FALSE);
187 $a_xml_writer->xmlEndTag(
"material");
191 $this->
object->addQTIMaterial($a_xml_writer, $answer->getAnswertext());
193 $a_xml_writer->xmlEndTag(
"response_label");
195 $a_xml_writer->xmlEndTag(
"render_choice");
196 $a_xml_writer->xmlEndTag(
"response_lid");
197 $a_xml_writer->xmlEndTag(
"flow");
198 $a_xml_writer->xmlEndTag(
"presentation");
201 $a_xml_writer->xmlStartTag(
"resprocessing");
202 $a_xml_writer->xmlStartTag(
"outcomes");
203 $a_xml_writer->xmlStartTag(
"decvar");
204 $a_xml_writer->xmlEndTag(
"decvar");
205 $a_xml_writer->xmlEndTag(
"outcomes");
207 foreach ($answers as $index => $answer)
212 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
214 $a_xml_writer->xmlStartTag(
"conditionvar");
217 "respident" =>
"MCSR"
219 $a_xml_writer->xmlElement(
"varequal", $attrs, $index);
220 $a_xml_writer->xmlEndTag(
"conditionvar");
225 $a_xml_writer->xmlElement(
"setvar", $attrs, $answer->getPoints());
227 $linkrefid =
"response_$index";
229 "feedbacktype" =>
"Response",
230 "linkrefid" => $linkrefid
232 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
233 $a_xml_writer->xmlEndTag(
"respcondition");
236 $feedback_allcorrect = $this->
object->getFeedbackGeneric(1);
237 if (strlen($feedback_allcorrect))
242 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
244 $a_xml_writer->xmlStartTag(
"conditionvar");
247 foreach ($answers as $index => $answer)
249 if ($answer->getPoints() > $maxpoints)
251 $maxpoints = $answer->getPoints();
256 "respident" =>
"MCSR"
258 $a_xml_writer->xmlElement(
"varequal", $attrs, $bestindex);
259 $a_xml_writer->xmlEndTag(
"conditionvar");
262 "feedbacktype" =>
"Response",
263 "linkrefid" =>
"response_allcorrect"
265 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
266 $a_xml_writer->xmlEndTag(
"respcondition");
269 $feedback_onenotcorrect = $this->
object->getFeedbackGeneric(0);
270 if (strlen($feedback_onenotcorrect))
275 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
277 $a_xml_writer->xmlStartTag(
"conditionvar");
280 foreach ($answers as $index => $answer)
282 if ($answer->getPoints() > $maxpoints)
284 $maxpoints = $answer->getPoints();
289 "respident" =>
"MCSR"
291 $a_xml_writer->xmlStartTag(
"not");
292 $a_xml_writer->xmlElement(
"varequal", $attrs, $bestindex);
293 $a_xml_writer->xmlEndTag(
"not");
294 $a_xml_writer->xmlEndTag(
"conditionvar");
297 "feedbacktype" =>
"Response",
298 "linkrefid" =>
"response_onenotcorrect"
300 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
301 $a_xml_writer->xmlEndTag(
"respcondition");
304 $a_xml_writer->xmlEndTag(
"resprocessing");
307 foreach ($answers as $index => $answer)
309 $linkrefid =
"response_$index";
311 "ident" => $linkrefid,
314 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
316 $a_xml_writer->xmlStartTag(
"flow_mat");
317 $this->
object->addQTIMaterial($a_xml_writer, $this->object->getFeedbackSingleAnswer($index));
318 $a_xml_writer->xmlEndTag(
"flow_mat");
319 $a_xml_writer->xmlEndTag(
"itemfeedback");
321 if (strlen($feedback_allcorrect))
324 "ident" =>
"response_allcorrect",
327 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
329 $a_xml_writer->xmlStartTag(
"flow_mat");
330 $this->
object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
331 $a_xml_writer->xmlEndTag(
"flow_mat");
332 $a_xml_writer->xmlEndTag(
"itemfeedback");
334 if (strlen($feedback_onenotcorrect))
337 "ident" =>
"response_onenotcorrect",
340 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
342 $a_xml_writer->xmlStartTag(
"flow_mat");
343 $this->
object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
344 $a_xml_writer->xmlEndTag(
"flow_mat");
345 $a_xml_writer->xmlEndTag(
"itemfeedback");
348 $a_xml_writer->xmlEndTag(
"item");
349 $a_xml_writer->xmlEndTag(
"questestinterop");
351 $xml = $a_xml_writer->xmlDumpMem(FALSE);
352 if (!$a_include_header)
354 $pos = strpos($xml,
"?>");
355 $xml = substr($xml, $pos + 2);