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