ILIAS  trunk Revision v5.2.0beta1-34115-g3a2438be29
assImagemapQuestionExport Class Reference

Class for imagemap question exports. More...

+ Inheritance diagram for assImagemapQuestionExport:
+ Collaboration diagram for assImagemapQuestionExport:

Public Member Functions

 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 sets the internal domxml variable with the DOM XML representation of the QTI xml representation. More...
 
- Public Member Functions inherited from assQuestionExport
 __construct ($a_object)
 assQuestionExport constructor More...
 
 exportFeedbackOnly ($a_xml_writer)
 
 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 sets the internal domxml variable with the DOM XML representation of the QTI xml representation. More...
 
 addQTIMaterial (ilXmlWriter $a_xml_writer, string $a_material, bool $close_material_tag=true, bool $add_mobs=true)
 

Additional Inherited Members

- Data Fields inherited from assQuestionExport
 $object
 
const ITEM_SOLUTIONHINT = 'solutionhint'
 
- Protected Member Functions inherited from assQuestionExport
 addAnswerSpecificFeedback (ilXmlWriter $a_xml_writer, $answers)
 
 addGenericFeedback (ilXmlWriter $a_xml_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 context of opened "qtimetadata" tag) More...
 
 addAdditionalContentEditingModeInformation (ilXmlWriter $a_xml_writer)
 adds a qti meta data field for ilias specific information of "additional content editing mode" (xml writer must be in context of opened "qtimetadata" tag) More...
 
 addGeneralMetadata (ilXmlWriter $xmlwriter)
 
 addSolutionHints (ilXmlWriter $writer)
 
 addSuggestedSolutionLink (ilXmlWriter $writer, assQuestionSuggestedSolution $suggested_solution)
 

Detailed Description

Class for imagemap question exports.

assImagemapQuestionExport is a class for imagemap question exports

Author
Helmut Schottmüller helmu.nosp@m.t.sc.nosp@m.hottm.nosp@m.uell.nosp@m.er@ma.nosp@m.c.co.nosp@m.m
Version
$Id$ \

Definition at line 29 of file class.assImagemapQuestionExport.php.

Member Function Documentation

◆ toXML()

assImagemapQuestionExport::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 sets the internal domxml variable with the DOM XML representation of the QTI xml representation.

Returns
string The QTI xml representation of the question public

Definition at line 38 of file class.assImagemapQuestionExport.php.

References $DIC, $GLOBALS, $ilErr, assQuestionExport\addAdditionalContentEditingModeInformation(), assQuestionExport\addGeneralMetadata(), assQuestionExport\addQTIMaterial(), assQuestionExport\addSolutionHints(), assQuestionExport\addSuggestedSolutionLink(), IL_INST_ID, and ILIAS\Repository\object().

