Skip to content
This repository has been archived by the owner on Apr 8, 2022. It is now read-only.

Commit

Permalink
MDL-47637 core_grades: Outcomes must not be weighted when non aggregated
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederic Massart committed Oct 22, 2014
1 parent 7a61e64 commit 6aeebc2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
6 changes: 4 additions & 2 deletions grade/edit/tree/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -698,9 +698,11 @@ public function get_item_cell($item, $params) {
}
$itemcell = parent::get_item_cell($item, $params);
$itemcell->text = ' ';
$object = $params['element']['object'];

if (!in_array($params['element']['object']->itemtype, array('courseitem', 'categoryitem', 'category'))
&& !in_array($params['element']['object']->gradetype, array(GRADE_TYPE_NONE, GRADE_TYPE_TEXT))) {
if (!in_array($object->itemtype, array('courseitem', 'categoryitem', 'category'))
&& !in_array($object->gradetype, array(GRADE_TYPE_NONE, GRADE_TYPE_TEXT))
&& (!$object->is_outcome_item() || $object->load_parent_category()->aggregateoutcomes)) {
$itemcell->text = grade_edit_tree::get_weight_input($item);
}

Expand Down
9 changes: 6 additions & 3 deletions grade/edit/tree/outcomeitem_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ function definition_after_data() {

$parent_category->apply_forced_settings();

if (!$parent_category->is_aggregationcoef_used()) {
if (!$parent_category->is_aggregationcoef_used() || !$parent_category->aggregateoutcomes) {
if ($mform->elementExists('aggregationcoef')) {
$mform->removeElement('aggregationcoef');
}
Expand All @@ -228,8 +228,11 @@ function definition_after_data() {
$mform->addHelpButton('aggregationcoef', $aggcoef, 'grades');
}
}
// Remove fields used by natural weighting if the parent category is not using natural weighting.
if ($parent_category->aggregation != GRADE_AGGREGATE_SUM) {

// Remove the natural weighting fields for other aggregations,
// or when the category does not aggregate outcomes.
if ($parent_category->aggregation != GRADE_AGGREGATE_SUM ||
!$parent_category->aggregateoutcomes) {
if ($mform->elementExists('weightoverride')) {
$mform->removeElement('weightoverride');
}
Expand Down
6 changes: 6 additions & 0 deletions lib/grade/grade_category.php
Original file line number Diff line number Diff line change
Expand Up @@ -1436,6 +1436,9 @@ private function auto_update_weights() {
if ($gradeitem->gradetype == GRADE_TYPE_NONE || $gradeitem->gradetype == GRADE_TYPE_TEXT) {
// Text items and none items do not have a weight.
continue;
} else if (!$this->aggregateoutcomes && $gradeitem->is_outcome_item()) {
// We will not aggregate outcome items, so we can ignore them.
continue;
}

// Record the ID and the weight for this grade item.
Expand Down Expand Up @@ -1506,6 +1509,9 @@ private function auto_update_weights() {
// Text items and none items do not have a weight, no need to set their weight to
// zero as they must never be used during aggregation.
continue;
} else if (!$this->aggregateoutcomes && $gradeitem->is_outcome_item()) {
// We will not aggregate outcome items, so we can ignore updating their weights.
continue;
}

if (!$gradeitem->weightoverride) {
Expand Down

0 comments on commit 6aeebc2

Please sign in to comment.