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);
}