31 string $importdirectory,
37 int &$question_counter,
46 foreach ($presentation->order as $entry) {
47 switch ($entry[
"type"]) {
49 $response = $presentation->response[$entry[
"index"]];
51 switch (strtolower(get_class($rendertype))) {
52 case "ilqtirenderhotspot":
53 foreach ($rendertype->material as $mat) {
54 for ($i = 0; $i < $mat->getMaterialCount(); $i++) {
55 $m = $mat->getMaterial($i);
56 if (strcmp($m[
"type"],
"matimage") == 0) {
58 "imagetype" => $m[
"material"]->getImageType(),
59 "label" => $m[
"material"]->getLabel(),
60 "content" => $m[
"material"]->getContent()
65 foreach ($rendertype->response_labels as $response_label) {
66 $ident = $response_label->getIdent();
68 foreach ($response_label->material as $mat) {
72 "answerhint" => $answerhint,
73 "areatype" => $response_label->getRarea(),
74 "coordinates" => $response_label->getContent(),
76 "answerorder" => $response_label->getIdent(),
79 "points_unchecked" => 0
89 $feedbacksgeneric = [];
90 foreach ($item->resprocessing as $resprocessing) {
91 foreach ($resprocessing->respcondition as $respcondition) {
94 $conditionvar = $respcondition->getConditionvar();
95 foreach ($conditionvar->order as $order) {
96 switch ($order[
"field"]) {
101 $coordinates = $conditionvar->varinside[$order[
"index"]]->getContent();
104 $coordinates = $conditionvar->varequal[$order[
"index"]]->getContent();
108 foreach ($respcondition->setvar as $setvar) {
109 foreach ($answers as $ident => $answer) {
110 if (strcmp($answer[
"coordinates"], $coordinates) == 0) {
112 $answers[$ident][
"action"] = $setvar->getAction();
113 $answers[$ident][
"points"] = $setvar->getContent();
114 if (count($respcondition->displayfeedback)) {
115 foreach ($respcondition->displayfeedback as $feedbackpointer) {
116 if (strlen($feedbackpointer->getLinkrefid())) {
117 foreach ($item->itemfeedback as $ifb) {
118 if (strcmp($ifb->getIdent(),
"response_allcorrect") == 0) {
120 if (count($ifb->material)) {
121 foreach ($ifb->material as $material) {
122 $feedbacksgeneric[1] = $material;
125 if ((count($ifb->flow_mat) > 0)) {
126 foreach ($ifb->flow_mat as $fmat) {
127 if (count($fmat->material)) {
128 foreach ($fmat->material as $material) {
129 $feedbacksgeneric[1] = $material;
134 } elseif (strcmp($ifb->getIdent(),
"response_onenotcorrect") == 0) {
136 if (count($ifb->material)) {
137 foreach ($ifb->material as $material) {
138 $feedbacksgeneric[0] = $material;
141 if ((count($ifb->flow_mat) > 0)) {
142 foreach ($ifb->flow_mat as $fmat) {
143 if (count($fmat->material)) {
144 foreach ($fmat->material as $material) {
145 $feedbacksgeneric[0] = $material;
151 if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0) {
153 if (count($ifb->material)) {
154 foreach ($ifb->material as $material) {
155 $feedbacks[$ident] = $material;
158 if ((count($ifb->flow_mat) > 0)) {
159 foreach ($ifb->flow_mat as $fmat) {
160 if (count($fmat->material)) {
161 foreach ($fmat->material as $material) {
162 $feedbacks[$ident] = $material;
173 $answers[$ident][
"action"] = $setvar->getAction();
174 $answers[$ident][
"points_unchecked"] = $setvar->getContent();
183 $this->
object->setTitle($item->
getTitle());
185 $this->
object->setComment($item->
getComment());
186 $this->
object->setAuthor($item->
getAuthor());
187 $this->
object->setOwner($user_id);
189 $this->
object->setObjId($questionpool_id);
190 $this->
object->setIsMultipleChoice($item->
getMetadataEntry(
"IS_MULTIPLE_CHOICE"));
191 $areas = [
"2" =>
"rect",
"1" =>
"circle",
"3" =>
"poly"];
192 $this->
object->setImageFilename($questionimage[
"label"]);
193 foreach ($answers as $answer) {
194 $this->
object->addAnswer($answer[
"answerhint"], $answer[
"points"], $answer[
"answerorder"], $answer[
"coordinates"], $areas[$answer[
"areatype"]], $answer[
"points_unchecked"]);
197 $this->
object->setAdditionalContentEditingMode(
200 $this->
object->saveToDb();
202 $image = base64_decode($questionimage[
"content"]);
203 $imagepath = $this->
object->getImagePath();
204 if (!file_exists($imagepath)) {
207 $imagepath .= $questionimage[
"label"];
208 $fh = fopen($imagepath,
"wb");
210 $imagefile = fwrite($fh, $image);
214 foreach ($feedbacks as $ident => $material) {
216 $feedbacks[$ident] = $m;
218 foreach ($feedbacksgeneric as $correctness => $material) {
220 $feedbacksgeneric[$correctness] = $m;
222 $questiontext = $this->
object->getQuestion();
225 $importfile = $importdirectory . DIRECTORY_SEPARATOR . $mob[
"uri"];
228 $DIC[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
232 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
233 foreach ($feedbacks as $ident => $material) {
234 $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
236 foreach ($feedbacksgeneric as $correctness => $material) {
237 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
242 foreach ($feedbacks as $ident => $material) {
243 $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
250 foreach ($feedbacksgeneric as $correctness => $material) {
251 $this->
object->feedbackOBJ->importGenericFeedback(
257 $this->
object->saveToDb();
259 $q_1_id = $this->
object->getId();
260 $question_id = $this->
object->duplicate(
true,
"",
"", -1, $tst_id);
261 $tst_object->questions[$question_counter++] = $question_id;
262 $import_mapping[$item->
getIdent()] = [
"pool" => $q_1_id,
"test" => $question_id];
264 $import_mapping[$item->
getIdent()] = [
"pool" => $this->
object->getId(),
"test" => 0];
266 return $import_mapping;
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)
addGeneralMetadata(ilQTIItem $item)
QTIMaterialToString(ilQTIMaterial $a_material)
Reads an QTI material tag and creates a text or XHTML string.
getMetadataEntry(string $a_label)
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
fromXML(string $importdirectory, int $user_id, ilQTIItem $item, int $questionpool_id, ?int $tst_id, ?ilObject &$tst_object, int &$question_counter, array $import_mapping)
importSuggestedSolutions(int $question_id, array $solution_from_import)
Class for question imports.
static clear(string $a_var)