ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assJavaAppletExport.php
Go to the documentation of this file.
1 <?php
2  /*
3  +----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +----------------------------------------------------------------------------+
22 */
23 
24 include_once "./Modules/TestQuestionPool/classes/export/qti12/class.assQuestionExport.php";
25 
36 {
46  function toXML($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false)
47  {
48  global $ilias;
49  include_once("./Services/Xml/classes/class.ilXmlWriter.php");
50  $a_xml_writer = new ilXmlWriter;
51  // set xml header
52  $a_xml_writer->xmlHeader();
53  $a_xml_writer->xmlStartTag("questestinterop");
54  $attrs = array(
55  "ident" => "il_".IL_INST_ID."_qst_".$this->object->getId(),
56  "title" => $this->object->getTitle(),
57  "maxattempts" => $this->object->getNrOfTries()
58  );
59  $a_xml_writer->xmlStartTag("item", $attrs);
60  // add question description
61  $a_xml_writer->xmlElement("qticomment", NULL, $this->object->getComment());
62  // add estimated working time
63  $workingtime = $this->object->getEstimatedWorkingTime();
64  $duration = sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]);
65  $a_xml_writer->xmlElement("duration", NULL, $duration);
66  // add ILIAS specific metadata
67  $a_xml_writer->xmlStartTag("itemmetadata");
68  $a_xml_writer->xmlStartTag("qtimetadata");
69  $a_xml_writer->xmlStartTag("qtimetadatafield");
70  $a_xml_writer->xmlElement("fieldlabel", NULL, "ILIAS_VERSION");
71  $a_xml_writer->xmlElement("fieldentry", NULL, $ilias->getSetting("ilias_version"));
72  $a_xml_writer->xmlEndTag("qtimetadatafield");
73  $a_xml_writer->xmlStartTag("qtimetadatafield");
74  $a_xml_writer->xmlElement("fieldlabel", NULL, "QUESTIONTYPE");
75  $a_xml_writer->xmlElement("fieldentry", NULL, JAVAAPPLET_QUESTION_IDENTIFIER);
76  $a_xml_writer->xmlEndTag("qtimetadatafield");
77  $a_xml_writer->xmlStartTag("qtimetadatafield");
78  $a_xml_writer->xmlElement("fieldlabel", NULL, "AUTHOR");
79  $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getAuthor());
80  $a_xml_writer->xmlEndTag("qtimetadatafield");
81  $a_xml_writer->xmlEndTag("qtimetadata");
82  $a_xml_writer->xmlEndTag("itemmetadata");
83 
84  // PART I: qti presentation
85  $attrs = array(
86  "label" => $this->object->getTitle()
87  );
88  $a_xml_writer->xmlStartTag("presentation", $attrs);
89  // add flow to presentation
90  $a_xml_writer->xmlStartTag("flow");
91  // add material with question text to presentation
92  $this->object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
93  $solution = $this->object->getSuggestedSolution(0);
94  if (count($solution))
95  {
96  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches))
97  {
98  $a_xml_writer->xmlStartTag("material");
99  $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
100  if (strcmp($matches[1], "") != 0)
101  {
102  $intlink = $solution["internal_link"];
103  }
104  $attrs = array(
105  "label" => "suggested_solution"
106  );
107  $a_xml_writer->xmlElement("mattext", $attrs, $intlink);
108  $a_xml_writer->xmlEndTag("material");
109  }
110  }
111 
112  $a_xml_writer->xmlStartTag("material");
113  $attrs = array(
114  "label" => "applet data",
115  "uri" => $this->object->getJavaAppletFilename(),
116  "height" => $this->object->getJavaHeight(),
117  "width" => $this->object->getJavaWidth(),
118  "embedded" => "base64"
119  );
120  $javapath = $this->object->getJavaPath() . $this->object->getJavaAppletFilename();
121  $fh = @fopen($javapath, "rb");
122  if ($fh == false)
123  {
124  return;
125  }
126  $javafile = fread($fh, filesize($javapath));
127  fclose($fh);
128  $base64 = base64_encode($javafile);
129  $a_xml_writer->xmlElement("matapplet", $attrs, $base64);
130 
131  if ($this->object->buildParamsOnly())
132  {
133  if ($this->object->getJavaCode())
134  {
135  $attrs = array(
136  "label" => "java_code"
137  );
138  $a_xml_writer->xmlElement("mattext", $attrs, $this->object->getJavaCode());
139  }
140  if ($this->object->getJavaCodebase())
141  {
142  $attrs = array(
143  "label" => "java_codebase"
144  );
145  $a_xml_writer->xmlElement("mattext", $attrs, $this->object->getJavaCodebase());
146  }
147  if ($this->object->getJavaArchive())
148  {
149  $attrs = array(
150  "label" => "java_archive"
151  );
152  $a_xml_writer->xmlElement("mattext", $attrs, $this->object->getJavaArchive());
153  }
154  for ($i = 0; $i < $this->object->getParameterCount(); $i++)
155  {
156  $param = $this->object->getParameter($i);
157  $attrs = array(
158  "label" => $param["name"]
159  );
160  $a_xml_writer->xmlElement("mattext", $attrs, $param["value"]);
161  }
162  }
163  $a_xml_writer->xmlEndTag("material");
164  $a_xml_writer->xmlStartTag("material");
165  $attrs = array(
166  "label" => "points"
167  );
168  $a_xml_writer->xmlElement("mattext", $attrs, $this->object->getPoints());
169  $a_xml_writer->xmlEndTag("material");
170 
171  $a_xml_writer->xmlEndTag("flow");
172  $a_xml_writer->xmlEndTag("presentation");
173 
174  // PART II: qti resprocessing
175  $feedback_allcorrect = $this->object->getFeedbackGeneric(1);
176  $feedback_onenotcorrect = $this->object->getFeedbackGeneric(0);
177  if (strlen($feedback_allcorrect . $feedback_onenotcorrect))
178  {
179  $a_xml_writer->xmlStartTag("resprocessing");
180  $a_xml_writer->xmlStartTag("outcomes");
181  $a_xml_writer->xmlStartTag("decvar");
182  $a_xml_writer->xmlEndTag("decvar");
183  $a_xml_writer->xmlEndTag("outcomes");
184 
185  if (strlen($feedback_allcorrect))
186  {
187  $attrs = array(
188  "continue" => "Yes"
189  );
190  $a_xml_writer->xmlStartTag("respcondition", $attrs);
191  // qti conditionvar
192  $a_xml_writer->xmlStartTag("conditionvar");
193  $attrs = array(
194  "respident" => "points"
195  );
196  $a_xml_writer->xmlElement("varequal", $attrs, $this->object->getPoints());
197  $a_xml_writer->xmlEndTag("conditionvar");
198  // qti displayfeedback
199  $attrs = array(
200  "feedbacktype" => "Response",
201  "linkrefid" => "response_allcorrect"
202  );
203  $a_xml_writer->xmlElement("displayfeedback", $attrs);
204  $a_xml_writer->xmlEndTag("respcondition");
205  }
206 
207  if (strlen($feedback_onenotcorrect))
208  {
209  $attrs = array(
210  "continue" => "Yes"
211  );
212  $a_xml_writer->xmlStartTag("respcondition", $attrs);
213  // qti conditionvar
214  $a_xml_writer->xmlStartTag("conditionvar");
215  $a_xml_writer->xmlStartTag("not");
216  $attrs = array(
217  "respident" => "points"
218  );
219  $a_xml_writer->xmlElement("varequal", $attrs, $this->object->getPoints());
220  $a_xml_writer->xmlEndTag("not");
221  $a_xml_writer->xmlEndTag("conditionvar");
222  // qti displayfeedback
223  $attrs = array(
224  "feedbacktype" => "Response",
225  "linkrefid" => "response_onenotcorrect"
226  );
227  $a_xml_writer->xmlElement("displayfeedback", $attrs);
228  $a_xml_writer->xmlEndTag("respcondition");
229  }
230  $a_xml_writer->xmlEndTag("resprocessing");
231  }
232 
233  if (strlen($feedback_allcorrect))
234  {
235  $attrs = array(
236  "ident" => "response_allcorrect",
237  "view" => "All"
238  );
239  $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
240  // qti flow_mat
241  $a_xml_writer->xmlStartTag("flow_mat");
242  $this->object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
243  $a_xml_writer->xmlEndTag("flow_mat");
244  $a_xml_writer->xmlEndTag("itemfeedback");
245  }
246  if (strlen($feedback_onenotcorrect))
247  {
248  $attrs = array(
249  "ident" => "response_onenotcorrect",
250  "view" => "All"
251  );
252  $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
253  // qti flow_mat
254  $a_xml_writer->xmlStartTag("flow_mat");
255  $this->object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
256  $a_xml_writer->xmlEndTag("flow_mat");
257  $a_xml_writer->xmlEndTag("itemfeedback");
258  }
259 
260  $a_xml_writer->xmlEndTag("item");
261  $a_xml_writer->xmlEndTag("questestinterop");
262  $xml = $a_xml_writer->xmlDumpMem(FALSE);
263  if (!$a_include_header)
264  {
265  $pos = strpos($xml, "?>");
266  $xml = substr($xml, $pos + 2);
267  }
268  return $xml;
269  }
270 }
271 
272 ?>