ILIAS  release_7 Revision v7.30-3-g800a261c036
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
 
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

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

Reimplemented from assQuestionExport.

Definition at line 26 of file class.assMultipleChoiceExport.php.

27 {
28 global $DIC;
29 $ilias = $DIC['ilias'];
30
31 include_once("./Services/Xml/classes/class.ilXmlWriter.php");
32 $a_xml_writer = new ilXmlWriter;
33 // set xml header
34 $a_xml_writer->xmlHeader();
35 $a_xml_writer->xmlStartTag("questestinterop");
36 $attrs = array(
37 "ident" => "il_" . IL_INST_ID . "_qst_" . $this->object->getId(),
38 "title" => $this->object->getTitle(),
39 "maxattempts" => $this->object->getNrOfTries()
40 );
41 $a_xml_writer->xmlStartTag("item", $attrs);
42 // add question description
43 $a_xml_writer->xmlElement("qticomment", null, $this->object->getComment());
44 // add estimated working time
45 $workingtime = $this->object->getEstimatedWorkingTime();
46 $duration = sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]);
47 $a_xml_writer->xmlElement("duration", null, $duration);
48 // add ILIAS specific metadata
49 $a_xml_writer->xmlStartTag("itemmetadata");
50 $a_xml_writer->xmlStartTag("qtimetadata");
51 $a_xml_writer->xmlStartTag("qtimetadatafield");
52 $a_xml_writer->xmlElement("fieldlabel", null, "ILIAS_VERSION");
53 $a_xml_writer->xmlElement("fieldentry", null, $ilias->getSetting("ilias_version"));
54 $a_xml_writer->xmlEndTag("qtimetadatafield");
55 $a_xml_writer->xmlStartTag("qtimetadatafield");
56 $a_xml_writer->xmlElement("fieldlabel", null, "QUESTIONTYPE");
57 $a_xml_writer->xmlElement("fieldentry", null, MULTIPLE_CHOICE_QUESTION_IDENTIFIER);
58 $a_xml_writer->xmlEndTag("qtimetadatafield");
59 $a_xml_writer->xmlStartTag("qtimetadatafield");
60 $a_xml_writer->xmlElement("fieldlabel", null, "AUTHOR");
61 $a_xml_writer->xmlElement("fieldentry", null, $this->object->getAuthor());
62 $a_xml_writer->xmlEndTag("qtimetadatafield");
63
64 // additional content editing information
66 $this->addGeneralMetadata($a_xml_writer);
67
68 $a_xml_writer->xmlStartTag("qtimetadatafield");
69 $a_xml_writer->xmlElement("fieldlabel", null, "thumb_size");
70 $a_xml_writer->xmlElement("fieldentry", null, $this->object->getThumbSize());
71 $a_xml_writer->xmlEndTag("qtimetadatafield");
72
73 $a_xml_writer->xmlStartTag("qtimetadatafield");
74 $a_xml_writer->xmlElement("fieldlabel", null, "feedback_setting");
75 $a_xml_writer->xmlElement("fieldentry", null, $this->object->getSpecificFeedbackSetting());
76 $a_xml_writer->xmlEndTag("qtimetadatafield");
77
78 $this->addQtiMetaDataField($a_xml_writer, 'singleline', $this->object->isSingleline ? 1 : 0);
79
80 $a_xml_writer->xmlEndTag("qtimetadata");
81 $a_xml_writer->xmlEndTag("itemmetadata");
82
83 // PART I: qti presentation
84 $attrs = array(
85 "label" => $this->object->getTitle()
86 );
87 $a_xml_writer->xmlStartTag("presentation", $attrs);
88 // add flow to presentation
89 $a_xml_writer->xmlStartTag("flow");
90 // add material with question text to presentation
91 $this->object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
92 // add answers to presentation
93 $attrs = array();
94 $attrs = array(
95 "ident" => "MCMR",
96 "rcardinality" => "Multiple"
97 );
98 $a_xml_writer->xmlStartTag("response_lid", $attrs);
99 $solution = $this->object->getSuggestedSolution(0);
100 if (count($solution)) {
101 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches)) {
102 $a_xml_writer->xmlStartTag("material");
103 $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
104 if (strcmp($matches[1], "") != 0) {
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 and max choice
115 $attrs = array('shuffle' => $this->object->getShuffle() ? 'Yes' : 'No');
116 if ($this->object->getSelectionLimit()) {
117 $attrs['minnumber'] = '0';
118 $attrs['maxnumber'] = (string) $this->object->getSelectionLimit();
119 }
120 $a_xml_writer->xmlStartTag("render_choice", $attrs);
121 $answers = &$this->object->getAnswers();
122 $akeys = array_keys($answers);
123 if ($this->object->getShuffle() && $a_shuffle) {
124 $akeys = $this->object->pcArrayShuffle($akeys);
125 }
126 // add answers
127 foreach ($akeys as $index) {
128 $answer = $answers[$index];
129 $attrs = array(
130 "ident" => $index
131 );
132 $a_xml_writer->xmlStartTag("response_label", $attrs);
133
134 if (strlen($answer->getImage())) {
135 $this->object->addQTIMaterial($a_xml_writer, $answer->getAnswertext(), false, false);
136 $imagetype = "image/jpeg";
137 if (preg_match("/.*\.(png|gif)$/", $answer->getImage(), $matches)) {
138 $imagetype = "image/" . $matches[1];
139 }
140 if ($force_image_references) {
141 $attrs = array(
142 "imagtype" => $imagetype,
143 "label" => $answer->getImage(),
144 "uri" => $this->object->getImagePathWeb() . $answer->getImage()
145 );
146 $a_xml_writer->xmlElement("matimage", $attrs);
147 } else {
148 $imagepath = $this->object->getImagePath() . $answer->getImage();
149 $fh = @fopen($imagepath, "rb");
150 if ($fh != false) {
151 $imagefile = fread($fh, filesize($imagepath));
152 fclose($fh);
153 $base64 = base64_encode($imagefile);
154 $attrs = array(
155 "imagtype" => $imagetype,
156 "label" => $answer->getImage(),
157 "embedded" => "base64"
158 );
159 $a_xml_writer->xmlElement("matimage", $attrs, $base64, false, false);
160 }
161 }
162 $a_xml_writer->xmlEndTag("material");
163 } else {
164 $this->object->addQTIMaterial($a_xml_writer, $answer->getAnswertext());
165 }
166 $a_xml_writer->xmlEndTag("response_label");
167 }
168 $a_xml_writer->xmlEndTag("render_choice");
169 $a_xml_writer->xmlEndTag("response_lid");
170 $a_xml_writer->xmlEndTag("flow");
171 $a_xml_writer->xmlEndTag("presentation");
172
173 // PART II: qti resprocessing
174 $a_xml_writer->xmlStartTag("resprocessing");
175 $a_xml_writer->xmlStartTag("outcomes");
176 $a_xml_writer->xmlStartTag("decvar");
177 $a_xml_writer->xmlEndTag("decvar");
178 $a_xml_writer->xmlEndTag("outcomes");
179 // add response conditions
180 foreach ($answers as $index => $answer) {
181 $attrs = array(
182 "continue" => "Yes"
183 );
184 $a_xml_writer->xmlStartTag("respcondition", $attrs);
185 // qti conditionvar
186 $a_xml_writer->xmlStartTag("conditionvar");
187 $attrs = array();
188 $attrs = array(
189 "respident" => "MCMR"
190 );
191 $a_xml_writer->xmlElement("varequal", $attrs, $index);
192 $a_xml_writer->xmlEndTag("conditionvar");
193 // qti setvar
194 $attrs = array(
195 "action" => "Add"
196 );
197 $a_xml_writer->xmlElement("setvar", $attrs, $answer->getPoints());
198 // qti displayfeedback
199 $linkrefid = "response_$index";
200 $attrs = array(
201 "feedbacktype" => "Response",
202 "linkrefid" => $linkrefid
203 );
204 $a_xml_writer->xmlElement("displayfeedback", $attrs);
205 $a_xml_writer->xmlEndTag("respcondition");
206 $attrs = array(
207 "continue" => "Yes"
208 );
209 $a_xml_writer->xmlStartTag("respcondition", $attrs);
210
211 // qti conditionvar
212 $a_xml_writer->xmlStartTag("conditionvar");
213 $attrs = array();
214 $attrs = array(
215 "respident" => "MCMR"
216 );
217 $a_xml_writer->xmlStartTag("not");
218 $a_xml_writer->xmlElement("varequal", $attrs, $index);
219 $a_xml_writer->xmlEndTag("not");
220 $a_xml_writer->xmlEndTag("conditionvar");
221 // qti setvar
222 $attrs = array(
223 "action" => "Add"
224 );
225 $a_xml_writer->xmlElement("setvar", $attrs, $answer->getPointsUnchecked());
226 $a_xml_writer->xmlEndTag("respcondition");
227 }
228 $feedback_allcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
229 $this->object->getId(),
230 true
231 );
232 if (strlen($feedback_allcorrect)) {
233 $attrs = array(
234 "continue" => "Yes"
235 );
236 $a_xml_writer->xmlStartTag("respcondition", $attrs);
237 // qti conditionvar
238 $a_xml_writer->xmlStartTag("conditionvar");
239 foreach ($answers as $index => $answer) {
240 if ($answer->getPointsChecked() < $answer->getPointsUnchecked()) {
241 $a_xml_writer->xmlStartTag("not");
242 }
243 $attrs = array(
244 "respident" => "MCMR"
245 );
246 $a_xml_writer->xmlElement("varequal", $attrs, $index);
247 if ($answer->getPointsChecked() < $answer->getPointsUnchecked()) {
248 $a_xml_writer->xmlEndTag("not");
249 }
250 }
251 $a_xml_writer->xmlEndTag("conditionvar");
252 // qti displayfeedback
253 $attrs = array(
254 "feedbacktype" => "Response",
255 "linkrefid" => "response_allcorrect"
256 );
257 $a_xml_writer->xmlElement("displayfeedback", $attrs);
258 $a_xml_writer->xmlEndTag("respcondition");
259 }
260 $feedback_onenotcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
261 $this->object->getId(),
262 false
263 );
264 if (strlen($feedback_onenotcorrect)) {
265 $attrs = array(
266 "continue" => "Yes"
267 );
268 $a_xml_writer->xmlStartTag("respcondition", $attrs);
269 // qti conditionvar
270 $a_xml_writer->xmlStartTag("conditionvar");
271 foreach ($answers as $index => $answer) {
272 if ($index > 0) {
273 $a_xml_writer->xmlStartTag("or");
274 }
275 if ($answer->getPointsChecked() >= $answer->getPointsUnchecked()) {
276 $a_xml_writer->xmlStartTag("not");
277 }
278 $attrs = array(
279 "respident" => "MCMR"
280 );
281 $a_xml_writer->xmlElement("varequal", $attrs, $index);
282 if ($answer->getPointsChecked() >= $answer->getPointsUnchecked()) {
283 $a_xml_writer->xmlEndTag("not");
284 }
285 if ($index > 0) {
286 $a_xml_writer->xmlEndTag("or");
287 }
288 }
289 $a_xml_writer->xmlEndTag("conditionvar");
290 // qti displayfeedback
291 $attrs = array(
292 "feedbacktype" => "Response",
293 "linkrefid" => "response_onenotcorrect"
294 );
295 $a_xml_writer->xmlElement("displayfeedback", $attrs);
296 $a_xml_writer->xmlEndTag("respcondition");
297 }
298 $a_xml_writer->xmlEndTag("resprocessing");
299
300 // PART III: qti itemfeedback
301 foreach ($answers as $index => $answer) {
302 $linkrefid = "response_$index";
303 $attrs = array(
304 "ident" => $linkrefid,
305 "view" => "All"
306 );
307 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
308 // qti flow_mat
309 $a_xml_writer->xmlStartTag("flow_mat");
310 $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation(
311 $this->object->getId(),
312 0,
313 $index
314 );
315 $this->object->addQTIMaterial($a_xml_writer, $fb);
316 $a_xml_writer->xmlEndTag("flow_mat");
317 $a_xml_writer->xmlEndTag("itemfeedback");
318 }
319 if (strlen($feedback_allcorrect)) {
320 $attrs = array(
321 "ident" => "response_allcorrect",
322 "view" => "All"
323 );
324 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
325 // qti flow_mat
326 $a_xml_writer->xmlStartTag("flow_mat");
327 $this->object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
328 $a_xml_writer->xmlEndTag("flow_mat");
329 $a_xml_writer->xmlEndTag("itemfeedback");
330 }
331 if (strlen($feedback_onenotcorrect)) {
332 $attrs = array(
333 "ident" => "response_onenotcorrect",
334 "view" => "All"
335 );
336 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
337 // qti flow_mat
338 $a_xml_writer->xmlStartTag("flow_mat");
339 $this->object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
340 $a_xml_writer->xmlEndTag("flow_mat");
341 $a_xml_writer->xmlEndTag("itemfeedback");
342 }
343
344 $a_xml_writer = $this->addSolutionHints($a_xml_writer);
345
346 $a_xml_writer->xmlEndTag("item");
347 $a_xml_writer->xmlEndTag("questestinterop");
348
349 $xml = $a_xml_writer->xmlDumpMem(false);
350 if (!$a_include_header) {
351 $pos = strpos($xml, "?>");
352 $xml = substr($xml, $pos + 2);
353 }
354 return $xml;
355 }
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 ...
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...
XML writer class.
xmlHeader()
Writes xml header @access public.
const IL_INST_ID
Definition: constants.php:38
global $DIC
Definition: goto.php:24
const MULTIPLE_CHOICE_QUESTION_IDENTIFIER
$index
Definition: metadata.php:128
$xml
Definition: metadata.php:332

References $DIC, $index, $xml, assQuestionExport\addAdditionalContentEditingModeInformation(), assQuestionExport\addGeneralMetadata(), assQuestionExport\addQtiMetaDataField(), assQuestionExport\addSolutionHints(), IL_INST_ID, MULTIPLE_CHOICE_QUESTION_IDENTIFIER, and ilXmlWriter\xmlHeader().

+ Here is the call graph for this function:

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