ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assFlashQuestionImport.php
Go to the documentation of this file.
1 <?php
2  /*
3  +----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +----------------------------------------------------------------------------+
22 */
23 
24 include_once "./Modules/TestQuestionPool/classes/import/qti12/class.assQuestionImport.php";
25 
34 {
48  function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
49  {
50  global $ilUser;
51 
52  // empty session variable for imported xhtml mobs
53  unset($_SESSION["import_mob_xhtml"]);
54  $presentation = $item->getPresentation();
55  $duration = $item->getDuration();
56  $now = getdate();
57  $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
58 
59  $feedbacksgeneric = array();
60 
61  $this->object->setTitle($item->getTitle());
62  $this->object->setNrOfTries($item->getMaxattempts());
63  $this->object->setComment($item->getComment());
64  $this->object->setAuthor($item->getAuthor());
65  $this->object->setOwner($ilUser->getId());
66  $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
67  $this->object->setObjId($questionpool_id);
68  $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
69  $this->object->setWidth($item->getMetadataEntry("width"));
70  $this->object->setHeight($item->getMetadataEntry("height"));
71  $this->object->setApplet($item->getMetadataEntry("applet"));
72  $this->object->setParameters(unserialize($item->getMetadataEntry("params")));
73  $this->object->setPoints($item->getMetadataEntry("points"));
74  $this->object->saveToDb();
75 
76  $flashapplet =& base64_decode($item->getMetadataEntry("swf"));
77  if (!file_exists($this->object->getFlashPath()))
78  {
79  include_once "./Services/Utilities/classes/class.ilUtil.php";
80  ilUtil::makeDirParents($this->object->getFlashPath());
81  }
82  $filename = $this->object->getFlashPath() . $this->object->getApplet();
83  $fh = fopen($filename, "wb");
84  if ($fh == false)
85  {
86 // global $ilErr;
87 // $ilErr->raiseError($this->object->lng->txt("error_save_image_file") . ": $php_errormsg", $ilErr->MESSAGE);
88 // return;
89  }
90  else
91  {
92  fwrite($fh, $flashapplet);
93  fclose($fh);
94  }
95 
96  $feedbacksgeneric = $this->getFeedbackGeneric($item);
97 
98  // handle the import of media objects in XHTML code
99  $questiontext = $this->object->getQuestion();
100  if (is_array($_SESSION["import_mob_xhtml"]))
101  {
102  include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
103  include_once "./Services/RTE/classes/class.ilRTE.php";
104  foreach ($_SESSION["import_mob_xhtml"] as $mob)
105  {
106  if ($tst_id > 0)
107  {
108  $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
109  }
110  else
111  {
112  $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
113  }
114 
115  $GLOBALS['ilLog']->write(__METHOD__.': import mob from dir: '. $importfile);
116 
117  $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
118  ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
119  $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
120  foreach ($feedbacksgeneric as $correctness => $material)
121  {
122  $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
123  }
124  }
125  }
126  $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
127  foreach ($feedbacksgeneric as $correctness => $material)
128  {
129  $this->object->saveFeedbackGeneric($correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1));
130  }
131  $this->object->saveToDb();
132  if (count($item->suggested_solutions))
133  {
134  foreach ($item->suggested_solutions as $suggested_solution)
135  {
136  $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
137  }
138  $this->object->saveToDb();
139  }
140  if ($tst_id > 0)
141  {
142  $q_1_id = $this->object->getId();
143  $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
144  $tst_object->questions[$question_counter++] = $question_id;
145  $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
146  }
147  else
148  {
149  $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
150  }
151  }
152 }
153 
154 ?>