ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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. More...
 
- Public Member Functions inherited from assQuestionExport
 assQuestionExport (&$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. More...
 

Additional Inherited Members

- Data Fields inherited from assQuestionExport
 $object
 
- 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)
 

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 15 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 26 of file class.assImagemapQuestionExport.php.

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

References $GLOBALS, $ilErr, assQuestionExport\addAdditionalContentEditingModeInformation(), assQuestionExport\addGeneralMetadata(), IMAGEMAP_QUESTION_IDENTIFIER, and ilXmlWriter\xmlHeader().

+ Here is the call graph for this function:

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