mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-47681 core_grades: Ignore weights of grade items 'none' or 'text'
It can happen that some grade items with the type 'None' have a max grade different than 0, in which case we would have set a weight for them which is wrong as they must not have any. This patch always ignores the grade items 'None' and 'Text' when calculating the weights and locks the weight UI fields for those items too.
This commit is contained in:
parent
799190cd2d
commit
f8c8f980c7
3 changed files with 19 additions and 2 deletions
|
@ -178,11 +178,15 @@ class edit_item_form extends moodleform {
|
|||
|
||||
$mform->addElement('advcheckbox', 'weightoverride', get_string('adjustedweight', 'grades'));
|
||||
$mform->addHelpButton('weightoverride', 'weightoverride', 'grades');
|
||||
$mform->disabledIf('weightoverride', 'gradetype', 'eq', GRADE_TYPE_NONE);
|
||||
$mform->disabledIf('weightoverride', 'gradetype', 'eq', GRADE_TYPE_TEXT);
|
||||
|
||||
$mform->addElement('text', 'aggregationcoef2', get_string('weight', 'grades'));
|
||||
$mform->addHelpButton('aggregationcoef2', 'weight', 'grades');
|
||||
$mform->setType('aggregationcoef2', PARAM_RAW);
|
||||
$mform->disabledIf('aggregationcoef2', 'weightoverride');
|
||||
$mform->disabledIf('aggregationcoef2', 'gradetype', 'eq', GRADE_TYPE_NONE);
|
||||
$mform->disabledIf('aggregationcoef2', 'gradetype', 'eq', GRADE_TYPE_TEXT);
|
||||
|
||||
$options = array();
|
||||
$coefstring = '';
|
||||
|
@ -300,7 +304,8 @@ class edit_item_form extends moodleform {
|
|||
}
|
||||
$mform->addHelpButton('aggregationcoef', $coefstring, 'grades');
|
||||
}
|
||||
|
||||
$mform->disabledIf('aggregationcoef', 'gradetype', 'eq', GRADE_TYPE_NONE);
|
||||
$mform->disabledIf('aggregationcoef', 'gradetype', 'eq', GRADE_TYPE_TEXT);
|
||||
$mform->disabledIf('aggregationcoef', 'parentcategory', 'eq', $parent_category->id);
|
||||
}
|
||||
|
||||
|
|
|
@ -699,7 +699,8 @@ class grade_edit_tree_column_weight extends grade_edit_tree_column {
|
|||
$itemcell = parent::get_item_cell($item, $params);
|
||||
$itemcell->text = ' ';
|
||||
|
||||
if (!in_array($params['element']['object']->itemtype, array('courseitem', 'categoryitem', 'category'))) {
|
||||
if (!in_array($params['element']['object']->itemtype, array('courseitem', 'categoryitem', 'category'))
|
||||
&& !in_array($params['element']['object']->gradetype, array(GRADE_TYPE_NONE, GRADE_TYPE_TEXT))) {
|
||||
$itemcell->text = grade_edit_tree::get_weight_input($item);
|
||||
}
|
||||
|
||||
|
|
|
@ -1299,6 +1299,11 @@ class grade_category extends grade_object {
|
|||
$gradeitem = $child['object']->load_grade_item();
|
||||
}
|
||||
|
||||
if ($gradeitem->gradetype == GRADE_TYPE_NONE || $gradeitem->gradetype == GRADE_TYPE_TEXT) {
|
||||
// Text items and none items do not have a weight.
|
||||
continue;
|
||||
}
|
||||
|
||||
// Record the ID and the weight for this grade item.
|
||||
$overridearray[$gradeitem->id] = array();
|
||||
$overridearray[$gradeitem->id]['extracredit'] = intval($gradeitem->aggregationcoef);
|
||||
|
@ -1363,6 +1368,12 @@ class grade_category extends grade_object {
|
|||
$gradeitem = $child['object']->load_grade_item();
|
||||
}
|
||||
|
||||
if ($gradeitem->gradetype == GRADE_TYPE_NONE || $gradeitem->gradetype == GRADE_TYPE_TEXT) {
|
||||
// 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;
|
||||
}
|
||||
|
||||
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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue