ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
assSingleChoiceExport Class Reference

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

Returns
string The QTI xml representation of the question @access public

Reimplemented from assQuestionExport.

Definition at line 26 of file class.assSingleChoiceExport.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, SINGLE_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" => "MCSR",
96 "rcardinality" => "Single"
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
115 $attrs = array();
116 if ($this->object->getShuffle()) {
117 $attrs = array(
118 "shuffle" => "Yes"
119 );
120 } else {
121 $attrs = array(
122 "shuffle" => "No"
123 );
124 }
125 $a_xml_writer->xmlStartTag("render_choice", $attrs);
126 $answers = &$this->object->getAnswers();
127 $akeys = array_keys($answers);
128 if ($this->object->getShuffle() && $a_shuffle) {
129 $akeys = $this->object->pcArrayShuffle($akeys);
130 }
131 // add answers
132 foreach ($akeys as $index) {
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 $this->object->addQTIMaterial($a_xml_writer, $answer->getAnswertext(), false, false);
141 $imagetype = "image/jpeg";
142 if (preg_match("/.*\.(png|gif)$/", $answer->getImage(), $matches)) {
143 $imagetype = "image/" . $matches[1];
144 }
145 if ($force_image_references) {
146 $attrs = array(
147 "imagtype" => $imagetype,
148 "label" => $answer->getImage(),
149 "uri" => $this->object->getImagePathWeb() . $answer->getImage()
150 );
151 $a_xml_writer->xmlElement("matimage", $attrs);
152 } else {
153 $imagepath = $this->object->getImagePath() . $answer->getImage();
154 $fh = @fopen($imagepath, "rb");
155 if ($fh != false) {
156 $imagefile = fread($fh, filesize($imagepath));
157 fclose($fh);
158 $base64 = base64_encode($imagefile);
159 $attrs = array(
160 "imagtype" => $imagetype,
161 "label" => $answer->getImage(),
162 "embedded" => "base64"
163 );
164 $a_xml_writer->xmlElement("matimage", $attrs, $base64, false, false);
165 }
166 }
167 $a_xml_writer->xmlEndTag("material");
168 } else {
169 $this->object->addQTIMaterial($a_xml_writer, $answer->getAnswertext());
170 }
171 $a_xml_writer->xmlEndTag("response_label");
172 }
173 $a_xml_writer->xmlEndTag("render_choice");
174 $a_xml_writer->xmlEndTag("response_lid");
175 $a_xml_writer->xmlEndTag("flow");
176 $a_xml_writer->xmlEndTag("presentation");
177
178 // PART II: qti resprocessing
179 $a_xml_writer->xmlStartTag("resprocessing");
180 $a_xml_writer->xmlStartTag("outcomes");
181 $a_xml_writer->xmlStartTag("decvar");
182 $a_xml_writer->xmlEndTag("decvar");
183 $a_xml_writer->xmlEndTag("outcomes");
184 // add response conditions
185 foreach ($answers as $index => $answer) {
186 $attrs = array(
187 "continue" => "Yes"
188 );
189 $a_xml_writer->xmlStartTag("respcondition", $attrs);
190 // qti conditionvar
191 $a_xml_writer->xmlStartTag("conditionvar");
192 $attrs = array();
193 $attrs = array(
194 "respident" => "MCSR"
195 );
196 $a_xml_writer->xmlElement("varequal", $attrs, $index);
197 $a_xml_writer->xmlEndTag("conditionvar");
198 // qti setvar
199 $attrs = array(
200 "action" => "Add"
201 );
202 $a_xml_writer->xmlElement("setvar", $attrs, $answer->getPoints());
203 // qti displayfeedback
204 $linkrefid = "response_$index";
205 $attrs = array(
206 "feedbacktype" => "Response",
207 "linkrefid" => $linkrefid
208 );
209 $a_xml_writer->xmlElement("displayfeedback", $attrs);
210 $a_xml_writer->xmlEndTag("respcondition");
211 }
212
213 $feedback_allcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
214 $this->object->getId(),
215 true
216 );
217 if (strlen($feedback_allcorrect)) {
218 $attrs = array(
219 "continue" => "Yes"
220 );
221 $a_xml_writer->xmlStartTag("respcondition", $attrs);
222 // qti conditionvar
223 $a_xml_writer->xmlStartTag("conditionvar");
224 $bestindex = 0;
225 $maxpoints = 0;
226 foreach ($answers as $index => $answer) {
227 if ($answer->getPoints() > $maxpoints) {
228 $maxpoints = $answer->getPoints();
229 $bestindex = $index;
230 }
231 }
232 $attrs = array(
233 "respident" => "MCSR"
234 );
235 $a_xml_writer->xmlElement("varequal", $attrs, $bestindex);
236 $a_xml_writer->xmlEndTag("conditionvar");
237 // qti displayfeedback
238 $attrs = array(
239 "feedbacktype" => "Response",
240 "linkrefid" => "response_allcorrect"
241 );
242 $a_xml_writer->xmlElement("displayfeedback", $attrs);
243 $a_xml_writer->xmlEndTag("respcondition");
244 }
245
246 $feedback_onenotcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
247 $this->object->getId(),
248 false
249 );
250 if (strlen($feedback_onenotcorrect)) {
251 $attrs = array(
252 "continue" => "Yes"
253 );
254 $a_xml_writer->xmlStartTag("respcondition", $attrs);
255 // qti conditionvar
256 $a_xml_writer->xmlStartTag("conditionvar");
257 $bestindex = 0;
258 $maxpoints = 0;
259 foreach ($answers as $index => $answer) {
260 if ($answer->getPoints() > $maxpoints) {
261 $maxpoints = $answer->getPoints();
262 $bestindex = $index;
263 }
264 }
265 $attrs = array(
266 "respident" => "MCSR"
267 );
268 $a_xml_writer->xmlStartTag("not");
269 $a_xml_writer->xmlElement("varequal", $attrs, $bestindex);
270 $a_xml_writer->xmlEndTag("not");
271 $a_xml_writer->xmlEndTag("conditionvar");
272 // qti displayfeedback
273 $attrs = array(
274 "feedbacktype" => "Response",
275 "linkrefid" => "response_onenotcorrect"
276 );
277 $a_xml_writer->xmlElement("displayfeedback", $attrs);
278 $a_xml_writer->xmlEndTag("respcondition");
279 }
280
281 $a_xml_writer->xmlEndTag("resprocessing");
282
283 // PART III: qti itemfeedback
284 foreach ($answers as $index => $answer) {
285 $linkrefid = "response_$index";
286 $attrs = array(
287 "ident" => $linkrefid,
288 "view" => "All"
289 );
290 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
291 // qti flow_mat
292 $a_xml_writer->xmlStartTag("flow_mat");
293 $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation(
294 $this->object->getId(),
295 0,
296 $index
297 );
298 $this->object->addQTIMaterial($a_xml_writer, $fb);
299 $a_xml_writer->xmlEndTag("flow_mat");
300 $a_xml_writer->xmlEndTag("itemfeedback");
301 }
302 if (strlen($feedback_allcorrect)) {
303 $attrs = array(
304 "ident" => "response_allcorrect",
305 "view" => "All"
306 );
307 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
308 // qti flow_mat
309 $a_xml_writer->xmlStartTag("flow_mat");
310 $this->object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
311 $a_xml_writer->xmlEndTag("flow_mat");
312 $a_xml_writer->xmlEndTag("itemfeedback");
313 }
314 if (strlen($feedback_onenotcorrect)) {
315 $attrs = array(
316 "ident" => "response_onenotcorrect",
317 "view" => "All"
318 );
319 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
320 // qti flow_mat
321 $a_xml_writer->xmlStartTag("flow_mat");
322 $this->object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
323 $a_xml_writer->xmlEndTag("flow_mat");
324 $a_xml_writer->xmlEndTag("itemfeedback");
325 }
326
327 $a_xml_writer->xmlEndTag("item");
328 $a_xml_writer->xmlEndTag("questestinterop");
329
330 $xml = $a_xml_writer->xmlDumpMem(false);
331 if (!$a_include_header) {
332 $pos = strpos($xml, "?>");
333 $xml = substr($xml, $pos + 2);
334 }
335 return $xml;
336 }
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 ...
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 SINGLE_CHOICE_QUESTION_IDENTIFIER
$index
Definition: metadata.php:128
$xml
Definition: metadata.php:332
$DIC
Definition: xapitoken.php:46

References $DIC, $index, $xml, assQuestionExport\addAdditionalContentEditingModeInformation(), assQuestionExport\addGeneralMetadata(), assQuestionExport\addQtiMetaDataField(), SINGLE_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: