34 $ilUser = $DIC[
'ilUser'];
41 $presentation = $item->getPresentation();
42 foreach ($presentation->order as $entry) {
43 switch ($entry[
"type"]) {
45 $response = $presentation->response[$entry[
"index"]];
47 switch (strtolower(get_class(
$response->getRenderType()))) {
48 case "ilqtirenderchoice":
49 $shuffle = $rendertype->getShuffle();
52 foreach ($rendertype->response_labels as $response_label) {
53 $ident = $response_label->getIdent();
55 $answerimage = array();
56 foreach ($response_label->material as $mat) {
58 for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
59 $foundmat = $mat->getMaterial($m);
60 if (strcmp($foundmat[
"type"],
"mattext") == 0) {
62 if (strcmp($foundmat[
"type"],
"matimage") == 0) {
63 if (strlen($foundmat[
"material"]->getEmbedded())) {
69 for ($m = 0; $m < $mat->getMaterialCount(); $m++) {
70 $foundmat = $mat->getMaterial($m);
71 if (strcmp($foundmat[
"type"],
"mattext") == 0) {
72 $answertext .= $foundmat[
"material"]->getContent();
74 if (strcmp($foundmat[
"type"],
"matimage") == 0) {
77 "imagetype" => $foundmat[
"material"]->getImageType(),
78 "label" => $foundmat[
"material"]->getLabel(),
79 "content" => $foundmat[
"material"]->
getContent()
88 $answers[$ident] = array(
89 "answertext" => $answertext,
90 "imagefile" => $answerimage,
91 "answerorder" => $ident
100 $feedbacks = array();
101 $feedbacksgeneric = array();
103 foreach ($item->resprocessing as $resprocessing) {
104 foreach ($resprocessing->outcomes->decvar as $decvar) {
105 if ($decvar->getVarname() ==
'SCORE') {
106 $this->
object->setPoints($decvar->getMaxvalue());
108 if ($decvar->getMinvalue() > 0) {
109 $this->
object->setScorePartialSolutionEnabled(
true);
111 $this->
object->setScorePartialSolutionEnabled(
false);
116 foreach ($resprocessing->respcondition as $respcondition) {
117 if (!count($respcondition->setvar)) {
118 foreach ($respcondition->getConditionvar()->varequal as $varequal) {
119 $ident = $varequal->respident;
120 $answers[$ident][
'correctness'] = (bool) $varequal->getContent();
125 foreach ($respcondition->displayfeedback as $feedbackpointer) {
126 if (strlen($feedbackpointer->getLinkrefid())) {
127 foreach ($item->itemfeedback as $ifb) {
128 if (strcmp($ifb->getIdent(), $feedbackpointer->getLinkrefid()) == 0) {
130 if (count($ifb->material)) {
131 foreach ($ifb->material as $material) {
132 $feedbacks[$ident] = $material;
135 if ((count($ifb->flow_mat) > 0)) {
136 foreach ($ifb->flow_mat as $fmat) {
137 if (count($fmat->material)) {
138 foreach ($fmat->material as $material) {
139 $feedbacks[$ident] = $material;
149 foreach ($respcondition->displayfeedback as $feedbackpointer) {
150 if (strlen($feedbackpointer->getLinkrefid())) {
151 foreach ($item->itemfeedback as $ifb) {
152 if ($ifb->getIdent() ==
"response_allcorrect") {
154 if (count($ifb->material)) {
155 foreach ($ifb->material as $material) {
156 $feedbacksgeneric[1] = $material;
159 if ((count($ifb->flow_mat) > 0)) {
160 foreach ($ifb->flow_mat as $fmat) {
161 if (count($fmat->material)) {
162 foreach ($fmat->material as $material) {
163 $feedbacksgeneric[1] = $material;
168 } elseif ($ifb->getIdent() ==
"response_onenotcorrect") {
170 if (count($ifb->material)) {
171 foreach ($ifb->material as $material) {
172 $feedbacksgeneric[0] = $material;
175 if ((count($ifb->flow_mat) > 0)) {
176 foreach ($ifb->flow_mat as $fmat) {
177 if (count($fmat->material)) {
178 foreach ($fmat->material as $material) {
179 $feedbacksgeneric[0] = $material;
193 $this->
object->setTitle($item->getTitle());
194 $this->
object->setNrOfTries((
int) $item->getMaxattempts());
195 $this->
object->setComment($item->getComment());
196 $this->
object->setAuthor($item->getAuthor());
197 $this->
object->setOwner($ilUser->getId());
199 $this->
object->setObjId($questionpool_id);
200 $this->
object->setShuffleAnswersEnabled($shuffle);
201 $this->
object->setAnswerType($item->getMetadataEntry(
'answer_type'));
202 $this->
object->setOptionLabel($item->getMetadataEntry(
'option_label_setting'));
203 $this->
object->setCustomTrueOptionLabel($item->getMetadataEntry(
'custom_true_option_label'));
204 $this->
object->setCustomFalseOptionLabel($item->getMetadataEntry(
'custom_false_option_label'));
205 $this->
object->setThumbSize(
209 $this->
object->saveToDb();
211 foreach ($answers as $answerData) {
213 $answer->setImageFsDir($this->
object->getImagePath());
214 $answer->setImageWebDir($this->
object->getImagePathWeb());
216 $answer->setPosition($answerData[
'answerorder']);
217 $answer->setAnswertext($answerData[
'answertext']);
218 $answer->setCorrectness($answerData[
'correctness']);
220 if (isset($answerData[
'imagefile'][
'label'])) {
221 $answer->setImageFile($answerData[
'imagefile'][
'label']);
224 $this->
object->addAnswer($answer);
227 $this->
object->setAdditionalContentEditingMode(
231 $this->
object->saveToDb();
233 foreach ($answers as $answer) {
234 if (is_array($answer[
"imagefile"]) && (count($answer[
"imagefile"]) > 0)) {
235 $image = base64_decode($answer[
"imagefile"][
"content"]);
236 $imagepath = $this->
object->getImagePath();
237 if (!file_exists($imagepath)) {
240 $imagepath .= $answer[
"imagefile"][
"label"];
241 if ($fh = fopen($imagepath,
"wb")) {
242 $imagefile = fwrite($fh, $image);
244 $this->
object->generateThumbForFile(
245 $answer[
"imagefile"][
"label"],
246 $this->
object->getImagePath(),
247 $this->
object->getThumbSize()
253 $feedbackSetting = $item->getMetadataEntry(
'feedback_setting');
254 if (!is_null($feedbackSetting)) {
255 $this->
object->feedbackOBJ->saveSpecificFeedbackSetting($this->
object->getId(), $feedbackSetting);
256 $this->
object->setSpecificFeedbackSetting($feedbackSetting);
260 foreach ($feedbacks as $ident => $material) {
262 $feedbacks[$ident] = $m;
264 foreach ($feedbacksgeneric as $correctness => $material) {
266 $feedbacksgeneric[$correctness] = $m;
268 $questiontext = $this->
object->getQuestion();
269 $answers = $this->
object->getAnswers();
279 $DIC[
'ilLog']->write(__METHOD__ .
': import mob from dir: ' . $importfile);
283 $questiontext = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $questiontext);
284 foreach ($answers as
$key => $value) {
285 $answer_obj = &$answers[
$key];
286 $answer_obj->setAnswertext(str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $answer_obj->getAnswertext()));
288 foreach ($feedbacks as $ident => $material) {
289 $feedbacks[$ident] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
291 foreach ($feedbacksgeneric as $correctness => $material) {
292 $feedbacksgeneric[$correctness] = str_replace(
"src=\"" . $mob[
"mob"] .
"\"",
"src=\"" .
"il_" .
IL_INST_ID .
"_mob_" . $media_object->getId() .
"\"", $material);
297 foreach ($answers as
$key => $value) {
298 $answer_obj = &$answers[
$key];
301 foreach ($feedbacks as $ident => $material) {
302 $this->
object->feedbackOBJ->importSpecificAnswerFeedback(
309 foreach ($feedbacksgeneric as $correctness => $material) {
310 $this->
object->feedbackOBJ->importGenericFeedback(
316 $this->
object->saveToDb();
319 $q_1_id = $this->
object->getId();
320 $question_id = $this->
object->duplicate(
true,
"",
"", -1, $tst_id);
321 $tst_object->questions[$question_counter++] = $question_id;
322 $import_mapping[$item->getIdent()] = array(
"pool" => $q_1_id,
"test" => $question_id);
324 $import_mapping[$item->getIdent()] = array(
"pool" => $this->
object->getId(),
"test" => 0);
326 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.
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.
importSuggestedSolutions(int $question_id, array $solution_from_import)
getTstImportArchivDirectory()
returns the full path to extracted tst import archiv (tst import dir + tst archiv subdir) ...
static clear(string $a_var)