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->xmlEndTag(
"qtimetadata");
95 $a_xml_writer->xmlEndTag(
"itemmetadata");
99 "label" => $this->object->getTitle()
101 $a_xml_writer->xmlStartTag(
"presentation", $attrs);
103 $a_xml_writer->xmlStartTag(
"flow");
105 $this->
object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
109 "rcardinality" =>
"Multiple"
111 $a_xml_writer->xmlStartTag(
"response_grp", $attrs);
112 $solution = $this->
object->getSuggestedSolution(0);
113 if (count($solution))
115 if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $solution[
"internal_link"], $matches))
117 $a_xml_writer->xmlStartTag(
"material");
118 $intlink =
"il_" . IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
119 if (strcmp($matches[1],
"") != 0)
121 $intlink = $solution[
"internal_link"];
124 "label" =>
"suggested_solution"
126 $a_xml_writer->xmlElement(
"mattext", $attrs, $intlink);
127 $a_xml_writer->xmlEndTag(
"material");
132 if ($this->object->getShuffle())
144 $a_xml_writer->xmlStartTag(
"render_choice", $attrs);
146 $matchingtext_orders = array();
147 foreach ($this->object->getMatchingPairs() as $index => $matchingpair)
149 array_push($matchingtext_orders, $matchingpair->term->identifier);
153 foreach ($this->object->getTerms() as $term)
155 array_push($termids, $term->identifier);
158 foreach ($this->object->getDefinitions() as $definition)
161 "ident" => $definition->identifier,
163 "match_group" => join($termids,
",")
165 $a_xml_writer->xmlStartTag(
"response_label", $attrs);
166 $a_xml_writer->xmlStartTag(
"material");
167 if (strlen($definition->picture))
169 if ($force_image_references)
172 "imagtype" =>
"image/jpeg",
173 "label" => $definition->picture,
174 "uri" => $this->object->getImagePathWeb() . $definition->picture
176 $a_xml_writer->xmlElement(
"matimage", $attrs);
180 $imagepath = $this->
object->getImagePath() . $definition->picture;
181 $fh = @fopen($imagepath,
"rb");
184 $imagefile = fread($fh, filesize($imagepath));
186 $base64 = base64_encode($imagefile);
188 "imagtype" =>
"image/jpeg",
189 "label" => $definition->picture,
190 "embedded" =>
"base64"
192 $a_xml_writer->xmlElement(
"matimage", $attrs, $base64, FALSE, FALSE);
196 if (strlen($definition->text))
199 "texttype" =>
"text/plain"
201 if ($this->object->isHTML($definition->text))
203 $attrs[
"texttype"] =
"text/xhtml";
205 $a_xml_writer->xmlElement(
"mattext", $attrs, $definition->text);
207 $a_xml_writer->xmlEndTag(
"material");
208 $a_xml_writer->xmlEndTag(
"response_label");
211 foreach ($this->object->getTerms() as $term)
214 "ident" => $term->identifier
216 $a_xml_writer->xmlStartTag(
"response_label", $attrs);
217 $a_xml_writer->xmlStartTag(
"material");
218 if (strlen($term->picture))
220 if ($force_image_references)
223 "imagtype" =>
"image/jpeg",
224 "label" => $term->picture,
225 "uri" => $this->object->getImagePathWeb() . $term->picture
227 $a_xml_writer->xmlElement(
"matimage", $attrs);
231 $imagepath = $this->
object->getImagePath() . $term->picture;
232 $fh = @fopen($imagepath,
"rb");
235 $imagefile = fread($fh, filesize($imagepath));
237 $base64 = base64_encode($imagefile);
239 "imagtype" =>
"image/jpeg",
240 "label" => $term->picture,
241 "embedded" =>
"base64"
243 $a_xml_writer->xmlElement(
"matimage", $attrs, $base64, FALSE, FALSE);
247 if (strlen($term->text))
250 "texttype" =>
"text/plain"
252 if ($this->object->isHTML($term->text))
254 $attrs[
"texttype"] =
"text/xhtml";
256 $a_xml_writer->xmlElement(
"mattext", $attrs, $term->text);
258 $a_xml_writer->xmlEndTag(
"material");
259 $a_xml_writer->xmlEndTag(
"response_label");
261 $a_xml_writer->xmlEndTag(
"render_choice");
262 $a_xml_writer->xmlEndTag(
"response_grp");
263 $a_xml_writer->xmlEndTag(
"flow");
264 $a_xml_writer->xmlEndTag(
"presentation");
267 $a_xml_writer->xmlStartTag(
"resprocessing");
268 $a_xml_writer->xmlStartTag(
"outcomes");
269 $a_xml_writer->xmlStartTag(
"decvar");
270 $a_xml_writer->xmlEndTag(
"decvar");
271 $a_xml_writer->xmlEndTag(
"outcomes");
273 foreach ($this->object->getMatchingPairs() as $matchingpair)
278 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
280 $a_xml_writer->xmlStartTag(
"conditionvar");
284 $a_xml_writer->xmlElement(
"varsubset", $attrs, $matchingpair->term->identifier .
"," . $matchingpair->definition->identifier);
285 $a_xml_writer->xmlEndTag(
"conditionvar");
291 $a_xml_writer->xmlElement(
"setvar", $attrs, $matchingpair->points);
294 "feedbacktype" =>
"Response",
295 "linkrefid" =>
"correct_" . $matchingpair->term->identifier .
"_" . $matchingpair->definition_identifier
297 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
298 $a_xml_writer->xmlEndTag(
"respcondition");
301 $feedback_allcorrect = $this->
object->getFeedbackGeneric(1);
302 if (strlen($feedback_allcorrect))
307 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
309 $a_xml_writer->xmlStartTag(
"conditionvar");
311 foreach ($this->object->getMatchingPairs() as $matchingpair)
316 $a_xml_writer->xmlElement(
"varsubset", $attrs, $matchingpair->term->identifier .
"," . $matchingpair->definition->identifier);
318 $a_xml_writer->xmlEndTag(
"conditionvar");
321 "feedbacktype" =>
"Response",
322 "linkrefid" =>
"response_allcorrect"
324 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
325 $a_xml_writer->xmlEndTag(
"respcondition");
327 $feedback_onenotcorrect = $this->
object->getFeedbackGeneric(0);
328 if (strlen($feedback_onenotcorrect))
333 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
335 $a_xml_writer->xmlStartTag(
"conditionvar");
336 $a_xml_writer->xmlStartTag(
"not");
337 foreach ($this->object->getMatchingPairs() as $matchingpair)
342 $a_xml_writer->xmlElement(
"varsubset", $attrs, $matchingpair->term->identifier .
"," . $matchingpair->definition->identifier);
344 $a_xml_writer->xmlEndTag(
"not");
345 $a_xml_writer->xmlEndTag(
"conditionvar");
348 "feedbacktype" =>
"Response",
349 "linkrefid" =>
"response_onenotcorrect"
351 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
352 $a_xml_writer->xmlEndTag(
"respcondition");
355 $a_xml_writer->xmlEndTag(
"resprocessing");
358 foreach ($this->object->getMatchingPairs() as $matchingpair)
361 "ident" =>
"correct_" . $matchingpair->term->identifier .
"_" . $matchingpair->definition->identifier,
364 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
366 $a_xml_writer->xmlStartTag(
"flow_mat");
367 $a_xml_writer->xmlStartTag(
"material");
368 $a_xml_writer->xmlElement(
"mattext");
369 $a_xml_writer->xmlEndTag(
"material");
370 $a_xml_writer->xmlEndTag(
"flow_mat");
371 $a_xml_writer->xmlEndTag(
"itemfeedback");
374 if (strlen($feedback_allcorrect))
377 "ident" =>
"response_allcorrect",
380 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
382 $a_xml_writer->xmlStartTag(
"flow_mat");
383 $this->
object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
384 $a_xml_writer->xmlEndTag(
"flow_mat");
385 $a_xml_writer->xmlEndTag(
"itemfeedback");
387 if (strlen($feedback_onenotcorrect))
390 "ident" =>
"response_onenotcorrect",
393 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
395 $a_xml_writer->xmlStartTag(
"flow_mat");
396 $this->
object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
397 $a_xml_writer->xmlEndTag(
"flow_mat");
398 $a_xml_writer->xmlEndTag(
"itemfeedback");
401 $a_xml_writer->xmlEndTag(
"item");
402 $a_xml_writer->xmlEndTag(
"questestinterop");
404 $xml = $a_xml_writer->xmlDumpMem(FALSE);
405 if (!$a_include_header)
407 $pos = strpos($xml,
"?>");
408 $xml = substr($xml, $pos + 2);