ILIAS  release_4-3 Revision
 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, "QUESTIONTYPE");
76  $a_xml_writer->xmlElement("fieldentry", NULL, TEXTSUBSET_QUESTION_IDENTIFIER);
77  $a_xml_writer->xmlEndTag("qtimetadatafield");
78  $a_xml_writer->xmlStartTag("qtimetadatafield");
79  $a_xml_writer->xmlElement("fieldlabel", NULL, "AUTHOR");
80  $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getAuthor());
81  $a_xml_writer->xmlEndTag("qtimetadatafield");
82  $a_xml_writer->xmlStartTag("qtimetadatafield");
83  $a_xml_writer->xmlElement("fieldlabel", NULL, "textrating");
84  $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getTextRating());
85  $a_xml_writer->xmlEndTag("qtimetadatafield");
86  $a_xml_writer->xmlStartTag("qtimetadatafield");
87  $a_xml_writer->xmlElement("fieldlabel", NULL, "correctanswers");
88  $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getCorrectAnswers());
89  $a_xml_writer->xmlEndTag("qtimetadatafield");
90  $a_xml_writer->xmlStartTag("qtimetadatafield");
91  $a_xml_writer->xmlElement("fieldlabel", NULL, "points");
92  $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getPoints());
93  $a_xml_writer->xmlEndTag("qtimetadatafield");
94  $a_xml_writer->xmlEndTag("qtimetadata");
95  $a_xml_writer->xmlEndTag("itemmetadata");
96 
97  // PART I: qti presentation
98  $attrs = array(
99  "label" => $this->object->getTitle()
100  );
101  $a_xml_writer->xmlStartTag("presentation", $attrs);
102  // add flow to presentation
103  $a_xml_writer->xmlStartTag("flow");
104  // add material with question text to presentation
105  $this->object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
106  // add answers to presentation
107  for ($counter = 1; $counter <= $this->object->getCorrectAnswers(); $counter++)
108  {
109  $attrs = array(
110  "ident" => "TEXTSUBSET_" . sprintf("%02d", $counter),
111  "rcardinality" => "Single"
112  );
113  $a_xml_writer->xmlStartTag("response_str", $attrs);
114  $solution = $this->object->getSuggestedSolution(0);
115  if (count($solution))
116  {
117  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches))
118  {
119  $a_xml_writer->xmlStartTag("material");
120  $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
121  if (strcmp($matches[1], "") != 0)
122  {
123  $intlink = $solution["internal_link"];
124  }
125  $attrs = array(
126  "label" => "suggested_solution"
127  );
128  $a_xml_writer->xmlElement("mattext", $attrs, $intlink);
129  $a_xml_writer->xmlEndTag("material");
130  }
131  }
132  // shuffle output
133  $attrs = array(
134  "fibtype" => "String",
135  "columns" => $this->object->getMaxTextboxWidth()
136  );
137  $a_xml_writer->xmlStartTag("render_fib", $attrs);
138  $a_xml_writer->xmlEndTag("render_fib");
139  $a_xml_writer->xmlEndTag("response_str");
140  }
141 
142  $a_xml_writer->xmlEndTag("flow");
143  $a_xml_writer->xmlEndTag("presentation");
144 
145  // PART II: qti resprocessing
146  $a_xml_writer->xmlStartTag("resprocessing");
147  $a_xml_writer->xmlStartTag("outcomes");
148  $a_xml_writer->xmlStartTag("decvar");
149  $a_xml_writer->xmlEndTag("decvar");
150  $attribs = array(
151  "varname" => "matches",
152  "defaultval" => "0"
153  );
154  $a_xml_writer->xmlElement("decvar", $attribs, NULL);
155  $a_xml_writer->xmlEndTag("outcomes");
156  // add response conditions
157  for ($counter = 1; $counter <= $this->object->getCorrectAnswers(); $counter++)
158  {
159  $scoregroups =& $this->object->joinAnswers();
160  foreach ($scoregroups as $points => $scoreanswers)
161  {
162  $attrs = array(
163  "continue" => "Yes"
164  );
165  $a_xml_writer->xmlStartTag("respcondition", $attrs);
166  // qti conditionvar
167  $a_xml_writer->xmlStartTag("conditionvar");
168  $attrs = array(
169  "respident" => "TEXTSUBSET_" . sprintf("%02d", $counter)
170  );
171  $a_xml_writer->xmlElement("varsubset", $attrs, join(",", $scoreanswers));
172  $a_xml_writer->xmlEndTag("conditionvar");
173  // qti setvar
174  $attrs = array(
175  "varname" => "matches",
176  "action" => "Add"
177  );
178  $a_xml_writer->xmlElement("setvar", $attrs, $points);
179  // qti displayfeedback
180  $attrs = array(
181  "feedbacktype" => "Response",
182  "linkrefid" => "Matches_" . sprintf("%02d", $counter)
183  );
184  $a_xml_writer->xmlElement("displayfeedback", $attrs);
185  $a_xml_writer->xmlEndTag("respcondition");
186  }
187  }
188 
189  $feedback_allcorrect = $this->object->getFeedbackGeneric(1);
190  $feedback_onenotcorrect = $this->object->getFeedbackGeneric(0);
191  if (strlen($feedback_allcorrect . $feedback_onenotcorrect))
192  {
193  if (strlen($feedback_allcorrect))
194  {
195  $attrs = array(
196  "continue" => "Yes"
197  );
198  $a_xml_writer->xmlStartTag("respcondition", $attrs);
199  // qti conditionvar
200  $a_xml_writer->xmlStartTag("conditionvar");
201  $attrs = array(
202  "respident" => "points"
203  );
204  $a_xml_writer->xmlElement("varsubset", $attrs, $this->object->getMaximumPoints());
205  $a_xml_writer->xmlEndTag("conditionvar");
206  // qti displayfeedback
207  $attrs = array(
208  "feedbacktype" => "Response",
209  "linkrefid" => "response_allcorrect"
210  );
211  $a_xml_writer->xmlElement("displayfeedback", $attrs);
212  $a_xml_writer->xmlEndTag("respcondition");
213  }
214 
215  if (strlen($feedback_onenotcorrect))
216  {
217  $attrs = array(
218  "continue" => "Yes"
219  );
220  $a_xml_writer->xmlStartTag("respcondition", $attrs);
221  // qti conditionvar
222  $a_xml_writer->xmlStartTag("conditionvar");
223  $a_xml_writer->xmlStartTag("not");
224 
225  $attrs = array(
226  "respident" => "points"
227  );
228  $a_xml_writer->xmlElement("varsubset", $attrs, $this->object->getMaximumPoints());
229 
230  $a_xml_writer->xmlEndTag("not");
231  $a_xml_writer->xmlEndTag("conditionvar");
232  // qti displayfeedback
233  $attrs = array(
234  "feedbacktype" => "Response",
235  "linkrefid" => "response_onenotcorrect"
236  );
237  $a_xml_writer->xmlElement("displayfeedback", $attrs);
238  $a_xml_writer->xmlEndTag("respcondition");
239  }
240  }
241 
242  $a_xml_writer->xmlEndTag("resprocessing");
243 
244  // PART III: qti itemfeedback
245  for ($counter = 1; $counter <= $this->object->getCorrectAnswers(); $counter++)
246  {
247  $attrs = array(
248  "ident" => "Matches_" . sprintf("%02d", $counter),
249  "view" => "All"
250  );
251  $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
252  // qti flow_mat
253  $a_xml_writer->xmlStartTag("flow_mat");
254  $a_xml_writer->xmlStartTag("material");
255  $a_xml_writer->xmlElement("mattext");
256  $a_xml_writer->xmlEndTag("material");
257  $a_xml_writer->xmlEndTag("flow_mat");
258  $a_xml_writer->xmlEndTag("itemfeedback");
259  }
260 
261  if (strlen($feedback_allcorrect))
262  {
263  $attrs = array(
264  "ident" => "response_allcorrect",
265  "view" => "All"
266  );
267  $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
268  // qti flow_mat
269  $a_xml_writer->xmlStartTag("flow_mat");
270  $this->object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
271  $a_xml_writer->xmlEndTag("flow_mat");
272  $a_xml_writer->xmlEndTag("itemfeedback");
273  }
274  if (strlen($feedback_onenotcorrect))
275  {
276  $attrs = array(
277  "ident" => "response_onenotcorrect",
278  "view" => "All"
279  );
280  $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
281  // qti flow_mat
282  $a_xml_writer->xmlStartTag("flow_mat");
283  $this->object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
284  $a_xml_writer->xmlEndTag("flow_mat");
285  $a_xml_writer->xmlEndTag("itemfeedback");
286  }
287 
288  $a_xml_writer->xmlEndTag("item");
289  $a_xml_writer->xmlEndTag("questestinterop");
290 
291  $xml = $a_xml_writer->xmlDumpMem(FALSE);
292  if (!$a_include_header)
293  {
294  $pos = strpos($xml, "?>");
295  $xml = substr($xml, $pos + 2);
296  }
297  return $xml;
298  }
299 }
300 
301 ?>