From 59080eee21a5d5d13f4a47c3c772854560f59d0d Mon Sep 17 00:00:00 2001 From: skodak Date: Wed, 29 Apr 2009 08:55:25 +0000 Subject: [PATCH] MDL-18993 implemented frull support for droplow and keephigh in sum aggregation type --- lib/grade/grade_category.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/grade/grade_category.php b/lib/grade/grade_category.php index 40833af366..a707521491 100644 --- a/lib/grade/grade_category.php +++ b/lib/grade/grade_category.php @@ -720,22 +720,25 @@ class grade_category extends grade_object { return; } - $max = 0; - - //find max grade + //find max grade possible + $maxes = array(); foreach ($items as $item) { if ($item->aggregationcoef > 0) { // extra credit from this activity - does not affect total continue; } if ($item->gradetype == GRADE_TYPE_VALUE) { - $max += $item->grademax; + $maxes[] = $item->grademax; } else if ($item->gradetype == GRADE_TYPE_SCALE) { - $max += $item->grademax; // 0 = nograde, 1 = first scale item, 2 = second scale item + $maxes[] = $item->grademax; // 0 = nograde, 1 = first scale item, 2 = second scale item } } + // apply droplow and keephigh + $this->apply_limit_rules($maxes); + $max = array_sum($maxes); - if ($this->grade_item->grademax != $max or $this->grade_item->grademin != 0 or $this->grade_item->gradetype != GRADE_TYPE_VALUE){ + // update db if anything changed + if ($this->grade_item->grademax != $max or $this->grade_item->grademin != 0 or $this->grade_item->gradetype != GRADE_TYPE_VALUE) { $this->grade_item->grademax = $max; $this->grade_item->grademin = 0; $this->grade_item->gradetype = GRADE_TYPE_VALUE; @@ -800,6 +803,10 @@ class grade_category extends grade_object { arsort($grade_values, SORT_NUMERIC); if (!empty($this->droplow)) { for ($i = 0; $i < $this->droplow; $i++) { + if (empty($grade_values)) { + // nothing to remove + return; + } array_pop($grade_values); } } elseif (!empty($this->keephigh)) { -- 2.39.5