ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.assOrderingHorizontalImport.php
Go to the documentation of this file.
1 <?php
2 
29 {
43  public function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, $import_mapping): array
44  {
45  global $DIC;
46  $ilUser = $DIC['ilUser'];
47 
48  // empty session variable for imported xhtml mobs
49  ilSession::clear('import_mob_xhtml');
50 
51  $presentation = $item->getPresentation();
52  $now = getdate();
53  $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
54 
55  $this->addGeneralMetadata($item);
56  $this->object->setTitle($item->getTitle());
57  $this->object->setNrOfTries((int) $item->getMaxattempts());
58  $this->object->setComment($item->getComment());
59  $this->object->setAuthor($item->getAuthor());
60  $this->object->setOwner($ilUser->getId());
61  $this->object->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
62  $this->object->setObjId($questionpool_id);
63  $this->object->setPoints($item->getMetadataEntry("points"));
64  $this->object->setOrderText($item->getMetadataEntry("ordertext"));
65  $this->object->setTextSize($item->getMetadataEntry("textsize"));
66  $this->object->setSeparator($item->getMetadataEntry("separator"));
67  // additional content editing mode information
68  $this->object->setAdditionalContentEditingMode(
70  );
71  $this->object->saveToDb();
72 
73  $feedbacks = $this->getFeedbackAnswerSpecific($item);
74  $feedbacksgeneric = $this->getFeedbackGeneric($item);
75 
76  // handle the import of media objects in XHTML code
77  $questiontext = $this->object->getQuestion();
78  if (is_array(ilSession::get("import_mob_xhtml"))) {
79  foreach (ilSession::get("import_mob_xhtml") as $mob) {
80  if ($tst_id > 0) {
81  $importfile = $this->getTstImportArchivDirectory() . '/' . $mob["uri"];
82  } else {
83  $importfile = $this->getQplImportArchivDirectory() . '/' . $mob["uri"];
84  }
85 
86  global $DIC; /* @var ILIAS\DI\Container $DIC */
87  $DIC['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
88 
89  $media_object = ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);
90  ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
91  $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
92 
93  foreach ($feedbacks as $ident => $material) {
94  $feedbacks[$ident] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
95  }
96  foreach ($feedbacksgeneric as $correctness => $material) {
97  $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
98  }
99  }
100  }
101  $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
102 
103  foreach ($feedbacks as $ident => $material) {
104  $index = $this->fetchIndexFromFeedbackIdent($ident);
105 
106  $this->object->feedbackOBJ->importSpecificAnswerFeedback(
107  $this->object->getId(),
108  0,
109  $index,
111  );
112  }
113  foreach ($feedbacksgeneric as $correctness => $material) {
114  $this->object->feedbackOBJ->importGenericFeedback(
115  $this->object->getId(),
116  $correctness,
118  );
119  }
120 
121  $this->object->saveToDb();
122  if (count($item->suggested_solutions)) {
123  foreach ($item->suggested_solutions as $suggested_solution) {
124  $this->object->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
125  }
126  $this->object->saveToDb();
127  }
128  if ($tst_id > 0) {
129  $q_1_id = $this->object->getId();
130  $question_id = $this->object->duplicate(true, "", "", "", $tst_id);
131  $tst_object->questions[$question_counter++] = $question_id;
132  $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
133  } else {
134  $import_mapping[$item->getIdent()] = array("pool" => $this->object->getId(), "test" => 0);
135  }
136  return $import_mapping;
137  }
138 }
static _replaceMediaObjectImageSrc(string $a_text, int $a_direction=0, string $nic='')
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
static get(string $a_var)
getFeedbackAnswerSpecific(ilQTIItem $item, $prefix='response_')
addGeneralMetadata(ilQTIItem $item)
const IL_INST_ID
Definition: constants.php:40
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
static _saveUsage(int $a_mob_id, string $a_type, int $a_id, int $a_usage_hist_nr=0, string $a_lang="-")
Save usage of mob within another container (e.g.
getQplImportArchivDirectory()
returns the full path to extracted qpl import archiv (qpl import dir + qpl archiv subdir) ...
$index
Definition: metadata.php:145
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _saveTempFileAsMediaObject(string $name, string $tmp_name, bool $upload=true)
Create new media object and update page in db and return new media object.
$ilUser
Definition: imgupload.php:34
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) ...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static clear(string $a_var)
fetchIndexFromFeedbackIdent($feedbackIdent, $prefix='response_')
int $created
Timestamp for when the object was created.
Definition: System.php:151
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, $import_mapping)
Creates a question from a QTI file.