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