MDL-38628 mod_assign: Allow a user to specify "No Grade" when grading an assignment...
authorJody Steele <steelej@queensu.ca>
Wed, 16 Oct 2013 15:19:34 +0000 (11:19 -0400)
committerMarina Glancy <marina@moodle.com>
Mon, 21 Oct 2013 05:47:05 +0000 (16:47 +1100)
mod/assign/gradeform.php
mod/assign/locallib.php

index bff82de..751d220 100644 (file)
@@ -94,7 +94,7 @@ class mod_assign_grade_form extends moodleform {
             // This is a scale.
             if ($scale = $DB->get_record('scale', array('id'=>-($instance->grade)))) {
                 $scaleoptions = make_menu_from_list($scale->scale);
-                if (!array_key_exists((int)$data['grade'], $scaleoptions)) {
+                if ((int)$data['grade'] !== -1 && !array_key_exists((int)$data['grade'], $scaleoptions)) {
                     $errors['grade'] = get_string('invalidgradeforscale', 'assign');
                 }
             }
index 8056ba3..167406f 100644 (file)
@@ -3909,6 +3909,10 @@ class assign {
         if ($grade->grade >= 0) {
             $gradebookgrade['rawgrade'] = $grade->grade;
         }
+        // Allow "no grade" to be chosen.
+        if ($grade->grade == -1) {
+            $gradebookgrade['rawgrade'] = NULL;
+        }
         $gradebookgrade['userid'] = $grade->userid;
         $gradebookgrade['usermodified'] = $grade->grader;
         $gradebookgrade['datesubmitted'] = null;
@@ -5520,8 +5524,8 @@ class assign {
                     $mform->addHelpButton('gradedisabled', 'gradeoutofhelp', 'assign');
                 }
             } else {
-                $grademenu = make_grades_menu($this->get_instance()->grade);
-                if (count($grademenu) > 0) {
+                $grademenu = array(-1 => get_string("nograde")) + make_grades_menu($this->get_instance()->grade);
+                if (count($grademenu) > 1) {
                     $gradingelement = $mform->addElement('select', 'grade', get_string('grade') . ':', $grademenu);
 
                     // The grade is already formatted with format_float so it needs to be converted back to an integer.