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