ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assNumericExport.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, NUMERIC_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, "externalID");
84  $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getExternalID());
85  $a_xml_writer->xmlEndTag("qtimetadatafield");
86  $a_xml_writer->xmlEndTag("qtimetadata");
87  $a_xml_writer->xmlEndTag("itemmetadata");
88 
89  // PART I: qti presentation
90  $attrs = array(
91  "label" => $this->object->getTitle()
92  );
93  $a_xml_writer->xmlStartTag("presentation", $attrs);
94  // add flow to presentation
95  $a_xml_writer->xmlStartTag("flow");
96  // add material with question text to presentation
97  $this->object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
98  // add answers to presentation
99  $attrs = array(
100  "ident" => "NUM",
101  "rcardinality" => "Single",
102  "numtype" => "Decimal"
103  );
104  $a_xml_writer->xmlStartTag("response_num", $attrs);
105  $solution = $this->object->getSuggestedSolution(0);
106  if (count($solution))
107  {
108  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches))
109  {
110  $a_xml_writer->xmlStartTag("material");
111  $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
112  if (strcmp($matches[1], "") != 0)
113  {
114  $intlink = $solution["internal_link"];
115  }
116  $attrs = array(
117  "label" => "suggested_solution"
118  );
119  $a_xml_writer->xmlElement("mattext", $attrs, $intlink);
120  $a_xml_writer->xmlEndTag("material");
121  }
122  }
123  // shuffle output
124  $attrs = array(
125  "fibtype" => "Decimal",
126  "maxchars" => $this->object->getMaxChars()
127  );
128  $a_xml_writer->xmlStartTag("render_fib", $attrs);
129  $a_xml_writer->xmlEndTag("render_fib");
130  $a_xml_writer->xmlEndTag("response_num");
131  $a_xml_writer->xmlEndTag("flow");
132  $a_xml_writer->xmlEndTag("presentation");
133 
134  // PART II: qti resprocessing
135  $a_xml_writer->xmlStartTag("resprocessing");
136  $a_xml_writer->xmlStartTag("outcomes");
137  $a_xml_writer->xmlStartTag("decvar");
138  $a_xml_writer->xmlEndTag("decvar");
139  $a_xml_writer->xmlEndTag("outcomes");
140  // add response conditions
141  $a_xml_writer->xmlStartTag("respcondition");
142  // qti conditionvar
143  $a_xml_writer->xmlStartTag("conditionvar");
144  $attrs = array(
145  "respident" => "NUM"
146  );
147  $a_xml_writer->xmlElement("vargte", $attrs, $this->object->getLowerLimit());
148  $a_xml_writer->xmlElement("varlte", $attrs, $this->object->getUpperLimit());
149  $a_xml_writer->xmlEndTag("conditionvar");
150  // qti setvar
151  $attrs = array(
152  "action" => "Add"
153  );
154  $a_xml_writer->xmlElement("setvar", $attrs, $this->object->getPoints());
155  // qti displayfeedback
156  $attrs = array(
157  "feedbacktype" => "Response",
158  "linkrefid" => "Correct"
159  );
160  $a_xml_writer->xmlElement("displayfeedback", $attrs);
161  $a_xml_writer->xmlEndTag("respcondition");
162 
163  $feedback_allcorrect = $this->object->getFeedbackGeneric(1);
164  if (strlen($feedback_allcorrect))
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" => "NUM"
174  );
175  $a_xml_writer->xmlElement("vargte", $attrs, $this->object->getLowerLimit());
176  $a_xml_writer->xmlElement("varlte", $attrs, $this->object->getUpperLimit());
177  $a_xml_writer->xmlEndTag("conditionvar");
178  // qti displayfeedback
179  $attrs = array(
180  "feedbacktype" => "Response",
181  "linkrefid" => "response_allcorrect"
182  );
183  $a_xml_writer->xmlElement("displayfeedback", $attrs);
184  $a_xml_writer->xmlEndTag("respcondition");
185  }
186 
187  $feedback_onenotcorrect = $this->object->getFeedbackGeneric(0);
188  if (strlen($feedback_onenotcorrect))
189  {
190  $attrs = array(
191  "continue" => "Yes"
192  );
193  $a_xml_writer->xmlStartTag("respcondition", $attrs);
194  // qti conditionvar
195  $a_xml_writer->xmlStartTag("conditionvar");
196  $a_xml_writer->xmlStartTag("not");
197  $attrs = array(
198  "respident" => "NUM"
199  );
200  $a_xml_writer->xmlElement("vargte", $attrs, $this->object->getLowerLimit());
201  $a_xml_writer->xmlElement("varlte", $attrs, $this->object->getUpperLimit());
202  $a_xml_writer->xmlEndTag("not");
203  $a_xml_writer->xmlEndTag("conditionvar");
204  // qti displayfeedback
205  $attrs = array(
206  "feedbacktype" => "Response",
207  "linkrefid" => "response_onenotcorrect"
208  );
209  $a_xml_writer->xmlElement("displayfeedback", $attrs);
210  $a_xml_writer->xmlEndTag("respcondition");
211  }
212 
213  $a_xml_writer->xmlEndTag("resprocessing");
214 
215  // PART III: qti itemfeedback
216  $attrs = array(
217  "ident" => "Correct",
218  "view" => "All"
219  );
220  $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
221  // qti flow_mat
222  $a_xml_writer->xmlStartTag("flow_mat");
223  $a_xml_writer->xmlStartTag("material");
224  $a_xml_writer->xmlElement("mattext");
225  $a_xml_writer->xmlEndTag("material");
226  $a_xml_writer->xmlEndTag("flow_mat");
227  $a_xml_writer->xmlEndTag("itemfeedback");
228  if (strlen($feedback_allcorrect))
229  {
230  $attrs = array(
231  "ident" => "response_allcorrect",
232  "view" => "All"
233  );
234  $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
235  // qti flow_mat
236  $a_xml_writer->xmlStartTag("flow_mat");
237  $this->object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
238  $a_xml_writer->xmlEndTag("flow_mat");
239  $a_xml_writer->xmlEndTag("itemfeedback");
240  }
241  if (strlen($feedback_onenotcorrect))
242  {
243  $attrs = array(
244  "ident" => "response_onenotcorrect",
245  "view" => "All"
246  );
247  $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
248  // qti flow_mat
249  $a_xml_writer->xmlStartTag("flow_mat");
250  $this->object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
251  $a_xml_writer->xmlEndTag("flow_mat");
252  $a_xml_writer->xmlEndTag("itemfeedback");
253  }
254 
255  $a_xml_writer->xmlEndTag("item");
256  $a_xml_writer->xmlEndTag("questestinterop");
257 
258  $xml = $a_xml_writer->xmlDumpMem(FALSE);
259  if (!$a_include_header)
260  {
261  $pos = strpos($xml, "?>");
262  $xml = substr($xml, $pos + 2);
263  }
264  return $xml;
265  }
266 }
267 
268 ?>