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
27 {
30 global $ilias;
31
32 include_once("./Services/Xml/classes/class.ilXmlWriter.php");
34
36 $a_xml_writer->xmlStartTag("questestinterop");
37 $attrs = array(
38 "ident" => "il_".IL_INST_ID."_qst_".$this->object->getId(),
39 "title" => $this->object->getTitle(),
40 "maxattempts" => $this->object->getNrOfTries()
41 );
42 $a_xml_writer->xmlStartTag("item", $attrs);
43
44 $a_xml_writer->xmlElement("qticomment", NULL, $this->object->getComment());
45
46 $workingtime = $this->object->getEstimatedWorkingTime();
47 $duration = sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]);
48 $a_xml_writer->xmlElement("duration", NULL, $duration);
49
50 $a_xml_writer->xmlStartTag("itemmetadata");
51 $a_xml_writer->xmlStartTag("qtimetadata");
52 $a_xml_writer->xmlStartTag("qtimetadatafield");
53 $a_xml_writer->xmlElement("fieldlabel", NULL, "ILIAS_VERSION");
54 $a_xml_writer->xmlElement("fieldentry", NULL, $ilias->getSetting("ilias_version"));
55 $a_xml_writer->xmlEndTag("qtimetadatafield");
56 $a_xml_writer->xmlStartTag("qtimetadatafield");
57 $a_xml_writer->xmlElement("fieldlabel", NULL, "QUESTIONTYPE");
59 $a_xml_writer->xmlEndTag("qtimetadatafield");
60 $a_xml_writer->xmlStartTag("qtimetadatafield");
61 $a_xml_writer->xmlElement("fieldlabel", NULL, "AUTHOR");
62 $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getAuthor());
63 $a_xml_writer->xmlEndTag("qtimetadatafield");
64
65
68
69 $a_xml_writer->xmlStartTag("qtimetadatafield");
70 $a_xml_writer->xmlElement("fieldlabel", NULL, "thumb_geometry");
71 $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getThumbGeometry());
72 $a_xml_writer->xmlEndTag("qtimetadatafield");
73 $a_xml_writer->xmlStartTag("qtimetadatafield");
74 $a_xml_writer->xmlElement("fieldlabel", NULL, "element_height");
75 $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getElementHeight());
76 $a_xml_writer->xmlEndTag("qtimetadatafield");
77 $a_xml_writer->xmlStartTag("qtimetadatafield");
78 $a_xml_writer->xmlElement("fieldlabel", NULL, "points");
79 $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getPoints());
80 $a_xml_writer->xmlEndTag("qtimetadatafield");
81 $a_xml_writer->xmlEndTag("qtimetadata");
82 $a_xml_writer->xmlEndTag("itemmetadata");
83
84
85 $attrs = array(
86 "label" => $this->object->getTitle()
87 );
88 $a_xml_writer->xmlStartTag("presentation", $attrs);
89
90 $a_xml_writer->xmlStartTag("flow");
91
92 $this->object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
93
94 $attrs = array();
95
96 if ($this->object->getOrderingType() ==
OQ_PICTURES)
97 $ordering_type ='OQP';
99 $ordering_type ='OQNP';
101 $ordering_type ='OQNT';
102 else if($this->object->getOrderingType() ==
OQ_TERMS)
103 $ordering_type ='OQT';
104
105 $attrs = array(
106 "ident" => $ordering_type,
107 "rcardinality" => "Ordered"
108 );
109
111 {
112 $attrs["output"] = "javascript";
113 }
114 $a_xml_writer->xmlStartTag("response_lid", $attrs);
115 $solution = $this->object->getSuggestedSolution(0);
116 if (count($solution))
117 {
118 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches))
119 {
120 $a_xml_writer->xmlStartTag("material");
121 $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
122 if (strcmp($matches[1], "") != 0)
123 {
124 $intlink = $solution["internal_link"];
125 }
126 $attrs = array(
127 "label" => "suggested_solution"
128 );
129 $a_xml_writer->xmlElement("mattext", $attrs, $intlink);
130 $a_xml_writer->xmlEndTag("material");
131 }
132 }
133
134 $attrs = array();
135 if ($this->object->getShuffle())
136 {
137 $attrs = array(
138 "shuffle" => "Yes"
139 );
140 }
141 else
142 {
143 $attrs = array(
144 "shuffle" => "No"
145 );
146 }
147 $a_xml_writer->xmlStartTag("render_choice", $attrs);
148
149 $akeys = array_keys($this->object->getAnswers());
150 if ($this->object->getShuffle() && $a_shuffle)
151 {
152 $akeys = $this->object->pcArrayShuffle($akeys);
153 }
154
155
156 foreach ($akeys as $index)
157 {
158 $answer = $this->object->getAnswer($index);
159 $attrs = array(
160 "ident" => $index
161 );
162 $a_xml_writer->xmlStartTag("response_label", $attrs);
163 if ($this->object->getOrderingType() ==
OQ_PICTURES
165 {
166 $imagetype = "image/jpeg";
167
168 $a_xml_writer->xmlStartTag("material");
169 if ($force_image_references)
170 {
171 $attrs = array(
172 "imagtype" => $imagetype,
173 "label" => $answer->getAnswertext(),
174 "uri" => $this->object->getImagePathWeb() . $answer->getAnswertext()
175 );
176 $a_xml_writer->xmlElement("matimage", $attrs);
177 }
178 else
179 {
180 $imagepath = $this->object->getImagePath() . $answer->getAnswertext();
181 $fh = @fopen($imagepath, "rb");
182 if ($fh != false)
183 {
184 $imagefile = fread($fh, filesize($imagepath));
185 fclose($fh);
186 $base64 = base64_encode($imagefile);
187
188 if (preg_match("/.*\.(png|gif)$/", $answer->getAnswertext(), $matches))
189 {
190 $imagetype = "image/".$matches[1];
191 }
192 $attrs = array(
193 "imagtype" => $imagetype,
194 "label" => $answer->getAnswertext(),
195 "embedded" => "base64"
196 );
197 $a_xml_writer->xmlElement("matimage", $attrs, $base64, FALSE, FALSE);
198 }
199 }
200 $a_xml_writer->xmlEndTag("material");
201 }
202 else if ($this->object->getOrderingType() ==
OQ_TERMS
204 {
205 $a_xml_writer->xmlStartTag("material");
206 $this->object->addQTIMaterial($a_xml_writer, $answer->getAnswertext(), TRUE, FALSE);
207 $a_xml_writer->xmlEndTag("material");
208 $a_xml_writer->xmlStartTag("material");
209 if ($this->object->getOldLeveledOrdering())
210 {
211 $attrs = array(
212 "label" => "answerdepth"
213 );
214 $a_xml_writer->xmlElement("mattext", $attrs, $answer->getOrderingDepth());
215 }
216 $a_xml_writer->xmlEndTag("material");
217 }
218 $a_xml_writer->xmlEndTag("response_label");
219 }
220 $a_xml_writer->xmlEndTag("render_choice");
221 $a_xml_writer->xmlEndTag("response_lid");
222 $a_xml_writer->xmlEndTag("flow");
223 $a_xml_writer->xmlEndTag("presentation");
224
225
226 $a_xml_writer->xmlStartTag("resprocessing");
227 $a_xml_writer->xmlStartTag("outcomes");
228 $a_xml_writer->xmlStartTag("decvar");
229 $a_xml_writer->xmlEndTag("decvar");
230 $a_xml_writer->xmlEndTag("outcomes");
231
232 foreach ($this->object->getAnswers() as $index => $answer)
233 {
234 $attrs = array(
235 "continue" => "Yes"
236 );
237 $a_xml_writer->xmlStartTag("respcondition", $attrs);
238
239 $a_xml_writer->xmlStartTag("conditionvar");
240 $attrs = array();
241
242 if ($this->object->getOrderingType() ==
OQ_PICTURES)
243 $ordering_type ='OQP';
245 $ordering_type ='OQNP';
247 $ordering_type ='OQNT';
248 else if($this->object->getOrderingType() ==
OQ_TERMS)
249 $ordering_type ='OQT';
250
251 $attrs = array("respident" => $ordering_type);
252
253 $attrs["index"] = $index;
254 $a_xml_writer->xmlElement("varequal", $attrs, $index);
255 $a_xml_writer->xmlEndTag("conditionvar");
256
257 $attrs = array(
258 "action" => "Add"
259 );
260 $a_xml_writer->xmlElement("setvar", $attrs, $this->object->getPoints() / count($this->object->getAnswers()));
261
262 $attrs = array(
263 "feedbacktype" => "Response",
264 "linkrefid" => "link_$index"
265 );
266 $a_xml_writer->xmlElement("displayfeedback", $attrs);
267 $a_xml_writer->xmlEndTag("respcondition");
268 }
269
270 $feedback_allcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
271 $this->object->getId(), true
272 );
273 if (strlen($feedback_allcorrect))
274 {
275 $attrs = array(
276 "continue" => "Yes"
277 );
278 $a_xml_writer->xmlStartTag("respcondition", $attrs);
279
280 $a_xml_writer->xmlStartTag("conditionvar");
281
282 foreach ($this->object->getAnswers() as $index => $answer)
283 {
284 $attrs = array();
285
286 if ($this->object->getOrderingType() ==
OQ_PICTURES)
287 $ordering_type ='OQP';
289 $ordering_type ='OQNP';
291 $ordering_type ='OQNT';
292 else if($this->object->getOrderingType() ==
OQ_TERMS)
293 $ordering_type ='OQT';
294
295 $attrs = array("respident" => $ordering_type);
296
297 $attrs["index"] = $index;
298 $a_xml_writer->xmlElement("varequal", $attrs, $index);
299 }
300
301 $a_xml_writer->xmlEndTag("conditionvar");
302
303 $attrs = array(
304 "feedbacktype" => "Response",
305 "linkrefid" => "response_allcorrect"
306 );
307 $a_xml_writer->xmlElement("displayfeedback", $attrs);
308 $a_xml_writer->xmlEndTag("respcondition");
309 }
310
311 $feedback_onenotcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
312 $this->object->getId(), false
313 );
314 if (strlen($feedback_onenotcorrect))
315 {
316 $attrs = array(
317 "continue" => "Yes"
318 );
319 $a_xml_writer->xmlStartTag("respcondition", $attrs);
320
321 $a_xml_writer->xmlStartTag("conditionvar");
322 $a_xml_writer->xmlStartTag("not");
323
324 foreach ($this->object->getAnswers() as $index => $answer)
325 {
326 $attrs = array();
327 if ($this->object->getOrderingType() ==
OQ_PICTURES)
328 $ordering_type ='OQP';
330 $ordering_type ='OQNP';
332 $ordering_type ='OQNT';
333 else if($this->object->getOrderingType() ==
OQ_TERMS)
334 $ordering_type ='OQT';
335
336 $attrs = array("respident" => $ordering_type);
337
338 $attrs["index"] = $index;
339 $a_xml_writer->xmlElement("varequal", $attrs, $index);
340 }
341
342 $a_xml_writer->xmlEndTag("not");
343 $a_xml_writer->xmlEndTag("conditionvar");
344
345 $attrs = array(
346 "feedbacktype" => "Response",
347 "linkrefid" => "response_onenotcorrect"
348 );
349 $a_xml_writer->xmlElement("displayfeedback", $attrs);
350 $a_xml_writer->xmlEndTag("respcondition");
351 }
352
353 $a_xml_writer->xmlEndTag("resprocessing");
354
355
356 foreach ($this->object->getAnswers() as $index => $answer)
357 {
358 $attrs = array(
359 "ident" => "link_$index",
360 "view" => "All"
361 );
362 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
363
364 $a_xml_writer->xmlStartTag("flow_mat");
365 $a_xml_writer->xmlStartTag("material");
366 $a_xml_writer->xmlElement("mattext");
367 $a_xml_writer->xmlEndTag("material");
368 $a_xml_writer->xmlEndTag("flow_mat");
369 $a_xml_writer->xmlEndTag("itemfeedback");
370 }
371
372 if (strlen($feedback_allcorrect))
373 {
374 $attrs = array(
375 "ident" => "response_allcorrect",
376 "view" => "All"
377 );
378 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
379
380 $a_xml_writer->xmlStartTag("flow_mat");
381 $this->object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
382 $a_xml_writer->xmlEndTag("flow_mat");
383 $a_xml_writer->xmlEndTag("itemfeedback");
384 }
385 if (strlen($feedback_onenotcorrect))
386 {
387 $attrs = array(
388 "ident" => "response_onenotcorrect",
389 "view" => "All"
390 );
391 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
392
393 $a_xml_writer->xmlStartTag("flow_mat");
394 $this->object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
395 $a_xml_writer->xmlEndTag("flow_mat");
396 $a_xml_writer->xmlEndTag("itemfeedback");
397 }
398
399 $a_xml_writer->xmlEndTag("item");
400 $a_xml_writer->xmlEndTag("questestinterop");
401
402 $xml = $a_xml_writer->xmlDumpMem(FALSE);
403 if (!$a_include_header)
404 {
405 $pos = strpos($xml, "?>");
406 $xml = substr($xml, $pos + 2);
407 }
408 return $xml;
409 }
addGeneralMetadata(ilXmlWriter $xmlwriter)
addAdditionalContentEditingModeInformation(ilXmlWriter $a_xml_writer)
adds a qti meta data field for ilias specific information of "additional content editing mode" (xml w...
xmlHeader()
Writes xml header @access public.
const OQ_PICTURES
Ordering question constants.
const ORDERING_QUESTION_IDENTIFIER