-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Emailfrom #63
base: MOODLE_400_STABLE
Are you sure you want to change the base?
Emailfrom #63
Changes from 15 commits
25093ba
88cefd7
0f099ba
5922ce9
0a6c180
b42efd6
73956cb
d2886fb
91da59f
1d6e410
9a4838a
3d46cbe
13b00ca
4013b50
b074b4b
da7da56
8e82fa9
6462a85
01b99b1
2ada7aa
e2b51e0
e822522
fddb0b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,10 @@ | |
$string['emailcontentmanagerdefaultvalue'] = 'This is a reminder notification from course %courseshortname%, regarding user %userfirstname% %userlastname%.'; | ||
$string['emaildelay'] = 'Notification delay'; | ||
$string['emaildelay_help'] = 'When module is set to notify users "after delay", this setting controls how long the delay is.'; | ||
$string['emailfrom'] = 'Send notification from'; | ||
$string['emailfrom_help'] = 'The user to send the message from, pending permissions check. Default teacher is the first teacher in the course, will send from support user if no teachers are found.'; | ||
$string['emailfromsupport'] = 'Support User'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moodle uses sentance case. Support User -> Support user. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed |
||
$string['emailfromteacher'] = 'Default Teacher'; | ||
$string['emailrecipient'] = 'Notify recipient(s)'; | ||
$string['emailrecipient_help'] = 'When a notification needs to be sent out to prompt a user\'s re-engagement with the course, this setting controls if a notification is sent to the user, their manager(s), or both.'; | ||
$string['emailsubject'] = 'Notification subject (User)'; | ||
|
@@ -88,6 +92,10 @@ | |
$string['nochangenoaccess'] = 'No change (user has not accessed course)'; | ||
$string['noemailattimex'] = 'Message scheduled for {$a} will not be sent because you have completed the target activity'; | ||
$string['nosuppresstarget'] = 'No target activity selected'; | ||
$string['notificationemail'] = 'Email'; | ||
$string['notificationim'] = 'Instant message'; | ||
$string['notificationtype'] = 'Notification type'; | ||
$string['notificationtype_help'] = 'Send notifications as an email or as a Moodle instant message. Third party notifications always send as emails.'; | ||
$string['oncompletion'] = 'On reengagement completion'; | ||
$string['receiveemailattimex'] = 'Message will be sent on {$a}.'; | ||
$string['receiveemailattimexunless'] = 'Message will be sent on {$a} unless you complete target activity.'; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,12 @@ | |
define('REENGAGEMENT_RECIPIENT_MANAGER', 1); | ||
define('REENGAGEMENT_RECIPIENT_BOTH', 2); | ||
|
||
define('REENGAGEMENT_EMAILFROM_SUPPORT', 0); | ||
define('REENGAGEMENT_EMAILFROM_TEACHER', 1); | ||
|
||
define('REENGAGEMENT_NOTIFICATION_EMAIL', 0); | ||
define('REENGAGEMENT_NOTIFICATION_IM', 1); | ||
|
||
/** | ||
* Given an object containing all the necessary data, | ||
* (defined by the form in mod_form.php) this function | ||
|
@@ -546,22 +552,29 @@ function reengagement_email_user($reengagement, $inprogress) { | |
* @param object $reengagement database record | ||
*/ | ||
function reengagement_send_notification($userto, $subject, $messageplain, $messagehtml, $reengagement) { | ||
$eventdata = new \core\message\message(); | ||
$eventdata->courseid = $reengagement->courseid; | ||
$eventdata->modulename = 'reengagement'; | ||
$eventdata->userfrom = core_user::get_support_user(); | ||
$eventdata->userto = $userto; | ||
$eventdata->subject = $subject; | ||
$eventdata->fullmessage = $messageplain; | ||
$eventdata->fullmessageformat = FORMAT_HTML; | ||
$eventdata->fullmessagehtml = $messagehtml; | ||
$eventdata->smallmessage = $subject; | ||
|
||
// Required for messaging framework | ||
$eventdata->name = 'mod_reengagement'; | ||
$eventdata->component = 'mod_reengagement'; | ||
|
||
return message_send($eventdata); | ||
$emailfrom = reengagement_get_emailfrom($reengagement); | ||
// Check instant message setting and verify we're sending to a real user, not third party. | ||
if ($reengagement->instantmessage == REENGAGEMENT_NOTIFICATION_IM && $userto->id > 0) { | ||
return message_post_message($emailfrom, $userto, $messagehtml, FORMAT_HTML); | ||
} else { | ||
$eventdata = new \core\message\message(); | ||
$eventdata->courseid = $reengagement->courseid; | ||
$eventdata->modulename = 'reengagement'; | ||
$eventdata->userfrom = $emailfrom; | ||
$eventdata->userto = $userto; | ||
$eventdata->subject = $subject; | ||
$eventdata->fullmessage = $messageplain; | ||
$eventdata->fullmessageformat = FORMAT_HTML; | ||
$eventdata->fullmessagehtml = $messagehtml; | ||
$eventdata->smallmessage = $subject; | ||
$eventdata->replyto = $emailfrom->email; | ||
|
||
// Required for messaging framework | ||
$eventdata->name = 'mod_reengagement'; | ||
$eventdata->component = 'mod_reengagement'; | ||
|
||
return message_send($eventdata); | ||
} | ||
} | ||
|
||
|
||
|
@@ -578,6 +591,8 @@ function reengagement_template_variables($reengagement, $inprogress, $user) { | |
|
||
require_once($CFG->dirroot.'/user/profile/lib.php'); | ||
|
||
$emailfrom = reengagement_get_emailfrom($reengagement); | ||
|
||
$templatevars = array( | ||
'/%courseshortname%/' => $reengagement->courseshortname, | ||
'/%coursefullname%/' => $reengagement->coursefullname, | ||
|
@@ -588,6 +603,10 @@ function reengagement_template_variables($reengagement, $inprogress, $user) { | |
'/%usercity%/' => $user->city, | ||
'/%userinstitution%/' => $user->institution, | ||
'/%userdepartment%/' => $user->department, | ||
'/%fromfirstname%/' => $emailfrom->firstname, | ||
'/%fromlastname%/' => $emailfrom->lastname, | ||
'/%fromid%/' => $emailfrom->id, | ||
'/%fromemail%/' => $emailfrom->email, | ||
); | ||
// Add the users course groups as a template item. | ||
$groups = $DB->get_records_sql_menu("SELECT g.id, g.name | ||
|
@@ -980,3 +999,31 @@ function reengagement_checkstart($course, $cm, $reengagement) { | |
} | ||
return $output; | ||
} | ||
|
||
/** | ||
* Check that emailfrom user has capability to add reengagments, | ||
* otherwise return support user | ||
* | ||
* @param object $reengagement | ||
* @return object $user | ||
*/ | ||
function reengagement_get_emailfrom($reengagement) { | ||
$userid = $reengagement->emailfrom; | ||
if ($userid > 0) { | ||
$context = context_course::instance($reengagement->course); | ||
if ($userid == 1) { // Default teacher, get first teacher in course. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. better to use something like is siteadmin() style code - userid ===1 might not always be the siteadmin. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be the variable REENGAGEMENT_EMAILFROM_TEACHER, but I take your point that the user with id 1 may not be the siteadmin, so I'm changing the value for default teacher to -1, 0 is still the support user, and then any integer above 0 will be the actual user. |
||
global $DB; | ||
$params = array('roleid' => 3, 'contextid' => $context->id); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hard-coded roleid - this should be a site-level setting for re-engagement that allows the admin to select a role that is used for teaching staff or better still, use a has_capability check instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in fact - it would be better to use the get_course_contacts() style handling here with the $CFG->coursecontact settings instead of hard-coding this to a specific role. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed this to get_enrolled_users() with a permissions check for 'mod/reengagement:addinstance' |
||
$userid = $DB->get_field('role_assignments', 'userid', $params); | ||
} | ||
$user = $userid ? core_user::get_user($userid) : null; | ||
|
||
// Check selected teacher still has capability. | ||
if ($user && has_capability('mod/reengagement:addinstance', $context, $user) ) { | ||
return $user; | ||
} | ||
} | ||
|
||
// If no default teacher, or selected teacher now lacks capability, return support user. | ||
return core_user::get_support_user(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it makes me nervous to see xmldb files changed that don't include a version bump, it makes me wonder if this is hand-rolled or if you have used xmldb editor - can you please make sure you have used xmldb editor to add these fields to the install.xml file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Dan,
I used XMLDB editor but my dev site is not connected to the github repo, so I had to copy and paste the updated file from there to here. I don't have a lot of experience with the XMLDB editor so I'm not sure how to do it in a better way, hope that clears things up?