ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.assJavaAppletExport.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once "./Modules/TestQuestionPool/classes/export/qti12/class.assQuestionExport.php";
5
16{
26 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 include_once("./Services/Xml/classes/class.ilXmlWriter.php");
30 $a_xml_writer = new ilXmlWriter;
31 // set xml header
32 $a_xml_writer->xmlHeader();
33 $a_xml_writer->xmlStartTag("questestinterop");
34 $attrs = array(
35 "ident" => "il_".IL_INST_ID."_qst_".$this->object->getId(),
36 "title" => $this->object->getTitle(),
37 "maxattempts" => $this->object->getNrOfTries()
38 );
39 $a_xml_writer->xmlStartTag("item", $attrs);
40 // add question description
41 $a_xml_writer->xmlElement("qticomment", NULL, $this->object->getComment());
42 // add estimated working time
43 $workingtime = $this->object->getEstimatedWorkingTime();
44 $duration = sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]);
45 $a_xml_writer->xmlElement("duration", NULL, $duration);
46 // add ILIAS specific metadata
47 $a_xml_writer->xmlStartTag("itemmetadata");
48 $a_xml_writer->xmlStartTag("qtimetadata");
49 $a_xml_writer->xmlStartTag("qtimetadatafield");
50 $a_xml_writer->xmlElement("fieldlabel", NULL, "ILIAS_VERSION");
51 $a_xml_writer->xmlElement("fieldentry", NULL, $ilias->getSetting("ilias_version"));
52 $a_xml_writer->xmlEndTag("qtimetadatafield");
53 $a_xml_writer->xmlStartTag("qtimetadatafield");
54 $a_xml_writer->xmlElement("fieldlabel", NULL, "QUESTIONTYPE");
55 $a_xml_writer->xmlElement("fieldentry", NULL, JAVAAPPLET_QUESTION_IDENTIFIER);
56 $a_xml_writer->xmlEndTag("qtimetadatafield");
57 $a_xml_writer->xmlStartTag("qtimetadatafield");
58 $a_xml_writer->xmlElement("fieldlabel", NULL, "AUTHOR");
59 $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getAuthor());
60 $a_xml_writer->xmlEndTag("qtimetadatafield");
61
62 // additional content editing information
64 $this->addGeneralMetadata($a_xml_writer);
65
66 $a_xml_writer->xmlEndTag("qtimetadata");
67 $a_xml_writer->xmlEndTag("itemmetadata");
68
69 // PART I: qti presentation
70 $attrs = array(
71 "label" => $this->object->getTitle()
72 );
73 $a_xml_writer->xmlStartTag("presentation", $attrs);
74 // add flow to presentation
75 $a_xml_writer->xmlStartTag("flow");
76 // add material with question text to presentation
77 $this->object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
78 $solution = $this->object->getSuggestedSolution(0);
79 if (count($solution))
80 {
81 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches))
82 {
83 $a_xml_writer->xmlStartTag("material");
84 $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
85 if (strcmp($matches[1], "") != 0)
86 {
87 $intlink = $solution["internal_link"];
88 }
89 $attrs = array(
90 "label" => "suggested_solution"
91 );
92 $a_xml_writer->xmlElement("mattext", $attrs, $intlink);
93 $a_xml_writer->xmlEndTag("material");
94 }
95 }
96
97 $a_xml_writer->xmlStartTag("material");
98 $attrs = array(
99 "label" => "applet data",
100 "uri" => $this->object->getJavaAppletFilename(),
101 "height" => $this->object->getJavaHeight(),
102 "width" => $this->object->getJavaWidth(),
103 "embedded" => "base64"
104 );
105 $javapath = $this->object->getJavaPath() . $this->object->getJavaAppletFilename();
106 $fh = @fopen($javapath, "rb");
107 if ($fh == false)
108 {
109 return;
110 }
111 $javafile = fread($fh, filesize($javapath));
112 fclose($fh);
113 $base64 = base64_encode($javafile);
114 $a_xml_writer->xmlElement("matapplet", $attrs, $base64);
115
116 if ($this->object->buildParamsOnly())
117 {
118 if ($this->object->getJavaCode())
119 {
120 $attrs = array(
121 "label" => "java_code"
122 );
123 $a_xml_writer->xmlElement("mattext", $attrs, $this->object->getJavaCode());
124 }
125 if ($this->object->getJavaCodebase())
126 {
127 $attrs = array(
128 "label" => "java_codebase"
129 );
130 $a_xml_writer->xmlElement("mattext", $attrs, $this->object->getJavaCodebase());
131 }
132 if ($this->object->getJavaArchive())
133 {
134 $attrs = array(
135 "label" => "java_archive"
136 );
137 $a_xml_writer->xmlElement("mattext", $attrs, $this->object->getJavaArchive());
138 }
139 for ($i = 0; $i < $this->object->getParameterCount(); $i++)
140 {
141 $param = $this->object->getParameter($i);
142 $attrs = array(
143 "label" => $param["name"]
144 );
145 $a_xml_writer->xmlElement("mattext", $attrs, $param["value"]);
146 }
147 }
148 $a_xml_writer->xmlEndTag("material");
149 $a_xml_writer->xmlStartTag("material");
150 $attrs = array(
151 "label" => "points"
152 );
153 $a_xml_writer->xmlElement("mattext", $attrs, $this->object->getPoints());
154 $a_xml_writer->xmlEndTag("material");
155
156 $a_xml_writer->xmlEndTag("flow");
157 $a_xml_writer->xmlEndTag("presentation");
158
159 // PART II: qti resprocessing
160 $feedback_allcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
161 $this->object->getId(), true
162 );
163 $feedback_onenotcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
164 $this->object->getId(), false
165 );
166 if (strlen($feedback_allcorrect . $feedback_onenotcorrect))
167 {
168 $a_xml_writer->xmlStartTag("resprocessing");
169 $a_xml_writer->xmlStartTag("outcomes");
170 $a_xml_writer->xmlStartTag("decvar");
171 $a_xml_writer->xmlEndTag("decvar");
172 $a_xml_writer->xmlEndTag("outcomes");
173
174 if (strlen($feedback_allcorrect))
175 {
176 $attrs = array(
177 "continue" => "Yes"
178 );
179 $a_xml_writer->xmlStartTag("respcondition", $attrs);
180 // qti conditionvar
181 $a_xml_writer->xmlStartTag("conditionvar");
182 $attrs = array(
183 "respident" => "points"
184 );
185 $a_xml_writer->xmlElement("varequal", $attrs, $this->object->getPoints());
186 $a_xml_writer->xmlEndTag("conditionvar");
187 // qti displayfeedback
188 $attrs = array(
189 "feedbacktype" => "Response",
190 "linkrefid" => "response_allcorrect"
191 );
192 $a_xml_writer->xmlElement("displayfeedback", $attrs);
193 $a_xml_writer->xmlEndTag("respcondition");
194 }
195
196 if (strlen($feedback_onenotcorrect))
197 {
198 $attrs = array(
199 "continue" => "Yes"
200 );
201 $a_xml_writer->xmlStartTag("respcondition", $attrs);
202 // qti conditionvar
203 $a_xml_writer->xmlStartTag("conditionvar");
204 $a_xml_writer->xmlStartTag("not");
205 $attrs = array(
206 "respident" => "points"
207 );
208 $a_xml_writer->xmlElement("varequal", $attrs, $this->object->getPoints());
209 $a_xml_writer->xmlEndTag("not");
210 $a_xml_writer->xmlEndTag("conditionvar");
211 // qti displayfeedback
212 $attrs = array(
213 "feedbacktype" => "Response",
214 "linkrefid" => "response_onenotcorrect"
215 );
216 $a_xml_writer->xmlElement("displayfeedback", $attrs);
217 $a_xml_writer->xmlEndTag("respcondition");
218 }
219 $a_xml_writer->xmlEndTag("resprocessing");
220 }
221
222 if (strlen($feedback_allcorrect))
223 {
224 $attrs = array(
225 "ident" => "response_allcorrect",
226 "view" => "All"
227 );
228 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
229 // qti flow_mat
230 $a_xml_writer->xmlStartTag("flow_mat");
231 $this->object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
232 $a_xml_writer->xmlEndTag("flow_mat");
233 $a_xml_writer->xmlEndTag("itemfeedback");
234 }
235 if (strlen($feedback_onenotcorrect))
236 {
237 $attrs = array(
238 "ident" => "response_onenotcorrect",
239 "view" => "All"
240 );
241 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
242 // qti flow_mat
243 $a_xml_writer->xmlStartTag("flow_mat");
244 $this->object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
245 $a_xml_writer->xmlEndTag("flow_mat");
246 $a_xml_writer->xmlEndTag("itemfeedback");
247 }
248
249 $a_xml_writer->xmlEndTag("item");
250 $a_xml_writer->xmlEndTag("questestinterop");
251 $xml = $a_xml_writer->xmlDumpMem(FALSE);
252 if (!$a_include_header)
253 {
254 $pos = strpos($xml, "?>");
255 $xml = substr($xml, $pos + 2);
256 }
257 return $xml;
258 }
259}
260
261?>
Class for java applet question exports.
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 JAVAAPPLET_QUESTION_IDENTIFIER