ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
assImagemapQuestionImport Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Inheritance diagram for assImagemapQuestionImport:
+ Collaboration diagram for assImagemapQuestionImport:

Public Member Functions

 fromXML (string $importdirectory, int $user_id, ilQTIItem $item, int $questionpool_id, ?int $tst_id, ?ilObject &$tst_object, int &$question_counter, array $import_mapping)
 
- Public Member Functions inherited from assQuestionImport
 getQuestionId ()
 
 getFeedbackGeneric ($item)
 
 fromXML (string $importdirectory, int $user_id, ilQTIItem $item, int $questionpool_id, ?int $tst_id, ?ilObject &$tst_object, int &$question_counter, array $import_mapping)
 
 importSuggestedSolutions (int $question_id, array $solution_from_import)
 
 QTIMaterialToString (ilQTIMaterial $a_material)
 Reads an QTI material tag and creates a text or XHTML string. 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)
 
 processNonAbstractedImageReferences ($text, $sourceNic)
 
 fetchAdditionalContentEditingModeInformation ($qtiItem)
 fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_CONTENT_EDITING_MODE_RTE when no or invalid information is given More...
 
 findSolutionTypeByValue (string $value)
 
 getSuggestedSolutionsRepo ()
 
 deduceThumbSizeFromImportValue (?int $size)
 
 addQuestionToParentObjectAndBuildMappingEntry (int $questionpool_id, ?int $tst_id, int &$question_counter, ?ilObjTest &$tst_object)
 
- Protected Attributes inherited from assQuestionImport
SuggestedSolutionsDatabaseRepository $suggestedsolution_repo = null
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Class for imagemap question imports

assImagemapQuestionImport is a class for imagemap 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$ \
Deprecated:
Use normalized question import instead

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

Member Function Documentation

◆ fromXML()

assImagemapQuestionImport::fromXML ( string  $importdirectory,
int  $user_id,
ilQTIItem  $item,
int  $questionpool_id,
?int  $tst_id,
?ilObject &  $tst_object,
int &  $question_counter,
array  $import_mapping 
)

Reimplemented from assQuestionImport.

Definition at line 32 of file class.assImagemapQuestionImport.php.

