4 include_once
"./Modules/TestQuestionPool/classes/import/qti12/class.assQuestionImport.php";
30 function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
36 $presentation = $item->getPresentation();
39 $packageIliasVersion = $item->getIliasSourceVersion(
'ILIAS_VERSION');
40 $seperate_question_field = $item->getMetadataEntry(
"question");
43 if( !$packageIliasVersion || version_compare($packageIliasVersion,
'5.0.0',
'<') )
45 $questiontext =
' ';
47 elseif($seperate_question_field)
50 $seperate_question_field, $item->getIliasSourceNic()
57 $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
59 foreach ($presentation->order as $entry)
61 switch ($entry[
"type"])
65 $materialString = $this->
object->QTIMaterialToString(
66 $presentation->material[$entry[
"index"]]
69 if($questiontext === null)
71 $questiontext = $materialString;
75 array_push($clozetext, $materialString);
80 $response = $presentation->response[$entry[
"index"]];
81 $rendertype = $response->getRenderType();
82 array_push($clozetext,
"<<" . $response->getIdent() .
">>");
84 switch (strtolower(get_class($response->getRenderType())))
86 case "ilqtirenderfib":
87 switch ($response->getRenderType()->getFibtype())
93 "ident" => $response->getIdent(),
96 "minnumber" => $response->getRenderType()->getMinnumber(),
97 "maxnumber" => $response->getRenderType()->getMaxnumber(),
98 'gap_size' => $response->getRenderType()->getMaxchars()
105 array(
"ident" => $response->getIdent(),
107 "answers" =>
array(),
108 'gap_size' => $response->getRenderType()->getMaxchars()
113 case "ilqtirenderchoice":
115 $shuffle = $rendertype->getShuffle();
117 foreach ($rendertype->response_labels as $response_label)
119 $ident = $response_label->getIdent();
121 foreach ($response_label->material as $mat)
123 $answertext .= $this->
object->QTIMaterialToString($mat);
125 $answers[$ident] =
array(
126 "answertext" => $answertext,
128 "answerorder" => $answerorder++,
130 "shuffle" => $rendertype->getShuffle()
133 array_push($gaps,
array(
"ident" => $response->getIdent(),
"type" =>
CLOZE_SELECT,
"shuffle" => $rendertype->getShuffle(),
"answers" => $answers));
139 $responses =
array();
140 $feedbacks =
array();
141 $feedbacksgeneric =
array();
142 foreach ($item->resprocessing as $resprocessing)
144 foreach ($resprocessing->respcondition as $respcondition)
148 $conditionvar = $respcondition->getConditionvar();
149 foreach ($conditionvar->order as $order)
151 switch ($order[
"field"])
154 $equals = $conditionvar->varequal[$order[
"index"]]->getContent();
155 $gapident = $conditionvar->varequal[$order[
"index"]]->getRespident();
159 foreach ($respcondition->setvar as $setvar)
161 if (strcmp($gapident,
"") != 0)
163 foreach ($gaps as $gi => $g)
165 if (strcmp($g[
"ident"], $gapident) == 0)
169 foreach ($gaps[$gi][
"answers"] as
$ai => $answer)
171 if (strcmp($answer[
"answertext"], $equals) == 0)
173 $gaps[$gi][
"answers"][
$ai][
"action"] = $setvar->getAction();
174 $gaps[$gi][
"answers"][
$ai][
"points"] = $setvar->getContent();
180 array_push($gaps[$gi][
"answers"],
array(
181 "answertext" => $equals,
182 "points" => $setvar->getContent(),
183 "answerorder" => count($gaps[$gi][
"answers"]),
184 "action" => $setvar->getAction()
190 array_push($gaps[$gi][
"answers"],
array(
191 "answertext" => $equals,
192 "points" => $setvar->getContent(),
193 "answerorder" => count($gaps[$gi][
"answers"]),
194 "action" => $setvar->getAction()
202 if (count($respcondition->displayfeedback))
204 foreach ($respcondition->displayfeedback as $feedbackpointer)
206 if (strlen($feedbackpointer->getLinkrefid()))
208 foreach ($item->itemfeedback as $ifb)
210 if (strcmp($ifb->getIdent(),
"response_allcorrect") == 0)
213 if (count($ifb->material))
215 foreach ($ifb->material as $material)
217 $feedbacksgeneric[1] = $material;
220 if ((count($ifb->flow_mat) > 0))
222 foreach ($ifb->flow_mat as $fmat)
224 if (count($fmat->material))
226 foreach ($fmat->material as $material)
228 $feedbacksgeneric[1] = $material;
234 else if (strcmp($ifb->getIdent(),
"response_onenotcorrect") == 0)
237 if (count($ifb->material))
239 foreach ($ifb->material as $material)
241 $feedbacksgeneric[0] = $material;
244 if ((count($ifb->flow_mat) > 0))
246 foreach ($ifb->flow_mat as $fmat)
248 if (count($fmat->material))
250 foreach ($fmat->material as $material)
252 $feedbacksgeneric[0] = $material;
261 if (count($ifb->material))
263 foreach ($ifb->material as $material)
265 $feedbacks[$ifb->getIdent()] = $material;
268 if ((count($ifb->flow_mat) > 0))
270 foreach ($ifb->flow_mat as $fmat)
272 if (count($fmat->material))
274 foreach ($fmat->material as $material)
276 $feedbacks[$ifb->getIdent()] = $material;
292 $this->
object->setTitle($item->getTitle());
293 $this->
object->setNrOfTries($item->getMaxattempts());
294 $this->
object->setComment($item->getComment());
295 $this->
object->setAuthor($item->getAuthor());
296 $this->
object->setOwner($ilUser->getId());
297 $this->
object->setObjId($questionpool_id);
299 $textgap_rating = $item->getMetadataEntry(
"textgaprating");
300 $this->
object->setFixedTextLength($item->getMetadataEntry(
"fixedTextLength"));
301 $this->
object->setIdenticalScoring($item->getMetadataEntry(
"identicalScoring"));
302 $combination = json_decode(base64_decode($item->getMetadataEntry(
"combinations")));
303 if (strlen($textgap_rating) == 0) $textgap_rating =
"ci";
304 $this->
object->setTextgapRating($textgap_rating);
306 foreach ($gaps as $gapidx => $gap)
308 $gapcontent =
array();
309 include_once
"./Modules/TestQuestionPool/classes/class.assClozeGap.php";
311 foreach ($gap[
"answers"] as $index => $answer)
313 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerCloze.php";
314 $gapanswer =
new assAnswerCloze($answer[
"answertext"], $answer[
"points"], $answer[
"answerorder"]);
315 $gapanswer->setGapSize($gap[
"gap_size"]);
316 switch ($clozegap->getType())
319 $clozegap->setShuffle($answer[
"shuffle"]);
322 $gapanswer->setLowerBound($gap[
"minnumber"]);
323 $gapanswer->setUpperBound($gap[
"maxnumber"]);
326 $clozegap->setGapSize($gap[
"gap_size"]);
327 $clozegap->addItem($gapanswer);
328 array_push($gapcontent, $answer[
"answertext"]);
330 $this->
object->addGapAtIndex($clozegap, $gapidx);
331 $gaptext[$gap[
"ident"]] =
"[gap]" . join(
",", $gapcontent).
"[/gap]";
334 $this->
object->setQuestion($questiontext);
335 $clozetext = join(
"", $clozetext);
337 foreach ($gaptext as $idx => $val)
339 $clozetext = str_replace(
"<<" . $idx .
">>", $val, $clozetext);
341 $this->
object->setClozeTextValue($clozetext);
344 $this->
object->setAdditionalContentEditingMode(
347 $this->
object->saveToDb();
350 foreach ($feedbacks as $ident => $material)
352 $m = $this->
object->QTIMaterialToString($material);
353 $feedbacks[$ident] = $m;
355 foreach ($feedbacksgeneric as $correctness => $material)
357 $m = $this->
object->QTIMaterialToString($material);
358 $feedbacksgeneric[$correctness] = $m;
360 $questiontext = $this->
object->getQuestion();
361 $clozetext = $this->
object->getClozeText();
362 if (is_array(
$_SESSION[
"import_mob_xhtml"]))
364 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
365 include_once
"./Services/RTE/classes/class.ilRTE.php";
366 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob)
377 $GLOBALS[
'ilLog']->write(__METHOD__.
': import mob from dir: '. $importfile);
380 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
381 $clozetext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $clozetext);
382 foreach ($feedbacks as $ident => $material)
384 $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
386 foreach ($feedbacksgeneric as $correctness => $material)
388 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
394 foreach ($feedbacks as $ident => $material)
396 $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
400 foreach ($feedbacksgeneric as $correctness => $material)
402 $this->
object->feedbackOBJ->importGenericFeedback(
406 $this->
object->saveToDb();
407 if (count($item->suggested_solutions))
409 foreach ($item->suggested_solutions as $suggested_solution)
411 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->getContent(), $suggested_solution[
"gap_index"],
true);
413 $this->
object->saveToDb();
417 $q_1_id = $this->
object->getId();
418 $question_id = $this->
object->duplicate(
true, null, null, null, $tst_id);
419 $tst_object->questions[$question_counter++] = $question_id;
420 $import_mapping[$item->getIdent()] =
array(
"pool" => $q_1_id,
"test" => $question_id);
424 $import_mapping[$item->getIdent()] =
array(
"pool" => $this->
object->getId(),
"test" => 0);
426 $this->
object->saveToDb();
427 if(count($combination) > 0)
429 require_once
'./Modules/TestQuestionPool/classes/class.assClozeGapCombination.php';
433 $this->
object->saveToDb();
Class for cloze question numeric answers.
addGeneralMetadata(ilQTIItem $item)
static importGapCombinationToDb($question_id, $gap_combinations)
const CLOZE_TEXT
Cloze question constants.
processNonAbstractedImageReferences($text, $sourceNic)
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
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.
static _replaceMediaObjectImageSrc($a_text, $a_direction=0, $nic=IL_INST_ID)
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
Creates a question from a QTI file.
static clearGapCombinationsFromDb($question_id)
Create styles array
The data for the language used.
Create new PHPExcel object
obj_idprivate
Class for cloze question imports.
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) ...
Class for question imports.