ILIAS  release_8 Revision v8.24
class.assTextQuestionExport.php
Go to the documentation of this file.
1<?php
28{
32 public $object;
33
39 public function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false): string
40 {
41 global $DIC;
42 $ilias = $DIC['ilias'];
43
44 include_once("./Services/Xml/classes/class.ilXmlWriter.php");
45 $a_xml_writer = new ilXmlWriter();
46 // set xml header
47 $a_xml_writer->xmlHeader();
48 $a_xml_writer->xmlStartTag("questestinterop");
49 $attrs = array(
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, TEXT_QUESTION_IDENTIFIER);
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 = array(
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->object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
123 // add information on response rendering
124 $attrs = array(
125 "ident" => "TEXT",
126 "rcardinality" => "Ordered"
127 );
128 $a_xml_writer->xmlStartTag("response_str", $attrs);
129 $attrs = array(
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 = array(
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
144 $solution = $this->object->getSuggestedSolution(0);
145 if ($solution !== null && count($solution)) {
146 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches)) {
147 $a_xml_writer->xmlStartTag("material");
148 $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
149 if (strcmp($matches[1], "") != 0) {
150 $intlink = $solution["internal_link"];
151 }
152 $attrs = array(
153 "label" => "suggested_solution"
154 );
155 $a_xml_writer->xmlElement("mattext", $attrs, $intlink);
156 $a_xml_writer->xmlEndTag("material");
157 }
158 }
159 $a_xml_writer->xmlEndTag("response_str");
160 $a_xml_writer->xmlEndTag("flow");
161 $a_xml_writer->xmlEndTag("presentation");
162
163 // PART II: qti resprocessing
164 $attrs = array(
165 "scoremodel" => "HumanRater"
166 );
167 $a_xml_writer->xmlStartTag("resprocessing", $attrs);
168 $a_xml_writer->xmlStartTag("outcomes");
169 $attrs = array(
170 "varname" => "WritingScore",
171 "vartype" => "Integer",
172 "minvalue" => "0",
173 "maxvalue" => $this->object->getPoints()
174 );
175 $a_xml_writer->xmlStartTag("decvar", $attrs);
176 $a_xml_writer->xmlEndTag("decvar");
177 $a_xml_writer->xmlEndTag("outcomes");
178
179 $feedback_allcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
180 $this->object->getId(),
181 true
182 );
183 $feedback_onenotcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
184 $this->object->getId(),
185 false
186 );
187 if (strlen($feedback_allcorrect . $feedback_onenotcorrect)) {
188 if (strlen($feedback_allcorrect)) {
189 $attrs = array(
190 "continue" => "Yes"
191 );
192 $a_xml_writer->xmlStartTag("respcondition", $attrs);
193 // qti conditionvar
194 $a_xml_writer->xmlStartTag("conditionvar");
195 $attrs = array(
196 "respident" => "points"
197 );
198 $a_xml_writer->xmlElement("varequal", $attrs, $this->object->getPoints());
199 $a_xml_writer->xmlEndTag("conditionvar");
200 // qti displayfeedback
201 $attrs = array(
202 "feedbacktype" => "Response",
203 "linkrefid" => "response_allcorrect"
204 );
205 $a_xml_writer->xmlElement("displayfeedback", $attrs);
206 $a_xml_writer->xmlEndTag("respcondition");
207 }
208
209 if (strlen($feedback_onenotcorrect)) {
210 $attrs = array(
211 "continue" => "Yes"
212 );
213 $a_xml_writer->xmlStartTag("respcondition", $attrs);
214 // qti conditionvar
215 $a_xml_writer->xmlStartTag("conditionvar");
216 $a_xml_writer->xmlStartTag("not");
217 $attrs = array(
218 "respident" => "points"
219 );
220 $a_xml_writer->xmlElement("varequal", $attrs, $this->object->getPoints());
221 $a_xml_writer->xmlEndTag("not");
222 $a_xml_writer->xmlEndTag("conditionvar");
223 // qti displayfeedback
224 $attrs = array(
225 "feedbacktype" => "Response",
226 "linkrefid" => "response_onenotcorrect"
227 );
228 $a_xml_writer->xmlElement("displayfeedback", $attrs);
229 $a_xml_writer->xmlEndTag("respcondition");
230 }
231 }
232
233 $a_xml_writer->xmlStartTag("respcondition");
234 $a_xml_writer->xmlStartTag("conditionvar");
235 $a_xml_writer->xmlElement("other", null, "tutor_rated");
236 $a_xml_writer->xmlEndTag("conditionvar");
237 $a_xml_writer->xmlEndTag("respcondition");
238 $a_xml_writer->xmlEndTag("resprocessing");
239
240 $this->addAnswerSpecificFeedback($a_xml_writer, $this->object->feedbackOBJ->getAnswerOptionsByAnswerIndex());
241
242 if (strlen($feedback_allcorrect)) {
243 $attrs = array(
244 "ident" => "response_allcorrect",
245 "view" => "All"
246 );
247 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
248 // qti flow_mat
249 $a_xml_writer->xmlStartTag("flow_mat");
250 $this->object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
251 $a_xml_writer->xmlEndTag("flow_mat");
252 $a_xml_writer->xmlEndTag("itemfeedback");
253 }
254 if (strlen($feedback_onenotcorrect)) {
255 $attrs = array(
256 "ident" => "response_onenotcorrect",
257 "view" => "All"
258 );
259 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
260 // qti flow_mat
261 $a_xml_writer->xmlStartTag("flow_mat");
262 $this->object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
263 $a_xml_writer->xmlEndTag("flow_mat");
264 $a_xml_writer->xmlEndTag("itemfeedback");
265 }
266
267 $a_xml_writer = $this->addSolutionHints($a_xml_writer);
268
269 $a_xml_writer->xmlEndTag("item");
270 $a_xml_writer->xmlEndTag("questestinterop");
271
272 $xml = $a_xml_writer->xmlDumpMem(false);
273 if (!$a_include_header) {
274 $pos = strpos($xml, "?>");
275 $xml = substr($xml, $pos + 2);
276 }
277 return $xml;
278 }
279}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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 ...
addAnswerSpecificFeedback(ilXmlWriter $a_xml_writer, $answers)
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...
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: feed.php:28
const TEXT_QUESTION_IDENTIFIER
$xml
Definition: metadata.php:351