ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assErrorTextImport.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->setExternalID($item->getMetadataEntry("externalID"));
63  $this->object->setNrOfTries($item->getMaxattempts());
64  $this->object->setComment($item->getComment());
65  $this->object->setAuthor($item->getAuthor());
66  $this->object->setOwner($ilUser->getId());
67  $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
68  $this->object->setObjId($questionpool_id);
69  $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
70  $this->object->setPointsWrong($item->getMetadataEntry("points_wrong"));
71  $this->object->setErrorText($item->getMetadataEntry("errortext"));
72  $this->object->setTextSize($item->getMetadataEntry("textsize"));
73  $errordata = unserialize($item->getMetadataEntry("errordata"));
74  if (is_array($errordata))
75  {
76  foreach ($errordata as $data)
77  {
78  $this->object->addErrorData($data[1], $data[0], $data[2]);
79  }
80  }
81  $this->object->saveToDb();
82 
83  // handle the import of media objects in XHTML code
84  $questiontext = $this->object->getQuestion();
85  if (is_array($_SESSION["import_mob_xhtml"]))
86  {
87  include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
88  include_once "./Services/RTE/classes/class.ilRTE.php";
89  foreach ($_SESSION["import_mob_xhtml"] as $mob)
90  {
91  if ($tst_id > 0)
92  {
93  include_once "./Modules/Test/classes/class.ilObjTest.php";
94  $importfile = ilObjTest::_getImportDirectory() . "/" . $mob["uri"];
95  }
96  else
97  {
98  include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
99  $importfile = ilObjQuestionPool::_getImportDirectory() . "/" . $_SESSION["qpl_import_subdir"] . "/" . $mob["uri"];
100  }
101  $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
102  ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
103  $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
104  }
105  }
106  $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
107  $this->object->saveToDb();
108  if (count($item->suggested_solutions))
109  {
110  foreach ($item->suggested_solutions as $suggested_solution)
111  {
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  {
118  $q_1_id = $this->object->getId();
119  $question_id = $this->object->duplicate(true);
120  $tst_object->questions[$question_counter++] = $question_id;
121  $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
122  }
123  else
124  {
125  $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
126  }
127  }
128 }
129 
130 ?>