From e7af1926064c22e866859721eefcb2be947dd27c Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Fri, 5 Apr 2013 15:53:38 +0800 Subject: [PATCH] MDL-36804 Assign history: Fix automatic coding error when using auto-reopen method 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 | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/mod/assign/locallib.php b/mod/assign/locallib.php index 04c82190eaa..5cf0de7f427 100644 --- a/mod/assign/locallib.php +++ b/mod/assign/locallib.php @@ -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 &&