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.
35 : string
36 {
38 $ilias =
$DIC[
'ilias'];
39
41
42 $a_xml_writer->xmlHeader();
43 $a_xml_writer->xmlStartTag("questestinterop");
44 $attrs = [
45 "ident" =>
"il_" .
IL_INST_ID .
"_qst_" . $this->
object->getId(),
46 "title" => $this->object->getTitle(),
47 "maxattempts" => $this->object->getNrOfTries()
48 ];
49 $a_xml_writer->xmlStartTag("item", $attrs);
50
51 $a_xml_writer->xmlElement(
"qticomment",
null, $this->
object->getComment());
52 $a_xml_writer->xmlStartTag("itemmetadata");
53 $a_xml_writer->xmlStartTag("qtimetadata");
54 $a_xml_writer->xmlStartTag("qtimetadatafield");
55 $a_xml_writer->xmlElement("fieldlabel", null, "ILIAS_VERSION");
56 $a_xml_writer->xmlElement("fieldentry", null, $ilias->getSetting("ilias_version"));
57 $a_xml_writer->xmlEndTag("qtimetadatafield");
58 $a_xml_writer->xmlStartTag("qtimetadatafield");
59 $a_xml_writer->xmlElement("fieldlabel", null, "QUESTIONTYPE");
60 $a_xml_writer->xmlElement(
"fieldentry",
null, $this->
object->getQuestionType());
61 $a_xml_writer->xmlEndTag("qtimetadatafield");
62 $a_xml_writer->xmlStartTag("qtimetadatafield");
63 $a_xml_writer->xmlElement("fieldlabel", null, "AUTHOR");
64 $a_xml_writer->xmlElement(
"fieldentry",
null, $this->
object->getAuthor());
65 $a_xml_writer->xmlEndTag("qtimetadatafield");
66
67
70
71 $a_xml_writer->xmlStartTag("qtimetadatafield");
72 $a_xml_writer->xmlElement("fieldlabel", null, "thumb_size");
73 $a_xml_writer->xmlElement(
"fieldentry",
null, $this->
object->getThumbSize());
74 $a_xml_writer->xmlEndTag("qtimetadatafield");
75
76 $a_xml_writer->xmlStartTag("qtimetadatafield");
77 $a_xml_writer->xmlElement("fieldlabel", null, "feedback_setting");
78 $a_xml_writer->xmlElement(
"fieldentry",
null, $this->
object->getSpecificFeedbackSetting());
79 $a_xml_writer->xmlEndTag("qtimetadatafield");
80
82
83 $a_xml_writer->xmlEndTag("qtimetadata");
84 $a_xml_writer->xmlEndTag("itemmetadata");
85
86
87 $attrs = [
88 "label" => $this->object->getTitle()
89 ];
90 $a_xml_writer->xmlStartTag("presentation", $attrs);
91
92 $a_xml_writer->xmlStartTag("flow");
93
95
96 $attrs = [
97 "ident" => "MCSR",
98 "rcardinality" => "Single"
99 ];
100 $a_xml_writer->xmlStartTag("response_lid", $attrs);
102
103 $attrs = [];
104 if ($this->
object->getShuffle()) {
105 $attrs = [
106 "shuffle" => "Yes"
107 ];
108 } else {
109 $attrs = [
110 "shuffle" => "No"
111 ];
112 }
113 $a_xml_writer->xmlStartTag("render_choice", $attrs);
114 $answers = $this->object->getAnswers();
115 $akeys = array_keys($answers);
116 if ($this->
object->getShuffle() && $a_shuffle) {
117 $akeys = shuffle($akeys);
118 }
119
120 foreach ($akeys as $index) {
121 $answer = $answers[$index];
122 $attrs = [
123 "ident" => $index
124 ];
125 $a_xml_writer->xmlStartTag("response_label", $attrs);
126
127 if ($answer->hasImage()) {
128 $this->
addQTIMaterial($a_xml_writer, $answer->getAnswertext(),
false,
false);
129 $imagetype = "image/jpeg";
130 if (preg_match("/.*\.(png|gif)$/", $answer->getImage(), $matches)) {
131 $imagetype = "image/" . $matches[1];
132 }
133 if ($force_image_references) {
134 $attrs = [
135 "imagtype" => $imagetype,
136 "label" => $answer->getImage(),
137 "uri" => $this->object->getImagePathWeb() . $answer->getImage()
138 ];
139 $a_xml_writer->xmlElement("matimage", $attrs);
140 } else {
141 $imagepath = $this->object->getImagePath() . $answer->getImage();
142 $fh = @fopen($imagepath, "rb");
143 if ($fh != false) {
144 $imagefile = fread($fh, filesize($imagepath));
145 fclose($fh);
146 $base64 = base64_encode($imagefile);
147 $attrs = [
148 "imagtype" => $imagetype,
149 "label" => $answer->getImage(),
150 "embedded" => "base64"
151 ];
152 $a_xml_writer->xmlElement("matimage", $attrs, $base64, false, false);
153 }
154 }
155 $a_xml_writer->xmlEndTag("material");
156 } else {
158 }
159 $a_xml_writer->xmlEndTag("response_label");
160 }
161 $a_xml_writer->xmlEndTag("render_choice");
162 $a_xml_writer->xmlEndTag("response_lid");
163 $a_xml_writer->xmlEndTag("flow");
164 $a_xml_writer->xmlEndTag("presentation");
165
166
167 $a_xml_writer->xmlStartTag("resprocessing");
168 $a_xml_writer->xmlStartTag("outcomes");
169 $a_xml_writer->xmlStartTag("decvar");
170 $a_xml_writer->xmlEndTag("decvar");
171 $a_xml_writer->xmlEndTag("outcomes");
172
173 foreach ($answers as $index => $answer) {
174 $attrs = [
175 "continue" => "Yes"
176 ];
177 $a_xml_writer->xmlStartTag("respcondition", $attrs);
178
179 $a_xml_writer->xmlStartTag("conditionvar");
180 $attrs = [
181 "respident" => "MCSR"
182 ];
183 $a_xml_writer->xmlElement("varequal", $attrs, $index);
184 $a_xml_writer->xmlEndTag("conditionvar");
185
186 $attrs = [
187 "action" => "Add"
188 ];
189 $a_xml_writer->xmlElement("setvar", $attrs, $answer->getPoints());
190
191 $linkrefid = "response_$index";
192 $attrs = [
193 "feedbacktype" => "Response",
194 "linkrefid" => $linkrefid
195 ];
196 $a_xml_writer->xmlElement("displayfeedback", $attrs);
197 $a_xml_writer->xmlEndTag("respcondition");
198 }
199
200 $feedback_allcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
202 true
203 );
204 if (strlen($feedback_allcorrect)) {
205 $attrs = [
206 "continue" => "Yes"
207 ];
208 $a_xml_writer->xmlStartTag("respcondition", $attrs);
209
210 $a_xml_writer->xmlStartTag("conditionvar");
211 $bestindex = 0;
212 $maxpoints = 0;
213 foreach ($answers as $index => $answer) {
214 if ($answer->getPoints() > $maxpoints) {
215 $maxpoints = $answer->getPoints();
216 $bestindex = $index;
217 }
218 }
219 $attrs = [
220 "respident" => "MCSR"
221 ];
222 $a_xml_writer->xmlElement("varequal", $attrs, $bestindex);
223 $a_xml_writer->xmlEndTag("conditionvar");
224
225 $attrs = [
226 "feedbacktype" => "Response",
227 "linkrefid" => "response_allcorrect"
228 ];
229 $a_xml_writer->xmlElement("displayfeedback", $attrs);
230 $a_xml_writer->xmlEndTag("respcondition");
231 }
232
233 $feedback_onenotcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
235 false
236 );
237 if (strlen($feedback_onenotcorrect)) {
238 $attrs = [
239 "continue" => "Yes"
240 ];
241 $a_xml_writer->xmlStartTag("respcondition", $attrs);
242
243 $a_xml_writer->xmlStartTag("conditionvar");
244 $bestindex = 0;
245 $maxpoints = 0;
246 foreach ($answers as $index => $answer) {
247 if ($answer->getPoints() > $maxpoints) {
248 $maxpoints = $answer->getPoints();
249 $bestindex = $index;
250 }
251 }
252 $attrs = [
253 "respident" => "MCSR"
254 ];
255 $a_xml_writer->xmlStartTag("not");
256 $a_xml_writer->xmlElement("varequal", $attrs, $bestindex);
257 $a_xml_writer->xmlEndTag("not");
258 $a_xml_writer->xmlEndTag("conditionvar");
259
260 $attrs = [
261 "feedbacktype" => "Response",
262 "linkrefid" => "response_onenotcorrect"
263 ];
264 $a_xml_writer->xmlElement("displayfeedback", $attrs);
265 $a_xml_writer->xmlEndTag("respcondition");
266 }
267
268 $a_xml_writer->xmlEndTag("resprocessing");
269
270
271 foreach ($answers as $index => $answer) {
272 $linkrefid = "response_$index";
273 $attrs = [
274 "ident" => $linkrefid,
275 "view" => "All"
276 ];
277 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
278
279 $a_xml_writer->xmlStartTag("flow_mat");
280 $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation(
282 0,
283 $index
284 );
286 $a_xml_writer->xmlEndTag("flow_mat");
287 $a_xml_writer->xmlEndTag("itemfeedback");
288 }
289 if (strlen($feedback_allcorrect)) {
290 $attrs = [
291 "ident" => "response_allcorrect",
292 "view" => "All"
293 ];
294 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
295
296 $a_xml_writer->xmlStartTag("flow_mat");
298 $a_xml_writer->xmlEndTag("flow_mat");
299 $a_xml_writer->xmlEndTag("itemfeedback");
300 }
301 if (strlen($feedback_onenotcorrect)) {
302 $attrs = [
303 "ident" => "response_onenotcorrect",
304 "view" => "All"
305 ];
306 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
307
308 $a_xml_writer->xmlStartTag("flow_mat");
310 $a_xml_writer->xmlEndTag("flow_mat");
311 $a_xml_writer->xmlEndTag("itemfeedback");
312 }
313
314 $a_xml_writer->xmlEndTag("item");
315 $a_xml_writer->xmlEndTag("questestinterop");
316 $xml = $a_xml_writer->xmlDumpMem(false);
317 if (!$a_include_header) {
318 $pos = strpos($xml, "?>");
319 $xml = substr($xml, $pos + 2);
320 }
321 return $xml;
322 }
addGeneralMetadata(ilXmlWriter $xmlwriter)
addQTIMaterial(ilXmlWriter $a_xml_writer, string $a_material, bool $close_material_tag=true, bool $add_mobs=true)
addSuggestedSolution(ilXmlWriter $writer)
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...