ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.assFileUploadImport.php
Go to the documentation of this file.
1 <?php
26 {
27  public function fromXML(
28  string $importdirectory,
29  int $user_id,
30  ilQTIItem $item,
31  int $questionpool_id,
32  ?int $tst_id,
33  ?ilObject &$tst_object,
34  int &$question_counter,
35  array $import_mapping
36  ): array {
37  // empty session variable for imported xhtml mobs
38  ilSession::clear('import_mob_xhtml');
39 
40  $this->addGeneralMetadata($item);
41  $this->object->setTitle($item->getTitle());
42  $this->object->setNrOfTries((int) $item->getMaxattempts());
43  $this->object->setComment($item->getComment());
44  $this->object->setAuthor($item->getAuthor());
45  $this->object->setOwner($user_id);
46  $this->object->setQuestion($this->QTIMaterialToString($item->getQuestiontext()));
47  $this->object->setObjId($questionpool_id);
48  $this->object->setPoints($item->getMetadataEntry("points"));
49  $this->object->setMaxSize($item->getMetadataEntry("maxsize") ? (int) $item->getMetadataEntry("maxsize") : null);
50  $this->object->setAllowedExtensions($item->getMetadataEntry("allowedextensions") ?? '');
51  // additional content editing mode information
52  $this->object->setAdditionalContentEditingMode(
54  );
55  $this->object->saveToDb();
56 
57  $feedbacksgeneric = $this->getFeedbackGeneric($item);
58 
59  // handle the import of media objects in XHTML code
60  $questiontext = $this->object->getQuestion();
61  if (is_array(ilSession::get("import_mob_xhtml"))) {
62  foreach (ilSession::get("import_mob_xhtml") as $mob) {
63  $importfile = $importdirectory . DIRECTORY_SEPARATOR . $mob["uri"];
64 
65  global $DIC; /* @var ILIAS\DI\Container $DIC */
66  $DIC['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
67 
68  $media_object = ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);
69  ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
70  $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
71  foreach ($feedbacksgeneric as $correctness => $material) {
72  $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
73  }
74  }
75  }
76  $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
77  foreach ($feedbacksgeneric as $correctness => $material) {
78  $this->object->feedbackOBJ->importGenericFeedback(
79  $this->object->getId(),
80  $correctness,
82  );
83  }
84  $this->object->saveToDb();
85  $this->importSuggestedSolutions($this->object->getId(), $item->suggested_solutions);
86  if ($tst_id > 0) {
87  $q_1_id = $this->object->getId();
88  $question_id = $this->object->duplicate(true, "", "", -1, $tst_id);
89  $tst_object->questions[$question_counter++] = $question_id;
90  $import_mapping[$item->getIdent()] = ["pool" => $q_1_id, "test" => $question_id];
91  } else {
92  $import_mapping[$item->getIdent()] = ["pool" => $this->object->getId(), "test" => 0];
93  }
94  return $import_mapping;
95  }
96 }
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
QTIMaterialToString(ilQTIMaterial $a_material)
Reads an QTI material tag and creates a text or XHTML string.
getMetadataEntry(string $a_label)
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
global $DIC
Definition: shib_login.php:22
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)
static _saveTempFileAsMediaObject(string $name, string $tmp_name, bool $upload=true)
Class for question imports.
static clear(string $a_var)