From b43cd17b0d3dae67ca03bac16dd50da4813167b0 Mon Sep 17 00:00:00 2001 From: Zachary Durber Date: Tue, 2 Dec 2014 09:42:13 +0800 Subject: [PATCH] MDL-46442 mod_assign: Notify users when grades are changed --- mod/assign/locallib.php | 8 ++++++-- mod/assign/tests/locallib_test.php | 7 +++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/mod/assign/locallib.php b/mod/assign/locallib.php index adf30c1f2b9..0d2d33049c0 100644 --- a/mod/assign/locallib.php +++ b/mod/assign/locallib.php @@ -1775,13 +1775,14 @@ class assign { * 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 + * @param bool $mailedoverride when true, flag notification to be sent again. * @return bool true for success */ - public function notify_grade_modified($grade) { + public function notify_grade_modified($grade, $mailedoverride = false) { global $DB; $flags = $this->get_user_flags($grade->userid, true); - if ($flags->mailed != 1) { + if ($flags->mailed != 1 || $mailedoverride) { $flags->mailed = 0; } @@ -6422,6 +6423,9 @@ class assign { // Note the default if not provided for this option is true (e.g. webservices). // This is for backwards compatibility. if (!isset($formdata->sendstudentnotifications) || $formdata->sendstudentnotifications) { + if (isset($formdata->sendstudentnotifications)) { + $this->notify_grade_modified($grade, $formdata->sendstudentnotifications); + } $this->notify_grade_modified($grade); } } diff --git a/mod/assign/tests/locallib_test.php b/mod/assign/tests/locallib_test.php index ae213e3f6a2..34bdace3cbd 100644 --- a/mod/assign/tests/locallib_test.php +++ b/mod/assign/tests/locallib_test.php @@ -780,6 +780,13 @@ class mod_assign_locallib_testcase extends mod_assign_base_testcase { $this->assertEquals(2, count($messages)); $this->assertEquals(1, $messages[0]->notification); $this->assertEquals($assign->get_instance()->name, $messages[0]->contexturlname); + + // Regrading a grade causes a notification to the user. + $data->sendstudentnotifications = true; + $assign->testable_apply_grade_to_user($data, $this->students[0]->id, 0); + assign::cron(); + $messages = $sink->get_messages(); + $this->assertEquals(3, count($messages)); } public function test_is_graded() {