ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
 __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. 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 $duration, $fh, assQuestionExport\addAdditionalContentEditingModeInformation(), assQuestionExport\addGeneralMetadata(), assQuestionExport\addQtiMetaDataField(), array, MULTIPLE_CHOICE_QUESTION_IDENTIFIER, object, string, 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  $this->addQtiMetaDataField($a_xml_writer, 'singleline', $this->object->isSingleline ? 1 : 0);
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  $attrs = array(
94  "ident" => "MCMR",
95  "rcardinality" => "Multiple"
96  );
97  $a_xml_writer->xmlStartTag("response_lid", $attrs);
98  $solution = $this->object->getSuggestedSolution(0);
99  if (count($solution))
100  {
101  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches))
102  {
103  $a_xml_writer->xmlStartTag("material");
104  $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
105  if (strcmp($matches[1], "") != 0)
106  {
107  $intlink = $solution["internal_link"];
108  }
109  $attrs = array(
110  "label" => "suggested_solution"
111  );
112  $a_xml_writer->xmlElement("mattext", $attrs, $intlink);
113  $a_xml_writer->xmlEndTag("material");
114  }
115  }
116  // shuffle output and max choice
117  $attrs = array('shuffle' => $this->object->getShuffle() ? 'Yes' : 'No');
118  if($this->object->getSelectionLimit())
119  {
120  $attrs['minnumber'] = '0';
121  $attrs['maxnumber'] = (string)$this->object->getSelectionLimit();
122  }
123  $a_xml_writer->xmlStartTag("render_choice", $attrs);
124  $answers =& $this->object->getAnswers();
125  $akeys = array_keys($answers);
126  if ($this->object->getShuffle() && $a_shuffle)
127  {
128  $akeys = $this->object->pcArrayShuffle($akeys);
129  }
130  // add answers
131  foreach ($akeys as $index)
132  {
133  $answer = $answers[$index];
134  $attrs = array(
135  "ident" => $index
136  );
137  $a_xml_writer->xmlStartTag("response_label", $attrs);
138 
139  if (strlen($answer->getImage()))
140  {
141  $this->object->addQTIMaterial($a_xml_writer, $answer->getAnswertext(), FALSE, FALSE);
142  $imagetype = "image/jpeg";
143  if (preg_match("/.*\.(png|gif)$/", $answer->getImage(), $matches))
144  {
145  $imagetype = "image/" . $matches[1];
146  }
147  if ($force_image_references)
148  {
149  $attrs = array(
150  "imagtype" => $imagetype,
151  "label" => $answer->getImage(),
152  "uri" => $this->object->getImagePathWeb() . $answer->getImage()
153  );
154  $a_xml_writer->xmlElement("matimage", $attrs);
155  }
156  else
157  {
158  $imagepath = $this->object->getImagePath() . $answer->getImage();
159  $fh = @fopen($imagepath, "rb");
160  if ($fh != false)
161  {
162  $imagefile = fread($fh, filesize($imagepath));
163  fclose($fh);
164  $base64 = base64_encode($imagefile);
165  $attrs = array(
166  "imagtype" => $imagetype,
167  "label" => $answer->getImage(),
168  "embedded" => "base64"
169  );
170  $a_xml_writer->xmlElement("matimage", $attrs, $base64, FALSE, FALSE);
171  }
172  }
173  $a_xml_writer->xmlEndTag("material");
174  }
175  else
176  {
177  $this->object->addQTIMaterial($a_xml_writer, $answer->getAnswertext());
178  }
179  $a_xml_writer->xmlEndTag("response_label");
180  }
181  $a_xml_writer->xmlEndTag("render_choice");
182  $a_xml_writer->xmlEndTag("response_lid");
183  $a_xml_writer->xmlEndTag("flow");
184  $a_xml_writer->xmlEndTag("presentation");
185 
186  // PART II: qti resprocessing
187  $a_xml_writer->xmlStartTag("resprocessing");
188  $a_xml_writer->xmlStartTag("outcomes");
189  $a_xml_writer->xmlStartTag("decvar");
190  $a_xml_writer->xmlEndTag("decvar");
191  $a_xml_writer->xmlEndTag("outcomes");
192  // add response conditions
193  foreach ($answers as $index => $answer)
194  {
195  $attrs = array(
196  "continue" => "Yes"
197  );
198  $a_xml_writer->xmlStartTag("respcondition", $attrs);
199  // qti conditionvar
200  $a_xml_writer->xmlStartTag("conditionvar");
201  $attrs = array();
202  $attrs = array(
203  "respident" => "MCMR"
204  );
205  $a_xml_writer->xmlElement("varequal", $attrs, $index);
206  $a_xml_writer->xmlEndTag("conditionvar");
207  // qti setvar
208  $attrs = array(
209  "action" => "Add"
210  );
211  $a_xml_writer->xmlElement("setvar", $attrs, $answer->getPoints());
212  // qti displayfeedback
213  $linkrefid = "response_$index";
214  $attrs = array(
215  "feedbacktype" => "Response",
216  "linkrefid" => $linkrefid
217  );
218  $a_xml_writer->xmlElement("displayfeedback", $attrs);
219  $a_xml_writer->xmlEndTag("respcondition");
220  $attrs = array(
221  "continue" => "Yes"
222  );
223  $a_xml_writer->xmlStartTag("respcondition", $attrs);
224 
225  // qti conditionvar
226  $a_xml_writer->xmlStartTag("conditionvar");
227  $attrs = array();
228  $attrs = array(
229  "respident" => "MCMR"
230  );
231  $a_xml_writer->xmlStartTag("not");
232  $a_xml_writer->xmlElement("varequal", $attrs, $index);
233  $a_xml_writer->xmlEndTag("not");
234  $a_xml_writer->xmlEndTag("conditionvar");
235  // qti setvar
236  $attrs = array(
237  "action" => "Add"
238  );
239  $a_xml_writer->xmlElement("setvar", $attrs, $answer->getPointsUnchecked());
240  $a_xml_writer->xmlEndTag("respcondition");
241  }
242  $feedback_allcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
243  $this->object->getId(), true
244  );
245  if (strlen($feedback_allcorrect))
246  {
247  $attrs = array(
248  "continue" => "Yes"
249  );
250  $a_xml_writer->xmlStartTag("respcondition", $attrs);
251  // qti conditionvar
252  $a_xml_writer->xmlStartTag("conditionvar");
253  foreach ($answers as $index => $answer)
254  {
255  if ($answer->getPointsChecked() < $answer->getPointsUnchecked())
256  {
257  $a_xml_writer->xmlStartTag("not");
258  }
259  $attrs = array(
260  "respident" => "MCMR"
261  );
262  $a_xml_writer->xmlElement("varequal", $attrs, $index);
263  if ($answer->getPointsChecked() < $answer->getPointsUnchecked())
264  {
265  $a_xml_writer->xmlEndTag("not");
266  }
267  }
268  $a_xml_writer->xmlEndTag("conditionvar");
269  // qti displayfeedback
270  $attrs = array(
271  "feedbacktype" => "Response",
272  "linkrefid" => "response_allcorrect"
273  );
274  $a_xml_writer->xmlElement("displayfeedback", $attrs);
275  $a_xml_writer->xmlEndTag("respcondition");
276  }
277  $feedback_onenotcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
278  $this->object->getId(), false
279  );
280  if (strlen($feedback_onenotcorrect))
281  {
282  $attrs = array(
283  "continue" => "Yes"
284  );
285  $a_xml_writer->xmlStartTag("respcondition", $attrs);
286  // qti conditionvar
287  $a_xml_writer->xmlStartTag("conditionvar");
288  foreach ($answers as $index => $answer)
289  {
290  if ($index > 0)
291  {
292  $a_xml_writer->xmlStartTag("or");
293  }
294  if ($answer->getPointsChecked() >= $answer->getPointsUnchecked())
295  {
296  $a_xml_writer->xmlStartTag("not");
297  }
298  $attrs = array(
299  "respident" => "MCMR"
300  );
301  $a_xml_writer->xmlElement("varequal", $attrs, $index);
302  if ($answer->getPointsChecked() >= $answer->getPointsUnchecked())
303  {
304  $a_xml_writer->xmlEndTag("not");
305  }
306  if ($index > 0)
307  {
308  $a_xml_writer->xmlEndTag("or");
309  }
310  }
311  $a_xml_writer->xmlEndTag("conditionvar");
312  // qti displayfeedback
313  $attrs = array(
314  "feedbacktype" => "Response",
315  "linkrefid" => "response_onenotcorrect"
316  );
317  $a_xml_writer->xmlElement("displayfeedback", $attrs);
318  $a_xml_writer->xmlEndTag("respcondition");
319  }
320  $a_xml_writer->xmlEndTag("resprocessing");
321 
322  // PART III: qti itemfeedback
323  foreach ($answers as $index => $answer)
324  {
325  $linkrefid = "response_$index";
326  $attrs = array(
327  "ident" => $linkrefid,
328  "view" => "All"
329  );
330  $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
331  // qti flow_mat
332  $a_xml_writer->xmlStartTag("flow_mat");
333  $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation(
334  $this->object->getId(), $index
335  );
336  $this->object->addQTIMaterial($a_xml_writer, $fb);
337  $a_xml_writer->xmlEndTag("flow_mat");
338  $a_xml_writer->xmlEndTag("itemfeedback");
339  }
340  if (strlen($feedback_allcorrect))
341  {
342  $attrs = array(
343  "ident" => "response_allcorrect",
344  "view" => "All"
345  );
346  $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
347  // qti flow_mat
348  $a_xml_writer->xmlStartTag("flow_mat");
349  $this->object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
350  $a_xml_writer->xmlEndTag("flow_mat");
351  $a_xml_writer->xmlEndTag("itemfeedback");
352  }
353  if (strlen($feedback_onenotcorrect))
354  {
355  $attrs = array(
356  "ident" => "response_onenotcorrect",
357  "view" => "All"
358  );
359  $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
360  // qti flow_mat
361  $a_xml_writer->xmlStartTag("flow_mat");
362  $this->object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
363  $a_xml_writer->xmlEndTag("flow_mat");
364  $a_xml_writer->xmlEndTag("itemfeedback");
365  }
366 
367  $a_xml_writer->xmlEndTag("item");
368  $a_xml_writer->xmlEndTag("questestinterop");
369 
370  $xml = $a_xml_writer->xmlDumpMem(FALSE);
371  if (!$a_include_header)
372  {
373  $pos = strpos($xml, "?>");
374  $xml = substr($xml, $pos + 2);
375  }
376  return $xml;
377  }
const MULTIPLE_CHOICE_QUESTION_IDENTIFIER
XML writer class.
Add rich text string
The name of the decorator.
addGeneralMetadata(ilXmlWriter $xmlwriter)
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 ...
xmlHeader()
Writes xml header public.
Create styles array
The data for the language used.
addAdditionalContentEditingModeInformation(ilXmlWriter $a_xml_writer)
adds a qti meta data field for ilias specific information of "additional content editing mode" (xml w...
Create new PHPExcel object
obj_idprivate
+ Here is the call graph for this function:

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