From 6a7c8feb10e213e503ace8d7ebcee02f0990795b Mon Sep 17 00:00:00 2001 From: Adrian Greeve Date: Mon, 29 Jun 2015 14:39:11 +0800 Subject: [PATCH] MDL-48239 gradebook: Change to calculated grade item min and max. Regardless of the setting 'Min and max grades used in calculation' Calculated grade items will always update the min and max raw grade. --- .../grade_calculated_grade_items.feature | 10 +++---- grade/tests/behat/grade_minmax.feature | 24 +++++++-------- lib/grade/grade_item.php | 29 ++++++++++++++----- 3 files changed, 38 insertions(+), 25 deletions(-) diff --git a/grade/tests/behat/grade_calculated_grade_items.feature b/grade/tests/behat/grade_calculated_grade_items.feature index 1ba9d87cbfc..e295c02a2f1 100644 --- a/grade/tests/behat/grade_calculated_grade_items.feature +++ b/grade/tests/behat/grade_calculated_grade_items.feature @@ -105,8 +105,8 @@ Feature: Calculated grade items can be used in the gradebook And the following should exist in the "user-grade" table: | Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total | | grade item 1 | - | 75.00 | 0–100 | 75.00 % | - | - | Calc cat totalInclude empty grades. | 100.00 % | 37.50 | 0–50 | 75.00 % | - | - | Course total | - | 37.50 | 0–50 | 75.00 % | - | + | Calc cat totalInclude empty grades. | 100.00 % | 37.50 | 0–40 | 93.75 % | - | + | Course total | - | 37.50 | 0–40 | 93.75 % | - | And I select "Student 2" from the "Select all or one user" singleselect And the following should exist in the "user-grade" table: | Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total | @@ -153,9 +153,9 @@ Feature: Calculated grade items can be used in the gradebook And I select "Student 1" from the "Select all or one user" singleselect And the following should exist in the "user-grade" table: | Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total | - | grade item 1 | 66.67 % | 75.00 | 0–100 | 75.00 % | 50.00 % | - | calc item | 33.33 % | 37.50 | 0–50 | 75.00 % | 25.00 % | - | Course total | - | 112.50 | 0–150 | 75.00 % | - | + | grade item 1 | 71.43 % | 75.00 | 0–100 | 75.00 % | 53.57 % | + | calc item | 28.57 % | 37.50 | 0–40 | 93.75 % | 26.79 % | + | Course total | - | 112.50 | 0–140 | 80.36 % | - | And I select "Student 2" from the "Select all or one user" singleselect And the following should exist in the "user-grade" table: | Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total | diff --git a/grade/tests/behat/grade_minmax.feature b/grade/tests/behat/grade_minmax.feature index 2102bfdcf2b..055a3c1ae35 100644 --- a/grade/tests/behat/grade_minmax.feature +++ b/grade/tests/behat/grade_minmax.feature @@ -148,20 +148,20 @@ Feature: We can choose what min or max grade to use when aggregating grades. And I select "Student 1" from the "Select all or one user" singleselect Then the following should exist in the "user-grade" table: | Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total | - | MI 1 | 20.00 % | 75.00 | 0–100 | 75.00 % | 15.00 % | - | MI 2 | 20.00 % | 25.00 | 0–100 | 25.00 % | 5.00 % | - | MI 3 | 50.00 % | 50.00 | 0–100 | 50.00 % | 10.00 % | - | MI 4 | 50.00 % | 100.00 | 0–100 | 100.00 % | 20.00 % | - | MI 5 | 20.00 % | 150.00 | 0–100 | 100.00 % | 30.00 % | - | CAT1 total | 40.00 % | 150.00 | 0–200 | 75.00 % | - | - | Course total | - | 400.00 | 0–500 | 80.00 % | - | + | MI 1 | 16.67 % | 75.00 | 0–100 | 75.00 % | 12.50 % | + | MI 2 | 16.67 % | 25.00 | 0–100 | 25.00 % | 4.17 % | + | MI 3 | 50.00 % | 50.00 | 0–100 | 50.00 % | 8.33 % | + | MI 4 | 50.00 % | 100.00 | 0–100 | 100.00 % | 16.67 % | + | MI 5 | 33.33 % | 150.00 | 0–200 | 75.00 % | 25.00 % | + | CAT1 total | 33.33 % | 150.00 | 0–200 | 75.00 % | - | + | Course total | - | 400.00 | 0–600 | 66.67 % | - | And I select "Student 2" from the "Select all or one user" singleselect And the following should exist in the "user-grade" table: | Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total | - | MI 1 | 33.33 % | 20.00 | 0–100 | 20.00 % | 6.67 % | + | MI 1 | 25.00 % | 20.00 | 0–100 | 20.00 % | 5.00 % | | MI 2 | 0.00 % | - | 0–100 | - | 0.00 % | - | MI 3 | 100.00 % | 10.00 | 0–100 | 10.00 % | 3.33 % | + | MI 3 | 100.00 % | 10.00 | 0–100 | 10.00 % | 2.50 % | | MI 4 | 0.00 % | - | 0–100 | - | 0.00 % | - | MI 5 | 33.33 % | 30.00 | 0–100 | 30.00 % | 10.00 % | - | CAT1 total | 33.33 % | 10.00 | 0–100 | 10.00 % | - | - | Course total | - | 60.00 | 0–300 | 20.00 % | - | + | MI 5 | 50.00 % | 30.00 | 0–200 | 15.00 % | 7.50 % | + | CAT1 total | 25.00 % | 10.00 | 0–100 | 10.00 % | - | + | Course total | - | 60.00 | 0–400 | 15.00 % | - | diff --git a/lib/grade/grade_item.php b/lib/grade/grade_item.php index 47289b2d2d6..267e6ada450 100644 --- a/lib/grade/grade_item.php +++ b/lib/grade/grade_item.php @@ -2013,17 +2013,30 @@ class grade_item extends grade_object { // normalize $grade->finalgrade = $this->bounded_grade($result); } - } - // update in db if changed - if (grade_floats_different($grade->finalgrade, $oldfinalgrade)) { - $grade->timemodified = time(); - $success = $grade->update('compute'); + // Only run through this code if the gradebook isn't frozen. + if ($gradebookcalculationsfreeze && (int)$gradebookcalculationsfreeze <= 20150627) { + // Update in db if changed. + if (grade_floats_different($grade->finalgrade, $oldfinalgrade)) { + $grade->timemodified = time(); + $success = $grade->update('compute'); - // If successful trigger a user_graded event. - if ($success) { - \core\event\user_graded::create_from_grade($grade)->trigger(); + // If successful trigger a user_graded event. + if ($success) { + \core\event\user_graded::create_from_grade($grade)->trigger(); + } + } + } else { + // Update in db if changed. + if (grade_floats_different($grade->finalgrade, $oldfinalgrade) || $rawminandmaxchanged) { + $grade->timemodified = time(); + $success = $grade->update('compute'); + + // If successful trigger a user_graded event. + if ($success) { + \core\event\user_graded::create_from_grade($grade)->trigger(); + } } }