ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.assOrderingHorizontalImport.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  $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
41 
42  $this->addGeneralMetadata($item);
43  $this->object->setTitle($item->getTitle());
44  $this->object->setNrOfTries($item->getMaxattempts());
45  $this->object->setComment($item->getComment());
46  $this->object->setAuthor($item->getAuthor());
47  $this->object->setOwner($ilUser->getId());
48  $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
49  $this->object->setObjId($questionpool_id);
50  $this->object->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
51  $this->object->setPoints($item->getMetadataEntry("points"));
52  $this->object->setOrderText($item->getMetadataEntry("ordertext"));
53  $this->object->setTextSize($item->getMetadataEntry("textsize"));
54  $this->object->setSeparator($item->getMetadataEntry("separator"));
55  // additional content editing mode information
56  $this->object->setAdditionalContentEditingMode(
58  );
59  $this->object->saveToDb();
60 
61  $feedbacks = $this->getFeedbackAnswerSpecific($item);
62  $feedbacksgeneric = $this->getFeedbackGeneric($item);
63 
64  // handle the import of media objects in XHTML code
65  $questiontext = $this->object->getQuestion();
66  if (is_array($_SESSION["import_mob_xhtml"])) {
67  include_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php";
68  include_once "./Services/RTE/classes/class.ilRTE.php";
69  foreach ($_SESSION["import_mob_xhtml"] as $mob) {
70  if ($tst_id > 0) {
71  $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
72  } else {
73  $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
74  }
75 
76  global $DIC; /* @var ILIAS\DI\Container $DIC */
77  $DIC['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
78 
79  $media_object = &ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);
80  ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
81  $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
82 
83  foreach ($feedbacks as $ident => $material) {
84  $feedbacks[$ident] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
85  }
86  foreach ($feedbacksgeneric as $correctness => $material) {
87  $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
88  }
89  }
90  }
91  $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
92 
93  foreach ($feedbacks as $ident => $material) {
94  $index = $this->fetchIndexFromFeedbackIdent($ident);
95 
96  $this->object->feedbackOBJ->importSpecificAnswerFeedback(
97  $this->object->getId(),
98  0,
99  $index,
101  );
102  }
103  foreach ($feedbacksgeneric as $correctness => $material) {
104  $this->object->feedbackOBJ->importGenericFeedback(
105  $this->object->getId(),
106  $correctness,
108  );
109  }
110 
111  $this->object->saveToDb();
112  if (count($item->suggested_solutions)) {
113  foreach ($item->suggested_solutions as $suggested_solution) {
114  $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
115  }
116  $this->object->saveToDb();
117  }
118  if ($tst_id > 0) {
119  $q_1_id = $this->object->getId();
120  $question_id = $this->object->duplicate(true, null, null, null, $tst_id);
121  $tst_object->questions[$question_counter++] = $question_id;
122  $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
123  } else {
124  $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
125  }
126  }
127 }
getFeedbackAnswerSpecific(ilQTIItem $item, $prefix='response_')
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) ...
$index
Definition: metadata.php:60
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...
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
Creates a question from a QTI file.
$ilUser
Definition: imgupload.php:18
Class for formula question imports.
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.
fetchIndexFromFeedbackIdent($feedbackIdent, $prefix='response_')