35 string $importdirectory,
41 int &$question_counter,
50 foreach ($presentation->order as $entry) {
51 if ($entry[
'type'] !==
'response') {
55 $response = $presentation->response[$entry[
'index']];
57 if (strtolower(get_class(
$response->getRenderType())) !==
'ilqtirenderchoice') {
61 $shuffle = $rendertype->getShuffle();
63 foreach ($rendertype->response_labels as $response_label) {
64 $ident = $response_label->getIdent();
67 foreach ($response_label->material as $mat) {
69 for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
70 $foundmat = $mat->getMaterial($m);
71 if ($foundmat[
'type'] ===
'matimage'
72 && $foundmat[
'material']->getEmbedded() !==
'') {
81 for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
82 $foundmat = $mat->getMaterial($m);
83 if ($foundmat[
'type'] ===
'mattext') {
84 $answertext .= $foundmat[
'material']->getContent();
86 if ($foundmat[
'type'] ===
'matimage') {
89 'imagetype' => $foundmat[
'material']->getImageType(),
90 'label' => $foundmat[
'material']->getLabel(),
91 'content' => $foundmat[
'material']->getContent()
98 'answertext' => $answertext,
99 'imagefile' => $answerimage,
100 'answerorder' => $ident
106 $feedbacksgeneric = [];
108 foreach ($item->resprocessing as $resprocessing) {
109 foreach ($resprocessing->outcomes->decvar as $decvar) {
110 if ($decvar->getVarname() ==
'SCORE') {
111 $this->
object->setPoints($decvar->getMaxvalue());
112 $this->
object->setScorePartialSolutionEnabled(
false);
113 if ($decvar->getMinvalue() > 0) {
114 $this->
object->setScorePartialSolutionEnabled(
true);
119 foreach ($resprocessing->respcondition as $respcondition) {
120 if ($respcondition->setvar === []) {
121 foreach ($respcondition->getConditionvar()->varequal as $varequal) {
122 $ident = $varequal->respident;
123 $answers[$ident][
'correctness'] = (bool) $varequal->getContent();
127 foreach ($respcondition->displayfeedback as $feedbackpointer) {
128 if ($feedbackpointer->getLinkrefid() ===
'') {
131 foreach ($item->itemfeedback as $ifb) {
132 if ($ifb->getIdent() !== $feedbackpointer->getLinkrefid()) {
136 foreach ($ifb->material as $material) {
137 $feedbacks[$ident] = $material;
139 foreach ($ifb->flow_mat as $fmat) {
140 foreach ($fmat->material as $material) {
141 $feedbacks[$ident] = $material;
150 foreach ($respcondition->displayfeedback as $feedbackpointer) {
151 if ($feedbackpointer->getLinkrefid() ===
'') {
155 foreach ($item->itemfeedback as $ifb) {
156 if ($ifb->getIdent() ===
'response_allcorrect') {
157 foreach ($ifb->material as $material) {
158 $feedbacksgeneric[1] = $material;
160 foreach ($ifb->flow_mat as $fmat) {
161 foreach ($fmat->material as $material) {
162 $feedbacksgeneric[1] = $material;
168 if ($ifb->getIdent() ===
'response_onenotcorrect') {
170 foreach ($ifb->material as $material) {
171 $feedbacksgeneric[0] = $material;
173 foreach ($ifb->flow_mat as $fmat) {
174 foreach ($fmat->material as $material) {
175 $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->setObjId($questionpool_id);
192 $this->
object->setShuffleAnswersEnabled($shuffle);
194 $this->
object->setOptionLabel($item->
getMetadataEntry(
'option_label_setting'));
195 $this->
object->setCustomTrueOptionLabel($item->
getMetadataEntry(
'custom_true_option_label'));
196 $this->
object->setCustomFalseOptionLabel($item->
getMetadataEntry(
'custom_false_option_label'));
197 $this->
object->setThumbSize(
201 $this->
object->saveToDb();
203 $answer_objects = [];
204 foreach ($answers as $answer_data) {
206 $answer->setImageFsDir($this->
object->getImagePath());
207 $answer->setImageWebDir($this->
object->getImagePathWeb());
208 $answer->setPosition($answer_data[
'answerorder']);
209 $answer->setAnswertext($answer_data[
'answertext']);
210 $answer->setCorrectness($answer_data[
'correctness']);
211 if (isset($answer_data[
'imagefile'][
'label'])) {
212 $answer->setImageFile($answer_data[
'imagefile'][
'label']);
214 $answer_objects[] = $answer;
216 $this->
object->setAnswers($answer_objects);
218 $this->
object->setAdditionalContentEditingMode(
222 $this->
object->saveToDb();
224 foreach ($answers as $answer) {
225 if (!is_array($answer[
'imagefile']) || $answer[
'imagefile'] === []) {
228 $image = base64_decode($answer[
'imagefile'][
'content']);
229 $imagepath = $this->
object->getImagePath();
230 if (!file_exists($imagepath)) {
233 $imagepath .= $answer[
'imagefile'][
'label'];
234 if ($fh = fopen($imagepath,
'wb')) {
235 $imagefile = fwrite($fh, $image);
237 $this->
object->generateThumbForFile(
238 $answer[
'imagefile'][
'label'],
239 $this->
object->getImagePath(),
240 $this->object->getThumbSize()
246 if (!is_null($feedback_setting)) {
247 $this->
object->feedbackOBJ->saveSpecificFeedbackSetting($this->
object->getId(), $feedback_setting);
248 $this->
object->setSpecificFeedbackSetting($feedback_setting);
252 foreach ($feedbacks as $ident => $material) {
254 $feedbacks[$ident] = $m;
256 foreach ($feedbacksgeneric as $correctness => $material) {
258 $feedbacksgeneric[$correctness] = $m;
260 $questiontext = $this->
object->getQuestion();
261 $answers = $this->
object->getAnswers();
264 $importfile = $importdirectory . DIRECTORY_SEPARATOR . $mob[
"uri"];
267 $DIC[
'ilLog']->info(
'import mob from dir: ' . $importfile);
271 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
272 foreach ($answers as $answer_obj) {
273 if ($answer_obj->getAnswertext() ===
null) {
276 $answer_obj->setAnswertext(str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $answer_obj->getAnswertext()));
278 foreach ($feedbacks as $ident => $material) {
279 $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
281 foreach ($feedbacksgeneric as $correctness => $material) {
282 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
287 foreach ($answers as $answer_obj) {
288 if ($answer_obj->getAnswertext() ===
null) {
293 foreach ($feedbacks as $ident => $material) {
294 $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
301 foreach ($feedbacksgeneric as $correctness => $material) {
302 $this->
object->feedbackOBJ->importGenericFeedback(
308 $this->
object->saveToDb();
316 return $import_mapping;
fromXML(string $importdirectory, int $user_id, ilQTIItem $item, int $questionpool_id, ?int $tst_id, ?ilObject &$tst_object, int &$question_counter, array $import_mapping)
Class for question imports.
fetchAdditionalContentEditingModeInformation($qtiItem)
fetches the "additional content editing mode" information from qti item and falls back to ADDITIONAL_...
addQuestionToParentObjectAndBuildMappingEntry(int $questionpool_id, ?int $tst_id, int &$question_counter, ?ilObjTest &$tst_object)
QTIMaterialToString(ilQTIMaterial $a_material)
Reads an QTI material tag and creates a text or XHTML string.
addGeneralMetadata(ilQTIItem $item)
deduceThumbSizeFromImportValue(?int $size)
importSuggestedSolutions(int $question_id, array $solution_from_import)
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
Class ilObject Basic functions for all objects.
getMetadataEntry(string $a_label)
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)