diff --git a/Modules/TestQuestionPool/classes/class.assMultipleChoice.php b/Modules/TestQuestionPool/classes/class.assMultipleChoice.php index d256c0868ad6..a81bb654e7c4 100755 --- a/Modules/TestQuestionPool/classes/class.assMultipleChoice.php +++ b/Modules/TestQuestionPool/classes/class.assMultipleChoice.php @@ -454,7 +454,7 @@ public function deleteAnswer($index = 0): void return; } $answer = $this->answers[$index]; - if (strlen($answer->getImage())) { + if ($answer->hasImage()) { $this->deleteImage($answer->getImage()); } unset($this->answers[$index]); @@ -890,8 +890,8 @@ public function duplicateImages($question_id, $objectId = null): void } foreach ($this->answers as $answer) { - $filename = $answer->getImage(); - if (strlen($filename)) { + if ($answer->hasImage()) { + $filename = $answer->getImage(); if (!file_exists($imagepath)) { ilFileUtils::makeDirParents($imagepath); } @@ -935,8 +935,8 @@ public function copyImages($question_id, $source_questionpool): void $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath); $imagepath_original = str_replace("/$this->obj_id/", "/$source_questionpool/", $imagepath_original); foreach ($this->answers as $answer) { - $filename = $answer->getImage(); - if (strlen($filename)) { + if ($answer->hasImage()) { + $filename = $answer->getImage(); if (!file_exists($imagepath)) { ilFileUtils::makeDirParents($imagepath); } @@ -968,8 +968,8 @@ protected function syncImages(): void ilFileUtils::delDir($imagepath_original); foreach ($this->answers as $answer) { - $filename = $answer->getImage(); - if (strlen($filename)) { + if ($answer->hasImage()) { + $filename = $answer->getImage(); if (@file_exists($imagepath . $filename)) { if (!file_exists($imagepath)) { ilFileUtils::makeDirParents($imagepath); diff --git a/Modules/TestQuestionPool/classes/class.assSingleChoice.php b/Modules/TestQuestionPool/classes/class.assSingleChoice.php index 6e926d4cf735..ebc50b7c024b 100755 --- a/Modules/TestQuestionPool/classes/class.assSingleChoice.php +++ b/Modules/TestQuestionPool/classes/class.assSingleChoice.php @@ -105,7 +105,7 @@ public function isComplete(): bool { if (strlen($this->title) and ($this->author) and ($this->question) and (count($this->answers)) and ($this->getMaximumPoints() > 0)) { foreach ($this->answers as $answer) { - if ((strlen($answer->getAnswertext()) == 0) && (strlen($answer->getImage()) == 0)) { + if ((strlen($answer->getAnswertext()) == 0) && !$answer->hasImage()) { return false; } } @@ -890,8 +890,8 @@ public function duplicateImages($question_id, $objectId = null): void } foreach ($this->answers as $answer) { - $filename = $answer->getImage(); - if (strlen($filename)) { + if ($answer->hasImage()) { + $filename = $answer->getImage(); if (!file_exists($imagepath)) { ilFileUtils::makeDirParents($imagepath); } @@ -919,8 +919,8 @@ public function copyImages($question_id, $source_questionpool): void $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath); $imagepath_original = str_replace("/$this->obj_id/", "/$source_questionpool/", $imagepath_original); foreach ($this->answers as $answer) { - $filename = $answer->getImage(); - if (strlen($filename)) { + if ($answer->hasImage()) { + $filename = $answer->getImage(); if (!file_exists($imagepath)) { ilFileUtils::makeDirParents($imagepath); } @@ -968,8 +968,8 @@ protected function syncImages(): void $imagepath_original = str_replace("/$this->id/images", "/$question_id/images", $imagepath); ilFileUtils::delDir($imagepath_original); foreach ($this->answers as $answer) { - $filename = $answer->getImage(); - if (strlen($filename)) { + if ($answer->hasImage()) { + $filename = $answer->getImage(); if (@file_exists($imagepath . $filename)) { if (!file_exists($imagepath)) { ilFileUtils::makeDirParents($imagepath); diff --git a/Modules/TestQuestionPool/classes/export/qti12/class.assMultipleChoiceExport.php b/Modules/TestQuestionPool/classes/export/qti12/class.assMultipleChoiceExport.php index e4354c85ff8d..172b2dc61d6b 100644 --- a/Modules/TestQuestionPool/classes/export/qti12/class.assMultipleChoiceExport.php +++ b/Modules/TestQuestionPool/classes/export/qti12/class.assMultipleChoiceExport.php @@ -1,4 +1,5 @@ <?php + /** * This file is part of ILIAS, a powerful learning management system * published by ILIAS open source e-Learning e.V. @@ -15,6 +16,7 @@ * *********************************************************************/ + /** * Class for multiple choice question exports * @@ -122,7 +124,7 @@ public function toXML($a_include_header = true, $a_include_binary = true, $a_shu ]; $a_xml_writer->xmlStartTag("response_label", $attrs); - if (strlen($answer->getImage())) { + if ($answer->hasImage()) { $this->addQTIMaterial($a_xml_writer, $answer->getAnswertext(), false, false); $imagetype = "image/jpeg"; if (preg_match("/.*\.(png|gif)$/", $answer->getImage(), $matches)) { diff --git a/Modules/TestQuestionPool/classes/export/qti12/class.assSingleChoiceExport.php b/Modules/TestQuestionPool/classes/export/qti12/class.assSingleChoiceExport.php index 22db5c392911..7c14d03d0f17 100644 --- a/Modules/TestQuestionPool/classes/export/qti12/class.assSingleChoiceExport.php +++ b/Modules/TestQuestionPool/classes/export/qti12/class.assSingleChoiceExport.php @@ -1,4 +1,5 @@ <?php + /** * This file is part of ILIAS, a powerful learning management system * published by ILIAS open source e-Learning e.V. @@ -15,6 +16,7 @@ * *********************************************************************/ + /** * Class for single choice question exports * @@ -126,7 +128,7 @@ public function toXML($a_include_header = true, $a_include_binary = true, $a_shu ]; $a_xml_writer->xmlStartTag("response_label", $attrs); - if (strlen($answer->getImage())) { + if ($answer->hasImage()) { $this->addQTIMaterial($a_xml_writer, $answer->getAnswertext(), false, false); $imagetype = "image/jpeg"; if (preg_match("/.*\.(png|gif)$/", $answer->getImage(), $matches)) { diff --git a/Modules/TestQuestionPool/classes/import/qti12/class.assMultipleChoiceImport.php b/Modules/TestQuestionPool/classes/import/qti12/class.assMultipleChoiceImport.php index acc85d6d2cf5..a80f5069d598 100644 --- a/Modules/TestQuestionPool/classes/import/qti12/class.assMultipleChoiceImport.php +++ b/Modules/TestQuestionPool/classes/import/qti12/class.assMultipleChoiceImport.php @@ -223,7 +223,13 @@ public function fromXML(&$item, $questionpool_id, &$tst_id, &$tst_object, &$ques if ($item->getMetadataEntry('singleline') || (is_array($answer["imagefile"]) && count($answer["imagefile"]) > 0)) { $this->object->setIsSingleline(true); } - $this->object->addAnswer($answer["answertext"], $answer["points"], $answer["points_unchecked"], $answer["answerorder"], $answer["imagefile"]["label"] ?? ''); + $this->object->addAnswer( + $answer["answertext"], + $answer["points"], + $answer["points_unchecked"], + $answer["answerorder"], + $answer["imagefile"]["label"] ?? null + ); } // additional content editing mode information $this->object->setAdditionalContentEditingMode(