ILIAS  trunk Revision v11.0_alpha-1866-gfa368f7776e
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
assImagemapQuestionExport Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. 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)
 
 addSuggestedSolution (ilXmlWriter $writer)
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning 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 27 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 36 of file class.assImagemapQuestionExport.php.

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

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

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