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