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" => "MCMR",
95 "rcardinality" => "Multiple"
96 );
97 $a_xml_writer->xmlStartTag("response_lid", $attrs);
98 $solution = $this->object->getSuggestedSolution(0);
99 if (count($solution)) {
100 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches)) {
101 $a_xml_writer->xmlStartTag("material");
102 $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
103 if (strcmp($matches[1], "") != 0) {
104 $intlink = $solution["internal_link"];
105 }
106 $attrs = array(
107 "label" => "suggested_solution"
108 );
109 $a_xml_writer->xmlElement("mattext", $attrs, $intlink);
110 $a_xml_writer->xmlEndTag("material");
111 }
112 }
113
114 $attrs = array('shuffle' => $this->object->getShuffle() ? 'Yes' : 'No');
115 if ($this->object->getSelectionLimit()) {
116 $attrs['minnumber'] = '0';
117 $attrs['maxnumber'] = (string) $this->object->getSelectionLimit();
118 }
119 $a_xml_writer->xmlStartTag("render_choice", $attrs);
120 $answers =&$this->object->getAnswers();
121 $akeys = array_keys($answers);
122 if ($this->object->getShuffle() && $a_shuffle) {
123 $akeys = $this->object->pcArrayShuffle($akeys);
124 }
125
126 foreach ($akeys as
$index) {
127 $answer = $answers[
$index];
128 $attrs = array(
130 );
131 $a_xml_writer->xmlStartTag("response_label", $attrs);
132
133 if (strlen($answer->getImage())) {
134 $this->object->addQTIMaterial($a_xml_writer, $answer->getAnswertext(), false, false);
135 $imagetype = "image/jpeg";
136 if (preg_match("/.*\.(png|gif)$/", $answer->getImage(), $matches)) {
137 $imagetype = "image/" . $matches[1];
138 }
139 if ($force_image_references) {
140 $attrs = array(
141 "imagtype" => $imagetype,
142 "label" => $answer->getImage(),
143 "uri" => $this->object->getImagePathWeb() . $answer->getImage()
144 );
145 $a_xml_writer->xmlElement("matimage", $attrs);
146 } else {
147 $imagepath = $this->object->getImagePath() . $answer->getImage();
148 $fh = @fopen($imagepath,
"rb");
150 $imagefile = fread(
$fh, filesize($imagepath));
152 $base64 = base64_encode($imagefile);
153 $attrs = array(
154 "imagtype" => $imagetype,
155 "label" => $answer->getImage(),
156 "embedded" => "base64"
157 );
158 $a_xml_writer->xmlElement("matimage", $attrs, $base64, false, false);
159 }
160 }
161 $a_xml_writer->xmlEndTag("material");
162 } else {
163 $this->object->addQTIMaterial($a_xml_writer, $answer->getAnswertext());
164 }
165 $a_xml_writer->xmlEndTag("response_label");
166 }
167 $a_xml_writer->xmlEndTag("render_choice");
168 $a_xml_writer->xmlEndTag("response_lid");
169 $a_xml_writer->xmlEndTag("flow");
170 $a_xml_writer->xmlEndTag("presentation");
171
172
173 $a_xml_writer->xmlStartTag("resprocessing");
174 $a_xml_writer->xmlStartTag("outcomes");
175 $a_xml_writer->xmlStartTag("decvar");
176 $a_xml_writer->xmlEndTag("decvar");
177 $a_xml_writer->xmlEndTag("outcomes");
178
179 foreach ($answers as
$index => $answer) {
180 $attrs = array(
181 "continue" => "Yes"
182 );
183 $a_xml_writer->xmlStartTag("respcondition", $attrs);
184
185 $a_xml_writer->xmlStartTag("conditionvar");
186 $attrs = array();
187 $attrs = array(
188 "respident" => "MCMR"
189 );
190 $a_xml_writer->xmlElement(
"varequal", $attrs,
$index);
191 $a_xml_writer->xmlEndTag("conditionvar");
192
193 $attrs = array(
194 "action" => "Add"
195 );
196 $a_xml_writer->xmlElement("setvar", $attrs, $answer->getPoints());
197
198 $linkrefid = "response_$index";
199 $attrs = array(
200 "feedbacktype" => "Response",
201 "linkrefid" => $linkrefid
202 );
203 $a_xml_writer->xmlElement("displayfeedback", $attrs);
204 $a_xml_writer->xmlEndTag("respcondition");
205 $attrs = array(
206 "continue" => "Yes"
207 );
208 $a_xml_writer->xmlStartTag("respcondition", $attrs);
209
210
211 $a_xml_writer->xmlStartTag("conditionvar");
212 $attrs = array();
213 $attrs = array(
214 "respident" => "MCMR"
215 );
216 $a_xml_writer->xmlStartTag("not");
217 $a_xml_writer->xmlElement(
"varequal", $attrs,
$index);
218 $a_xml_writer->xmlEndTag("not");
219 $a_xml_writer->xmlEndTag("conditionvar");
220
221 $attrs = array(
222 "action" => "Add"
223 );
224 $a_xml_writer->xmlElement("setvar", $attrs, $answer->getPointsUnchecked());
225 $a_xml_writer->xmlEndTag("respcondition");
226 }
227 $feedback_allcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
228 $this->object->getId(),
229 true
230 );
231 if (strlen($feedback_allcorrect)) {
232 $attrs = array(
233 "continue" => "Yes"
234 );
235 $a_xml_writer->xmlStartTag("respcondition", $attrs);
236
237 $a_xml_writer->xmlStartTag("conditionvar");
238 foreach ($answers as
$index => $answer) {
239 if ($answer->getPointsChecked() < $answer->getPointsUnchecked()) {
240 $a_xml_writer->xmlStartTag("not");
241 }
242 $attrs = array(
243 "respident" => "MCMR"
244 );
245 $a_xml_writer->xmlElement(
"varequal", $attrs,
$index);
246 if ($answer->getPointsChecked() < $answer->getPointsUnchecked()) {
247 $a_xml_writer->xmlEndTag("not");
248 }
249 }
250 $a_xml_writer->xmlEndTag("conditionvar");
251
252 $attrs = array(
253 "feedbacktype" => "Response",
254 "linkrefid" => "response_allcorrect"
255 );
256 $a_xml_writer->xmlElement("displayfeedback", $attrs);
257 $a_xml_writer->xmlEndTag("respcondition");
258 }
259 $feedback_onenotcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
260 $this->object->getId(),
261 false
262 );
263 if (strlen($feedback_onenotcorrect)) {
264 $attrs = array(
265 "continue" => "Yes"
266 );
267 $a_xml_writer->xmlStartTag("respcondition", $attrs);
268
269 $a_xml_writer->xmlStartTag("conditionvar");
270 foreach ($answers as
$index => $answer) {
272 $a_xml_writer->xmlStartTag("or");
273 }
274 if ($answer->getPointsChecked() >= $answer->getPointsUnchecked()) {
275 $a_xml_writer->xmlStartTag("not");
276 }
277 $attrs = array(
278 "respident" => "MCMR"
279 );
280 $a_xml_writer->xmlElement(
"varequal", $attrs,
$index);
281 if ($answer->getPointsChecked() >= $answer->getPointsUnchecked()) {
282 $a_xml_writer->xmlEndTag("not");
283 }
285 $a_xml_writer->xmlEndTag("or");
286 }
287 }
288 $a_xml_writer->xmlEndTag("conditionvar");
289
290 $attrs = array(
291 "feedbacktype" => "Response",
292 "linkrefid" => "response_onenotcorrect"
293 );
294 $a_xml_writer->xmlElement("displayfeedback", $attrs);
295 $a_xml_writer->xmlEndTag("respcondition");
296 }
297 $a_xml_writer->xmlEndTag("resprocessing");
298
299
300 foreach ($answers as
$index => $answer) {
301 $linkrefid = "response_$index";
302 $attrs = array(
303 "ident" => $linkrefid,
304 "view" => "All"
305 );
306 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
307
308 $a_xml_writer->xmlStartTag("flow_mat");
309 $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation(
310 $this->object->getId(),
312 );
313 $this->object->addQTIMaterial($a_xml_writer, $fb);
314 $a_xml_writer->xmlEndTag("flow_mat");
315 $a_xml_writer->xmlEndTag("itemfeedback");
316 }
317 if (strlen($feedback_allcorrect)) {
318 $attrs = array(
319 "ident" => "response_allcorrect",
320 "view" => "All"
321 );
322 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
323
324 $a_xml_writer->xmlStartTag("flow_mat");
325 $this->object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
326 $a_xml_writer->xmlEndTag("flow_mat");
327 $a_xml_writer->xmlEndTag("itemfeedback");
328 }
329 if (strlen($feedback_onenotcorrect)) {
330 $attrs = array(
331 "ident" => "response_onenotcorrect",
332 "view" => "All"
333 );
334 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
335
336 $a_xml_writer->xmlStartTag("flow_mat");
337 $this->object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
338 $a_xml_writer->xmlEndTag("flow_mat");
339 $a_xml_writer->xmlEndTag("itemfeedback");
340 }
341
342 $a_xml_writer->xmlEndTag("item");
343 $a_xml_writer->xmlEndTag("questestinterop");
344
345 $xml = $a_xml_writer->xmlDumpMem(
false);
346 if (!$a_include_header) {
347 $pos = strpos(
$xml,
"?>");
349 }
351 }
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 MULTIPLE_CHOICE_QUESTION_IDENTIFIER