41 : array {
42 // empty session variable for imported xhtml mobs
43 ilSession::clear('import_mob_xhtml');
44
45 $presentation = $item->getPresentation();
46 $questionimage = [];
47 $answers = [];
48 foreach ($presentation->order as $entry) {
49 switch ($entry["type"]) {
50 case "response":
51 $response = $presentation->response[$entry["index"]];
52 $rendertype = $response->getRenderType();
53 switch (strtolower(get_class($rendertype))) {
54 case "ilqtirenderhotspot":
55 foreach ($rendertype->material as $mat) {
56 for ($i = 0; $i < $mat->getMaterialCount(); $i++) {
57 $m = $mat->getMaterial($i);
58 if (strcmp($m["type"], "matimage") == 0) {
59 $questionimage = [
60 "imagetype" => $m["material"]->getImageType(),
61 "label" => $m["material"]->getLabel(),
62 "content" => $m["material"]->getContent()
63 ];
64 }
65 }
66 }
67 foreach ($rendertype->response_labels as $response_label) {
68 $ident = $response_label->getIdent();
69 $answerhint = "";
70 foreach ($response_label->material as $mat) {
71 $answerhint .= $this->QTIMaterialToString($mat);
72 }
73 $answers[$ident] = [
74 "answerhint" => $answerhint,
75 "areatype" => $response_label->getRarea(),
76 "coordinates" => $response_label->getContent(),
77 "points" => 0,
78 "answerorder" => $response_label->getIdent(),
79 "correctness" => "1",
80 "action" => "",
81 "points_unchecked" => 0
82 ];
83 }
84 break;
85 }
86 break;
87 }
88 }
89 $responses = [];
90 $feedbacks = [];
91 $feedbacksgeneric = [];
92 foreach ($item->resprocessing as $resprocessing) {
93 foreach ($resprocessing->respcondition as $respcondition) {
94 $coordinates = "";
95 $correctness = 1;
96 $conditionvar = $respcondition->getConditionvar();
97 foreach ($conditionvar->order as $order) {
98 switch ($order["field"]) {
99 case "arr_not":
100 $correctness = 0;
101 break;
102 case "varinside":
103 $coordinates = $conditionvar->varinside[$order["index"]]->getContent();
104 break;
105 case "varequal":
106 $coordinates = $conditionvar->varequal[$order["index"]]->getContent();
107 break;
108 }
109 }
110 foreach ($respcondition->setvar as $setvar) {
111 foreach ($answers as $ident => $answer) {
112 if (strcmp($answer["coordinates"], $coordinates) == 0) {
113 if ($correctness) {
114 $answers[$ident]["action"] = $setvar->getAction();
115 $answers[$ident]["points"] = $setvar->getContent();
116 if (count($respcondition->displayfeedback)) {
117 foreach ($respcondition->displayfeedback as $feedbackpointer) {
118 if (strlen($feedbackpointer->getLinkrefid())) {
119 foreach ($item->itemfeedback as $ifb) {
120 if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
121 // found a feedback for the identifier
122 if (count($ifb->material)) {
123 foreach ($ifb->material as $material) {
124 $feedbacksgeneric[1] = $material;
125 }
126 }
127 if ((count($ifb->flow_mat) > 0)) {
128 foreach ($ifb->flow_mat as $fmat) {
129 if (count($fmat->material)) {
130 foreach ($fmat->material as $material) {
131 $feedbacksgeneric[1] = $material;
132 }
133 }
134 }
135 }
136 } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
137 // found a feedback for the identifier
138 if (count($ifb->material)) {
139 foreach ($ifb->material as $material) {
140 $feedbacksgeneric[0] = $material;
141 }
142 }
143 if ((count($ifb->flow_mat) > 0)) {
144 foreach ($ifb->flow_mat as $fmat) {
145 if (count($fmat->material)) {
146 foreach ($fmat->material as $material) {
147 $feedbacksgeneric[0] = $material;
148 }
149 }
150 }
151 }
152 }
153 if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0) {
154 // found a feedback for the identifier
155 if (count($ifb->material)) {
156 foreach ($ifb->material as $material) {
157 $feedbacks[$ident] = $material;
158 }
159 }
160 if ((count($ifb->flow_mat) > 0)) {
161 foreach ($ifb->flow_mat as $fmat) {
162 if (count($fmat->material)) {
163 foreach ($fmat->material as $material) {
164 $feedbacks[$ident] = $material;
165 }
166 }
167 }
168 }
169 }
170 }
171 }
172 }
173 }
174 } else {
175 $answers[$ident]["action"] = $setvar->getAction();
176 $answers[$ident]["points_unchecked"] = $setvar->getContent();
177 }
178 }
179 }
180 }
181 }
182 }
183
184 $this->addGeneralMetadata($item);
185 $this->object->setTitle($item->getTitle());
186 $this->object->setNrOfTries((int) $item->getMaxattempts());
187 $this->object->setComment($item->getComment());
188 $this->object->setAuthor($item->getAuthor());
189 $this->object->setOwner($user_id);
190 $this->object->setQuestion($this->QTIMaterialToString($item->getQuestiontext()));
191 $this->object->setObjId($questionpool_id);
192 $this->object->setIsMultipleChoice($item->getMetadataEntry("IS_MULTIPLE_CHOICE"));
193 $areas = ["2" => "rect", "1" => "circle", "3" => "poly"];
194 $this->object->setImageFilename($questionimage["label"]);
195 foreach ($answers as $answer) {
196 $this->object->addAnswer($answer["answerhint"], $answer["points"], $answer["answerorder"], $answer["coordinates"], $areas[$answer["areatype"]], $answer["points_unchecked"]);
197 }
198 // additional content editing mode information
199 $this->object->setAdditionalContentEditingMode(
201 );
202 $this->object->saveToDb();
203 $this->importSuggestedSolutions($this->object->getId(), $item->suggested_solutions);
204 $image = base64_decode($questionimage["content"]);
205 $imagepath = $this->object->getImagePath();
206 if (!file_exists($imagepath)) {
207 ilFileUtils::makeDirParents($imagepath);
208 }
209 $imagepath .= $questionimage["label"];
210 $fh = fopen($imagepath, "wb");
211 if ($fh == true) {
212 $imagefile = fwrite($fh, $image);
213 fclose($fh);
214 }
215 // handle the import of media objects in XHTML code
216 foreach ($feedbacks as $ident => $material) {
217 $m = $this->QTIMaterialToString($material);
218 $feedbacks[$ident] = $m;
219 }
220 foreach ($feedbacksgeneric as $correctness => $material) {
221 $m = $this->QTIMaterialToString($material);
222 $feedbacksgeneric[$correctness] = $m;
223 }
224 $questiontext = $this->object->getQuestion();
225 if (is_array(ilSession::get("import_mob_xhtml"))) {
226 foreach (ilSession::get("import_mob_xhtml") as $mob) {
227 $importfile = $importdirectory . DIRECTORY_SEPARATOR . $mob["uri"];
228
229 global $DIC; /* @var ILIAS\DI\Container $DIC */
230 $DIC['ilLog']->info('import mob from dir: ' . $importfile);
231
232 $media_object = ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);
233 ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
234 $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
235 foreach ($feedbacks as $ident => $material) {
236 $feedbacks[$ident] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
237 }
238 foreach ($feedbacksgeneric as $correctness => $material) {
239 $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
240 }
241 }
242 }
243 $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
244 foreach ($feedbacks as $ident => $material) {
245 $this->object->feedbackOBJ->importSpecificAnswerFeedback(
246 $this->object->getId(),
247 0,
248 $ident,
250 );
251 }
252 foreach ($feedbacksgeneric as $correctness => $material) {
253 $this->object->feedbackOBJ->importGenericFeedback(
254 $this->object->getId(),
255 $correctness,
257 );
258 }
259 $this->object->saveToDb();
260 $import_mapping[$item->getIdent()] = $this->addQuestionToParentObjectAndBuildMappingEntry(
261 $questionpool_id,
262 $tst_id,
263 $question_counter,
264 $tst_object
265 );
266 return $import_mapping;
267 }
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
addQuestionToParentObjectAndBuildMappingEntry(int $questionpool_id, ?int $tst_id, int &$question_counter, ?ilObjTest &$tst_object)
QTIMaterialToString(ilQTIMaterial $a_material)
Reads an QTI material tag and creates a text or XHTML string.
addGeneralMetadata(ilQTIItem $item)
importSuggestedSolutions(int $question_id, array $solution_from_import)
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
static _saveTempFileAsMediaObject(string $name, string $tmp_name, bool $upload=true)
static _saveUsage(int $a_mob_id, string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
Save usage of mob within another container (e.g.
getMetadataEntry(string $a_label)
static _replaceMediaObjectImageSrc(string $a_text, int $a_direction=0, string $nic='')
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
static get(string $a_var)
static clear(string $a_var)
const IL_INST_ID
Definition: constants.php:40
global $DIC
Definition: shib_login.php:26
$response
Definition: xapitoken.php:92

References $response, and assQuestionImport\QTIMaterialToString().

+ Here is the call graph for this function:

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