MDL-50957 grade/report/user: Fix division by zero
authorClement Smith <cdsmith@umn.edu>
Thu, 30 Jul 2015 12:44:42 +0000 (07:44 -0500)
committerClement Smith <cdsmith@umn.edu>
Mon, 24 Aug 2015 14:05:30 +0000 (09:05 -0500)
When using "sum of grades" and $grademax is zero, a division by zero
error occurs in fill_contributions_column() in
grade/report/user/lib.php.

grade/report/user/lib.php

index d6928fa..0f35f82 100644 (file)
@@ -731,7 +731,12 @@ class grade_report_user extends grade_report {
                 if ($gradecat->aggregation == GRADE_AGGREGATE_SUM) {
                     // Natural aggregation/Sum of grades does not consider the mingrade, cannot traditionnally normalise it.
                     $graderange = $this->aggregationhints[$itemid]['grademax'];
-                    $gradeval = $this->aggregationhints[$itemid]['grade'] / $graderange;
+
+                    if ($graderange != 0) {
+                        $gradeval = $this->aggregationhints[$itemid]['grade'] / $graderange;
+                    } else {
+                        $gradeval = 0;
+                    }
                 } else {
                     $gradeval = grade_grade::standardise_score($this->aggregationhints[$itemid]['grade'],
                         $this->aggregationhints[$itemid]['grademin'], $this->aggregationhints[$itemid]['grademax'], 0, 1);