Skip to content

Commit

Permalink
Merge pull request #4611 from HochschuleLuzern/fix_divisible_by_formu…
Browse files Browse the repository at this point in the history
…la_question

Fix inconsistency in Value für Division of Int in Formula Question
  • Loading branch information
mbecker-databay authored Jul 5, 2022
2 parents 342e71b + 36b6aea commit b01af5c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lang/ilias_de.lang
Original file line number Diff line number Diff line change
Expand Up @@ -11688,7 +11688,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.
Expand Down
2 changes: 1 addition & 1 deletion lang/ilias_en.lang
Original file line number Diff line number Diff line change
Expand Up @@ -11737,7 +11737,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
Expand Down

0 comments on commit b01af5c

Please sign in to comment.