ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.assTextQuestionExport.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once "./Modules/TestQuestionPool/classes/export/qti12/class.assQuestionExport.php";
5
16{
26 public function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false)
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, TEXT_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, "textrating");
70 $a_xml_writer->xmlElement("fieldentry", null, $this->object->getTextRating());
71 $a_xml_writer->xmlEndTag("qtimetadatafield");
72
73 /*
74 $a_xml_writer->xmlStartTag("qtimetadatafield");
75 $a_xml_writer->xmlElement("fieldlabel", NULL, "keywords");
76 $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getKeywords());
77 $a_xml_writer->xmlEndTag("qtimetadatafield");
78 */
79
80 $a_xml_writer->xmlStartTag("qtimetadatafield");
81 $a_xml_writer->xmlElement("fieldlabel", null, "matchcondition");
82 $a_xml_writer->xmlElement("fieldentry", null, $this->object->matchcondition);
83 $a_xml_writer->xmlEndTag("qtimetadatafield");
84
85 $a_xml_writer->xmlStartTag("qtimetadatafield");
86 $a_xml_writer->xmlElement("fieldlabel", null, "termscoring");
87 $scores = base64_encode(serialize($this->object->getAnswers()));
88 $a_xml_writer->xmlElement("fieldentry", null, $scores);
89 $a_xml_writer->xmlEndTag("qtimetadatafield");
90
91 $a_xml_writer->xmlStartTag("qtimetadatafield");
92 $a_xml_writer->xmlElement("fieldlabel", null, "termrelation");
93 $a_xml_writer->xmlElement("fieldentry", null, $this->object->getKeywordRelation());
94 $a_xml_writer->xmlEndTag("qtimetadatafield");
95
96 $a_xml_writer->xmlStartTag("qtimetadatafield");
97 $a_xml_writer->xmlElement("fieldlabel", null, "specificfeedback");
98 $a_xml_writer->xmlElement("fieldentry", null, $this->object->getKeywordRelation());
99 $a_xml_writer->xmlEndTag("qtimetadatafield");
100
101 $a_xml_writer->xmlEndTag("qtimetadata");
102 $a_xml_writer->xmlEndTag("itemmetadata");
103
104 // PART I: qti presentation
105 $attrs = array(
106 "label" => $this->object->getTitle()
107 );
108 $a_xml_writer->xmlStartTag("presentation", $attrs);
109 // add flow to presentation
110 $a_xml_writer->xmlStartTag("flow");
111 // add material with question text to presentation
112 $this->object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
113 // add information on response rendering
114 $attrs = array(
115 "ident" => "TEXT",
116 "rcardinality" => "Ordered"
117 );
118 $a_xml_writer->xmlStartTag("response_str", $attrs);
119 $attrs = array(
120 "fibtype" => "String",
121 "prompt" => "Box"
122 );
123 if ($this->object->getMaxNumOfChars() > 0) {
124 $attrs["maxchars"] = $this->object->getMaxNumOfChars();
125 }
126 $a_xml_writer->xmlStartTag("render_fib", $attrs);
127 $attrs = array(
128 "ident" => "A"
129 );
130 $a_xml_writer->xmlStartTag("response_label", $attrs);
131 $a_xml_writer->xmlEndTag("response_label");
132 $a_xml_writer->xmlEndTag("render_fib");
133
134 $solution = $this->object->getSuggestedSolution(0);
135 if (count($solution)) {
136 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches)) {
137 $a_xml_writer->xmlStartTag("material");
138 $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
139 if (strcmp($matches[1], "") != 0) {
140 $intlink = $solution["internal_link"];
141 }
142 $attrs = array(
143 "label" => "suggested_solution"
144 );
145 $a_xml_writer->xmlElement("mattext", $attrs, $intlink);
146 $a_xml_writer->xmlEndTag("material");
147 }
148 }
149 $a_xml_writer->xmlEndTag("response_str");
150 $a_xml_writer->xmlEndTag("flow");
151 $a_xml_writer->xmlEndTag("presentation");
152
153 // PART II: qti resprocessing
154 $attrs = array(
155 "scoremodel" => "HumanRater"
156 );
157 $a_xml_writer->xmlStartTag("resprocessing", $attrs);
158 $a_xml_writer->xmlStartTag("outcomes");
159 $attrs = array(
160 "varname" => "WritingScore",
161 "vartype" => "Integer",
162 "minvalue" => "0",
163 "maxvalue" => $this->object->getPoints()
164 );
165 $a_xml_writer->xmlStartTag("decvar", $attrs);
166 $a_xml_writer->xmlEndTag("decvar");
167 $a_xml_writer->xmlEndTag("outcomes");
168
169 $feedback_allcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
170 $this->object->getId(),
171 true
172 );
173 $feedback_onenotcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
174 $this->object->getId(),
175 false
176 );
177 if (strlen($feedback_allcorrect . $feedback_onenotcorrect)) {
178 if (strlen($feedback_allcorrect)) {
179 $attrs = array(
180 "continue" => "Yes"
181 );
182 $a_xml_writer->xmlStartTag("respcondition", $attrs);
183 // qti conditionvar
184 $a_xml_writer->xmlStartTag("conditionvar");
185 $attrs = array(
186 "respident" => "points"
187 );
188 $a_xml_writer->xmlElement("varequal", $attrs, $this->object->getPoints());
189 $a_xml_writer->xmlEndTag("conditionvar");
190 // qti displayfeedback
191 $attrs = array(
192 "feedbacktype" => "Response",
193 "linkrefid" => "response_allcorrect"
194 );
195 $a_xml_writer->xmlElement("displayfeedback", $attrs);
196 $a_xml_writer->xmlEndTag("respcondition");
197 }
198
199 if (strlen($feedback_onenotcorrect)) {
200 $attrs = array(
201 "continue" => "Yes"
202 );
203 $a_xml_writer->xmlStartTag("respcondition", $attrs);
204 // qti conditionvar
205 $a_xml_writer->xmlStartTag("conditionvar");
206 $a_xml_writer->xmlStartTag("not");
207 $attrs = array(
208 "respident" => "points"
209 );
210 $a_xml_writer->xmlElement("varequal", $attrs, $this->object->getPoints());
211 $a_xml_writer->xmlEndTag("not");
212 $a_xml_writer->xmlEndTag("conditionvar");
213 // qti displayfeedback
214 $attrs = array(
215 "feedbacktype" => "Response",
216 "linkrefid" => "response_onenotcorrect"
217 );
218 $a_xml_writer->xmlElement("displayfeedback", $attrs);
219 $a_xml_writer->xmlEndTag("respcondition");
220 }
221 }
222
223 $a_xml_writer->xmlStartTag("respcondition");
224 $a_xml_writer->xmlStartTag("conditionvar");
225 $a_xml_writer->xmlElement("other", null, "tutor_rated");
226 $a_xml_writer->xmlEndTag("conditionvar");
227 $a_xml_writer->xmlEndTag("respcondition");
228 $a_xml_writer->xmlEndTag("resprocessing");
229
230 $this->addAnswerSpecificFeedback($a_xml_writer, $this->object->feedbackOBJ->getAnswerOptionsByAnswerIndex());
231
232 if (strlen($feedback_allcorrect)) {
233 $attrs = array(
234 "ident" => "response_allcorrect",
235 "view" => "All"
236 );
237 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
238 // qti flow_mat
239 $a_xml_writer->xmlStartTag("flow_mat");
240 $this->object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
241 $a_xml_writer->xmlEndTag("flow_mat");
242 $a_xml_writer->xmlEndTag("itemfeedback");
243 }
244 if (strlen($feedback_onenotcorrect)) {
245 $attrs = array(
246 "ident" => "response_onenotcorrect",
247 "view" => "All"
248 );
249 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
250 // qti flow_mat
251 $a_xml_writer->xmlStartTag("flow_mat");
252 $this->object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
253 $a_xml_writer->xmlEndTag("flow_mat");
254 $a_xml_writer->xmlEndTag("itemfeedback");
255 }
256
257 $a_xml_writer->xmlEndTag("item");
258 $a_xml_writer->xmlEndTag("questestinterop");
259
260 $xml = $a_xml_writer->xmlDumpMem(false);
261 if (!$a_include_header) {
262 $pos = strpos($xml, "?>");
263 $xml = substr($xml, $pos + 2);
264 }
265 return $xml;
266 }
267}
An exception for terminatinating execution or to throw for unit testing.
Class for question exports.
addGeneralMetadata(ilXmlWriter $xmlwriter)
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...
Class for essay question exports.
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.
XML writer class.
xmlHeader()
Writes xml header @access public.
const TEXT_QUESTION_IDENTIFIER
global $DIC
Definition: saml.php:7