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