ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.assLongMenuExport.php
Go to the documentation of this file.
1<?php
2require_once 'Modules/TestQuestionPool/classes/export/qti12/class.assQuestionExport.php';
4{
8 public $object;
9
10 public function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false)
11 {
12 global $ilias;
13
14 $correct_answers = $this->object->getCorrectAnswers();
15 $answers = $this->object->getAnswers();
16
17 include_once("./Services/Xml/classes/class.ilXmlWriter.php");
18 $xml = new ilXmlWriter;
19 // set xml header
20 $xml->xmlHeader();
21 $xml->xmlStartTag("questestinterop");
22 // add question description
23 $attrs = array(
24 "ident" => "il_" . IL_INST_ID . "_qst_" . $this->object->getId(),
25 "title" => $this->object->getTitle(),
26 "maxattempts" => $this->object->getNrOfTries()
27 );
28 $xml->xmlStartTag("item", $attrs);
29 $xml->xmlElement("qticomment", null, $this->object->getComment());
30 // add estimated working time
31 $workingtime = $this->object->getEstimatedWorkingTime();
32 $duration = sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]);
33 $xml->xmlElement("duration", null, $duration);
34 // add ILIAS specific metadata
35 $xml->xmlStartTag("itemmetadata");
36 $xml->xmlStartTag("qtimetadata");
37 $xml->xmlStartTag("qtimetadatafield");
38 $xml->xmlElement("fieldlabel", null, "ILIAS_VERSION");
39 $xml->xmlElement("fieldentry", null, $ilias->getSetting("ilias_version"));
40 $xml->xmlEndTag("qtimetadatafield");
41 $xml->xmlStartTag("qtimetadatafield");
42 $xml->xmlElement("fieldlabel", null, "QUESTIONTYPE");
43 $xml->xmlElement("fieldentry", null, LONG_MENU_QUESTION_IDENTIFIER);
44 $xml->xmlEndTag("qtimetadatafield");
45 $xml->xmlStartTag("qtimetadatafield");
46 $xml->xmlElement("fieldlabel", null, "AUTHOR");
47 $xml->xmlElement("fieldentry", null, $this->object->getAuthor());
48 $xml->xmlEndTag("qtimetadatafield");
49
50 $xml->xmlStartTag("qtimetadatafield");
51 $xml->xmlElement("fieldlabel", null, "minAutoCompleteLength");
52 $xml->xmlElement("fieldentry", null, $this->object->getMinAutoComplete());
53 $xml->xmlEndTag("qtimetadatafield");
54
55 $xml->xmlStartTag("qtimetadatafield");
56 $xml->xmlElement("fieldlabel", null, "gapTypes");
57 $gap_types = array();
58 if (is_array($correct_answers)) {
59 foreach ($correct_answers as $key => $value) {
60 $gap_types[] = $value[2];
61 }
62 }
63 $xml->xmlElement("fieldentry", null, json_encode($gap_types));
64 $xml->xmlEndTag("qtimetadatafield");
65
66 // additional content editing information
69
70 $xml->xmlStartTag("qtimetadatafield");
71 $xml->xmlElement("fieldlabel", null, "feedback_setting");
72 $xml->xmlElement("fieldentry", null, $this->object->getSpecificFeedbackSetting());
73 $xml->xmlEndTag("qtimetadatafield");
74
75 $xml->xmlEndTag("qtimetadata");
76 $xml->xmlEndTag("itemmetadata");
77 $xml->xmlStartTag("presentation");
78 // add flow to presentation
79 $xml->xmlStartTag("flow");
80
81
82 $this->object->addQTIMaterial($xml, $this->object->getQuestion());
83 $this->object->addQTIMaterial($xml, $this->object->getLongMenuTextValue());
84
85 foreach ($answers as $key => $values) {
86 $real_id = $key +1;
87 $attrs = array(
88 "ident" => "LongMenu_" . $real_id,
89 "rcardinality" => "Single"
90 );
91 $xml->xmlStartTag("response_str", $attrs);
92 foreach ($values as $index => $value) {
93 $xml->xmlStartTag("response_label", array('ident' => $index));
94 $xml->xmlStartTag("material");
95 $xml->xmlElement("fieldentry", null, $value);
96 $xml->xmlEndTag("material");
97 $xml->xmlEndTag("response_label");
98 }
99 $xml->xmlEndTag("response_str");
100 }
101 $xml->xmlEndTag("flow");
102 $xml->xmlEndTag("presentation");
103
104 $xml->xmlStartTag("resprocessing");
105 $xml->xmlStartTag("outcomes");
106 $xml->xmlElement("decvar");
107 $xml->xmlEndTag("outcomes");
108 foreach ($answers as $key => $values) {
109 $real_id = $key + 1;
110 foreach ($values as $index => $value) {
111 $xml->xmlStartTag("respcondition", array('continue' => 'Yes'));
112 $xml->xmlStartTag("conditionvar");
113 $xml->xmlElement("varequal", array('respident' => "LongMenu_" . $real_id), $value);
114 $xml->xmlEndTag("conditionvar");
115
116 if (in_array($value, $correct_answers[$key][0])) {
117 $xml->xmlElement("setvar", array('action' => "Add"), $correct_answers[$key][1]);
118 } else {
119 $xml->xmlElement("setvar", array('action' => "Add"), 0);
120 }
121 $xml->xmlElement("displayfeedback", array('feedbacktype' => "Response", 'linkrefid' => $key . '_Response_' . $index));
122 $xml->xmlEndTag("respcondition");
123 }
124 }
125 $feedback_allcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
126 $this->object->getId(),
127 true
128 );
129 if (strlen($feedback_allcorrect) > 0) {
130 $xml->xmlStartTag("respcondition", array('continue' => 'Yes'));
131 $xml->xmlStartTag("conditionvar");
132 foreach ($correct_answers as $key => $values) {
133 $real_id = $key + 1;
134 if ($key > 0) {
135 $xml->xmlStartTag("and");
136 }
137
138 foreach ($values[0] as $index => $value) {
139 if ($index > 0) {
140 $xml->xmlStartTag("or");
141 }
142 $xml->xmlElement("varequal", array('respident' => "LongMenu_" . $real_id), $value);
143 if ($index > 0) {
144 $xml->xmlEndTag("or");
145 }
146 }
147 if ($key > 0) {
148 $xml->xmlEndTag("and");
149 }
150 }
151 $xml->xmlEndTag("conditionvar");
152 $xml->xmlElement("displayfeedback", array('feedbacktype' => "Response", 'linkrefid' => 'response_allcorrect'));
153 $xml->xmlEndTag("respcondition");
154 }
155
156 $feedback_onenotcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
157 $this->object->getId(),
158 false
159 );
160 if (strlen($feedback_onenotcorrect)) {
161 $xml->xmlStartTag("respcondition", array('continue' => 'Yes'));
162 $xml->xmlStartTag("conditionvar");
163 $xml->xmlStartTag("not");
164 foreach ($correct_answers as $key => $values) {
165 $real_id = $key + 1;
166 if ($key > 0) {
167 $xml->xmlStartTag("and");
168 }
169
170 foreach ($values[0] as $index => $value) {
171 if ($index > 0) {
172 $xml->xmlStartTag("or");
173 }
174 $xml->xmlElement("varequal", array('respident' => "LongMenu_" . $real_id), $value);
175 if ($index > 0) {
176 $xml->xmlEndTag("or");
177 }
178 }
179 if ($key > 0) {
180 $xml->xmlEndTag("and");
181 }
182 }
183 $xml->xmlEndTag("not");
184 $xml->xmlEndTag("conditionvar");
185 $xml->xmlElement("displayfeedback", array('feedbacktype' => "Response", 'linkrefid' => 'response_onenotcorrect'));
186 $xml->xmlEndTag("respcondition");
187 }
188
189 $xml->xmlEndTag("resprocessing");
190
191
192
193
194 for ($i = 0; $i < sizeof($correct_answers); $i++) {
195 $attrs = array(
196 "ident" => $i,
197 "view" => "All"
198 );
199 $xml->xmlStartTag("itemfeedback", $attrs);
200 // qti flow_mat
201 $xml->xmlStartTag("flow_mat");
202 $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation(
203 $this->object->getId(),
204 $i
205 );
206 $this->object->addQTIMaterial($xml, $fb);
207 $xml->xmlEndTag("flow_mat");
208 $xml->xmlEndTag("itemfeedback");
209 }
210
211 if (strlen($feedback_allcorrect) > 0) {
212 $xml->xmlStartTag("itemfeedback", array('ident' => 'response_allcorrect','view' => 'All'));
213 $xml->xmlStartTag("flow_mat");
214 $xml->xmlStartTag("material");
215 $xml->xmlElement("mattext", array('texttype' => 'text/xhtml'), $feedback_allcorrect);
216 $xml->xmlEndTag("material");
217 $xml->xmlEndTag("flow_mat");
218 $xml->xmlEndTag("itemfeedback");
219 }
220 if (strlen($feedback_onenotcorrect) > 0) {
221 $xml->xmlStartTag("itemfeedback", array('ident' => 'response_onenotcorrect', 'view' => 'All'));
222 $xml->xmlStartTag("flow_mat");
223 $xml->xmlStartTag("material");
224 $xml->xmlElement("mattext", array('texttype' => 'text/xhtml'), $feedback_onenotcorrect);
225 $xml->xmlEndTag("material");
226 $xml->xmlEndTag("flow_mat");
227 $xml->xmlEndTag("itemfeedback");
228 }
229
230 $xml->xmlEndTag("item");
231 $xml->xmlEndTag("questestinterop");
232
233 $xml = $xml->xmlDumpMem(false);
234 if (!$a_include_header) {
235 $pos = strpos($xml, "?>");
236 $xml = substr($xml, $pos + 2);
237 }
238 return $xml;
239 }
240}
sprintf('%.4f', $callTime)
An exception for terminatinating execution or to throw for unit testing.
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.
Class for question exports.
addGeneralMetadata(ilXmlWriter $xmlwriter)
addAdditionalContentEditingModeInformation(ilXmlWriter $a_xml_writer)
adds a qti meta data field for ilias specific information of "additional content editing mode" (xml w...
XML writer class.
$key
Definition: croninfo.php:18
$i
Definition: disco.tpl.php:19
const LONG_MENU_QUESTION_IDENTIFIER
$index
Definition: metadata.php:60
$xml
Definition: metadata.php:240