43 public function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, $import_mapping): array
50 $presentation = $item->getPresentation();
53 $item->getMetadataEntry(
"question") ??
' ',
54 $item->getIliasSourceNic()
57 $clozetext_array = [];
59 foreach ($presentation->order as $entry) {
60 switch ($entry[
"type"]) {
63 $material_string = $this->
object->QTIMaterialToString(
64 $presentation->material[$entry[
"index"]]
67 if ($questiontext ===
' ') {
68 $questiontext = $material_string;
70 array_push($clozetext_array, $material_string);
75 $response = $presentation->response[$entry[
"index"]];
77 array_push($clozetext_array,
"<<" .
$response->getIdent() .
">>");
79 switch (strtolower(get_class(
$response->getRenderType()))) {
80 case "ilqtirenderfib":
81 switch (
$response->getRenderType()->getFibtype()) {
90 "minnumber" =>
$response->getRenderType()->getMinnumber(),
91 "maxnumber" =>
$response->getRenderType()->getMaxnumber(),
92 'gap_size' =>
$response->getRenderType()->getMaxchars()
102 "answers" => array(),
103 'gap_size' =>
$response->getRenderType()->getMaxchars()
109 case "ilqtirenderchoice":
111 $shuffle = $rendertype->getShuffle();
113 foreach ($rendertype->response_labels as $response_label) {
114 $ident = $response_label->getIdent();
116 foreach ($response_label->material as $mat) {
117 $answertext .= $this->
object->QTIMaterialToString($mat);
119 $answers[$ident] = array(
120 "answertext" => $answertext,
122 "answerorder" => $answerorder++,
124 "shuffle" => $rendertype->getShuffle()
127 array_push($gaps, array(
"ident" =>
$response->getIdent(),
"type" =>
CLOZE_SELECT,
"shuffle" => $rendertype->getShuffle(),
"answers" => $answers));
133 $responses = array();
134 $feedbacks = array();
135 $feedbacksgeneric = array();
136 foreach ($item->resprocessing as $resprocessing) {
137 foreach ($resprocessing->respcondition as $respcondition) {
140 $conditionvar = $respcondition->getConditionvar();
141 foreach ($conditionvar->order as $order) {
142 switch ($order[
"field"]) {
144 $equals = $conditionvar->varequal[$order[
"index"]]->getContent();
145 $gapident = $conditionvar->varequal[$order[
"index"]]->getRespident();
149 foreach ($respcondition->setvar as $setvar) {
150 if (strcmp($gapident,
"") != 0) {
151 foreach ($gaps as $gi => $g) {
152 if (strcmp($g[
"ident"], $gapident) == 0) {
154 foreach ($gaps[$gi][
"answers"] as $ai => $answer) {
155 if (strcmp($answer[
"answertext"], $equals) == 0) {
156 $gaps[$gi][
"answers"][$ai][
"action"] = $setvar->getAction();
157 $gaps[$gi][
"answers"][$ai][
"points"] = $setvar->getContent();
161 array_push($gaps[$gi][
"answers"], array(
162 "answertext" => $equals,
163 "points" => $setvar->getContent(),
164 "answerorder" => count($gaps[$gi][
"answers"]),
165 "action" => $setvar->getAction()
169 array_push($gaps[$gi][
"answers"], array(
170 "answertext" => $equals,
171 "points" => $setvar->getContent(),
172 "answerorder" => count($gaps[$gi][
"answers"]),
173 "action" => $setvar->getAction()
181 if (count($respcondition->displayfeedback)) {
182 foreach ($respcondition->displayfeedback as $feedbackpointer) {
183 if (strlen($feedbackpointer->getLinkrefid())) {
184 foreach ($item->itemfeedback as $ifb) {
185 if (strcmp($ifb->getIdent(),
"response_allcorrect") == 0) {
187 if (count($ifb->material)) {
188 foreach ($ifb->material as $material) {
189 $feedbacksgeneric[1] = $material;
192 if ((count($ifb->flow_mat) > 0)) {
193 foreach ($ifb->flow_mat as $fmat) {
194 if (count($fmat->material)) {
195 foreach ($fmat->material as $material) {
196 $feedbacksgeneric[1] = $material;
201 } elseif (strcmp($ifb->getIdent(),
"response_onenotcorrect") == 0) {
203 if (count($ifb->material)) {
204 foreach ($ifb->material as $material) {
205 $feedbacksgeneric[0] = $material;
208 if ((count($ifb->flow_mat) > 0)) {
209 foreach ($ifb->flow_mat as $fmat) {
210 if (count($fmat->material)) {
211 foreach ($fmat->material as $material) {
212 $feedbacksgeneric[0] = $material;
219 if (count($ifb->material)) {
220 foreach ($ifb->material as $material) {
221 $feedbacks[$ifb->getIdent()] = $material;
224 if ((count($ifb->flow_mat) > 0)) {
225 foreach ($ifb->flow_mat as $fmat) {
226 if (count($fmat->material)) {
227 foreach ($fmat->material as $material) {
228 $feedbacks[$ifb->getIdent()] = $material;
242 $this->
object->setTitle($item->getTitle());
243 $this->
object->setNrOfTries((
int) $item->getMaxattempts());
244 $this->
object->setComment($item->getComment());
245 $this->
object->setAuthor($item->getAuthor());
246 $this->
object->setOwner(
$ilUser->getId());
247 $this->
object->setObjId($questionpool_id);
248 $textgap_rating = $item->getMetadataEntry(
"textgaprating");
249 $this->
object->setFixedTextLength($item->getMetadataEntry(
"fixedTextLength"));
250 $this->
object->setIdenticalScoring($item->getMetadataEntry(
"identicalScoring"));
251 $this->
object->setFeedbackMode(
252 strlen($item->getMetadataEntry(
"feedback_mode")) ?
255 $combinations = json_decode(base64_decode($item->getMetadataEntry(
"combinations")));
256 if (strlen($textgap_rating) == 0) {
257 $textgap_rating =
"ci";
259 $this->
object->setTextgapRating($textgap_rating);
261 foreach ($gaps as $gapidx => $gap) {
262 $gapcontent = array();
264 foreach ($gap[
"answers"] as
$index => $answer) {
265 $gapanswer =
new assAnswerCloze($answer[
"answertext"], $answer[
"points"], $answer[
"answerorder"]);
266 $gapanswer->setGapSize((
int) ($gap[
"gap_size"] ?? 0));
267 switch ($clozegap->getType()) {
269 $clozegap->setShuffle($answer[
"shuffle"]);
272 $gapanswer->setLowerBound($gap[
"minnumber"]);
273 $gapanswer->setUpperBound($gap[
"maxnumber"]);
276 $clozegap->setGapSize((
int) ($gap[
"gap_size"] ?? 0));
277 $clozegap->addItem($gapanswer);
278 array_push($gapcontent, $answer[
"answertext"]);
280 $this->
object->addGapAtIndex($clozegap, $gapidx);
281 $gaptext[$gap[
"ident"]] =
"[gap]" . join(
",", $gapcontent) .
"[/gap]";
284 $this->
object->setQuestion($questiontext);
285 $clozetext = join(
"", $clozetext_array);
287 foreach ($gaptext as $idx => $val) {
288 $clozetext = str_replace(
"<<" . $idx .
">>", $val, $clozetext);
290 $this->
object->setClozeTextValue($clozetext);
293 $this->
object->setAdditionalContentEditingMode(
296 $this->
object->saveToDb();
298 if (is_array($combinations) && count($combinations) > 0) {
302 $gap_combinations->loadFromDb($this->
object->getId());
303 $this->
object->setGapCombinations($gap_combinations);
304 $this->
object->setGapCombinationsExists(
true);
308 foreach ($feedbacks as $ident => $material) {
309 $m = $this->
object->QTIMaterialToString($material);
310 $feedbacks[$ident] = $m;
312 foreach ($feedbacksgeneric as $correctness => $material) {
313 $m = $this->
object->QTIMaterialToString($material);
314 $feedbacksgeneric[$correctness] = $m;
325 $DIC[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
328 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
329 $clozetext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $clozetext);
330 foreach ($feedbacks as $ident => $material) {
331 $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
333 foreach ($feedbacksgeneric as $correctness => $material) {
334 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
340 foreach ($feedbacks as $ident => $material) {
342 $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
344 $fbIdentifier->getQuestionIndex(),
345 $fbIdentifier->getAnswerIndex(),
349 foreach ($feedbacksgeneric as $correctness => $material) {
350 $this->
object->feedbackOBJ->importGenericFeedback(
356 $this->
object->saveToDb();
358 if (count($item->suggested_solutions)) {
359 foreach ($item->suggested_solutions as $suggested_solution) {
360 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->
getContent(), $suggested_solution[
"gap_index"],
true);
362 $this->
object->saveToDb();
364 if (isset($tst_id) && $tst_id !== $questionpool_id) {
365 $qpl_qid = $this->
object->getId();
366 $tst_qid = $this->
object->duplicate(
true,
"",
"",
"", $tst_id);
367 $tst_object->questions[$question_counter++] = $tst_qid;
368 $import_mapping[$item->getIdent()] = array(
"pool" => $qpl_qid,
"test" => $tst_qid);
369 return $import_mapping;
372 if (isset($tst_id)) {
373 $tst_object->questions[$question_counter++] = $this->
object->getId();
374 $import_mapping[$item->getIdent()] = [
"pool" => 0,
"test" => $this->
object->getId()];
375 return $import_mapping;
378 $import_mapping[$item->getIdent()] = [
"pool" => $this->
object->getId(),
"test" => 0];
379 return $import_mapping;
390 $ident = explode(
'_', $ident);
392 if (count($ident) > 1) {
393 $fbIdentifier->setQuestionIndex($ident[0]);
394 $fbIdentifier->setAnswerIndex($ident[1]);
396 $fbIdentifier->setQuestionIndex($ident[0]);
397 $fbIdentifier->setAnswerIndex(0);
400 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)
static importGapCombinationToDb($question_id, $gap_combinations)
const CLOZE_TEXT
Cloze question constants.
processNonAbstractedImageReferences($text, $sourceNic)
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
getQplImportArchivDirectory()
returns the full path to extracted qpl import archiv (qpl import dir + qpl archiv subdir) ...
Class for cloze question gaps.
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, $import_mapping)
Creates a question from a QTI file.
static clearGapCombinationsFromDb($question_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) ...
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...
static clear(string $a_var)
buildFeedbackIdentifier($ident)
const FB_MODE_GAP_QUESTION
constants for different feedback modes (per gap or per gap-answers/options)