diff --git a/grade/edit/tree/index.php b/grade/edit/tree/index.php index 26fb0bb..bb86c1d 100644 --- a/grade/edit/tree/index.php +++ b/grade/edit/tree/index.php @@ -89,12 +89,35 @@ if (has_capability('moodle/grade:manage', $context)) { // Change category aggregation if requested if (!is_null($category) && !is_null($aggregationtype) && confirm_sesskey()) { if (!$grade_category = grade_category::fetch(array('id'=>$category, 'courseid'=>$courseid))) { error('Incorrect category id!'); } $data->aggregation = $aggregationtype; + + // RT# 57186 20100115 kimx0794. + // Go through and set the aggregationcoef for all the children to 0 when switching from WM to SUM/SWM. + if ($grade_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN AND ($aggregationtype == GRADE_AGGREGATE_WEIGHTED_MEAN2 + OR $aggregationtype == GRADE_AGGREGATE_SUM)) { + $grade_category->children = $grade_category->get_children(); + foreach ( $grade_category->children as $useditem) { + $useditem['object']->grade_item = $useditem['object']->get_grade_item(); + $useditem['object']->grade_item->aggregationcoef = 0; + $useditem['object']->grade_item->update(); + } + // Go through and set the aggregationcoef for all the children to 1 when switching from SUM/SWM to WM. + } elseif (($grade_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN2 OR $grade_category->aggregation == GRADE_AGGREGATE_SUM) + AND $aggregationtype == GRADE_AGGREGATE_WEIGHTED_MEAN) { + $grade_category->children = $grade_category->get_children(); + foreach ( $grade_category->children as $useditem) { + $useditem['object']->grade_item = $useditem['object']->get_grade_item(); + $useditem['object']->grade_item->aggregationcoef = 1; + $useditem['object']->grade_item->update(); + } + } + + grade_category::set_properties($grade_category, $data); $grade_category->update(); grade_regrade_final_grades($courseid); } //first make sure we have proper final grades - we need it for locking changes diff --git a/lib/grade/grade_item.php b/lib/grade/grade_item.php index d4199d6..8a5f175 100644 --- a/lib/grade/grade_item.php +++ b/lib/grade/grade_item.php @@ -1208,14 +1208,22 @@ class grade_item extends grade_object { return false; } // MDL-19407 If moving from a non-SWM category to a SWM category, convert aggregationcoef to 0 $currentparent = $this->load_parent_category(); - if ($currentparent->aggregation != GRADE_AGGREGATE_WEIGHTED_MEAN2 && $parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN2) { - $this->aggregationcoef = 0; + // RT# 57186 20100115 kimx0794. + // If moving from a non-SWM/non-SUM category to a SUM/SWM category, convert aggregationcoef to 0. + if ($currentparent->aggregation != GRADE_AGGREGATE_WEIGHTED_MEAN2 && $currentparent->aggregation != GRADE_AGGREGATE_SUM + && ($parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN2 || $parent_category->aggregation == GRADE_AGGREGATE_SUM)) { + $this->aggregationcoef = 0; + + // If moving from a non-WM category to a WM category, convert aggregationcoef to 1. + } elseif (($currentparent->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN2 || $currentparent->aggregation == GRADE_AGGREGATE_SUM) + && $parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) { + $this->aggregationcoef = 1; } $this->force_regrading(); // set new parent $this->categoryid = $parent_category->id;