ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
class.assLongMenuImport.php
Go to the documentation of this file.
1<?php
2
23{
24 public $object;
25
26 public function fromXML(
27 string $importdirectory,
28 int $user_id,
29 ilQTIItem $item,
30 int $questionpool_id,
31 ?int $tst_id,
32 ?ilObject &$tst_object,
33 int &$question_counter,
34 array $import_mapping
35 ): array {
36 ilSession::clear('import_mob_xhtml');
37
38 $answers = [];
39 $correct_answers = [];
40 $presentation = $item->getPresentation();
41 $gap_types = json_decode($item->getMetadataEntry("gapTypes"));
42 foreach ($presentation->order as $entry) {
43 switch ($entry["type"]) {
44 case "material":
45
46 $material = $presentation->material[$entry["index"]];
47 if (preg_match('/\[Longmenu \d\]/', $this->QTIMaterialToString($material))) {
48 $this->object->setLongMenuTextValue($this->QTIMaterialToString($material));
49 } else {
50 $this->object->setQuestion($this->QTIMaterialToString($material));
51 }
52
53
54 break;
55 }
56 }
57
58 // fixLongMenuImageImport - process images in question and long menu text when question is imported
59 $questiontext = $this->object->getQuestion();
60 $longmenutext = $this->object->getLongMenuTextValue();
61 if (is_array(ilSession::get("import_mob_xhtml"))) {
62 foreach (ilSession::get("import_mob_xhtml") as $mob) {
63 $importfile = $importdirectory . DIRECTORY_SEPARATOR . $mob["uri"];
64
65 global $DIC; /* @var ILIAS\DI\Container $DIC */
66 $DIC['ilLog']->info('import mob from dir: ' . $importfile);
67
68 $media_object = ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, false);
69 ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->object->getId());
70
71 $questiontext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $questiontext);
72 $longmenutext = str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $longmenutext);
73 }
74 }
75 $this->object->setQuestion(ilRTE::_replaceMediaObjectImageSrc($questiontext, 1));
76 $this->object->setLongMenuTextValue(ilRTE::_replaceMediaObjectImageSrc($longmenutext, 1));
77 // fau.
78
79 foreach ($item->resprocessing as $resprocessing) {
80 foreach ($resprocessing->respcondition as $respcondition) {
81 $correctness = 1;
82 $conditionvar = $respcondition->getConditionvar();
83 foreach ($conditionvar->order as $order) {
84 switch ($order['field']) {
85 case 'varequal':
86 $equals = $conditionvar->varequal[$order["index"]]->getContent();
87 $gapident = $conditionvar->varequal[$order["index"]]->getRespident();
88 $id = $this->getIdFromGapIdent($gapident);
89 if (!isset($answers[$id]) || !in_array($equals, $answers[$id])) {
90 $answers[$id][] = $equals;
91 }
92 break;
93 }
94 }
95 foreach ($respcondition->setvar as $setvar) {
96 if ($gapident !== '') {
97 if ($setvar->getContent() > 0) {
98 $id = $this->getIdFromGapIdent($gapident);
99 $correct_answers[$id][0][] = $equals;
100 $correct_answers[$id][1] = $setvar->getContent();
101 if (is_array($gap_types) && key_exists($id, $gap_types)) {
102 $correct_answers[$id][2] = $gap_types[$id];
103 }
104 }
105 }
106 }
107 foreach ($respcondition->displayfeedback as $feedbackpointer) {
108 if (strlen($feedbackpointer->getLinkrefid())) {
109 foreach ($item->itemfeedback as $ifb) {
110 if ($ifb->getIdent() === 'response_allcorrect') {
111 foreach ($ifb->material as $material) {
112 $feedbacksgeneric[1] = $material;
113 }
114 foreach ($ifb->flow_mat as $fmat) {
115 if (count($fmat->material)) {
116 foreach ($fmat->material as $material) {
117 $feedbacksgeneric[1] = $material;
118 }
119 }
120 }
121 } elseif ($ifb->getIdent() === 'response_onenotcorrect') {
122 foreach ($ifb->material as $material) {
123 $feedbacksgeneric[0] = $material;
124 }
125 foreach ($ifb->flow_mat as $fmat) {
126 if (count($fmat->material)) {
127 foreach ($fmat->material as $material) {
128 $feedbacksgeneric[0] = $material;
129 }
130 }
131 }
132 } else {
133 foreach ($ifb->material as $material) {
134 $feedbacks[$ifb->getIdent()] = $material;
135 }
136 foreach ($ifb->flow_mat as $fmat) {
137 if (count($fmat->material)) {
138 foreach ($fmat->material as $material) {
139 $feedbacks[$ifb->getIdent()] = $material;
140 }
141 }
142 }
143 }
144 }
145 }
146 }
147 }
148 }
149
150 $sum = 0;
151 foreach ($correct_answers as $row) {
152 $sum += $row[1];
153 }
154 $this->object->setAnswers($answers);
155 // handle the import of media objects in XHTML code
156 if (isset($feedbacks) && count($feedbacks) > 0) {
157 foreach ($feedbacks as $ident => $material) {
158 $m = $this->QTIMaterialToString($material);
159 $feedbacks[$ident] = $m;
160 }
161 }
162 if (isset($feedbacksgeneric) && is_array($feedbacksgeneric) && count($feedbacksgeneric) > 0) {
163 foreach ($feedbacksgeneric as $correctness => $material) {
164 $m = $this->QTIMaterialToString($material);
165 $feedbacksgeneric[$correctness] = $m;
166 }
167 }
168
169 $this->addGeneralMetadata($item);
170 $this->object->setTitle($item->getTitle());
171 $this->object->setNrOfTries((int) $item->getMaxattempts());
172 $this->object->setComment($item->getComment());
173 $this->object->setAuthor($item->getAuthor());
174 $this->object->setOwner($user_id);
175 $this->object->setObjId($questionpool_id);
176 $this->object->setMinAutoComplete((int) ($item->getMetadataEntry('minAutoCompleteLength') ?? assLongMenu::MIN_LENGTH_AUTOCOMPLETE));
177 $this->object->setIdenticalscoring((int) $item->getMetadataEntry('identical_scoring'));
178 $this->object->setCorrectAnswers($correct_answers);
179 $this->object->setPoints($sum);
180 // additional content editing mode information
181 $this->object->setAdditionalContentEditingMode(
183 );
184 $this->object->saveToDb();
185 $this->importSuggestedSolutions($this->object->getId(), $item->suggested_solutions);
186 if (isset($feedbacks) && count($feedbacks) > 0) {
187 foreach ($feedbacks as $ident => $material) {
188 $this->object->feedbackOBJ->importSpecificAnswerFeedback(
189 $this->object->getId(),
190 0,
191 $ident,
193 );
194 }
195 }
196 if (isset($feedbacksgeneric) && is_array($feedbacksgeneric) && count($feedbacksgeneric) > 0) {
197 foreach ($feedbacksgeneric as $correctness => $material) {
198 $this->object->feedbackOBJ->importGenericFeedback(
199 $this->object->getId(),
200 $correctness,
202 );
203 }
204 }
205 $this->object->saveToDb();
206
207 $import_mapping[$item->getIdent()] = $this->addQuestionToParentObjectAndBuildMappingEntry(
208 $questionpool_id,
209 $tst_id,
210 $question_counter,
211 $tst_object
212 );
213 return $import_mapping;
214 }
215
216 private function getIdFromGapIdent($ident)
217 {
218 $id = preg_split('/_/', $ident);
219 return $id[1] - 1;
220 }
221}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
fromXML(string $importdirectory, int $user_id, ilQTIItem $item, int $questionpool_id, ?int $tst_id, ?ilObject &$tst_object, int &$question_counter, array $import_mapping)
const MIN_LENGTH_AUTOCOMPLETE
Class for question imports.
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
addQuestionToParentObjectAndBuildMappingEntry(int $questionpool_id, ?int $tst_id, int &$question_counter, ?ilObjTest &$tst_object)
QTIMaterialToString(ilQTIMaterial $a_material)
Reads an QTI material tag and creates a text or XHTML string.
addGeneralMetadata(ilQTIItem $item)
importSuggestedSolutions(int $question_id, array $solution_from_import)
static _saveTempFileAsMediaObject(string $name, string $tmp_name, bool $upload=true)
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.
Class ilObject Basic functions for all objects.
getMetadataEntry(string $a_label)
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)
const IL_INST_ID
Definition: constants.php:40
global $DIC
Definition: shib_login.php:26