Skip to content

Commit

Permalink
TA: 39853, 39840, 39841 - check on null/bool instead of strlen for im…
Browse files Browse the repository at this point in the history
…ages
  • Loading branch information
nhaagen authored and kergomard committed Jan 11, 2024
1 parent 5eb8847 commit 9ba148e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
14 changes: 7 additions & 7 deletions Modules/TestQuestionPool/classes/class.assMultipleChoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions Modules/TestQuestionPool/classes/class.assSingleChoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -15,6 +16,7 @@
*
*********************************************************************/


/**
* Class for multiple choice question exports
*
Expand Down Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -15,6 +16,7 @@
*
*********************************************************************/


/**
* Class for single choice question exports
*
Expand Down Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 9ba148e

Please sign in to comment.