From 368c1bb6744a1fa9928aa620b25d3461a78c7e10 Mon Sep 17 00:00:00 2001 From: Clement Smith Date: Thu, 30 Jul 2015 07:44:42 -0500 Subject: [PATCH] MDL-50957 grade/report/user: Fix division by zero 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 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/grade/report/user/lib.php b/grade/report/user/lib.php index d6928fa20ac..0f35f8289c4 100644 --- a/grade/report/user/lib.php +++ b/grade/report/user/lib.php @@ -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);