From e2768be0a436c264488e26851e2513322a2384c9 Mon Sep 17 00:00:00 2001 From: Matheus Zych Date: Thu, 11 Dec 2025 08:49:26 +0100 Subject: [PATCH] Allows answertext of cloze question to only be a string instead of also null --- .../Test/src/Setup/Test11DBUpdateSteps.php | 10 +++ .../classes/class.assClozeTest.php | 76 +++++++++---------- 2 files changed, 48 insertions(+), 38 deletions(-) diff --git a/components/ILIAS/Test/src/Setup/Test11DBUpdateSteps.php b/components/ILIAS/Test/src/Setup/Test11DBUpdateSteps.php index d0c0552d5feb..3dc82c72fe75 100644 --- a/components/ILIAS/Test/src/Setup/Test11DBUpdateSteps.php +++ b/components/ILIAS/Test/src/Setup/Test11DBUpdateSteps.php @@ -155,4 +155,14 @@ public function step_3(): void $this->db->modifyTableColumn('tst_test_settings', $column, ['length' => 8]); } } + + public function step_4(): void + { + $table = 'qpl_a_cloze'; + $column = 'answertext'; + if ($this->db->tableExists($table) && $this->db->tableColumnExists($table, $column)) { + $this->db->manipulate("UPDATE {$table} SET {$column} = '' WHERE {$column} IS NULL"); + $this->db->modifyTableColumn($table, $column, ['default' => '', 'notnull' => true]); + } + } } diff --git a/components/ILIAS/TestQuestionPool/classes/class.assClozeTest.php b/components/ILIAS/TestQuestionPool/classes/class.assClozeTest.php index 4e74cfa497a3..fa6520069c81 100755 --- a/components/ILIAS/TestQuestionPool/classes/class.assClozeTest.php +++ b/components/ILIAS/TestQuestionPool/classes/class.assClozeTest.php @@ -311,24 +311,24 @@ protected function saveClozeTextGapRecordToDb( $this->db->manipulateF( 'INSERT INTO qpl_a_cloze (answer_id, question_fi, gap_id, answertext, points, aorder, cloze_type, gap_size) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)', [ - 'integer', - 'integer', - 'integer', - 'text', - 'float', - 'integer', - 'text', - 'integer' + ilDBConstants::T_INTEGER, + ilDBConstants::T_INTEGER, + ilDBConstants::T_INTEGER, + ilDBConstants::T_TEXT, + ilDBConstants::T_FLOAT, + ilDBConstants::T_INTEGER, + ilDBConstants::T_TEXT, + ilDBConstants::T_INTEGER ], [ $next_id, $this->getId(), $key, - strlen($item->getAnswertext()) ? $item->getAnswertext() : '', + $item->getAnswertext(), $item->getPoints(), $item->getOrder(), $gap->getType(), - (int) $gap->getGapSize() + $gap->getGapSize() ] ); } @@ -342,24 +342,24 @@ protected function saveClozeSelectGapRecordToDb( $this->db->manipulateF( 'INSERT INTO qpl_a_cloze (answer_id, question_fi, gap_id, answertext, points, aorder, cloze_type, shuffle) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)', [ - 'integer', - 'integer', - 'integer', - 'text', - 'float', - 'integer', - 'text', - 'text' + ilDBConstants::T_INTEGER, + ilDBConstants::T_INTEGER, + ilDBConstants::T_INTEGER, + ilDBConstants::T_TEXT, + ilDBConstants::T_FLOAT, + ilDBConstants::T_INTEGER, + ilDBConstants::T_TEXT, + ilDBConstants::T_TEXT ], [ $next_id, $this->getId(), $key, - strlen($item->getAnswertext()) ? $item->getAnswertext() : '', + $item->getAnswertext(), $item->getPoints(), $item->getOrder(), $gap->getType(), - ($gap->getShuffle()) ? '1' : '0' + $gap->getShuffle() ? '1' : '0' ] ); } @@ -375,32 +375,32 @@ protected function saveClozeNumericGapRecordToDb( $this->db->manipulateF( 'INSERT INTO qpl_a_cloze (answer_id, question_fi, gap_id, answertext, points, aorder, cloze_type, lowerlimit, upperlimit, gap_size) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)', [ - 'integer', - 'integer', - 'integer', - 'text', - 'float', - 'integer', - 'text', - 'text', - 'text', - 'integer' + ilDBConstants::T_INTEGER, + ilDBConstants::T_INTEGER, + ilDBConstants::T_INTEGER, + ilDBConstants::T_TEXT, + ilDBConstants::T_FLOAT, + ilDBConstants::T_INTEGER, + ilDBConstants::T_TEXT, + ilDBConstants::T_TEXT, + ilDBConstants::T_TEXT, + ilDBConstants::T_INTEGER ], [ $next_id, $this->getId(), $key, - strlen($item->getAnswertext()) ? $item->getAnswertext() : '', + $item->getAnswertext(), $item->getPoints(), $item->getOrder(), $gap->getType(), - ($eval->e($item->getLowerBound()) !== false && strlen( - $item->getLowerBound() - ) > 0) ? $item->getLowerBound() : $item->getAnswertext(), - ($eval->e($item->getUpperBound()) !== false && strlen( - $item->getUpperBound() - ) > 0) ? $item->getUpperBound() : $item->getAnswertext(), - (int) $gap->getGapSize() + ($eval->e($item->getLowerBound()) !== false && ($item->getLowerBound() ?? '') !== '') + ? $item->getLowerBound() + : $item->getAnswertext(), + ($eval->e($item->getUpperBound()) !== false && ($item->getUpperBound() ?? '') !== '') + ? $item->getUpperBound() + : $item->getAnswertext(), + $gap->getGapSize() ] ); }