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" =>
"Single"
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" =>
"MCSR"
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");
240 $feedback_allcorrect = $this->
object->getFeedbackGeneric(1);
241 if (strlen($feedback_allcorrect))
246 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
248 $a_xml_writer->xmlStartTag(
"conditionvar");
251 foreach ($answers as $index => $answer)
253 if ($answer->getPoints() > $maxpoints)
255 $maxpoints = $answer->getPoints();
260 "respident" =>
"MCSR"
262 $a_xml_writer->xmlElement(
"varequal", $attrs, $bestindex);
263 $a_xml_writer->xmlEndTag(
"conditionvar");
266 "feedbacktype" =>
"Response",
267 "linkrefid" =>
"response_allcorrect"
269 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
270 $a_xml_writer->xmlEndTag(
"respcondition");
273 $feedback_onenotcorrect = $this->
object->getFeedbackGeneric(0);
274 if (strlen($feedback_onenotcorrect))
279 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
281 $a_xml_writer->xmlStartTag(
"conditionvar");
284 foreach ($answers as $index => $answer)
286 if ($answer->getPoints() > $maxpoints)
288 $maxpoints = $answer->getPoints();
293 "respident" =>
"MCSR"
295 $a_xml_writer->xmlStartTag(
"not");
296 $a_xml_writer->xmlElement(
"varequal", $attrs, $bestindex);
297 $a_xml_writer->xmlEndTag(
"not");
298 $a_xml_writer->xmlEndTag(
"conditionvar");
301 "feedbacktype" =>
"Response",
302 "linkrefid" =>
"response_onenotcorrect"
304 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
305 $a_xml_writer->xmlEndTag(
"respcondition");
308 $a_xml_writer->xmlEndTag(
"resprocessing");
311 foreach ($answers as $index => $answer)
313 $linkrefid =
"response_$index";
315 "ident" => $linkrefid,
318 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
320 $a_xml_writer->xmlStartTag(
"flow_mat");
321 $this->
object->addQTIMaterial($a_xml_writer, $this->object->getFeedbackSingleAnswer($index));
322 $a_xml_writer->xmlEndTag(
"flow_mat");
323 $a_xml_writer->xmlEndTag(
"itemfeedback");
325 if (strlen($feedback_allcorrect))
328 "ident" =>
"response_allcorrect",
331 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
333 $a_xml_writer->xmlStartTag(
"flow_mat");
334 $this->
object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
335 $a_xml_writer->xmlEndTag(
"flow_mat");
336 $a_xml_writer->xmlEndTag(
"itemfeedback");
338 if (strlen($feedback_onenotcorrect))
341 "ident" =>
"response_onenotcorrect",
344 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
346 $a_xml_writer->xmlStartTag(
"flow_mat");
347 $this->
object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
348 $a_xml_writer->xmlEndTag(
"flow_mat");
349 $a_xml_writer->xmlEndTag(
"itemfeedback");
352 $a_xml_writer->xmlEndTag(
"item");
353 $a_xml_writer->xmlEndTag(
"questestinterop");
355 $xml = $a_xml_writer->xmlDumpMem(FALSE);
356 if (!$a_include_header)
358 $pos = strpos($xml,
"?>");
359 $xml = substr($xml,
$pos + 2);