MDL-47703 core_grades: Prevent use of weights with non-aggregated scales

This commit is contained in:
Frederic Massart 2014-10-16 11:12:44 +08:00 committed by Frederic Massart
parent d63a81c507
commit 8b5c454562
4 changed files with 16 additions and 3 deletions

View file

@ -467,7 +467,9 @@ class edit_category_form extends moodleform {
}
// Remove fields used by natural weighting if the parent category is not using natural weighting.
if ($parent_category->aggregation != GRADE_AGGREGATE_SUM) {
// Or if the item is a scale and scales are not used in aggregation.
if ($parent_category->aggregation != GRADE_AGGREGATE_SUM
|| (empty($CFG->grade_includescalesinaggregation) && $grade_item->gradetype == GRADE_TYPE_SCALE)) {
if ($mform->elementExists('grade_item_weightoverride')) {
$mform->removeElement('grade_item_weightoverride');
}

View file

@ -310,7 +310,9 @@ class edit_item_form extends moodleform {
}
// Remove fields used by natural weighting if the parent category is not using natural weighting.
if ($parent_category->aggregation != GRADE_AGGREGATE_SUM) {
// Or if the item is a scale and scales are not used in aggregation.
if ($parent_category->aggregation != GRADE_AGGREGATE_SUM
|| (empty($CFG->grade_includescalesinaggregation) && $grade_item->gradetype == GRADE_TYPE_SCALE)) {
if ($mform->elementExists('weightoverride')) {
$mform->removeElement('weightoverride');
}

View file

@ -706,6 +706,7 @@ class grade_edit_tree_column_weight extends grade_edit_tree_column {
}
public function get_item_cell($item, $params) {
global $CFG;
if (empty($params['element'])) {
throw new Exception('Array key (element) missing from 2nd param of grade_edit_tree_column_weightorextracredit::get_item_cell($item, $params)');
}
@ -715,7 +716,8 @@ class grade_edit_tree_column_weight extends grade_edit_tree_column {
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)) {
&& (!$object->is_outcome_item() || $object->load_parent_category()->aggregateoutcomes)
&& ($object->gradetype != GRADE_TYPE_SCALE || !empty($CFG->grade_includescalesinaggregation))) {
$itemcell->text = grade_edit_tree::get_weight_input($item);
}

View file

@ -1419,6 +1419,7 @@ class grade_category extends grade_object {
* @return void
*/
private function auto_update_weights() {
global $CFG;
if ($this->aggregation != GRADE_AGGREGATE_SUM) {
// This is only required if we are using natural weights.
return;
@ -1457,6 +1458,9 @@ class grade_category extends grade_object {
} else if (!$this->aggregateoutcomes && $gradeitem->is_outcome_item()) {
// We will not aggregate outcome items, so we can ignore them.
continue;
} else if (empty($CFG->grade_includescalesinaggregation) && $gradeitem->gradetype == GRADE_TYPE_SCALE) {
// The scales are not included in the aggregation, ignore them.
continue;
}
// Record the ID and the weight for this grade item.
@ -1530,6 +1534,9 @@ class grade_category extends grade_object {
} else if (!$this->aggregateoutcomes && $gradeitem->is_outcome_item()) {
// We will not aggregate outcome items, so we can ignore updating their weights.
continue;
} 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;
}
if (!$gradeitem->weightoverride) {