4include_once
"./Modules/TestQuestionPool/classes/import/qti12/class.assQuestionImport.php";
30 function fromXML(&$item, &$questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
35 $presentation = $item->getPresentation();
36 $duration = $item->getDuration();
39 $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
41 foreach ($presentation->order as $entry)
43 switch ($entry[
"type"])
46 $response = $presentation->response[$entry[
"index"]];
47 $rendertype = $response->getRenderType();
48 switch (strtolower(get_class($response->getRenderType())))
50 case "ilqtirenderchoice":
51 $shuffle = $rendertype->getShuffle();
54 foreach ($rendertype->response_labels as $response_label)
56 $ident = $response_label->getIdent();
58 $answerimage = array();
59 foreach ($response_label->material as $mat)
62 for ($m = 0; $m < $mat->getMaterialCount(); $m++)
64 $foundmat = $mat->getMaterial($m);
65 if (strcmp($foundmat[
"type"],
"mattext") == 0)
68 if (strcmp($foundmat[
"type"],
"matimage") == 0)
70 if (strlen($foundmat[
"material"]->getEmbedded()))
78 for ($m = 0; $m < $mat->getMaterialCount(); $m++)
80 $foundmat = $mat->getMaterial($m);
81 if (strcmp($foundmat[
"type"],
"mattext") == 0)
83 $answertext .= $foundmat[
"material"]->getContent();
85 if (strcmp($foundmat[
"type"],
"matimage") == 0)
89 "imagetype" => $foundmat[
"material"]->getImageType(),
90 "label" => $foundmat[
"material"]->getLabel(),
91 "content" => $foundmat[
"material"]->getContent()
98 $answertext = $this->
object->QTIMaterialToString($mat);
101 $answers[$ident] = array(
102 "answertext" => $answertext,
103 "imagefile" => $answerimage,
105 "answerorder" => $answerorder++,
106 "points_unchecked" => 0,
115 $responses = array();
116 $feedbacks = array();
117 $feedbacksgeneric = array();
118 foreach ($item->resprocessing as $resprocessing)
120 foreach ($resprocessing->respcondition as $respcondition)
124 $conditionvar = $respcondition->getConditionvar();
125 foreach ($conditionvar->order as $order)
127 switch ($order[
"field"])
133 $ident = $conditionvar->varequal[$order[
"index"]]->getContent();
137 foreach ($respcondition->setvar as $setvar)
139 if (strcmp($ident,
"") != 0)
143 $answers[$ident][
"action"] = $setvar->getAction();
144 $answers[$ident][
"points"] = $setvar->getContent();
145 if (count($respcondition->displayfeedback))
147 foreach ($respcondition->displayfeedback as $feedbackpointer)
149 if (strlen($feedbackpointer->getLinkrefid()))
151 foreach ($item->itemfeedback as $ifb)
153 if (strcmp($ifb->getIdent(),
"response_allcorrect") == 0)
156 if (count($ifb->material))
158 foreach ($ifb->material as $material)
160 $feedbacksgeneric[1] = $material;
163 if ((count($ifb->flow_mat) > 0))
165 foreach ($ifb->flow_mat as $fmat)
167 if (count($fmat->material))
169 foreach ($fmat->material as $material)
171 $feedbacksgeneric[1] = $material;
177 else if (strcmp($ifb->getIdent(),
"response_onenotcorrect") == 0)
180 if (count($ifb->material))
182 foreach ($ifb->material as $material)
184 $feedbacksgeneric[0] = $material;
187 if ((count($ifb->flow_mat) > 0))
189 foreach ($ifb->flow_mat as $fmat)
191 if (count($fmat->material))
193 foreach ($fmat->material as $material)
195 $feedbacksgeneric[0] = $material;
201 if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0)
204 if (count($ifb->material))
206 foreach ($ifb->material as $material)
208 $feedbacks[$ident] = $material;
211 if ((count($ifb->flow_mat) > 0))
213 foreach ($ifb->flow_mat as $fmat)
215 if (count($fmat->material))
217 foreach ($fmat->material as $material)
219 $feedbacks[$ident] = $material;
232 $answers[$ident][
"action"] = $setvar->getAction();
233 $answers[$ident][
"points_unchecked"] = $setvar->getContent();
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->setQuestion($this->object->QTIMaterialToString($item->getQuestiontext()));
246 $this->
object->setObjId($questionpool_id);
247 $this->
object->setEstimatedWorkingTime($duration[
"h"], $duration[
"m"], $duration[
"s"]);
248 $this->
object->setShuffle($shuffle);
249 $this->
object->setThumbSize($item->getMetadataEntry(
"thumb_size"));
251 foreach ($answers as $answer)
253 if (is_array($answer[
"imagefile"]) && (count($answer[
"imagefile"]) > 0))
255 $this->
object->isSingleline =
true;
257 $this->
object->addAnswer($answer[
"answertext"], $answer[
"points"], $answer[
"points_unchecked"], $answer[
"answerorder"], $answer[
"imagefile"][
"label"]);
260 $this->
object->setAdditionalContentEditingMode(
263 $this->
object->saveToDb();
264 foreach ($answers as $answer)
266 if (is_array($answer[
"imagefile"]) && (count($answer[
"imagefile"]) > 0))
268 $image =& base64_decode($answer[
"imagefile"][
"content"]);
269 $imagepath = $this->
object->getImagePath();
270 include_once
"./Services/Utilities/classes/class.ilUtil.php";
271 if (!file_exists($imagepath))
275 $imagepath .= $answer[
"imagefile"][
"label"];
276 $fh = fopen($imagepath,
"wb");
282 $imagefile = fwrite($fh, $image);
288 $feedbackSetting = $item->getMetadataEntry(
'feedback_setting');
289 if( !is_null($feedbackSetting) )
291 $this->
object->feedbackOBJ->saveSpecificFeedbackSetting($this->object->getId(), $feedbackSetting);
295 foreach ($feedbacks as $ident => $material)
297 $m = $this->
object->QTIMaterialToString($material);
298 $feedbacks[$ident] = $m;
300 foreach ($feedbacksgeneric as $correctness => $material)
302 $m = $this->
object->QTIMaterialToString($material);
303 $feedbacksgeneric[$correctness] = $m;
305 $questiontext = $this->
object->getQuestion();
306 $answers =& $this->
object->getAnswers();
307 if (is_array(
$_SESSION[
"import_mob_xhtml"]))
309 include_once
"./Services/MediaObjects/classes/class.ilObjMediaObject.php";
310 include_once
"./Services/RTE/classes/class.ilRTE.php";
311 foreach (
$_SESSION[
"import_mob_xhtml"] as $mob)
322 $GLOBALS[
'ilLog']->write(__METHOD__.
': import mob from dir: '. $importfile);
326 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
327 foreach ($answers as $key => $value)
329 $answer_obj =& $answers[$key];
330 $answer_obj->setAnswertext(str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $answer_obj->getAnswertext()));
332 foreach ($feedbacks as $ident => $material)
334 $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
336 foreach ($feedbacksgeneric as $correctness => $material)
338 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" . IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
343 foreach ($answers as $key => $value)
345 $answer_obj =& $answers[$key];
348 foreach ($feedbacks as $ident => $material)
350 $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
354 foreach ($feedbacksgeneric as $correctness => $material)
356 $this->
object->feedbackOBJ->importGenericFeedback(
360 $this->
object->saveToDb();
361 if (count($item->suggested_solutions))
363 foreach ($item->suggested_solutions as $suggested_solution)
365 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->getContent(), $suggested_solution[
"gap_index"],
true);
367 $this->
object->saveToDb();
371 $q_1_id = $this->
object->getId();
372 $question_id = $this->
object->duplicate(
true,
null,
null,
null, $tst_id);
373 $tst_object->questions[$question_counter++] = $question_id;
374 $import_mapping[$item->getIdent()] = array(
"pool" => $q_1_id,
"test" => $question_id);
378 $import_mapping[$item->getIdent()] = array(
"pool" => $this->object->getId(),
"test" => 0);
Class for multiple choice question imports.
fromXML(&$item, &$questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
Creates a question from a QTI file.
Class for question imports.
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir)
addGeneralMetadata(ilQTIItem $item)
getQplImportArchivDirectory()
returns the full path to extracted qpl import archiv (qpl import dir + qpl archiv subdir)
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 makeDirParents($a_dir)
Create a new directory and all parent directories.
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.