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" =>
"Multiple"
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" =>
"MCMR"
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");
237 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
240 $a_xml_writer->xmlStartTag(
"conditionvar");
243 "respident" =>
"MCMR"
245 $a_xml_writer->xmlStartTag(
"not");
246 $a_xml_writer->xmlElement(
"varequal", $attrs, $index);
247 $a_xml_writer->xmlEndTag(
"not");
248 $a_xml_writer->xmlEndTag(
"conditionvar");
253 $a_xml_writer->xmlElement(
"setvar", $attrs, $answer->getPointsUnchecked());
254 $a_xml_writer->xmlEndTag(
"respcondition");
256 $feedback_allcorrect = $this->
object->getFeedbackGeneric(1);
257 if (strlen($feedback_allcorrect))
262 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
264 $a_xml_writer->xmlStartTag(
"conditionvar");
265 foreach ($answers as $index => $answer)
267 if ($answer->getPointsChecked() < $answer->getPointsUnchecked())
269 $a_xml_writer->xmlStartTag(
"not");
272 "respident" =>
"MCMR"
274 $a_xml_writer->xmlElement(
"varequal", $attrs, $index);
275 if ($answer->getPointsChecked() < $answer->getPointsUnchecked())
277 $a_xml_writer->xmlEndTag(
"not");
280 $a_xml_writer->xmlEndTag(
"conditionvar");
283 "feedbacktype" =>
"Response",
284 "linkrefid" =>
"response_allcorrect"
286 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
287 $a_xml_writer->xmlEndTag(
"respcondition");
289 $feedback_onenotcorrect = $this->
object->getFeedbackGeneric(0);
290 if (strlen($feedback_onenotcorrect))
295 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
297 $a_xml_writer->xmlStartTag(
"conditionvar");
298 foreach ($answers as $index => $answer)
302 $a_xml_writer->xmlStartTag(
"or");
304 if ($answer->getPointsChecked() >= $answer->getPointsUnchecked())
306 $a_xml_writer->xmlStartTag(
"not");
309 "respident" =>
"MCMR"
311 $a_xml_writer->xmlElement(
"varequal", $attrs, $index);
312 if ($answer->getPointsChecked() >= $answer->getPointsUnchecked())
314 $a_xml_writer->xmlEndTag(
"not");
318 $a_xml_writer->xmlEndTag(
"or");
321 $a_xml_writer->xmlEndTag(
"conditionvar");
324 "feedbacktype" =>
"Response",
325 "linkrefid" =>
"response_onenotcorrect"
327 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
328 $a_xml_writer->xmlEndTag(
"respcondition");
330 $a_xml_writer->xmlEndTag(
"resprocessing");
333 foreach ($answers as $index => $answer)
335 $linkrefid =
"response_$index";
337 "ident" => $linkrefid,
340 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
342 $a_xml_writer->xmlStartTag(
"flow_mat");
343 $this->
object->addQTIMaterial($a_xml_writer, $this->object->getFeedbackSingleAnswer($index));
344 $a_xml_writer->xmlEndTag(
"flow_mat");
345 $a_xml_writer->xmlEndTag(
"itemfeedback");
347 if (strlen($feedback_allcorrect))
350 "ident" =>
"response_allcorrect",
353 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
355 $a_xml_writer->xmlStartTag(
"flow_mat");
356 $this->
object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
357 $a_xml_writer->xmlEndTag(
"flow_mat");
358 $a_xml_writer->xmlEndTag(
"itemfeedback");
360 if (strlen($feedback_onenotcorrect))
363 "ident" =>
"response_onenotcorrect",
366 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
368 $a_xml_writer->xmlStartTag(
"flow_mat");
369 $this->
object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
370 $a_xml_writer->xmlEndTag(
"flow_mat");
371 $a_xml_writer->xmlEndTag(
"itemfeedback");
374 $a_xml_writer->xmlEndTag(
"item");
375 $a_xml_writer->xmlEndTag(
"questestinterop");
377 $xml = $a_xml_writer->xmlDumpMem(FALSE);
378 if (!$a_include_header)
380 $pos = strpos($xml,
"?>");
381 $xml = substr($xml, $pos + 2);