Merge branch 'MDL-47681-master' of git://github.com/FMCorz/moodle
authorDan Poltawski <dan@moodle.com>
Thu, 16 Oct 2014 14:14:20 +0000 (15:14 +0100)
committerDan Poltawski <dan@moodle.com>
Thu, 16 Oct 2014 14:14:20 +0000 (15:14 +0100)
grade/edit/tree/item_form.php
grade/edit/tree/lib.php
lib/grade/grade_category.php

index 1c209f4..c89631b 100644 (file)
@@ -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);
             }
 
index aa4e077..4a86cb3 100644 (file)
@@ -699,7 +699,8 @@ class grade_edit_tree_column_weight extends grade_edit_tree_column {
         $itemcell = parent::get_item_cell($item, $params);
         $itemcell->text = '&nbsp;';
 
-        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);
         }
 
index 3f64375..889006f 100644 (file)
@@ -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) {