ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.assTextSubsetExport.php
Go to the documentation of this file.
1 <?php
2 
29 {
35  public function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false): string
36  {
37  global $DIC;
38  $ilias = $DIC['ilias'];
39 
40  $a_xml_writer = new ilXmlWriter();
41  // set xml header
42  $a_xml_writer->xmlHeader();
43  $a_xml_writer->xmlStartTag("questestinterop");
44  $attrs = [
45  "ident" => "il_" . IL_INST_ID . "_qst_" . $this->object->getId(),
46  "title" => $this->object->getTitle(),
47  "maxattempts" => $this->object->getNrOfTries()
48  ];
49  $a_xml_writer->xmlStartTag("item", $attrs);
50  // add question description
51  $a_xml_writer->xmlElement("qticomment", null, $this->object->getComment());
52  $a_xml_writer->xmlStartTag("itemmetadata");
53  $a_xml_writer->xmlStartTag("qtimetadata");
54  $a_xml_writer->xmlStartTag("qtimetadatafield");
55  $a_xml_writer->xmlElement("fieldlabel", null, "ILIAS_VERSION");
56  $a_xml_writer->xmlElement("fieldentry", null, $ilias->getSetting("ilias_version"));
57  $a_xml_writer->xmlEndTag("qtimetadatafield");
58  $a_xml_writer->xmlStartTag("qtimetadatafield");
59  $a_xml_writer->xmlElement("fieldlabel", null, "QUESTIONTYPE");
60  $a_xml_writer->xmlElement("fieldentry", null, $this->object->getQuestionType());
61  $a_xml_writer->xmlEndTag("qtimetadatafield");
62  $a_xml_writer->xmlStartTag("qtimetadatafield");
63  $a_xml_writer->xmlElement("fieldlabel", null, "AUTHOR");
64  $a_xml_writer->xmlElement("fieldentry", null, $this->object->getAuthor());
65  $a_xml_writer->xmlEndTag("qtimetadatafield");
66 
67  // additional content editing information
68  $this->addAdditionalContentEditingModeInformation($a_xml_writer);
69  $this->addGeneralMetadata($a_xml_writer);
70 
71  $a_xml_writer->xmlStartTag("qtimetadatafield");
72  $a_xml_writer->xmlElement("fieldlabel", null, "textrating");
73  $a_xml_writer->xmlElement("fieldentry", null, $this->object->getTextRating());
74  $a_xml_writer->xmlEndTag("qtimetadatafield");
75  $a_xml_writer->xmlStartTag("qtimetadatafield");
76  $a_xml_writer->xmlElement("fieldlabel", null, "correctanswers");
77  $a_xml_writer->xmlElement("fieldentry", null, $this->object->getCorrectAnswers());
78  $a_xml_writer->xmlEndTag("qtimetadatafield");
79  $a_xml_writer->xmlStartTag("qtimetadatafield");
80  $a_xml_writer->xmlElement("fieldlabel", null, "points");
81  $a_xml_writer->xmlElement("fieldentry", null, $this->object->getPoints());
82  $a_xml_writer->xmlEndTag("qtimetadatafield");
83  $a_xml_writer->xmlEndTag("qtimetadata");
84  $a_xml_writer->xmlEndTag("itemmetadata");
85 
86  // PART I: qti presentation
87  $attrs = [
88  "label" => $this->object->getTitle()
89  ];
90  $a_xml_writer->xmlStartTag("presentation", $attrs);
91  // add flow to presentation
92  $a_xml_writer->xmlStartTag("flow");
93  // add material with question text to presentation
94  $this->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
95  // add answers to presentation
96  for ($counter = 1; $counter <= $this->object->getCorrectAnswers(); $counter++) {
97  $attrs = [
98  "ident" => "TEXTSUBSET_$counter",
99  "rcardinality" => "Single"
100  ];
101  $a_xml_writer->xmlStartTag("response_str", $attrs);
102  $a_xml_writer = $this->addSuggestedSolution($a_xml_writer);
103  // shuffle output
104  $attrs = [
105  "fibtype" => "String",
106  "columns" => $this->object->getMaxTextboxWidth()
107  ];
108  $a_xml_writer->xmlStartTag("render_fib", $attrs);
109  $a_xml_writer->xmlEndTag("render_fib");
110  $a_xml_writer->xmlEndTag("response_str");
111  }
112 
113  $a_xml_writer->xmlEndTag("flow");
114  $a_xml_writer->xmlEndTag("presentation");
115 
116  // PART II: qti resprocessing
117  $a_xml_writer->xmlStartTag("resprocessing");
118  $a_xml_writer->xmlStartTag("outcomes");
119  $a_xml_writer->xmlStartTag("decvar");
120  $a_xml_writer->xmlEndTag("decvar");
121  $attribs = [
122  "varname" => "matches",
123  "defaultval" => "0"
124  ];
125  $a_xml_writer->xmlElement("decvar", $attribs, null);
126  $a_xml_writer->xmlEndTag("outcomes");
127  // add response conditions
128  for ($counter = 1; $counter <= $this->object->getCorrectAnswers(); $counter++) {
129  $scoregroups = &$this->object->joinAnswers();
130  foreach ($scoregroups as $points => $scoreanswers) {
131  $attrs = [
132  "continue" => "Yes"
133  ];
134  $a_xml_writer->xmlStartTag("respcondition", $attrs);
135  // qti conditionvar
136  $a_xml_writer->xmlStartTag("conditionvar");
137  $attrs = [
138  "respident" => "TEXTSUBSET_$counter"
139  ];
140  $a_xml_writer->xmlElement("varsubset", $attrs, join(",", $scoreanswers));
141  $a_xml_writer->xmlEndTag("conditionvar");
142  // qti setvar
143  $attrs = [
144  "varname" => "matches",
145  "action" => "Add"
146  ];
147  $a_xml_writer->xmlElement("setvar", $attrs, $points);
148  // qti displayfeedback
149  $attrs = [
150  "feedbacktype" => "Response",
151  "linkrefid" => "Matches_$counter"
152  ];
153  $a_xml_writer->xmlElement("displayfeedback", $attrs);
154  $a_xml_writer->xmlEndTag("respcondition");
155  }
156  }
157 
158  $feedback_allcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
159  $this->object->getId(),
160  true
161  );
162  $feedback_onenotcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
163  $this->object->getId(),
164  false
165  );
166  if (strlen($feedback_allcorrect . $feedback_onenotcorrect)) {
167  if (strlen($feedback_allcorrect)) {
168  $attrs = [
169  "continue" => "Yes"
170  ];
171  $a_xml_writer->xmlStartTag("respcondition", $attrs);
172  // qti conditionvar
173  $a_xml_writer->xmlStartTag("conditionvar");
174  $attrs = [
175  "respident" => "points"
176  ];
177  $a_xml_writer->xmlElement("varsubset", $attrs, $this->object->getMaximumPoints());
178  $a_xml_writer->xmlEndTag("conditionvar");
179  // qti displayfeedback
180  $attrs = [
181  "feedbacktype" => "Response",
182  "linkrefid" => "response_allcorrect"
183  ];
184  $a_xml_writer->xmlElement("displayfeedback", $attrs);
185  $a_xml_writer->xmlEndTag("respcondition");
186  }
187 
188  if (strlen($feedback_onenotcorrect)) {
189  $attrs = [
190  "continue" => "Yes"
191  ];
192  $a_xml_writer->xmlStartTag("respcondition", $attrs);
193  // qti conditionvar
194  $a_xml_writer->xmlStartTag("conditionvar");
195  $a_xml_writer->xmlStartTag("not");
196 
197  $attrs = [
198  "respident" => "points"
199  ];
200  $a_xml_writer->xmlElement("varsubset", $attrs, $this->object->getMaximumPoints());
201 
202  $a_xml_writer->xmlEndTag("not");
203  $a_xml_writer->xmlEndTag("conditionvar");
204  // qti displayfeedback
205  $attrs = [
206  "feedbacktype" => "Response",
207  "linkrefid" => "response_onenotcorrect"
208  ];
209  $a_xml_writer->xmlElement("displayfeedback", $attrs);
210  $a_xml_writer->xmlEndTag("respcondition");
211  }
212  }
213 
214  $a_xml_writer->xmlEndTag("resprocessing");
215 
216  // PART III: qti itemfeedback
217  for ($counter = 1; $counter <= $this->object->getCorrectAnswers(); $counter++) {
218  $attrs = [
219  "ident" => "Matches_$counter",
220  "view" => "All"
221  ];
222  $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
223  // qti flow_mat
224  $a_xml_writer->xmlStartTag("flow_mat");
225  $a_xml_writer->xmlStartTag("material");
226  $a_xml_writer->xmlElement("mattext");
227  $a_xml_writer->xmlEndTag("material");
228  $a_xml_writer->xmlEndTag("flow_mat");
229  $a_xml_writer->xmlEndTag("itemfeedback");
230  }
231 
232  if (strlen($feedback_allcorrect)) {
233  $attrs = [
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->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 = [
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->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 }
const IL_INST_ID
Definition: constants.php:40
addQTIMaterial(ilXmlWriter $a_xml_writer, string $a_material, bool $close_material_tag=true, bool $add_mobs=true)
Class for question exports.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addGeneralMetadata(ilXmlWriter $xmlwriter)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
global $DIC
Definition: shib_login.php:26
addAdditionalContentEditingModeInformation(ilXmlWriter $a_xml_writer)
adds a qti meta data field for ilias specific information of "additional content editing mode" (xml w...
addSuggestedSolution(ilXmlWriter $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...