38  : string
39  {
40  global $DIC;
41  $ilias = $DIC['ilias'];
42 
43  $a_xml_writer = new ilXmlWriter();
44  // set xml header
45  $a_xml_writer->xmlHeader();
46  $a_xml_writer->xmlStartTag("questestinterop");
47  $attrs = [
48  "ident" => "il_" . IL_INST_ID . "_qst_" . $this->object->getId(),
49  "title" => $this->object->getTitle(),
50  "maxattempts" => $this->object->getNrOfTries()
51  ];
52  $a_xml_writer->xmlStartTag("item", $attrs);
53  // add question description
54  $a_xml_writer->xmlElement("qticomment", null, $this->object->getComment());
55  $a_xml_writer->xmlStartTag("itemmetadata");
56  $a_xml_writer->xmlStartTag("qtimetadata");
57  $a_xml_writer->xmlStartTag("qtimetadatafield");
58  $a_xml_writer->xmlElement("fieldlabel", null, "ILIAS_VERSION");
59  $a_xml_writer->xmlElement("fieldentry", null, $ilias->getSetting("ilias_version"));
60  $a_xml_writer->xmlEndTag("qtimetadatafield");
61  $a_xml_writer->xmlStartTag("qtimetadatafield");
62  $a_xml_writer->xmlElement("fieldlabel", null, "QUESTIONTYPE");
63  $a_xml_writer->xmlElement("fieldentry", null, QuestionIdentifiers::IMAGEMAP_QUESTION_IDENTIFIER);
64  $a_xml_writer->xmlEndTag("qtimetadatafield");
65  $a_xml_writer->xmlStartTag("qtimetadatafield");
66  $a_xml_writer->xmlElement("fieldlabel", null, "IS_MULTIPLE_CHOICE");
67  $a_xml_writer->xmlElement("fieldentry", null, ($this->object->getIsMultipleChoice()) ? "1" : "0");
68  $a_xml_writer->xmlEndTag("qtimetadatafield");
69  $a_xml_writer->xmlStartTag("qtimetadatafield");
70  $a_xml_writer->xmlElement("fieldlabel", null, "AUTHOR");
71  $a_xml_writer->xmlElement("fieldentry", null, $this->object->getAuthor());
72  $a_xml_writer->xmlEndTag("qtimetadatafield");
73 
74  // additional content editing information
75  $this->addAdditionalContentEditingModeInformation($a_xml_writer);
76  $this->addGeneralMetadata($a_xml_writer);
77 
78  $a_xml_writer->xmlEndTag("qtimetadata");
79  $a_xml_writer->xmlEndTag("itemmetadata");
80 
81  // PART I: qti presentation
82  $attrs = [
83  "label" => $this->object->getTitle()
84  ];
85  $a_xml_writer->xmlStartTag("presentation", $attrs);
86  // add flow to presentation
87  $a_xml_writer->xmlStartTag("flow");
88  // add material with question text to presentation
89  $this->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
90  // add answers to presentation
91  $attrs = [
92  "ident" => "IM",
93  "rcardinality" => "Single"
94  ];
95  $a_xml_writer->xmlStartTag("response_xy", $attrs);
96  $solution = $this->object->getSuggestedSolution(0);
97  if ($solution !== null) {
98  $a_xml_writer = $this->addSuggestedSolutionLink($a_xml_writer, $solution);
99  }
100  $a_xml_writer->xmlStartTag("render_hotspot");
101  $a_xml_writer->xmlStartTag("material");
102  $imagetype = "image/jpeg";
103  if (preg_match("/.*\.(png|gif)$/i", $this->object->getImageFilename(), $matches)) {
104  $imagetype = "image/" . strtolower($matches[1]);
105  }
106  $attrs = [
107  "imagtype" => $imagetype,
108  "label" => $this->object->getImageFilename()
109  ];
110  if ($a_include_binary) {
111  if ($force_image_references) {
112  $attrs["uri"] = $this->object->getImagePathWeb() . $this->object->getImageFilename();
113  $a_xml_writer->xmlElement("matimage", $attrs);
114  } else {
115  $attrs["embedded"] = "base64";
116  $imagepath = $this->object->getImagePath() . $this->object->getImageFilename();
117  $fh = fopen($imagepath, "rb");
118  if ($fh == false) {
119  global $DIC;
120  $ilErr = $DIC['ilErr'];
121  $ilErr->raiseError($GLOBALS['DIC']['lng']->txt("error_open_image_file"), $ilErr->MESSAGE);
122  }
123  $imagefile = fread($fh, filesize($imagepath));
124  fclose($fh);
125  $base64 = base64_encode($imagefile);
126  $a_xml_writer->xmlElement("matimage", $attrs, $base64, false, false);
127  }
128  } else {
129  $a_xml_writer->xmlElement("matimage", $attrs);
130  }
131  $a_xml_writer->xmlEndTag("material");
132 
133  // add answers
134  foreach ($this->object->getAnswers() as $index => $answer) {
135  $rared = "";
136  switch ($answer->getArea()) {
137  case "rect":
138  $rarea = "Rectangle";
139  break;
140  case "circle":
141  $rarea = "Ellipse";
142  break;
143  case "poly":
144  $rarea = "Bounded";
145  break;
146  }
147  $attrs = [
148  "ident" => $index,
149  "rarea" => $rarea
150  ];
151  $a_xml_writer->xmlStartTag("response_label", $attrs);
152  $a_xml_writer->xmlData($answer->getCoords());
153  $a_xml_writer->xmlStartTag("material");
154  $a_xml_writer->xmlElement("mattext", null, $answer->getAnswertext());
155  $a_xml_writer->xmlEndTag("material");
156  $a_xml_writer->xmlEndTag("response_label");
157  }
158  $a_xml_writer->xmlEndTag("render_hotspot");
159  $a_xml_writer->xmlEndTag("response_xy");
160  $a_xml_writer->xmlEndTag("flow");
161  $a_xml_writer->xmlEndTag("presentation");
162 
163  // PART II: qti resprocessing
164  $a_xml_writer->xmlStartTag("resprocessing");
165  $a_xml_writer->xmlStartTag("outcomes");
166  $a_xml_writer->xmlStartTag("decvar");
167  $a_xml_writer->xmlEndTag("decvar");
168  $a_xml_writer->xmlEndTag("outcomes");
169  // add response conditions
170  foreach ($this->object->getAnswers() as $index => $answer) {
171  $attrs = [
172  "continue" => "Yes"
173  ];
174  $a_xml_writer->xmlStartTag("respcondition", $attrs);
175  // qti conditionvar
176  $a_xml_writer->xmlStartTag("conditionvar");
177  if (!$answer->isStateSet()) {
178  $a_xml_writer->xmlStartTag("not");
179  }
180  $areatype = "";
181  switch ($answer->getArea()) {
182  case "rect":
183  $areatype = "Rectangle";
184  break;
185  case "circle":
186  $areatype = "Ellipse";
187  break;
188  case "poly":
189  $areatype = "Bounded";
190  break;
191  }
192  $attrs = [
193  "respident" => "IM",
194  "areatype" => $areatype
195  ];
196  $a_xml_writer->xmlElement("varequal", $attrs, $answer->getCoords());
197  if (!$answer->isStateSet()) {
198  $a_xml_writer->xmlEndTag("not");
199  }
200  $a_xml_writer->xmlEndTag("conditionvar");
201  // qti setvar
202  $attrs = [
203  "action" => "Add"
204  ];
205  $a_xml_writer->xmlElement("setvar", $attrs, $answer->getPoints());
206  $linkrefid = "response_$index";
207  $attrs = [
208  "feedbacktype" => "Response",
209  "linkrefid" => $linkrefid
210  ];
211  $a_xml_writer->xmlElement("displayfeedback", $attrs);
212  $a_xml_writer->xmlEndTag("respcondition");
213  $attrs = [
214  "continue" => "Yes"
215  ];
216  $a_xml_writer->xmlStartTag("respcondition", $attrs);
217  // qti conditionvar
218  $a_xml_writer->xmlStartTag("conditionvar");
219  $attrs = [
220  "respident" => "IM"
221  ];
222  $a_xml_writer->xmlStartTag("not");
223  $a_xml_writer->xmlElement("varequal", $attrs, $answer->getCoords());
224  $a_xml_writer->xmlEndTag("not");
225  $a_xml_writer->xmlEndTag("conditionvar");
226  // qti setvar
227  $attrs = [
228  "action" => "Add"
229  ];
230  $a_xml_writer->xmlElement("setvar", $attrs, $answer->getPointsUnchecked());
231  $a_xml_writer->xmlEndTag("respcondition");
232  }
233 
234  $answers = $this->object->getAnswers();
235  $feedback_allcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
236  $this->object->getId(),
237  true
238  );
239  if (strlen($feedback_allcorrect) && count($answers) > 0) {
240  $attrs = [
241  "continue" => "Yes"
242  ];
243  $a_xml_writer->xmlStartTag("respcondition", $attrs);
244  // qti conditionvar
245  $a_xml_writer->xmlStartTag("conditionvar");
246  if (!$this->object->getIsMultipleChoice()) {
247  $bestindex = 0;
248  $maxpoints = 0;
249  foreach ($answers as $index => $answer) {
250  if ($answer->getPoints() > $maxpoints) {
251  $maxpoints = $answer->getPoints();
252  $bestindex = $index;
253  }
254  }
255 
256  $areatype = "";
257  $answer = $answers[$bestindex];
258  switch ($answer->getArea()) {
259  case "rect":
260  $areatype = "Rectangle";
261  break;
262  case "circle":
263  $areatype = "Ellipse";
264  break;
265  case "poly":
266  $areatype = "Bounded";
267  break;
268  }
269  $attrs = [
270  "respident" => "IM",
271  "areatype" => $areatype
272  ];
273  $a_xml_writer->xmlElement("varinside", $attrs, $answer->getCoords());
274  } else {
275  foreach ($answers as $index => $answer) {
276  if ($answer->getPoints() < $answer->getPointsUnchecked()) {
277  $a_xml_writer->xmlStartTag("not");
278  }
279  switch ($answer->getArea()) {
280  case "rect":
281  $areatype = "Rectangle";
282  break;
283  case "circle":
284  $areatype = "Ellipse";
285  break;
286  case "poly":
287  $areatype = "Bounded";
288  break;
289  }
290  $attrs = [
291  "respident" => "IM",
292  "areatype" => $areatype
293  ];
294  $a_xml_writer->xmlElement("varequal", $attrs, $index);
295  if ($answer->getPoints() < $answer->getPointsUnchecked()) {
296  $a_xml_writer->xmlEndTag("not");
297  }
298  }
299  }
300 
301  $a_xml_writer->xmlEndTag("conditionvar");
302  // qti displayfeedback
303  $attrs = [
304  "feedbacktype" => "Response",
305  "linkrefid" => "response_allcorrect"
306  ];
307  $a_xml_writer->xmlElement("displayfeedback", $attrs);
308  $a_xml_writer->xmlEndTag("respcondition");
309  }
310 
311  $feedback_onenotcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
312  $this->object->getId(),
313  false
314  );
315  if (strlen($feedback_onenotcorrect) && count($answers) > 0) {
316  $attrs = [
317  "continue" => "Yes"
318  ];
319  $a_xml_writer->xmlStartTag("respcondition", $attrs);
320  // qti conditionvar
321  $a_xml_writer->xmlStartTag("conditionvar");
322  if (!$this->object->getIsMultipleChoice()) {
323  $bestindex = 0;
324  $maxpoints = 0;
325  foreach ($answers as $index => $answer) {
326  if ($answer->getPoints() > $maxpoints) {
327  $maxpoints = $answer->getPoints();
328  $bestindex = $index;
329  }
330  }
331  $attrs = [
332  "respident" => "IM"
333  ];
334  $a_xml_writer->xmlStartTag("not");
335 
336  $areatype = "";
337  $answer = $answers[$bestindex];
338  switch ($answer->getArea()) {
339  case "rect":
340  $areatype = "Rectangle";
341  break;
342  case "circle":
343  $areatype = "Ellipse";
344  break;
345  case "poly":
346  $areatype = "Bounded";
347  break;
348  }
349  $attrs = [
350  "respident" => "IM",
351  "areatype" => $areatype
352  ];
353  $a_xml_writer->xmlElement("varinside", $attrs, $answer->getCoords());
354 
355  $a_xml_writer->xmlEndTag("not");
356  } else {
357  foreach ($answers as $index => $answer) {
358  if ($index > 0) {
359  $a_xml_writer->xmlStartTag("or");
360  }
361  if ($answer->getPoints() >= $answer->getPointsUnchecked()) {
362  $a_xml_writer->xmlStartTag("not");
363  }
364  switch ($answer->getArea()) {
365  case "rect":
366  $areatype = "Rectangle";
367  break;
368  case "circle":
369  $areatype = "Ellipse";
370  break;
371  case "poly":
372  $areatype = "Bounded";
373  break;
374  }
375  $attrs = [
376  "respident" => "IM",
377  "areatype" => $areatype
378  ];
379  $a_xml_writer->xmlElement("varequal", $attrs, $index);
380  if ($answer->getPoints() >= $answer->getPointsUnchecked()) {
381  $a_xml_writer->xmlEndTag("not");
382  }
383  if ($index > 0) {
384  $a_xml_writer->xmlEndTag("or");
385  }
386  }
387  }
388  $a_xml_writer->xmlEndTag("conditionvar");
389  // qti displayfeedback
390  $attrs = [
391  "feedbacktype" => "Response",
392  "linkrefid" => "response_onenotcorrect"
393  ];
394  $a_xml_writer->xmlElement("displayfeedback", $attrs);
395  $a_xml_writer->xmlEndTag("respcondition");
396  }
397 
398  $a_xml_writer->xmlEndTag("resprocessing");
399 
400  // PART III: qti itemfeedback
401  foreach ($this->object->getAnswers() as $index => $answer) {
402  $linkrefid = "response_$index";
403  $attrs = [
404  "ident" => $linkrefid,
405  "view" => "All"
406  ];
407  $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
408  // qti flow_mat
409  $a_xml_writer->xmlStartTag("flow_mat");
410  $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation(
411  $this->object->getId(),
412  0,
413  $index
414  );
415  $this->addQTIMaterial($a_xml_writer, $fb);
416  $a_xml_writer->xmlEndTag("flow_mat");
417  $a_xml_writer->xmlEndTag("itemfeedback");
418  }
419  if (strlen($feedback_allcorrect)) {
420  $attrs = [
421  "ident" => "response_allcorrect",
422  "view" => "All"
423  ];
424  $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
425  // qti flow_mat
426  $a_xml_writer->xmlStartTag("flow_mat");
427  $this->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
428  $a_xml_writer->xmlEndTag("flow_mat");
429  $a_xml_writer->xmlEndTag("itemfeedback");
430  }
431  if (strlen($feedback_onenotcorrect)) {
432  $attrs = [
433  "ident" => "response_onenotcorrect",
434  "view" => "All"
435  ];
436  $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
437  // qti flow_mat
438  $a_xml_writer->xmlStartTag("flow_mat");
439  $this->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
440  $a_xml_writer->xmlEndTag("flow_mat");
441  $a_xml_writer->xmlEndTag("itemfeedback");
442  }
443 
444  $a_xml_writer = $this->addSolutionHints($a_xml_writer);
445 
446  $a_xml_writer->xmlEndTag("item");
447  $a_xml_writer->xmlEndTag("questestinterop");
448 
449  $xml = $a_xml_writer->xmlDumpMem(false);
450  if (!$a_include_header) {
451  $pos = strpos($xml, "?>");
452  $xml = substr($xml, $pos + 2);
453  }
454  return $xml;
455  }
const IL_INST_ID
Definition: constants.php:40
addSuggestedSolutionLink(ilXmlWriter $writer, assQuestionSuggestedSolution $suggested_solution)
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...
addGeneralMetadata(ilXmlWriter $xmlwriter)
$ilErr
Definition: raiseError.php:17
$GLOBALS["DIC"]
Definition: wac.php:31
$DIC
Definition: xapitoken.php:62
addAdditionalContentEditingModeInformation(ilXmlWriter $a_xml_writer)
adds a qti meta data field for ilias specific information of "additional content editing mode" (xml w...
addSolutionHints(ilXmlWriter $writer)
+ Here is the call graph for this function:

The documentation for this class was generated from the following file: