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