ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.assTextSubsetImport.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once "./Modules/TestQuestionPool/classes/import/qti12/class.assQuestionImport.php";
5 
16 {
30  function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
31  {
32  global $ilUser;
33 
34  // empty session variable for imported xhtml mobs
35  unset($_SESSION["import_mob_xhtml"]);
36  $presentation = $item->getPresentation();
37  $duration = $item->getDuration();
38  $shuffle = 0;
39  $idents = array();
40  $now = getdate();
41  $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
42  $gaps = array();
43  foreach ($presentation->order as $entry)
44  {
45  switch ($entry["type"])
46  {
47  case "response":
48  $response = $presentation->response[$entry["index"]];
49  if ($response->getResponseType() == RT_RESPONSE_STR)
50  {
51  array_push($idents, $response->getIdent());
52  }
53  break;
54  }
55  }
56  $responses = array();
57  $feedbacksgeneric = array();
58  foreach ($item->resprocessing as $resprocessing)
59  {
60  foreach ($resprocessing->respcondition as $respcondition)
61  {
62  $ident = "";
63  $correctness = 1;
64  $conditionvar = $respcondition->getConditionvar();
65  foreach ($conditionvar->order as $order)
66  {
67  switch ($order["field"])
68  {
69  case "varsubset":
70  $respident = $conditionvar->varsubset[$order["index"]]->getRespident();
71  $content = $conditionvar->varsubset[$order["index"]]->getContent();
72  if (!is_array($responses[$respident])) $responses[$respident] = array();
73  $vars = explode(",", $content);
74  foreach ($vars as $var)
75  {
76  array_push($responses[$respident], array("solution" => $var, "points" => ""));
77  }
78  break;
79  }
80  }
81  foreach ($respcondition->setvar as $setvar)
82  {
83  if ((strcmp($setvar->getVarname(), "matches") == 0) && ($setvar->getAction() == ACTION_ADD))
84  {
85  foreach ($responses[$respident] as $idx => $solutionarray)
86  {
87  if (strlen($solutionarray["points"] == 0))
88  {
89  $responses[$respident][$idx]["points"] = $setvar->getContent();
90  }
91  }
92  }
93  }
94  foreach ($resprocessing->respcondition as $respcondition)
95  {
96  foreach ($respcondition->displayfeedback as $feedbackpointer)
97  {
98  if (strlen($feedbackpointer->getLinkrefid()))
99  {
100  foreach ($item->itemfeedback as $ifb)
101  {
102  if (strcmp($ifb->getIdent(), "response_allcorrect") == 0)
103  {
104  // found a feedback for the identifier
105  if (count($ifb->material))
106  {
107  foreach ($ifb->material as $material)
108  {
109  $feedbacksgeneric[1] = $material;
110  }
111  }
112  if ((count($ifb->flow_mat) > 0))
113  {
114  foreach ($ifb->flow_mat as $fmat)
115  {
116  if (count($fmat->material))
117  {
118  foreach ($fmat->material as $material)
119  {
120  $feedbacksgeneric[1] = $material;
121  }
122  }
123  }
124  }
125  }
126  else if (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0)
127  {
128  // found a feedback for the identifier
129  if (count($ifb->material))
130  {
131  foreach ($ifb->material as $material)
132  {
133  $feedbacksgeneric[0] = $material;
134  }
135  }
136  if ((count($ifb->flow_mat) > 0))
137  {
138  foreach ($ifb->flow_mat as $fmat)
139  {
140  if (count($fmat->material))
141  {
142  foreach ($fmat->material as $material)
143  {
144  $feedbacksgeneric[0] = $material;
145  }
146  }
147  }
148  }
149  }
150  }
151  }
152  }
153  }
154  }
155  }
156  $this->addGeneralMetadata($item);
157  $this->object->setTitle($item->getTitle());
158  $this->object->setNrOfTries($item->getMaxattempts());
159  $this->object->setComment($item->getComment());
160  $this->object->setAuthor($item->getAuthor());
161  $this->object->setOwner($ilUser->getId());
162  $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
163  $this->object->setObjId($questionpool_id);
164  $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
165  $textrating = $item->getMetadataEntry("textrating");
166  if (strlen($textrating) == 0) $textrating = "ci";
167  $this->object->setTextRating($textrating);
168  $this->object->setCorrectAnswers($item->getMetadataEntry("correctanswers"));
169  $response = current($responses);
170  $counter = 0;
171  if (is_array($response))
172  {
173  foreach ($response as $answer)
174  {
175  $this->object->addAnswer($answer["solution"], $answer["points"], $counter);
176  $counter++;
177  }
178  }
179  // additional content editing mode information
180  $this->object->setAdditionalContentEditingMode(
182  );
183  $this->object->saveToDb();
184  if (count($item->suggested_solutions))
185  {
186  foreach ($item->suggested_solutions as $suggested_solution)
187  {
188  $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
189  }
190  $this->object->saveToDb();
191  }
192  foreach ($feedbacksgeneric as $correctness => $material)
193  {
194  $m = $this->object->QTIMaterialToString($material);
195  $feedbacksgeneric[$correctness] = $m;
196  }
197  // handle the import of media objects in XHTML code
198  $questiontext = $this->object->getQuestion();
199  if (is_array($_SESSION["import_mob_xhtml"]))
200  {
201  include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
202  include_once "./Services/RTE/classes/class.ilRTE.php";
203  foreach ($_SESSION["import_mob_xhtml"] as $mob)
204  {
205  if ($tst_id > 0)
206  {
207  $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
208  }
209  else
210  {
211  $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
212  }
213 
214  $GLOBALS['ilLog']->write(__METHOD__.': import mob from dir: '. $importfile);
215 
216  $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
217  ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
218  $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
219  foreach ($feedbacksgeneric as $correctness => $material)
220  {
221  $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
222  }
223  }
224  }
225  $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
226  foreach ($feedbacksgeneric as $correctness => $material)
227  {
228  $this->object->feedbackOBJ->importGenericFeedback(
229  $this->object->getId(), $correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1)
230  );
231  }
232  $this->object->saveToDb();
233  if ($tst_id > 0)
234  {
235  $q_1_id = $this->object->getId();
236  $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
237  $tst_object->questions[$question_counter++] = $question_id;
238  $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
239  }
240  else
241  {
242  $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
243  }
244  }
245 }
246 
247 ?>
Class for text subset question imports.
addGeneralMetadata(ilQTIItem $item)
$_SESSION["AccountId"]
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
const RT_RESPONSE_STR
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
getQplImportArchivDirectory()
returns the full path to extracted qpl import archiv (qpl import dir + qpl archiv subdir) ...
static _replaceMediaObjectImageSrc($a_text, $a_direction=0, $nic=IL_INST_ID)
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
$counter
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
Creates a question from a QTI file.
static _saveTempFileAsMediaObject($name, $tmp_name, $upload=TRUE)
Create new media object and update page in db and return new media object.
const ACTION_ADD
$ilUser
Definition: imgupload.php:18
Create styles array
The data for the language used.
Create new PHPExcel object
obj_idprivate
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) ...
Class for question imports.
static _saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr=0, $a_lang="-")
Save usage of mob within another container (e.g.