ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
assJavaAppletImport Class Reference

Class for java applet question imports. More...

+ Inheritance diagram for assJavaAppletImport:
+ Collaboration diagram for assJavaAppletImport:

Public Member Functions

 fromXML (&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
 Creates a question from a QTI file. More...
 
- Public Member Functions inherited from assQuestionImport
 assQuestionImport (&$a_object)
 assQuestionImport constructor More...
 
 getFeedbackGeneric ($item)
 
 fromXML (&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
 Creates a question from a QTI file. More...
 

Additional Inherited Members

- Data Fields inherited from assQuestionImport
 $object
 
- Protected Member Functions inherited from assQuestionImport
 getFeedbackAnswerSpecific (ilQTIItem $item)
 
 addGeneralMetadata (ilQTIItem $item)
 
 getQplImportArchivDirectory ()
 returns the full path to extracted qpl import archiv (qpl import dir + qpl archiv subdir) More...
 
 getTstImportArchivDirectory ()
 returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) More...
 
 processNonAbstractedImageReferences ($text, $sourceNic)
 
 fetchAdditionalContentEditingModeInformation ($qtiItem)
 fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_CONTENT_EDITING_MODE_DEFAULT when no or invalid information is given More...
 

Detailed Description

Class for java applet question imports.

assJavaAppletImport is a class for java applet question imports

Author
Helmut Schottmüller helmu.nosp@m.t.sc.nosp@m.hottm.nosp@m.uell.nosp@m.er@ma.nosp@m.c.co.nosp@m.m
Version
$Id$

Definition at line 15 of file class.assJavaAppletImport.php.

Member Function Documentation

◆ fromXML()

assJavaAppletImport::fromXML ( $item,
  $questionpool_id,
$tst_id,
$tst_object,
$question_counter,
$import_mapping 
)

Creates a question from a QTI file.

Receives parameters from a QTI parser and creates a valid ILIAS question object

Parameters
object$itemThe QTI item object
integer$questionpool_idThe id of the parent questionpool
integer$tst_idThe id of the parent test if the question is part of a test
object$tst_objectA reference to the parent test object
integer$question_counterA reference to a question counter to count the questions of an imported question pool
array$import_mappingAn array containing references to included ILIAS objects @access public

Reimplemented from assQuestionImport.

Definition at line 30 of file class.assJavaAppletImport.php.

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 {
49 switch ($entry["type"])
50 {
51 case "material":
52 $material = $presentation->material[$entry["index"]];
53 for ($i = 0; $i < $material->getMaterialCount(); $i++)
54 {
55 $mat = $material->getMaterial($i);
56 if (strcmp($mat["type"], "mattext") == 0)
57 {
58 $mattext = $mat["material"];
59 if ((strlen($mattext->getLabel()) == 0) && (strlen($this->object->QTIMaterialToString($item->getQuestiontext())) == 0))
60 {
61 $item->setQuestiontext($mattext->getContent());
62 }
63 if (strcmp($mattext->getLabel(), "points") == 0)
64 {
65 $maxpoints = $mattext->getContent();
66 }
67 else if (strcmp($mattext->getLabel(), "java_code") == 0)
68 {
69 $javacode = $mattext->getContent();
70 }
71 else if (strcmp($mattext->getLabel(), "java_codebase") == 0)
72 {
73 $javacodebase = $mattext->getContent();
74 }
75 else if (strcmp($mattext->getLabel(), "java_archive") == 0)
76 {
77 $javaarchive = $mattext->getContent();
78 }
79 else if (strlen($mattext->getLabel()) > 0)
80 {
81 array_push($params, array("key" => $mattext->getLabel(), "value" => $mattext->getContent()));
82 }
83 }
84 elseif (strcmp($mat["type"], "matapplet") == 0)
85 {
86 $applet = $mat["material"];
87 }
88 }
89 break;
90 }
91 }
92
93 $feedbacksgeneric = array();
94 foreach ($item->resprocessing as $resprocessing)
95 {
96 foreach ($resprocessing->respcondition as $respcondition)
97 {
98 foreach ($respcondition->displayfeedback as $feedbackpointer)
99 {
100 if (strlen($feedbackpointer->getLinkrefid()))
101 {
102 foreach ($item->itemfeedback as $ifb)
103 {
104 if (strcmp($ifb->getIdent(), "response_allcorrect") == 0)
105 {
106 // found a feedback for the identifier
107 if (count($ifb->material))
108 {
109 foreach ($ifb->material as $material)
110 {
111 $feedbacksgeneric[1] = $material;
112 }
113 }
114 if ((count($ifb->flow_mat) > 0))
115 {
116 foreach ($ifb->flow_mat as $fmat)
117 {
118 if (count($fmat->material))
119 {
120 foreach ($fmat->material as $material)
121 {
122 $feedbacksgeneric[1] = $material;
123 }
124 }
125 }
126 }
127 }
128 else if (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0)
129 {
130 // found a feedback for the identifier
131 if (count($ifb->material))
132 {
133 foreach ($ifb->material as $material)
134 {
135 $feedbacksgeneric[0] = $material;
136 }
137 }
138 if ((count($ifb->flow_mat) > 0))
139 {
140 foreach ($ifb->flow_mat as $fmat)
141 {
142 if (count($fmat->material))
143 {
144 foreach ($fmat->material as $material)
145 {
146 $feedbacksgeneric[0] = $material;
147 }
148 }
149 }
150 }
151 }
152 }
153 }
154 }
155 }
156 }
157
158 $this->addGeneralMetadata($item);
159 $this->object->setTitle($item->getTitle());
160 $this->object->setNrOfTries($item->getMaxattempts());
161 $this->object->setComment($item->getComment());
162 $this->object->setAuthor($item->getAuthor());
163 $this->object->setOwner($ilUser->getId());
164 $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
165 $this->object->setObjId($questionpool_id);
166 $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
167 $this->object->setJavaAppletFilename($applet->getUri());
168 $this->object->setJavaWidth($applet->getWidth());
169 $this->object->setJavaHeight($applet->getHeight());
170 $this->object->setJavaCode($javacode);
171 $this->object->setJavaCodebase($javacodebase);
172 $this->object->setJavaArchive($javaarchive);
173 $this->object->setPoints($maxpoints);
174 foreach ($params as $pair)
175 {
176 $this->object->addParameter($pair["key"], $pair["value"]);
177 }
178 // additional content editing mode information
179 $this->object->setAdditionalContentEditingMode(
181 );
182 $this->object->saveToDb();
183 if (count($item->suggested_solutions))
184 {
185 foreach ($item->suggested_solutions as $suggested_solution)
186 {
187 $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
188 }
189 $this->object->saveToDb();
190 }
191 $javaapplet =& base64_decode($applet->getContent());
192 $javapath = $this->object->getJavaPath();
193 if (!file_exists($javapath))
194 {
195 include_once "./Services/Utilities/classes/class.ilUtil.php";
196 ilUtil::makeDirParents($javapath);
197 }
198 $javapath .= $this->object->getJavaAppletFilename();
199 $fh = fopen($javapath, "wb");
200 if ($fh == false)
201 {
202// global $ilErr;
203// $ilErr->raiseError($this->object->lng->txt("error_save_image_file") . ": $php_errormsg", $ilErr->MESSAGE);
204// return;
205 }
206 else
207 {
208 $javafile = fwrite($fh, $javaapplet);
209 fclose($fh);
210 }
211 // handle the import of media objects in XHTML code
212 foreach ($feedbacksgeneric as $correctness => $material)
213 {
214 $m = $this->object->QTIMaterialToString($material);
215 $feedbacksgeneric[$correctness] = $m;
216 }
217 $questiontext = $this->object->getQuestion();
218 if (is_array($_SESSION["import_mob_xhtml"]))
219 {
220 include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
221 include_once "./Services/RTE/classes/class.ilRTE.php";
222 foreach ($_SESSION["import_mob_xhtml"] as $mob)
223 {
224 if ($tst_id > 0)
225 {
226 $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
227 }
228 else
229 {
230 $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
231 }
232
233 $GLOBALS['ilLog']->write(__METHOD__.': import mob from dir: '. $importfile);
234
235 $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
236 ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
237 $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
238 foreach ($feedbacksgeneric as $correctness => $material)
239 {
240 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
241 }
242 }
243 }
244 $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
245 foreach ($feedbacksgeneric as $correctness => $material)
246 {
247 $this->object->feedbackOBJ->importGenericFeedback(
248 $this->object->getId(), $correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1)
249 );
250 }
251 $this->object->saveToDb();
252 if ($tst_id > 0)
253 {
254 $q_1_id = $this->object->getId();
255 $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
256 $tst_object->questions[$question_counter++] = $question_id;
257 $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
258 }
259 else
260 {
261 $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
262 }
263 }
$_SESSION["AccountId"]
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)
_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.
$params
Definition: example_049.php:96
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
global $ilUser
Definition: imgupload.php:15

References $_SESSION, $GLOBALS, $ilUser, $params, ilRTE\_replaceMediaObjectImageSrc(), ilObjMediaObject\_saveTempFileAsMediaObject(), ilObjMediaObject\_saveUsage(), assQuestionImport\addGeneralMetadata(), assQuestionImport\fetchAdditionalContentEditingModeInformation(), assQuestionImport\getQplImportArchivDirectory(), assQuestionImport\getTstImportArchivDirectory(), and ilUtil\makeDirParents().

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: