ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 {
60 foreach($correct_answers as $key => $value)
61 {
62 $gap_types[] = $value[2];
63 }
64 }
65 $xml->xmlElement("fieldentry", NULL, json_encode($gap_types));
66 $xml->xmlEndTag("qtimetadatafield");
67
68 // additional content editing information
70 $this->addGeneralMetadata($xml);
71
72 $xml->xmlStartTag("qtimetadatafield");
73 $xml->xmlElement("fieldlabel", NULL, "feedback_setting");
74 $xml->xmlElement("fieldentry", NULL, $this->object->getSpecificFeedbackSetting());
75 $xml->xmlEndTag("qtimetadatafield");
76
77 $xml->xmlEndTag("qtimetadata");
78 $xml->xmlEndTag("itemmetadata");
79 $xml->xmlStartTag("presentation");
80 // add flow to presentation
81 $xml->xmlStartTag("flow");
82
83
84 $this->object->addQTIMaterial($xml, $this->object->getQuestion());
85 $this->object->addQTIMaterial($xml, $this->object->getLongMenuTextValue());
86
87 foreach($answers as $key => $values)
88 {
89 $real_id = $key +1;
90 $attrs = array(
91 "ident" => "LongMenu_" . $real_id,
92 "rcardinality" => "Single"
93 );
94 $xml->xmlStartTag("response_str", $attrs);
95 foreach($values as $index => $value)
96 {
97 $xml->xmlStartTag("response_label", array('ident' => $index));
98 $xml->xmlStartTag("material");
99 $xml->xmlElement("fieldentry", NULL, $value);
100 $xml->xmlEndTag("material");
101 $xml->xmlEndTag("response_label");
102 }
103 $xml->xmlEndTag("response_str");
104 }
105 $xml->xmlEndTag("flow");
106 $xml->xmlEndTag("presentation");
107
108 $xml->xmlStartTag("resprocessing");
109 $xml->xmlStartTag("outcomes");
110 $xml->xmlElement("decvar");
111 $xml->xmlEndTag("outcomes");
112 foreach($answers as $key => $values)
113 {
114 $real_id = $key + 1;
115 foreach($values as $index => $value)
116 {
117 $xml->xmlStartTag("respcondition", array('continue' => 'Yes'));
118 $xml->xmlStartTag("conditionvar");
119 $xml->xmlElement("varequal", array('respident' => "LongMenu_" . $real_id) ,$value);
120 $xml->xmlEndTag("conditionvar");
121
122 if(in_array($value, $correct_answers[$key][0]))
123 {
124 $xml->xmlElement("setvar", array('action' => "Add"), $correct_answers[$key][1]);
125 }
126 else
127 {
128 $xml->xmlElement("setvar", array('action' => "Add"), 0);
129 }
130 $xml->xmlElement("displayfeedback", array('feedbacktype' => "Response", 'linkrefid' => $key . '_Response_' . $index));
131 $xml->xmlEndTag("respcondition");
132 }
133 }
134 $feedback_allcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
135 $this->object->getId(), true
136 );
137 if(strlen($feedback_allcorrect) > 0)
138 {
139 $xml->xmlStartTag("respcondition", array('continue' => 'Yes'));
140 $xml->xmlStartTag("conditionvar");
141 foreach($correct_answers as $key => $values)
142 {
143 $real_id = $key + 1;
144 if($key > 0)
145 {
146 $xml->xmlStartTag("and");
147 }
148
149 foreach($values[0] as $index => $value)
150 {
151 if($index > 0)
152 {
153 $xml->xmlStartTag("or");
154 }
155 $xml->xmlElement("varequal", array('respident' => "LongMenu_" . $real_id), $value);
156 if($index > 0)
157 {
158 $xml->xmlEndTag("or");
159 }
160 }
161 if($key > 0)
162 {
163 $xml->xmlEndTag("and");
164 }
165 }
166 $xml->xmlEndTag("conditionvar");
167 $xml->xmlElement("displayfeedback", array('feedbacktype' => "Response", 'linkrefid' => 'response_allcorrect'));
168 $xml->xmlEndTag("respcondition");
169 }
170
171 $feedback_onenotcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
172 $this->object->getId(), false
173 );
174 if (strlen($feedback_onenotcorrect))
175 {
176 $xml->xmlStartTag("respcondition", array('continue' => 'Yes'));
177 $xml->xmlStartTag("conditionvar");
178 $xml->xmlStartTag("not");
179 foreach($correct_answers as $key => $values)
180 {
181 $real_id = $key + 1;
182 if($key > 0)
183 {
184 $xml->xmlStartTag("and");
185 }
186
187 foreach($values[0] as $index => $value)
188 {
189 if($index > 0)
190 {
191 $xml->xmlStartTag("or");
192 }
193 $xml->xmlElement("varequal", array('respident' => "LongMenu_" . $real_id), $value);
194 if($index > 0)
195 {
196 $xml->xmlEndTag("or");
197 }
198 }
199 if($key > 0)
200 {
201 $xml->xmlEndTag("and");
202 }
203 }
204 $xml->xmlEndTag("not");
205 $xml->xmlEndTag("conditionvar");
206 $xml->xmlElement("displayfeedback", array('feedbacktype' => "Response", 'linkrefid' => 'response_onenotcorrect'));
207 $xml->xmlEndTag("respcondition");
208 }
209
210 $xml->xmlEndTag("resprocessing");
211
212
213
214
215 for ($i = 0; $i < sizeof($correct_answers); $i++)
216 {
217
218 $attrs = array(
219 "ident" => $i,
220 "view" => "All"
221 );
222 $xml->xmlStartTag("itemfeedback", $attrs);
223 // qti flow_mat
224 $xml->xmlStartTag("flow_mat");
225 $fb = $this->object->feedbackOBJ->getSpecificAnswerFeedbackExportPresentation(
226 $this->object->getId(), $i
227 );
228 $this->object->addQTIMaterial($xml, $fb);
229 $xml->xmlEndTag("flow_mat");
230 $xml->xmlEndTag("itemfeedback");
231 }
232
233 if(strlen($feedback_allcorrect) > 0)
234 {
235 $xml->xmlStartTag("itemfeedback", array('ident' => 'response_allcorrect','view' => 'All'));
236 $xml->xmlStartTag("flow_mat");
237 $xml->xmlStartTag("material");
238 $xml->xmlElement("mattext", array('texttype' => 'text/xhtml'), $feedback_allcorrect);
239 $xml->xmlEndTag("material");
240 $xml->xmlEndTag("flow_mat");
241 $xml->xmlEndTag("itemfeedback");
242 }
243 if(strlen($feedback_onenotcorrect) > 0)
244 {
245 $xml->xmlStartTag("itemfeedback", array('ident' => 'response_onenotcorrect', 'view' => 'All'));
246 $xml->xmlStartTag("flow_mat");
247 $xml->xmlStartTag("material");
248 $xml->xmlElement("mattext", array('texttype' => 'text/xhtml'), $feedback_onenotcorrect);
249 $xml->xmlEndTag("material");
250 $xml->xmlEndTag("flow_mat");
251 $xml->xmlEndTag("itemfeedback");
252 }
253
254 $xml->xmlEndTag("item");
255$xml->xmlEndTag("questestinterop");
256
257 $xml = $xml->xmlDumpMem(FALSE);
258 if (!$a_include_header)
259 {
260 $pos = strpos($xml, "?>");
261 $xml = substr($xml, $pos + 2);
262 }
263 return $xml;
264 }
265}
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.
xmlHeader()
Writes xml header @access public.
const LONG_MENU_QUESTION_IDENTIFIER