36 $this->db = $DIC[
'ilDB'];
55 string $importdirectory,
61 int &$question_counter,
73 $clozetext_array = [];
75 foreach ($presentation->order as $entry) {
76 if ($entry[
'type'] ===
'material') {
78 $presentation->material[$entry[
'index']]
81 if ($questiontext ===
' ') {
87 $questiontext = $material_string;
91 $clozetext_array[] = $material_string;
95 if ($entry[
'type'] ===
'response') {
96 $response = $presentation->response[$entry[
'index']];
97 $clozetext_array[] =
"<<{$response->getIdent()}>>";
100 $fibtype =
$response->getRenderType()->getFibtype();
107 'minnumber' =>
$response->getRenderType()->getMinnumber(),
108 'maxnumber' =>
$response->getRenderType()->getMaxnumber(),
109 'gap_size' =>
$response->getRenderType()->getMaxchars()
118 'gap_size' =>
$response->getRenderType()->getMaxchars()
126 foreach (
$response->getRenderType()->response_labels as $response_label) {
127 $ident = $response_label->getIdent();
129 foreach ($response_label->material as $mat) {
133 'answertext' => $answertext,
135 'answerorder' => $answerorder++,
137 'shuffle' =>
$response->getRenderType()->getShuffle()
143 'shuffle' =>
$response->getRenderType()->getShuffle(),
144 'answers' => $answers
150 $feedbacksgeneric = [];
151 foreach ($item->resprocessing as $resprocessing) {
152 foreach ($resprocessing->respcondition as $respcondition) {
155 $conditionvar = $respcondition->getConditionvar();
158 foreach ($conditionvar->order as $order) {
159 if ($order[
'field'] ===
'varequal') {
160 $equals = $conditionvar->varequal[$order[
'index']]->getContent();
161 $gapident = $conditionvar->varequal[$order[
'index']]->getRespident();
164 if ($gapident ===
'') {
167 foreach ($respcondition->setvar as $setvar) {
168 foreach ($gaps as $gi => $g) {
169 if ($g[
'ident'] !== $gapident) {
172 switch ($g[
'type']) {
174 foreach ($gaps[$gi][
'answers'] as $ai => $answer) {
175 if ($answer[
'answertext'] === $equals) {
176 $gaps[$gi][
'answers'][$ai][
'action'] = $setvar->getAction();
177 $gaps[$gi][
'answers'][$ai][
'points'] = $setvar->getContent();
183 $gaps[$gi][
'answers'][] = [
184 'answertext' => $equals,
185 'points' => $setvar->getContent(),
186 'answerorder' => count($gaps[$gi][
'answers']),
187 'action' => $setvar->getAction()
195 if ($respcondition->displayfeedback === []) {
199 foreach ($respcondition->displayfeedback as $feedbackpointer) {
200 if ($feedbackpointer->getLinkrefid() ===
'') {
203 foreach ($item->itemfeedback as $ifb) {
204 switch ($ifb->getIdent()) {
205 case 'response_allcorrect':
206 foreach ($ifb->material as $material) {
207 $feedbacksgeneric[1] = $material;
209 foreach ($ifb->flow_mat as $fmat) {
210 foreach ($fmat->material as $material) {
211 $feedbacksgeneric[1] = $material;
215 case 'response_onenotcorrect':
216 foreach ($ifb->material as $material) {
217 $feedbacksgeneric[0] = $material;
219 foreach ($ifb->flow_mat as $fmat) {
220 foreach ($fmat->material as $material) {
221 $feedbacksgeneric[0] = $material;
226 foreach ($ifb->material as $material) {
227 $feedbacks[$ifb->getIdent()] = $material;
229 foreach ($ifb->flow_mat as $fmat) {
230 foreach ($fmat->material as $material) {
231 $feedbacks[$ifb->getIdent()] = $material;
241 $this->
object->setTitle($item->
getTitle());
243 $this->
object->setComment($item->
getComment());
244 $this->
object->setAuthor($item->
getAuthor());
245 $this->
object->setOwner($user_id);
246 $this->
object->setObjId($questionpool_id);
248 $this->
object->setFixedTextLength((
int) $item->
getMetadataEntry(
'fixedTextLength'));
249 $this->
object->setIdenticalScoring((
bool) $item->
getMetadataEntry(
'identicalScoring'));
250 $this->
object->setFeedbackMode(
254 $combinations = json_decode(base64_decode($item->
getMetadataEntry(
'combinations') ??
''));
255 if ($textgap_rating ===
'') {
256 $textgap_rating =
'ci';
258 $this->
object->setTextgapRating($textgap_rating);
260 foreach ($gaps as $gapidx => $gap) {
263 foreach ($gap[
'answers'] as $answer) {
264 $gapanswer =
new assAnswerCloze($answer[
'answertext'], $answer[
'points'], $answer[
'answerorder']);
265 $gapanswer->setGapSize((
int) ($gap[
'gap_size'] ?? 0));
266 switch ($clozegap->getType()) {
268 $clozegap->setShuffle($answer[
'shuffle']);
271 $gapanswer->setLowerBound($gap[
'minnumber']);
272 $gapanswer->setUpperBound($gap[
'maxnumber']);
275 $clozegap->setGapSize((
int) ($gap[
'gap_size'] ?? 0));
276 $clozegap->addItem($gapanswer);
277 array_push($gapcontent, $answer[
'answertext']);
279 $this->
object->addGapAtIndex($clozegap, $gapidx);
280 $gaptext[$gap[
'ident']] =
'[gap]' . join(
',', $gapcontent) .
'[/gap]';
283 $this->
object->setQuestion($questiontext);
284 $clozetext = join(
'', $clozetext_array);
286 foreach ($gaptext as $idx => $val) {
287 $clozetext = str_replace(
'<<' . $idx .
'>>', $val, $clozetext);
289 $this->
object->setClozeTextValue($clozetext);
292 $this->
object->setAdditionalContentEditingMode(
295 $this->
object->saveToDb();
297 if (is_array($combinations) && count($combinations) > 0) {
299 $gap_combinations->clearGapCombinationsFromDb($this->
object->getId());
300 $gap_combinations->importGapCombinationToDb($this->
object->getId(), $combinations);
301 $gap_combinations->loadFromDb($this->
object->getId());
302 $this->
object->setGapCombinations($gap_combinations);
303 $this->
object->setGapCombinationsExists(
true);
307 foreach ($feedbacks as $ident => $material) {
309 $feedbacks[$ident] = $m;
311 foreach ($feedbacksgeneric as $correctness => $material) {
313 $feedbacksgeneric[$correctness] = $m;
317 $importfile = $importdirectory . DIRECTORY_SEPARATOR . $mob[
'uri'];
319 $DIC[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
322 $questiontext = str_replace(
'src="' . $mob[
'mob'] .
'"',
'src="' .
'il_' .
IL_INST_ID .
'_mob_' . $media_object->getId() .
'"', $questiontext);
323 $clozetext = str_replace(
'src="' . $mob[
'mob'] .
'"',
'src="' .
'il_' .
IL_INST_ID .
'_mob_' . $media_object->getId() .
'"', $clozetext);
324 foreach ($feedbacks as $ident => $material) {
325 $feedbacks[$ident] = str_replace(
'src="' . $mob[
'mob'] .
'"',
'src="' .
'il_' .
IL_INST_ID .
'_mob_' . $media_object->getId() .
'"', $material);
327 foreach ($feedbacksgeneric as $correctness => $material) {
328 $feedbacksgeneric[$correctness] = str_replace(
'src="' . $mob[
'mob'] .
'"',
'src="' .
'il_' .
IL_INST_ID .
'_mob_' . $media_object->getId() .
'"', $material);
334 foreach ($feedbacks as $ident => $material) {
336 $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
338 $fbIdentifier->getQuestionIndex(),
339 $fbIdentifier->getAnswerIndex(),
343 foreach ($feedbacksgeneric as $correctness => $material) {
344 $this->
object->feedbackOBJ->importGenericFeedback(
350 $this->
object->saveToDb();
359 return $import_mapping;
370 $ident = explode(
'_', $ident);
372 if (count($ident) > 1) {
373 $fbIdentifier->setQuestionIndex($ident[0]);
374 $fbIdentifier->setAnswerIndex($ident[1]);
376 $fbIdentifier->setQuestionIndex($ident[0]);
377 $fbIdentifier->setAnswerIndex(0);
380 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.
addQuestionToParentObjectAndBuildMappingEntry(int $questionpool_id, ?int $tst_id, int &$question_counter, ?ilObjTest &$tst_object)
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.