ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
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 (&$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...
 
 getQuestionId ()
 
 getFeedbackGeneric ($item)
 
 fromXML (&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, $import_mapping)
 Creates a question from a QTI file. More...
 
 importSuggestedSolution (int $question_id, string $value="", int $subquestion_index=0)
 

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_RTE when no or invalid information is given More...
 
 deduceThumbSizeFromImportValue (?int $size)
 

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$

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

Member Function Documentation

◆ fromXML()

assImagemapQuestionImport::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
ilQtiItem$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 public

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

References ILIAS\LTI\ToolProvider\$created, $DIC, $i, $ilUser, $response, ilRTE\_replaceMediaObjectImageSrc(), ilObjMediaObject\_saveTempFileAsMediaObject(), ilObjMediaObject\_saveUsage(), assQuestionImport\addGeneralMetadata(), ilSession\clear(), assQuestionImport\fetchAdditionalContentEditingModeInformation(), ilSession\get(), ILIAS\UI\Implementation\Component\Input\ViewControl\getContent(), assQuestionImport\getQplImportArchivDirectory(), assQuestionImport\getTstImportArchivDirectory(), IL_INST_ID, ilFileUtils\makeDirParents(), and ILIAS\Repository\object().

43  : array
44  {
45  global $DIC;
46  $ilUser = $DIC['ilUser'];
47 
48  // empty session variable for imported xhtml mobs
49  ilSession::clear('import_mob_xhtml');
50 
51  $presentation = $item->getPresentation();
52  $now = getdate();
53  $questionimage = array();
54  $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
55  $answers = array();
56  foreach ($presentation->order as $entry) {
57  switch ($entry["type"]) {
58  case "response":
59  $response = $presentation->response[$entry["index"]];
60  $rendertype = $response->getRenderType();
61  switch (strtolower(get_class($rendertype))) {
62  case "ilqtirenderhotspot":
63  foreach ($rendertype->material as $mat) {
64  for ($i = 0; $i < $mat->getMaterialCount(); $i++) {
65  $m = $mat->getMaterial($i);
66  if (strcmp($m["type"], "matimage") == 0) {
67  $questionimage = array(
68  "imagetype" => $m["material"]->getImageType(),
69  "label" => $m["material"]->getLabel(),
70  "content" => $m["material"]->getContent()
71  );
72  }
73  }
74  }
75  foreach ($rendertype->response_labels as $response_label) {
76  $ident = $response_label->getIdent();
77  $answerhint = "";
78  foreach ($response_label->material as $mat) {
79  $answerhint .= $this->object->QTIMaterialToString($mat);
80  }
81  $answers[$ident] = array(
82  "answerhint" => $answerhint,
83  "areatype" => $response_label->getRarea(),
84  "coordinates" => $response_label->getContent(),
85  "points" => 0,
86  "answerorder" => $response_label->getIdent(),
87  "correctness" => "1",
88  "action" => "",
89  "points_unchecked" => 0
90  );
91  }
92  break;
93  }
94  break;
95  }
96  }
97  $responses = array();
98  $feedbacks = array();
99  $feedbacksgeneric = array();
100  foreach ($item->resprocessing as $resprocessing) {
101  foreach ($resprocessing->respcondition as $respcondition) {
102  $coordinates = "";
103  $correctness = 1;
104  $conditionvar = $respcondition->getConditionvar();
105  foreach ($conditionvar->order as $order) {
106  switch ($order["field"]) {
107  case "arr_not":
108  $correctness = 0;
109  break;
110  case "varinside":
111  $coordinates = $conditionvar->varinside[$order["index"]]->getContent();
112  break;
113  case "varequal":
114  $coordinates = $conditionvar->varequal[$order["index"]]->getContent();
115  break;
116  }
117  }
118  foreach ($respcondition->setvar as $setvar) {
119  foreach ($answers as $ident => $answer) {
120  if (strcmp($answer["coordinates"], $coordinates) == 0) {
121  if ($correctness) {
122  $answers[$ident]["action"] = $setvar->getAction();
123  $answers[$ident]["points"] = $setvar->getContent();
124  if (count($respcondition->displayfeedback)) {
125  foreach ($respcondition->displayfeedback as $feedbackpointer) {
126  if (strlen($feedbackpointer->getLinkrefid())) {
127  foreach ($item->itemfeedback as $ifb) {
128  if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
129  // found a feedback for the identifier
130  if (count($ifb->material)) {
131  foreach ($ifb->material as $material) {
132  $feedbacksgeneric[1] = $material;
133  }
134  }
135  if ((count($ifb->flow_mat) > 0)) {
136  foreach ($ifb->flow_mat as $fmat) {
137  if (count($fmat->material)) {
138  foreach ($fmat->material as $material) {
139  $feedbacksgeneric[1] = $material;
140  }
141  }
142  }
143  }
144  } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
145  // found a feedback for the identifier
146  if (count($ifb->material)) {
147  foreach ($ifb->material as $material) {
148  $feedbacksgeneric[0] = $material;
149  }
150  }
151  if ((count($ifb->flow_mat) > 0)) {
152  foreach ($ifb->flow_mat as $fmat) {
153  if (count($fmat->material)) {
154  foreach ($fmat->material as $material) {
155  $feedbacksgeneric[0] = $material;
156  }
157  }
158  }
159  }
160  }
161  if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0) {
162  // found a feedback for the identifier
163  if (count($ifb->material)) {
164  foreach ($ifb->material as $material) {
165  $feedbacks[$ident] = $material;
166  }
167  }
168  if ((count($ifb->flow_mat) > 0)) {
169  foreach ($ifb->flow_mat as $fmat) {
170  if (count($fmat->material)) {
171  foreach ($fmat->material as $material) {
172  $feedbacks[$ident] = $material;
173  }
174  }
175  }
176  }
177  }
178  }
179  }
180  }
181  }
182  } else {
183  $answers[$ident]["action"] = $setvar->getAction();
184  $answers[$ident]["points_unchecked"] = $setvar->getContent();
185  }
186  }
187  }
188  }
189  }
190  }
191 
192  $this->addGeneralMetadata($item);
193  $this->object->setTitle($item->getTitle());
194  $this->object->setNrOfTries((int) $item->getMaxattempts());
195  $this->object->setComment($item->getComment());
196  $this->object->setAuthor($item->getAuthor());
197  $this->object->setOwner($ilUser->getId());
198  $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
199  $this->object->setObjId($questionpool_id);
200  $this->object->setIsMultipleChoice($item->getMetadataEntry("IS_MULTIPLE_CHOICE"));
201  $areas = array("2" => "rect", "1" => "circle", "3" => "poly");
202  $this->object->setImageFilename($questionimage["label"]);
203  foreach ($answers as $answer) {
204  $this->object->addAnswer($answer["answerhint"], $answer["points"], $answer["answerorder"], $answer["coordinates"], $areas[$answer["areatype"]], $answer["points_unchecked"]);
205  }
206  // additional content editing mode information
207  $this->object->setAdditionalContentEditingMode(
209  );
210  $this->object->saveToDb();
211  if (count($item->suggested_solutions)) {
212  foreach ($item->suggested_solutions as $suggested_solution) {
213  $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
214  }
215  $this->object->saveToDb();
216  }
217  $image = base64_decode($questionimage["content"]);
218  $imagepath = $this->object->getImagePath();
219  if (!file_exists($imagepath)) {
220  ilFileUtils::makeDirParents($imagepath);
221  }
222  $imagepath .= $questionimage["label"];
223  $fh = fopen($imagepath, "wb");
224  if ($fh == true) {
225  $imagefile = fwrite($fh, $image);
226  fclose($fh);
227  }
228  // handle the import of media objects in XHTML code
229  foreach ($feedbacks as $ident => $material) {
230  $m = $this->object->QTIMaterialToString($material);
231  $feedbacks[$ident] = $m;
232  }
233  foreach ($feedbacksgeneric as $correctness => $material) {
234  $m = $this->object->QTIMaterialToString($material);
235  $feedbacksgeneric[$correctness] = $m;
236  }
237  $questiontext = $this->object->getQuestion();
238  if (is_array(ilSession::get("import_mob_xhtml"))) {
239  foreach (ilSession::get("import_mob_xhtml") as $mob) {
240  if ($tst_id > 0) {
241  $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
242  } else {
243  $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
244  }
245 
246  global $DIC; /* @var ILIAS\DI\Container $DIC */
247  $DIC['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
248 
249  $media_object = ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);
250  ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
251  $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
252  foreach ($feedbacks as $ident => $material) {
253  $feedbacks[$ident] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
254  }
255  foreach ($feedbacksgeneric as $correctness => $material) {
256  $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
257  }
258  }
259  }
260  $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
261  foreach ($feedbacks as $ident => $material) {
262  $this->object->feedbackOBJ->importSpecificAnswerFeedback(
263  $this->object->getId(),
264  0,
265  $ident,
267  );
268  }
269  foreach ($feedbacksgeneric as $correctness => $material) {
270  $this->object->feedbackOBJ->importGenericFeedback(
271  $this->object->getId(),
272  $correctness,
274  );
275  }
276  $this->object->saveToDb();
277  if ($tst_id > 0) {
278  $q_1_id = $this->object->getId();
279  $question_id = $this->object->duplicate(true, "", "", "", $tst_id);
280  $tst_object->questions[$question_counter++] = $question_id;
281  $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
282  } else {
283  $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
284  }
285  return $import_mapping;
286  }
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)
addGeneralMetadata(ilQTIItem $item)
const IL_INST_ID
Definition: constants.php:40
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
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.
getQplImportArchivDirectory()
returns the full path to extracted qpl import archiv (qpl import dir + qpl archiv subdir) ...
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
global $DIC
Definition: feed.php:28
static _saveTempFileAsMediaObject(string $name, string $tmp_name, bool $upload=true)
Create new media object and update page in db and return new media object.
$ilUser
Definition: imgupload.php:34
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) ...
$response
static clear(string $a_var)
int $created
Timestamp for when the object was created.
Definition: System.php:151
$i
Definition: metadata.php:41
+ Here is the call graph for this function:

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