From 3d6b1bf4e37489e026cec75a7567605fdf70f394 Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Wed, 21 Nov 2012 16:26:47 +0800 Subject: [PATCH] MDL-36712: Assignment - Do not always send feedback available emails when grade is created The entry in the assign_grades table contains grades feedback and other settings such as locked. Only send the student an email about new feedback if it is actually grades or feedback that has been added. This is done by using another state for the mailed flag (2) which means "unset". --- mod/assign/feedback/file/importziplib.php | 2 +- mod/assign/feedback/file/locallib.php | 1 + mod/assign/feedback/offline/locallib.php | 2 ++ mod/assign/locallib.php | 23 +++++++++++++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/mod/assign/feedback/file/importziplib.php b/mod/assign/feedback/file/importziplib.php index b355b33cad3..c3a0441ea7a 100644 --- a/mod/assign/feedback/file/importziplib.php +++ b/mod/assign/feedback/file/importziplib.php @@ -266,7 +266,7 @@ class assignfeedback_file_zip_importer { $fileplugin->update_file_count($grade); // Update the last modified time on the grade which will trigger student notifications. - $assignment->update_grade($grade); + $assignment->notify_grade_modified($grade); } } } diff --git a/mod/assign/feedback/file/locallib.php b/mod/assign/feedback/file/locallib.php index 6ed295eca93..7c6a12a5438 100644 --- a/mod/assign/feedback/file/locallib.php +++ b/mod/assign/feedback/file/locallib.php @@ -403,6 +403,7 @@ class assign_feedback_file extends assign_feedback_plugin { // Now copy each of these files to the users feedback file area. foreach ($users as $userid) { $grade = $this->assignment->get_user_grade($userid, true); + $this->assignment->notify_grade_modified($grade); $this->copy_area_files($fs, $this->assignment->get_context()->id, diff --git a/mod/assign/feedback/offline/locallib.php b/mod/assign/feedback/offline/locallib.php index d64927fac30..e01d7b89245 100644 --- a/mod/assign/feedback/offline/locallib.php +++ b/mod/assign/feedback/offline/locallib.php @@ -157,6 +157,7 @@ class assign_feedback_offline extends assign_feedback_plugin { $grade->grade = $record->grade; $grade->grader = $USER->id; if ($this->assignment->update_grade($grade)) { + $this->assignment->notify_grade_modified($grade); $this->assignment->add_to_log('grade submission', $this->assignment->format_grade_for_log($grade)); $updatecount += 1; } @@ -178,6 +179,7 @@ class assign_feedback_offline extends assign_feedback_plugin { if ($newvalue != $oldvalue) { $updatecount += 1; $grade = $this->assignment->get_user_grade($record->user->id, true); + $this->assignment->notify_grade_modified($grade); if ($plugin->set_editor_text($field, $newvalue, $grade->id)) { $logdesc = get_string('feedbackupdate', 'assignfeedback_offline', array('field'=>$description, diff --git a/mod/assign/locallib.php b/mod/assign/locallib.php index 9971cd04059..6b4b8eda143 100644 --- a/mod/assign/locallib.php +++ b/mod/assign/locallib.php @@ -1476,6 +1476,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 * @@ -2175,6 +2192,10 @@ class assign { $grade->grade = -1; $grade->grader = $USER->id; $grade->extensionduedate = 0; + + // 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; @@ -3712,6 +3733,7 @@ class assign { } $this->update_grade($grade); + $this->notify_grade_modified($grade); // save outcomes if ($CFG->enableoutcomes) { @@ -4406,6 +4428,7 @@ class assign { } } $this->update_grade($grade); + $this->notify_grade_modified($grade); $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST); $this->add_to_log('grade submission', $this->format_grade_for_log($grade));