ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assJavaAppletImport.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/import/qti12/class.assQuestionImport.php";
25 
36 {
50  function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
51  {
52  global $ilUser;
53 
54  // empty session variable for imported xhtml mobs
55  unset($_SESSION["import_mob_xhtml"]);
56  $presentation = $item->getPresentation();
57  $duration = $item->getDuration();
58  $now = getdate();
59  $applet = NULL;
60  $maxpoints = 0;
61  $javacode = "";
62  $javacodebase = "";
63  $javaarchive = "";
64  $params = array();
65  $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
66  $answers = array();
67  foreach ($presentation->order as $entry)
68  {
69  switch ($entry["type"])
70  {
71  case "material":
72  $material = $presentation->material[$entry["index"]];
73  for ($i = 0; $i < $material->getMaterialCount(); $i++)
74  {
75  $mat = $material->getMaterial($i);
76  if (strcmp($mat["type"], "mattext") == 0)
77  {
78  $mattext = $mat["material"];
79  if ((strlen($mattext->getLabel()) == 0) && (strlen($this->object->QTIMaterialToString($item->getQuestiontext())) == 0))
80  {
81  $item->setQuestiontext($mattext->getContent());
82  }
83  if (strcmp($mattext->getLabel(), "points") == 0)
84  {
85  $maxpoints = $mattext->getContent();
86  }
87  else if (strcmp($mattext->getLabel(), "java_code") == 0)
88  {
89  $javacode = $mattext->getContent();
90  }
91  else if (strcmp($mattext->getLabel(), "java_codebase") == 0)
92  {
93  $javacodebase = $mattext->getContent();
94  }
95  else if (strcmp($mattext->getLabel(), "java_archive") == 0)
96  {
97  $javaarchive = $mattext->getContent();
98  }
99  else if (strlen($mattext->getLabel()) > 0)
100  {
101  array_push($params, array("key" => $mattext->getLabel(), "value" => $mattext->getContent()));
102  }
103  }
104  elseif (strcmp($mat["type"], "matapplet") == 0)
105  {
106  $applet = $mat["material"];
107  }
108  }
109  break;
110  }
111  }
112 
113  $feedbacksgeneric = array();
114  foreach ($item->resprocessing as $resprocessing)
115  {
116  foreach ($resprocessing->respcondition as $respcondition)
117  {
118  foreach ($respcondition->displayfeedback as $feedbackpointer)
119  {
120  if (strlen($feedbackpointer->getLinkrefid()))
121  {
122  foreach ($item->itemfeedback as $ifb)
123  {
124  if (strcmp($ifb->getIdent(), "response_allcorrect") == 0)
125  {
126  // found a feedback for the identifier
127  if (count($ifb->material))
128  {
129  foreach ($ifb->material as $material)
130  {
131  $feedbacksgeneric[1] = $material;
132  }
133  }
134  if ((count($ifb->flow_mat) > 0))
135  {
136  foreach ($ifb->flow_mat as $fmat)
137  {
138  if (count($fmat->material))
139  {
140  foreach ($fmat->material as $material)
141  {
142  $feedbacksgeneric[1] = $material;
143  }
144  }
145  }
146  }
147  }
148  else if (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0)
149  {
150  // found a feedback for the identifier
151  if (count($ifb->material))
152  {
153  foreach ($ifb->material as $material)
154  {
155  $feedbacksgeneric[0] = $material;
156  }
157  }
158  if ((count($ifb->flow_mat) > 0))
159  {
160  foreach ($ifb->flow_mat as $fmat)
161  {
162  if (count($fmat->material))
163  {
164  foreach ($fmat->material as $material)
165  {
166  $feedbacksgeneric[0] = $material;
167  }
168  }
169  }
170  }
171  }
172  }
173  }
174  }
175  }
176  }
177 
178  $this->object->setTitle($item->getTitle());
179  $this->object->setExternalID($item->getMetadataEntry("externalID"));
180  $this->object->setNrOfTries($item->getMaxattempts());
181  $this->object->setComment($item->getComment());
182  $this->object->setAuthor($item->getAuthor());
183  $this->object->setOwner($ilUser->getId());
184  $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
185  $this->object->setObjId($questionpool_id);
186  $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
187  $this->object->setJavaAppletFilename($applet->getUri());
188  $this->object->setJavaWidth($applet->getWidth());
189  $this->object->setJavaHeight($applet->getHeight());
190  $this->object->setJavaCode($javacode);
191  $this->object->setJavaCodebase($javacodebase);
192  $this->object->setJavaArchive($javaarchive);
193  $this->object->setPoints($maxpoints);
194  foreach ($params as $pair)
195  {
196  $this->object->addParameter($pair["key"], $pair["value"]);
197  }
198  $this->object->saveToDb();
199  if (count($item->suggested_solutions))
200  {
201  foreach ($item->suggested_solutions as $suggested_solution)
202  {
203  $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
204  }
205  $this->object->saveToDb();
206  }
207  $javaapplet =& base64_decode($applet->getContent());
208  $javapath = $this->object->getJavaPath();
209  if (!file_exists($javapath))
210  {
211  include_once "./Services/Utilities/classes/class.ilUtil.php";
212  ilUtil::makeDirParents($javapath);
213  }
214  $javapath .= $this->object->getJavaAppletFilename();
215  $fh = fopen($javapath, "wb");
216  if ($fh == false)
217  {
218 // global $ilErr;
219 // $ilErr->raiseError($this->object->lng->txt("error_save_image_file") . ": $php_errormsg", $ilErr->MESSAGE);
220 // return;
221  }
222  else
223  {
224  $javafile = fwrite($fh, $javaapplet);
225  fclose($fh);
226  }
227  // handle the import of media objects in XHTML code
228  foreach ($feedbacksgeneric as $correctness => $material)
229  {
230  $m = $this->object->QTIMaterialToString($material);
231  $feedbacksgeneric[$correctness] = $m;
232  }
233  $questiontext = $this->object->getQuestion();
234  if (is_array($_SESSION["import_mob_xhtml"]))
235  {
236  include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
237  include_once "./Services/RTE/classes/class.ilRTE.php";
238  foreach ($_SESSION["import_mob_xhtml"] as $mob)
239  {
240  if ($tst_id > 0)
241  {
242  include_once "./Modules/Test/classes/class.ilObjTest.php";
243  $importfile = ilObjTest::_getImportDirectory() . "/" . $mob["uri"];
244  }
245  else
246  {
247  include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
248  $importfile = ilObjQuestionPool::_getImportDirectory() . "/" . $_SESSION["qpl_import_subdir"] . "/" . $mob["uri"];
249  }
250  $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
251  ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
252  $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
253  foreach ($feedbacksgeneric as $correctness => $material)
254  {
255  $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
256  }
257  }
258  }
259  $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
260  foreach ($feedbacksgeneric as $correctness => $material)
261  {
262  $this->object->saveFeedbackGeneric($correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1));
263  }
264  $this->object->saveToDb();
265  if ($tst_id > 0)
266  {
267  $q_1_id = $this->object->getId();
268  $question_id = $this->object->duplicate(true);
269  $tst_object->questions[$question_counter++] = $question_id;
270  $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
271  }
272  else
273  {
274  $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
275  }
276  }
277 }
278 
279 ?>