ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.assJavaAppletImport.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once "./Modules/TestQuestionPool/classes/import/qti12/class.assQuestionImport.php";
5 
16 {
30  public function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
31  {
32  global $DIC;
33  $ilUser = $DIC['ilUser'];
34 
35  // empty session variable for imported xhtml mobs
36  unset($_SESSION["import_mob_xhtml"]);
37  $presentation = $item->getPresentation();
38  $duration = $item->getDuration();
39  $now = getdate();
40  $applet = null;
41  $maxpoints = 0;
42  $javacode = "";
43  $javacodebase = "";
44  $javaarchive = "";
45  $params = array();
46  $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
47  $answers = array();
48  foreach ($presentation->order as $entry) {
49  switch ($entry["type"]) {
50  case "material":
51  $material = $presentation->material[$entry["index"]];
52  for ($i = 0; $i < $material->getMaterialCount(); $i++) {
53  $mat = $material->getMaterial($i);
54  if (strcmp($mat["type"], "mattext") == 0) {
55  $mattext = $mat["material"];
56  if ((strlen($mattext->getLabel()) == 0) && (strlen($this->object->QTIMaterialToString($item->getQuestiontext())) == 0)) {
57  $item->setQuestiontext($mattext->getContent());
58  }
59  if (strcmp($mattext->getLabel(), "points") == 0) {
60  $maxpoints = $mattext->getContent();
61  } elseif (strcmp($mattext->getLabel(), "java_code") == 0) {
62  $javacode = $mattext->getContent();
63  } elseif (strcmp($mattext->getLabel(), "java_codebase") == 0) {
64  $javacodebase = $mattext->getContent();
65  } elseif (strcmp($mattext->getLabel(), "java_archive") == 0) {
66  $javaarchive = $mattext->getContent();
67  } elseif (strlen($mattext->getLabel()) > 0) {
68  array_push($params, array("key" => $mattext->getLabel(), "value" => $mattext->getContent()));
69  }
70  } elseif (strcmp($mat["type"], "matapplet") == 0) {
71  $applet = $mat["material"];
72  }
73  }
74  break;
75  }
76  }
77 
78  $feedbacksgeneric = array();
79  foreach ($item->resprocessing as $resprocessing) {
80  foreach ($resprocessing->respcondition as $respcondition) {
81  foreach ($respcondition->displayfeedback as $feedbackpointer) {
82  if (strlen($feedbackpointer->getLinkrefid())) {
83  foreach ($item->itemfeedback as $ifb) {
84  if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
85  // found a feedback for the identifier
86  if (count($ifb->material)) {
87  foreach ($ifb->material as $material) {
88  $feedbacksgeneric[1] = $material;
89  }
90  }
91  if ((count($ifb->flow_mat) > 0)) {
92  foreach ($ifb->flow_mat as $fmat) {
93  if (count($fmat->material)) {
94  foreach ($fmat->material as $material) {
95  $feedbacksgeneric[1] = $material;
96  }
97  }
98  }
99  }
100  } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
101  // found a feedback for the identifier
102  if (count($ifb->material)) {
103  foreach ($ifb->material as $material) {
104  $feedbacksgeneric[0] = $material;
105  }
106  }
107  if ((count($ifb->flow_mat) > 0)) {
108  foreach ($ifb->flow_mat as $fmat) {
109  if (count($fmat->material)) {
110  foreach ($fmat->material as $material) {
111  $feedbacksgeneric[0] = $material;
112  }
113  }
114  }
115  }
116  }
117  }
118  }
119  }
120  }
121  }
122 
123  $this->addGeneralMetadata($item);
124  $this->object->setTitle($item->getTitle());
125  $this->object->setNrOfTries($item->getMaxattempts());
126  $this->object->setComment($item->getComment());
127  $this->object->setAuthor($item->getAuthor());
128  $this->object->setOwner($ilUser->getId());
129  $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
130  $this->object->setObjId($questionpool_id);
131  $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
132  $this->object->setJavaAppletFilename($applet->getUri());
133  $this->object->setJavaWidth($applet->getWidth());
134  $this->object->setJavaHeight($applet->getHeight());
135  $this->object->setJavaCode($javacode);
136  $this->object->setJavaCodebase($javacodebase);
137  $this->object->setJavaArchive($javaarchive);
138  $this->object->setPoints($maxpoints);
139  foreach ($params as $pair) {
140  $this->object->addParameter($pair["key"], $pair["value"]);
141  }
142  // additional content editing mode information
143  $this->object->setAdditionalContentEditingMode(
145  );
146  $this->object->saveToDb();
147  if (count($item->suggested_solutions)) {
148  foreach ($item->suggested_solutions as $suggested_solution) {
149  $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
150  }
151  $this->object->saveToDb();
152  }
153  $javaapplet = &base64_decode($applet->getContent());
154  $javapath = $this->object->getJavaPath();
155  if (!file_exists($javapath)) {
156  include_once "./Services/Utilities/classes/class.ilUtil.php";
157  ilUtil::makeDirParents($javapath);
158  }
159  $javapath .= $this->object->getJavaAppletFilename();
160  $fh = fopen($javapath, "wb");
161  if ($fh == false) {
162  // global $DIC;
163 // $ilErr = $DIC['ilErr'];
164 // $ilErr->raiseError($this->object->lng->txt("error_save_image_file") . ": $php_errormsg", $ilErr->MESSAGE);
165 // return;
166  } else {
167  $javafile = fwrite($fh, $javaapplet);
168  fclose($fh);
169  }
170  // handle the import of media objects in XHTML code
171  foreach ($feedbacksgeneric as $correctness => $material) {
172  $m = $this->object->QTIMaterialToString($material);
173  $feedbacksgeneric[$correctness] = $m;
174  }
175  $questiontext = $this->object->getQuestion();
176  if (is_array($_SESSION["import_mob_xhtml"])) {
177  include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
178  include_once "./Services/RTE/classes/class.ilRTE.php";
179  foreach ($_SESSION["import_mob_xhtml"] as $mob) {
180  if ($tst_id > 0) {
181  $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
182  } else {
183  $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
184  }
185 
186  global $DIC; /* @var ILIAS\DI\Container $DIC */
187  $DIC['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
188 
189  $media_object = &ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);
190  ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
191  $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
192  foreach ($feedbacksgeneric as $correctness => $material) {
193  $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
194  }
195  }
196  }
197  $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
198  foreach ($feedbacksgeneric as $correctness => $material) {
199  $this->object->feedbackOBJ->importGenericFeedback(
200  $this->object->getId(),
201  $correctness,
203  );
204  }
205  $this->object->saveToDb();
206  if ($tst_id > 0) {
207  $q_1_id = $this->object->getId();
208  $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
209  $tst_object->questions[$question_counter++] = $question_id;
210  $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
211  } else {
212  $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
213  }
214  }
215 }
static makeDirParents($a_dir)
Create a new directory and all parent directories.
addGeneralMetadata(ilQTIItem $item)
$_SESSION["AccountId"]
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
Creates a question from a QTI file.
global $DIC
Definition: saml.php:7
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
getQplImportArchivDirectory()
returns the full path to extracted qpl import archiv (qpl import dir + qpl archiv subdir) ...
static _saveTempFileAsMediaObject($name, $tmp_name, $upload=true)
Create new media object and update page in db and return new media object.
static _replaceMediaObjectImageSrc($a_text, $a_direction=0, $nic=IL_INST_ID)
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
$ilUser
Definition: imgupload.php:18
$i
Definition: disco.tpl.php:19
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) ...
Class for question imports.
Class for java applet question imports.
static _saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Save usage of mob within another container (e.g.