ILIAS  eassessment Revision 61809
 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->xmlStartTag("qtimetadatafield");
82  $a_xml_writer->xmlElement("fieldlabel", NULL, "externalID");
83  $a_xml_writer->xmlElement("fieldentry", NULL, $this->object->getExternalID());
84  $a_xml_writer->xmlEndTag("qtimetadatafield");
85  $a_xml_writer->xmlEndTag("qtimetadata");
86  $a_xml_writer->xmlEndTag("itemmetadata");
87 
88  // PART I: qti presentation
89  $attrs = array(
90  "label" => $this->object->getTitle()
91  );
92  $a_xml_writer->xmlStartTag("presentation", $attrs);
93  // add flow to presentation
94  $a_xml_writer->xmlStartTag("flow");
95  // add material with question text to presentation
96  $this->object->addQTIMaterial($a_xml_writer, $this->object->getQuestion());
97  $solution = $this->object->getSuggestedSolution(0);
98  if (count($solution))
99  {
100  if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches))
101  {
102  $a_xml_writer->xmlStartTag("material");
103  $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
104  if (strcmp($matches[1], "") != 0)
105  {
106  $intlink = $solution["internal_link"];
107  }
108  $attrs = array(
109  "label" => "suggested_solution"
110  );
111  $a_xml_writer->xmlElement("mattext", $attrs, $intlink);
112  $a_xml_writer->xmlEndTag("material");
113  }
114  }
115 
116  $a_xml_writer->xmlStartTag("material");
117  $attrs = array(
118  "label" => "applet data",
119  "uri" => $this->object->getJavaAppletFilename(),
120  "height" => $this->object->getJavaHeight(),
121  "width" => $this->object->getJavaWidth(),
122  "embedded" => "base64"
123  );
124  $javapath = $this->object->getJavaPath() . $this->object->getJavaAppletFilename();
125  $fh = @fopen($javapath, "rb");
126  if ($fh == false)
127  {
128  return;
129  }
130  $javafile = fread($fh, filesize($javapath));
131  fclose($fh);
132  $base64 = base64_encode($javafile);
133  $a_xml_writer->xmlElement("matapplet", $attrs, $base64);
134 
135  if ($this->object->buildParamsOnly())
136  {
137  if ($this->object->getJavaCode())
138  {
139  $attrs = array(
140  "label" => "java_code"
141  );
142  $a_xml_writer->xmlElement("mattext", $attrs, $this->object->getJavaCode());
143  }
144  if ($this->object->getJavaCodebase())
145  {
146  $attrs = array(
147  "label" => "java_codebase"
148  );
149  $a_xml_writer->xmlElement("mattext", $attrs, $this->object->getJavaCodebase());
150  }
151  if ($this->object->getJavaArchive())
152  {
153  $attrs = array(
154  "label" => "java_archive"
155  );
156  $a_xml_writer->xmlElement("mattext", $attrs, $this->object->getJavaArchive());
157  }
158  for ($i = 0; $i < $this->object->getParameterCount(); $i++)
159  {
160  $param = $this->object->getParameter($i);
161  $attrs = array(
162  "label" => $param["name"]
163  );
164  $a_xml_writer->xmlElement("mattext", $attrs, $param["value"]);
165  }
166  }
167  $a_xml_writer->xmlEndTag("material");
168  $a_xml_writer->xmlStartTag("material");
169  $attrs = array(
170  "label" => "points"
171  );
172  $a_xml_writer->xmlElement("mattext", $attrs, $this->object->getPoints());
173  $a_xml_writer->xmlEndTag("material");
174 
175  $a_xml_writer->xmlEndTag("flow");
176  $a_xml_writer->xmlEndTag("presentation");
177 
178  // PART II: qti resprocessing
179  $feedback_allcorrect = $this->object->getFeedbackGeneric(1);
180  $feedback_onenotcorrect = $this->object->getFeedbackGeneric(0);
181  if (strlen($feedback_allcorrect . $feedback_onenotcorrect))
182  {
183  $a_xml_writer->xmlStartTag("resprocessing");
184  $a_xml_writer->xmlStartTag("outcomes");
185  $a_xml_writer->xmlStartTag("decvar");
186  $a_xml_writer->xmlEndTag("decvar");
187  $a_xml_writer->xmlEndTag("outcomes");
188 
189  if (strlen($feedback_allcorrect))
190  {
191  $attrs = array(
192  "continue" => "Yes"
193  );
194  $a_xml_writer->xmlStartTag("respcondition", $attrs);
195  // qti conditionvar
196  $a_xml_writer->xmlStartTag("conditionvar");
197  $attrs = array(
198  "respident" => "points"
199  );
200  $a_xml_writer->xmlElement("varequal", $attrs, $this->object->getPoints());
201  $a_xml_writer->xmlEndTag("conditionvar");
202  // qti displayfeedback
203  $attrs = array(
204  "feedbacktype" => "Response",
205  "linkrefid" => "response_allcorrect"
206  );
207  $a_xml_writer->xmlElement("displayfeedback", $attrs);
208  $a_xml_writer->xmlEndTag("respcondition");
209  }
210 
211  if (strlen($feedback_onenotcorrect))
212  {
213  $attrs = array(
214  "continue" => "Yes"
215  );
216  $a_xml_writer->xmlStartTag("respcondition", $attrs);
217  // qti conditionvar
218  $a_xml_writer->xmlStartTag("conditionvar");
219  $a_xml_writer->xmlStartTag("not");
220  $attrs = array(
221  "respident" => "points"
222  );
223  $a_xml_writer->xmlElement("varequal", $attrs, $this->object->getPoints());
224  $a_xml_writer->xmlEndTag("not");
225  $a_xml_writer->xmlEndTag("conditionvar");
226  // qti displayfeedback
227  $attrs = array(
228  "feedbacktype" => "Response",
229  "linkrefid" => "response_onenotcorrect"
230  );
231  $a_xml_writer->xmlElement("displayfeedback", $attrs);
232  $a_xml_writer->xmlEndTag("respcondition");
233  }
234  $a_xml_writer->xmlEndTag("resprocessing");
235  }
236 
237  if (strlen($feedback_allcorrect))
238  {
239  $attrs = array(
240  "ident" => "response_allcorrect",
241  "view" => "All"
242  );
243  $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
244  // qti flow_mat
245  $a_xml_writer->xmlStartTag("flow_mat");
246  $this->object->addQTIMaterial($a_xml_writer, $feedback_allcorrect);
247  $a_xml_writer->xmlEndTag("flow_mat");
248  $a_xml_writer->xmlEndTag("itemfeedback");
249  }
250  if (strlen($feedback_onenotcorrect))
251  {
252  $attrs = array(
253  "ident" => "response_onenotcorrect",
254  "view" => "All"
255  );
256  $a_xml_writer->xmlStartTag("itemfeedback", $attrs);
257  // qti flow_mat
258  $a_xml_writer->xmlStartTag("flow_mat");
259  $this->object->addQTIMaterial($a_xml_writer, $feedback_onenotcorrect);
260  $a_xml_writer->xmlEndTag("flow_mat");
261  $a_xml_writer->xmlEndTag("itemfeedback");
262  }
263 
264  $a_xml_writer->xmlEndTag("item");
265  $a_xml_writer->xmlEndTag("questestinterop");
266  $xml = $a_xml_writer->xmlDumpMem(FALSE);
267  if (!$a_include_header)
268  {
269  $pos = strpos($xml, "?>");
270  $xml = substr($xml, $pos + 2);
271  }
272  return $xml;
273  }
274 }
275 
276 ?>