MDL-45029 core_course: set aggregationcoef while creating a new course module
authorSimey Lameze <simey@moodle.com>
Fri, 1 Aug 2014 07:43:10 +0000 (15:43 +0800)
committerSimey Lameze <simey@moodle.com>
Wed, 20 Aug 2014 03:56:11 +0000 (11:56 +0800)
course/modlib.php
mod/workshop/lib.php

index 208a9ba..14c91bf 100644 (file)
@@ -209,12 +209,23 @@ function edit_module_post_actions($moduleinfo, $course) {
             }
             $moduleinfo->gradecat = $grade_category->id;
         }
+        $gradecategory = $grade_item->get_parent_category();
         foreach ($items as $itemid=>$unused) {
             $items[$itemid]->set_parent($moduleinfo->gradecat);
             if ($itemid == $grade_item->id) {
                 // Use updated grade_item.
                 $grade_item = $items[$itemid];
             }
+            if (!empty($moduleinfo->add)) {
+                if (grade_category::aggregation_uses_aggregationcoef($gradecategory->aggregation)) {
+                    if ($gradecategory->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
+                        $grade_item->aggregationcoef = 1;
+                    } else {
+                        $grade_item->aggregationcoef = 0;
+                    }
+                    $grade_item->update();
+                }
+            }
         }
     }
 
@@ -273,6 +284,17 @@ function edit_module_post_actions($moduleinfo, $course) {
                 } else if (isset($moduleinfo->gradecat)) {
                     $outcome_item->set_parent($moduleinfo->gradecat);
                 }
+                $gradecategory = $outcome_item->get_parent_category();
+                if ($outcomeexists == false) {
+                    if (grade_category::aggregation_uses_aggregationcoef($gradecategory->aggregation)) {
+                        if ($gradecategory->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
+                            $outcome_item->aggregationcoef = 1;
+                        } else {
+                            $outcome_item->aggregationcoef = 0;
+                        }
+                        $outcome_item->update();
+                    }
+                }
             }
         }
     }
index 616bc4e..af9061c 100644 (file)
@@ -1141,6 +1141,17 @@ function workshop_grade_item_category_update($workshop) {
                     $gradeitem->set_parent($workshop->gradinggradecategory);
                 }
             }
+            if (!empty($workshop->add)) {
+                $gradecategory = $gradeitem->get_parent_category();
+                if (grade_category::aggregation_uses_aggregationcoef($gradecategory->aggregation)) {
+                    if ($gradecategory->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN) {
+                        $gradeitem->aggregationcoef = 1;
+                    } else {
+                        $gradeitem->aggregationcoef = 0;
+                    }
+                    $gradeitem->update();
+                }
+            }
         }
     }
 }