Skip to content
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

Add possibility to not send emails for users that have emailstop=1 #173

Open
wants to merge 1 commit into
base: MOODLE_405_STABLE
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<FIELD NAME="remindercount" TYPE="int" LENGTH="3" NOTNULL="true" DEFAULT="1" SEQUENCE="false" COMMENT="how many times to send the email"/>
<FIELD NAME="suppresstarget" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="ID of module that, if completed, should prevent an email being sent out."/>
<FIELD NAME="emaildelay" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="604800" SEQUENCE="false" COMMENT="Time setting related to email"/>
<FIELD NAME="respectemailstop" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Should the email be suppressed for user that has emailstop preference set to true"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
Expand Down
11 changes: 11 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,16 @@ function xmldb_reengagement_upgrade($oldversion=0) {
upgrade_mod_savepoint(true, 2017102001, 'reengagement');
}

if ($oldversion < 2024091800) {
//Define new field to suppress email for user that has emailstop preference set to true
$table = new xmldb_table('reengagement');
$field = new xmldb_field('respectemailstop', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

upgrade_mod_savepoint(true, 2024091800, 'reengagement');
}

return true;
}
4 changes: 4 additions & 0 deletions lang/en/reengagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@
* Reset completion date by course access - For adjusting the reengagement completion date based on the first access to this course.';
$string['seconds'] = 'Seconds';

$string['respectemailstop'] = "Suppress notification for those users that have 'emailstop' set to true";
$string['respectemailstop_help'] = "This option instructs the activity to suppress notifications for those users that have 'emailstop' preference set to true";


$string['privacy:metadata:reengagement'] = 'Reengagement ID';
$string['privacy:metadata:userid'] = 'User id this record relates to';
$string['privacy:metadata:completiontime'] = 'When this module will be complete';
Expand Down
7 changes: 7 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,13 @@ function reengagement_email_user($reengagement, $inprogress) {
// User has been deleted - don't send an e-mail.
return true;
}
if (!empty($reengagement->respectemailstop) && !empty($user->emailstop)) {
//User has "emailstop" preference set to true
//Don't send
debugging('', DEBUG_DEVELOPER) && mtrace('Reengagement modules: User:'.$user->id.
' has emailstop preference set to true, Email not sent');
return true;
}
if (!empty($reengagement->suppresstarget)) {
$targetcomplete = reengagement_check_target_completion($user->id, $reengagement->suppresstarget);
if ($targetcomplete) {
Expand Down
4 changes: 4 additions & 0 deletions mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ public function definition() {
$mform->hideif('suppresstarget', 'suppressemail', 'notchecked');
$mform->addHelpbutton('suppresstarget', 'suppresstarget', 'reengagement');

$mform->addElement('advcheckbox', 'respectemailstop', get_string('respectemailstop', 'reengagement'));
$mform->addHelpbutton('respectemailstop', 'respectemailstop', 'reengagement');


// Add standard elements, common to all modules.
$this->standard_coursemodule_elements();
if ($mform->elementExists('completion')) {
Expand Down
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2024081300; // The current module version.
$plugin->release = 2023020804;
$plugin->version = 2024091800; // The current module version.
$plugin->release = 2024091800;
$plugin->requires = 2024081000; // Requires 4.5.
$plugin->component = 'mod_reengagement';
$plugin->maturity = MATURITY_STABLE;
Expand Down