ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.assFlashQuestionImport.php
Go to the documentation of this file.
1 <?php
2 
27 {
41  public function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, $import_mapping): array
42  {
43  global $DIC;
44  $ilUser = $DIC['ilUser'];
45 
46  // empty session variable for imported xhtml mobs
47  ilSession::clear('import_mob_xhtml');
48 
49  $presentation = $item->getPresentation();
50  $now = getdate();
51  $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
52 
53  $feedbacksgeneric = array();
54 
55  $this->addGeneralMetadata($item);
56  $this->object->setTitle($item->getTitle());
57  $this->object->setNrOfTries((int) $item->getMaxattempts());
58  $this->object->setComment($item->getComment());
59  $this->object->setAuthor($item->getAuthor());
60  $this->object->setOwner($ilUser->getId());
61  $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
62  $this->object->setObjId($questionpool_id);
63  $this->object->setWidth($item->getMetadataEntry("width"));
64  $this->object->setHeight($item->getMetadataEntry("height"));
65  $this->object->setApplet($item->getMetadataEntry("applet"));
66  $this->object->setParameters(unserialize($item->getMetadataEntry("params"), ["allowed_classes" => false]));
67  $this->object->setPoints($item->getMetadataEntry("points"));
68  // additional content editing mode information
69  $this->object->setAdditionalContentEditingMode(
71  );
72  $this->object->saveToDb();
73 
74  $flashapplet = base64_decode($item->getMetadataEntry("swf"));
75  if (!file_exists($this->object->getFlashPath())) {
76  ilFileUtils::makeDirParents($this->object->getFlashPath());
77  }
78  $filename = $this->object->getFlashPath() . $this->object->getApplet();
79  $fh = fopen($filename, "wb");
80  if ($fh == false) {
81  // global $DIC;
82  // $ilErr = $DIC['ilErr'];
83  // $ilErr->raiseError($this->object->lng->txt("error_save_image_file") . ": $php_errormsg", $ilErr->MESSAGE);
84  // return;
85  } else {
86  fwrite($fh, $flashapplet);
87  fclose($fh);
88  }
89 
90  $feedbacksgeneric = $this->getFeedbackGeneric($item);
91 
92  // handle the import of media objects in XHTML code
93  $questiontext = $this->object->getQuestion();
94  if (is_array(ilSession::get("import_mob_xhtml"))) {
95  foreach (ilSession::get("import_mob_xhtml") as $mob) {
96  if ($tst_id > 0) {
97  $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
98  } else {
99  $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
100  }
101 
102  global $DIC; /* @var ILIAS\DI\Container $DIC */
103  $DIC['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
104 
105  $media_object = ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);
106  ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
107  $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
108  foreach ($feedbacksgeneric as $correctness => $material) {
109  $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
110  }
111  }
112  }
113  $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
114  foreach ($feedbacksgeneric as $correctness => $material) {
115  $this->object->feedbackOBJ->importGenericFeedback(
116  $this->object->getId(),
117  $correctness,
119  );
120  }
121  $this->object->saveToDb();
122  if (count($item->suggested_solutions)) {
123  foreach ($item->suggested_solutions as $suggested_solution) {
124  $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
125  }
126  $this->object->saveToDb();
127  }
128  if ($tst_id > 0) {
129  $q_1_id = $this->object->getId();
130  $question_id = $this->object->duplicate(true, "", "", "", $tst_id);
131  $tst_object->questions[$question_counter++] = $question_id;
132  $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
133  } else {
134  $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
135  }
136  return $import_mapping;
137  }
138 }
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) ...
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, $import_mapping)
Creates a question from a QTI file.
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
global $DIC
Definition: feed.php:28
$filename
Definition: buildRTE.php:78
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
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) ...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static clear(string $a_var)
int $created
Timestamp for when the object was created.
Definition: System.php:151