35 string $importdirectory,
41 int &$question_counter,
53 foreach ($presentation->order as $entry) {
54 switch ($entry[
'type']) {
56 $response = $presentation->response[$entry[
"index"]];
60 } elseif (
$response->getIdent() ===
'OQNP') {
62 } elseif (
$response->getIdent() ===
'OQNT') {
64 } elseif (
$response->getIdent() ===
'OQT') {
69 switch (get_class($rendertype)) {
70 case ilQTIRenderChoice::class:
71 $shuffle = $rendertype->getShuffle();
73 foreach ($rendertype->response_labels as $response_label) {
74 $ident = $response_label->getIdent();
78 foreach ($response_label->material as $mat) {
79 for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
80 $foundmat = $mat->getMaterial($m);
82 if ($foundmat[
'material']->
getLabel() ===
'answerdepth') {
83 $answerdepth = $foundmat[
'material']->getContent();
85 if ($foundmat[
'type'] ===
'mattext' 86 && $foundmat[
'material']->
getLabel() !==
'answerdepth') {
87 $answertext .= $foundmat[
'material']->getContent();
89 if ($foundmat[
'type'] ===
'matimage' 90 && $foundmat[
'material']->
getLabel() !==
'answerdepth') {
93 'imagetype' => $foundmat[
'material']->getImageType(),
94 'label' => $foundmat[
'material']->getLabel(),
95 'content' => $foundmat[
'material']->getContent()
100 $answers[$answerorder] = [
102 'answertext' => $answertext,
103 'answerimage' => $answerimage,
105 'answerorder' => $answerorder,
106 'answerdepth' => $answerdepth,
118 $feedbacksgeneric = [];
119 foreach ($item->resprocessing as $resprocessing) {
120 foreach ($resprocessing->respcondition as $respcondition) {
123 $conditionvar = $respcondition->getConditionvar();
124 foreach ($conditionvar->order as $order) {
125 switch ($order[
'field']) {
130 $ident = $conditionvar->varequal[$order[
'index']]->getContent();
131 $orderindex = $conditionvar->varequal[$order[
'index']]->getIndex();
135 foreach ($respcondition->setvar as $setvar) {
137 $answers[$ident][
'solutionorder'] = $orderindex;
138 $answers[$ident][
'action'] = $setvar->getAction();
139 $answers[$ident][
'points'] = $setvar->getContent();
142 if (!is_array($respcondition->displayfeedback)) {
146 foreach ($respcondition->displayfeedback as $feedbackpointer) {
147 if ($feedbackpointer->getLinkrefid() ===
'') {
151 foreach ($item->itemfeedback as $ifb) {
152 if ($ifb->getIdent() ===
'response_allcorrect') {
154 foreach ($ifb->material as $material) {
155 $feedbacksgeneric[1] = $material;
157 foreach ($ifb->flow_mat as $fmat) {
158 foreach ($fmat->material as $material) {
159 $feedbacksgeneric[1] = $material;
165 if ($ifb->getIdent() ===
'response_onenotcorrect') {
167 foreach ($ifb->material as $material) {
168 $feedbacksgeneric[0] = $material;
170 foreach ($ifb->flow_mat as $fmat) {
171 foreach ($fmat->material as $material) {
172 $feedbacksgeneric[0] = $material;
184 $this->
object->setTitle($item->
getTitle());
186 $this->
object->setComment($item->
getComment());
187 $this->
object->setAuthor($item->
getAuthor());
188 $this->
object->setOwner($user_id);
190 $this->
object->setOrderingType($type);
191 $this->
object->setObjId($questionpool_id);
192 $this->
object->setThumbSize(
198 $this->
object->setShuffle($shuffle);
199 $this->
object->setPoints(0);
200 $this->
object->saveQuestionDataToDb();
204 foreach ($answers as $answer) {
205 if (isset($answer[
'solutionorder'])) {
206 $solanswers[$answer[
'solutionorder']] = $answer;
211 $element_list = $this->
object->getOrderingElementList();
212 foreach ($solanswers as $answer) {
213 $points += $answer[
'points'];
217 if ($element->isExportIdent($answer[
'ident'])) {
218 $element->setExportIdent($answer[
'ident']);
220 $element = $element->withPosition($position++);
221 if (isset($answer[
'answerdepth'])) {
222 $element = $element->withIndentation((
int) $answer[
'answerdepth']);
226 if ($this->
object->isImageOrderingType()) {
227 $filename = $this->handleUploadedfile($answer);
229 $element = $element->withContent(
$filename);
232 $element = $element->withContent($answer[
'answertext']);
235 $element_list->addElement($element);
237 $this->
object->setOrderingElementList($element_list);
239 $this->
object->setPoints($points);
241 $this->
object->setAdditionalContentEditingMode(
244 $this->
object->saveToDb();
246 foreach ($feedbacksgeneric as $correctness => $material) {
248 $feedbacksgeneric[$correctness] = $m;
250 $questiontext = $this->
object->getQuestion();
255 $importfile = $importdirectory . DIRECTORY_SEPARATOR . $mob[
'uri'];
258 $DIC[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
262 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
263 foreach ($this->
object->getOrderingElementList() as $element) {
264 $element->setContent(str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $element->getContent()));
266 foreach ($feedbacksgeneric as $correctness => $material) {
267 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
269 foreach ($itemfeedbacks as $ident => $material) {
270 $itemfeedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
275 foreach ($this->
object->getOrderingElementList() as $element) {
278 foreach ($feedbacksgeneric as $correctness => $material) {
279 $this->
object->feedbackOBJ->importGenericFeedback(
285 foreach ($itemfeedbacks as $ident => $material) {
288 $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
295 $this->
object->saveToDb();
296 if (isset($tst_id) && $tst_id !== $questionpool_id) {
297 $qplQid = $this->
object->getId();
298 $tstQid = $this->
object->duplicate(
true,
'',
'', -1, $tst_id);
299 $tst_object->questions[$question_counter++] = $tstQid;
300 $import_mapping[$item->
getIdent()] = [
"pool" => $qplQid,
"test" => $tstQid];
301 return $import_mapping;
305 $tst_object->questions[$question_counter++] = $this->
object->
getId();
306 $import_mapping[$item->
getIdent()] = [
"pool" => 0,
"test" => $this->
object->getId()];
307 return $import_mapping;
310 $import_mapping[$item->
getIdent()] = [
"pool" => $this->
object->getId(),
"test" => 0];
311 return $import_mapping;
316 $image = base64_decode($answer[
"answerimage"][
"content"] ??
'');
317 $image_file_name = $answer[
'answerimage'][
'label'] ??
'';
320 $file_handle = fopen($tmp_path,
"wb");
321 if ($file_handle ===
false) {
324 fwrite($file_handle, $image);
325 fclose($file_handle);
327 $filename_path_parts = explode(
".", $image_file_name);
328 $suffix = strtolower(array_pop($filename_path_parts));
334 $target_filename = $this->
object->buildHashedImageFilename($image_file_name,
true);
335 $target_filepath = $this->
object->getImagePath() . $target_filename;
336 if (rename($tmp_path, $target_filepath)) {
337 $thumb_path = $this->
object->getImagePath() . $this->
object->getThumbPrefix() . $target_filename;
339 return $target_filename;
347 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)
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_')