ILIAS  release_8 Revision v8.24
assKprimChoiceExport Class Reference
+ Inheritance diagram for assKprimChoiceExport:
+ Collaboration diagram for assKprimChoiceExport:

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

Data Fields

 $object
 
- Data Fields inherited from assQuestionExport
 $object
 
const ITEM_SOLUTIONHINT = 'solutionhint'
 

Private Member Functions

 getMinPoints ()
 
 getMaxPoints ()
 

Additional Inherited Members

- 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

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

Member Function Documentation

◆ getMaxPoints()

assKprimChoiceExport::getMaxPoints ( )
private

Definition at line 321 of file class.assKprimChoiceExport.php.

321 : float
322 {
323 return $this->object->getPoints();
324 }

Referenced by toXML().

+ Here is the caller graph for this function:

◆ getMinPoints()

assKprimChoiceExport::getMinPoints ( )
private

Definition at line 312 of file class.assKprimChoiceExport.php.

313 {
314 if ($this->object->isScorePartialSolutionEnabled()) {
315 return ($this->object->getPoints() / 2);
316 }
317
318 return 0;
319 }

References ILIAS\Repository\object().

Referenced by toXML().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toXML()

assKprimChoiceExport::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 33 of file class.assKprimChoiceExport.php.

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

References $DIC, $index, $xml, assQuestionExport\addAdditionalContentEditingModeInformation(), assQuestionExport\addGeneralMetadata(), assQuestionExport\addSolutionHints(), getMaxPoints(), getMinPoints(), IL_INST_ID, KPRIM_CHOICE_QUESTION_IDENTIFIER, and ILIAS\Repository\object().

+ Here is the call graph for this function:

Field Documentation

◆ $object

assKprimChoiceExport::$object

Definition at line 31 of file class.assKprimChoiceExport.php.


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