ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.assFlashQuestionImport.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once "./Modules/TestQuestionPool/classes/import/qti12/class.assQuestionImport.php";
5 
14 {
28  public function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
29  {
30  global $DIC;
31  $ilUser = $DIC['ilUser'];
32 
33  // empty session variable for imported xhtml mobs
34  unset($_SESSION["import_mob_xhtml"]);
35  $presentation = $item->getPresentation();
36  $duration = $item->getDuration();
37  $now = getdate();
38  $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
39 
40  $feedbacksgeneric = array();
41 
42  $this->addGeneralMetadata($item);
43  $this->object->setTitle($item->getTitle());
44  $this->object->setNrOfTries($item->getMaxattempts());
45  $this->object->setComment($item->getComment());
46  $this->object->setAuthor($item->getAuthor());
47  $this->object->setOwner($ilUser->getId());
48  $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
49  $this->object->setObjId($questionpool_id);
50  $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
51  $this->object->setWidth($item->getMetadataEntry("width"));
52  $this->object->setHeight($item->getMetadataEntry("height"));
53  $this->object->setApplet($item->getMetadataEntry("applet"));
54  $this->object->setParameters(unserialize($item->getMetadataEntry("params")));
55  $this->object->setPoints($item->getMetadataEntry("points"));
56  // additional content editing mode information
57  $this->object->setAdditionalContentEditingMode(
59  );
60  $this->object->saveToDb();
61 
62  $flashapplet = &base64_decode($item->getMetadataEntry("swf"));
63  if (!file_exists($this->object->getFlashPath())) {
64  include_once "./Services/Utilities/classes/class.ilUtil.php";
65  ilUtil::makeDirParents($this->object->getFlashPath());
66  }
67  $filename = $this->object->getFlashPath() . $this->object->getApplet();
68  $fh = fopen($filename, "wb");
69  if ($fh == false) {
70  // global $DIC;
71 // $ilErr = $DIC['ilErr'];
72 // $ilErr->raiseError($this->object->lng->txt("error_save_image_file") . ": $php_errormsg", $ilErr->MESSAGE);
73 // return;
74  } else {
75  fwrite($fh, $flashapplet);
76  fclose($fh);
77  }
78 
79  $feedbacksgeneric = $this->getFeedbackGeneric($item);
80 
81  // handle the import of media objects in XHTML code
82  $questiontext = $this->object->getQuestion();
83  if (is_array($_SESSION["import_mob_xhtml"])) {
84  include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
85  include_once "./Services/RTE/classes/class.ilRTE.php";
86  foreach ($_SESSION["import_mob_xhtml"] as $mob) {
87  if ($tst_id > 0) {
88  $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
89  } else {
90  $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
91  }
92 
93  global $DIC; /* @var ILIAS\DI\Container $DIC */
94  $DIC['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
95 
96  $media_object = &ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);
97  ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
98  $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
99  foreach ($feedbacksgeneric as $correctness => $material) {
100  $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
101  }
102  }
103  }
104  $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
105  foreach ($feedbacksgeneric as $correctness => $material) {
106  $this->object->feedbackOBJ->importGenericFeedback(
107  $this->object->getId(),
108  $correctness,
110  );
111  }
112  $this->object->saveToDb();
113  if (count($item->suggested_solutions)) {
114  foreach ($item->suggested_solutions as $suggested_solution) {
115  $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
116  }
117  $this->object->saveToDb();
118  }
119  if ($tst_id > 0) {
120  $q_1_id = $this->object->getId();
121  $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
122  $tst_object->questions[$question_counter++] = $question_id;
123  $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
124  } else {
125  $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
126  }
127  }
128 }
static makeDirParents($a_dir)
Create a new directory and all parent directories.
addGeneralMetadata(ilQTIItem $item)
$_SESSION["AccountId"]
global $DIC
Definition: saml.php:7
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
getQplImportArchivDirectory()
returns the full path to extracted qpl import archiv (qpl import dir + qpl archiv subdir) ...
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...
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
Creates a question from a QTI file.
$ilUser
Definition: imgupload.php:18
$filename
Definition: buildRTE.php:89
Class for flash question imports.
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) ...
Class for question imports.
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.