Creates a question from a QTI file.
36 $presentation = $item->getPresentation();
37 $duration = $item->getDuration();
39 $packageIliasVersion = $item->getIliasSourceVersion(
'ILIAS_VERSION');
40 $seperate_question_field = $item->getMetadataEntry(
"question");
43 if (!$packageIliasVersion || version_compare($packageIliasVersion,
'5.0.0',
'<')) {
44 $questiontext =
' ';
45 } elseif ($seperate_question_field) {
47 $seperate_question_field,
48 $item->getIliasSourceNic()
55 $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
57 foreach ($presentation->order as $entry) {
58 switch ($entry[
"type"]) {
61 $materialString = $this->
object->QTIMaterialToString(
62 $presentation->material[$entry[
"index"]]
65 if ($questiontext === null) {
66 $questiontext = $materialString;
68 array_push($clozetext, $materialString);
73 $response = $presentation->response[$entry[
"index"]];
75 array_push($clozetext,
"<<" .
$response->getIdent() .
">>");
77 switch (strtolower(get_class(
$response->getRenderType()))) {
78 case "ilqtirenderfib":
79 switch (
$response->getRenderType()->getFibtype()) {
88 "minnumber" =>
$response->getRenderType()->getMinnumber(),
89 "maxnumber" =>
$response->getRenderType()->getMaxnumber(),
90 'gap_size' =>
$response->getRenderType()->getMaxchars()
100 "answers" =>
array(),
101 'gap_size' =>
$response->getRenderType()->getMaxchars()
107 case "ilqtirenderchoice":
109 $shuffle = $rendertype->getShuffle();
111 foreach ($rendertype->response_labels as $response_label) {
112 $ident = $response_label->getIdent();
114 foreach ($response_label->material as $mat) {
115 $answertext .= $this->
object->QTIMaterialToString($mat);
117 $answers[$ident] =
array(
118 "answertext" => $answertext,
120 "answerorder" => $answerorder++,
122 "shuffle" => $rendertype->getShuffle()
125 array_push($gaps,
array(
"ident" =>
$response->getIdent(),
"type" =>
CLOZE_SELECT,
"shuffle" => $rendertype->getShuffle(),
"answers" => $answers));
131 $responses =
array();
132 $feedbacks =
array();
133 $feedbacksgeneric =
array();
134 foreach ($item->resprocessing as $resprocessing) {
135 foreach ($resprocessing->respcondition as $respcondition) {
138 $conditionvar = $respcondition->getConditionvar();
139 foreach ($conditionvar->order as $order) {
140 switch ($order[
"field"]) {
142 $equals = $conditionvar->varequal[$order[
"index"]]->getContent();
143 $gapident = $conditionvar->varequal[$order[
"index"]]->getRespident();
147 foreach ($respcondition->setvar as $setvar) {
148 if (strcmp($gapident,
"") != 0) {
149 foreach ($gaps as $gi => $g) {
150 if (strcmp($g[
"ident"], $gapident) == 0) {
152 foreach ($gaps[$gi][
"answers"] as $ai => $answer) {
153 if (strcmp($answer[
"answertext"], $equals) == 0) {
154 $gaps[$gi][
"answers"][$ai][
"action"] = $setvar->getAction();
155 $gaps[$gi][
"answers"][$ai][
"points"] = $setvar->getContent();
159 array_push($gaps[$gi][
"answers"],
array(
160 "answertext" => $equals,
161 "points" => $setvar->getContent(),
162 "answerorder" => count($gaps[$gi][
"answers"]),
163 "action" => $setvar->getAction()
167 array_push($gaps[$gi][
"answers"],
array(
168 "answertext" => $equals,
169 "points" => $setvar->getContent(),
170 "answerorder" => count($gaps[$gi][
"answers"]),
171 "action" => $setvar->getAction()
179 if (count($respcondition->displayfeedback)) {
180 foreach ($respcondition->displayfeedback as $feedbackpointer) {
181 if (strlen($feedbackpointer->getLinkrefid())) {
182 foreach ($item->itemfeedback as $ifb) {
183 if (strcmp($ifb->getIdent(),
"response_allcorrect") == 0) {
185 if (count($ifb->material)) {
186 foreach ($ifb->material as $material) {
187 $feedbacksgeneric[1] = $material;
190 if ((count($ifb->flow_mat) > 0)) {
191 foreach ($ifb->flow_mat as $fmat) {
192 if (count($fmat->material)) {
193 foreach ($fmat->material as $material) {
194 $feedbacksgeneric[1] = $material;
199 } elseif (strcmp($ifb->getIdent(),
"response_onenotcorrect") == 0) {
201 if (count($ifb->material)) {
202 foreach ($ifb->material as $material) {
203 $feedbacksgeneric[0] = $material;
206 if ((count($ifb->flow_mat) > 0)) {
207 foreach ($ifb->flow_mat as $fmat) {
208 if (count($fmat->material)) {
209 foreach ($fmat->material as $material) {
210 $feedbacksgeneric[0] = $material;
217 if (count($ifb->material)) {
218 foreach ($ifb->material as $material) {
219 $feedbacks[$ifb->getIdent()] = $material;
222 if ((count($ifb->flow_mat) > 0)) {
223 foreach ($ifb->flow_mat as $fmat) {
224 if (count($fmat->material)) {
225 foreach ($fmat->material as $material) {
226 $feedbacks[$ifb->getIdent()] = $material;
240 $this->
object->setTitle($item->getTitle());
241 $this->
object->setNrOfTries($item->getMaxattempts());
242 $this->
object->setComment($item->getComment());
243 $this->
object->setAuthor($item->getAuthor());
244 $this->
object->setOwner($ilUser->getId());
245 $this->
object->setObjId($questionpool_id);
246 $this->
object->setEstimatedWorkingTime($duration[
"h"], $duration[
"m"], $duration[
"s"]);
247 $textgap_rating = $item->getMetadataEntry(
"textgaprating");
248 $this->
object->setFixedTextLength($item->getMetadataEntry(
"fixedTextLength"));
249 $this->
object->setIdenticalScoring($item->getMetadataEntry(
"identicalScoring"));
250 $combination = json_decode(base64_decode($item->getMetadataEntry(
"combinations")));
251 if (strlen($textgap_rating) == 0) {
252 $textgap_rating =
"ci";
254 $this->
object->setTextgapRating($textgap_rating);
256 foreach ($gaps as $gapidx => $gap) {
257 $gapcontent =
array();
258 include_once
"./Modules/TestQuestionPool/classes/class.assClozeGap.php";
260 foreach ($gap[
"answers"] as
$index => $answer) {
261 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerCloze.php";
262 $gapanswer =
new assAnswerCloze($answer[
"answertext"], $answer[
"points"], $answer[
"answerorder"]);
263 $gapanswer->setGapSize($gap[
"gap_size"]);
264 switch ($clozegap->getType()) {
266 $clozegap->setShuffle($answer[
"shuffle"]);
269 $gapanswer->setLowerBound($gap[
"minnumber"]);
270 $gapanswer->setUpperBound($gap[
"maxnumber"]);
273 $clozegap->setGapSize($gap[
"gap_size"]);
274 $clozegap->addItem($gapanswer);
275 array_push($gapcontent, $answer[
"answertext"]);
277 $this->
object->addGapAtIndex($clozegap, $gapidx);
278 $gaptext[$gap[
"ident"]] =
"[gap]" . join(
",", $gapcontent) .
"[/gap]";
281 $this->
object->setQuestion($questiontext);
282 $clozetext = join(
"", $clozetext);
284 foreach ($gaptext as $idx => $val) {
285 $clozetext = str_replace(
"<<" . $idx .
">>", $val, $clozetext);
287 $this->
object->setClozeTextValue($clozetext);
290 $this->
object->setAdditionalContentEditingMode(
293 $this->
object->saveToDb();
296 foreach ($feedbacks as $ident => $material) {
297 $m = $this->
object->QTIMaterialToString($material);
298 $feedbacks[$ident] =
$m;
300 foreach ($feedbacksgeneric as $correctness => $material) {
301 $m = $this->
object->QTIMaterialToString($material);
302 $feedbacksgeneric[$correctness] =
$m;
304 $questiontext = $this->
object->getQuestion();
305 $clozetext = $this->
object->getClozeText();
306 if (is_array(
$_SESSION[
"import_mob_xhtml"])) {
307 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
308 include_once
"./Services/RTE/classes/class.ilRTE.php";
309 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob) {
316 $GLOBALS[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
319 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
320 $clozetext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $clozetext);
321 foreach ($feedbacks as $ident => $material) {
322 $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
324 foreach ($feedbacksgeneric as $correctness => $material) {
325 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
331 foreach ($feedbacks as $ident => $material) {
332 $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
338 foreach ($feedbacksgeneric as $correctness => $material) {
339 $this->
object->feedbackOBJ->importGenericFeedback(
345 $this->
object->saveToDb();
346 if (count($item->suggested_solutions)) {
347 foreach ($item->suggested_solutions as $suggested_solution) {
348 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->getContent(), $suggested_solution[
"gap_index"],
true);
350 $this->
object->saveToDb();
353 $q_1_id = $this->
object->getId();
354 $question_id = $this->
object->duplicate(
true, null, null, null, $tst_id);
355 $tst_object->questions[$question_counter++] = $question_id;
356 $import_mapping[$item->getIdent()] =
array(
"pool" => $q_1_id,
"test" => $question_id);
358 $import_mapping[$item->getIdent()] =
array(
"pool" => $this->
object->getId(),
"test" => 0);
360 $this->
object->saveToDb();
361 if (is_array($combination) && count($combination) > 0) {
362 require_once
'./Modules/TestQuestionPool/classes/class.assClozeGapCombination.php';
366 $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...
static clearGapCombinationsFromDb($question_id)
Create styles array
The data for the language used.
Create new PHPExcel object
obj_idprivate
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) ...