From 36b6aeadcd613bda4c123568def772203ca81abd Mon Sep 17 00:00:00 2001 From: Stephan Winiker Date: Mon, 30 May 2022 12:07:25 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20inconsistency=20in=20Value=20f=C3=BCr=20D?= =?UTF-8?q?ivision=20of=20Int?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../classes/class.assFormulaQuestionGUI.php | 6 +++++- .../class.assFormulaQuestionVariable.php | 17 ++++++++++++++++- lang/ilias_de.lang | 2 +- lang/ilias_en.lang | 2 +- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Modules/TestQuestionPool/classes/class.assFormulaQuestionGUI.php b/Modules/TestQuestionPool/classes/class.assFormulaQuestionGUI.php index b9c715b932de..2b99b537a2f4 100755 --- a/Modules/TestQuestionPool/classes/class.assFormulaQuestionGUI.php +++ b/Modules/TestQuestionPool/classes/class.assFormulaQuestionGUI.php @@ -650,7 +650,11 @@ public function editQuestion($checkonly = false) $intPrecision = $form->getItemByPostVar('intprecision_' . $variable->getVariable()); $decimal_spots = $form->getItemByPostVar('precision_' . $variable->getVariable()); if ($decimal_spots->getValue() == 0) { - if ($intPrecision->getValue() > $max_range->getValue()) { + if (!$variable->isIntPrecisionValid( + $intPrecision->getValue(), + $min_range->getValue(), + $max_range->getValue() + )) { $intPrecision->setAlert($this->lng->txt('err_division')); $custom_errors = true; } diff --git a/Modules/TestQuestionPool/classes/class.assFormulaQuestionVariable.php b/Modules/TestQuestionPool/classes/class.assFormulaQuestionVariable.php index b3bd2ac95138..1dbbc50a5a51 100755 --- a/Modules/TestQuestionPool/classes/class.assFormulaQuestionVariable.php +++ b/Modules/TestQuestionPool/classes/class.assFormulaQuestionVariable.php @@ -48,7 +48,11 @@ public function getRandomValue() // @todo check this if ($this->getPrecision() == 0) { - if ($this->getIntprecision() > $this->getRangeMax()) { + if (!$this->isIntPrecisionValid( + $this->getIntprecision(), + $this->getRangeMin(), + $this->getRangeMax() + )) { global $DIC; $lng = $DIC['lng']; ilUtil::sendFailure($lng->txt('err_divider_too_big')); @@ -90,6 +94,17 @@ public function setRandomValue() { $this->setValue($this->getRandomValue()); } + + public function isIntPrecisionValid($int_precision, $min_range, $max_range) + { + $min_abs = abs($min_range); + $max_abs = abs($max_range); + $bigger_abs = $max_abs > $min_abs ? $max_abs : $min_abs; + if ($int_precision > $bigger_abs) { + return false; + } + return true; + } /************************************ * Getter and Setter diff --git a/lang/ilias_de.lang b/lang/ilias_de.lang index ae5e36c1c629..ac5c55186853 100644 --- a/lang/ilias_de.lang +++ b/lang/ilias_de.lang @@ -11687,7 +11687,7 @@ assessment#:#tolerance#:#Toleranz (%) assessment#:#result_units#:#Auswählbare Einheiten assessment#:#precision#:#Präzision assessment#:#err_range#:#Die obere Grenze muss größer als die untere Grenze sein. -assessment#:#err_division#:#Dieser Wert muss kleiner als das Maximum sein. +assessment#:#err_division#:#Der von Ihnen gesetzte Wert macht es unmöglich einen gültigen Wert für die Variable zu generieren. assessment#:#err_divider_too_big#:#Der Teiler einer der Variablen in dieser Frage ist zu gross. assessment#:#err_no_formula#:#Bitte geben Sie eine Formel zur Berechnung des Ergebnisses an. assessment#:#err_wrong_rating_advanced#:#Bitte stellen Sie sicher, dass die Summe der erweiterten Bewertungsoptionen genau 100 Prozent ergibt. diff --git a/lang/ilias_en.lang b/lang/ilias_en.lang index 474555659d9f..b25a8c494eb8 100644 --- a/lang/ilias_en.lang +++ b/lang/ilias_en.lang @@ -11736,7 +11736,7 @@ assessment#:#tolerance#:#Tolerance (%) assessment#:#result_units#:#Available Units assessment#:#precision#:#Precision assessment#:#err_range#:#The maximum range must be greater than the minimum range -assessment#:#err_division#:#This value has to be smaller than the maximum range. +assessment#:#err_division#:#The value you chose would make it impossible to generate a valid value for the variable. assessment#:#err_divider_too_big#:#The divider of one of the variables in this question is too big. assessment#:#err_no_formula#:#You must enter a formula assessment#:#err_wrong_rating_advanced#:#Please make sure that the addition of the advanced rating settings equals to 100 percent