ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.assNumericImport.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  public function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
31  {
32  global $DIC;
33  $ilUser = $DIC['ilUser'];
34 
35  // empty session variable for imported xhtml mobs
36  unset($_SESSION["import_mob_xhtml"]);
37  $presentation = $item->getPresentation();
38  $duration = $item->getDuration();
39  $now = getdate();
40  $maxchars = 0;
41  $points = 0;
42  $upperlimit = 0;
43  $lowerlimit = 0;
44  $feedbacksgeneric = array();
45  $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
46  foreach ($presentation->order as $entry) {
47  switch ($entry["type"]) {
48  case "response":
49  $response = $presentation->response[$entry["index"]];
50  $rendertype = $response->getRenderType();
51  switch (strtolower(get_class($rendertype))) {
52  case "ilqtirenderfib":
53  $maxchars = $rendertype->getMaxchars();
54  break;
55  }
56  break;
57  }
58  }
59 
60  foreach ($item->resprocessing as $resprocessing) {
61  foreach ($resprocessing->respcondition as $respcondition) {
62  $conditionvar = $respcondition->getConditionvar();
63  foreach ($conditionvar->order as $order) {
64  switch ($order["field"]) {
65  case "varlte":
66  $upperlimit = $conditionvar->varlte[$order["index"]]->getContent();
67  break;
68  case "vargte":
69  $lowerlimit = $conditionvar->vargte[$order["index"]]->getContent();
70  break;
71  }
72  }
73  foreach ($respcondition->setvar as $setvar) {
74  $points = $setvar->getContent();
75  }
76  if (count($respcondition->displayfeedback)) {
77  foreach ($respcondition->displayfeedback as $feedbackpointer) {
78  if (strlen($feedbackpointer->getLinkrefid())) {
79  foreach ($item->itemfeedback as $ifb) {
80  if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
81  // found a feedback for the identifier
82  if (count($ifb->material)) {
83  foreach ($ifb->material as $material) {
84  $feedbacksgeneric[1] = $material;
85  }
86  }
87  if ((count($ifb->flow_mat) > 0)) {
88  foreach ($ifb->flow_mat as $fmat) {
89  if (count($fmat->material)) {
90  foreach ($fmat->material as $material) {
91  $feedbacksgeneric[1] = $material;
92  }
93  }
94  }
95  }
96  } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
97  // found a feedback for the identifier
98  if (count($ifb->material)) {
99  foreach ($ifb->material as $material) {
100  $feedbacksgeneric[0] = $material;
101  }
102  }
103  if ((count($ifb->flow_mat) > 0)) {
104  foreach ($ifb->flow_mat as $fmat) {
105  if (count($fmat->material)) {
106  foreach ($fmat->material as $material) {
107  $feedbacksgeneric[0] = $material;
108  }
109  }
110  }
111  }
112  }
113  }
114  }
115  }
116  }
117  }
118  }
119 
120  $this->addGeneralMetadata($item);
121  $this->object->setTitle($item->getTitle());
122  $this->object->setNrOfTries($item->getMaxattempts());
123  $this->object->setComment($item->getComment());
124  $this->object->setAuthor($item->getAuthor());
125  $this->object->setOwner($ilUser->getId());
126  $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
127  $this->object->setObjId($questionpool_id);
128  $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
129  $this->object->setMaxChars($maxchars);
130  $this->object->setPoints($points);
131  $this->object->setLowerLimit($lowerlimit);
132  $this->object->setUpperLimit($upperlimit);
133  // additional content editing mode information
134  $this->object->setAdditionalContentEditingMode(
136  );
137  $this->object->saveToDb();
138  if (count($item->suggested_solutions)) {
139  foreach ($item->suggested_solutions as $suggested_solution) {
140  $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
141  }
142  $this->object->saveToDb();
143  }
144  foreach ($feedbacksgeneric as $correctness => $material) {
145  $m = $this->object->QTIMaterialToString($material);
146  $feedbacksgeneric[$correctness] = $m;
147  }
148  // handle the import of media objects in XHTML code
149  $questiontext = $this->object->getQuestion();
150  if (is_array($_SESSION["import_mob_xhtml"])) {
151  include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
152  include_once "./Services/RTE/classes/class.ilRTE.php";
153  foreach ($_SESSION["import_mob_xhtml"] as $mob) {
154  if ($tst_id > 0) {
155  $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
156  } else {
157  $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
158  }
159 
160  global $DIC; /* @var ILIAS\DI\Container $DIC */
161  $DIC['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
162 
163  $media_object = &ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);
164  ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
165  $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
166  foreach ($feedbacksgeneric as $correctness => $material) {
167  $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
168  }
169  }
170  }
171  $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
172  foreach ($feedbacksgeneric as $correctness => $material) {
173  $this->object->feedbackOBJ->importGenericFeedback(
174  $this->object->getId(),
175  $correctness,
177  );
178  }
179  $this->object->saveToDb();
180  if ($tst_id > 0) {
181  $q_1_id = $this->object->getId();
182  $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
183  $tst_object->questions[$question_counter++] = $question_id;
184  $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
185  } else {
186  $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
187  }
188  }
189 }
Class for numeric question imports.
addGeneralMetadata(ilQTIItem $item)
$_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_...
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
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
Creates a question from a QTI file.
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) ...
Class for question imports.
$response
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.