Skip to content

Commit

Permalink
Merged branch 'MDL-22232_easier_turn_off_notifications_20' from git:/…
Browse files Browse the repository at this point in the history
…/github.com/andyjdavis/moodle.git with conflict resolution
  • Loading branch information
Sam Hemelryk committed Sep 12, 2011
2 parents 5fbc147 + e186fee commit 62920e8
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 19 deletions.
2 changes: 2 additions & 0 deletions lang/en/message.php
Expand Up @@ -43,6 +43,8 @@
$string['context'] = 'context'; $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['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['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['disabled'] = 'Messaging is disabled on this site';
$string['discussion'] = 'Discussion'; $string['discussion'] = 'Discussion';
$string['editmymessage'] = 'Messaging'; $string['editmymessage'] = 'Messaging';
Expand Down
11 changes: 10 additions & 1 deletion lib/db/upgrade.php
Expand Up @@ -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; return true;
} }




//TODO: AFTER 2.0 remove the column user->emailstop and the user preference "message_showmessagewindow"
34 changes: 19 additions & 15 deletions lib/messagelib.php
Expand Up @@ -109,21 +109,25 @@ function message_send($eventdata) {


$savemessage->timecreated = time(); $savemessage->timecreated = time();


// Find out what processors are defined currently //only look for their preference if notifications are not disabled
// When a user doesn't have settings none gets return, if he doesn't want contact "" gets returned $processor = 'none';
$preferencename = 'message_provider_'.$eventdata->component.'_'.$eventdata->name.'_'.$userstate; if (!$eventdata->userto->emailstop) {

// Find out what processors are defined currently
$processor = get_user_preferences($preferencename, null, $eventdata->userto->id); // When a user doesn't have settings none gets return, if he doesn't want contact "" gets returned
if ($processor == NULL) { //this user never had a preference, save default $preferencename = 'message_provider_'.$eventdata->component.'_'.$eventdata->name.'_'.$userstate;
if (!message_set_default_message_preferences($eventdata->userto)) {
print_error('cannotsavemessageprefs', 'message'); $processor = get_user_preferences($preferencename, null, $eventdata->userto->id);
} if ($processor == NULL) { //this user never had a preference, save default
$processor = get_user_preferences($preferencename, NULL, $eventdata->userto->id); if (!message_set_default_message_preferences($eventdata->userto)) {
if (empty($processor)) { print_error('cannotsavemessageprefs', 'message');
//MDL-25114 They supplied an $eventdata->component $eventdata->name combination which doesn't }
//exist in the message_provider table $processor = get_user_preferences($preferencename, NULL, $eventdata->userto->id);
$preferrormsg = get_string('couldnotfindpreference', 'message', $preferencename); if (empty($processor)) {
throw new coding_exception($preferrormsg,'blah'); //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');
}
} }
} }


Expand Down
18 changes: 17 additions & 1 deletion message/edit.php
Expand Up @@ -27,6 +27,7 @@


$userid = optional_param('id', $USER->id, PARAM_INT); // user id $userid = optional_param('id', $USER->id, PARAM_INT); // user id
$course = optional_param('course', SITEID, PARAM_INT); // course id (defaults to Site) $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'); $url = new moodle_url('/message/edit.php');
if ($userid !== $USER->id) { if ($userid !== $USER->id) {
Expand Down Expand Up @@ -67,6 +68,7 @@


$PAGE->set_context($personalcontext); $PAGE->set_context($personalcontext);
$PAGE->set_pagelayout('course'); $PAGE->set_pagelayout('course');
$PAGE->requires->js_init_call('M.core_message.init_editsettings');


// check access control // check access control
if ($user->id == $USER->id) { if ($user->id == $USER->id) {
Expand Down Expand Up @@ -96,6 +98,12 @@
/// Save new preferences if data was submitted /// Save new preferences if data was submitted


if (($form = data_submitted()) && confirm_sesskey()) { 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(); $preferences = array();


$possiblestates = array('loggedin', 'loggedoff'); $possiblestates = array('loggedin', 'loggedoff');
Expand Down Expand Up @@ -222,6 +230,10 @@
$providername = get_string('messageprovider:'.$provider->name, $provider->component); $providername = get_string('messageprovider:'.$provider->name, $provider->component);


echo '<tr><th align="right">'.$providername.'</th><td colspan="'.$number_procs.'"></td></tr>'."\n"; 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){ foreach (array('loggedin', 'loggedoff') as $state){
$state_res = get_string($state.'description', 'message'); $state_res = get_string($state.'description', 'message');
echo '<tr><td align="right">'.$state_res.'</td>'."\n"; echo '<tr><td align="right">'.$state_res.'</td>'."\n";
Expand All @@ -233,12 +245,16 @@
} else { } else {
$checked = $preferences->{$provider->component.'_'.$provider->name.'_'.$state}[$processor->name]==1?" checked=\"checked\"":""; $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 '</tr>'."\n";
} }
} }
echo '</table>'; 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>'; echo '</fieldset>';


/// Show all the message processors /// Show all the message processors
Expand Down
26 changes: 25 additions & 1 deletion message/module.js
Expand Up @@ -42,4 +42,28 @@ M.core_message.init_notification = function(Y, title, content, url) {
return false; return false;
}, o); }, 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();
}
2 changes: 1 addition & 1 deletion version.php
Expand Up @@ -30,7 +30,7 @@
defined('MOODLE_INTERNAL') || die(); 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 // RR = release version - do not change in weeklies
// .XX = incremental changes // .XX = incremental changes


Expand Down

0 comments on commit 62920e8

Please sign in to comment.