From 78618bc6772e9b53ba6918db69328b063ff94d7a Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Fri, 1 Aug 2014 15:43:10 +0800 Subject: [PATCH] MDL-45029 core_course: set aggregationcoef while creating a new course module --- course/modlib.php | 22 ++++++++++++++++++++++ mod/workshop/lib.php | 11 +++++++++++ 2 files changed, 33 insertions(+) diff --git a/course/modlib.php b/course/modlib.php index 208a9ba192c..14c91bf50b2 100644 --- a/course/modlib.php +++ b/course/modlib.php @@ -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(); + } + } } } } diff --git a/mod/workshop/lib.php b/mod/workshop/lib.php index 616bc4e104f..af9061cd354 100644 --- a/mod/workshop/lib.php +++ b/mod/workshop/lib.php @@ -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(); + } + } } } }