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