From bb55642327a8ea164eb8ffa33c7b53f61dd99cf0 Mon Sep 17 00:00:00 2001
From: nicolasconnault <nicolasconnault>
Date: Thu, 17 Sep 2009 07:16:51 +0000
Subject: [PATCH] MDL-19407 Defaulting all grade items to non-extra-credit when
 moving to a SWM category, except if they originally come from a SWM category
 and were set as extra credit there.  Merged from MOODLE_19_STABLE

---
 lib/grade/grade_item.php | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lib/grade/grade_item.php b/lib/grade/grade_item.php
index a67b112a44..62b752bd3c 100644
--- a/lib/grade/grade_item.php
+++ b/lib/grade/grade_item.php
@@ -1221,6 +1221,13 @@ 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;
+        }
+
         $this->force_regrading();
 
         // set new parent
-- 
2.39.5