48 public function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, $import_mapping): array
56 $presentation = $item->getPresentation();
60 $created = sprintf(
"%04d%02d%02d%02d%02d%02d", $now[
'year'], $now[
'mon'], $now[
'mday'], $now[
'hours'], $now[
'minutes'], $now[
'seconds']);
64 foreach ($presentation->order as $entry) {
65 switch ($entry[
"type"]) {
67 $response = $presentation->response[$entry[
"index"]];
71 } elseif (
$response->getIdent() ==
'OQNP') {
73 } elseif (
$response->getIdent() ==
'OQNT') {
75 } elseif (
$response->getIdent() ==
'OQT') {
80 switch (strtolower(get_class($rendertype))) {
81 case "ilqtirenderchoice":
82 $shuffle = $rendertype->getShuffle();
84 foreach ($rendertype->response_labels as $response_label) {
85 $ident = $response_label->getIdent();
89 foreach ($response_label->material as $mat) {
90 for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
91 $foundmat = $mat->getMaterial($m);
93 if (strcmp($foundmat[
"material"]->getLabel(),
"answerdepth") == 0) {
94 $answerdepth = $foundmat[
"material"]->getContent();
96 if (strcmp($foundmat[
"type"],
"mattext") == 0
97 && strcmp($foundmat[
"material"]->getLabel(),
"answerdepth") != 0) {
98 $answertext .= $foundmat[
"material"]->getContent();
100 if (strcmp($foundmat[
"type"],
"matimage") == 0
101 && strcmp($foundmat[
"material"]->getLabel(),
"answerdepth") != 0) {
103 $answerimage = array(
104 "imagetype" => $foundmat[
"material"]->getImageType(),
105 "label" => $foundmat[
"material"]->getLabel(),
106 "content" => $foundmat[
"material"]->
getContent()
111 $answers[$answerorder] = array(
113 "answertext" => $answertext,
114 "answerimage" => $answerimage,
116 "answerorder" => $answerorder,
117 "answerdepth" => $answerdepth,
129 $feedbacksgeneric = array();
130 foreach ($item->resprocessing as $resprocessing) {
131 foreach ($resprocessing->respcondition as $respcondition) {
134 $conditionvar = $respcondition->getConditionvar();
135 foreach ($conditionvar->order as $order) {
136 switch ($order[
"field"]) {
141 $ident = $conditionvar->varequal[$order[
"index"]]->getContent();
142 $orderindex = $conditionvar->varequal[$order[
"index"]]->getIndex();
146 foreach ($respcondition->setvar as $setvar) {
147 if (strcmp($ident,
"") != 0) {
148 $answers[$ident][
"solutionorder"] = $orderindex;
149 $answers[$ident][
"action"] = $setvar->getAction();
150 $answers[$ident][
"points"] = $setvar->getContent();
153 if (count($respcondition->displayfeedback)) {
154 foreach ($respcondition->displayfeedback as $feedbackpointer) {
155 if (strlen($feedbackpointer->getLinkrefid())) {
156 foreach ($item->itemfeedback as $ifb) {
157 if (strcmp($ifb->getIdent(),
"response_allcorrect") == 0) {
159 if (count($ifb->material)) {
160 foreach ($ifb->material as $material) {
161 $feedbacksgeneric[1] = $material;
164 if ((count($ifb->flow_mat) > 0)) {
165 foreach ($ifb->flow_mat as $fmat) {
166 if (count($fmat->material)) {
167 foreach ($fmat->material as $material) {
168 $feedbacksgeneric[1] = $material;
173 } elseif (strcmp($ifb->getIdent(),
"response_onenotcorrect") == 0) {
175 if (count($ifb->material)) {
176 foreach ($ifb->material as $material) {
177 $feedbacksgeneric[0] = $material;
180 if ((count($ifb->flow_mat) > 0)) {
181 foreach ($ifb->flow_mat as $fmat) {
182 if (count($fmat->material)) {
183 foreach ($fmat->material as $material) {
184 $feedbacksgeneric[0] = $material;
200 $this->
object->setTitle($item->getTitle());
201 $this->
object->setNrOfTries((
int) $item->getMaxattempts());
202 $this->
object->setComment($item->getComment());
203 $this->
object->setAuthor($item->getAuthor());
204 $this->
object->setOwner(
$ilUser->getId());
205 $this->
object->setQuestion($this->
object->QTIMaterialToString($item->getQuestiontext()));
206 $this->
object->setOrderingType(
$type);
207 $this->
object->setObjId($questionpool_id);
208 $this->
object->setThumbSize(
211 $this->
object->setElementHeight($item->getMetadataEntry(
'element_height')
212 ? (
int) $item->getMetadataEntry(
'element_height')
214 $this->
object->setShuffle($shuffle);
215 $this->
object->setPoints(0);
216 $this->
object->saveQuestionDataToDb();
218 $solanswers = array();
220 foreach ($answers as $answer) {
221 $solanswers[$answer[
"solutionorder"] ?? null] = $answer;
225 $element_list = $this->
object->getOrderingElementList();
226 foreach ($solanswers as $answer) {
227 $points += $answer[
"points"];
231 if ($element->isExportIdent($answer[
'ident'])) {
232 $element->setExportIdent($answer[
'ident']);
234 $element = $element->withPosition($position++);
235 if (isset($answer[
'answerdepth'])) {
236 $element = $element->withIndentation((
int) $answer[
'answerdepth']);
240 if ($this->
object->isImageOrderingType()) {
241 $filename = $this->handleUploadedfile($answer);
243 $element = $element->withContent(
$filename);
246 $element = $element->withContent($answer[
"answertext"]);
249 $element_list->addElement($element);
251 $this->
object->setOrderingElementList($element_list);
252 $points = ($item->getMetadataEntry(
"points") > 0) ? $item->getMetadataEntry(
"points") : $points;
253 $this->
object->setPoints($points);
255 $this->
object->setAdditionalContentEditingMode(
258 $this->
object->saveToDb();
259 if (count($item->suggested_solutions)) {
260 foreach ($item->suggested_solutions as $suggested_solution) {
261 $this->
object->setSuggestedSolution($suggested_solution[
"solution"]->
getContent(), $suggested_solution[
"gap_index"],
true);
263 $this->
object->saveToDb();
266 foreach ($feedbacksgeneric as $correctness => $material) {
267 $m = $this->
object->QTIMaterialToString($material);
268 $feedbacksgeneric[$correctness] = $m;
270 $questiontext = $this->
object->getQuestion();
282 $DIC[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
286 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
287 foreach ($this->
object->getOrderingElementList() as $element) {
288 $element->setContent(str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $element->getContent()));
290 foreach ($feedbacksgeneric as $correctness => $material) {
291 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
293 foreach ($itemfeedbacks as $ident => $material) {
294 $itemfeedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
299 foreach ($this->
object->getOrderingElementList() as $element) {
302 foreach ($feedbacksgeneric as $correctness => $material) {
303 $this->
object->feedbackOBJ->importGenericFeedback(
309 foreach ($itemfeedbacks as $ident => $material) {
312 $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
319 $this->
object->saveToDb();
320 if (isset($tst_id) && $tst_id !== $questionpool_id) {
321 $qplQid = $this->
object->getId();
322 $tstQid = $this->
object->duplicate(
true,
'',
'',
'', $tst_id);
323 $tst_object->questions[$question_counter++] = $tstQid;
324 $import_mapping[$item->getIdent()] = [
"pool" => $qplQid,
"test" => $tstQid];
325 return $import_mapping;
329 $tst_object->questions[$question_counter++] = $this->
object->getId();
330 $import_mapping[$item->getIdent()] = [
"pool" => 0,
"test" => $this->
object->getId()];
331 return $import_mapping;
334 $import_mapping[$item->getIdent()] = [
"pool" => $this->
object->getId(),
"test" => 0];
335 return $import_mapping;
340 $image = base64_decode($answer[
"answerimage"][
"content"] ??
'');
341 $image_file_name = $answer[
'answerimage'][
'label'] ??
'';
344 $file_handle = fopen($tmp_path,
"wb");
345 if ($file_handle ===
false) {
348 fwrite($file_handle, $image);
349 fclose($file_handle);
351 $filename_path_parts = explode(
".", $image_file_name);
352 $suffix = strtolower(array_pop($filename_path_parts));
358 $target_filename = $this->
object->buildHashedImageFilename($image_file_name,
true);
359 $target_filepath = $this->
object->getImagePath() . $target_filename;
360 if (rename($tmp_path, $target_filepath)) {
361 $thumb_path = $this->
object->getImagePath() . $this->
object->getThumbPrefix() . $target_filename;
363 return $target_filename;
371 if (!file_exists($this->
object->getImagePath())) {
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)
getFeedbackAnswerSpecific(ilQTIItem $item, $prefix='response_')
deduceThumbSizeFromImportValue(?int $size)
addGeneralMetadata(ilQTIItem $item)
fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$question_counter, $import_mapping)
Creates a question from a QTI file.
const VALID_UPLOAD_SUFFIXES
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) ...
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const OQ_PICTURES
Ordering question constants.
handleUploadedFile(array $answer)
static convertImage(string $a_from, string $a_to, string $a_target_format="", string $a_geometry="", string $a_background_color="")
convert image
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
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)
fetchIndexFromFeedbackIdent($feedbackIdent, $prefix='response_')