ILIAS  release_8 Revision v8.24
class.assMatchingQuestionExport.php
Go to the documentation of this file.
1<?php
28{
34 public function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false): string
35 {
36 global $DIC;
37 $ilias = $DIC['ilias'];
38
39 include_once("./Services/Xml/classes/class.ilXmlWriter.php");
40 $a_xml_writer = new ilXmlWriter();
41 // set xml header
42 $a_xml_writer->xmlHeader();
43 $a_xml_writer->xmlStartTag("questestinterop");
44 $attrs = array(
45 "ident" => "il_" . IL_INST_ID . "_qst_" . $this->object->getId(),
46 "title" => $this->object->getTitle(),
47 "maxattempts" => $this->object->getNrOfTries()
48 );
49 $a_xml_writer->xmlStartTag("item", $attrs);
50 // add question description
51 $a_xml_writer->xmlElement("qticomment", null, $this->object->getComment());
52 $a_xml_writer->xmlStartTag("itemmetadata");
53 $a_xml_writer->xmlStartTag("qtimetadata");
54 $a_xml_writer->xmlStartTag("qtimetadatafield");
55 $a_xml_writer->xmlElement("fieldlabel", null, "ILIAS_VERSION");
56 $a_xml_writer->xmlElement("fieldentry", null, $ilias->getSetting("ilias_version"));
57 $a_xml_writer->xmlEndTag("qtimetadatafield");
58 $a_xml_writer->xmlStartTag("qtimetadatafield");
59 $a_xml_writer->xmlElement("fieldlabel", null, "QUESTIONTYPE");
60 $a_xml_writer->xmlElement("fieldentry", null, MATCHING_QUESTION_IDENTIFIER);
61 $a_xml_writer->xmlEndTag("qtimetadatafield");
62 $a_xml_writer->xmlStartTag("qtimetadatafield");
63 $a_xml_writer->xmlElement("fieldlabel", null, "AUTHOR");
64 $a_xml_writer->xmlElement("fieldentry", null, $this->object->getAuthor());
65 $a_xml_writer->xmlEndTag("qtimetadatafield");
66
67 // additional content editing information
69 $this->addGeneralMetadata($a_xml_writer);
70
71 $a_xml_writer->xmlStartTag("qtimetadatafield");
72 $a_xml_writer->xmlElement("fieldlabel", null, "shuffle");
73 $a_xml_writer->xmlElement("fieldentry", null, $this->object->getShuffle());
74 $a_xml_writer->xmlEndTag("qtimetadatafield");
75 $a_xml_writer->xmlStartTag("qtimetadatafield");
76 $a_xml_writer->xmlElement("fieldlabel", null, "thumb_geometry");
77 $a_xml_writer->xmlElement("fieldentry", null, $this->object->getThumbGeometry());
78 $a_xml_writer->xmlEndTag("qtimetadatafield");
79 $a_xml_writer->xmlStartTag("qtimetadatafield");
80 $a_xml_writer->xmlElement("fieldlabel", null, 'matching_mode');
81 $a_xml_writer->xmlElement("fieldentry", null, $this->object->getMatchingMode());
82 $a_xml_writer->xmlEndTag("qtimetadatafield");
83 $a_xml_writer->xmlEndTag("qtimetadata");
84 $a_xml_writer->xmlEndTag("itemmetadata");
85
86 // PART I: qti presentation
87 $attrs = array(
88 "label" => $this->object->getTitle()
89 );
90 $a_xml_writer->xmlStartTag("presentation", $attrs);
91 // add flow to presentation
92 $a_xml_writer->xmlStartTag("flow");
93 // add material with question text to presentation
94 $this->object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
95 // add answers to presentation
96 $attrs = array(
97 "ident" => "MQ",
98 "rcardinality" => "Multiple"
99 );
100 $a_xml_writer->xmlStartTag("response_grp", $attrs);
101 $solution = $this->object->getSuggestedSolution(0);
102 if ($solution !== null && count($solution)) {
103 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches)) {
104 $a_xml_writer->xmlStartTag("material");
105 $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
106 if (strcmp($matches[1], "") != 0) {
107 $intlink = $solution["internal_link"];
108 }
109 $attrs = array(
110 "label" => "suggested_solution"
111 );
112 $a_xml_writer->xmlElement("mattext", $attrs, $intlink);
113 $a_xml_writer->xmlEndTag("material");
114 }
115 }
116 // shuffle output
117 $attrs = array();
118 if ($this->object->getShuffle()) {
119 $attrs = array(
120 "shuffle" => "Yes"
121 );
122 } else {
123 $attrs = array(
124 "shuffle" => "No"
125 );
126 }
127 $a_xml_writer->xmlStartTag("render_choice", $attrs);
128 // add answertext
129 $matchingtext_orders = array();
130 foreach ($this->object->getMatchingPairs() as $index => $matchingpair) {
131 array_push($matchingtext_orders, $matchingpair->getTerm()->getIdentifier());
132 }
133
134 $termids = array();
135 foreach ($this->object->getTerms() as $term) {
136 array_push($termids, $term->getidentifier());
137 }
138 // add answers
139 foreach ($this->object->getDefinitions() as $definition) {
140 $attrs = array(
141 "ident" => $definition->getIdentifier(),
142 "match_max" => "1",
143 "match_group" => join(",", $termids)
144 );
145 $a_xml_writer->xmlStartTag("response_label", $attrs);
146 $a_xml_writer->xmlStartTag("material");
147 if (strlen($definition->getPicture())) {
148 if ($force_image_references) {
149 $attrs = array(
150 "imagtype" => "image/jpeg",
151 "label" => $definition->getPicture(),
152 "uri" => $this->object->getImagePathWeb() . $definition->getPicture()
153 );
154 $a_xml_writer->xmlElement("matimage", $attrs);
155 } else {
156 $imagepath = $this->object->getImagePath() . $definition->getPicture();
157 $fh = @fopen($imagepath, "rb");
158 if ($fh != false) {
159 $imagefile = fread($fh, filesize($imagepath));
160 fclose($fh);
161 $base64 = base64_encode($imagefile);
162 $attrs = array(
163 "imagtype" => "image/jpeg",
164 "label" => $definition->getPicture(),
165 "embedded" => "base64"
166 );
167 $a_xml_writer->xmlElement("matimage", $attrs, $base64, false, false);
168 }
169 }
170 }
171 if (strlen($definition->getText())) {
172 $attrs = array(
173 "texttype" => "text/plain"
174 );
175 if ($this->object->isHTML($definition->getText())) {
176 $attrs["texttype"] = "text/xhtml";
177 }
178 $a_xml_writer->xmlElement("mattext", $attrs, $definition->getText());
179 }
180 $a_xml_writer->xmlEndTag("material");
181 $a_xml_writer->xmlEndTag("response_label");
182 }
183 // add matchingtext
184 foreach ($this->object->getTerms() as $term) {
185 $attrs = array(
186 "ident" => $term->getIdentifier()
187 );
188 $a_xml_writer->xmlStartTag("response_label", $attrs);
189 $a_xml_writer->xmlStartTag("material");
190 if (strlen($term->getPicture())) {
191 if ($force_image_references) {
192 $attrs = array(
193 "imagtype" => "image/jpeg",
194 "label" => $term->getPicture(),
195 "uri" => $this->object->getImagePathWeb() . $term->getPicture()
196 );
197 $a_xml_writer->xmlElement("matimage", $attrs);
198 } else {
199 $imagepath = $this->object->getImagePath() . $term->getPicture();
200 $fh = @fopen($imagepath, "rb");
201 if ($fh != false) {
202 $imagefile = fread($fh, filesize($imagepath));
203 fclose($fh);
204 $base64 = base64_encode($imagefile);
205 $attrs = array(
206 "imagtype" => "image/jpeg",
207 "label" => $term->getPicture(),
208 "embedded" => "base64"
209 );
210 $a_xml_writer->xmlElement("matimage", $attrs, $base64, false, false);
211 }
212 }
213 }
214 if (strlen($term->getText())) {
215 $attrs = array(
216 "texttype" => "text/plain"
217 );
218 if ($this->object->isHTML($term->getText())) {
219 $attrs["texttype"] = "text/xhtml";
220 }
221 $a_xml_writer->xmlElement("mattext", $attrs, $term->getText());
222 }
223 $a_xml_writer->xmlEndTag("material");
224 $a_xml_writer->xmlEndTag("response_label");
225 }
226 $a_xml_writer->xmlEndTag("render_choice");
227 $a_xml_writer->xmlEndTag("response_grp");
228 $a_xml_writer->xmlEndTag("flow");
229 $a_xml_writer->xmlEndTag("presentation");
230
231 // PART II: qti resprocessing
232 $a_xml_writer->xmlStartTag("resprocessing");
233 $a_xml_writer->xmlStartTag("outcomes");
234 $a_xml_writer->xmlStartTag("decvar");
235 $a_xml_writer->xmlEndTag("decvar");
236 $a_xml_writer->xmlEndTag("outcomes");
237 // add response conditions
238 foreach ($this->object->getMatchingPairs() as $matchingpair) {
239 $attrs = array(
240 "continue" => "Yes"
241 );
242 $a_xml_writer->xmlStartTag("respcondition", $attrs);
243 // qti conditionvar
244 $a_xml_writer->xmlStartTag("conditionvar");
245 $attrs = array(
246 "respident" => "MQ"
247 );
248 $a_xml_writer->xmlElement("varsubset", $attrs, $matchingpair->getTerm()->getIdentifier() . "," . $matchingpair->getDefinition()->getidentifier());
249 $a_xml_writer->xmlEndTag("conditionvar");
250
251 // qti setvar
252 $attrs = array(
253 "action" => "Add"
254 );
255 $a_xml_writer->xmlElement("setvar", $attrs, $matchingpair->getPoints());
256 // qti displayfeedback
257 $attrs = array(
258 "feedbacktype" => "Response",
259 "linkrefid" => "correct_" . $matchingpair->getTerm()->getIdentifier() . "_" . $matchingpair->getDefinition()->getIdentifier()
260 );
261 $a_xml_writer->xmlElement("displayfeedback", $attrs);
262 $a_xml_writer->xmlEndTag("respcondition");
263 }
264
265 $feedback_allcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
266 $this->object->getId(),
267 true
268 );
269 if (strlen($feedback_allcorrect)) {
270 $attrs = array(
271 "continue" => "Yes"
272 );
273 $a_xml_writer->xmlStartTag("respcondition", $attrs);
274 // qti conditionvar
275 $a_xml_writer->xmlStartTag("conditionvar");
276
277 foreach ($this->object->getMatchingPairs() as $matchingpair) {
278 $attrs = array(
279 "respident" => "MQ"
280 );
281 $a_xml_writer->xmlElement("varsubset", $attrs, $matchingpair->getTerm()->getIdentifier() . "," . $matchingpair->getDefinition()->getIdentifier());
282 }
283 $a_xml_writer->xmlEndTag("conditionvar");
284 // qti displayfeedback
285 $attrs = array(
286 "feedbacktype" => "Response",
287 "linkrefid" => "response_allcorrect"
288 );
289 $a_xml_writer->xmlElement("displayfeedback", $attrs);
290 $a_xml_writer->xmlEndTag("respcondition");
291 }
292 $feedback_onenotcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
293 $this->object->getId(),
294 false
295 );
296 if (strlen($feedback_onenotcorrect)) {
297 $attrs = array(
298 "continue" => "Yes"
299 );
300 $a_xml_writer->xmlStartTag("respcondition", $attrs);
301 // qti conditionvar
302 $a_xml_writer->xmlStartTag("conditionvar");
303 $a_xml_writer->xmlStartTag("not");
304 foreach ($this->object->getMatchingPairs() as $matchingpair) {
305 $attrs = array(
306 "respident" => "MQ"
307 );
308 $a_xml_writer->xmlElement("varsubset", $attrs, $matchingpair->getTerm()->getIdentifier() . "," . $matchingpair->getDefinition()->getIdentifier());
309 }
310 $a_xml_writer->xmlEndTag("not");
311 $a_xml_writer->xmlEndTag("conditionvar");
312 // qti displayfeedback
313 $attrs = array(
314 "feedbacktype" => "Response",
315 "linkrefid" => "response_onenotcorrect"
316 );
317 $a_xml_writer->xmlElement("displayfeedback", $attrs);
318 $a_xml_writer->xmlEndTag("respcondition");
319 }
320
321 $a_xml_writer->xmlEndTag("resprocessing");
322
323 // PART III: qti itemfeedback
324 foreach ($this->object->getMatchingPairs() as $index => $matchingpair) {
325 $attrs = array(
326 "ident" => "correct_" . $matchingpair->getTerm()->getIdentifier() . "_" . $matchingpair->getDefinition()->getIdentifier(),
327 "view" => "All"
328 );
329 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
330 // qti flow_mat
331 $a_xml_writer->xmlStartTag("flow_mat");
332 $a_xml_writer->xmlStartTag("material");
333 $a_xml_writer->xmlElement("mattext", null, $this->object->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation(
334 $this->object->getId(),
335 0,
336 $index
337 ));
338 $a_xml_writer->xmlEndTag("material");
339 $a_xml_writer->xmlEndTag("flow_mat");
340 $a_xml_writer->xmlEndTag("itemfeedback");
341 }
342
343 if (strlen($feedback_allcorrect)) {
344 $attrs = array(
345 "ident" => "response_allcorrect",
346 "view" => "All"
347 );
348 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
349 // qti flow_mat
350 $a_xml_writer->xmlStartTag("flow_mat");
351 $this->object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
352 $a_xml_writer->xmlEndTag("flow_mat");
353 $a_xml_writer->xmlEndTag("itemfeedback");
354 }
355 if (strlen($feedback_onenotcorrect)) {
356 $attrs = array(
357 "ident" => "response_onenotcorrect",
358 "view" => "All"
359 );
360 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
361 // qti flow_mat
362 $a_xml_writer->xmlStartTag("flow_mat");
363 $this->object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
364 $a_xml_writer->xmlEndTag("flow_mat");
365 $a_xml_writer->xmlEndTag("itemfeedback");
366 }
367
368 $a_xml_writer = $this->addSolutionHints($a_xml_writer);
369
370 $a_xml_writer->xmlEndTag("item");
371 $a_xml_writer->xmlEndTag("questestinterop");
372
373 $xml = $a_xml_writer->xmlDumpMem(false);
374 if (!$a_include_header) {
375 $pos = strpos($xml, "?>");
376 $xml = substr($xml, $pos + 2);
377 }
378 return $xml;
379 }
380}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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...
addGeneralMetadata(ilXmlWriter $xmlwriter)
addSolutionHints(ilXmlWriter $writer)
addAdditionalContentEditingModeInformation(ilXmlWriter $a_xml_writer)
adds a qti meta data field for ilias specific information of "additional content editing mode" (xml w...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const IL_INST_ID
Definition: constants.php:40
global $DIC
Definition: feed.php:28
const MATCHING_QUESTION_IDENTIFIER
$index
Definition: metadata.php:145
$xml
Definition: metadata.php:351