From 7821a81662c556429ca0c0c402545a9f4501900e Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Fri, 4 Sep 2015 11:04:17 +0800 Subject: [PATCH] MDL-48861 assign: Fix the "needs grading" filter When auto-creating a new grade record - do not set the timemodified > than the submission timemodified --- mod/assign/locallib.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/mod/assign/locallib.php b/mod/assign/locallib.php index 79d509f1a1fa7..effc0bfdfbd14 100644 --- a/mod/assign/locallib.php +++ b/mod/assign/locallib.php @@ -1518,7 +1518,7 @@ public function count_submissions_need_grading() { s.assignment = :assignid AND s.timemodified IS NOT NULL AND s.status = :submitted AND - (s.timemodified > g.timemodified OR g.timemodified IS NULL OR g.grade IS NULL)'; + (s.timemodified > g.timemodified OR g.timemodified IS NULL)'; return $DB->count_records_sql($sql, $params); } @@ -2890,9 +2890,10 @@ public function get_user_grade($userid, $create, $attemptnumber=-1) { if (!$userid) { $userid = $USER->id; } + $submission = null; $params = array('assignment'=>$this->get_instance()->id, 'userid'=>$userid); - if ($attemptnumber < 0) { + if ($attemptnumber < 0 || $create) { // Make sure this grade matches the latest submission attempt. if ($this->get_instance()->teamsubmission) { $submission = $this->get_group_submission($userid, 0, true); @@ -2918,7 +2919,14 @@ public function get_user_grade($userid, $create, $attemptnumber=-1) { $grade->assignment = $this->get_instance()->id; $grade->userid = $userid; $grade->timecreated = time(); - $grade->timemodified = $grade->timecreated; + // If we are "auto-creating" a grade - and there is a submission + // the new grade should not have a more recent timemodified value + // than the submission. + if ($submission) { + $grade->timemodified = $submission->timemodified; + } else { + $grade->timemodified = $grade->timecreated; + } $grade->grade = -1; $grade->grader = $USER->id; if ($attemptnumber >= 0) {