ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.assTextSubsetExport.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_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, TEXTSUBSET_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
65  $this->addAdditionalContentEditingModeInformation($a_xml_writer);
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  $a_xml_writer->xmlStartTag("qtimetadatafield");
73  $a_xml_writer->xmlElement("fieldlabel", null, "correctanswers");
74  $a_xml_writer->xmlElement("fieldentry", null, $this->object->getCorrectAnswers());
75  $a_xml_writer->xmlEndTag("qtimetadatafield");
76  $a_xml_writer->xmlStartTag("qtimetadatafield");
77  $a_xml_writer->xmlElement("fieldlabel", null, "points");
78  $a_xml_writer->xmlElement("fieldentry", null, $this->object->getPoints());
79  $a_xml_writer->xmlEndTag("qtimetadatafield");
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  for ($counter = 1; $counter <= $this->object->getCorrectAnswers(); $counter++) {
94  $attrs = array(
95  "ident" => "TEXTSUBSET_" . sprintf("%02d", $counter),
96  "rcardinality" => "Single"
97  );
98  $a_xml_writer->xmlStartTag("response_str", $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  "fibtype" => "String",
117  "columns" => $this->object->getMaxTextboxWidth()
118  );
119  $a_xml_writer->xmlStartTag("render_fib", $attrs);
120  $a_xml_writer->xmlEndTag("render_fib");
121  $a_xml_writer->xmlEndTag("response_str");
122  }
123 
124  $a_xml_writer->xmlEndTag("flow");
125  $a_xml_writer->xmlEndTag("presentation");
126 
127  // PART II: qti resprocessing
128  $a_xml_writer->xmlStartTag("resprocessing");
129  $a_xml_writer->xmlStartTag("outcomes");
130  $a_xml_writer->xmlStartTag("decvar");
131  $a_xml_writer->xmlEndTag("decvar");
132  $attribs = array(
133  "varname" => "matches",
134  "defaultval" => "0"
135  );
136  $a_xml_writer->xmlElement("decvar", $attribs, null);
137  $a_xml_writer->xmlEndTag("outcomes");
138  // add response conditions
139  for ($counter = 1; $counter <= $this->object->getCorrectAnswers(); $counter++) {
140  $scoregroups = &$this->object->joinAnswers();
141  foreach ($scoregroups as $points => $scoreanswers) {
142  $attrs = array(
143  "continue" => "Yes"
144  );
145  $a_xml_writer->xmlStartTag("respcondition", $attrs);
146  // qti conditionvar
147  $a_xml_writer->xmlStartTag("conditionvar");
148  $attrs = array(
149  "respident" => "TEXTSUBSET_" . sprintf("%02d", $counter)
150  );
151  $a_xml_writer->xmlElement("varsubset", $attrs, join(",", $scoreanswers));
152  $a_xml_writer->xmlEndTag("conditionvar");
153  // qti setvar
154  $attrs = array(
155  "varname" => "matches",
156  "action" => "Add"
157  );
158  $a_xml_writer->xmlElement("setvar", $attrs, $points);
159  // qti displayfeedback
160  $attrs = array(
161  "feedbacktype" => "Response",
162  "linkrefid" => "Matches_" . sprintf("%02d", $counter)
163  );
164  $a_xml_writer->xmlElement("displayfeedback", $attrs);
165  $a_xml_writer->xmlEndTag("respcondition");
166  }
167  }
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("varsubset", $attrs, $this->object->getMaximumPoints());
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 
208  $attrs = array(
209  "respident" => "points"
210  );
211  $a_xml_writer->xmlElement("varsubset", $attrs, $this->object->getMaximumPoints());
212 
213  $a_xml_writer->xmlEndTag("not");
214  $a_xml_writer->xmlEndTag("conditionvar");
215  // qti displayfeedback
216  $attrs = array(
217  "feedbacktype" => "Response",
218  "linkrefid" => "response_onenotcorrect"
219  );
220  $a_xml_writer->xmlElement("displayfeedback", $attrs);
221  $a_xml_writer->xmlEndTag("respcondition");
222  }
223  }
224 
225  $a_xml_writer->xmlEndTag("resprocessing");
226 
227  // PART III: qti itemfeedback
228  for ($counter = 1; $counter <= $this->object->getCorrectAnswers(); $counter++) {
229  $attrs = array(
230  "ident" => "Matches_" . sprintf("%02d", $counter),
231  "view" => "All"
232  );
233  $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
234  // qti flow_mat
235  $a_xml_writer->xmlStartTag("flow_mat");
236  $a_xml_writer->xmlStartTag("material");
237  $a_xml_writer->xmlElement("mattext");
238  $a_xml_writer->xmlEndTag("material");
239  $a_xml_writer->xmlEndTag("flow_mat");
240  $a_xml_writer->xmlEndTag("itemfeedback");
241  }
242 
243  if (strlen($feedback_allcorrect)) {
244  $attrs = array(
245  "ident" => "response_allcorrect",
246  "view" => "All"
247  );
248  $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
249  // qti flow_mat
250  $a_xml_writer->xmlStartTag("flow_mat");
251  $this->object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
252  $a_xml_writer->xmlEndTag("flow_mat");
253  $a_xml_writer->xmlEndTag("itemfeedback");
254  }
255  if (strlen($feedback_onenotcorrect)) {
256  $attrs = array(
257  "ident" => "response_onenotcorrect",
258  "view" => "All"
259  );
260  $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
261  // qti flow_mat
262  $a_xml_writer->xmlStartTag("flow_mat");
263  $this->object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
264  $a_xml_writer->xmlEndTag("flow_mat");
265  $a_xml_writer->xmlEndTag("itemfeedback");
266  }
267 
268  $a_xml_writer->xmlEndTag("item");
269  $a_xml_writer->xmlEndTag("questestinterop");
270 
271  $xml = $a_xml_writer->xmlDumpMem(false);
272  if (!$a_include_header) {
273  $pos = strpos($xml, "?>");
274  $xml = substr($xml, $pos + 2);
275  }
276  return $xml;
277  }
278 }
global $DIC
Definition: saml.php:7
const TEXTSUBSET_QUESTION_IDENTIFIER
XML writer class.
Class for question exports.
Class for text subset question exports.
addGeneralMetadata(ilXmlWriter $xmlwriter)
xmlHeader()
Writes xml header public.
addAdditionalContentEditingModeInformation(ilXmlWriter $a_xml_writer)
adds a qti meta data field for ilias specific information of "additional content editing mode" (xml w...
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.