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