ILIAS  release_8 Revision v8.24
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...
 

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)
 

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 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 @access public

Reimplemented from assQuestionExport.

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

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

References $DIC, $GLOBALS, $ilErr, $index, $xml, assQuestionExport\addAdditionalContentEditingModeInformation(), assQuestionExport\addGeneralMetadata(), assQuestionExport\addSolutionHints(), IL_INST_ID, IMAGEMAP_QUESTION_IDENTIFIER, and ILIAS\Repository\object().

+ Here is the call graph for this function:

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