ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.assTextQuestionExport.php
Go to the documentation of this file.
1<?php
2
29{
33 public $object;
34
40 public function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false): string
41 {
42 global $DIC;
43 $ilias = $DIC['ilias'];
44
45 $a_xml_writer = new ilXmlWriter();
46 // set xml header
47 $a_xml_writer->xmlHeader();
48 $a_xml_writer->xmlStartTag("questestinterop");
49 $attrs = [
50 "ident" => "il_" . IL_INST_ID . "_qst_" . $this->object->getId(),
51 "title" => $this->object->getTitle(),
52 "maxattempts" => $this->object->getNrOfTries()
53 ];
54 $a_xml_writer->xmlStartTag("item", $attrs);
55 // add question description
56 $a_xml_writer->xmlElement("qticomment", null, $this->object->getComment());
57 $a_xml_writer->xmlStartTag("itemmetadata");
58 $a_xml_writer->xmlStartTag("qtimetadata");
59 $a_xml_writer->xmlStartTag("qtimetadatafield");
60 $a_xml_writer->xmlElement("fieldlabel", null, "ILIAS_VERSION");
61 $a_xml_writer->xmlElement("fieldentry", null, $ilias->getSetting("ilias_version"));
62 $a_xml_writer->xmlEndTag("qtimetadatafield");
63 $a_xml_writer->xmlStartTag("qtimetadatafield");
64 $a_xml_writer->xmlElement("fieldlabel", null, "QUESTIONTYPE");
65 $a_xml_writer->xmlElement("fieldentry", null, $this->object->getQuestionType());
66 $a_xml_writer->xmlEndTag("qtimetadatafield");
67 $a_xml_writer->xmlStartTag("qtimetadatafield");
68 $a_xml_writer->xmlElement("fieldlabel", null, "AUTHOR");
69 $a_xml_writer->xmlElement("fieldentry", null, $this->object->getAuthor());
70 $a_xml_writer->xmlEndTag("qtimetadatafield");
71
72 // additional content editing information
74 $this->addGeneralMetadata($a_xml_writer);
75
76 $this->addQtiMetaDataField($a_xml_writer, 'wordcounter', (int) $this->object->isWordCounterEnabled());
77
78 $a_xml_writer->xmlStartTag("qtimetadatafield");
79 $a_xml_writer->xmlElement("fieldlabel", null, "textrating");
80 $a_xml_writer->xmlElement("fieldentry", null, $this->object->getTextRating());
81 $a_xml_writer->xmlEndTag("qtimetadatafield");
82
83 /*
84 $a_xml_writer->xmlStartTag("qtimetadatafield");
85 $a_xml_writer->xmlElement("fieldlabel", NULL, "keywords");
86 $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getKeywords());
87 $a_xml_writer->xmlEndTag("qtimetadatafield");
88 */
89
90 $a_xml_writer->xmlStartTag("qtimetadatafield");
91 $a_xml_writer->xmlElement("fieldlabel", null, "matchcondition");
92 $a_xml_writer->xmlElement("fieldentry", null, $this->object->getMatchcondition());
93 $a_xml_writer->xmlEndTag("qtimetadatafield");
94
95 $a_xml_writer->xmlStartTag("qtimetadatafield");
96 $a_xml_writer->xmlElement("fieldlabel", null, "termscoring");
97 $scores = base64_encode(serialize($this->object->getAnswers()));
98 $a_xml_writer->xmlElement("fieldentry", null, $scores);
99 $a_xml_writer->xmlEndTag("qtimetadatafield");
100
101 $a_xml_writer->xmlStartTag("qtimetadatafield");
102 $a_xml_writer->xmlElement("fieldlabel", null, "termrelation");
103 $a_xml_writer->xmlElement("fieldentry", null, $this->object->getKeywordRelation());
104 $a_xml_writer->xmlEndTag("qtimetadatafield");
105
106 $a_xml_writer->xmlStartTag("qtimetadatafield");
107 $a_xml_writer->xmlElement("fieldlabel", null, "specificfeedback");
108 $a_xml_writer->xmlElement("fieldentry", null, $this->object->getKeywordRelation());
109 $a_xml_writer->xmlEndTag("qtimetadatafield");
110
111 $a_xml_writer->xmlEndTag("qtimetadata");
112 $a_xml_writer->xmlEndTag("itemmetadata");
113
114 // PART I: qti presentation
115 $attrs = [
116 "label" => $this->object->getTitle()
117 ];
118 $a_xml_writer->xmlStartTag("presentation", $attrs);
119 // add flow to presentation
120 $a_xml_writer->xmlStartTag("flow");
121 // add material with question text to presentation
122 $this->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
123 // add information on response rendering
124 $attrs = [
125 "ident" => "TEXT",
126 "rcardinality" => "Ordered"
127 ];
128 $a_xml_writer->xmlStartTag("response_str", $attrs);
129 $attrs = [
130 "fibtype" => "String",
131 "prompt" => "Box"
132 ];
133 if ($this->object->getMaxNumOfChars() > 0) {
134 $attrs["maxchars"] = $this->object->getMaxNumOfChars();
135 }
136 $a_xml_writer->xmlStartTag("render_fib", $attrs);
137 $attrs = [
138 "ident" => "A"
139 ];
140 $a_xml_writer->xmlStartTag("response_label", $attrs);
141 $a_xml_writer->xmlEndTag("response_label");
142 $a_xml_writer->xmlEndTag("render_fib");
143 $a_xml_writer = $this->addSuggestedSolution($a_xml_writer);
144 $a_xml_writer->xmlEndTag("response_str");
145 $a_xml_writer->xmlEndTag("flow");
146 $a_xml_writer->xmlEndTag("presentation");
147
148 // PART II: qti resprocessing
149 $attrs = [
150 "scoremodel" => "HumanRater"
151 ];
152 $a_xml_writer->xmlStartTag("resprocessing", $attrs);
153 $a_xml_writer->xmlStartTag("outcomes");
154 $attrs = [
155 "varname" => "WritingScore",
156 "vartype" => "Integer",
157 "minvalue" => "0",
158 "maxvalue" => $this->object->getPoints()
159 ];
160 $a_xml_writer->xmlStartTag("decvar", $attrs);
161 $a_xml_writer->xmlEndTag("decvar");
162 $a_xml_writer->xmlEndTag("outcomes");
163
164 $feedback_allcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
165 $this->object->getId(),
166 true
167 );
168 $feedback_onenotcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
169 $this->object->getId(),
170 false
171 );
172 if (strlen($feedback_allcorrect . $feedback_onenotcorrect)) {
173 if (strlen($feedback_allcorrect)) {
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" => "points"
182 ];
183 $a_xml_writer->xmlElement("varequal", $attrs, $this->object->getPoints());
184 $a_xml_writer->xmlEndTag("conditionvar");
185 // qti displayfeedback
186 $attrs = [
187 "feedbacktype" => "Response",
188 "linkrefid" => "response_allcorrect"
189 ];
190 $a_xml_writer->xmlElement("displayfeedback", $attrs);
191 $a_xml_writer->xmlEndTag("respcondition");
192 }
193
194 if (strlen($feedback_onenotcorrect)) {
195 $attrs = [
196 "continue" => "Yes"
197 ];
198 $a_xml_writer->xmlStartTag("respcondition", $attrs);
199 // qti conditionvar
200 $a_xml_writer->xmlStartTag("conditionvar");
201 $a_xml_writer->xmlStartTag("not");
202 $attrs = [
203 "respident" => "points"
204 ];
205 $a_xml_writer->xmlElement("varequal", $attrs, $this->object->getPoints());
206 $a_xml_writer->xmlEndTag("not");
207 $a_xml_writer->xmlEndTag("conditionvar");
208 // qti displayfeedback
209 $attrs = [
210 "feedbacktype" => "Response",
211 "linkrefid" => "response_onenotcorrect"
212 ];
213 $a_xml_writer->xmlElement("displayfeedback", $attrs);
214 $a_xml_writer->xmlEndTag("respcondition");
215 }
216 }
217
218 $a_xml_writer->xmlStartTag("respcondition");
219 $a_xml_writer->xmlStartTag("conditionvar");
220 $a_xml_writer->xmlElement("other", null, "tutor_rated");
221 $a_xml_writer->xmlEndTag("conditionvar");
222 $a_xml_writer->xmlEndTag("respcondition");
223 $a_xml_writer->xmlEndTag("resprocessing");
224
225 $this->addAnswerSpecificFeedback($a_xml_writer, $this->object->feedbackOBJ->getAnswerOptionsByAnswerIndex());
226
227 if (strlen($feedback_allcorrect)) {
228 $attrs = [
229 "ident" => "response_allcorrect",
230 "view" => "All"
231 ];
232 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
233 // qti flow_mat
234 $a_xml_writer->xmlStartTag("flow_mat");
235 $this->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
236 $a_xml_writer->xmlEndTag("flow_mat");
237 $a_xml_writer->xmlEndTag("itemfeedback");
238 }
239 if (strlen($feedback_onenotcorrect)) {
240 $attrs = [
241 "ident" => "response_onenotcorrect",
242 "view" => "All"
243 ];
244 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
245 // qti flow_mat
246 $a_xml_writer->xmlStartTag("flow_mat");
247 $this->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
248 $a_xml_writer->xmlEndTag("flow_mat");
249 $a_xml_writer->xmlEndTag("itemfeedback");
250 }
251
252 $a_xml_writer->xmlEndTag("item");
253 $a_xml_writer->xmlEndTag("questestinterop");
254
255 $xml = $a_xml_writer->xmlDumpMem(false);
256 if (!$a_include_header) {
257 $pos = strpos($xml, "?>");
258 $xml = substr($xml, $pos + 2);
259 }
260 return $xml;
261 }
262}
Class for question exports.
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 ...
addAnswerSpecificFeedback(ilXmlWriter $a_xml_writer, $answers)
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...
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...
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