ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assTextQuestionExport.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, TEXT_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->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, "keywords");
92  $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getKeywords());
93  $a_xml_writer->xmlEndTag("qtimetadatafield");
94  $a_xml_writer->xmlStartTag("qtimetadatafield");
95  $a_xml_writer->xmlElement("fieldlabel", NULL, "matchcondition");
96  $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->matchcondition);
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 information on response rendering
111  $attrs = array(
112  "ident" => "TEXT",
113  "rcardinality" => "Ordered"
114  );
115  $a_xml_writer->xmlStartTag("response_str", $attrs);
116  $attrs = array(
117  "fibtype" => "String",
118  "prompt" => "Box"
119  );
120  if ($this->object->getMaxNumOfChars() > 0)
121  {
122  $attrs["maxchars"] = $this->object->getMaxNumOfChars();
123  }
124  $a_xml_writer->xmlStartTag("render_fib", $attrs);
125  $attrs = array(
126  "ident" => "A"
127  );
128  $a_xml_writer->xmlStartTag("response_label", $attrs);
129  $a_xml_writer->xmlEndTag("response_label");
130  $a_xml_writer->xmlEndTag("render_fib");
131 
132  $solution = $this->object->getSuggestedSolution(0);
133  if (count($solution))
134  {
135  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches))
136  {
137  $a_xml_writer->xmlStartTag("material");
138  $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
139  if (strcmp($matches[1], "") != 0)
140  {
141  $intlink = $solution["internal_link"];
142  }
143  $attrs = array(
144  "label" => "suggested_solution"
145  );
146  $a_xml_writer->xmlElement("mattext", $attrs, $intlink);
147  $a_xml_writer->xmlEndTag("material");
148  }
149  }
150  $a_xml_writer->xmlEndTag("response_str");
151  $a_xml_writer->xmlEndTag("flow");
152  $a_xml_writer->xmlEndTag("presentation");
153 
154  // PART II: qti resprocessing
155  $attrs = array(
156  "scoremodel" => "HumanRater"
157  );
158  $a_xml_writer->xmlStartTag("resprocessing", $attrs);
159  $a_xml_writer->xmlStartTag("outcomes");
160  $attrs = array(
161  "varname" => "WritingScore",
162  "vartype" => "Integer",
163  "minvalue" => "0",
164  "maxvalue" => $this->object->getPoints()
165  );
166  $a_xml_writer->xmlStartTag("decvar", $attrs);
167  $a_xml_writer->xmlEndTag("decvar");
168  $a_xml_writer->xmlEndTag("outcomes");
169 
170  $feedback_allcorrect = $this->object->getFeedbackGeneric(1);
171  $feedback_onenotcorrect = $this->object->getFeedbackGeneric(0);
172  if (strlen($feedback_allcorrect . $feedback_onenotcorrect))
173  {
174  if (strlen($feedback_allcorrect))
175  {
176  $attrs = array(
177  "continue" => "Yes"
178  );
179  $a_xml_writer->xmlStartTag("respcondition", $attrs);
180  // qti conditionvar
181  $a_xml_writer->xmlStartTag("conditionvar");
182  $attrs = array(
183  "respident" => "points"
184  );
185  $a_xml_writer->xmlElement("varequal", $attrs, $this->object->getPoints());
186  $a_xml_writer->xmlEndTag("conditionvar");
187  // qti displayfeedback
188  $attrs = array(
189  "feedbacktype" => "Response",
190  "linkrefid" => "response_allcorrect"
191  );
192  $a_xml_writer->xmlElement("displayfeedback", $attrs);
193  $a_xml_writer->xmlEndTag("respcondition");
194  }
195 
196  if (strlen($feedback_onenotcorrect))
197  {
198  $attrs = array(
199  "continue" => "Yes"
200  );
201  $a_xml_writer->xmlStartTag("respcondition", $attrs);
202  // qti conditionvar
203  $a_xml_writer->xmlStartTag("conditionvar");
204  $a_xml_writer->xmlStartTag("not");
205  $attrs = array(
206  "respident" => "points"
207  );
208  $a_xml_writer->xmlElement("varequal", $attrs, $this->object->getPoints());
209  $a_xml_writer->xmlEndTag("not");
210  $a_xml_writer->xmlEndTag("conditionvar");
211  // qti displayfeedback
212  $attrs = array(
213  "feedbacktype" => "Response",
214  "linkrefid" => "response_onenotcorrect"
215  );
216  $a_xml_writer->xmlElement("displayfeedback", $attrs);
217  $a_xml_writer->xmlEndTag("respcondition");
218  }
219  }
220 
221  $a_xml_writer->xmlStartTag("respcondition");
222  $a_xml_writer->xmlStartTag("conditionvar");
223  $a_xml_writer->xmlElement("other", NULL, "tutor_rated");
224  $a_xml_writer->xmlEndTag("conditionvar");
225  $a_xml_writer->xmlEndTag("respcondition");
226  $a_xml_writer->xmlEndTag("resprocessing");
227 
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 ?>