ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.assNumericExport.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once "./Modules/TestQuestionPool/classes/export/qti12/class.assQuestionExport.php";
5 
16 {
26  public function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false)
27  {
28  global $ilias;
29 
30  include_once("./Services/Xml/classes/class.ilXmlWriter.php");
31  $a_xml_writer = new ilXmlWriter;
32  // set xml header
33  $a_xml_writer->xmlHeader();
34  $a_xml_writer->xmlStartTag("questestinterop");
35  $attrs = array(
36  "ident" => "il_" . IL_INST_ID . "_qst_" . $this->object->getId(),
37  "title" => $this->object->getTitle(),
38  "maxattempts" => $this->object->getNrOfTries()
39  );
40  $a_xml_writer->xmlStartTag("item", $attrs);
41  // add question description
42  $a_xml_writer->xmlElement("qticomment", null, $this->object->getComment());
43  // add estimated working time
44  $workingtime = $this->object->getEstimatedWorkingTime();
45  $duration = sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]);
46  $a_xml_writer->xmlElement("duration", null, $duration);
47  // add ILIAS specific metadata
48  $a_xml_writer->xmlStartTag("itemmetadata");
49  $a_xml_writer->xmlStartTag("qtimetadata");
50  $a_xml_writer->xmlStartTag("qtimetadatafield");
51  $a_xml_writer->xmlElement("fieldlabel", null, "ILIAS_VERSION");
52  $a_xml_writer->xmlElement("fieldentry", null, $ilias->getSetting("ilias_version"));
53  $a_xml_writer->xmlEndTag("qtimetadatafield");
54  $a_xml_writer->xmlStartTag("qtimetadatafield");
55  $a_xml_writer->xmlElement("fieldlabel", null, "QUESTIONTYPE");
56  $a_xml_writer->xmlElement("fieldentry", null, NUMERIC_QUESTION_IDENTIFIER);
57  $a_xml_writer->xmlEndTag("qtimetadatafield");
58  $a_xml_writer->xmlStartTag("qtimetadatafield");
59  $a_xml_writer->xmlElement("fieldlabel", null, "AUTHOR");
60  $a_xml_writer->xmlElement("fieldentry", null, $this->object->getAuthor());
61  $a_xml_writer->xmlEndTag("qtimetadatafield");
62 
63  // additional content editing information
64  $this->addAdditionalContentEditingModeInformation($a_xml_writer);
65  $this->addGeneralMetadata($a_xml_writer);
66 
67  $a_xml_writer->xmlEndTag("qtimetadata");
68  $a_xml_writer->xmlEndTag("itemmetadata");
69 
70  // PART I: qti presentation
71  $attrs = array(
72  "label" => $this->object->getTitle()
73  );
74  $a_xml_writer->xmlStartTag("presentation", $attrs);
75  // add flow to presentation
76  $a_xml_writer->xmlStartTag("flow");
77  // add material with question text to presentation
78  $this->object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
79  // add answers to presentation
80  $attrs = array(
81  "ident" => "NUM",
82  "rcardinality" => "Single",
83  "numtype" => "Decimal"
84  );
85  $a_xml_writer->xmlStartTag("response_num", $attrs);
86  $solution = $this->object->getSuggestedSolution(0);
87  if (count($solution)) {
88  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches)) {
89  $a_xml_writer->xmlStartTag("material");
90  $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
91  if (strcmp($matches[1], "") != 0) {
92  $intlink = $solution["internal_link"];
93  }
94  $attrs = array(
95  "label" => "suggested_solution"
96  );
97  $a_xml_writer->xmlElement("mattext", $attrs, $intlink);
98  $a_xml_writer->xmlEndTag("material");
99  }
100  }
101  // shuffle output
102  $attrs = array(
103  "fibtype" => "Decimal",
104  "maxchars" => $this->object->getMaxChars()
105  );
106  $a_xml_writer->xmlStartTag("render_fib", $attrs);
107  $a_xml_writer->xmlEndTag("render_fib");
108  $a_xml_writer->xmlEndTag("response_num");
109  $a_xml_writer->xmlEndTag("flow");
110  $a_xml_writer->xmlEndTag("presentation");
111 
112  // PART II: qti resprocessing
113  $a_xml_writer->xmlStartTag("resprocessing");
114  $a_xml_writer->xmlStartTag("outcomes");
115  $a_xml_writer->xmlStartTag("decvar");
116  $a_xml_writer->xmlEndTag("decvar");
117  $a_xml_writer->xmlEndTag("outcomes");
118  // add response conditions
119  $a_xml_writer->xmlStartTag("respcondition");
120  // qti conditionvar
121  $a_xml_writer->xmlStartTag("conditionvar");
122  $attrs = array(
123  "respident" => "NUM"
124  );
125  $a_xml_writer->xmlElement("vargte", $attrs, $this->object->getLowerLimit());
126  $a_xml_writer->xmlElement("varlte", $attrs, $this->object->getUpperLimit());
127  $a_xml_writer->xmlEndTag("conditionvar");
128  // qti setvar
129  $attrs = array(
130  "action" => "Add"
131  );
132  $a_xml_writer->xmlElement("setvar", $attrs, $this->object->getPoints());
133  // qti displayfeedback
134  $attrs = array(
135  "feedbacktype" => "Response",
136  "linkrefid" => "Correct"
137  );
138  $a_xml_writer->xmlElement("displayfeedback", $attrs);
139  $a_xml_writer->xmlEndTag("respcondition");
140 
141  $feedback_allcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
142  $this->object->getId(),
143  true
144  );
145  if (strlen($feedback_allcorrect)) {
146  $attrs = array(
147  "continue" => "Yes"
148  );
149  $a_xml_writer->xmlStartTag("respcondition", $attrs);
150  // qti conditionvar
151  $a_xml_writer->xmlStartTag("conditionvar");
152  $attrs = array(
153  "respident" => "NUM"
154  );
155  $a_xml_writer->xmlElement("vargte", $attrs, $this->object->getLowerLimit());
156  $a_xml_writer->xmlElement("varlte", $attrs, $this->object->getUpperLimit());
157  $a_xml_writer->xmlEndTag("conditionvar");
158  // qti displayfeedback
159  $attrs = array(
160  "feedbacktype" => "Response",
161  "linkrefid" => "response_allcorrect"
162  );
163  $a_xml_writer->xmlElement("displayfeedback", $attrs);
164  $a_xml_writer->xmlEndTag("respcondition");
165  }
166 
167  $feedback_onenotcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
168  $this->object->getId(),
169  false
170  );
171  if (strlen($feedback_onenotcorrect)) {
172  $attrs = array(
173  "continue" => "Yes"
174  );
175  $a_xml_writer->xmlStartTag("respcondition", $attrs);
176  // qti conditionvar
177  $a_xml_writer->xmlStartTag("conditionvar");
178  $a_xml_writer->xmlStartTag("not");
179  $attrs = array(
180  "respident" => "NUM"
181  );
182  $a_xml_writer->xmlElement("vargte", $attrs, $this->object->getLowerLimit());
183  $a_xml_writer->xmlElement("varlte", $attrs, $this->object->getUpperLimit());
184  $a_xml_writer->xmlEndTag("not");
185  $a_xml_writer->xmlEndTag("conditionvar");
186  // qti displayfeedback
187  $attrs = array(
188  "feedbacktype" => "Response",
189  "linkrefid" => "response_onenotcorrect"
190  );
191  $a_xml_writer->xmlElement("displayfeedback", $attrs);
192  $a_xml_writer->xmlEndTag("respcondition");
193  }
194 
195  $a_xml_writer->xmlEndTag("resprocessing");
196 
197  // PART III: qti itemfeedback
198  $attrs = array(
199  "ident" => "Correct",
200  "view" => "All"
201  );
202  $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
203  // qti flow_mat
204  $a_xml_writer->xmlStartTag("flow_mat");
205  $a_xml_writer->xmlStartTag("material");
206  $a_xml_writer->xmlElement("mattext");
207  $a_xml_writer->xmlEndTag("material");
208  $a_xml_writer->xmlEndTag("flow_mat");
209  $a_xml_writer->xmlEndTag("itemfeedback");
210  if (strlen($feedback_allcorrect)) {
211  $attrs = array(
212  "ident" => "response_allcorrect",
213  "view" => "All"
214  );
215  $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
216  // qti flow_mat
217  $a_xml_writer->xmlStartTag("flow_mat");
218  $this->object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
219  $a_xml_writer->xmlEndTag("flow_mat");
220  $a_xml_writer->xmlEndTag("itemfeedback");
221  }
222  if (strlen($feedback_onenotcorrect)) {
223  $attrs = array(
224  "ident" => "response_onenotcorrect",
225  "view" => "All"
226  );
227  $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
228  // qti flow_mat
229  $a_xml_writer->xmlStartTag("flow_mat");
230  $this->object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
231  $a_xml_writer->xmlEndTag("flow_mat");
232  $a_xml_writer->xmlEndTag("itemfeedback");
233  }
234 
235  $a_xml_writer->xmlEndTag("item");
236  $a_xml_writer->xmlEndTag("questestinterop");
237 
238  $xml = $a_xml_writer->xmlDumpMem(false);
239  if (!$a_include_header) {
240  $pos = strpos($xml, "?>");
241  $xml = substr($xml, $pos + 2);
242  }
243  return $xml;
244  }
245 }
XML writer class.
Class for question exports.
addGeneralMetadata(ilXmlWriter $xmlwriter)
$xml
Definition: metadata.php:240
const NUMERIC_QUESTION_IDENTIFIER
toXML($a_include_header=true, $a_include_binary=true, $a_shuffle=false, $test_output=false, $force_image_references=false)
Returns a QTI xml representation of the question.
xmlHeader()
Writes xml header public.
Create styles array
The data for the language used.
Class for numeric question exports.
addAdditionalContentEditingModeInformation(ilXmlWriter $a_xml_writer)
adds a qti meta data field for ilias specific information of "additional content editing mode" (xml w...
Create new PHPExcel object
obj_idprivate