From bec1c29d84a4b6761d139d17935c9f026e7e0450 Mon Sep 17 00:00:00 2001 From: "Andrew Davis (andyjdavis)" Date: Mon, 22 Aug 2011 09:51:17 +0800 Subject: [PATCH 1/4] MDL-22232 messaging: reimplementing support for "emailstop" in 2.0 stable --- lang/en/message.php | 2 ++ lib/messagelib.php | 34 +++++++++++++++++++--------------- message/edit.php | 16 ++++++++++++++++ 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/lang/en/message.php b/lang/en/message.php index fa805a3bbf3b5..6ec572f2be073 100644 --- a/lang/en/message.php +++ b/lang/en/message.php @@ -43,6 +43,8 @@ $string['context'] = 'context'; $string['couldnotfindpreference'] = 'Could not load preference {$a}. Does the component and name you supplied to message_send() match a row in message_providers? Message providers must appear in the database so users can configure how they will be notified when they receive messages.'; $string['deletemessagesdays'] = 'Number of days before old messages are automatically deleted'; +$string['disableall'] = 'Temporarily disable notifications'; +$string['disableall_help'] = 'Temporarily disable all notifications except those marked as "forced" by the site administrator'; $string['disabled'] = 'Messaging is disabled on this site'; $string['discussion'] = 'Discussion'; $string['editmymessage'] = 'Messaging'; diff --git a/lib/messagelib.php b/lib/messagelib.php index c457ece193e77..b3ec8139f928f 100644 --- a/lib/messagelib.php +++ b/lib/messagelib.php @@ -109,21 +109,25 @@ function message_send($eventdata) { $savemessage->timecreated = time(); - // Find out what processors are defined currently - // When a user doesn't have settings none gets return, if he doesn't want contact "" gets returned - $preferencename = 'message_provider_'.$eventdata->component.'_'.$eventdata->name.'_'.$userstate; - - $processor = get_user_preferences($preferencename, null, $eventdata->userto->id); - if ($processor == NULL) { //this user never had a preference, save default - if (!message_set_default_message_preferences($eventdata->userto)) { - print_error('cannotsavemessageprefs', 'message'); - } - $processor = get_user_preferences($preferencename, NULL, $eventdata->userto->id); - if (empty($processor)) { - //MDL-25114 They supplied an $eventdata->component $eventdata->name combination which doesn't - //exist in the message_provider table - $preferrormsg = get_string('couldnotfindpreference', 'message', $preferencename); - throw new coding_exception($preferrormsg,'blah'); + //only look for their preference if notifications are not disabled + $processor = 'none'; + if (!$eventdata->userto->emailstop) { + // Find out what processors are defined currently + // When a user doesn't have settings none gets return, if he doesn't want contact "" gets returned + $preferencename = 'message_provider_'.$eventdata->component.'_'.$eventdata->name.'_'.$userstate; + + $processor = get_user_preferences($preferencename, null, $eventdata->userto->id); + if ($processor == NULL) { //this user never had a preference, save default + if (!message_set_default_message_preferences($eventdata->userto)) { + print_error('cannotsavemessageprefs', 'message'); + } + $processor = get_user_preferences($preferencename, NULL, $eventdata->userto->id); + if (empty($processor)) { + //MDL-25114 They supplied an $eventdata->component $eventdata->name combination which doesn't + //exist in the message_provider table + $preferrormsg = get_string('couldnotfindpreference', 'message', $preferencename); + throw new coding_exception($preferrormsg,'blah'); + } } } diff --git a/message/edit.php b/message/edit.php index 4943e5d4932e7..a032dd9f4f3f2 100644 --- a/message/edit.php +++ b/message/edit.php @@ -27,6 +27,7 @@ $userid = optional_param('id', $USER->id, PARAM_INT); // user id $course = optional_param('course', SITEID, PARAM_INT); // course id (defaults to Site) +$disableall = optional_param('disableall', 0, PARAM_BOOL); //disable all of this user's notifications $url = new moodle_url('/message/edit.php'); if ($userid !== $USER->id) { @@ -96,6 +97,17 @@ /// Save new preferences if data was submitted if (($form = data_submitted()) && confirm_sesskey()) { + //only update the user's "emailstop" if its actually changed + if ( $user->emailstop != $disableall ) { + $user->emailstop = $disableall; + //create a new user object just in case any other changes have been + //made to the user object that we don't want to save + $usertoupdate = new stdClass(); + $usertoupdate->id = $user->id; + $usertoupdate->emailstop = $user->emailstop; + $DB->update_record('user', $usertoupdate); + } + $preferences = array(); $possiblestates = array('loggedin', 'loggedoff'); @@ -239,6 +251,10 @@ } } echo ''; + +$disableallcheckbox = $OUTPUT->help_icon('disableall', 'message') . get_string('disableall', 'message') . html_writer::checkbox('disableall', 1, $user->emailstop, '', array('class'=>'disableallcheckbox')); +echo html_writer::nonempty_tag('div', $disableallcheckbox, array('class'=>'disableall')); + echo ''; /// Show all the message processors From 87a4bba39c2e84a17a947294a704f6e659bb6fa7 Mon Sep 17 00:00:00 2001 From: "Andrew Davis (andyjdavis)" Date: Fri, 26 Aug 2011 15:59:31 +0800 Subject: [PATCH 2/4] MDL-22232 messaging: miscelaneous fixes after integration review --- lib/db/upgrade.php | 11 ++++++++++- message/edit.php | 7 +------ version.php | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 287977431e6c3..8eb24e19e1bb4 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -6119,6 +6119,16 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2011033003.09); } + if ($oldversion < 2011033004.04) { + //preference not required since 2.0 + $DB->delete_records('user_preferences', array('name'=>'message_showmessagewindow')); + + //re-introducing emailstop. check that its turned off so people dont suddenly stop getting notifications + $DB->set_field('user', 'emailstop', 0); + + upgrade_main_savepoint(true, 2011033004.04); + } + return true; } @@ -6126,4 +6136,3 @@ function xmldb_main_upgrade($oldversion) { // 1/ drop block_pinned_old table here and in install.xml // 2/ drop block_instance_old table here and in install.xml -//TODO: AFTER 2.0 remove the column user->emailstop and the user preference "message_showmessagewindow" diff --git a/message/edit.php b/message/edit.php index a032dd9f4f3f2..06ddac76654bb 100644 --- a/message/edit.php +++ b/message/edit.php @@ -100,12 +100,7 @@ //only update the user's "emailstop" if its actually changed if ( $user->emailstop != $disableall ) { $user->emailstop = $disableall; - //create a new user object just in case any other changes have been - //made to the user object that we don't want to save - $usertoupdate = new stdClass(); - $usertoupdate->id = $user->id; - $usertoupdate->emailstop = $user->emailstop; - $DB->update_record('user', $usertoupdate); + $DB->set_field('user', 'emailstop', $user->emailstop, array("id"=>$user->id)); } $preferences = array(); diff --git a/version.php b/version.php index 8d2673ab9a526..42a8646476533 100644 --- a/version.php +++ b/version.php @@ -30,7 +30,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2011033004.03; // 20110330 = branching date YYYYMMDD - do not modify! +$version = 2011033004.04; // 20110330 = branching date YYYYMMDD - do not modify! // RR = release version - do not change in weeklies // .XX = incremental changes From b15713760e2d5616f22549b70fd509e9344bae12 Mon Sep 17 00:00:00 2001 From: "Andrew Davis (andyjdavis)" Date: Mon, 29 Aug 2011 15:37:30 +0800 Subject: [PATCH 3/4] MDL-22232 messaging: added some Javascript to the messaging preferences screen to make it awesomer --- message/edit.php | 7 ++++++- message/module.js | 26 +++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/message/edit.php b/message/edit.php index 06ddac76654bb..6f418850754f4 100644 --- a/message/edit.php +++ b/message/edit.php @@ -68,6 +68,7 @@ $PAGE->set_context($personalcontext); $PAGE->set_pagelayout('course'); +$PAGE->requires->js_init_call('M.core_message.init_editsettings'); // check access control if ($user->id == $USER->id) { @@ -229,6 +230,10 @@ $providername = get_string('messageprovider:'.$provider->name, $provider->component); echo ''.$providername.''."\n"; + $disabled = ''; + if ($user->emailstop) { + $disabled = 'disabled="disabled"'; + } foreach (array('loggedin', 'loggedoff') as $state){ $state_res = get_string($state.'description', 'message'); echo ''.$state_res.''."\n"; @@ -240,7 +245,7 @@ } else { $checked = $preferences->{$provider->component.'_'.$provider->name.'_'.$state}[$processor->name]==1?" checked=\"checked\"":""; } - echo ''."\n"; + echo ''."\n"; } echo ''."\n"; } diff --git a/message/module.js b/message/module.js index e0627d0cc6552..cb2576401a0fe 100644 --- a/message/module.js +++ b/message/module.js @@ -42,4 +42,28 @@ M.core_message.init_notification = function(Y, title, content, url) { return false; }, o); }); -}; \ No newline at end of file +}; + +M.core_message.init_editsettings = function(Y) { + var editsettings = { + + init : function() { + var disableall = Y.one(".disableallcheckbox"); + disableall.on('change', editsettings.changeState); + //disableall.simulate("change"); simulate() not available in this version of YUI + }, + + changeState : function(e) { + Y.all('.notificationpreference').each(function(node) { + var disabled = e.target.get('checked'); + + node.removeAttribute('disabled'); + if (disabled) { + node.setAttribute('disabled', 1) + } + }, this); + } + } + + editsettings.init(); +} \ No newline at end of file From e186fee5e34429f2bf8092871446bcb4109615e5 Mon Sep 17 00:00:00 2001 From: "Andrew Davis (andyjdavis)" Date: Thu, 1 Sep 2011 16:47:39 +0800 Subject: [PATCH 4/4] MDL-22232 messaging: updated upgrade code to reduce server load during upgrade --- lib/db/upgrade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 8eb24e19e1bb4..0891bf0d00185 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -6124,7 +6124,7 @@ function xmldb_main_upgrade($oldversion) { $DB->delete_records('user_preferences', array('name'=>'message_showmessagewindow')); //re-introducing emailstop. check that its turned off so people dont suddenly stop getting notifications - $DB->set_field('user', 'emailstop', 0); + $DB->set_field('user', 'emailstop', 0, array('emailstop' => 1)); upgrade_main_savepoint(true, 2011033004.04); }