ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
assMultipleChoiceExport 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 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 Returns a QTI xml representation of the question and sets the internal domxml variable with the DOM XML representation of the QTI xml representation @access public. 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...
 
 addQTIMaterial (ilXmlWriter $a_xml_writer, string $a_material, bool $close_material_tag=true, bool $add_mobs=true)
 

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)
 
 addSuggestedSolution (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 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 28 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 @access public.

Reimplemented from assQuestionExport.

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

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

References $DIC, assQuestionExport\addAdditionalContentEditingModeInformation(), assQuestionExport\addGeneralMetadata(), assQuestionExport\addQTIMaterial(), assQuestionExport\addQtiMetaDataField(), assQuestionExport\addSuggestedSolution(), IL_INST_ID, and ILIAS\Repository\object().

+ Here is the call graph for this function:

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