ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.assOrderingQuestionExport.php
Go to the documentation of this file.
1 <?php
2 
29 {
33  public $object;
34 
40  public function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false): string
41  {
42  global $DIC;
43  $ilias = $DIC['ilias'];
44 
45  $a_xml_writer = new ilXmlWriter();
46  // set xml header
47  $a_xml_writer->xmlHeader();
48  $a_xml_writer->xmlStartTag("questestinterop");
49  $attrs = [
50  "ident" => "il_" . IL_INST_ID . "_qst_" . $this->object->getId(),
51  "title" => $this->object->getTitle(),
52  "maxattempts" => $this->object->getNrOfTries()
53  ];
54  $a_xml_writer->xmlStartTag("item", $attrs);
55  // add question description
56  $a_xml_writer->xmlElement("qticomment", null, $this->object->getComment());
57  $a_xml_writer->xmlStartTag("itemmetadata");
58  $a_xml_writer->xmlStartTag("qtimetadata");
59  $a_xml_writer->xmlStartTag("qtimetadatafield");
60  $a_xml_writer->xmlElement("fieldlabel", null, "ILIAS_VERSION");
61  $a_xml_writer->xmlElement("fieldentry", null, $ilias->getSetting("ilias_version"));
62  $a_xml_writer->xmlEndTag("qtimetadatafield");
63  $a_xml_writer->xmlStartTag("qtimetadatafield");
64  $a_xml_writer->xmlElement("fieldlabel", null, "QUESTIONTYPE");
65  $a_xml_writer->xmlElement("fieldentry", null, $this->object->getQuestionType());
66  $a_xml_writer->xmlEndTag("qtimetadatafield");
67  $a_xml_writer->xmlStartTag("qtimetadatafield");
68  $a_xml_writer->xmlElement("fieldlabel", null, "AUTHOR");
69  $a_xml_writer->xmlElement("fieldentry", null, $this->object->getAuthor());
70  $a_xml_writer->xmlEndTag("qtimetadatafield");
71 
72  // additional content editing information
73  $this->addAdditionalContentEditingModeInformation($a_xml_writer);
74  $this->addGeneralMetadata($a_xml_writer);
75 
76  $a_xml_writer->xmlStartTag("qtimetadatafield");
77  $a_xml_writer->xmlElement("fieldlabel", null, "thumb_geometry");
78  $a_xml_writer->xmlElement("fieldentry", null, $this->object->getThumbSize());
79  $a_xml_writer->xmlEndTag("qtimetadatafield");
80  $a_xml_writer->xmlStartTag("qtimetadatafield");
81  $a_xml_writer->xmlElement("fieldlabel", null, "element_height");
82  $a_xml_writer->xmlElement("fieldentry", null, $this->object->getElementHeight());
83  $a_xml_writer->xmlEndTag("qtimetadatafield");
84  $a_xml_writer->xmlStartTag("qtimetadatafield");
85  $a_xml_writer->xmlElement("fieldlabel", null, "points");
86  $a_xml_writer->xmlElement("fieldentry", null, $this->object->getPoints());
87  $a_xml_writer->xmlEndTag("qtimetadatafield");
88  $a_xml_writer->xmlEndTag("qtimetadata");
89  $a_xml_writer->xmlEndTag("itemmetadata");
90 
91  // PART I: qti presentation
92  $attrs = [
93  "label" => $this->object->getTitle()
94  ];
95  $a_xml_writer->xmlStartTag("presentation", $attrs);
96  // add flow to presentation
97  $a_xml_writer->xmlStartTag("flow");
98  // add material with question text to presentation
99  $this->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
100  // add answers to presentation
101  $attrs = [];
102 
103  if ($this->object->getOrderingType() == assOrderingQuestion::OQ_PICTURES) {
104  $ordering_type = 'OQP';
105  } elseif ($this->object->getOrderingType() == assOrderingQuestion::OQ_NESTED_PICTURES) {
106  $ordering_type = 'OQNP';
107  } elseif ($this->object->getOrderingType() == assOrderingQuestion::OQ_NESTED_TERMS) {
108  $ordering_type = 'OQNT';
109  } elseif ($this->object->getOrderingType() == assOrderingQuestion::OQ_TERMS) {
110  $ordering_type = 'OQT';
111  }
112 
113  $attrs = [
114  "ident" => $ordering_type,
115  "rcardinality" => "Ordered"
116  ];
117 
118  $attrs["output"] = "javascript";
119  $a_xml_writer->xmlStartTag("response_lid", $attrs);
120  $a_xml_writer = $this->addSuggestedSolution($a_xml_writer);
121  // shuffle output
122  $attrs = [];
123  if ($this->object->getShuffle()) {
124  $attrs = [
125  "shuffle" => "Yes"
126  ];
127  } else {
128  $attrs = [
129  "shuffle" => "No"
130  ];
131  }
132  $a_xml_writer->xmlStartTag("render_choice", $attrs);
133 
134  // add answers
135  foreach ($this->object->getOrderingElementList() as $element) {
136  $attrs = [
137  'ident' => $element->getExportIdent()
138  ];
139  $a_xml_writer->xmlStartTag("response_label", $attrs);
140  if ($this->object->getOrderingType() == assOrderingQuestion::OQ_PICTURES
141  || $this->object->getOrderingType() == assOrderingQuestion::OQ_NESTED_PICTURES) {
142  $imagetype = "image/jpeg";
143 
144  $a_xml_writer->xmlStartTag("material");
145  if ($force_image_references) {
146  $attrs = [
147  "imagtype" => $imagetype,
148  "label" => $element->getContent(),
149  "uri" => $this->object->getImagePathWeb() . $element->getContent()
150  ];
151  $a_xml_writer->xmlElement("matimage", $attrs);
152  } else {
153  $imagepath = $this->object->getImagePath() . $element->getContent();
154  if (file_exists($imagepath) && is_file($imagepath)) {
155  $fh = @fopen($imagepath, "rb");
156  if ($fh != false) {
157  $imagefile = fread($fh, filesize($imagepath));
158  fclose($fh);
159  $base64 = base64_encode($imagefile);
160 
161  if (preg_match("/.*\.(png|gif)$/", $element->getContent(), $matches)) {
162  $imagetype = "image/" . $matches[1];
163  }
164  $attrs = [
165  "imagtype" => $imagetype,
166  "label" => $element->getContent(),
167  "embedded" => "base64"
168  ];
169  $a_xml_writer->xmlElement("matimage", $attrs, $base64, false, false);
170  }
171  }
172  }
173  $a_xml_writer->xmlEndTag("material");
174  } elseif ($this->object->getOrderingType() == assOrderingQuestion::OQ_TERMS
175  || $this->object->getOrderingType() == assOrderingQuestion::OQ_NESTED_TERMS) {
176  $a_xml_writer->xmlStartTag("material");
177  $this->addQTIMaterial($a_xml_writer, $element->getContent(), true, false);
178  $a_xml_writer->xmlEndTag("material");
179  $a_xml_writer->xmlStartTag("material");
180  $attrs = ["label" => "answerdepth"];
181  $a_xml_writer->xmlElement("mattext", $attrs, $element->getIndentation());
182  $a_xml_writer->xmlEndTag("material");
183  }
184  $a_xml_writer->xmlEndTag("response_label");
185  }
186  $a_xml_writer->xmlEndTag("render_choice");
187  $a_xml_writer->xmlEndTag("response_lid");
188  $a_xml_writer->xmlEndTag("flow");
189  $a_xml_writer->xmlEndTag("presentation");
190 
191  // PART II: qti resprocessing
192  $a_xml_writer->xmlStartTag("resprocessing");
193  $a_xml_writer->xmlStartTag("outcomes");
194  $a_xml_writer->xmlStartTag("decvar");
195  $a_xml_writer->xmlEndTag("decvar");
196  $a_xml_writer->xmlEndTag("outcomes");
197  // add response conditions
198  foreach ($this->object->getOrderingElementList() as $element) {
199  $attrs = [
200  "continue" => "Yes"
201  ];
202  $a_xml_writer->xmlStartTag("respcondition", $attrs);
203  // qti conditionvar
204  $a_xml_writer->xmlStartTag("conditionvar");
205  $attrs = [];
206 
207  if ($this->object->getOrderingType() == assOrderingQuestion::OQ_PICTURES) {
208  $ordering_type = 'OQP';
209  } elseif ($this->object->getOrderingType() == assOrderingQuestion::OQ_NESTED_PICTURES) {
210  $ordering_type = 'OQNP';
211  } elseif ($this->object->getOrderingType() == assOrderingQuestion::OQ_NESTED_TERMS) {
212  $ordering_type = 'OQNT';
213  } elseif ($this->object->getOrderingType() == assOrderingQuestion::OQ_TERMS) {
214  $ordering_type = 'OQT';
215  }
216 
217  $attrs = ["respident" => $ordering_type];
218 
219  $attrs["index"] = $element->getPosition();
220  $a_xml_writer->xmlElement("varequal", $attrs, $element->getPosition());
221  $a_xml_writer->xmlEndTag("conditionvar");
222  // qti setvar
223  $attrs = [
224  "action" => "Add"
225  ];
226  $points = $this->object->getPoints() / $this->object->getOrderingElementList()->countElements();
227  $a_xml_writer->xmlElement("setvar", $attrs, $points);
228  // qti displayfeedback
229  $attrs = [
230  "feedbacktype" => "Response",
231  "linkrefid" => "link_" . $element->getPosition()
232  ];
233  $a_xml_writer->xmlElement("displayfeedback", $attrs);
234  $a_xml_writer->xmlEndTag("respcondition");
235  }
236 
237  $feedback_allcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
238  $this->object->getId(),
239  true
240  );
241  if (strlen($feedback_allcorrect)) {
242  $attrs = [
243  "continue" => "Yes"
244  ];
245  $a_xml_writer->xmlStartTag("respcondition", $attrs);
246  // qti conditionvar
247  $a_xml_writer->xmlStartTag("conditionvar");
248 
249  foreach ($this->object->getOrderingElementList() as $element) {
250  $attrs = [];
251 
252  if ($this->object->getOrderingType() == assOrderingQuestion::OQ_PICTURES) {
253  $ordering_type = 'OQP';
254  } elseif ($this->object->getOrderingType() == assOrderingQuestion::OQ_NESTED_PICTURES) {
255  $ordering_type = 'OQNP';
256  } elseif ($this->object->getOrderingType() == assOrderingQuestion::OQ_NESTED_TERMS) {
257  $ordering_type = 'OQNT';
258  } elseif ($this->object->getOrderingType() == assOrderingQuestion::OQ_TERMS) {
259  $ordering_type = 'OQT';
260  }
261 
262  $attrs = ["respident" => $ordering_type];
263 
264  $attrs["index"] = $element->getPosition();
265  $a_xml_writer->xmlElement("varequal", $attrs, $element->getPosition());
266  }
267 
268  $a_xml_writer->xmlEndTag("conditionvar");
269  // qti displayfeedback
270  $attrs = [
271  "feedbacktype" => "Response",
272  "linkrefid" => "response_allcorrect"
273  ];
274  $a_xml_writer->xmlElement("displayfeedback", $attrs);
275  $a_xml_writer->xmlEndTag("respcondition");
276  }
277 
278  $feedback_onenotcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
279  $this->object->getId(),
280  false
281  );
282  if (strlen($feedback_onenotcorrect)) {
283  $attrs = [
284  "continue" => "Yes"
285  ];
286  $a_xml_writer->xmlStartTag("respcondition", $attrs);
287  // qti conditionvar
288  $a_xml_writer->xmlStartTag("conditionvar");
289  $a_xml_writer->xmlStartTag("not");
290 
291  foreach ($this->object->getOrderingElementList() as $element) {
292  $attrs = [];
293  if ($this->object->getOrderingType() == assOrderingQuestion::OQ_PICTURES) {
294  $ordering_type = 'OQP';
295  } elseif ($this->object->getOrderingType() == assOrderingQuestion::OQ_NESTED_PICTURES) {
296  $ordering_type = 'OQNP';
297  } elseif ($this->object->getOrderingType() == assOrderingQuestion::OQ_NESTED_TERMS) {
298  $ordering_type = 'OQNT';
299  } elseif ($this->object->getOrderingType() == assOrderingQuestion::OQ_TERMS) {
300  $ordering_type = 'OQT';
301  }
302 
303  $attrs = ["respident" => $ordering_type];
304 
305  $attrs["index"] = $element->getPosition();
306  $a_xml_writer->xmlElement("varequal", $attrs, $element->getPosition());
307  }
308 
309  $a_xml_writer->xmlEndTag("not");
310  $a_xml_writer->xmlEndTag("conditionvar");
311  // qti displayfeedback
312  $attrs = [
313  "feedbacktype" => "Response",
314  "linkrefid" => "response_onenotcorrect"
315  ];
316  $a_xml_writer->xmlElement("displayfeedback", $attrs);
317  $a_xml_writer->xmlEndTag("respcondition");
318  }
319 
320  $a_xml_writer->xmlEndTag("resprocessing");
321 
322  // PART III: qti itemfeedback
323  foreach ($this->object->getOrderingElementList() as $element) {
324  $attrs = [
325  "ident" => "link_" . $element->getPosition(),
326  "view" => "All"
327  ];
328  $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
329  // qti flow_mat
330  $a_xml_writer->xmlStartTag("flow_mat");
331  $a_xml_writer->xmlStartTag("material");
332  $a_xml_writer->xmlElement("mattext", null, $this->object->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation(
333  $this->object->getId(),
334  0,
335  $element->getPosition()
336  ));
337  $a_xml_writer->xmlEndTag("material");
338  $a_xml_writer->xmlEndTag("flow_mat");
339  $a_xml_writer->xmlEndTag("itemfeedback");
340  }
341 
342  if (strlen($feedback_allcorrect)) {
343  $attrs = [
344  "ident" => "response_allcorrect",
345  "view" => "All"
346  ];
347  $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
348  // qti flow_mat
349  $a_xml_writer->xmlStartTag("flow_mat");
350  $this->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
351  $a_xml_writer->xmlEndTag("flow_mat");
352  $a_xml_writer->xmlEndTag("itemfeedback");
353  }
354  if (strlen($feedback_onenotcorrect)) {
355  $attrs = [
356  "ident" => "response_onenotcorrect",
357  "view" => "All"
358  ];
359  $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
360  // qti flow_mat
361  $a_xml_writer->xmlStartTag("flow_mat");
362  $this->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
363  $a_xml_writer->xmlEndTag("flow_mat");
364  $a_xml_writer->xmlEndTag("itemfeedback");
365  }
366 
367  $a_xml_writer->xmlEndTag("item");
368  $a_xml_writer->xmlEndTag("questestinterop");
369 
370  $xml = $a_xml_writer->xmlDumpMem(false);
371  if (!$a_include_header) {
372  $pos = strpos($xml, "?>");
373  $xml = substr($xml, $pos + 2);
374  }
375  return $xml;
376  }
377 }
const IL_INST_ID
Definition: constants.php:40
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addQTIMaterial(ilXmlWriter $a_xml_writer, string $a_material, bool $close_material_tag=true, bool $add_mobs=true)
Class for question exports.
addGeneralMetadata(ilXmlWriter $xmlwriter)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
global $DIC
Definition: shib_login.php:26
toXML($a_include_header=true, $a_include_binary=true, $a_shuffle=false, $test_output=false, $force_image_references=false)
Returns a QTI xml representation of the question Returns a QTI xml representation of the question and...
addAdditionalContentEditingModeInformation(ilXmlWriter $a_xml_writer)
adds a qti meta data field for ilias specific information of "additional content editing mode" (xml w...
addSuggestedSolution(ilXmlWriter $writer)