ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assTextSubsetImport.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  $shuffle = 0;
59  $idents = array();
60  $now = getdate();
61  $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
62  $gaps = array();
63  foreach ($presentation->order as $entry)
64  {
65  switch ($entry["type"])
66  {
67  case "response":
68  $response = $presentation->response[$entry["index"]];
69  if ($response->getResponseType() == RT_RESPONSE_STR)
70  {
71  array_push($idents, $response->getIdent());
72  }
73  break;
74  }
75  }
76  $responses = array();
77  $feedbacksgeneric = array();
78  foreach ($item->resprocessing as $resprocessing)
79  {
80  foreach ($resprocessing->respcondition as $respcondition)
81  {
82  $ident = "";
83  $correctness = 1;
84  $conditionvar = $respcondition->getConditionvar();
85  foreach ($conditionvar->order as $order)
86  {
87  switch ($order["field"])
88  {
89  case "varsubset":
90  $respident = $conditionvar->varsubset[$order["index"]]->getRespident();
91  $content = $conditionvar->varsubset[$order["index"]]->getContent();
92  if (!is_array($responses[$respident])) $responses[$respident] = array();
93  $vars = split(",", $content);
94  foreach ($vars as $var)
95  {
96  array_push($responses[$respident], array("solution" => $var, "points" => ""));
97  }
98  break;
99  }
100  }
101  foreach ($respcondition->setvar as $setvar)
102  {
103  if ((strcmp($setvar->getVarname(), "matches") == 0) && ($setvar->getAction() == ACTION_ADD))
104  {
105  foreach ($responses[$respident] as $idx => $solutionarray)
106  {
107  if (strlen($solutionarray["points"] == 0))
108  {
109  $responses[$respident][$idx]["points"] = $setvar->getContent();
110  }
111  }
112  }
113  }
114  foreach ($resprocessing->respcondition as $respcondition)
115  {
116  foreach ($respcondition->displayfeedback as $feedbackpointer)
117  {
118  if (strlen($feedbackpointer->getLinkrefid()))
119  {
120  foreach ($item->itemfeedback as $ifb)
121  {
122  if (strcmp($ifb->getIdent(), "response_allcorrect") == 0)
123  {
124  // found a feedback for the identifier
125  if (count($ifb->material))
126  {
127  foreach ($ifb->material as $material)
128  {
129  $feedbacksgeneric[1] = $material;
130  }
131  }
132  if ((count($ifb->flow_mat) > 0))
133  {
134  foreach ($ifb->flow_mat as $fmat)
135  {
136  if (count($fmat->material))
137  {
138  foreach ($fmat->material as $material)
139  {
140  $feedbacksgeneric[1] = $material;
141  }
142  }
143  }
144  }
145  }
146  else if (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0)
147  {
148  // found a feedback for the identifier
149  if (count($ifb->material))
150  {
151  foreach ($ifb->material as $material)
152  {
153  $feedbacksgeneric[0] = $material;
154  }
155  }
156  if ((count($ifb->flow_mat) > 0))
157  {
158  foreach ($ifb->flow_mat as $fmat)
159  {
160  if (count($fmat->material))
161  {
162  foreach ($fmat->material as $material)
163  {
164  $feedbacksgeneric[0] = $material;
165  }
166  }
167  }
168  }
169  }
170  }
171  }
172  }
173  }
174  }
175  }
176 
177  $this->object->setTitle($item->getTitle());
178  $this->object->setExternalID($item->getMetadataEntry("externalID"));
179  $this->object->setNrOfTries($item->getMaxattempts());
180  $this->object->setComment($item->getComment());
181  $this->object->setAuthor($item->getAuthor());
182  $this->object->setOwner($ilUser->getId());
183  $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
184  $this->object->setObjId($questionpool_id);
185  $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
186  $textrating = $item->getMetadataEntry("textrating");
187  if (strlen($textrating) == 0) $textrating = "ci";
188  $this->object->setTextRating($textgap_rating);
189  $this->object->setCorrectAnswers($item->getMetadataEntry("correctanswers"));
190  $response = current($responses);
191  $counter = 0;
192  if (is_array($response))
193  {
194  foreach ($response as $answer)
195  {
196  $this->object->addAnswer($answer["solution"], $answer["points"], $counter);
197  $counter++;
198  }
199  }
200  $this->object->saveToDb();
201  if (count($item->suggested_solutions))
202  {
203  foreach ($item->suggested_solutions as $suggested_solution)
204  {
205  $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
206  }
207  $this->object->saveToDb();
208  }
209  foreach ($feedbacksgeneric as $correctness => $material)
210  {
211  $m = $this->object->QTIMaterialToString($material);
212  $feedbacksgeneric[$correctness] = $m;
213  }
214  // handle the import of media objects in XHTML code
215  $questiontext = $this->object->getQuestion();
216  if (is_array($_SESSION["import_mob_xhtml"]))
217  {
218  include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
219  include_once "./Services/RTE/classes/class.ilRTE.php";
220  foreach ($_SESSION["import_mob_xhtml"] as $mob)
221  {
222  if ($tst_id > 0)
223  {
224  include_once "./Modules/Test/classes/class.ilObjTest.php";
225  $importfile = ilObjTest::_getImportDirectory() . "/" . $mob["uri"];
226  }
227  else
228  {
229  include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
230  $importfile = ilObjQuestionPool::_getImportDirectory() . "/" . $_SESSION["qpl_import_subdir"] . "/" . $mob["uri"];
231  }
232  $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
233  ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
234  $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
235  foreach ($feedbacksgeneric as $correctness => $material)
236  {
237  $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
238  }
239  }
240  }
241  $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
242  foreach ($feedbacksgeneric as $correctness => $material)
243  {
244  $this->object->saveFeedbackGeneric($correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1));
245  }
246  $this->object->saveToDb();
247  if ($tst_id > 0)
248  {
249  $q_1_id = $this->object->getId();
250  $question_id = $this->object->duplicate(true);
251  $tst_object->questions[$question_counter++] = $question_id;
252  $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
253  }
254  else
255  {
256  $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
257  }
258  }
259 }
260 
261 ?>