ILIAS  trunk Revision v11.0_alpha-1702-gfd3ecb7f852
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.assFormulaQuestionImport.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  $this->object->setTitle($item->getTitle());
44  $this->object->setComment($item->getComment());
45  $this->object->setAuthor($item->getAuthor());
46  $this->object->setOwner($user_id);
47  $this->object->setQuestion($this->QTIMaterialToString($item->getQuestiontext()));
48  $this->object->setObjId($questionpool_id);
49  if (preg_match_all("/(\\\$v\\d+)/ims", $this->object->getQuestion(), $matches)) {
50  foreach ($matches[1] as $variable) {
51  $data = unserialize($item->getMetadataEntry($variable), ["allowed_classes" => false]);
52  $unit = $this->object->getUnitRepository()->getUnit((int) $data["unitvalue"]);
53  $varObj = new assFormulaQuestionVariable($variable, $data["rangemin"], $data["rangemax"], $unit, $data["precision"], $data["intprecision"]);
54  $this->object->addVariable($varObj);
55  }
56  }
57  if (preg_match_all("/(\\\$r\\d+)/ims", $this->object->getQuestion(), $rmatches)) {
58  foreach ($rmatches[1] as $result) {
59  $data = unserialize($item->getMetadataEntry($result), ["allowed_classes" => false]);
60  $unit = $this->object->getUnitRepository()->getUnit((int) $data["unitvalue"]);
61  if (!is_array($data["rating"])) {
62  $resObj = new assFormulaQuestionResult($result, $data["rangemin"], $data["rangemax"], $data["tolerance"], $unit, $data["formula"], $data["points"], $data["precision"], true);
63  } else {
64  $resObj = new assFormulaQuestionResult($result, $data["rangemin"], $data["rangemax"], $data["tolerance"], $unit, $data["formula"], $data["points"], $data["precision"], false, $data["rating"]["sign"], $data["rating"]["value"], $data["rating"]["unit"]);
65  }
66  if (array_key_exists('resulttype', $data)) {
67  $resObj->setResultType($data["resulttype"]);
68  }
69  $this->object->addResult($resObj);
70  if (is_array($data["resultunits"])) {
71  foreach ($data["resultunits"] as $resu) {
72  $ru = $this->object->getUnitRepository()->getUnit($resu["unitvalue"]);
73  if (is_object($ru)) {
74  $this->object->addResultUnit($resObj, $ru);
75  }
76  }
77  }
78  }
79  }
80  $this->object->setPoints($item->getMetadataEntry("points"));
81  $this->addGeneralMetadata($item);
82  // additional content editing mode information
83  $this->object->setAdditionalContentEditingMode(
85  );
86  $this->object->saveToDb();
87  // handle the import of media objects in XHTML code
88  $questiontext = $this->object->getQuestion();
89  $feedbacksgeneric = $this->getFeedbackGeneric($item);
90 
91  if (is_array(ilSession::get("import_mob_xhtml"))) {
92  foreach (ilSession::get("import_mob_xhtml") as $mob) {
93  $importfile = $importdirectory . DIRECTORY_SEPARATOR . $mob["uri"];
94  $media_object = ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);
95  ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
96  $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
97 
98  foreach ($feedbacksgeneric as $correctness => $material) {
99  $feedbacksgeneric[$correctness] = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $material);
100  }
101  }
102  }
103  $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
104 
105  foreach ($feedbacksgeneric as $correctness => $material) {
106  $this->object->feedbackOBJ->importGenericFeedback(
107  $this->object->getId(),
108  $correctness,
110  );
111  }
112 
113  // additional content editing mode information
114  $this->object->setAdditionalContentEditingMode(
116  );
117  $this->object->saveToDb();
118  $this->importSuggestedSolutions($this->object->getId(), $item->suggested_solutions);
119  if ($tst_id > 0) {
120  $q_1_id = $this->object->getId();
121  $question_id = $this->object->duplicate();
122  $tst_object->questions[$question_counter++] = $question_id;
123  $import_mapping[$item->getIdent()] = ["pool" => $q_1_id, "test" => $question_id];
124  } else {
125  $import_mapping[$item->getIdent()] = ["pool" => $this->object->getId(), "test" => 0];
126  }
127  return $import_mapping;
128  }
129 }
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...
fromXML(string $importdirectory, int $user_id, ilQTIItem $item, int $questionpool_id, ?int $tst_id, ?ilObject &$tst_object, int &$question_counter, array $import_mapping)
static get(string $a_var)
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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.
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)