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 {
28 global $ilias;
29
30 include_once("./Services/Xml/classes/class.ilXmlWriter.php");
32
34 $a_xml_writer->xmlStartTag("questestinterop");
35 $attrs = array(
36 "ident" => "il_".IL_INST_ID."_qst_".$this->object->getId(),
37 "title" => $this->object->getTitle(),
38 "maxattempts" => $this->object->getNrOfTries()
39 );
40 $a_xml_writer->xmlStartTag("item", $attrs);
41
42 $a_xml_writer->xmlElement("qticomment", NULL, $this->object->getComment());
43
44 $workingtime = $this->object->getEstimatedWorkingTime();
45 $duration =
sprintf(
"P0Y0M0DT%dH%dM%dS", $workingtime[
"h"], $workingtime[
"m"], $workingtime[
"s"]);
46 $a_xml_writer->xmlElement(
"duration", NULL,
$duration);
47
48 $a_xml_writer->xmlStartTag("itemmetadata");
49 $a_xml_writer->xmlStartTag("qtimetadata");
50 $a_xml_writer->xmlStartTag("qtimetadatafield");
51 $a_xml_writer->xmlElement("fieldlabel", NULL, "ILIAS_VERSION");
52 $a_xml_writer->xmlElement("fieldentry", NULL, $ilias->getSetting("ilias_version"));
53 $a_xml_writer->xmlEndTag("qtimetadatafield");
54 $a_xml_writer->xmlStartTag("qtimetadatafield");
55 $a_xml_writer->xmlElement("fieldlabel", NULL, "QUESTIONTYPE");
57 $a_xml_writer->xmlEndTag("qtimetadatafield");
58 $a_xml_writer->xmlStartTag("qtimetadatafield");
59 $a_xml_writer->xmlElement("fieldlabel", NULL, "AUTHOR");
60 $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getAuthor());
61 $a_xml_writer->xmlEndTag("qtimetadatafield");
62
63
66
67 $a_xml_writer->xmlStartTag("qtimetadatafield");
68 $a_xml_writer->xmlElement("fieldlabel", NULL, "thumb_size");
69 $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getThumbSize());
70 $a_xml_writer->xmlEndTag("qtimetadatafield");
71
72 $a_xml_writer->xmlStartTag("qtimetadatafield");
73 $a_xml_writer->xmlElement("fieldlabel", NULL, "feedback_setting");
74 $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getSpecificFeedbackSetting());
75 $a_xml_writer->xmlEndTag("qtimetadatafield");
76
77 $this->
addQtiMetaDataField($a_xml_writer,
'singleline', $this->object->isSingleline ? 1 : 0);
78
79 $a_xml_writer->xmlEndTag("qtimetadata");
80 $a_xml_writer->xmlEndTag("itemmetadata");
81
82
83 $attrs = array(
84 "label" => $this->object->getTitle()
85 );
86 $a_xml_writer->xmlStartTag("presentation", $attrs);
87
88 $a_xml_writer->xmlStartTag("flow");
89
90 $this->object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
91
92 $attrs = array();
93 $attrs = array(
94 "ident" => "MCSR",
95 "rcardinality" => "Single"
96 );
97 $a_xml_writer->xmlStartTag("response_lid", $attrs);
98 $solution = $this->object->getSuggestedSolution(0);
99 if (count($solution))
100 {
101 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches))
102 {
103 $a_xml_writer->xmlStartTag("material");
104 $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
105 if (strcmp($matches[1], "") != 0)
106 {
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
117 $attrs = array();
118 if ($this->object->getShuffle())
119 {
120 $attrs = array(
121 "shuffle" => "Yes"
122 );
123 }
124 else
125 {
126 $attrs = array(
127 "shuffle" => "No"
128 );
129 }
130 $a_xml_writer->xmlStartTag("render_choice", $attrs);
131 $answers =& $this->object->getAnswers();
132 $akeys = array_keys($answers);
133 if ($this->object->getShuffle() && $a_shuffle)
134 {
135 $akeys = $this->object->pcArrayShuffle($akeys);
136 }
137
138 foreach ($akeys as $index)
139 {
140 $answer = $answers[$index];
141 $attrs = array(
142 "ident" => $index
143 );
144 $a_xml_writer->xmlStartTag("response_label", $attrs);
145
146 if (strlen($answer->getImage()))
147 {
148 $this->object->addQTIMaterial($a_xml_writer, $answer->getAnswertext(), FALSE, FALSE);
149 $imagetype = "image/jpeg";
150 if (preg_match("/.*\.(png|gif)$/", $answer->getImage(), $matches))
151 {
152 $imagetype = "image/" . $matches[1];
153 }
154 if ($force_image_references)
155 {
156 $attrs = array(
157 "imagtype" => $imagetype,
158 "label" => $answer->getImage(),
159 "uri" => $this->object->getImagePathWeb() . $answer->getImage()
160 );
161 $a_xml_writer->xmlElement("matimage", $attrs);
162 }
163 else
164 {
165 $imagepath = $this->object->getImagePath() . $answer->getImage();
166 $fh = @fopen($imagepath,
"rb");
168 {
169 $imagefile = fread(
$fh, filesize($imagepath));
171 $base64 = base64_encode($imagefile);
172 $attrs = array(
173 "imagtype" => $imagetype,
174 "label" => $answer->getImage(),
175 "embedded" => "base64"
176 );
177 $a_xml_writer->xmlElement("matimage", $attrs, $base64, FALSE, FALSE);
178 }
179 }
180 $a_xml_writer->xmlEndTag("material");
181 }
182 else
183 {
184 $this->object->addQTIMaterial($a_xml_writer, $answer->getAnswertext());
185 }
186 $a_xml_writer->xmlEndTag("response_label");
187 }
188 $a_xml_writer->xmlEndTag("render_choice");
189 $a_xml_writer->xmlEndTag("response_lid");
190 $a_xml_writer->xmlEndTag("flow");
191 $a_xml_writer->xmlEndTag("presentation");
192
193
194 $a_xml_writer->xmlStartTag("resprocessing");
195 $a_xml_writer->xmlStartTag("outcomes");
196 $a_xml_writer->xmlStartTag("decvar");
197 $a_xml_writer->xmlEndTag("decvar");
198 $a_xml_writer->xmlEndTag("outcomes");
199
200 foreach ($answers as $index => $answer)
201 {
202 $attrs = array(
203 "continue" => "Yes"
204 );
205 $a_xml_writer->xmlStartTag("respcondition", $attrs);
206
207 $a_xml_writer->xmlStartTag("conditionvar");
208 $attrs = array();
209 $attrs = array(
210 "respident" => "MCSR"
211 );
212 $a_xml_writer->xmlElement("varequal", $attrs, $index);
213 $a_xml_writer->xmlEndTag("conditionvar");
214
215 $attrs = array(
216 "action" => "Add"
217 );
218 $a_xml_writer->xmlElement("setvar", $attrs, $answer->getPoints());
219
220 $linkrefid = "response_$index";
221 $attrs = array(
222 "feedbacktype" => "Response",
223 "linkrefid" => $linkrefid
224 );
225 $a_xml_writer->xmlElement("displayfeedback", $attrs);
226 $a_xml_writer->xmlEndTag("respcondition");
227 }
228
229 $feedback_allcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
230 $this->object->getId(), true
231 );
232 if (strlen($feedback_allcorrect))
233 {
234 $attrs = array(
235 "continue" => "Yes"
236 );
237 $a_xml_writer->xmlStartTag("respcondition", $attrs);
238
239 $a_xml_writer->xmlStartTag("conditionvar");
240 $bestindex = 0;
241 $maxpoints = 0;
242 foreach ($answers as $index => $answer)
243 {
244 if ($answer->getPoints() > $maxpoints)
245 {
246 $maxpoints = $answer->getPoints();
247 $bestindex = $index;
248 }
249 }
250 $attrs = array(
251 "respident" => "MCSR"
252 );
253 $a_xml_writer->xmlElement("varequal", $attrs, $bestindex);
254 $a_xml_writer->xmlEndTag("conditionvar");
255
256 $attrs = array(
257 "feedbacktype" => "Response",
258 "linkrefid" => "response_allcorrect"
259 );
260 $a_xml_writer->xmlElement("displayfeedback", $attrs);
261 $a_xml_writer->xmlEndTag("respcondition");
262 }
263
264 $feedback_onenotcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
265 $this->object->getId(), false
266 );
267 if (strlen($feedback_onenotcorrect))
268 {
269 $attrs = array(
270 "continue" => "Yes"
271 );
272 $a_xml_writer->xmlStartTag("respcondition", $attrs);
273
274 $a_xml_writer->xmlStartTag("conditionvar");
275 $bestindex = 0;
276 $maxpoints = 0;
277 foreach ($answers as $index => $answer)
278 {
279 if ($answer->getPoints() > $maxpoints)
280 {
281 $maxpoints = $answer->getPoints();
282 $bestindex = $index;
283 }
284 }
285 $attrs = array(
286 "respident" => "MCSR"
287 );
288 $a_xml_writer->xmlStartTag("not");
289 $a_xml_writer->xmlElement("varequal", $attrs, $bestindex);
290 $a_xml_writer->xmlEndTag("not");
291 $a_xml_writer->xmlEndTag("conditionvar");
292
293 $attrs = array(
294 "feedbacktype" => "Response",
295 "linkrefid" => "response_onenotcorrect"
296 );
297 $a_xml_writer->xmlElement("displayfeedback", $attrs);
298 $a_xml_writer->xmlEndTag("respcondition");
299 }
300
301 $a_xml_writer->xmlEndTag("resprocessing");
302
303
304 foreach ($answers as $index => $answer)
305 {
306 $linkrefid = "response_$index";
307 $attrs = array(
308 "ident" => $linkrefid,
309 "view" => "All"
310 );
311 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
312
313 $a_xml_writer->xmlStartTag("flow_mat");
314 $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation(
315 $this->object->getId(), $index
316 );
317 $this->object->addQTIMaterial($a_xml_writer, $fb);
318 $a_xml_writer->xmlEndTag("flow_mat");
319 $a_xml_writer->xmlEndTag("itemfeedback");
320 }
321 if (strlen($feedback_allcorrect))
322 {
323 $attrs = array(
324 "ident" => "response_allcorrect",
325 "view" => "All"
326 );
327 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
328
329 $a_xml_writer->xmlStartTag("flow_mat");
330 $this->object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
331 $a_xml_writer->xmlEndTag("flow_mat");
332 $a_xml_writer->xmlEndTag("itemfeedback");
333 }
334 if (strlen($feedback_onenotcorrect))
335 {
336 $attrs = array(
337 "ident" => "response_onenotcorrect",
338 "view" => "All"
339 );
340 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
341
342 $a_xml_writer->xmlStartTag("flow_mat");
343 $this->object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
344 $a_xml_writer->xmlEndTag("flow_mat");
345 $a_xml_writer->xmlEndTag("itemfeedback");
346 }
347
348 $a_xml_writer->xmlEndTag("item");
349 $a_xml_writer->xmlEndTag("questestinterop");
350
351 $xml = $a_xml_writer->xmlDumpMem(FALSE);
352 if (!$a_include_header)
353 {
354 $pos = strpos($xml, "?>");
355 $xml = substr($xml, $pos + 2);
356 }
357 return $xml;
358 }
sprintf('%.4f', $callTime)
addGeneralMetadata(ilXmlWriter $xmlwriter)
addQtiMetaDataField(ilXmlWriter $a_xml_writer, $fieldLabel, $fieldValue)
adds a qti meta data field with given name and value to the passed xml writer (xml writer must be in ...
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 SINGLE_CHOICE_QUESTION_IDENTIFIER