MDL-18772 fixed aut oupdating of grademax for SUM aggregation type

This commit is contained in:
skodak
2009-04-05 20:17:04 +00:00
parent 97481934ca
commit 3a03653edf
+47 -22
View File
@@ -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);