ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assTextQuestionImport.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 
36 {
50  function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
51  {
52  global $ilUser;
53 
54  // empty session variable for imported xhtml mobs
55  unset($_SESSION["import_mob_xhtml"]);
56  $presentation = $item->getPresentation();
57  $duration = $item->getDuration();
58  $now = getdate();
59  $maxchars = 0;
60  $maxpoints = 0;
61  $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
62  foreach ($presentation->order as $entry)
63  {
64  switch ($entry["type"])
65  {
66  case "response":
67  $response = $presentation->response[$entry["index"]];
68  $rendertype = $response->getRenderType();
69  switch (strtolower(get_class($rendertype)))
70  {
71  case "ilqtirenderfib":
72  $maxchars = $rendertype->getMaxchars();
73  break;
74  }
75  break;
76  }
77  }
78 
79  $feedbacksgeneric = array();
80  foreach ($item->resprocessing as $resprocessing)
81  {
82  $outcomes = $resprocessing->getOutcomes();
83  foreach ($outcomes->decvar as $decvar)
84  {
85  $maxpoints = $decvar->getMaxvalue();
86  }
87 
88  foreach ($resprocessing->respcondition as $respcondition)
89  {
90  foreach ($respcondition->displayfeedback as $feedbackpointer)
91  {
92  if (strlen($feedbackpointer->getLinkrefid()))
93  {
94  foreach ($item->itemfeedback as $ifb)
95  {
96  if (strcmp($ifb->getIdent(), "response_allcorrect") == 0)
97  {
98  // found a feedback for the identifier
99  if (count($ifb->material))
100  {
101  foreach ($ifb->material as $material)
102  {
103  $feedbacksgeneric[1] = $material;
104  }
105  }
106  if ((count($ifb->flow_mat) > 0))
107  {
108  foreach ($ifb->flow_mat as $fmat)
109  {
110  if (count($fmat->material))
111  {
112  foreach ($fmat->material as $material)
113  {
114  $feedbacksgeneric[1] = $material;
115  }
116  }
117  }
118  }
119  }
120  else if (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0)
121  {
122  // found a feedback for the identifier
123  if (count($ifb->material))
124  {
125  foreach ($ifb->material as $material)
126  {
127  $feedbacksgeneric[0] = $material;
128  }
129  }
130  if ((count($ifb->flow_mat) > 0))
131  {
132  foreach ($ifb->flow_mat as $fmat)
133  {
134  if (count($fmat->material))
135  {
136  foreach ($fmat->material as $material)
137  {
138  $feedbacksgeneric[0] = $material;
139  }
140  }
141  }
142  }
143  }
144  }
145  }
146  }
147  }
148  }
149 
150  $this->object->setTitle($item->getTitle());
151  $this->object->setExternalID($item->getMetadataEntry("externalID"));
152  $this->object->setNrOfTries($item->getMaxattempts());
153  $this->object->setComment($item->getComment());
154  $this->object->setAuthor($item->getAuthor());
155  $this->object->setOwner($ilUser->getId());
156  $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
157  $this->object->setObjId($questionpool_id);
158  $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
159  $this->object->setPoints($maxpoints);
160  $this->object->setMaxNumOfChars($maxchars);
161  $textrating = $item->getMetadataEntry("textrating");
162  if (strlen($textrating))
163  {
164  $this->object->setTextRating($textrating);
165  }
166  $this->object->matchcondition = (strlen($item->getMetadataEntry('matchcondition'))) ? $item->getMetadataEntry('matchcondition') : 0;
167  $keywords = $item->getMetadataEntry("keywords");
168  if (strlen($keywords))
169  {
170  $this->object->setKeywords($keywords);
171  }
172  $this->object->saveToDb();
173  if (count($item->suggested_solutions))
174  {
175  foreach ($item->suggested_solutions as $suggested_solution)
176  {
177  $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
178  }
179  $this->object->saveToDb();
180  }
181  foreach ($feedbacksgeneric as $correctness => $material)
182  {
183  $m = $this->object->QTIMaterialToString($material);
184  $feedbacksgeneric[$correctness] = $m;
185  }
186  // handle the import of media objects in XHTML code
187  $questiontext = $this->object->getQuestion();
188  if (is_array($_SESSION["import_mob_xhtml"]))
189  {
190  include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
191  include_once "./Services/RTE/classes/class.ilRTE.php";
192  foreach ($_SESSION["import_mob_xhtml"] as $mob)
193  {
194  if ($tst_id > 0)
195  {
196  include_once "./Modules/Test/classes/class.ilObjTest.php";
197  $importfile = ilObjTest::_getImportDirectory() . "/" . $mob["uri"];
198  }
199  else
200  {
201  include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
202  $importfile = ilObjQuestionPool::_getImportDirectory() . "/" . $_SESSION["qpl_import_subdir"] . "/" . $mob["uri"];
203  }
204  $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
205  ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
206  $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
207  foreach ($feedbacksgeneric as $correctness => $material)
208  {
209  $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
210  }
211  }
212  }
213  $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
214  foreach ($feedbacksgeneric as $correctness => $material)
215  {
216  $this->object->saveFeedbackGeneric($correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1));
217  }
218  $this->object->saveToDb();
219  if ($tst_id > 0)
220  {
221  $q_1_id = $this->object->getId();
222  $question_id = $this->object->duplicate(true);
223  $tst_object->questions[$question_counter++] = $question_id;
224  $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
225  }
226  else
227  {
228  $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
229  }
230  }
231 }
232 
233 ?>