33 string $importdirectory,
39 int &$question_counter,
48 foreach ($presentation->order as $entry) {
49 if ($entry[
'type'] !==
'response') {
53 $response = $presentation->response[$entry[
'index']];
55 if (strtolower(get_class(
$response->getRenderType())) !==
'ilqtirenderchoice') {
59 $shuffle = $rendertype->getShuffle();
61 foreach ($rendertype->response_labels as $response_label) {
62 $ident = $response_label->getIdent();
65 foreach ($response_label->material as $mat) {
67 for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
68 $foundmat = $mat->getMaterial($m);
69 if ($foundmat[
'type'] ===
'matimage' 70 && $foundmat[
'material']->getEmbedded() !==
'') {
79 for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
80 $foundmat = $mat->getMaterial($m);
81 if ($foundmat[
'type'] ===
'mattext') {
82 $answertext .= $foundmat[
'material']->getContent();
84 if ($foundmat[
'type'] ===
'matimage') {
87 'imagetype' => $foundmat[
'material']->getImageType(),
88 'label' => $foundmat[
'material']->getLabel(),
89 'content' => $foundmat[
'material']->getContent()
96 'answertext' => $answertext,
97 'imagefile' => $answerimage,
98 'answerorder' => $ident
104 $feedbacksgeneric = [];
106 foreach ($item->resprocessing as $resprocessing) {
107 foreach ($resprocessing->outcomes->decvar as $decvar) {
108 if ($decvar->getVarname() ==
'SCORE') {
109 $this->
object->setPoints($decvar->getMaxvalue());
110 $this->
object->setScorePartialSolutionEnabled(
false);
111 if ($decvar->getMinvalue() > 0) {
112 $this->
object->setScorePartialSolutionEnabled(
true);
117 foreach ($resprocessing->respcondition as $respcondition) {
118 if ($respcondition->setvar === []) {
119 foreach ($respcondition->getConditionvar()->varequal as $varequal) {
120 $ident = $varequal->respident;
121 $answers[$ident][
'correctness'] = (bool) $varequal->getContent();
125 foreach ($respcondition->displayfeedback as $feedbackpointer) {
126 if ($feedbackpointer->getLinkrefid() ===
'') {
129 foreach ($item->itemfeedback as $ifb) {
130 if ($ifb->getIdent() !== $feedbackpointer->getLinkrefid()) {
134 foreach ($ifb->material as $material) {
135 $feedbacks[$ident] = $material;
137 foreach ($ifb->flow_mat as $fmat) {
138 foreach ($fmat->material as $material) {
139 $feedbacks[$ident] = $material;
148 foreach ($respcondition->displayfeedback as $feedbackpointer) {
149 if ($feedbackpointer->getLinkrefid() ===
'') {
153 foreach ($item->itemfeedback as $ifb) {
154 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;
183 $this->
object->setTitle($item->
getTitle());
185 $this->
object->setComment($item->
getComment());
186 $this->
object->setAuthor($item->
getAuthor());
187 $this->
object->setOwner($user_id);
189 $this->
object->setObjId($questionpool_id);
190 $this->
object->setShuffleAnswersEnabled($shuffle);
192 $this->
object->setOptionLabel($item->
getMetadataEntry(
'option_label_setting'));
193 $this->
object->setCustomTrueOptionLabel($item->
getMetadataEntry(
'custom_true_option_label'));
194 $this->
object->setCustomFalseOptionLabel($item->
getMetadataEntry(
'custom_false_option_label'));
195 $this->
object->setThumbSize(
199 $this->
object->saveToDb();
201 $answer_objects = [];
202 foreach ($answers as $answer_data) {
204 $answer->setImageFsDir($this->
object->getImagePath());
205 $answer->setImageWebDir($this->
object->getImagePathWeb());
206 $answer->setPosition($answer_data[
'answerorder']);
207 $answer->setAnswertext($answer_data[
'answertext']);
208 $answer->setCorrectness($answer_data[
'correctness']);
209 if (isset($answer_data[
'imagefile'][
'label'])) {
210 $answer->setImageFile($answer_data[
'imagefile'][
'label']);
212 $answer_objects[] = $answer;
214 $this->
object->setAnswers($answer_objects);
216 $this->
object->setAdditionalContentEditingMode(
220 $this->
object->saveToDb();
222 foreach ($answers as $answer) {
223 if (!is_array($answer[
'imagefile']) || $answer[
'imagefile'] === []) {
226 $image = base64_decode($answer[
'imagefile'][
'content']);
227 $imagepath = $this->
object->getImagePath();
228 if (!file_exists($imagepath)) {
231 $imagepath .= $answer[
'imagefile'][
'label'];
232 if ($fh = fopen($imagepath,
'wb')) {
233 $imagefile = fwrite($fh, $image);
235 $this->
object->generateThumbForFile(
236 $answer[
'imagefile'][
'label'],
237 $this->
object->getImagePath(),
238 $this->
object->getThumbSize()
244 if (!is_null($feedback_setting)) {
245 $this->
object->feedbackOBJ->saveSpecificFeedbackSetting($this->
object->getId(), $feedback_setting);
246 $this->
object->setSpecificFeedbackSetting($feedback_setting);
250 foreach ($feedbacks as $ident => $material) {
252 $feedbacks[$ident] = $m;
254 foreach ($feedbacksgeneric as $correctness => $material) {
256 $feedbacksgeneric[$correctness] = $m;
258 $questiontext = $this->
object->getQuestion();
259 $answers = $this->
object->getAnswers();
262 $importfile = $importdirectory . DIRECTORY_SEPARATOR . $mob[
"uri"];
265 $DIC[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
269 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
270 foreach ($answers as $answer_obj) {
271 if ($answer_obj->getAnswertext() ===
null) {
274 $answer_obj->setAnswertext(str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $answer_obj->getAnswertext()));
276 foreach ($feedbacks as $ident => $material) {
277 $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
279 foreach ($feedbacksgeneric as $correctness => $material) {
280 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
285 foreach ($answers as $answer_obj) {
286 if ($answer_obj->getAnswertext() ===
null) {
291 foreach ($feedbacks as $ident => $material) {
292 $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
299 foreach ($feedbacksgeneric as $correctness => $material) {
300 $this->
object->feedbackOBJ->importGenericFeedback(
306 $this->
object->saveToDb();
314 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)
deduceThumbSizeFromImportValue(?int $size)
addGeneralMetadata(ilQTIItem $item)
QTIMaterialToString(ilQTIMaterial $a_material)
Reads an QTI material tag and creates a text or XHTML string.
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
importSuggestedSolutions(int $question_id, array $solution_from_import)
Class for question imports.
static clear(string $a_var)
fromXML(string $importdirectory, int $user_id, ilQTIItem $item, int $questionpool_id, ?int $tst_id, ?ilObject &$tst_object, int &$question_counter, array $import_mapping)