ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
 __construct ($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
 fetchIndexFromFeedbackIdent ($feedbackIdent, $prefix='response_')
 
 getFeedbackAnswerSpecific (ilQTIItem $item, $prefix='response_')
 
 addGeneralMetadata (ilQTIItem $item)
 
 fetchLifecycle (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 $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 }
$_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)
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: metadata.php:24
$ilUser
Definition: imgupload.php:18
$DIC
Definition: xapitoken.php:46

References $_SESSION, $DIC, $i, $ilUser, 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: