ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.assLongMenuImport.php
Go to the documentation of this file.
1 <?php
2 require_once 'Modules/TestQuestionPool/classes/import/qti12/class.assQuestionImport.php';
3 require_once 'Modules/TestQuestionPool/classes/class.assLongMenu.php';
4 
6 {
7  public $object;
8 
9  public function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
10  {
11  global $DIC;
12  $ilUser = $DIC['ilUser'];
13 
14  unset($_SESSION["import_mob_xhtml"]);
15 
16  $presentation = $item->getPresentation();
17  $duration = $item->getDuration();
18  $questiontext = array();
19  $seperate_question_field = $item->getMetadataEntry("question");
20  $clozetext = array();
21  $now = getdate();
22  $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
23  $answers = array();
24  $correct_answers = array();
25  $presentation = $item->getPresentation();
26  $gap_types = json_decode($item->getMetadataEntry("gapTypes"));
27  foreach ($presentation->order as $entry) {
28  switch ($entry["type"]) {
29  case "material":
30 
31  $material = $presentation->material[$entry["index"]];
32  if (preg_match('/\[Longmenu \d\]/', $this->object->QTIMaterialToString($material))) {
33  $this->object->setLongMenuTextValue($this->object->QTIMaterialToString($material));
34  } else {
35  $this->object->setQuestion($this->object->QTIMaterialToString($material));
36  }
37 
38 
39  break;
40  }
41  }
42 
43  // fixLongMenuImageImport - process images in question and long menu text when question is imported
44  $questiontext = $this->object->getQuestion();
45  $longmenutext = $this->object->getLongMenuTextValue();
46  if (is_array($_SESSION["import_mob_xhtml"]))
47  {
48  foreach ($_SESSION["import_mob_xhtml"] as $mob)
49  {
50  if ($tst_id > 0)
51  {
52  $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
53  }
54  else
55  {
56  $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
57  }
58 
59  global $DIC; /* @var ILIAS\DI\Container $DIC */
60  $DIC['ilLog']->write(__METHOD__.': import mob from dir: '. $importfile);
61 
62  $media_object = ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
63  ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
64 
65  $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
66  $longmenutext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $longmenutext);
67 
68  }
69  }
70  $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
71  $this->object->setLongMenuTextValue(ilRTE::_replaceMediaObjectImageSrc($longmenutext, 1));
72  // fau.
73 
74  foreach ($item->resprocessing as $resprocessing) {
75  foreach ($resprocessing->respcondition as $respcondition) {
76  $correctness = 1;
77  $conditionvar = $respcondition->getConditionvar();
78  foreach ($conditionvar->order as $order) {
79  switch ($order["field"]) {
80  case "varequal":
81  $equals = $conditionvar->varequal[$order["index"]]->getContent();
82  $gapident = $conditionvar->varequal[$order["index"]]->getRespident();
83  $id = $this->getIdFromGapIdent($gapident);
84  $answers[$id][] = $equals;
85  break;
86  }
87  }
88  foreach ($respcondition->setvar as $setvar) {
89  if (strcmp($gapident, "") != 0) {
90  if ($setvar->getContent() > 0) {
91  $id = $this->getIdFromGapIdent($gapident);
92  $correct_answers[$id][0][] = $equals;
93  $correct_answers[$id][1] = $setvar->getContent();
94  if (is_array($gap_types) && key_exists($id, $gap_types)) {
95  $correct_answers[$id][2] = $gap_types[$id];
96  }
97  }
98  }
99  }
100  if (count($respcondition->displayfeedback)) {
101  foreach ($respcondition->displayfeedback as $feedbackpointer) {
102  if (strlen($feedbackpointer->getLinkrefid())) {
103  foreach ($item->itemfeedback as $ifb) {
104  if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
105  // found a feedback for the identifier
106  if (count($ifb->material)) {
107  foreach ($ifb->material as $material) {
108  $feedbacksgeneric[1] = $material;
109  }
110  }
111  if ((count($ifb->flow_mat) > 0)) {
112  foreach ($ifb->flow_mat as $fmat) {
113  if (count($fmat->material)) {
114  foreach ($fmat->material as $material) {
115  $feedbacksgeneric[1] = $material;
116  }
117  }
118  }
119  }
120  } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
121  // found a feedback for the identifier
122  if (count($ifb->material)) {
123  foreach ($ifb->material as $material) {
124  $feedbacksgeneric[0] = $material;
125  }
126  }
127  if ((count($ifb->flow_mat) > 0)) {
128  foreach ($ifb->flow_mat as $fmat) {
129  if (count($fmat->material)) {
130  foreach ($fmat->material as $material) {
131  $feedbacksgeneric[0] = $material;
132  }
133  }
134  }
135  }
136  } else {
137  // found a feedback for the identifier
138  if (count($ifb->material)) {
139  foreach ($ifb->material as $material) {
140  $feedbacks[$ifb->getIdent()] = $material;
141  }
142  }
143  if ((count($ifb->flow_mat) > 0)) {
144  foreach ($ifb->flow_mat as $fmat) {
145  if (count($fmat->material)) {
146  foreach ($fmat->material as $material) {
147  $feedbacks[$ifb->getIdent()] = $material;
148  }
149  }
150  }
151  }
152  }
153  }
154  }
155  }
156  }
157  }
158  }
159 
160  $sum = 0;
161  foreach ($correct_answers as $row) {
162  $sum += $row[1];
163  }
164  $this->object->setAnswers($answers);
165  // handle the import of media objects in XHTML code
166  if (count($feedbacks) > 0) {
167  foreach ($feedbacks as $ident => $material) {
168  $m = $this->object->QTIMaterialToString($material);
169  $feedbacks[$ident] = $m;
170  }
171  }
172  if (is_array($feedbacksgeneric) && count($feedbacksgeneric) > 0) {
173  foreach ($feedbacksgeneric as $correctness => $material) {
174  $m = $this->object->QTIMaterialToString($material);
175  $feedbacksgeneric[$correctness] = $m;
176  }
177  }
178 
179  $this->addGeneralMetadata($item);
180  $this->object->setTitle($item->getTitle());
181  $this->object->setNrOfTries($item->getMaxattempts());
182  $this->object->setComment($item->getComment());
183  $this->object->setAuthor($item->getAuthor());
184  $this->object->setOwner($ilUser->getId());
185  $this->object->setObjId($questionpool_id);
186  $this->object->setMinAutoComplete($item->getMetadataEntry("minAutoCompleteLength"));
187  $this->object->setIdenticalscoring((int) $item->getMetadataEntry("identical_scoring"));
188  $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
189  $this->object->setCorrectAnswers($correct_answers);
190  $this->object->setPoints($sum);
191  // additional content editing mode information
192  $this->object->setAdditionalContentEditingMode(
194  );
195  $this->object->saveToDb();
196 
197  if (count($feedbacks) > 0) {
198  foreach ($feedbacks as $ident => $material) {
199  $this->object->feedbackOBJ->importSpecificAnswerFeedback(
200  $this->object->getId(),
201  0,
202  $ident,
204  );
205  }
206  }
207  if (is_array($feedbacksgeneric) && count($feedbacksgeneric) > 0) {
208  foreach ($feedbacksgeneric as $correctness => $material) {
209  $this->object->feedbackOBJ->importGenericFeedback(
210  $this->object->getId(),
211  $correctness,
213  );
214  }
215  }
216  $this->object->saveToDb();
217  if (count($item->suggested_solutions)) {
218  foreach ($item->suggested_solutions as $suggested_solution) {
219  $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
220  }
221  $this->object->saveToDb();
222  }
223 
224  if ($tst_id > 0) {
225  $q_1_id = $this->object->getId();
226  $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
227  $tst_object->questions[$question_counter++] = $question_id;
228  $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
229  } else {
230  $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
231  }
232  }
233 
234  private function getIdFromGapIdent($ident)
235  {
236  $id = preg_split('/_/', $ident);
237  return $id[1] - 1;
238  }
239 }
addGeneralMetadata(ilQTIItem $item)
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
$_SESSION["AccountId"]
global $DIC
Definition: saml.php:7
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
if(!array_key_exists('StateId', $_REQUEST)) $id
getQplImportArchivDirectory()
returns the full path to extracted qpl import archiv (qpl import dir + qpl archiv subdir) ...
static _saveTempFileAsMediaObject($name, $tmp_name, $upload=true)
Create new media object and update page in db and return new media object.
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...
$ilUser
Definition: imgupload.php:18
$row
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.