From ad6919e3ec01f671f83e8e5953228cdbbe7ab665 Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Mon, 26 Jun 2017 10:43:14 +1200 Subject: [PATCH] Add new capability to control who gets warning emails. --- classes/add_warning_form.php | 2 +- classes/task/notify.php | 16 +++++++++++----- db/access.php | 12 ++++++++++++ lang/en/attendance.php | 1 + version.php | 2 +- 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/classes/add_warning_form.php b/classes/add_warning_form.php index a8682a2..f337ce8 100644 --- a/classes/add_warning_form.php +++ b/classes/add_warning_form.php @@ -75,7 +75,7 @@ class mod_attendance_add_warning_form extends moodleform { $mform->setType('emailcontent', PARAM_RAW); $mform->addHelpButton('emailcontent', 'emailcontent', 'mod_attendance'); - $users = get_users_by_capability(context_course::instance($COURSE->id), 'mod/attendance:viewreports'); + $users = get_users_by_capability(context_course::instance($COURSE->id), 'mod/attendance:warningemails'); $options = array(); foreach ($users as $user) { $options[$user->id] = fullname($user); diff --git a/classes/task/notify.php b/classes/task/notify.php index 01531b1..a5a8a3c 100644 --- a/classes/task/notify.php +++ b/classes/task/notify.php @@ -80,12 +80,18 @@ class notify extends \core\task\scheduled_task { if (!empty($record->thirdpartyemails)) { $sendto = explode(',', $record->thirdpartyemails); $record->percent = round($record->percent * 100)."%"; + $context = context_module::instance($record->cmid); foreach ($sendto as $senduser) { - if (empty($thirdpartynotifications[$senduser])) { - $thirdpartynotifications[$senduser] = array(); - } - if (!isset($thirdpartynotifications[$senduser][$record->aid.'_'.$record->userid])) { - $thirdpartynotifications[$senduser][$record->aid.'_'.$record->userid] = get_string('thirdpartyemailtext', 'attendance', $record); + // Check user is allowed to receive warningemails. + if (has_capability('mod/attendance:warningemails', $context, $senduser)) { + if (empty($thirdpartynotifications[$senduser])) { + $thirdpartynotifications[$senduser] = array(); + } + if (!isset($thirdpartynotifications[$senduser][$record->aid . '_' . $record->userid])) { + $thirdpartynotifications[$senduser][$record->aid . '_' . $record->userid] = get_string('thirdpartyemailtext', 'attendance', $record); + } + } else { + mtrace("user".$senduser. "does not have capablity in cm".$record->cmid); } } } diff --git a/db/access.php b/db/access.php index 25a2bf0..22841ed 100644 --- a/db/access.php +++ b/db/access.php @@ -141,4 +141,16 @@ $capabilities = array( 'manager' => CAP_ALLOW ) ), + // Users that can receive extra warning e-mails. + 'mod/attendance:warningemails' => array( + 'riskbitmask' => RISK_DATALOSS, + + 'captype' => 'write', + 'contextlevel' => CONTEXT_MODULE, + 'archetypes' => array( + 'teacher' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, + 'manager' => CAP_ALLOW + ) + ) ); diff --git a/lang/en/attendance.php b/lang/en/attendance.php index a69e975..a80554a 100644 --- a/lang/en/attendance.php +++ b/lang/en/attendance.php @@ -52,6 +52,7 @@ $string['attendance:takeattendances'] = 'Taking Attendances'; $string['attendance:view'] = 'Viewing Attendances'; $string['attendance:viewreports'] = 'Viewing Reports'; $string['attendance:viewsummaryreports'] = 'View course summary reports'; +$string['attendance:warningemails'] = 'Can be subscribed to emails with at-risk users'; $string['attendance_already_submitted'] = 'You may not self register attendance that has already been set.'; $string['attendancedata'] = 'Attendance data'; $string['attendanceforthecourse'] = 'Attendance for the course'; diff --git a/version.php b/version.php index a7af682..7bbd407 100644 --- a/version.php +++ b/version.php @@ -23,7 +23,7 @@ */ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2016121315; +$plugin->version = 2016121316; $plugin->requires = 2016111800; $plugin->release = '3.2.14'; $plugin->maturity = MATURITY_STABLE;