ILIAS  release_4-3 Revision
 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, "textrating");
84  $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getTextRating());
85  $a_xml_writer->xmlEndTag("qtimetadatafield");
86 
87  /*
88  $a_xml_writer->xmlStartTag("qtimetadatafield");
89  $a_xml_writer->xmlElement("fieldlabel", NULL, "keywords");
90  $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getKeywords());
91  $a_xml_writer->xmlEndTag("qtimetadatafield");
92  */
93 
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 
99  $a_xml_writer->xmlStartTag("qtimetadatafield");
100  $a_xml_writer->xmlElement("fieldlabel", NULL, "termscoring");
101  $scores = serialize($this->object->getAnswers());
102  $a_xml_writer->xmlElement("fieldentry", NULL, $scores);
103  $a_xml_writer->xmlEndTag("qtimetadatafield");
104 
105  $a_xml_writer->xmlStartTag("qtimetadatafield");
106  $a_xml_writer->xmlElement("fieldlabel", NULL, "termrelation");
107  $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getKeywordRelation());
108  $a_xml_writer->xmlEndTag("qtimetadatafield");
109 
110  $a_xml_writer->xmlStartTag("qtimetadatafield");
111  $a_xml_writer->xmlElement("fieldlabel", NULL, "specificfeedback");
112  $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getKeywordRelation());
113  $a_xml_writer->xmlEndTag("qtimetadatafield");
114 
115  $a_xml_writer->xmlEndTag("qtimetadata");
116  $a_xml_writer->xmlEndTag("itemmetadata");
117 
118  // PART I: qti presentation
119  $attrs = array(
120  "label" => $this->object->getTitle()
121  );
122  $a_xml_writer->xmlStartTag("presentation", $attrs);
123  // add flow to presentation
124  $a_xml_writer->xmlStartTag("flow");
125  // add material with question text to presentation
126  $this->object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
127  // add information on response rendering
128  $attrs = array(
129  "ident" => "TEXT",
130  "rcardinality" => "Ordered"
131  );
132  $a_xml_writer->xmlStartTag("response_str", $attrs);
133  $attrs = array(
134  "fibtype" => "String",
135  "prompt" => "Box"
136  );
137  if ($this->object->getMaxNumOfChars() > 0)
138  {
139  $attrs["maxchars"] = $this->object->getMaxNumOfChars();
140  }
141  $a_xml_writer->xmlStartTag("render_fib", $attrs);
142  $attrs = array(
143  "ident" => "A"
144  );
145  $a_xml_writer->xmlStartTag("response_label", $attrs);
146  $a_xml_writer->xmlEndTag("response_label");
147  $a_xml_writer->xmlEndTag("render_fib");
148 
149  $solution = $this->object->getSuggestedSolution(0);
150  if (count($solution))
151  {
152  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches))
153  {
154  $a_xml_writer->xmlStartTag("material");
155  $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
156  if (strcmp($matches[1], "") != 0)
157  {
158  $intlink = $solution["internal_link"];
159  }
160  $attrs = array(
161  "label" => "suggested_solution"
162  );
163  $a_xml_writer->xmlElement("mattext", $attrs, $intlink);
164  $a_xml_writer->xmlEndTag("material");
165  }
166  }
167  $a_xml_writer->xmlEndTag("response_str");
168  $a_xml_writer->xmlEndTag("flow");
169  $a_xml_writer->xmlEndTag("presentation");
170 
171  // PART II: qti resprocessing
172  $attrs = array(
173  "scoremodel" => "HumanRater"
174  );
175  $a_xml_writer->xmlStartTag("resprocessing", $attrs);
176  $a_xml_writer->xmlStartTag("outcomes");
177  $attrs = array(
178  "varname" => "WritingScore",
179  "vartype" => "Integer",
180  "minvalue" => "0",
181  "maxvalue" => $this->object->getPoints()
182  );
183  $a_xml_writer->xmlStartTag("decvar", $attrs);
184  $a_xml_writer->xmlEndTag("decvar");
185  $a_xml_writer->xmlEndTag("outcomes");
186 
187  $feedback_allcorrect = $this->object->getFeedbackGeneric(1);
188  $feedback_onenotcorrect = $this->object->getFeedbackGeneric(0);
189  if (strlen($feedback_allcorrect . $feedback_onenotcorrect))
190  {
191  if (strlen($feedback_allcorrect))
192  {
193  $attrs = array(
194  "continue" => "Yes"
195  );
196  $a_xml_writer->xmlStartTag("respcondition", $attrs);
197  // qti conditionvar
198  $a_xml_writer->xmlStartTag("conditionvar");
199  $attrs = array(
200  "respident" => "points"
201  );
202  $a_xml_writer->xmlElement("varequal", $attrs, $this->object->getPoints());
203  $a_xml_writer->xmlEndTag("conditionvar");
204  // qti displayfeedback
205  $attrs = array(
206  "feedbacktype" => "Response",
207  "linkrefid" => "response_allcorrect"
208  );
209  $a_xml_writer->xmlElement("displayfeedback", $attrs);
210  $a_xml_writer->xmlEndTag("respcondition");
211  }
212 
213  if (strlen($feedback_onenotcorrect))
214  {
215  $attrs = array(
216  "continue" => "Yes"
217  );
218  $a_xml_writer->xmlStartTag("respcondition", $attrs);
219  // qti conditionvar
220  $a_xml_writer->xmlStartTag("conditionvar");
221  $a_xml_writer->xmlStartTag("not");
222  $attrs = array(
223  "respident" => "points"
224  );
225  $a_xml_writer->xmlElement("varequal", $attrs, $this->object->getPoints());
226  $a_xml_writer->xmlEndTag("not");
227  $a_xml_writer->xmlEndTag("conditionvar");
228  // qti displayfeedback
229  $attrs = array(
230  "feedbacktype" => "Response",
231  "linkrefid" => "response_onenotcorrect"
232  );
233  $a_xml_writer->xmlElement("displayfeedback", $attrs);
234  $a_xml_writer->xmlEndTag("respcondition");
235  }
236  }
237 
238  $a_xml_writer->xmlStartTag("respcondition");
239  $a_xml_writer->xmlStartTag("conditionvar");
240  $a_xml_writer->xmlElement("other", NULL, "tutor_rated");
241  $a_xml_writer->xmlEndTag("conditionvar");
242  $a_xml_writer->xmlEndTag("respcondition");
243  $a_xml_writer->xmlEndTag("resprocessing");
244 
245  if (strlen($feedback_allcorrect))
246  {
247  $attrs = array(
248  "ident" => "response_allcorrect",
249  "view" => "All"
250  );
251  $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
252  // qti flow_mat
253  $a_xml_writer->xmlStartTag("flow_mat");
254  $this->object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
255  $a_xml_writer->xmlEndTag("flow_mat");
256  $a_xml_writer->xmlEndTag("itemfeedback");
257  }
258  if (strlen($feedback_onenotcorrect))
259  {
260  $attrs = array(
261  "ident" => "response_onenotcorrect",
262  "view" => "All"
263  );
264  $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
265  // qti flow_mat
266  $a_xml_writer->xmlStartTag("flow_mat");
267  $this->object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
268  $a_xml_writer->xmlEndTag("flow_mat");
269  $a_xml_writer->xmlEndTag("itemfeedback");
270  }
271 
272  $a_xml_writer->xmlEndTag("item");
273  $a_xml_writer->xmlEndTag("questestinterop");
274 
275  $xml = $a_xml_writer->xmlDumpMem(FALSE);
276  if (!$a_include_header)
277  {
278  $pos = strpos($xml, "?>");
279  $xml = substr($xml, $pos + 2);
280  }
281  return $xml;
282  }
283 }
284 
285 ?>