From 59c005b76e912a0fa48495cc5f6ae2682a59e9a4 Mon Sep 17 00:00:00 2001 From: moodler Date: Wed, 5 Jan 2005 17:13:44 +0000 Subject: [PATCH] Email alerts to teachers ------------------------ Added a small new feature to the assignment module to alert teachers when new emails come in. This feature adds one new field (which is tested) but the operation of the new code has not been tested yet at all (apart from PHP syntax) and very likely has bugs in it. I'm checking this in so I can do tests on test.moodle.com which has email set up properly. I'm off to bed right now but if anyone else wants to test this feature before tomorrow please do! :-) While I'm rambling here in CVS, I need to have a good look soon at Pablo's work on Assignment and see if I can merge it all in... --- lang/en/assignment.php | 11 ++++ lang/en/help/assignment/emailteachers.html | 12 ++++ mod/assignment/db/mysql.php | 4 ++ mod/assignment/db/mysql.sql | 1 + mod/assignment/db/postgres7.php | 4 ++ mod/assignment/db/postgres7.sql | 1 + mod/assignment/lib.php | 74 ++++++++++++++++++++++ mod/assignment/mod.html | 13 ++++ mod/assignment/upload.php | 2 + mod/assignment/version.php | 2 +- 10 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 lang/en/help/assignment/emailteachers.html diff --git a/lang/en/assignment.php b/lang/en/assignment.php index ae772e5735..3b3add1b48 100644 --- a/lang/en/assignment.php +++ b/lang/en/assignment.php @@ -20,6 +20,17 @@ $string['description'] = 'Description'; $string['duedate'] = 'Due date'; $string['duedateno'] = 'No due date'; $string['early'] = '$a early'; +$string['emailteachers'] = 'Email alerts to teachers'; +$string['emailteachermail'] = ' +$a->username has updated their assignment submission +for \'$a->assignment\' + +It is available here: + + $a->url'; +$string['emailteachermailhtml'] = '$a->username has updated their assignment submission +for \'$a->assignment\'

+It is url\">available on the web site.'; $string['existingfiledeleted'] = 'Existing file has been deleted: $a'; $string['failedupdatefeedback'] = 'Failed to update submission feedback for user $a'; $string['feedback'] = 'Feedback'; diff --git a/lang/en/help/assignment/emailteachers.html b/lang/en/help/assignment/emailteachers.html new file mode 100644 index 0000000000..a4b7a7b537 --- /dev/null +++ b/lang/en/help/assignment/emailteachers.html @@ -0,0 +1,12 @@ +

Email alerts to teachers

+ +

If enabled, then teachers are alerted with a short email whenever students + add or update an assignment submission.

+ +

Only teachers who are able to grade the particular submission are notified. + So, for example, if the course uses separate groups, then teachers restricted + to particular groups won't receive any notices about students in other groups.

+ +

For offline activities, of course, mail is never sent since students never + submit anything.

