ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 $ilUser;
12 
13  unset($_SESSION["import_mob_xhtml"]);
14 
15  $presentation = $item->getPresentation();
16  $duration = $item->getDuration();
17  $questiontext = array();
18  $seperate_question_field = $item->getMetadataEntry("question");
19  $clozetext = array();
20  $now = getdate();
21  $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
22  $answers = array();
23  $correct_answers = array();
24  $presentation = $item->getPresentation();
25  $gap_types = json_decode($item->getMetadataEntry("gapTypes"));
26  foreach ($presentation->order as $entry)
27  {
28  switch ($entry["type"])
29  {
30  case "material":
31 
32  $material = $presentation->material[$entry["index"]];
33  if(preg_match('/\[Longmenu \d\]/', $this->object->QTIMaterialToString($material)))
34  {
35  $this->object->setLongMenuTextValue($this->object->QTIMaterialToString($material));
36  }
37  else
38  {
39  $this->object->setQuestion($this->object->QTIMaterialToString($material));
40  }
41 
42 
43  break;
44  }
45  }
46  foreach ($item->resprocessing as $resprocessing)
47  {
48  foreach ($resprocessing->respcondition as $respcondition)
49  {
50  $correctness = 1;
51  $conditionvar = $respcondition->getConditionvar();
52  foreach ($conditionvar->order as $order)
53  {
54  switch ($order["field"])
55  {
56  case "varequal":
57  $equals = $conditionvar->varequal[$order["index"]]->getContent();
58  $gapident = $conditionvar->varequal[$order["index"]]->getRespident();
59  $id = $this->getIdFromGapIdent($gapident);
60  $answers[$id][] = $equals;
61  break;
62  }
63  }
64  foreach ($respcondition->setvar as $setvar)
65  {
66  if (strcmp($gapident, "") != 0)
67  {
68  if($setvar->getContent() > 0 )
69  {
70  $id = $this->getIdFromGapIdent($gapident);
71  $correct_answers[$id][0][] = $equals;
72  $correct_answers[$id][1] = $setvar->getContent();
73  if(is_array($gap_types) && key_exists($id, $gap_types))
74  {
75  $correct_answers[$id][2] = $gap_types[$id];
76  }
77  }
78  }
79  }
80  if (count($respcondition->displayfeedback))
81  {
82  foreach ($respcondition->displayfeedback as $feedbackpointer)
83  {
84  if (strlen($feedbackpointer->getLinkrefid()))
85  {
86  foreach ($item->itemfeedback as $ifb)
87  {
88  if (strcmp($ifb->getIdent(), "response_allcorrect") == 0)
89  {
90  // found a feedback for the identifier
91  if (count($ifb->material))
92  {
93  foreach ($ifb->material as $material)
94  {
95  $feedbacksgeneric[1] = $material;
96  }
97  }
98  if ((count($ifb->flow_mat) > 0))
99  {
100  foreach ($ifb->flow_mat as $fmat)
101  {
102  if (count($fmat->material))
103  {
104  foreach ($fmat->material as $material)
105  {
106  $feedbacksgeneric[1] = $material;
107  }
108  }
109  }
110  }
111  }
112  else if (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0)
113  {
114  // found a feedback for the identifier
115  if (count($ifb->material))
116  {
117  foreach ($ifb->material as $material)
118  {
119  $feedbacksgeneric[0] = $material;
120  }
121  }
122  if ((count($ifb->flow_mat) > 0))
123  {
124  foreach ($ifb->flow_mat as $fmat)
125  {
126  if (count($fmat->material))
127  {
128  foreach ($fmat->material as $material)
129  {
130  $feedbacksgeneric[0] = $material;
131  }
132  }
133  }
134  }
135  }
136  else
137  {
138  // found a feedback for the identifier
139  if (count($ifb->material))
140  {
141  foreach ($ifb->material as $material)
142  {
143  $feedbacks[$ifb->getIdent()] = $material;
144  }
145  }
146  if ((count($ifb->flow_mat) > 0))
147  {
148  foreach ($ifb->flow_mat as $fmat)
149  {
150  if (count($fmat->material))
151  {
152  foreach ($fmat->material as $material)
153  {
154  $feedbacks[$ifb->getIdent()] = $material;
155  }
156  }
157  }
158  }
159 
160  }
161  }
162  }
163  }
164  }
165 
166  }
167  }
168 
169  $sum = 0;
170  foreach ($correct_answers as $row)
171  {
172  $sum += $row[1];
173  }
174  $this->object->setAnswers($answers);
175  // handle the import of media objects in XHTML code
176  if(count($feedbacks) > 0)
177  {
178  foreach($feedbacks as $ident => $material)
179  {
180  $m = $this->object->QTIMaterialToString($material);
181  $feedbacks[$ident] = $m;
182  }
183  }
184  if(count($feedbacksgeneric) > 0)
185  {
186  foreach ($feedbacksgeneric as $correctness => $material)
187  {
188  $m = $this->object->QTIMaterialToString($material);
189  $feedbacksgeneric[$correctness] = $m;
190  }
191  }
192 
193  $this->addGeneralMetadata($item);
194  $this->object->setTitle($item->getTitle());
195  $this->object->setNrOfTries($item->getMaxattempts());
196  $this->object->setComment($item->getComment());
197  $this->object->setAuthor($item->getAuthor());
198  $this->object->setOwner($ilUser->getId());
199  $this->object->setObjId($questionpool_id);
200  $this->object->setMinAutoComplete($item->getMetadataEntry("minAutoCompleteLength"));
201  $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
202  $this->object->setCorrectAnswers($correct_answers);
203  $this->object->setPoints($sum);
204  // additional content editing mode information
205  $this->object->setAdditionalContentEditingMode(
207  );
208  $this->object->saveToDb();
209 
210  if(count($feedbacks) > 0)
211  {
212  foreach($feedbacks as $ident => $material)
213  {
214  $this->object->feedbackOBJ->importSpecificAnswerFeedback(
215  $this->object->getId(), $ident, ilRTE::_replaceMediaObjectImageSrc($material, 1)
216  );
217  }
218  }
219  if(count($feedbacksgeneric) > 0)
220  {
221  foreach($feedbacksgeneric as $correctness => $material)
222  {
223  $this->object->feedbackOBJ->importGenericFeedback(
224  $this->object->getId(), $correctness, ilRTE::_replaceMediaObjectImageSrc($material, 1)
225  );
226  }
227  }
228  $this->object->saveToDb();
229  if (count($item->suggested_solutions))
230  {
231  foreach ($item->suggested_solutions as $suggested_solution)
232  {
233  $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
234  }
235  $this->object->saveToDb();
236  }
237 
238  if ($tst_id > 0)
239  {
240  $q_1_id = $this->object->getId();
241  $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
242  $tst_object->questions[$question_counter++] = $question_id;
243  $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
244  }
245  else
246  {
247  $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
248  }
249  }
250 
251  private function getIdFromGapIdent($ident)
252  {
253  $id = preg_split('/_/', $ident);
254  return $id[1] -1;
255  }
256 }
257 
addGeneralMetadata(ilQTIItem $item)
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
$_SESSION["AccountId"]
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
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
Create styles array
The data for the language used.
Create new PHPExcel object
obj_idprivate
Class for question imports.