18 include_once
"./Modules/TestQuestionPool/classes/export/qti12/class.assQuestionExport.php";
38 public function toXML($a_include_header =
true, $a_include_binary =
true, $a_shuffle =
false, $test_output =
false, $force_image_references =
false): string
41 $ilias = $DIC[
'ilias'];
43 include_once(
"./Services/Xml/classes/class.ilXmlWriter.php");
46 $a_xml_writer->xmlHeader();
47 $a_xml_writer->xmlStartTag(
"questestinterop");
50 "title" => $this->
object->getTitle(),
51 "maxattempts" => $this->
object->getNrOfTries()
53 $a_xml_writer->xmlStartTag(
"item", $attrs);
55 $a_xml_writer->xmlElement(
"qticomment", null, $this->
object->getComment());
56 $a_xml_writer->xmlStartTag(
"itemmetadata");
57 $a_xml_writer->xmlStartTag(
"qtimetadata");
58 $a_xml_writer->xmlStartTag(
"qtimetadatafield");
59 $a_xml_writer->xmlElement(
"fieldlabel", null,
"ILIAS_VERSION");
60 $a_xml_writer->xmlElement(
"fieldentry", null, $ilias->getSetting(
"ilias_version"));
61 $a_xml_writer->xmlEndTag(
"qtimetadatafield");
62 $a_xml_writer->xmlStartTag(
"qtimetadatafield");
63 $a_xml_writer->xmlElement(
"fieldlabel", null,
"QUESTIONTYPE");
65 $a_xml_writer->xmlEndTag(
"qtimetadatafield");
66 $a_xml_writer->xmlStartTag(
"qtimetadatafield");
67 $a_xml_writer->xmlElement(
"fieldlabel", null,
"IS_MULTIPLE_CHOICE");
68 $a_xml_writer->xmlElement(
"fieldentry", null, ($this->
object->getIsMultipleChoice()) ?
"1" :
"0");
69 $a_xml_writer->xmlEndTag(
"qtimetadatafield");
70 $a_xml_writer->xmlStartTag(
"qtimetadatafield");
71 $a_xml_writer->xmlElement(
"fieldlabel", null,
"AUTHOR");
72 $a_xml_writer->xmlElement(
"fieldentry", null, $this->
object->getAuthor());
73 $a_xml_writer->xmlEndTag(
"qtimetadatafield");
79 $a_xml_writer->xmlEndTag(
"qtimetadata");
80 $a_xml_writer->xmlEndTag(
"itemmetadata");
84 "label" => $this->
object->getTitle()
86 $a_xml_writer->xmlStartTag(
"presentation", $attrs);
88 $a_xml_writer->xmlStartTag(
"flow");
90 $this->
object->addQTIMaterial($a_xml_writer, $this->
object->getQuestion());
94 "rcardinality" =>
"Single" 96 $a_xml_writer->xmlStartTag(
"response_xy", $attrs);
97 $solution = $this->
object->getSuggestedSolution(0);
98 if ($solution !== null && count($solution)) {
99 if (preg_match(
"/il_(\d*?)_(\w+)_(\d+)/", $solution[
"internal_link"], $matches)) {
100 $a_xml_writer->xmlStartTag(
"material");
101 $intlink =
"il_" .
IL_INST_ID .
"_" . $matches[2] .
"_" . $matches[3];
102 if (strcmp($matches[1],
"") != 0) {
103 $intlink = $solution[
"internal_link"];
106 "label" =>
"suggested_solution" 108 $a_xml_writer->xmlElement(
"mattext", $attrs, $intlink);
109 $a_xml_writer->xmlEndTag(
"material");
112 $a_xml_writer->xmlStartTag(
"render_hotspot");
113 $a_xml_writer->xmlStartTag(
"material");
114 $imagetype =
"image/jpeg";
115 if (preg_match(
"/.*\.(png|gif)$/i", $this->
object->getImageFilename(), $matches)) {
116 $imagetype =
"image/" . strtolower($matches[1]);
119 "imagtype" => $imagetype,
120 "label" => $this->
object->getImageFilename()
122 if ($a_include_binary) {
123 if ($force_image_references) {
124 $attrs[
"uri"] = $this->
object->getImagePathWeb() . $this->
object->getImageFilename();
125 $a_xml_writer->xmlElement(
"matimage", $attrs);
127 $attrs[
"embedded"] =
"base64";
128 $imagepath = $this->
object->getImagePath() . $this->
object->getImageFilename();
129 $fh = fopen($imagepath,
"rb");
135 $imagefile = fread($fh, filesize($imagepath));
137 $base64 = base64_encode($imagefile);
138 $a_xml_writer->xmlElement(
"matimage", $attrs, $base64,
false,
false);
141 $a_xml_writer->xmlElement(
"matimage", $attrs);
143 $a_xml_writer->xmlEndTag(
"material");
146 foreach ($this->
object->getAnswers() as
$index => $answer) {
148 switch ($answer->getArea()) {
150 $rarea =
"Rectangle";
163 $a_xml_writer->xmlStartTag(
"response_label", $attrs);
164 $a_xml_writer->xmlData($answer->getCoords());
165 $a_xml_writer->xmlStartTag(
"material");
166 $a_xml_writer->xmlElement(
"mattext", null, $answer->getAnswertext());
167 $a_xml_writer->xmlEndTag(
"material");
168 $a_xml_writer->xmlEndTag(
"response_label");
170 $a_xml_writer->xmlEndTag(
"render_hotspot");
171 $a_xml_writer->xmlEndTag(
"response_xy");
172 $a_xml_writer->xmlEndTag(
"flow");
173 $a_xml_writer->xmlEndTag(
"presentation");
176 $a_xml_writer->xmlStartTag(
"resprocessing");
177 $a_xml_writer->xmlStartTag(
"outcomes");
178 $a_xml_writer->xmlStartTag(
"decvar");
179 $a_xml_writer->xmlEndTag(
"decvar");
180 $a_xml_writer->xmlEndTag(
"outcomes");
182 foreach ($this->
object->getAnswers() as $index => $answer) {
186 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
188 $a_xml_writer->xmlStartTag(
"conditionvar");
189 if (!$answer->isStateSet()) {
190 $a_xml_writer->xmlStartTag(
"not");
193 switch ($answer->getArea()) {
195 $areatype =
"Rectangle";
198 $areatype =
"Ellipse";
201 $areatype =
"Bounded";
206 "areatype" => $areatype
208 $a_xml_writer->xmlElement(
"varequal", $attrs, $answer->getCoords());
209 if (!$answer->isStateSet()) {
210 $a_xml_writer->xmlEndTag(
"not");
212 $a_xml_writer->xmlEndTag(
"conditionvar");
217 $a_xml_writer->xmlElement(
"setvar", $attrs, $answer->getPoints());
218 $linkrefid =
"response_$index";
220 "feedbacktype" =>
"Response",
221 "linkrefid" => $linkrefid
223 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
224 $a_xml_writer->xmlEndTag(
"respcondition");
228 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
230 $a_xml_writer->xmlStartTag(
"conditionvar");
234 $a_xml_writer->xmlStartTag(
"not");
235 $a_xml_writer->xmlElement(
"varequal", $attrs, $answer->getCoords());
236 $a_xml_writer->xmlEndTag(
"not");
237 $a_xml_writer->xmlEndTag(
"conditionvar");
242 $a_xml_writer->xmlElement(
"setvar", $attrs, $answer->getPointsUnchecked());
243 $a_xml_writer->xmlEndTag(
"respcondition");
246 $answers = $this->
object->getAnswers();
247 $feedback_allcorrect = $this->
object->feedbackOBJ->getGenericFeedbackExportPresentation(
251 if (strlen($feedback_allcorrect) && count($answers) > 0) {
255 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
257 $a_xml_writer->xmlStartTag(
"conditionvar");
258 if (!$this->
object->getIsMultipleChoice()) {
261 foreach ($answers as $index => $answer) {
262 if ($answer->getPoints() > $maxpoints) {
263 $maxpoints = $answer->getPoints();
269 $answer = $answers[$bestindex];
270 switch ($answer->getArea()) {
272 $areatype =
"Rectangle";
275 $areatype =
"Ellipse";
278 $areatype =
"Bounded";
283 "areatype" => $areatype
285 $a_xml_writer->xmlElement(
"varinside", $attrs, $answer->getCoords());
287 foreach ($answers as $index => $answer) {
288 if ($answer->getPoints() < $answer->getPointsUnchecked()) {
289 $a_xml_writer->xmlStartTag(
"not");
291 switch ($answer->getArea()) {
293 $areatype =
"Rectangle";
296 $areatype =
"Ellipse";
299 $areatype =
"Bounded";
304 "areatype" => $areatype
306 $a_xml_writer->xmlElement(
"varequal", $attrs, $index);
307 if ($answer->getPoints() < $answer->getPointsUnchecked()) {
308 $a_xml_writer->xmlEndTag(
"not");
313 $a_xml_writer->xmlEndTag(
"conditionvar");
316 "feedbacktype" =>
"Response",
317 "linkrefid" =>
"response_allcorrect" 319 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
320 $a_xml_writer->xmlEndTag(
"respcondition");
323 $feedback_onenotcorrect = $this->
object->feedbackOBJ->getGenericFeedbackExportPresentation(
327 if (strlen($feedback_onenotcorrect) && count($answers) > 0) {
331 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
333 $a_xml_writer->xmlStartTag(
"conditionvar");
334 if (!$this->
object->getIsMultipleChoice()) {
337 foreach ($answers as $index => $answer) {
338 if ($answer->getPoints() > $maxpoints) {
339 $maxpoints = $answer->getPoints();
346 $a_xml_writer->xmlStartTag(
"not");
349 $answer = $answers[$bestindex];
350 switch ($answer->getArea()) {
352 $areatype =
"Rectangle";
355 $areatype =
"Ellipse";
358 $areatype =
"Bounded";
363 "areatype" => $areatype
365 $a_xml_writer->xmlElement(
"varinside", $attrs, $answer->getCoords());
367 $a_xml_writer->xmlEndTag(
"not");
369 foreach ($answers as $index => $answer) {
371 $a_xml_writer->xmlStartTag(
"or");
373 if ($answer->getPoints() >= $answer->getPointsUnchecked()) {
374 $a_xml_writer->xmlStartTag(
"not");
376 switch ($answer->getArea()) {
378 $areatype =
"Rectangle";
381 $areatype =
"Ellipse";
384 $areatype =
"Bounded";
389 "areatype" => $areatype
391 $a_xml_writer->xmlElement(
"varequal", $attrs, $index);
392 if ($answer->getPoints() >= $answer->getPointsUnchecked()) {
393 $a_xml_writer->xmlEndTag(
"not");
396 $a_xml_writer->xmlEndTag(
"or");
400 $a_xml_writer->xmlEndTag(
"conditionvar");
403 "feedbacktype" =>
"Response",
404 "linkrefid" =>
"response_onenotcorrect" 406 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
407 $a_xml_writer->xmlEndTag(
"respcondition");
410 $a_xml_writer->xmlEndTag(
"resprocessing");
413 foreach ($this->
object->getAnswers() as $index => $answer) {
414 $linkrefid =
"response_$index";
416 "ident" => $linkrefid,
419 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
421 $a_xml_writer->xmlStartTag(
"flow_mat");
422 $fb = $this->
object->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation(
427 $this->
object->addQTIMaterial($a_xml_writer, $fb);
428 $a_xml_writer->xmlEndTag(
"flow_mat");
429 $a_xml_writer->xmlEndTag(
"itemfeedback");
431 if (strlen($feedback_allcorrect)) {
433 "ident" =>
"response_allcorrect",
436 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
438 $a_xml_writer->xmlStartTag(
"flow_mat");
439 $this->
object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
440 $a_xml_writer->xmlEndTag(
"flow_mat");
441 $a_xml_writer->xmlEndTag(
"itemfeedback");
443 if (strlen($feedback_onenotcorrect)) {
445 "ident" =>
"response_onenotcorrect",
448 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
450 $a_xml_writer->xmlStartTag(
"flow_mat");
451 $this->
object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
452 $a_xml_writer->xmlEndTag(
"flow_mat");
453 $a_xml_writer->xmlEndTag(
"itemfeedback");
458 $a_xml_writer->xmlEndTag(
"item");
459 $a_xml_writer->xmlEndTag(
"questestinterop");
461 $xml = $a_xml_writer->xmlDumpMem(
false);
462 if (!$a_include_header) {
463 $pos = strpos(
$xml,
"?>");
toXML($a_include_header=true, $a_include_binary=true, $a_shuffle=false, $test_output=false, $force_image_references=false)
Returns a QTI xml representation of the question Returns a QTI xml representation of the question and...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addGeneralMetadata(ilXmlWriter $xmlwriter)
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
addAdditionalContentEditingModeInformation(ilXmlWriter $a_xml_writer)
adds a qti meta data field for ilias specific information of "additional content editing mode" (xml w...
addSolutionHints(ilXmlWriter $writer)
const IMAGEMAP_QUESTION_IDENTIFIER