From: skodak Date: Sun, 5 Apr 2009 20:17:04 +0000 (+0000) Subject: MDL-18772 fixed aut oupdating of grademax for SUM aggregation type X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=3a03653edf6fa40e6f4d838d9fdc9f4e0f9ae2b3;p=moodle.git MDL-18772 fixed aut oupdating of grademax for SUM aggregation type --- diff --git a/lib/grade/grade_category.php b/lib/grade/grade_category.php index 74dd019305..f95b69f6d3 100644 --- a/lib/grade/grade_category.php +++ b/lib/grade/grade_category.php @@ -424,6 +424,9 @@ class grade_category extends grade_object { $items = $DB->get_records_sql($sql, $params); } + // needed mostly for SUM agg type + $this->auto_update_max($items); + $grade_inst = new grade_grade(); $fields = 'g.'.implode(',g.', $grade_inst->required_fields); @@ -691,6 +694,50 @@ class grade_category extends grade_object { return $agg_grade; } + /** + * Some aggregation tpyes may update max grade + * @param array $items sub items + * @return void + */ + private function auto_update_max($items) { + if ($this->aggregation != GRADE_AGGREGATE_SUM) { + // not needed at all + return; + } + + if (!$items) { + if ($this->grade_item->grademax != 0 or $this->grade_item->gradetype != GRADE_TYPE_VALUE) { + $this->grade_item->grademax = 0; + $this->grade_item->grademin = 0; + $this->grade_item->gradetype = GRADE_TYPE_VALUE; + $this->grade_item->update('aggregation'); + } + return; + } + + $max = 0; + + //find max grade + 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; + } else if ($item->gradetype == GRADE_TYPE_SCALE) { + $max += $item->grademax - 1; // scales min is 1 + } + } + + 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; + $this->grade_item->update('aggregation'); + } + } + /** * internal function for category grades summing * @@ -721,28 +768,6 @@ class grade_category extends grade_object { } } - $max = 0; - - //find max grade - 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; - } else if ($item->gradetype == GRADE_TYPE_SCALE) { - $max += $item->grademax - 1; // scales min is 1 - } - } - - 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; - $this->grade_item->update('aggregation'); - } - $this->apply_limit_rules($grade_values); $sum = array_sum($grade_values);