43 public function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, $import_mapping): array
51 $presentation = $item->getPresentation();
53 $questionimage = array();
54 $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
56 foreach ($presentation->order as $entry) {
57 switch ($entry[
"type"]) {
59 $response = $presentation->response[$entry[
"index"]];
61 switch (strtolower(get_class($rendertype))) {
62 case "ilqtirenderhotspot":
63 foreach ($rendertype->material as $mat) {
64 for (
$i = 0;
$i < $mat->getMaterialCount();
$i++) {
65 $m = $mat->getMaterial(
$i);
66 if (strcmp($m[
"type"],
"matimage") == 0) {
67 $questionimage = array(
68 "imagetype" => $m[
"material"]->getImageType(),
69 "label" => $m[
"material"]->getLabel(),
75 foreach ($rendertype->response_labels as $response_label) {
76 $ident = $response_label->getIdent();
78 foreach ($response_label->material as $mat) {
79 $answerhint .= $this->
object->QTIMaterialToString($mat);
81 $answers[$ident] = array(
82 "answerhint" => $answerhint,
83 "areatype" => $response_label->getRarea(),
84 "coordinates" => $response_label->getContent(),
86 "answerorder" => $response_label->getIdent(),
89 "points_unchecked" => 0
99 $feedbacksgeneric = array();
100 foreach ($item->resprocessing as $resprocessing) {
101 foreach ($resprocessing->respcondition as $respcondition) {
104 $conditionvar = $respcondition->getConditionvar();
105 foreach ($conditionvar->order as $order) {
106 switch ($order[
"field"]) {
111 $coordinates = $conditionvar->varinside[$order[
"index"]]->getContent();
114 $coordinates = $conditionvar->varequal[$order[
"index"]]->getContent();
118 foreach ($respcondition->setvar as $setvar) {
119 foreach ($answers as $ident => $answer) {
120 if (strcmp($answer[
"coordinates"], $coordinates) == 0) {
122 $answers[$ident][
"action"] = $setvar->getAction();
123 $answers[$ident][
"points"] = $setvar->getContent();
124 if (count($respcondition->displayfeedback)) {
125 foreach ($respcondition->displayfeedback as $feedbackpointer) {
126 if (strlen($feedbackpointer->getLinkrefid())) {
127 foreach ($item->itemfeedback as $ifb) {
128 if (strcmp($ifb->getIdent(),
"response_allcorrect") == 0) {
130 if (count($ifb->material)) {
131 foreach ($ifb->material as $material) {
132 $feedbacksgeneric[1] = $material;
135 if ((count($ifb->flow_mat) > 0)) {
136 foreach ($ifb->flow_mat as $fmat) {
137 if (count($fmat->material)) {
138 foreach ($fmat->material as $material) {
139 $feedbacksgeneric[1] = $material;
144 } elseif (strcmp($ifb->getIdent(),
"response_onenotcorrect") == 0) {
146 if (count($ifb->material)) {
147 foreach ($ifb->material as $material) {
148 $feedbacksgeneric[0] = $material;
151 if ((count($ifb->flow_mat) > 0)) {
152 foreach ($ifb->flow_mat as $fmat) {
153 if (count($fmat->material)) {
154 foreach ($fmat->material as $material) {
155 $feedbacksgeneric[0] = $material;
161 if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0) {
163 if (count($ifb->material)) {
164 foreach ($ifb->material as $material) {
165 $feedbacks[$ident] = $material;
168 if ((count($ifb->flow_mat) > 0)) {
169 foreach ($ifb->flow_mat as $fmat) {
170 if (count($fmat->material)) {
171 foreach ($fmat->material as $material) {
172 $feedbacks[$ident] = $material;
183 $answers[$ident][
"action"] = $setvar->getAction();
184 $answers[$ident][
"points_unchecked"] = $setvar->getContent();
193 $this->
object->setTitle($item->getTitle());
194 $this->
object->setNrOfTries((
int) $item->getMaxattempts());
195 $this->
object->setComment($item->getComment());
196 $this->
object->setAuthor($item->getAuthor());
197 $this->
object->setOwner(
$ilUser->getId());
198 $this->
object->setQuestion($this->
object->QTIMaterialToString($item->getQuestiontext()));
199 $this->
object->setObjId($questionpool_id);
200 $this->
object->setIsMultipleChoice($item->getMetadataEntry(
"IS_MULTIPLE_CHOICE"));
201 $areas = array(
"2" =>
"rect",
"1" =>
"circle",
"3" =>
"poly");
202 $this->
object->setImageFilename($questionimage[
"label"]);
203 foreach ($answers as $answer) {
204 $this->
object->addAnswer($answer[
"answerhint"], $answer[
"points"], $answer[
"answerorder"], $answer[
"coordinates"], $areas[$answer[
"areatype"]], $answer[
"points_unchecked"]);
207 $this->
object->setAdditionalContentEditingMode(
210 $this->
object->saveToDb();
211 if (count($item->suggested_solutions)) {
212 foreach ($item->suggested_solutions as $suggested_solution) {
213 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->
getContent(), $suggested_solution[
"gap_index"],
true);
215 $this->
object->saveToDb();
217 $image = base64_decode($questionimage[
"content"]);
218 $imagepath = $this->
object->getImagePath();
219 if (!file_exists($imagepath)) {
222 $imagepath .= $questionimage[
"label"];
223 $fh = fopen($imagepath,
"wb");
225 $imagefile = fwrite($fh, $image);
229 foreach ($feedbacks as $ident => $material) {
230 $m = $this->
object->QTIMaterialToString($material);
231 $feedbacks[$ident] = $m;
233 foreach ($feedbacksgeneric as $correctness => $material) {
234 $m = $this->
object->QTIMaterialToString($material);
235 $feedbacksgeneric[$correctness] = $m;
237 $questiontext = $this->
object->getQuestion();
247 $DIC[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
251 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
252 foreach ($feedbacks as $ident => $material) {
253 $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
255 foreach ($feedbacksgeneric as $correctness => $material) {
256 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
261 foreach ($feedbacks as $ident => $material) {
262 $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
269 foreach ($feedbacksgeneric as $correctness => $material) {
270 $this->
object->feedbackOBJ->importGenericFeedback(
276 $this->
object->saveToDb();
278 $q_1_id = $this->
object->getId();
279 $question_id = $this->
object->duplicate(
true,
"",
"",
"", $tst_id);
280 $tst_object->questions[$question_counter++] = $question_id;
281 $import_mapping[$item->getIdent()] = array(
"pool" => $q_1_id,
"test" => $question_id);
283 $import_mapping[$item->getIdent()] = array(
"pool" => $this->
object->getId(),
"test" => 0);
285 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)
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) ...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, $import_mapping)
Creates a question from a QTI file.
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
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...
static clear(string $a_var)