ILIAS  release_8 Revision v8.24
class.assQuestionImport.php
Go to the documentation of this file.
1<?php
18include_once "./Modules/Test/classes/inc.AssessmentConstants.php";
19
30{
34 public $object;
35
42 public function __construct($a_object)
43 {
44 $this->object = $a_object;
45 }
46
47 public function getQuestionId(): int
48 {
49 return (int) $this->object->getId();
50 }
51
52 public function getFeedbackGeneric($item): array
53 {
54 $feedbacksgeneric = array();
55 foreach ($item->resprocessing as $resprocessing) {
56 foreach ($resprocessing->respcondition as $respcondition) {
57 foreach ($respcondition->displayfeedback as $feedbackpointer) {
58 if (strlen($feedbackpointer->getLinkrefid())) {
59 foreach ($item->itemfeedback as $ifb) {
60 if (strcmp($ifb->getIdent(), "response_allcorrect") == 0) {
61 // found a feedback for the identifier
62 if (count($ifb->material)) {
63 foreach ($ifb->material as $material) {
64 $feedbacksgeneric[1] = $material;
65 }
66 }
67 if ((count($ifb->flow_mat) > 0)) {
68 foreach ($ifb->flow_mat as $fmat) {
69 if (count($fmat->material)) {
70 foreach ($fmat->material as $material) {
71 $feedbacksgeneric[1] = $material;
72 }
73 }
74 }
75 }
76 } elseif (strcmp($ifb->getIdent(), "response_onenotcorrect") == 0) {
77 // found a feedback for the identifier
78 if (count($ifb->material)) {
79 foreach ($ifb->material as $material) {
80 $feedbacksgeneric[0] = $material;
81 }
82 }
83 if ((count($ifb->flow_mat) > 0)) {
84 foreach ($ifb->flow_mat as $fmat) {
85 if (count($fmat->material)) {
86 foreach ($fmat->material as $material) {
87 $feedbacksgeneric[0] = $material;
88 }
89 }
90 }
91 }
92 }
93 }
94 }
95 }
96 }
97 }
98 // handle the import of media objects in XHTML code
99 foreach ($feedbacksgeneric as $correctness => $material) {
100 $m = $this->object->QTIMaterialToString($material);
101 $feedbacksgeneric[$correctness] = $m;
102 }
103 return $feedbacksgeneric;
104 }
105
111 protected function fetchIndexFromFeedbackIdent($feedbackIdent, $prefix = 'response_'): int
112 {
113 return (int) str_replace($prefix, '', $feedbackIdent);
114 }
115
121 protected function getFeedbackAnswerSpecific(ilQTIItem $item, $prefix = 'response_'): array
122 {
123 $feedbacks = array();
124
125 foreach ($item->itemfeedback as $ifb) {
126 if ($ifb->getIdent() == 'response_allcorrect' || $ifb->getIdent() == 'response_onenotcorrect') {
127 continue;
128 }
129
130 if ($ifb->getIdent() == $prefix . 'allcorrect' || $ifb->getIdent() == $prefix . 'onenotcorrect') {
131 continue;
132 }
133
134 if (substr($ifb->getIdent(), 0, strlen($prefix)) != $prefix) {
135 continue;
136 }
137
138 $ident = $ifb->getIdent();
139
140 // found a feedback for the identifier
141
142 if (count($ifb->material)) {
143 foreach ($ifb->material as $material) {
144 $feedbacks[$ident] = $material;
145 }
146 }
147
148 if ((count($ifb->flow_mat) > 0)) {
149 foreach ($ifb->flow_mat as $fmat) {
150 if (count($fmat->material)) {
151 foreach ($fmat->material as $material) {
152 $feedbacks[$ident] = $material;
153 }
154 }
155 }
156 }
157 }
158
159 foreach ($feedbacks as $ident => $material) {
160 $m = $this->object->QTIMaterialToString($material);
161 $feedbacks[$ident] = $m;
162 }
163
164 return $feedbacks;
165 }
166
180 public function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, $import_mapping): array
181 {
182 }
183
187 protected function addGeneralMetadata(ilQTIItem $item): void
188 {
189 if ($item->getMetadataEntry('externalID')) {
190 $this->object->setExternalId($item->getMetadataEntry('externalID'));
191 } else {
192 $this->object->setExternalId($item->getMetadataEntry('externalId'));
193 }
194
195 $this->object->setLifecycle($this->fetchLifecycle($item));
196 }
197
203 {
204 try {
206 $item->getMetadataEntry('ilias_lifecycle')
207 );
209 try {
210 $lomLifecycle = new ilAssQuestionLomLifecycle(
211 $item->getMetadataEntry('lifecycle')
212 );
213
215 $lomLifecycle->getMappedIliasLifecycleIdentifer()
216 );
219 }
220 }
221
222 return $lifecycle;
223 }
224
228 protected function getQplImportArchivDirectory(): string
229 {
230 return ilObjQuestionPool::_getImportDirectory() . '/' . ilSession::get("qpl_import_subdir");
231 }
232
236 protected function getTstImportArchivDirectory(): string
237 {
238 return ilObjTest::_getImportDirectory() . '/' . ilSession::get("tst_import_subdir");
239 }
240
241 protected function processNonAbstractedImageReferences($text, $sourceNic): string
242 {
243 $reg = '/<img.*src=".*\\/mm_(\\d+)\\/(.*?)".*>/m';
244 $matches = null;
245
246 if (preg_match_all($reg, $text, $matches)) {
247 $mobs = array();
248 for ($i = 0, $max = count($matches[1]); $i < $max; $i++) {
249 $mobSrcId = $matches[1][$i];
250 $mobSrcName = $matches[2][$i];
251 $mobSrcLabel = 'il_' . $sourceNic . '_mob_' . $mobSrcId;
252
253 //if (!is_array(ilSession::get("import_mob_xhtml"))) {
254 // ilSession::set("import_mob_xhtml", array());
255 //}
256
257 //$_SESSION["import_mob_xhtml"][] = array(
258 $mobs[] = array(
259 "mob" => $mobSrcLabel, "uri" => 'objects/' . $mobSrcLabel . '/' . $mobSrcName
260 );
261 }
262 ilSession::set('import_mob_xhtml', $mobs);
263 }
264
265 return ilRTE::_replaceMediaObjectImageSrc($text, 0, $sourceNic);
266 }
267
276 final protected function fetchAdditionalContentEditingModeInformation($qtiItem): string
277 {
278 $additionalContentEditingMode = $qtiItem->getMetadataEntry('additional_cont_edit_mode');
279
280 if (!$this->object->isValidAdditionalContentEditingMode($additionalContentEditingMode ?? '')) {
281 $additionalContentEditingMode = assQuestion::ADDITIONAL_CONTENT_EDITING_MODE_RTE;
282 }
283
284 return $additionalContentEditingMode;
285 }
286
287 public function importSuggestedSolution(
288 int $question_id,
289 string $value = "",
290 int $subquestion_index = 0
291 ): void {
292 $type = $this->findSolutionTypeByValue($value);
293 if (!$type) {
294 return;
295 }
296
297 $repo = $this->getSuggestedSolutionsRepo();
298
299 $nu_value = $this->object->_resolveInternalLink($value);
300 $solution = $repo->create($question_id, $type)
301 ->withInternalLink($nu_value)
302 ->withImportId($value);
303 $repo->update($solution);
304 }
305
306 protected function deduceThumbSizeFromImportValue(?int $size): int
307 {
308 if ($size === null) {
309 return $this->object->getThumbSize();
310 }
311
312 if ($size < $this->object->getMaximumThumbSize()) {
313 return $this->object->getMaximumThumbSize();
314 }
315
316 if ($size > $this->object->getMaximumThumbSize()) {
317 return $this->object->getMaximumThumbSize();
318 }
319
320 return $size;
321 }
322}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
getFeedbackAnswerSpecific(ilQTIItem $item, $prefix='response_')
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir)
__construct($a_object)
assQuestionImport constructor
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, $import_mapping)
Creates a question from a QTI file.
processNonAbstractedImageReferences($text, $sourceNic)
fetchLifecycle(ilQTIItem $item)
addGeneralMetadata(ilQTIItem $item)
deduceThumbSizeFromImportValue(?int $size)
getQplImportArchivDirectory()
returns the full path to extracted qpl import archiv (qpl import dir + qpl archiv subdir)
fetchIndexFromFeedbackIdent($feedbackIdent, $prefix='response_')
importSuggestedSolution(int $question_id, string $value="", int $subquestion_index=0)
const ADDITIONAL_CONTENT_EDITING_MODE_RTE
static _getImportDirectory()
get import directory of lm
static _getImportDirectory()
Get the import directory location of the test.
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)
static set(string $a_var, $a_val)
Set a value.
$mobs
Definition: imgupload.php:70
$i
Definition: metadata.php:41
$type