ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f87
assMultipleChoiceExport Class Reference

Class for multiple choice question exports. More...

+ Inheritance diagram for assMultipleChoiceExport:
+ Collaboration diagram for assMultipleChoiceExport:

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 multiple choice question exports.

assMultipleChoiceExport is a class for multiple choice 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.assMultipleChoiceExport.php.

Member Function Documentation

◆ toXML()

assMultipleChoiceExport::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 26 of file class.assMultipleChoiceExport.php.

References assQuestionExport\addAdditionalContentEditingModeInformation(), assQuestionExport\addGeneralMetadata(), MULTIPLE_CHOICE_QUESTION_IDENTIFIER, and ilXmlWriter\xmlHeader().

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, MULTIPLE_CHOICE_QUESTION_IDENTIFIER);
57  $a_xml_writer->xmlEndTag("qtimetadatafield");
58  $a_xml_writer->xmlStartTag("qtimetadatafield");
59  $a_xml_writer->xmlElement("fieldlabel", NULL, "AUTHOR");
60  $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getAuthor());
61  $a_xml_writer->xmlEndTag("qtimetadatafield");
62 
63  // additional content editing information
64  $this->addAdditionalContentEditingModeInformation($a_xml_writer);
65  $this->addGeneralMetadata($a_xml_writer);
66 
67  $a_xml_writer->xmlStartTag("qtimetadatafield");
68  $a_xml_writer->xmlElement("fieldlabel", NULL, "thumb_size");
69  $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getThumbSize());
70  $a_xml_writer->xmlEndTag("qtimetadatafield");
71 
72  $a_xml_writer->xmlStartTag("qtimetadatafield");
73  $a_xml_writer->xmlElement("fieldlabel", NULL, "feedback_setting");
74  $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getSpecificFeedbackSetting());
75  $a_xml_writer->xmlEndTag("qtimetadatafield");
76 
77  $a_xml_writer->xmlEndTag("qtimetadata");
78  $a_xml_writer->xmlEndTag("itemmetadata");
79 
80  // PART I: qti presentation
81  $attrs = array(
82  "label" => $this->object->getTitle()
83  );
84  $a_xml_writer->xmlStartTag("presentation", $attrs);
85  // add flow to presentation
86  $a_xml_writer->xmlStartTag("flow");
87  // add material with question text to presentation
88  $this->object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
89  // add answers to presentation
90  $attrs = array();
91  $attrs = array(
92  "ident" => "MCMR",
93  "rcardinality" => "Multiple"
94  );
95  $a_xml_writer->xmlStartTag("response_lid", $attrs);
96  $solution = $this->object->getSuggestedSolution(0);
97  if (count($solution))
98  {
99  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches))
100  {
101  $a_xml_writer->xmlStartTag("material");
102  $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
103  if (strcmp($matches[1], "") != 0)
104  {
105  $intlink = $solution["internal_link"];
106  }
107  $attrs = array(
108  "label" => "suggested_solution"
109  );
110  $a_xml_writer->xmlElement("mattext", $attrs, $intlink);
111  $a_xml_writer->xmlEndTag("material");
112  }
113  }
114  // shuffle output
115  $attrs = array();
116  if ($this->object->getShuffle())
117  {
118  $attrs = array(
119  "shuffle" => "Yes"
120  );
121  }
122  else
123  {
124  $attrs = array(
125  "shuffle" => "No"
126  );
127  }
128  $a_xml_writer->xmlStartTag("render_choice", $attrs);
129  $answers =& $this->object->getAnswers();
130  $akeys = array_keys($answers);
131  if ($this->object->getShuffle() && $a_shuffle)
132  {
133  $akeys = $this->object->pcArrayShuffle($akeys);
134  }
135  // add answers
136  foreach ($akeys as $index)
137  {
138  $answer = $answers[$index];
139  $attrs = array(
140  "ident" => $index
141  );
142  $a_xml_writer->xmlStartTag("response_label", $attrs);
143 
144  if (strlen($answer->getImage()))
145  {
146  $this->object->addQTIMaterial($a_xml_writer, $answer->getAnswertext(), FALSE, FALSE);
147  $imagetype = "image/jpeg";
148  if (preg_match("/.*\.(png|gif)$/", $answer->getImage(), $matches))
149  {
150  $imagetype = "image/" . $matches[1];
151  }
152  if ($force_image_references)
153  {
154  $attrs = array(
155  "imagtype" => $imagetype,
156  "label" => $answer->getImage(),
157  "uri" => $this->object->getImagePathWeb() . $answer->getImage()
158  );
159  $a_xml_writer->xmlElement("matimage", $attrs);
160  }
161  else
162  {
163  $imagepath = $this->object->getImagePath() . $answer->getImage();
164  $fh = @fopen($imagepath, "rb");
165  if ($fh != false)
166  {
167  $imagefile = fread($fh, filesize($imagepath));
168  fclose($fh);
169  $base64 = base64_encode($imagefile);
170  $attrs = array(
171  "imagtype" => $imagetype,
172  "label" => $answer->getImage(),
173  "embedded" => "base64"
174  );
175  $a_xml_writer->xmlElement("matimage", $attrs, $base64, FALSE, FALSE);
176  }
177  }
178  $a_xml_writer->xmlEndTag("material");
179  }
180  else
181  {
182  $this->object->addQTIMaterial($a_xml_writer, $answer->getAnswertext());
183  }
184  $a_xml_writer->xmlEndTag("response_label");
185  }
186  $a_xml_writer->xmlEndTag("render_choice");
187  $a_xml_writer->xmlEndTag("response_lid");
188  $a_xml_writer->xmlEndTag("flow");
189  $a_xml_writer->xmlEndTag("presentation");
190 
191  // PART II: qti resprocessing
192  $a_xml_writer->xmlStartTag("resprocessing");
193  $a_xml_writer->xmlStartTag("outcomes");
194  $a_xml_writer->xmlStartTag("decvar");
195  $a_xml_writer->xmlEndTag("decvar");
196  $a_xml_writer->xmlEndTag("outcomes");
197  // add response conditions
198  foreach ($answers as $index => $answer)
199  {
200  $attrs = array(
201  "continue" => "Yes"
202  );
203  $a_xml_writer->xmlStartTag("respcondition", $attrs);
204  // qti conditionvar
205  $a_xml_writer->xmlStartTag("conditionvar");
206  $attrs = array();
207  $attrs = array(
208  "respident" => "MCMR"
209  );
210  $a_xml_writer->xmlElement("varequal", $attrs, $index);
211  $a_xml_writer->xmlEndTag("conditionvar");
212  // qti setvar
213  $attrs = array(
214  "action" => "Add"
215  );
216  $a_xml_writer->xmlElement("setvar", $attrs, $answer->getPoints());
217  // qti displayfeedback
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 
230  // qti conditionvar
231  $a_xml_writer->xmlStartTag("conditionvar");
232  $attrs = array();
233  $attrs = array(
234  "respident" => "MCMR"
235  );
236  $a_xml_writer->xmlStartTag("not");
237  $a_xml_writer->xmlElement("varequal", $attrs, $index);
238  $a_xml_writer->xmlEndTag("not");
239  $a_xml_writer->xmlEndTag("conditionvar");
240  // qti setvar
241  $attrs = array(
242  "action" => "Add"
243  );
244  $a_xml_writer->xmlElement("setvar", $attrs, $answer->getPointsUnchecked());
245  $a_xml_writer->xmlEndTag("respcondition");
246  }
247  $feedback_allcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
248  $this->object->getId(), true
249  );
250  if (strlen($feedback_allcorrect))
251  {
252  $attrs = array(
253  "continue" => "Yes"
254  );
255  $a_xml_writer->xmlStartTag("respcondition", $attrs);
256  // qti conditionvar
257  $a_xml_writer->xmlStartTag("conditionvar");
258  foreach ($answers as $index => $answer)
259  {
260  if ($answer->getPointsChecked() < $answer->getPointsUnchecked())
261  {
262  $a_xml_writer->xmlStartTag("not");
263  }
264  $attrs = array(
265  "respident" => "MCMR"
266  );
267  $a_xml_writer->xmlElement("varequal", $attrs, $index);
268  if ($answer->getPointsChecked() < $answer->getPointsUnchecked())
269  {
270  $a_xml_writer->xmlEndTag("not");
271  }
272  }
273  $a_xml_writer->xmlEndTag("conditionvar");
274  // qti displayfeedback
275  $attrs = array(
276  "feedbacktype" => "Response",
277  "linkrefid" => "response_allcorrect"
278  );
279  $a_xml_writer->xmlElement("displayfeedback", $attrs);
280  $a_xml_writer->xmlEndTag("respcondition");
281  }
282  $feedback_onenotcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
283  $this->object->getId(), false
284  );
285  if (strlen($feedback_onenotcorrect))
286  {
287  $attrs = array(
288  "continue" => "Yes"
289  );
290  $a_xml_writer->xmlStartTag("respcondition", $attrs);
291  // qti conditionvar
292  $a_xml_writer->xmlStartTag("conditionvar");
293  foreach ($answers as $index => $answer)
294  {
295  if ($index > 0)
296  {
297  $a_xml_writer->xmlStartTag("or");
298  }
299  if ($answer->getPointsChecked() >= $answer->getPointsUnchecked())
300  {
301  $a_xml_writer->xmlStartTag("not");
302  }
303  $attrs = array(
304  "respident" => "MCMR"
305  );
306  $a_xml_writer->xmlElement("varequal", $attrs, $index);
307  if ($answer->getPointsChecked() >= $answer->getPointsUnchecked())
308  {
309  $a_xml_writer->xmlEndTag("not");
310  }
311  if ($index > 0)
312  {
313  $a_xml_writer->xmlEndTag("or");
314  }
315  }
316  $a_xml_writer->xmlEndTag("conditionvar");
317  // qti displayfeedback
318  $attrs = array(
319  "feedbacktype" => "Response",
320  "linkrefid" => "response_onenotcorrect"
321  );
322  $a_xml_writer->xmlElement("displayfeedback", $attrs);
323  $a_xml_writer->xmlEndTag("respcondition");
324  }
325  $a_xml_writer->xmlEndTag("resprocessing");
326 
327  // PART III: qti itemfeedback
328  foreach ($answers as $index => $answer)
329  {
330  $linkrefid = "response_$index";
331  $attrs = array(
332  "ident" => $linkrefid,
333  "view" => "All"
334  );
335  $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
336  // qti flow_mat
337  $a_xml_writer->xmlStartTag("flow_mat");
338  $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation(
339  $this->object->getId(), $index
340  );
341  $this->object->addQTIMaterial($a_xml_writer, $fb);
342  $a_xml_writer->xmlEndTag("flow_mat");
343  $a_xml_writer->xmlEndTag("itemfeedback");
344  }
345  if (strlen($feedback_allcorrect))
346  {
347  $attrs = array(
348  "ident" => "response_allcorrect",
349  "view" => "All"
350  );
351  $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
352  // qti flow_mat
353  $a_xml_writer->xmlStartTag("flow_mat");
354  $this->object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
355  $a_xml_writer->xmlEndTag("flow_mat");
356  $a_xml_writer->xmlEndTag("itemfeedback");
357  }
358  if (strlen($feedback_onenotcorrect))
359  {
360  $attrs = array(
361  "ident" => "response_onenotcorrect",
362  "view" => "All"
363  );
364  $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
365  // qti flow_mat
366  $a_xml_writer->xmlStartTag("flow_mat");
367  $this->object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
368  $a_xml_writer->xmlEndTag("flow_mat");
369  $a_xml_writer->xmlEndTag("itemfeedback");
370  }
371 
372  $a_xml_writer->xmlEndTag("item");
373  $a_xml_writer->xmlEndTag("questestinterop");
374 
375  $xml = $a_xml_writer->xmlDumpMem(FALSE);
376  if (!$a_include_header)
377  {
378  $pos = strpos($xml, "?>");
379  $xml = substr($xml, $pos + 2);
380  }
381  return $xml;
382  }
const MULTIPLE_CHOICE_QUESTION_IDENTIFIER
XML writer class.
addGeneralMetadata(ilXmlWriter $xmlwriter)
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...
+ Here is the call graph for this function:

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