36 string $importdirectory,
42 int &$question_counter,
54 foreach ($presentation->order as $entry) {
55 switch ($entry[
'type']) {
57 $response = $presentation->response[$entry[
"index"]];
61 } elseif (
$response->getIdent() ===
'OQNP') {
63 } elseif (
$response->getIdent() ===
'OQNT') {
65 } elseif (
$response->getIdent() ===
'OQT') {
70 switch (get_class($rendertype)) {
71 case ilQTIRenderChoice::class:
72 $shuffle = $rendertype->getShuffle();
74 foreach ($rendertype->response_labels as $response_label) {
75 $ident = $response_label->getIdent();
79 foreach ($response_label->material as $mat) {
80 for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
81 $foundmat = $mat->getMaterial($m);
83 if ($foundmat[
'material']->
getLabel() ===
'answerdepth') {
84 $answerdepth = $foundmat[
'material']->getContent();
86 if ($foundmat[
'type'] ===
'mattext' 87 && $foundmat[
'material']->
getLabel() !==
'answerdepth') {
88 $answertext .= $foundmat[
'material']->getContent();
90 if ($foundmat[
'type'] ===
'matimage' 91 && $foundmat[
'material']->
getLabel() !==
'answerdepth') {
94 'imagetype' => $foundmat[
'material']->getImageType(),
95 'label' => $foundmat[
'material']->getLabel(),
96 'content' => $foundmat[
'material']->getContent()
101 $answers[$answerorder] = [
103 'answertext' => $answertext,
104 'answerimage' => $answerimage,
106 'answerorder' => $answerorder,
107 'answerdepth' => $answerdepth,
119 $feedbacksgeneric = [];
120 foreach ($item->resprocessing as $resprocessing) {
121 foreach ($resprocessing->respcondition as $respcondition) {
124 $conditionvar = $respcondition->getConditionvar();
125 foreach ($conditionvar->order as $order) {
126 switch ($order[
'field']) {
131 $ident = $conditionvar->varequal[$order[
'index']]->getContent();
132 $orderindex = $conditionvar->varequal[$order[
'index']]->getIndex();
136 foreach ($respcondition->setvar as $setvar) {
138 $answers[$ident][
'solutionorder'] = $orderindex;
139 $answers[$ident][
'action'] = $setvar->getAction();
140 $answers[$ident][
'points'] = $setvar->getContent();
143 if (!is_array($respcondition->displayfeedback)) {
147 foreach ($respcondition->displayfeedback as $feedbackpointer) {
148 if ($feedbackpointer->getLinkrefid() ===
'') {
152 foreach ($item->itemfeedback as $ifb) {
153 if ($ifb->getIdent() ===
'response_allcorrect') {
155 foreach ($ifb->material as $material) {
156 $feedbacksgeneric[1] = $material;
158 foreach ($ifb->flow_mat as $fmat) {
159 foreach ($fmat->material as $material) {
160 $feedbacksgeneric[1] = $material;
166 if ($ifb->getIdent() ===
'response_onenotcorrect') {
168 foreach ($ifb->material as $material) {
169 $feedbacksgeneric[0] = $material;
171 foreach ($ifb->flow_mat as $fmat) {
172 foreach ($fmat->material as $material) {
173 $feedbacksgeneric[0] = $material;
185 $this->
object->setTitle($item->
getTitle());
187 $this->
object->setComment($item->
getComment());
188 $this->
object->setAuthor($item->
getAuthor());
189 $this->
object->setOwner($user_id);
191 $this->
object->setOrderingType($type);
192 $this->
object->setObjId($questionpool_id);
193 $this->
object->setThumbSize(
199 $this->
object->setShuffle($shuffle);
200 $this->
object->setPoints(0);
201 $this->
object->saveQuestionDataToDb();
205 foreach ($answers as $answer) {
206 if (isset($answer[
'solutionorder'])) {
207 $solanswers[$answer[
'solutionorder']] = $answer;
212 $element_list = $this->
object->getOrderingElementList();
213 foreach ($solanswers as $answer) {
214 $points += $answer[
'points'];
218 if ($element->isExportIdent($answer[
'ident'])) {
219 $element->setExportIdent($answer[
'ident']);
221 $element = $element->withPosition($position++);
222 if (isset($answer[
'answerdepth'])) {
223 $element = $element->withIndentation((
int) $answer[
'answerdepth']);
227 if ($this->
object->isImageOrderingType()) {
228 $filename = $this->handleUploadedfile($answer);
230 $element = $element->withContent(
$filename);
233 $element = $element->withContent($answer[
'answertext']);
236 $element_list->addElement($element);
238 $this->
object->setOrderingElementList($element_list);
240 $this->
object->setPoints($points);
242 $this->
object->setAdditionalContentEditingMode(
245 $this->
object->saveToDb();
247 foreach ($feedbacksgeneric as $correctness => $material) {
249 $feedbacksgeneric[$correctness] = $m;
251 $questiontext = $this->
object->getQuestion();
256 $importfile = $importdirectory . DIRECTORY_SEPARATOR . $mob[
'uri'];
259 $DIC[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
263 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
264 foreach ($this->
object->getOrderingElementList() as $element) {
265 $element->setContent(str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $element->getContent()));
267 foreach ($feedbacksgeneric as $correctness => $material) {
268 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
270 foreach ($itemfeedbacks as $ident => $material) {
271 $itemfeedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
276 foreach ($this->
object->getOrderingElementList() as $element) {
279 foreach ($feedbacksgeneric as $correctness => $material) {
280 $this->
object->feedbackOBJ->importGenericFeedback(
286 foreach ($itemfeedbacks as $ident => $material) {
289 $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
296 $this->
object->saveToDb();
303 return $import_mapping;
308 $image = base64_decode($answer[
"answerimage"][
"content"] ??
'');
309 $image_file_name = $answer[
'answerimage'][
'label'] ??
'';
312 $file_handle = fopen($tmp_path,
"wb");
313 if ($file_handle ===
false) {
316 fwrite($file_handle, $image);
317 fclose($file_handle);
319 $filename_path_parts = explode(
".", $image_file_name);
320 $suffix = strtolower(array_pop($filename_path_parts));
326 $target_filename = $this->
object->buildHashedImageFilename($image_file_name,
true);
327 $target_filepath = $this->
object->getImagePath() . $target_filename;
328 if (rename($tmp_path, $target_filepath)) {
329 $thumb_path = $this->
object->getImagePath() . $this->
object->getThumbPrefix() . $target_filename;
331 return $target_filename;
339 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)
QTIMaterialToString(ilQTIMaterial $a_material)
Reads an QTI material tag and creates a text or XHTML string.
const VALID_UPLOAD_SUFFIXES
fromXML(string $importdirectory, int $user_id, ilQTIItem $item, int $questionpool_id, ?int $tst_id, ?ilObject &$tst_object, int &$question_counter, array $import_mapping)
addQuestionToParentObjectAndBuildMappingEntry(int $questionpool_id, ?int $tst_id, int &$question_counter, ?ilObjTest &$tst_object)
getMetadataEntry(string $a_label)
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
handleUploadedFile(array $answer)
static convertImage(string $a_from, string $a_to, string $a_target_format="", string $a_geometry="", string $a_background_color="")
importSuggestedSolutions(int $question_id, array $solution_from_import)
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
Class for question imports.
static clear(string $a_var)
fetchIndexFromFeedbackIdent($feedbackIdent, $prefix='response_')