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,
"shuffle");
84 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->object->getShuffle());
85 $a_xml_writer->xmlEndTag(
"qtimetadatafield");
86 $a_xml_writer->xmlStartTag(
"qtimetadatafield");
87 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"thumb_geometry");
88 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->object->getThumbGeometry());
89 $a_xml_writer->xmlEndTag(
"qtimetadatafield");
90 $a_xml_writer->xmlStartTag(
"qtimetadatafield");
91 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"element_height");
92 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->object->getElementHeight());
93 $a_xml_writer->xmlEndTag(
"qtimetadatafield");
94 $a_xml_writer->xmlStartTag(
"qtimetadatafield");
95 $a_xml_writer->xmlElement(
"fieldlabel", NULL,
"externalID");
96 $a_xml_writer->xmlElement(
"fieldentry", NULL, $this->object->getExternalID());
97 $a_xml_writer->xmlEndTag(
"qtimetadatafield");
98 $a_xml_writer->xmlEndTag(
"qtimetadata");
99 $a_xml_writer->xmlEndTag(
"itemmetadata");
103 "label" => $this->object->getTitle()
105 $a_xml_writer->xmlStartTag(
"presentation", $attrs);
107 $a_xml_writer->xmlStartTag(
"flow");
109 $this->
object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
113 "rcardinality" =>
"Multiple"
115 $a_xml_writer->xmlStartTag(
"response_grp", $attrs);
116 $solution = $this->
object->getSuggestedSolution(0);
117 if (count($solution))
119 if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $solution[
"internal_link"], $matches))
121 $a_xml_writer->xmlStartTag(
"material");
122 $intlink =
"il_" . IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
123 if (strcmp($matches[1],
"") != 0)
125 $intlink = $solution[
"internal_link"];
128 "label" =>
"suggested_solution"
130 $a_xml_writer->xmlElement(
"mattext", $attrs, $intlink);
131 $a_xml_writer->xmlEndTag(
"material");
136 if ($this->object->getShuffle())
148 $a_xml_writer->xmlStartTag(
"render_choice", $attrs);
150 $matchingtext_orders = array();
151 foreach ($this->object->getMatchingPairs() as $index => $matchingpair)
153 array_push($matchingtext_orders, $matchingpair->term->identifier);
157 foreach ($this->object->getTerms() as $term)
159 array_push($termids, $term->identifier);
162 foreach ($this->object->getDefinitions() as $definition)
165 "ident" => $definition->identifier,
167 "match_group" => join($termids,
",")
169 $a_xml_writer->xmlStartTag(
"response_label", $attrs);
170 $a_xml_writer->xmlStartTag(
"material");
171 if (strlen($definition->picture))
173 if ($force_image_references)
176 "imagtype" =>
"image/jpeg",
177 "label" => $definition->picture,
178 "uri" => $this->object->getImagePathWeb() . $definition->picture
180 $a_xml_writer->xmlElement(
"matimage", $attrs);
184 $imagepath = $this->
object->getImagePath() . $definition->picture;
185 $fh = @fopen($imagepath,
"rb");
188 $imagefile = fread($fh, filesize($imagepath));
190 $base64 = base64_encode($imagefile);
192 "imagtype" =>
"image/jpeg",
193 "label" => $definition->picture,
194 "embedded" =>
"base64"
196 $a_xml_writer->xmlElement(
"matimage", $attrs, $base64, FALSE, FALSE);
200 if (strlen($definition->text))
203 "texttype" =>
"text/plain"
205 if ($this->object->isHTML($definition->text))
207 $attrs[
"texttype"] =
"text/xhtml";
209 $a_xml_writer->xmlElement(
"mattext", $attrs, $definition->text);
211 $a_xml_writer->xmlEndTag(
"material");
212 $a_xml_writer->xmlEndTag(
"response_label");
215 foreach ($this->object->getTerms() as $term)
218 "ident" => $term->identifier
220 $a_xml_writer->xmlStartTag(
"response_label", $attrs);
221 $a_xml_writer->xmlStartTag(
"material");
222 if (strlen($term->picture))
224 if ($force_image_references)
227 "imagtype" =>
"image/jpeg",
228 "label" => $term->picture,
229 "uri" => $this->object->getImagePathWeb() . $term->picture
231 $a_xml_writer->xmlElement(
"matimage", $attrs);
235 $imagepath = $this->
object->getImagePath() . $term->picture;
236 $fh = @fopen($imagepath,
"rb");
239 $imagefile = fread($fh, filesize($imagepath));
241 $base64 = base64_encode($imagefile);
243 "imagtype" =>
"image/jpeg",
244 "label" => $term->picture,
245 "embedded" =>
"base64"
247 $a_xml_writer->xmlElement(
"matimage", $attrs, $base64, FALSE, FALSE);
251 if (strlen($term->text))
254 "texttype" =>
"text/plain"
256 if ($this->object->isHTML($term->text))
258 $attrs[
"texttype"] =
"text/xhtml";
260 $a_xml_writer->xmlElement(
"mattext", $attrs, $term->text);
262 $a_xml_writer->xmlEndTag(
"material");
263 $a_xml_writer->xmlEndTag(
"response_label");
265 $a_xml_writer->xmlEndTag(
"render_choice");
266 $a_xml_writer->xmlEndTag(
"response_grp");
267 $a_xml_writer->xmlEndTag(
"flow");
268 $a_xml_writer->xmlEndTag(
"presentation");
271 $a_xml_writer->xmlStartTag(
"resprocessing");
272 $a_xml_writer->xmlStartTag(
"outcomes");
273 $a_xml_writer->xmlStartTag(
"decvar");
274 $a_xml_writer->xmlEndTag(
"decvar");
275 $a_xml_writer->xmlEndTag(
"outcomes");
277 foreach ($this->object->getMatchingPairs() as $matchingpair)
282 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
284 $a_xml_writer->xmlStartTag(
"conditionvar");
288 $a_xml_writer->xmlElement(
"varsubset", $attrs, $matchingpair->term->identifier .
"," . $matchingpair->definition->identifier);
289 $a_xml_writer->xmlEndTag(
"conditionvar");
295 $a_xml_writer->xmlElement(
"setvar", $attrs, $matchingpair->points);
298 "feedbacktype" =>
"Response",
299 "linkrefid" =>
"correct_" . $matchingpair->term->identifier .
"_" . $matchingpair->definition_identifier
301 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
302 $a_xml_writer->xmlEndTag(
"respcondition");
305 $feedback_allcorrect = $this->
object->getFeedbackGeneric(1);
306 if (strlen($feedback_allcorrect))
311 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
313 $a_xml_writer->xmlStartTag(
"conditionvar");
315 foreach ($this->object->getMatchingPairs() as $matchingpair)
320 $a_xml_writer->xmlElement(
"varsubset", $attrs, $matchingpair->term->identifier .
"," . $matchingpair->definition->identifier);
322 $a_xml_writer->xmlEndTag(
"conditionvar");
325 "feedbacktype" =>
"Response",
326 "linkrefid" =>
"response_allcorrect"
328 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
329 $a_xml_writer->xmlEndTag(
"respcondition");
331 $feedback_onenotcorrect = $this->
object->getFeedbackGeneric(0);
332 if (strlen($feedback_onenotcorrect))
337 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
339 $a_xml_writer->xmlStartTag(
"conditionvar");
340 $a_xml_writer->xmlStartTag(
"not");
341 foreach ($this->object->getMatchingPairs() as $matchingpair)
346 $a_xml_writer->xmlElement(
"varsubset", $attrs, $matchingpair->term->identifier .
"," . $matchingpair->definition->identifier);
348 $a_xml_writer->xmlEndTag(
"not");
349 $a_xml_writer->xmlEndTag(
"conditionvar");
352 "feedbacktype" =>
"Response",
353 "linkrefid" =>
"response_onenotcorrect"
355 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
356 $a_xml_writer->xmlEndTag(
"respcondition");
359 $a_xml_writer->xmlEndTag(
"resprocessing");
362 foreach ($this->object->getMatchingPairs() as $matchingpair)
365 "ident" =>
"correct_" . $matchingpair->term->identifier .
"_" . $matchingpair->definition->identifier,
368 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
370 $a_xml_writer->xmlStartTag(
"flow_mat");
371 $a_xml_writer->xmlStartTag(
"material");
372 $a_xml_writer->xmlElement(
"mattext");
373 $a_xml_writer->xmlEndTag(
"material");
374 $a_xml_writer->xmlEndTag(
"flow_mat");
375 $a_xml_writer->xmlEndTag(
"itemfeedback");
378 if (strlen($feedback_allcorrect))
381 "ident" =>
"response_allcorrect",
384 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
386 $a_xml_writer->xmlStartTag(
"flow_mat");
387 $this->
object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
388 $a_xml_writer->xmlEndTag(
"flow_mat");
389 $a_xml_writer->xmlEndTag(
"itemfeedback");
391 if (strlen($feedback_onenotcorrect))
394 "ident" =>
"response_onenotcorrect",
397 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
399 $a_xml_writer->xmlStartTag(
"flow_mat");
400 $this->
object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
401 $a_xml_writer->xmlEndTag(
"flow_mat");
402 $a_xml_writer->xmlEndTag(
"itemfeedback");
405 $a_xml_writer->xmlEndTag(
"item");
406 $a_xml_writer->xmlEndTag(
"questestinterop");
408 $xml = $a_xml_writer->xmlDumpMem(FALSE);
409 if (!$a_include_header)
411 $pos = strpos($xml,
"?>");
412 $xml = substr($xml,
$pos + 2);