ILIAS  trunk Revision v11.0_alpha-1702-gfd3ecb7f852
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.assOrderingHorizontalImport.php
Go to the documentation of this file.
1 <?php
2 
29 {
30  public function fromXML(
31  string $importdirectory,
32  int $user_id,
33  ilQTIItem $item,
34  int $questionpool_id,
35  ?int $tst_id,
36  ?ilObject &$tst_object,
37  int &$question_counter,
38  array $import_mapping
39  ): array {
40  // empty session variable for imported xhtml mobs
41  ilSession::clear('import_mob_xhtml');
42 
43  $presentation = $item->getPresentation();
44  $now = getdate();
45  $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
46 
47  $this->addGeneralMetadata($item);
48  $this->object->setTitle($item->getTitle());
49  $this->object->setNrOfTries((int) $item->getMaxattempts());
50  $this->object->setComment($item->getComment());
51  $this->object->setAuthor($item->getAuthor());
52  $this->object->setOwner($user_id);
53  $this->object->setQuestion($this->QTIMaterialToString($item->getQuestiontext()));
54  $this->object->setObjId($questionpool_id);
55  $this->object->setPoints($item->getMetadataEntry("points"));
56  $this->object->setOrderText($item->getMetadataEntry("ordertext"));
57  $this->object->setTextSize((float) $item->getMetadataEntry("textsize"));
58  $this->object->setSeparator($item->getMetadataEntry("separator"));
59  // additional content editing mode information
60  $this->object->setAdditionalContentEditingMode(
62  );
63  $this->object->saveToDb();
64 
65  $feedbacks = $this->getFeedbackAnswerSpecific($item);
66  $feedbacksgeneric = $this->getFeedbackGeneric($item);
67 
68  // handle the import of media objects in XHTML code
69  $questiontext = $this->object->getQuestion();
70  if (is_array(ilSession::get("import_mob_xhtml"))) {
71  foreach (ilSession::get("import_mob_xhtml") as $mob) {
72  $importfile = $importdirectory . DIRECTORY_SEPARATOR . $mob["uri"];
73 
74  global $DIC; /* @var ILIAS\DI\Container $DIC */
75  $DIC['ilLog']->write(__METHOD__ . ': import mob from dir: ' . $importfile);
76 
77  $media_object = ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);
78  ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
79  $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
80 
81  foreach ($feedbacks as $ident => $material) {
82  $feedbacks[$ident] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
83  }
84  foreach ($feedbacksgeneric as $correctness => $material) {
85  $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
86  }
87  }
88  }
89  $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
90 
91  foreach ($feedbacks as $ident => $material) {
92  $index = $this->fetchIndexFromFeedbackIdent($ident);
93 
94  $this->object->feedbackOBJ->importSpecificAnswerFeedback(
95  $this->object->getId(),
96  0,
97  $index,
99  );
100  }
101  foreach ($feedbacksgeneric as $correctness => $material) {
102  $this->object->feedbackOBJ->importGenericFeedback(
103  $this->object->getId(),
104  $correctness,
106  );
107  }
108  $this->object->saveToDb();
109  $this->importSuggestedSolutions($this->object->getId(), $item->suggested_solutions);
110  if ($tst_id > 0) {
111  $q_1_id = $this->object->getId();
112  $question_id = $this->object->duplicate(true, "", "", -1, $tst_id);
113  $tst_object->questions[$question_counter++] = $question_id;
114  $import_mapping[$item->getIdent()] = ["pool" => $q_1_id, "test" => $question_id];
115  } else {
116  $import_mapping[$item->getIdent()] = ["pool" => $this->object->getId(), "test" => 0];
117  }
118  return $import_mapping;
119  }
120 }
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
QTIMaterialToString(ilQTIMaterial $a_material)
Reads an QTI material tag and creates a text or XHTML string.
getMetadataEntry(string $a_label)
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.
global $DIC
Definition: shib_login.php:22
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
importSuggestedSolutions(int $question_id, array $solution_from_import)
static _saveTempFileAsMediaObject(string $name, string $tmp_name, bool $upload=true)
Class for question imports.
static clear(string $a_var)
fetchIndexFromFeedbackIdent($feedbackIdent, $prefix='response_')
fromXML(string $importdirectory, int $user_id, ilQTIItem $item, int $questionpool_id, ?int $tst_id, ?ilObject &$tst_object, int &$question_counter, array $import_mapping)