MDL-48239 gradebook: Change to calculated grade item min and max.
authorAdrian Greeve <adrian@moodle.com>
Mon, 29 Jun 2015 06:39:11 +0000 (14:39 +0800)
committerAdrian Greeve <adrian@moodle.com>
Thu, 2 Jul 2015 03:13:26 +0000 (11:13 +0800)
Regardless of the setting 'Min and max grades used in calculation'
Calculated grade items will always update the min and max raw grade.

grade/tests/behat/grade_calculated_grade_items.feature
grade/tests/behat/grade_minmax.feature
lib/grade/grade_item.php

index 1ba9d87..e295c02 100644 (file)
@@ -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 |
index 2102bfd..055a3c1 100644 (file)
@@ -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 %    | -                            |
index 47289b2..267e6ad 100644 (file)
@@ -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();
+                }
             }
         }