ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assTextSubsetExport.php
Go to the documentation of this file.
1 <?php
2  /*
3  +----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +----------------------------------------------------------------------------+
22 */
23 
24 include_once "./Modules/TestQuestionPool/classes/export/qti12/class.assQuestionExport.php";
25 
36 {
46  function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false)
47  {
48  global $ilias;
49 
50  include_once("./Services/Xml/classes/class.ilXmlWriter.php");
51  $a_xml_writer = new ilXmlWriter;
52  // set xml header
53  $a_xml_writer->xmlHeader();
54  $a_xml_writer->xmlStartTag("questestinterop");
55  $attrs = array(
56  "ident" => "il_".IL_INST_ID."_qst_".$this->object->getId(),
57  "title" => $this->object->getTitle(),
58  "maxattempts" => $this->object->getNrOfTries()
59  );
60  $a_xml_writer->xmlStartTag("item", $attrs);
61  // add question description
62  $a_xml_writer->xmlElement("qticomment", NULL, $this->object->getComment());
63  // add estimated working time
64  $workingtime = $this->object->getEstimatedWorkingTime();
65  $duration = sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]);
66  $a_xml_writer->xmlElement("duration", NULL, $duration);
67  // add ILIAS specific metadata
68  $a_xml_writer->xmlStartTag("itemmetadata");
69  $a_xml_writer->xmlStartTag("qtimetadata");
70  $a_xml_writer->xmlStartTag("qtimetadatafield");
71  $a_xml_writer->xmlElement("fieldlabel", NULL, "ILIAS_VERSION");
72  $a_xml_writer->xmlElement("fieldentry", NULL, $ilias->getSetting("ilias_version"));
73  $a_xml_writer->xmlEndTag("qtimetadatafield");
74  $a_xml_writer->xmlStartTag("qtimetadatafield");
75  $a_xml_writer->xmlElement("fieldlabel", NULL, "externalID");
76  $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getExternalID());
77  $a_xml_writer->xmlEndTag("qtimetadatafield");
78  $a_xml_writer->xmlStartTag("qtimetadatafield");
79  $a_xml_writer->xmlElement("fieldlabel", NULL, "QUESTIONTYPE");
80  $a_xml_writer->xmlElement("fieldentry", NULL, TEXTSUBSET_QUESTION_IDENTIFIER);
81  $a_xml_writer->xmlEndTag("qtimetadatafield");
82  $a_xml_writer->xmlStartTag("qtimetadatafield");
83  $a_xml_writer->xmlElement("fieldlabel", NULL, "AUTHOR");
84  $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getAuthor());
85  $a_xml_writer->xmlEndTag("qtimetadatafield");
86  $a_xml_writer->xmlStartTag("qtimetadatafield");
87  $a_xml_writer->xmlElement("fieldlabel", NULL, "textrating");
88  $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getTextRating());
89  $a_xml_writer->xmlEndTag("qtimetadatafield");
90  $a_xml_writer->xmlStartTag("qtimetadatafield");
91  $a_xml_writer->xmlElement("fieldlabel", NULL, "correctanswers");
92  $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getCorrectAnswers());
93  $a_xml_writer->xmlEndTag("qtimetadatafield");
94  $a_xml_writer->xmlStartTag("qtimetadatafield");
95  $a_xml_writer->xmlElement("fieldlabel", NULL, "points");
96  $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getPoints());
97  $a_xml_writer->xmlEndTag("qtimetadatafield");
98  $a_xml_writer->xmlEndTag("qtimetadata");
99  $a_xml_writer->xmlEndTag("itemmetadata");
100 
101  // PART I: qti presentation
102  $attrs = array(
103  "label" => $this->object->getTitle()
104  );
105  $a_xml_writer->xmlStartTag("presentation", $attrs);
106  // add flow to presentation
107  $a_xml_writer->xmlStartTag("flow");
108  // add material with question text to presentation
109  $this->object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
110  // add answers to presentation
111  for ($counter = 1; $counter <= $this->object->getCorrectAnswers(); $counter++)
112  {
113  $attrs = array(
114  "ident" => "TEXTSUBSET_" . sprintf("%02d", $counter),
115  "rcardinality" => "Single"
116  );
117  $a_xml_writer->xmlStartTag("response_str", $attrs);
118  $solution = $this->object->getSuggestedSolution(0);
119  if (count($solution))
120  {
121  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches))
122  {
123  $a_xml_writer->xmlStartTag("material");
124  $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
125  if (strcmp($matches[1], "") != 0)
126  {
127  $intlink = $solution["internal_link"];
128  }
129  $attrs = array(
130  "label" => "suggested_solution"
131  );
132  $a_xml_writer->xmlElement("mattext", $attrs, $intlink);
133  $a_xml_writer->xmlEndTag("material");
134  }
135  }
136  // shuffle output
137  $attrs = array(
138  "fibtype" => "String",
139  "columns" => $this->object->getMaxTextboxWidth()
140  );
141  $a_xml_writer->xmlStartTag("render_fib", $attrs);
142  $a_xml_writer->xmlEndTag("render_fib");
143  $a_xml_writer->xmlEndTag("response_str");
144  }
145 
146  $a_xml_writer->xmlEndTag("flow");
147  $a_xml_writer->xmlEndTag("presentation");
148 
149  // PART II: qti resprocessing
150  $a_xml_writer->xmlStartTag("resprocessing");
151  $a_xml_writer->xmlStartTag("outcomes");
152  $a_xml_writer->xmlStartTag("decvar");
153  $a_xml_writer->xmlEndTag("decvar");
154  $attribs = array(
155  "varname" => "matches",
156  "defaultval" => "0"
157  );
158  $a_xml_writer->xmlElement("decvar", $attribs, NULL);
159  $a_xml_writer->xmlEndTag("outcomes");
160  // add response conditions
161  for ($counter = 1; $counter <= $this->object->getCorrectAnswers(); $counter++)
162  {
163  $scoregroups =& $this->object->joinAnswers();
164  foreach ($scoregroups as $points => $scoreanswers)
165  {
166  $attrs = array(
167  "continue" => "Yes"
168  );
169  $a_xml_writer->xmlStartTag("respcondition", $attrs);
170  // qti conditionvar
171  $a_xml_writer->xmlStartTag("conditionvar");
172  $attrs = array(
173  "respident" => "TEXTSUBSET_" . sprintf("%02d", $counter)
174  );
175  $a_xml_writer->xmlElement("varsubset", $attrs, join(",", $scoreanswers));
176  $a_xml_writer->xmlEndTag("conditionvar");
177  // qti setvar
178  $attrs = array(
179  "varname" => "matches",
180  "action" => "Add"
181  );
182  $a_xml_writer->xmlElement("setvar", $attrs, $points);
183  // qti displayfeedback
184  $attrs = array(
185  "feedbacktype" => "Response",
186  "linkrefid" => "Matches_" . sprintf("%02d", $counter)
187  );
188  $a_xml_writer->xmlElement("displayfeedback", $attrs);
189  $a_xml_writer->xmlEndTag("respcondition");
190  }
191  }
192 
193  $feedback_allcorrect = $this->object->getFeedbackGeneric(1);
194  $feedback_onenotcorrect = $this->object->getFeedbackGeneric(0);
195  if (strlen($feedback_allcorrect . $feedback_onenotcorrect))
196  {
197  if (strlen($feedback_allcorrect))
198  {
199  $attrs = array(
200  "continue" => "Yes"
201  );
202  $a_xml_writer->xmlStartTag("respcondition", $attrs);
203  // qti conditionvar
204  $a_xml_writer->xmlStartTag("conditionvar");
205  $attrs = array(
206  "respident" => "points"
207  );
208  $a_xml_writer->xmlElement("varsubset", $attrs, $this->object->getMaximumPoints());
209  $a_xml_writer->xmlEndTag("conditionvar");
210  // qti displayfeedback
211  $attrs = array(
212  "feedbacktype" => "Response",
213  "linkrefid" => "response_allcorrect"
214  );
215  $a_xml_writer->xmlElement("displayfeedback", $attrs);
216  $a_xml_writer->xmlEndTag("respcondition");
217  }
218 
219  if (strlen($feedback_onenotcorrect))
220  {
221  $attrs = array(
222  "continue" => "Yes"
223  );
224  $a_xml_writer->xmlStartTag("respcondition", $attrs);
225  // qti conditionvar
226  $a_xml_writer->xmlStartTag("conditionvar");
227  $a_xml_writer->xmlStartTag("not");
228 
229  $attrs = array(
230  "respident" => "points"
231  );
232  $a_xml_writer->xmlElement("varsubset", $attrs, $this->object->getMaximumPoints());
233 
234  $a_xml_writer->xmlEndTag("not");
235  $a_xml_writer->xmlEndTag("conditionvar");
236  // qti displayfeedback
237  $attrs = array(
238  "feedbacktype" => "Response",
239  "linkrefid" => "response_onenotcorrect"
240  );
241  $a_xml_writer->xmlElement("displayfeedback", $attrs);
242  $a_xml_writer->xmlEndTag("respcondition");
243  }
244  }
245 
246  $a_xml_writer->xmlEndTag("resprocessing");
247 
248  // PART III: qti itemfeedback
249  for ($counter = 1; $counter <= $this->object->getCorrectAnswers(); $counter++)
250  {
251  $attrs = array(
252  "ident" => "Matches_" . sprintf("%02d", $counter),
253  "view" => "All"
254  );
255  $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
256  // qti flow_mat
257  $a_xml_writer->xmlStartTag("flow_mat");
258  $a_xml_writer->xmlStartTag("material");
259  $a_xml_writer->xmlElement("mattext");
260  $a_xml_writer->xmlEndTag("material");
261  $a_xml_writer->xmlEndTag("flow_mat");
262  $a_xml_writer->xmlEndTag("itemfeedback");
263  }
264 
265  if (strlen($feedback_allcorrect))
266  {
267  $attrs = array(
268  "ident" => "response_allcorrect",
269  "view" => "All"
270  );
271  $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
272  // qti flow_mat
273  $a_xml_writer->xmlStartTag("flow_mat");
274  $this->object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
275  $a_xml_writer->xmlEndTag("flow_mat");
276  $a_xml_writer->xmlEndTag("itemfeedback");
277  }
278  if (strlen($feedback_onenotcorrect))
279  {
280  $attrs = array(
281  "ident" => "response_onenotcorrect",
282  "view" => "All"
283  );
284  $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
285  // qti flow_mat
286  $a_xml_writer->xmlStartTag("flow_mat");
287  $this->object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
288  $a_xml_writer->xmlEndTag("flow_mat");
289  $a_xml_writer->xmlEndTag("itemfeedback");
290  }
291 
292  $a_xml_writer->xmlEndTag("item");
293  $a_xml_writer->xmlEndTag("questestinterop");
294 
295  $xml = $a_xml_writer->xmlDumpMem(FALSE);
296  if (!$a_include_header)
297  {
298  $pos = strpos($xml, "?>");
299  $xml = substr($xml, $pos + 2);
300  }
301  return $xml;
302  }
303 }
304 
305 ?>