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->xmlStartTag(
"qtimetadatafield");
87 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"externalID");
88 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->object->getExternalID());
89 $a_xml_writer->xmlEndTag(
"qtimetadatafield");
90 $a_xml_writer->xmlEndTag(
"qtimetadata");
91 $a_xml_writer->xmlEndTag(
"itemmetadata");
95 "label" => $this->object->getTitle()
97 $a_xml_writer->xmlStartTag(
"presentation", $attrs);
99 $a_xml_writer->xmlStartTag(
"flow");
101 $this->
object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
106 "rcardinality" =>
"Multiple"
108 $a_xml_writer->xmlStartTag(
"response_lid", $attrs);
109 $solution = $this->
object->getSuggestedSolution(0);
110 if (count($solution))
112 if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $solution[
"internal_link"], $matches))
114 $a_xml_writer->xmlStartTag(
"material");
115 $intlink =
"il_" . IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
116 if (strcmp($matches[1],
"") != 0)
118 $intlink = $solution[
"internal_link"];
121 "label" =>
"suggested_solution"
123 $a_xml_writer->xmlElement(
"mattext", $attrs, $intlink);
124 $a_xml_writer->xmlEndTag(
"material");
129 if ($this->object->getShuffle())
141 $a_xml_writer->xmlStartTag(
"render_choice", $attrs);
142 $answers =& $this->
object->getAnswers();
143 $akeys = array_keys($answers);
144 if ($this->object->getShuffle() && $a_shuffle)
146 $akeys = $this->
object->pcArrayShuffle($akeys);
149 foreach ($akeys as $index)
151 $answer = $answers[$index];
155 $a_xml_writer->xmlStartTag(
"response_label", $attrs);
157 if (strlen($answer->getImage()))
159 $this->
object->addQTIMaterial($a_xml_writer, $answer->getAnswertext(), FALSE, FALSE);
160 $imagetype =
"image/jpeg";
161 if (preg_match(
"/.*\.(png|gif)$/", $answer->getImage(), $matches))
163 $imagetype =
"image/" . $matches[1];
165 if ($force_image_references)
168 "imagtype" => $imagetype,
169 "label" => $answer->getImage(),
170 "uri" => $this->
object->getImagePathWeb() . $answer->getImage()
172 $a_xml_writer->xmlElement(
"matimage", $attrs);
176 $imagepath = $this->
object->getImagePath() . $answer->getImage();
177 $fh = @fopen($imagepath,
"rb");
180 $imagefile = fread($fh, filesize($imagepath));
182 $base64 = base64_encode($imagefile);
184 "imagtype" => $imagetype,
185 "label" => $answer->getImage(),
186 "embedded" =>
"base64"
188 $a_xml_writer->xmlElement(
"matimage", $attrs, $base64, FALSE, FALSE);
191 $a_xml_writer->xmlEndTag(
"material");
195 $this->
object->addQTIMaterial($a_xml_writer, $answer->getAnswertext());
197 $a_xml_writer->xmlEndTag(
"response_label");
199 $a_xml_writer->xmlEndTag(
"render_choice");
200 $a_xml_writer->xmlEndTag(
"response_lid");
201 $a_xml_writer->xmlEndTag(
"flow");
202 $a_xml_writer->xmlEndTag(
"presentation");
205 $a_xml_writer->xmlStartTag(
"resprocessing");
206 $a_xml_writer->xmlStartTag(
"outcomes");
207 $a_xml_writer->xmlStartTag(
"decvar");
208 $a_xml_writer->xmlEndTag(
"decvar");
209 $a_xml_writer->xmlEndTag(
"outcomes");
211 foreach ($answers as $index => $answer)
216 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
218 $a_xml_writer->xmlStartTag(
"conditionvar");
221 "respident" =>
"MCMR"
223 $a_xml_writer->xmlElement(
"varequal", $attrs, $index);
224 $a_xml_writer->xmlEndTag(
"conditionvar");
229 $a_xml_writer->xmlElement(
"setvar", $attrs, $answer->getPoints());
231 $linkrefid =
"response_$index";
233 "feedbacktype" =>
"Response",
234 "linkrefid" => $linkrefid
236 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
237 $a_xml_writer->xmlEndTag(
"respcondition");
241 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
244 $a_xml_writer->xmlStartTag(
"conditionvar");
247 "respident" =>
"MCMR"
249 $a_xml_writer->xmlStartTag(
"not");
250 $a_xml_writer->xmlElement(
"varequal", $attrs, $index);
251 $a_xml_writer->xmlEndTag(
"not");
252 $a_xml_writer->xmlEndTag(
"conditionvar");
257 $a_xml_writer->xmlElement(
"setvar", $attrs, $answer->getPointsUnchecked());
258 $a_xml_writer->xmlEndTag(
"respcondition");
260 $feedback_allcorrect = $this->
object->getFeedbackGeneric(1);
261 if (strlen($feedback_allcorrect))
266 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
268 $a_xml_writer->xmlStartTag(
"conditionvar");
269 foreach ($answers as $index => $answer)
271 if ($answer->getPointsChecked() < $answer->getPointsUnchecked())
273 $a_xml_writer->xmlStartTag(
"not");
276 "respident" =>
"MCMR"
278 $a_xml_writer->xmlElement(
"varequal", $attrs, $index);
279 if ($answer->getPointsChecked() < $answer->getPointsUnchecked())
281 $a_xml_writer->xmlEndTag(
"not");
284 $a_xml_writer->xmlEndTag(
"conditionvar");
287 "feedbacktype" =>
"Response",
288 "linkrefid" =>
"response_allcorrect"
290 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
291 $a_xml_writer->xmlEndTag(
"respcondition");
293 $feedback_onenotcorrect = $this->
object->getFeedbackGeneric(0);
294 if (strlen($feedback_onenotcorrect))
299 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
301 $a_xml_writer->xmlStartTag(
"conditionvar");
302 foreach ($answers as $index => $answer)
306 $a_xml_writer->xmlStartTag(
"or");
308 if ($answer->getPointsChecked() >= $answer->getPointsUnchecked())
310 $a_xml_writer->xmlStartTag(
"not");
313 "respident" =>
"MCMR"
315 $a_xml_writer->xmlElement(
"varequal", $attrs, $index);
316 if ($answer->getPointsChecked() >= $answer->getPointsUnchecked())
318 $a_xml_writer->xmlEndTag(
"not");
322 $a_xml_writer->xmlEndTag(
"or");
325 $a_xml_writer->xmlEndTag(
"conditionvar");
328 "feedbacktype" =>
"Response",
329 "linkrefid" =>
"response_onenotcorrect"
331 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
332 $a_xml_writer->xmlEndTag(
"respcondition");
334 $a_xml_writer->xmlEndTag(
"resprocessing");
337 foreach ($answers as $index => $answer)
339 $linkrefid =
"response_$index";
341 "ident" => $linkrefid,
344 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
346 $a_xml_writer->xmlStartTag(
"flow_mat");
347 $this->
object->addQTIMaterial($a_xml_writer, $this->object->getFeedbackSingleAnswer($index));
348 $a_xml_writer->xmlEndTag(
"flow_mat");
349 $a_xml_writer->xmlEndTag(
"itemfeedback");
351 if (strlen($feedback_allcorrect))
354 "ident" =>
"response_allcorrect",
357 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
359 $a_xml_writer->xmlStartTag(
"flow_mat");
360 $this->
object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
361 $a_xml_writer->xmlEndTag(
"flow_mat");
362 $a_xml_writer->xmlEndTag(
"itemfeedback");
364 if (strlen($feedback_onenotcorrect))
367 "ident" =>
"response_onenotcorrect",
370 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
372 $a_xml_writer->xmlStartTag(
"flow_mat");
373 $this->
object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
374 $a_xml_writer->xmlEndTag(
"flow_mat");
375 $a_xml_writer->xmlEndTag(
"itemfeedback");
378 $a_xml_writer->xmlEndTag(
"item");
379 $a_xml_writer->xmlEndTag(
"questestinterop");
381 $xml = $a_xml_writer->xmlDumpMem(FALSE);
382 if (!$a_include_header)
384 $pos = strpos($xml,
"?>");
385 $xml = substr($xml,
$pos + 2);