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