MDL-36804 Assign history: Fix automatic coding error when using auto-reopen method
authorDamyon Wiese <damyon@moodle.com>
Fri, 5 Apr 2013 07:53:38 +0000 (15:53 +0800)
committerDamyon Wiese <damyon@moodle.com>
Fri, 5 Apr 2013 07:53:38 +0000 (15:53 +0800)
This fix should call the gradebook function is_passed - but the gradebook is returning a record with
not enough information to create an instance of grade_grade.

mod/assign/locallib.php

index 04c8219..5cf0de7 100644 (file)
@@ -2499,6 +2499,18 @@ class assign {
         }
 
         $params = array('assignment'=>$this->get_instance()->id, 'userid'=>$userid);
+        if ($attemptnumber < 0) {
+            // Make sure this grade matches the latest submission attempt.
+            if ($this->get_instance()->teamsubmission) {
+                $submission = $this->get_group_submission($userid, 0, false);
+            } else {
+                $submission = $this->get_user_submission($userid, false);
+            }
+            if ($submission) {
+                $attemptnumber = $submission->attemptnumber;
+            }
+        }
+
         if ($attemptnumber >= 0) {
             $params['attemptnumber'] = $attemptnumber;
         }
@@ -5507,8 +5519,19 @@ class assign {
                     $gradingitem = $gradinginfo->items[0];
                     $gradebookgrade = $gradingitem->grades[$userid];
                 }
-                if ($gradebookgrade && !$gradebookgrade->is_passed($gradingitem)) {
+
+                if ($gradebookgrade) {
+                    // TODO: This code should call grade_grade->is_passed().
                     $shouldreopen = true;
+                    if (is_null($gradebookgrade->grade)) {
+                        $shouldreopen = false;
+                    }
+                    if (empty($gradingitem->gradepass) || $gradingitem->gradepass == $gradingitem->grademin) {
+                        $shouldreopen = false;
+                    }
+                    if ($gradebookgrade->grade >= $gradingitem->gradepass) {
+                        $shouldreopen = false;
+                    }
                 }
             }
             if ($instance->attemptreopenmethod == ASSIGN_ATTEMPT_REOPEN_METHOD_MANUAL &&