diff --git a/mod/assign/locallib.php b/mod/assign/locallib.php index 81b61868e6c..f61aa404ef1 100644 --- a/mod/assign/locallib.php +++ b/mod/assign/locallib.php @@ -1346,6 +1346,23 @@ class assign { return true; } + /** + * Mark in the database that this grade record should have an update notification sent by cron. + * + * @param stdClass $grade a grade record keyed on id + * @return bool true for success + */ + public function notify_grade_modified($grade) { + global $DB; + + $grade->timemodified = time(); + if ($grade->mailed != 1) { + $grade->mailed = 0; + } + + return $DB->update_record('assign_grades', $grade); + } + /** * Update a grade in the grade table for the assignment and in the gradebook * @@ -1691,6 +1708,10 @@ class assign { $grade->locked = 0; $grade->grade = -1; $grade->grader = $USER->id; + + // The mailed flag can be one of 3 values: 0 is unsent, 1 is sent and 2 is do not send yet. + // This is because students only want to be notified about certain types of update (grades and feedback). + $grade->mailed = 2; $gid = $DB->insert_record('assign_grades', $grade); $grade->id = $gid; return $grade; @@ -2761,6 +2782,7 @@ class assign { } $this->update_grade($grade); + $this->notify_grade_modified($grade); // save outcomes if ($CFG->enableoutcomes) { @@ -3406,6 +3428,7 @@ class assign { $grade->mailed = 0; $this->update_grade($grade); + $this->notify_grade_modified($grade); $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);