ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 public function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false)
27 {
28 global $DIC;
29 $ilias = $DIC['ilias'];
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, JAVAAPPLET_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
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 $solution = $this->object->getSuggestedSolution(0);
80 if (count($solution)) {
81 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches)) {
82 $a_xml_writer->xmlStartTag("material");
83 $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
84 if (strcmp($matches[1], "") != 0) {
85 $intlink = $solution["internal_link"];
86 }
87 $attrs = array(
88 "label" => "suggested_solution"
89 );
90 $a_xml_writer->xmlElement("mattext", $attrs, $intlink);
91 $a_xml_writer->xmlEndTag("material");
92 }
93 }
94
95 $a_xml_writer->xmlStartTag("material");
96 $attrs = array(
97 "label" => "applet data",
98 "uri" => $this->object->getJavaAppletFilename(),
99 "height" => $this->object->getJavaHeight(),
100 "width" => $this->object->getJavaWidth(),
101 "embedded" => "base64"
102 );
103 $javapath = $this->object->getJavaPath() . $this->object->getJavaAppletFilename();
104 $fh = @fopen($javapath, "rb");
105 if ($fh == false) {
106 return;
107 }
108 $javafile = fread($fh, filesize($javapath));
109 fclose($fh);
110 $base64 = base64_encode($javafile);
111 $a_xml_writer->xmlElement("matapplet", $attrs, $base64);
112
113 if ($this->object->buildParamsOnly()) {
114 if ($this->object->getJavaCode()) {
115 $attrs = array(
116 "label" => "java_code"
117 );
118 $a_xml_writer->xmlElement("mattext", $attrs, $this->object->getJavaCode());
119 }
120 if ($this->object->getJavaCodebase()) {
121 $attrs = array(
122 "label" => "java_codebase"
123 );
124 $a_xml_writer->xmlElement("mattext", $attrs, $this->object->getJavaCodebase());
125 }
126 if ($this->object->getJavaArchive()) {
127 $attrs = array(
128 "label" => "java_archive"
129 );
130 $a_xml_writer->xmlElement("mattext", $attrs, $this->object->getJavaArchive());
131 }
132 for ($i = 0; $i < $this->object->getParameterCount(); $i++) {
133 $param = $this->object->getParameter($i);
134 $attrs = array(
135 "label" => $param["name"]
136 );
137 $a_xml_writer->xmlElement("mattext", $attrs, $param["value"]);
138 }
139 }
140 $a_xml_writer->xmlEndTag("material");
141 $a_xml_writer->xmlStartTag("material");
142 $attrs = array(
143 "label" => "points"
144 );
145 $a_xml_writer->xmlElement("mattext", $attrs, $this->object->getPoints());
146 $a_xml_writer->xmlEndTag("material");
147
148 $a_xml_writer->xmlEndTag("flow");
149 $a_xml_writer->xmlEndTag("presentation");
150
151 // PART II: qti resprocessing
152 $feedback_allcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
153 $this->object->getId(),
154 true
155 );
156 $feedback_onenotcorrect = $this->object->feedbackOBJ->getGenericFeedbackExportPresentation(
157 $this->object->getId(),
158 false
159 );
160 if (strlen($feedback_allcorrect . $feedback_onenotcorrect)) {
161 $a_xml_writer->xmlStartTag("resprocessing");
162 $a_xml_writer->xmlStartTag("outcomes");
163 $a_xml_writer->xmlStartTag("decvar");
164 $a_xml_writer->xmlEndTag("decvar");
165 $a_xml_writer->xmlEndTag("outcomes");
166
167 if (strlen($feedback_allcorrect)) {
168 $attrs = array(
169 "continue" => "Yes"
170 );
171 $a_xml_writer->xmlStartTag("respcondition", $attrs);
172 // qti conditionvar
173 $a_xml_writer->xmlStartTag("conditionvar");
174 $attrs = array(
175 "respident" => "points"
176 );
177 $a_xml_writer->xmlElement("varequal", $attrs, $this->object->getPoints());
178 $a_xml_writer->xmlEndTag("conditionvar");
179 // qti displayfeedback
180 $attrs = array(
181 "feedbacktype" => "Response",
182 "linkrefid" => "response_allcorrect"
183 );
184 $a_xml_writer->xmlElement("displayfeedback", $attrs);
185 $a_xml_writer->xmlEndTag("respcondition");
186 }
187
188 if (strlen($feedback_onenotcorrect)) {
189 $attrs = array(
190 "continue" => "Yes"
191 );
192 $a_xml_writer->xmlStartTag("respcondition", $attrs);
193 // qti conditionvar
194 $a_xml_writer->xmlStartTag("conditionvar");
195 $a_xml_writer->xmlStartTag("not");
196 $attrs = array(
197 "respident" => "points"
198 );
199 $a_xml_writer->xmlElement("varequal", $attrs, $this->object->getPoints());
200 $a_xml_writer->xmlEndTag("not");
201 $a_xml_writer->xmlEndTag("conditionvar");
202 // qti displayfeedback
203 $attrs = array(
204 "feedbacktype" => "Response",
205 "linkrefid" => "response_onenotcorrect"
206 );
207 $a_xml_writer->xmlElement("displayfeedback", $attrs);
208 $a_xml_writer->xmlEndTag("respcondition");
209 }
210 $a_xml_writer->xmlEndTag("resprocessing");
211 }
212
213 if (strlen($feedback_allcorrect)) {
214 $attrs = array(
215 "ident" => "response_allcorrect",
216 "view" => "All"
217 );
218 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
219 // qti flow_mat
220 $a_xml_writer->xmlStartTag("flow_mat");
221 $this->object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
222 $a_xml_writer->xmlEndTag("flow_mat");
223 $a_xml_writer->xmlEndTag("itemfeedback");
224 }
225 if (strlen($feedback_onenotcorrect)) {
226 $attrs = array(
227 "ident" => "response_onenotcorrect",
228 "view" => "All"
229 );
230 $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
231 // qti flow_mat
232 $a_xml_writer->xmlStartTag("flow_mat");
233 $this->object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
234 $a_xml_writer->xmlEndTag("flow_mat");
235 $a_xml_writer->xmlEndTag("itemfeedback");
236 }
237
238 $a_xml_writer->xmlEndTag("item");
239 $a_xml_writer->xmlEndTag("questestinterop");
240 $xml = $a_xml_writer->xmlDumpMem(false);
241 if (!$a_include_header) {
242 $pos = strpos($xml, "?>");
243 $xml = substr($xml, $pos + 2);
244 }
245 return $xml;
246 }
247}
An exception for terminatinating execution or to throw for unit testing.
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
$i
Definition: metadata.php:24
$xml
Definition: metadata.php:332
$DIC
Definition: xapitoken.php:46
$param
Definition: xapitoken.php:31