+ diff --git a/mod/assignment/db/mysql.php b/mod/assignment/db/mysql.php index 031f97f010..c6ce006faf 100644 --- a/mod/assignment/db/mysql.php +++ b/mod/assignment/db/mysql.php @@ -113,6 +113,10 @@ function assignment_upgrade($oldversion) { modify_database('','ALTER TABLE prefix_assignment_submissions ADD INDEX timemarked (timemarked);'); } + if ($oldversion < 2005010500) { + table_column('assignment', '', 'emailteachers', 'integer', '2', 'unsigned', 0, 'not null', 'resubmit'); + } + return true; } diff --git a/mod/assignment/db/mysql.sql b/mod/assignment/db/mysql.sql index 0a3cf65bab..ac7608f015 100644 --- a/mod/assignment/db/mysql.sql +++ b/mod/assignment/db/mysql.sql @@ -9,6 +9,7 @@ CREATE TABLE `prefix_assignment` ( `description` text NOT NULL, `format` tinyint(2) unsigned NOT NULL default '0', `resubmit` tinyint(2) unsigned NOT NULL default '0', + `emailteachers` tinyint(2) unsigned NOT NULL default '0', `type` int(10) unsigned NOT NULL default '1', `maxbytes` int(10) unsigned NOT NULL default '100000', `timedue` int(10) unsigned NOT NULL default '0', diff --git a/mod/assignment/db/postgres7.php b/mod/assignment/db/postgres7.php index 4fadbf5737..afafaf8201 100644 --- a/mod/assignment/db/postgres7.php +++ b/mod/assignment/db/postgres7.php @@ -111,6 +111,10 @@ function assignment_upgrade($oldversion) { modify_database('','CREATE INDEX prefix_assignment_submissions_timemarked_idx ON prefix_assignment_submissions (timemarked);'); } + if ($oldversion < 2005010500) { + table_column('assignment', '', 'emailteachers', 'integer', '2', 'unsigned', 0, 'not null', 'resubmit'); + } + return true; } diff --git a/mod/assignment/db/postgres7.sql b/mod/assignment/db/postgres7.sql index 3902caf4dd..7d57ce7cdd 100644 --- a/mod/assignment/db/postgres7.sql +++ b/mod/assignment/db/postgres7.sql @@ -9,6 +9,7 @@ CREATE TABLE prefix_assignment ( description text NOT NULL default '', format integer NOT NULL default '0', resubmit integer NOT NULL default '0', + emailteachers integer NOT NULL default '0', type integer NOT NULL default '1', maxbytes integer NOT NULL default '100000', timedue integer NOT NULL default '0', diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php index 0621e169e6..585b9a0262 100644 --- a/mod/assignment/lib.php +++ b/mod/assignment/lib.php @@ -819,4 +819,78 @@ function assignment_get_user_file($assignment, $user) { return $tmpfile; } +if (!function_exists('get_group_teachers')) { // Will be in datalib.php later + function get_group_teachers($courseid, $groupid) { + /// Returns a list of all the teachers who can access a group + if ($teachers = get_course_teachers($courseid)) { + foreach ($teachers as $key => $teacher) { + if ($teacher->editall) { // These can access anything + continue; + } + if (($teacher->authority > 0) and ismember($groupid, $teacher->id)) { // Specific group teachers + continue; + } + unset($teacher[$key]); + } + } + return $teachers; + } +} + +function assignment_email_teachers($course, $cm, $assignment, $submission) { +/// Alerts teachers by email of new or changed assignments that need grading + + global $CFG; + + if (empty($assignment->emailteachers)) { // No need to do anything + return; + } + + $user = get_record('user', 'id', $submission->userid); + + if (groupmode($course, $cm) == SEPARATEGROUPS) { // Separate groups are being used + if (!$group = user_group($course->id, $user->id)) { // Try to find a group + $group->id = 0; // Not in a group, never mind + } + $teachers = get_group_teachers($course->id, $group->id); // Works even if not in group + } else { + $teachers = get_course_teachers($course->id); + } + + if (!$teachers) { + + $strassignments = get_string('modulenameplural', 'assignment'); + $strassignment = get_string('modulename', 'assignment'); + $strsubmitted = get_string('submitted', 'assignment'); + + foreach ($teachers as $teacher) { + unset($info); + $info->username = fullname($user); + $info->assignment = "$submission->name"; + $info->url = "$CFG->wwwroot/mod/assignment/view.php?id=$cm->id"; + + $postsubject = "$strsubmitted: $info->username -> $assignment->name"; + $posttext = "$course->shortname -> $strassignments -> $assignment->name\n"; + $posttext .= "---------------------------------------------------------------------\n"; + $posttext .= get_string("emailteachermail", "assignment", $info); + $posttext .= "---------------------------------------------------------------------\n"; + + if ($user->mailformat == 1) { // HTML + $posthtml = "

". + "wwwroot/course/view.php?id=$course->id\">$course->shortname ->". + "wwwroot/mod/assignment/index.php?id=$course->id\">$strassignments ->". + "wwwroot/mod/assignment/view.php?id=$cm->id\">$assignment->name

"; + $posthtml .= "
"; + $posthtml .= "

".get_string("emailteachermailhtml", "assignment", $info)."

"; + $posthtml .= "

"; + } else { + $posthtml = ""; + } + + @email_to_user($user, $teacher, $postsubject, $posttext, $posthtml); // If it fails, oh well, too bad. + } + } +} + + ?> diff --git a/mod/assignment/mod.html b/mod/assignment/mod.html index b4886b36cf..1fe0a400e9 100644 --- a/mod/assignment/mod.html +++ b/mod/assignment/mod.html @@ -23,6 +23,9 @@ if (empty($form->timedue)) { $form->timedue = ""; } + if (empty($form->emailteachers)) { + $form->emailteachers = ""; + } ?>
@@ -91,6 +94,16 @@ ?> + + : + + emailteachers, ""); + helpbutton("emailteachers", get_string("emailteachers", "assignment"), "assignment"); + ?> + + : diff --git a/mod/assignment/upload.php b/mod/assignment/upload.php index 5fd58d638b..275ae99a6e 100644 --- a/mod/assignment/upload.php +++ b/mod/assignment/upload.php @@ -44,6 +44,7 @@ $submission->numfiles = 1; $submission->comment = addslashes($submission->comment); if (update_record("assignment_submissions", $submission)) { + assignment_email_teachers($course, $cm, $assignment, $submission); print_heading(get_string('uploadedfile')); } else { notify(get_string("uploadfailnoupdate", "assignment")); @@ -56,6 +57,7 @@ $newsubmission->numfiles = 1; if (insert_record("assignment_submissions", $newsubmission)) { add_to_log($course->id, "assignment", "upload", "view.php?a=$assignment->id", "$assignment->id", $cm->id); + assignment_email_teachers($course, $cm, $assignment, $submission); print_heading(get_string('uploadedfile')); } else { notify(get_string("uploadnotregistered", "assignment", $newfile_name) ); diff --git a/mod/assignment/version.php b/mod/assignment/version.php index 41abc368e4..972f962d78 100644 --- a/mod/assignment/version.php +++ b/mod/assignment/version.php @@ -5,7 +5,7 @@ // This fragment is called by /admin/index.php //////////////////////////////////////////////////////////////////////////////// -$module->version = 2004111200; +$module->version = 2005010500; $module->requires = 2004091700; // Requires this Moodle version $module->cron = 60; -- 2.39.5