Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merged branch 'MDL-22232_easier_turn_off_notifications_20' from git:/…

…/github.com/andyjdavis/moodle.git with conflict resolution
  • Loading branch information...
commit 62920e80bace2288de29bd5d01901df1d745b56c 2 parents 5fbc147 + e186fee
@samhemelryk samhemelryk authored
View
2  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';
View
11 lib/db/upgrade.php
@@ -6150,8 +6150,17 @@ function xmldb_main_upgrade($oldversion) {
}
+ if ($oldversion < 2011033004.09) {
+ //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, array('emailstop' => 1));
+
+ upgrade_main_savepoint(true, 2011033004.09);
+ }
+
return true;
}
-//TODO: AFTER 2.0 remove the column user->emailstop and the user preference "message_showmessagewindow"
View
34 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');
+ }
}
}
View
18 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) {
@@ -67,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) {
@@ -96,6 +98,12 @@
/// 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;
+ $DB->set_field('user', 'emailstop', $user->emailstop, array("id"=>$user->id));
+ }
+
$preferences = array();
$possiblestates = array('loggedin', 'loggedoff');
@@ -222,6 +230,10 @@
$providername = get_string('messageprovider:'.$provider->name, $provider->component);
echo '<tr><th align="right">'.$providername.'</th><td colspan="'.$number_procs.'"></td></tr>'."\n";
+ $disabled = '';
+ if ($user->emailstop) {
+ $disabled = 'disabled="disabled"';
+ }
foreach (array('loggedin', 'loggedoff') as $state){
$state_res = get_string($state.'description', 'message');
echo '<tr><td align="right">'.$state_res.'</td>'."\n";
@@ -233,12 +245,16 @@
} else {
$checked = $preferences->{$provider->component.'_'.$provider->name.'_'.$state}[$processor->name]==1?" checked=\"checked\"":"";
}
- echo '<td align="center"><input type="checkbox" name="'.$provider->component.'_'.$provider->name.'_'.$state.'['.$processor->name.']" '.$checked.' /></td>'."\n";
+ echo '<td align="center"><input type="checkbox" '.$disabled.' class="notificationpreference" name="'.$provider->component.'_'.$provider->name.'_'.$state.'['.$processor->name.']" '.$checked.' /></td>'."\n";
}
echo '</tr>'."\n";
}
}
echo '</table>';
+
+$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 '</fieldset>';
/// Show all the message processors
View
26 message/module.js
@@ -42,4 +42,28 @@ M.core_message.init_notification = function(Y, title, content, url) {
return false;
}, o);
});
-};
+};
+
+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();
+}
View
2  version.php
@@ -30,7 +30,7 @@
defined('MOODLE_INTERNAL') || die();
-$version = 2011033004.08; // 20110330 = branching date YYYYMMDD - do not modify!
+$version = 2011033004.09; // 20110330 = branching date YYYYMMDD - do not modify!
// RR = release version - do not change in weeklies
// .XX = incremental changes
Please sign in to comment.
Something went wrong with that request. Please try again.