Skip to content

Commit

Permalink
Merge branch 'MDL-53301_master' of git://github.com/dmonllao/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Mar 15, 2016
2 parents 8ea783f + 488366b commit 37f9c6a
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions lib/grade/grade_category.php
Expand Up @@ -1618,19 +1618,20 @@ private function auto_update_weights() {
} else if (empty($CFG->grade_includescalesinaggregation) && $gradeitem->gradetype == GRADE_TYPE_SCALE) {
// We will not aggregate the scales, so we can ignore upating their weights.
continue;
} else if (!$oldextracreditcalculation && $gradeitem->aggregationcoef > 0 && $gradeitem->weightoverride) {
// For an item with extra credit ignore other weigths and overrides but do not change anything at all
// if it's weight was already overridden.
continue;
}

if (!$oldextracreditcalculation && $gradeitem->aggregationcoef > 0) {
// Store the previous value here, no need to update if it is the same value.
$prevaggregationcoef2 = $gradeitem->aggregationcoef2;

if (!$oldextracreditcalculation && $gradeitem->aggregationcoef > 0 && !$gradeitem->weightoverride) {
// For an item with extra credit ignore other weigths and overrides.
// Do not change anything at all if it's weight was already overridden.
if (!$gradeitem->weightoverride) {
$gradeitem->aggregationcoef2 = $totalgrademax ? ($gradeitem->grademax / $totalgrademax) : 0;
$gradeitem->update();
}
continue;
}
$gradeitem->aggregationcoef2 = $totalgrademax ? ($gradeitem->grademax / $totalgrademax) : 0;

if (!$gradeitem->weightoverride) {
} else if (!$gradeitem->weightoverride) {
// Calculations with a grade maximum of zero will cause problems. Just set the weight to zero.
if ($totaloverriddenweight >= 1 || $totalnonoverriddengrademax == 0 || $gradeitem->grademax == 0) {
// There is no more weight to distribute.
Expand All @@ -1641,7 +1642,7 @@ private function auto_update_weights() {
$gradeitem->aggregationcoef2 = ($gradeitem->grademax/$totalnonoverriddengrademax) *
(1 - $totaloverriddenweight);
}
$gradeitem->update();

} else if ((!$automaticgradeitemspresent && $normalisetotal != 1) || ($requiresnormalising)
|| $overridearray[$gradeitem->id]['weight'] < 0) {
// Just divide the overriden weight for this item against the total weight override of all
Expand All @@ -1653,6 +1654,9 @@ private function auto_update_weights() {
} else {
$gradeitem->aggregationcoef2 = $overridearray[$gradeitem->id]['weight'] / $normalisetotal;
}
}

if (grade_floatval($prevaggregationcoef2) !== grade_floatval($gradeitem->aggregationcoef2)) {
// Update the grade item to reflect these changes.
$gradeitem->update();
}
Expand Down

0 comments on commit 37f9c6a

Please sign in to comment.