From 25093ba862142b06133f6bd99f89b17206d315d0 Mon Sep 17 00:00:00 2001 From: tzerafnx Date: Fri, 28 Feb 2020 16:19:50 -0500 Subject: [PATCH 01/21] add emailfrom option to form --- lang/en/reengagement.php | 4 ++++ lib.php | 3 +++ mod_form.php | 15 ++++++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lang/en/reengagement.php b/lang/en/reengagement.php index e1e16e3..3570c43 100644 --- a/lang/en/reengagement.php +++ b/lang/en/reengagement.php @@ -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 email 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'; +$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)'; diff --git a/lib.php b/lib.php index 0a19be6..c4fd884 100644 --- a/lib.php +++ b/lib.php @@ -35,6 +35,9 @@ define('REENGAGEMENT_RECIPIENT_MANAGER', 1); define('REENGAGEMENT_RECIPIENT_BOTH', 2); +define('REENGAGEMENT_EMAILFROM_SUPPORT', 0); +define('REENGAGEMENT_EMAILFROM_TEACHER', 1); + /** * Given an object containing all the necessary data, * (defined by the form in mod_form.php) this function diff --git a/mod_form.php b/mod_form.php index c09df90..42eb462 100644 --- a/mod_form.php +++ b/mod_form.php @@ -44,7 +44,7 @@ class mod_reengagement_mod_form extends moodleform_mod { */ public function definition() { - global $COURSE, $CFG; + global $COURSE, $CFG, $DB; $mform =& $this->_form; // Make sure completion and restriction is enabled. if (empty($CFG->enablecompletion) || empty($CFG->enableavailability)) { @@ -126,6 +126,19 @@ public function definition() { $mform->addRule('remindercount', get_string('err_numeric', 'form'), 'numeric', '', 'client'); $mform->addHelpButton('remindercount', 'remindercount', 'reengagement'); $mform->hideif('remindercount', 'emailuser', 'neq', REENGAGEMENT_EMAILUSER_TIME); + + // tk Add email from selector + $emailfromoptions = array(); + $emailfromoptions[REENGAGEMENT_EMAILFROM_SUPPORT] = get_string('emailfromsupport', 'reengagement'); + $emailfromoptions[REENGAGEMENT_EMAILFROM_TEACHER] = get_string('emailfromteacher', 'reengagement'); + $coursecontext = context_course::instance($COURSE->id); + $emailfromusers = get_enrolled_users($coursecontext, $withcapability='mod/reengagement:addinstance'); + foreach($emailfromusers as $emailfromuser) { + $emailfromoptions[$emailfromuser->id] = get_string('fullnamedisplay', '', $emailfromuser); + } + $mform->addElement('select', 'emailfrom', get_string('emailfrom', 'reengagement'), $emailfromoptions); + $mform->hideif('emailfrom', 'emailuser', 'eq', REENGAGEMENT_EMAILUSER_NEVER); + $mform->addHelpButton('emailfrom', 'emailfrom', 'reengagement'); $mform->addElement('text', 'emailsubject', get_string('emailsubject', 'reengagement'), array('size' => '64')); $mform->setType('emailsubject', PARAM_TEXT); From 88cefd7af37e1ecae008aadc1364512eb94e49d1 Mon Sep 17 00:00:00 2001 From: tzerafnx Date: Fri, 28 Feb 2020 17:23:29 -0500 Subject: [PATCH 02/21] add emailfrom field in db --- db/install.xml | 1 + db/upgrade.php | 13 +++++++++++++ version.php | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/db/install.xml b/db/install.xml index 74b7616..0791783 100644 --- a/db/install.xml +++ b/db/install.xml @@ -27,6 +27,7 @@ + diff --git a/db/upgrade.php b/db/upgrade.php index f8351af..209d088 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -178,5 +178,18 @@ function xmldb_reengagement_upgrade($oldversion=0) { upgrade_mod_savepoint(true, 2017102001, 'reengagement'); } + // Add emailfrom fields. + if ($oldversion < 2020022200) { + + $table = new xmldb_table('reengagement'); + $field = new xmldb_field('emailfrom', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + upgrade_mod_savepoint(true, 2020022200, 'reengagement'); + } + + return true; + return true; } \ No newline at end of file diff --git a/version.php b/version.php index a191477..2a677cf 100644 --- a/version.php +++ b/version.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2019091000; // The current module version. +$plugin->version = 2020022200; // The current module version. $plugin->requires = 2018111800; // Requires 3.6 $plugin->component = 'mod_reengagement'; $plugin->release = '3.6.3'; From 0f099ba18a3c2ebe558126173c2606ff5131cc99 Mon Sep 17 00:00:00 2001 From: tzerafnx Date: Wed, 4 Mar 2020 11:03:42 -0500 Subject: [PATCH 03/21] helper function to get emailfrom user when sending message --- lib.php | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/lib.php b/lib.php index c4fd884..73f9b21 100644 --- a/lib.php +++ b/lib.php @@ -549,16 +549,18 @@ function reengagement_email_user($reengagement, $inprogress) { * @param object $reengagement database record */ function reengagement_send_notification($userto, $subject, $messageplain, $messagehtml, $reengagement) { + $emailfrom = reengagement_get_emailfrom($reengagement); $eventdata = new \core\message\message(); $eventdata->courseid = $reengagement->courseid; $eventdata->modulename = 'reengagement'; - $eventdata->userfrom = core_user::get_support_user(); + $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'; @@ -983,3 +985,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 + global $DB; + $params = array('roleid'=>3,'contextid'=>$context->id); + $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(); +} From 5922ce9419f3e496faf6bbf1d99c8c28136c064a Mon Sep 17 00:00:00 2001 From: tzerafnx Date: Wed, 4 Mar 2020 15:06:53 -0500 Subject: [PATCH 04/21] add emailfrom user info to template variables --- lib.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib.php b/lib.php index 73f9b21..f51b4a7 100644 --- a/lib.php +++ b/lib.php @@ -583,6 +583,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, @@ -593,6 +595,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 From 0a6c180b2bbb413249bc62b4cfb9e2f111a3b80a Mon Sep 17 00:00:00 2001 From: tzerafnx Date: Wed, 4 Mar 2020 15:11:50 -0500 Subject: [PATCH 05/21] updated language to better match form --- lang/en/reengagement.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lang/en/reengagement.php b/lang/en/reengagement.php index 3570c43..5915fd3 100644 --- a/lang/en/reengagement.php +++ b/lang/en/reengagement.php @@ -60,7 +60,7 @@ $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 email from'; +$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'; $string['emailfromteacher'] = 'Default Teacher'; From b42efd677d944fdf8087620be464cd1e2df86556 Mon Sep 17 00:00:00 2001 From: tzerafnx Date: Wed, 4 Mar 2020 15:46:37 -0500 Subject: [PATCH 06/21] added notification type option to form --- lang/en/reengagement.php | 3 +++ lib.php | 3 +++ mod_form.php | 12 +++++++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lang/en/reengagement.php b/lang/en/reengagement.php index 5915fd3..d1e688a 100644 --- a/lang/en/reengagement.php +++ b/lang/en/reengagement.php @@ -92,6 +92,9 @@ $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['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.'; diff --git a/lib.php b/lib.php index f51b4a7..ee4fbbd 100644 --- a/lib.php +++ b/lib.php @@ -38,6 +38,9 @@ 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 diff --git a/mod_form.php b/mod_form.php index 42eb462..44cdab2 100644 --- a/mod_form.php +++ b/mod_form.php @@ -127,7 +127,7 @@ public function definition() { $mform->addHelpButton('remindercount', 'remindercount', 'reengagement'); $mform->hideif('remindercount', 'emailuser', 'neq', REENGAGEMENT_EMAILUSER_TIME); - // tk Add email from selector + // Add email from selector $emailfromoptions = array(); $emailfromoptions[REENGAGEMENT_EMAILFROM_SUPPORT] = get_string('emailfromsupport', 'reengagement'); $emailfromoptions[REENGAGEMENT_EMAILFROM_TEACHER] = get_string('emailfromteacher', 'reengagement'); @@ -139,11 +139,20 @@ public function definition() { $mform->addElement('select', 'emailfrom', get_string('emailfrom', 'reengagement'), $emailfromoptions); $mform->hideif('emailfrom', 'emailuser', 'eq', REENGAGEMENT_EMAILUSER_NEVER); $mform->addHelpButton('emailfrom', 'emailfrom', 'reengagement'); + + // Add notification type selector + $instantmessageoptions = array(); + $instantmessageoptions[REENGAGEMENT_NOTIFICATION_EMAIL] = get_string('notificationemail', 'reengagement'); + $instantmessageoptions[REENGAGEMENT_NOTIFICATION_IM] = get_string('notificationim', 'reengagement'); + $mform->addElement('select', 'instantmessage', get_string('notificationtype', 'reengagement'), $instantmessageoptions); + $mform->hideif('instantmessage', 'emailuser', 'eq', REENGAGEMENT_EMAILUSER_NEVER); + $mform->addHelpButton('instantmessage', 'notificationtype', 'reengagement'); $mform->addElement('text', 'emailsubject', get_string('emailsubject', 'reengagement'), array('size' => '64')); $mform->setType('emailsubject', PARAM_TEXT); $mform->addRule('emailsubject', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $mform->hideif('emailsubject', 'emailuser', 'eq', REENGAGEMENT_EMAILUSER_NEVER); + $mform->hideif('emailsubject', 'instantmessage', 'eq', REENGAGEMENT_NOTIFICATION_IM); $mform->addHelpButton('emailsubject', 'emailsubject', 'reengagement'); $mform->addElement('editor', 'emailcontent', get_string('emailcontent', 'reengagement'), null, null); $mform->setDefault('emailcontent', get_string('emailcontentdefaultvalue', 'reengagement')); @@ -156,6 +165,7 @@ public function definition() { $mform->setType('emailsubjectmanager', PARAM_TEXT); $mform->addRule('emailsubjectmanager', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $mform->hideif('emailsubjectmanager', 'emailuser', 'eq', REENGAGEMENT_EMAILUSER_NEVER); + $mform->hideif('emailsubjectmanager', 'instantmessage', 'eq', REENGAGEMENT_NOTIFICATION_IM); $mform->addHelpButton('emailsubjectmanager', 'emailsubjectmanager', 'reengagement'); $mform->addElement('editor', 'emailcontentmanager', get_string('emailcontentmanager', 'reengagement'), null, null); $mform->setDefault('emailcontentmanager', get_string('emailcontentmanagerdefaultvalue', 'reengagement')); From 73956cb603a9437b12190cd19d73d4e8f62d3ebf Mon Sep 17 00:00:00 2001 From: tzerafnx Date: Wed, 4 Mar 2020 16:00:20 -0500 Subject: [PATCH 07/21] added instantmessage field to db --- db/install.xml | 1 + db/upgrade.php | 12 +++++++----- version.php | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/db/install.xml b/db/install.xml index 0791783..d04bc64 100644 --- a/db/install.xml +++ b/db/install.xml @@ -28,6 +28,7 @@ + diff --git a/db/upgrade.php b/db/upgrade.php index 209d088..1e2167d 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -178,18 +178,20 @@ function xmldb_reengagement_upgrade($oldversion=0) { upgrade_mod_savepoint(true, 2017102001, 'reengagement'); } - // Add emailfrom fields. - if ($oldversion < 2020022200) { + // Add emailfrom and instantmessage fields. + if ($oldversion < 2020022202) { $table = new xmldb_table('reengagement'); $field = new xmldb_field('emailfrom', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); if (!$dbman->field_exists($table, $field)) { $dbman->add_field($table, $field); } - upgrade_mod_savepoint(true, 2020022200, 'reengagement'); + $field = new xmldb_field('instantmessage', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0'); + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + upgrade_mod_savepoint(true, 2020022202, 'reengagement'); } return true; - - return true; } \ No newline at end of file diff --git a/version.php b/version.php index 2a677cf..85c78f9 100644 --- a/version.php +++ b/version.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2020022200; // The current module version. +$plugin->version = 2020022202; // The current module version. $plugin->requires = 2018111800; // Requires 3.6 $plugin->component = 'mod_reengagement'; $plugin->release = '3.6.3'; From d2886fb873d44d2a096154867ef58e9a3b5f3c71 Mon Sep 17 00:00:00 2001 From: tzerafnx Date: Wed, 4 Mar 2020 16:03:03 -0500 Subject: [PATCH 08/21] cleaned up extra return --- db/upgrade.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/db/upgrade.php b/db/upgrade.php index 209d088..7ff0fce 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -190,6 +190,4 @@ function xmldb_reengagement_upgrade($oldversion=0) { } return true; - - return true; } \ No newline at end of file From 91da59fbdd142d4ad199a1b22738d53970497bcc Mon Sep 17 00:00:00 2001 From: tzerafnx Date: Wed, 4 Mar 2020 16:13:01 -0500 Subject: [PATCH 09/21] update reengagement_send_notification with instant message option --- lib.php | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/lib.php b/lib.php index ee4fbbd..f586892 100644 --- a/lib.php +++ b/lib.php @@ -553,23 +553,28 @@ function reengagement_email_user($reengagement, $inprogress) { */ function reengagement_send_notification($userto, $subject, $messageplain, $messagehtml, $reengagement) { $emailfrom = reengagement_get_emailfrom($reengagement); - $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); + //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); + } } From 1d6e410bff741c666227233323f4f6634245e645 Mon Sep 17 00:00:00 2001 From: tzerafnx Date: Wed, 4 Mar 2020 18:05:19 -0500 Subject: [PATCH 10/21] style fixes for Travis CI --- lib.php | 16 ++++++++-------- mod_form.php | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib.php b/lib.php index f51b4a7..58aaa44 100644 --- a/lib.php +++ b/lib.php @@ -1001,21 +1001,21 @@ function reengagement_checkstart($course, $cm, $reengagement) { */ function reengagement_get_emailfrom($reengagement) { $userid = $reengagement->emailfrom; - if($userid > 0){ + if ($userid > 0) { $context = context_course::instance($reengagement->course); - if($userid == 1){ //default teacher, get first teacher in course + if ($userid == 1) { // Default teacher, get first teacher in course. global $DB; - $params = array('roleid'=>3,'contextid'=>$context->id); + $params = array('roleid' => 3,'contextid' => $context->id); $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) ){ + + // 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 + + // If no default teacher, or selected teacher now lacks capability, return support user. return core_user::get_support_user(); } diff --git a/mod_form.php b/mod_form.php index 42eb462..09326c4 100644 --- a/mod_form.php +++ b/mod_form.php @@ -126,14 +126,14 @@ public function definition() { $mform->addRule('remindercount', get_string('err_numeric', 'form'), 'numeric', '', 'client'); $mform->addHelpButton('remindercount', 'remindercount', 'reengagement'); $mform->hideif('remindercount', 'emailuser', 'neq', REENGAGEMENT_EMAILUSER_TIME); - - // tk Add email from selector + + // Add emailfrom selector. $emailfromoptions = array(); $emailfromoptions[REENGAGEMENT_EMAILFROM_SUPPORT] = get_string('emailfromsupport', 'reengagement'); $emailfromoptions[REENGAGEMENT_EMAILFROM_TEACHER] = get_string('emailfromteacher', 'reengagement'); $coursecontext = context_course::instance($COURSE->id); - $emailfromusers = get_enrolled_users($coursecontext, $withcapability='mod/reengagement:addinstance'); - foreach($emailfromusers as $emailfromuser) { + $emailfromusers = get_enrolled_users($coursecontext, 'mod/reengagement:addinstance'); + foreach ($emailfromusers as $emailfromuser) { $emailfromoptions[$emailfromuser->id] = get_string('fullnamedisplay', '', $emailfromuser); } $mform->addElement('select', 'emailfrom', get_string('emailfrom', 'reengagement'), $emailfromoptions); From 9a4838a611832c3ba538c4119312c153c29c9865 Mon Sep 17 00:00:00 2001 From: tzerafnx Date: Wed, 4 Mar 2020 21:59:03 -0500 Subject: [PATCH 11/21] style fix for Travis CI --- lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib.php b/lib.php index 58aaa44..828593e 100644 --- a/lib.php +++ b/lib.php @@ -1005,7 +1005,7 @@ function reengagement_get_emailfrom($reengagement) { $context = context_course::instance($reengagement->course); if ($userid == 1) { // Default teacher, get first teacher in course. global $DB; - $params = array('roleid' => 3,'contextid' => $context->id); + $params = array('roleid' => 3, 'contextid' => $context->id); $userid = $DB->get_field('role_assignments', 'userid', $params); } $user = $userid ? core_user::get_user($userid) : null; From 3d46cbe19b4e8b0c46efa7bef3e2ef0c81aa6e7f Mon Sep 17 00:00:00 2001 From: tzerafnx Date: Thu, 5 Mar 2020 11:16:57 -0500 Subject: [PATCH 12/21] use postgres 9.5 with Travis CI --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index defb290..3070ace 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ services: addons: firefox: "47.0.1" - postgresql: "9.4" + postgresql: "9.5" apt: packages: - openjdk-8-jre-headless From 4013b50f51ccd1aa7f114903b399d06b82962599 Mon Sep 17 00:00:00 2001 From: tzerafnx Date: Thu, 5 Mar 2020 11:45:57 -0500 Subject: [PATCH 13/21] style fixes for Travis CI --- lib.php | 2 +- mod_form.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib.php b/lib.php index 3916634..e2e0ee7 100644 --- a/lib.php +++ b/lib.php @@ -553,7 +553,7 @@ function reengagement_email_user($reengagement, $inprogress) { */ function reengagement_send_notification($userto, $subject, $messageplain, $messagehtml, $reengagement) { $emailfrom = reengagement_get_emailfrom($reengagement); - //check instant message setting and verify we're sending to a real user, not third party + // 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 { diff --git a/mod_form.php b/mod_form.php index 60d71a1..e885801 100644 --- a/mod_form.php +++ b/mod_form.php @@ -139,8 +139,8 @@ public function definition() { $mform->addElement('select', 'emailfrom', get_string('emailfrom', 'reengagement'), $emailfromoptions); $mform->hideif('emailfrom', 'emailuser', 'eq', REENGAGEMENT_EMAILUSER_NEVER); $mform->addHelpButton('emailfrom', 'emailfrom', 'reengagement'); - - // Add notification type selector + + // Add notification type selector. $instantmessageoptions = array(); $instantmessageoptions[REENGAGEMENT_NOTIFICATION_EMAIL] = get_string('notificationemail', 'reengagement'); $instantmessageoptions[REENGAGEMENT_NOTIFICATION_IM] = get_string('notificationim', 'reengagement'); From b074b4b4383c9b98adc7ea7790c48f6ea50b5cce Mon Sep 17 00:00:00 2001 From: tzerafnx Date: Thu, 5 Mar 2020 11:55:11 -0500 Subject: [PATCH 14/21] added help string --- lang/en/reengagement.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lang/en/reengagement.php b/lang/en/reengagement.php index d1e688a..6529441 100644 --- a/lang/en/reengagement.php +++ b/lang/en/reengagement.php @@ -95,6 +95,7 @@ $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.'; From da7da56b11128d82ab33ac6f655cbb63e8a40cd8 Mon Sep 17 00:00:00 2001 From: Nicholas Stefanski Date: Thu, 29 Sep 2022 10:54:29 -0500 Subject: [PATCH 15/21] REENGAGEMENT_EMAILFROM_TEACHER definition changed value to -1 and used in reengagement_get_emailfrom function --- lib.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib.php b/lib.php index e2e0ee7..e22f892 100644 --- a/lib.php +++ b/lib.php @@ -36,7 +36,7 @@ define('REENGAGEMENT_RECIPIENT_BOTH', 2); define('REENGAGEMENT_EMAILFROM_SUPPORT', 0); -define('REENGAGEMENT_EMAILFROM_TEACHER', 1); +define('REENGAGEMENT_EMAILFROM_TEACHER', -1); define('REENGAGEMENT_NOTIFICATION_EMAIL', 0); define('REENGAGEMENT_NOTIFICATION_IM', 1); @@ -1009,9 +1009,9 @@ function reengagement_checkstart($course, $cm, $reengagement) { */ function reengagement_get_emailfrom($reengagement) { $userid = $reengagement->emailfrom; - if ($userid > 0) { + if ($userid != 0) { $context = context_course::instance($reengagement->course); - if ($userid == 1) { // Default teacher, get first teacher in course. + if ($userid == REENGAGEMENT_EMAILFROM_TEACHER) { // Default teacher, get first teacher in course. global $DB; $params = array('roleid' => 3, 'contextid' => $context->id); $userid = $DB->get_field('role_assignments', 'userid', $params); From 8e82fa920ff91f1d8358033b85d4b7eff885fb55 Mon Sep 17 00:00:00 2001 From: Nicholas Stefanski Date: Thu, 29 Sep 2022 10:56:29 -0500 Subject: [PATCH 16/21] use sentence case --- lang/en/reengagement.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lang/en/reengagement.php b/lang/en/reengagement.php index 6529441..e6b81eb 100644 --- a/lang/en/reengagement.php +++ b/lang/en/reengagement.php @@ -62,8 +62,8 @@ $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'; -$string['emailfromteacher'] = 'Default Teacher'; +$string['emailfromsupport'] = 'Support user'; +$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)'; From 6462a857a29d39a2203e0a61e49c8e49f7be831d Mon Sep 17 00:00:00 2001 From: Nicholas Stefanski Date: Thu, 29 Sep 2022 10:58:58 -0500 Subject: [PATCH 17/21] changed comment using -1 for default teacher since userid 1 could in theory be a valid teacher --- db/install.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/install.xml b/db/install.xml index d04bc64..6969aa7 100644 --- a/db/install.xml +++ b/db/install.xml @@ -27,7 +27,7 @@ - + From 01b99b1c3c3c2ec8b5fd22d7ae18e77fae849ffd Mon Sep 17 00:00:00 2001 From: Nicholas Stefanski Date: Thu, 29 Sep 2022 11:02:01 -0500 Subject: [PATCH 18/21] Update version.php --- version.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.php b/version.php index 85c78f9..a8ab5af 100644 --- a/version.php +++ b/version.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2020022202; // The current module version. +$plugin->version = 2022092900; // The current module version. $plugin->requires = 2018111800; // Requires 3.6 $plugin->component = 'mod_reengagement'; $plugin->release = '3.6.3'; From 2ada7aa4975630c814b35867e9eeb503c2788a8d Mon Sep 17 00:00:00 2001 From: Nicholas Stefanski Date: Fri, 30 Sep 2022 15:12:35 -0500 Subject: [PATCH 19/21] change version for emailfrom and instantmessage --- db/upgrade.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/upgrade.php b/db/upgrade.php index 1e2167d..99e40fc 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -179,7 +179,7 @@ function xmldb_reengagement_upgrade($oldversion=0) { } // Add emailfrom and instantmessage fields. - if ($oldversion < 2020022202) { + if ($oldversion < 2022092900) { $table = new xmldb_table('reengagement'); $field = new xmldb_field('emailfrom', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0'); @@ -194,4 +194,4 @@ function xmldb_reengagement_upgrade($oldversion=0) { } return true; -} \ No newline at end of file +} From e2b51e0eba92b8f3f180a69d0191945fec51bdd1 Mon Sep 17 00:00:00 2001 From: Nicholas Stefanski Date: Fri, 30 Sep 2022 16:07:19 -0500 Subject: [PATCH 20/21] add fields to sql query --- lib.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib.php b/lib.php index e22f892..e020203 100644 --- a/lib.php +++ b/lib.php @@ -255,7 +255,8 @@ function reengagement_crontask() { r.thirdpartyemails, r.emailcontentmanager, r.emailcontentmanagerformat, r.emailsubjectmanager, r.emailcontentthirdparty, r.emailcontentthirdpartyformat, r.emailsubjectthirdparty, r.emailuser, r.name, r.suppresstarget, r.remindercount, c.shortname as courseshortname, - c.fullname as coursefullname, c.id as courseid, r.emailrecipient, r.emaildelay + c.fullname as coursefullname, c.id as courseid, r.emailrecipient, r.emaildelay, + r.emailfrom, r.instantmessage FROM {reengagement} r INNER JOIN {course_modules} cm ON cm.instance = r.id INNER JOIN {course} c ON cm.course = c.id From e822522ae7e2dc031cd1156053d25f2646a285e0 Mon Sep 17 00:00:00 2001 From: Nicholas Stefanski Date: Mon, 3 Oct 2022 11:39:54 -0500 Subject: [PATCH 21/21] get teachers by capability instead of looking for the specific teacher role, look for all users enrolled in the course with the capability to add a reengagement activity --- lib.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib.php b/lib.php index e020203..815c3f8 100644 --- a/lib.php +++ b/lib.php @@ -1011,17 +1011,19 @@ function reengagement_checkstart($course, $cm, $reengagement) { function reengagement_get_emailfrom($reengagement) { $userid = $reengagement->emailfrom; if ($userid != 0) { - $context = context_course::instance($reengagement->course); + $context = context_course::instance($reengagement->courseid); if ($userid == REENGAGEMENT_EMAILFROM_TEACHER) { // Default teacher, get first teacher in course. - global $DB; - $params = array('roleid' => 3, 'contextid' => $context->id); - $userid = $DB->get_field('role_assignments', 'userid', $params); - } - $user = $userid ? core_user::get_user($userid) : null; + $users = get_enrolled_users($context, 'mod/reengagement:addinstance', 0, 'u.*', '', 0, 1); + if ($users && $user = reset($users)) { + return $user; + } + } else { + $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; + // Check selected teacher still has capability. + if ($user && has_capability('mod/reengagement:addinstance', $context, $user) ) { + return $user; + } } }