MDL-46997 Grades: fix sum of grades with hidden items with differing maxgrades
authorDamyon Wiese <damyon@moodle.com>
Tue, 9 Sep 2014 02:43:41 +0000 (10:43 +0800)
committerDamyon Wiese <damyon@moodle.com>
Tue, 9 Sep 2014 09:11:59 +0000 (17:11 +0800)
lib/grade/grade_category.php

index 91cce7a..b31c307 100644 (file)
@@ -763,15 +763,17 @@ class grade_category extends grade_object {
 
             case GRADE_AGGREGATE_SUM:    // Add up all the items.
                 $num = count($grade_values);
-                $sum = array_sum($grade_values);
-                $agg_grade = $sum / $num;
                 // Excluded items can affect the grademax for this grade_item.
                 $grademin = 0;
                 $grademax = 0;
+                $sum = 0;
                 foreach ($grade_values as $itemid => $grade_value) {
+                    $sum += $grade_value * ($items[$itemid]->grademax - $items[$itemid]->grademin);
                     $grademin += $items[$itemid]->grademin;
                     $grademax += $items[$itemid]->grademax;
                 }
+
+                $agg_grade = $sum / ($grademax - $grademin);
                 break;
 
             case GRADE_AGGREGATE_MEAN:    // Arithmetic average of all grade items (if ungraded aggregated, NULL counted as minimum)