ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
assSingleChoiceExport 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 assSingleChoiceExport:
+ Collaboration diagram for assSingleChoiceExport:

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

assSingleChoiceExport is a class for single 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.assSingleChoiceExport.php.

Member Function Documentation

◆ toXML()

assSingleChoiceExport::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.

Reimplemented from assQuestionExport.

Definition at line 35 of file class.assSingleChoiceExport.php.

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