36 $this->db = $DIC[
'ilDB'];
55 string $importdirectory,
61 int &$question_counter,
73 $clozetext_array = [];
76 foreach ($presentation->order as $entry) {
77 switch ($entry[
'type']) {
81 $presentation->material[$entry[
'index']]
84 if ($questiontext ===
' ') {
90 $questiontext = $material_string;
92 array_push($clozetext_array, $material_string);
97 $response = $presentation->response[$entry[
'index']];
99 array_push($clozetext_array,
'<<' .
$response->getIdent() .
'>>');
101 switch (strtolower(get_class(
$response->getRenderType()))) {
102 case 'ilqtirenderfib':
103 switch (
$response->getRenderType()->getFibtype()) {
112 'minnumber' =>
$response->getRenderType()->getMinnumber(),
113 'maxnumber' =>
$response->getRenderType()->getMaxnumber(),
114 'gap_size' =>
$response->getRenderType()->getMaxchars()
126 'gap_size' =>
$response->getRenderType()->getMaxchars()
132 case 'ilqtirenderchoice':
134 $shuffle = $rendertype->getShuffle();
136 foreach ($rendertype->response_labels as $response_label) {
137 $ident = $response_label->getIdent();
139 foreach ($response_label->material as $mat) {
143 'answertext' => $answertext,
145 'answerorder' => $answerorder++,
147 'shuffle' => $rendertype->getShuffle()
153 'shuffle' => $rendertype->getShuffle(),
154 'answers' => $answers
162 $feedbacksgeneric = [];
163 foreach ($item->resprocessing as $resprocessing) {
164 foreach ($resprocessing->respcondition as $respcondition) {
167 $conditionvar = $respcondition->getConditionvar();
170 foreach ($conditionvar->order as $order) {
171 if ($order[
'field'] ===
'varequal') {
172 $equals = $conditionvar->varequal[$order[
'index']]->getContent();
173 $gapident = $conditionvar->varequal[$order[
'index']]->getRespident();
176 if ($gapident ===
'') {
179 foreach ($respcondition->setvar as $setvar) {
180 foreach ($gaps as $gi => $g) {
181 if ($g[
'ident'] !== $gapident) {
184 switch ($g[
'type']) {
186 foreach ($gaps[$gi][
'answers'] as $ai => $answer) {
187 if ($answer[
'answertext'] === $equals) {
188 $gaps[$gi][
'answers'][$ai][
'action'] = $setvar->getAction();
189 $gaps[$gi][
'answers'][$ai][
'points'] = $setvar->getContent();
195 $gaps[$gi][
'answers'][] = [
196 'answertext' => $equals,
197 'points' => $setvar->getContent(),
198 'answerorder' => count($gaps[$gi][
'answers']),
199 'action' => $setvar->getAction()
207 if ($respcondition->displayfeedback === []) {
211 foreach ($respcondition->displayfeedback as $feedbackpointer) {
212 if ($feedbackpointer->getLinkrefid() ===
'') {
215 foreach ($item->itemfeedback as $ifb) {
216 switch ($ifb->getIdent()) {
217 case 'response_allcorrect':
218 foreach ($ifb->material as $material) {
219 $feedbacksgeneric[1] = $material;
221 foreach ($ifb->flow_mat as $fmat) {
222 foreach ($fmat->material as $material) {
223 $feedbacksgeneric[1] = $material;
227 case 'response_onenotcorrect':
228 foreach ($ifb->material as $material) {
229 $feedbacksgeneric[0] = $material;
231 foreach ($ifb->flow_mat as $fmat) {
232 foreach ($fmat->material as $material) {
233 $feedbacksgeneric[0] = $material;
238 foreach ($ifb->material as $material) {
239 $feedbacks[$ifb->getIdent()] = $material;
241 foreach ($ifb->flow_mat as $fmat) {
242 foreach ($fmat->material as $material) {
243 $feedbacks[$ifb->getIdent()] = $material;
253 $this->
object->setTitle($item->
getTitle());
255 $this->
object->setComment($item->
getComment());
256 $this->
object->setAuthor($item->
getAuthor());
257 $this->
object->setOwner($user_id);
258 $this->
object->setObjId($questionpool_id);
260 $this->
object->setFixedTextLength((
int) $item->
getMetadataEntry(
'fixedTextLength'));
261 $this->
object->setIdenticalScoring((
bool) $item->
getMetadataEntry(
'identicalScoring'));
262 $this->
object->setFeedbackMode(
266 $combinations = json_decode(base64_decode($item->
getMetadataEntry(
'combinations') ??
''));
267 if ($textgap_rating ===
'') {
268 $textgap_rating =
'ci';
270 $this->
object->setTextgapRating($textgap_rating);
272 foreach ($gaps as $gapidx => $gap) {
275 foreach ($gap[
'answers'] as $answer) {
276 $gapanswer =
new assAnswerCloze($answer[
'answertext'], $answer[
'points'], $answer[
'answerorder']);
277 $gapanswer->setGapSize((
int) ($gap[
'gap_size'] ?? 0));
278 switch ($clozegap->getType()) {
280 $clozegap->setShuffle($answer[
'shuffle']);
283 $gapanswer->setLowerBound($gap[
'minnumber']);
284 $gapanswer->setUpperBound($gap[
'maxnumber']);
287 $clozegap->setGapSize((
int) ($gap[
'gap_size'] ?? 0));
288 $clozegap->addItem($gapanswer);
289 array_push($gapcontent, $answer[
'answertext']);
291 $this->
object->addGapAtIndex($clozegap, $gapidx);
292 $gaptext[$gap[
'ident']] =
'[gap]' . join(
',', $gapcontent) .
'[/gap]';
295 $this->
object->setQuestion($questiontext);
296 $clozetext = join(
'', $clozetext_array);
298 foreach ($gaptext as $idx => $val) {
299 $clozetext = str_replace(
'<<' . $idx .
'>>', $val, $clozetext);
301 $this->
object->setClozeTextValue($clozetext);
304 $this->
object->setAdditionalContentEditingMode(
307 $this->
object->saveToDb();
309 if (is_array($combinations) && count($combinations) > 0) {
311 $gap_combinations->clearGapCombinationsFromDb($this->
object->getId());
312 $gap_combinations->importGapCombinationToDb($this->
object->getId(), $combinations);
313 $gap_combinations->loadFromDb($this->
object->getId());
314 $this->
object->setGapCombinations($gap_combinations);
315 $this->
object->setGapCombinationsExists(
true);
319 foreach ($feedbacks as $ident => $material) {
321 $feedbacks[$ident] = $m;
323 foreach ($feedbacksgeneric as $correctness => $material) {
325 $feedbacksgeneric[$correctness] = $m;
329 $importfile = $importdirectory . DIRECTORY_SEPARATOR . $mob[
'uri'];
331 $DIC[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
334 $questiontext = str_replace(
'src="' . $mob[
'mob'] .
'"',
'src="' .
'il_' .
IL_INST_ID .
'_mob_' . $media_object->getId() .
'"', $questiontext);
335 $clozetext = str_replace(
'src="' . $mob[
'mob'] .
'"',
'src="' .
'il_' .
IL_INST_ID .
'_mob_' . $media_object->getId() .
'"', $clozetext);
336 foreach ($feedbacks as $ident => $material) {
337 $feedbacks[$ident] = str_replace(
'src="' . $mob[
'mob'] .
'"',
'src="' .
'il_' .
IL_INST_ID .
'_mob_' . $media_object->getId() .
'"', $material);
339 foreach ($feedbacksgeneric as $correctness => $material) {
340 $feedbacksgeneric[$correctness] = str_replace(
'src="' . $mob[
'mob'] .
'"',
'src="' .
'il_' .
IL_INST_ID .
'_mob_' . $media_object->getId() .
'"', $material);
346 foreach ($feedbacks as $ident => $material) {
348 $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
350 $fbIdentifier->getQuestionIndex(),
351 $fbIdentifier->getAnswerIndex(),
355 foreach ($feedbacksgeneric as $correctness => $material) {
356 $this->
object->feedbackOBJ->importGenericFeedback(
362 $this->
object->saveToDb();
365 if (isset($tst_id) && $tst_id !== $questionpool_id) {
366 $qpl_qid = $this->
object->getId();
367 $tst_qid = $this->
object->duplicate(
true,
'',
'', -1, $tst_id);
368 $tst_object->questions[$question_counter++] = $tst_qid;
369 $import_mapping[$item->
getIdent()] = [
'pool' => $qpl_qid,
'test' => $tst_qid];
370 return $import_mapping;
374 $tst_object->questions[$question_counter++] = $this->
object->
getId();
375 $import_mapping[$item->
getIdent()] = [
'pool' => 0,
'test' => $this->
object->getId()];
376 return $import_mapping;
379 $import_mapping[$item->
getIdent()] = [
'pool' => $this->
object->getId(),
'test' => 0];
380 return $import_mapping;
391 $ident = explode(
'_', $ident);
393 if (count($ident) > 1) {
394 $fbIdentifier->setQuestionIndex($ident[0]);
395 $fbIdentifier->setAnswerIndex($ident[1]);
397 $fbIdentifier->setQuestionIndex($ident[0]);
398 $fbIdentifier->setAnswerIndex(0);
401 return $fbIdentifier;
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)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addGeneralMetadata(ilQTIItem $item)
QTIMaterialToString(ilQTIMaterial $a_material)
Reads an QTI material tag and creates a text or XHTML string.
getMetadataEntry(string $a_label)
processNonAbstractedImageReferences($text, $sourceNic)
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
Class for cloze question gaps.
importSuggestedSolutions(int $question_id, array $solution_from_import)
__construct(Container $dic, ilPlugin $plugin)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class for question imports.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static clear(string $a_var)
buildFeedbackIdentifier($ident)
const FB_MODE_GAP_QUESTION
constants for different feedback modes (per gap or per gap-answers/options)
fromXML(string $importdirectory, int $user_id, ilQTIItem $item, int $questionpool_id, ?int $tst_id, ?ilObject &$tst_object, int &$question_counter, array $import_mapping)
Creates a question from a QTI file.