36 public function toXML($a_include_header =
true, $a_include_binary =
true, $a_shuffle =
false, $test_output =
false, $force_image_references =
false): string
39 $ilias = $DIC[
'ilias'];
43 $a_xml_writer->xmlHeader();
44 $a_xml_writer->xmlStartTag(
"questestinterop");
46 "ident" =>
"il_" .
IL_INST_ID .
"_qst_" . $this->
object->getId(),
47 "title" => $this->
object->getTitle(),
48 "maxattempts" => $this->
object->getNrOfTries()
50 $a_xml_writer->xmlStartTag(
"item", $attrs);
52 $a_xml_writer->xmlElement(
"qticomment",
null, $this->
object->getComment());
53 $a_xml_writer->xmlStartTag(
"itemmetadata");
54 $a_xml_writer->xmlStartTag(
"qtimetadata");
55 $a_xml_writer->xmlStartTag(
"qtimetadatafield");
56 $a_xml_writer->xmlElement(
"fieldlabel",
null,
"ILIAS_VERSION");
57 $a_xml_writer->xmlElement(
"fieldentry",
null, $ilias->getSetting(
"ilias_version"));
58 $a_xml_writer->xmlEndTag(
"qtimetadatafield");
59 $a_xml_writer->xmlStartTag(
"qtimetadatafield");
60 $a_xml_writer->xmlElement(
"fieldlabel",
null,
"QUESTIONTYPE");
61 $a_xml_writer->xmlElement(
"fieldentry",
null, $this->
object->getQuestionType());
62 $a_xml_writer->xmlEndTag(
"qtimetadatafield");
63 $a_xml_writer->xmlStartTag(
"qtimetadatafield");
64 $a_xml_writer->xmlElement(
"fieldlabel",
null,
"IS_MULTIPLE_CHOICE");
65 $a_xml_writer->xmlElement(
"fieldentry",
null, ($this->
object->getIsMultipleChoice()) ?
"1" :
"0");
66 $a_xml_writer->xmlEndTag(
"qtimetadatafield");
67 $a_xml_writer->xmlStartTag(
"qtimetadatafield");
68 $a_xml_writer->xmlElement(
"fieldlabel",
null,
"AUTHOR");
69 $a_xml_writer->xmlElement(
"fieldentry",
null, $this->
object->getAuthor());
70 $a_xml_writer->xmlEndTag(
"qtimetadatafield");
76 $a_xml_writer->xmlEndTag(
"qtimetadata");
77 $a_xml_writer->xmlEndTag(
"itemmetadata");
81 "label" => $this->
object->getTitle()
83 $a_xml_writer->xmlStartTag(
"presentation", $attrs);
85 $a_xml_writer->xmlStartTag(
"flow");
91 "rcardinality" =>
"Single" 93 $a_xml_writer->xmlStartTag(
"response_xy", $attrs);
95 $a_xml_writer->xmlStartTag(
"render_hotspot");
96 $a_xml_writer->xmlStartTag(
"material");
97 $imagetype =
"image/jpeg";
98 if (preg_match(
"/.*\.(png|gif)$/i", $this->
object->getImageFilename(), $matches)) {
99 $imagetype =
"image/" . strtolower($matches[1]);
102 "imagtype" => $imagetype,
103 "label" => $this->
object->getImageFilename()
105 if ($a_include_binary) {
106 if ($force_image_references) {
107 $attrs[
"uri"] = $this->
object->getImagePathWeb() . $this->
object->getImageFilename();
108 $a_xml_writer->xmlElement(
"matimage", $attrs);
110 $attrs[
"embedded"] =
"base64";
111 $imagepath = $this->
object->getImagePath() . $this->
object->getImageFilename();
112 $fh = fopen($imagepath,
"rb");
118 $imagefile = fread($fh, filesize($imagepath));
120 $base64 = base64_encode($imagefile);
121 $a_xml_writer->xmlElement(
"matimage", $attrs, $base64,
false,
false);
124 $a_xml_writer->xmlElement(
"matimage", $attrs);
126 $a_xml_writer->xmlEndTag(
"material");
129 foreach ($this->
object->getAnswers() as $index => $answer) {
131 switch ($answer->getArea()) {
133 $rarea =
"Rectangle";
146 $a_xml_writer->xmlStartTag(
"response_label", $attrs);
147 $a_xml_writer->xmlData($answer->getCoords());
148 $a_xml_writer->xmlStartTag(
"material");
149 $a_xml_writer->xmlElement(
"mattext",
null, $answer->getAnswertext());
150 $a_xml_writer->xmlEndTag(
"material");
151 $a_xml_writer->xmlEndTag(
"response_label");
153 $a_xml_writer->xmlEndTag(
"render_hotspot");
154 $a_xml_writer->xmlEndTag(
"response_xy");
155 $a_xml_writer->xmlEndTag(
"flow");
156 $a_xml_writer->xmlEndTag(
"presentation");
159 $a_xml_writer->xmlStartTag(
"resprocessing");
160 $a_xml_writer->xmlStartTag(
"outcomes");
161 $a_xml_writer->xmlStartTag(
"decvar");
162 $a_xml_writer->xmlEndTag(
"decvar");
163 $a_xml_writer->xmlEndTag(
"outcomes");
165 foreach ($this->
object->getAnswers() as $index => $answer) {
169 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
171 $a_xml_writer->xmlStartTag(
"conditionvar");
172 if (!$answer->isStateSet()) {
173 $a_xml_writer->xmlStartTag(
"not");
176 switch ($answer->getArea()) {
178 $areatype =
"Rectangle";
181 $areatype =
"Ellipse";
184 $areatype =
"Bounded";
189 "areatype" => $areatype
191 $a_xml_writer->xmlElement(
"varequal", $attrs, $answer->getCoords());
192 if (!$answer->isStateSet()) {
193 $a_xml_writer->xmlEndTag(
"not");
195 $a_xml_writer->xmlEndTag(
"conditionvar");
200 $a_xml_writer->xmlElement(
"setvar", $attrs, $answer->getPoints());
201 $linkrefid =
"response_$index";
203 "feedbacktype" =>
"Response",
204 "linkrefid" => $linkrefid
206 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
207 $a_xml_writer->xmlEndTag(
"respcondition");
211 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
213 $a_xml_writer->xmlStartTag(
"conditionvar");
217 $a_xml_writer->xmlStartTag(
"not");
218 $a_xml_writer->xmlElement(
"varequal", $attrs, $answer->getCoords());
219 $a_xml_writer->xmlEndTag(
"not");
220 $a_xml_writer->xmlEndTag(
"conditionvar");
225 $a_xml_writer->xmlElement(
"setvar", $attrs, $answer->getPointsUnchecked());
226 $a_xml_writer->xmlEndTag(
"respcondition");
229 $answers = $this->
object->getAnswers();
230 $feedback_allcorrect = $this->
object->feedbackOBJ->getGenericFeedbackExportPresentation(
234 if (strlen($feedback_allcorrect) && count($answers) > 0) {
238 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
240 $a_xml_writer->xmlStartTag(
"conditionvar");
241 if (!$this->
object->getIsMultipleChoice()) {
244 foreach ($answers as $index => $answer) {
245 if ($answer->getPoints() > $maxpoints) {
246 $maxpoints = $answer->getPoints();
252 $answer = $answers[$bestindex];
253 switch ($answer->getArea()) {
255 $areatype =
"Rectangle";
258 $areatype =
"Ellipse";
261 $areatype =
"Bounded";
266 "areatype" => $areatype
268 $a_xml_writer->xmlElement(
"varinside", $attrs, $answer->getCoords());
270 foreach ($answers as $index => $answer) {
271 if ($answer->getPoints() < $answer->getPointsUnchecked()) {
272 $a_xml_writer->xmlStartTag(
"not");
274 switch ($answer->getArea()) {
276 $areatype =
"Rectangle";
279 $areatype =
"Ellipse";
282 $areatype =
"Bounded";
287 "areatype" => $areatype
289 $a_xml_writer->xmlElement(
"varequal", $attrs, $index);
290 if ($answer->getPoints() < $answer->getPointsUnchecked()) {
291 $a_xml_writer->xmlEndTag(
"not");
296 $a_xml_writer->xmlEndTag(
"conditionvar");
299 "feedbacktype" =>
"Response",
300 "linkrefid" =>
"response_allcorrect" 302 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
303 $a_xml_writer->xmlEndTag(
"respcondition");
306 $feedback_onenotcorrect = $this->
object->feedbackOBJ->getGenericFeedbackExportPresentation(
310 if (strlen($feedback_onenotcorrect) && count($answers) > 0) {
314 $a_xml_writer->xmlStartTag(
"respcondition", $attrs);
316 $a_xml_writer->xmlStartTag(
"conditionvar");
317 if (!$this->
object->getIsMultipleChoice()) {
320 foreach ($answers as $index => $answer) {
321 if ($answer->getPoints() > $maxpoints) {
322 $maxpoints = $answer->getPoints();
329 $a_xml_writer->xmlStartTag(
"not");
332 $answer = $answers[$bestindex];
333 switch ($answer->getArea()) {
335 $areatype =
"Rectangle";
338 $areatype =
"Ellipse";
341 $areatype =
"Bounded";
346 "areatype" => $areatype
348 $a_xml_writer->xmlElement(
"varinside", $attrs, $answer->getCoords());
350 $a_xml_writer->xmlEndTag(
"not");
352 foreach ($answers as $index => $answer) {
354 $a_xml_writer->xmlStartTag(
"or");
356 if ($answer->getPoints() >= $answer->getPointsUnchecked()) {
357 $a_xml_writer->xmlStartTag(
"not");
359 switch ($answer->getArea()) {
361 $areatype =
"Rectangle";
364 $areatype =
"Ellipse";
367 $areatype =
"Bounded";
372 "areatype" => $areatype
374 $a_xml_writer->xmlElement(
"varequal", $attrs, $index);
375 if ($answer->getPoints() >= $answer->getPointsUnchecked()) {
376 $a_xml_writer->xmlEndTag(
"not");
379 $a_xml_writer->xmlEndTag(
"or");
383 $a_xml_writer->xmlEndTag(
"conditionvar");
386 "feedbacktype" =>
"Response",
387 "linkrefid" =>
"response_onenotcorrect" 389 $a_xml_writer->xmlElement(
"displayfeedback", $attrs);
390 $a_xml_writer->xmlEndTag(
"respcondition");
393 $a_xml_writer->xmlEndTag(
"resprocessing");
396 foreach ($this->
object->getAnswers() as $index => $answer) {
397 $linkrefid =
"response_$index";
399 "ident" => $linkrefid,
402 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
404 $a_xml_writer->xmlStartTag(
"flow_mat");
405 $fb = $this->
object->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation(
411 $a_xml_writer->xmlEndTag(
"flow_mat");
412 $a_xml_writer->xmlEndTag(
"itemfeedback");
414 if (strlen($feedback_allcorrect)) {
416 "ident" =>
"response_allcorrect",
419 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
421 $a_xml_writer->xmlStartTag(
"flow_mat");
423 $a_xml_writer->xmlEndTag(
"flow_mat");
424 $a_xml_writer->xmlEndTag(
"itemfeedback");
426 if (strlen($feedback_onenotcorrect)) {
428 "ident" =>
"response_onenotcorrect",
431 $a_xml_writer->xmlStartTag(
"itemfeedback", $attrs);
433 $a_xml_writer->xmlStartTag(
"flow_mat");
435 $a_xml_writer->xmlEndTag(
"flow_mat");
436 $a_xml_writer->xmlEndTag(
"itemfeedback");
441 $a_xml_writer->xmlEndTag(
"item");
442 $a_xml_writer->xmlEndTag(
"questestinterop");
444 $xml = $a_xml_writer->xmlDumpMem(
false);
445 if (!$a_include_header) {
446 $pos = strpos($xml,
"?>");
447 $xml = substr($xml, $pos + 2);
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...
addQTIMaterial(ilXmlWriter $a_xml_writer, string $a_material, bool $close_material_tag=true, bool $add_mobs=true)
Class for question exports.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addGeneralMetadata(ilXmlWriter $xmlwriter)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
addAdditionalContentEditingModeInformation(ilXmlWriter $a_xml_writer)
adds a qti meta data field for ilias specific information of "additional content editing mode" (xml w...
addSuggestedSolution(ilXmlWriter $writer)
addSolutionHints(ilXmlWriter $writer)