MDL-22232 messaging: added the ability to temporarily disable notifications to a particular user

This commit is contained in:
Andrew Davis (andyjdavis) 2011-08-16 14:06:11 +08:00
parent 5d2db8acc8
commit bb3546f3c2
7 changed files with 62 additions and 9 deletions

View File

@ -44,6 +44,8 @@ $string['couldnotfindpreference'] = 'Could not load preference {$a}. Does the co
$string['defaultmessageoutputs'] = 'Default message outputs';
$string['defaults'] = 'Defaults';
$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['disallowed'] = 'Disallowed';
$string['discussion'] = 'Discussion';

View File

@ -6696,8 +6696,16 @@ FROM
upgrade_main_savepoint(true, 2011083100.02);
}
if ($oldversion < 2011091200.00) {
//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, 2011091200.00);
}
return true;
}
//TODO: AFTER 2.0 remove the column user->emailstop and the user preference "message_showmessagewindow"

View File

@ -131,6 +131,7 @@ function message_send($eventdata) {
}
// Find out if user has configured this output
// Some processors cannot function without settings from the user
$userisconfigured = $processor->object->is_user_configured($eventdata->userto);
// DEBUG: notify if we are forcing unconfigured output
@ -142,7 +143,7 @@ function message_send($eventdata) {
if ($permitted == 'forced' && $userisconfigured) {
// We force messages for this processor, so use this processor unconditionally if user has configured it
$processorlist[] = $processor->name;
} else if ($permitted == 'permitted' && $userisconfigured) {
} else if ($permitted == 'permitted' && $userisconfigured && !$eventdata->userto->emailstop) {
// User settings are permitted, see if user set any, otherwise use site default ones
$userpreferencename = 'message_provider_'.$preferencebase.'_'.$userstate;
if ($userpreference = get_user_preferences($userpreferencename, null, $eventdata->userto->id)) {

View File

@ -28,6 +28,7 @@ require_once($CFG->dirroot . '/message/lib.php');
$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) {
@ -68,6 +69,7 @@ $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
$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) {
@ -99,13 +101,20 @@ $providers = message_get_providers_for_user($user->id);
if (($form = data_submitted()) && confirm_sesskey()) {
$preferences = array();
//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));
}
foreach ($providers as $provider) {
$componentproviderbase = $provider->component.'_'.$provider->name;
foreach (array('loggedin', 'loggedoff') as $state) {
$linepref = '';
$componentproviderstate = $componentproviderbase.'_'.$state;
if (array_key_exists($componentproviderstate, $form)) {
foreach (array_keys($form->{$componentproviderstate}) as $process){
foreach (array_keys($form->{$componentproviderstate}) as $process) {
if ($linepref == ''){
$linepref = $process;
} else {
@ -185,7 +194,7 @@ $renderer = $PAGE->get_renderer('core', 'message');
// Fetch default (site) preferences
$defaultpreferences = get_message_output_default_preferences();
$messagingoptions = $renderer->manage_messagingoptions($processors, $providers, $preferences, $defaultpreferences);
$messagingoptions = $renderer->manage_messagingoptions($processors, $providers, $preferences, $defaultpreferences, $user->emailstop);
echo $OUTPUT->header();
echo $messagingoptions;

View File

@ -87,4 +87,28 @@ M.core_message.init_defaultoutputs = function(Y) {
}
defaultoutputs.init();
}
M.core_message.init_editsettings = function(Y) {
var editsettings = {
init : function() {
var disableall = Y.one(".disableallcheckbox");
disableall.on('change', editsettings.changeState);
disableall.simulate("change");
},
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 File

@ -210,9 +210,11 @@ class core_message_renderer extends plugin_renderer_base {
* @param mixed $providers array of objects containing message providers
* @param mixed $preferences array of objects containing current preferences
* @param mixed $defaultpreferences array of objects containing site default preferences
* $param boolean $notificationsdisabled indicates whether the user's "emailstop" flag is
* set so shouldn't receive any non-forced notifications
* @return string The text to render
*/
public function manage_messagingoptions($processors, $providers, $preferences, $defaultpreferences) {
public function manage_messagingoptions($processors, $providers, $preferences, $defaultpreferences, $notificationsdisabled = false) {
// Filter out enabled, available system_configured and user_configured processors only.
$readyprocessors = array_filter($processors, create_function('$a', 'return $a->enabled && $a->configured && $a->object->is_user_configured();'));
@ -281,7 +283,10 @@ class core_message_renderer extends plugin_renderer_base {
$disabled['disabled'] = 1;
} else {
$checked = false;
// See if hser has touched this preference
if ($notificationsdisabled) {
$disabled['disabled'] = 1;
}
// See if user has touched this preference
if (isset($preferences->{$preferencebase.'_'.$state})) {
// User have some preferneces for this state in the database, use them
$checked = isset($preferences->{$preferencebase.'_'.$state}[$processor->name]);
@ -304,7 +309,7 @@ class core_message_renderer extends plugin_renderer_base {
);
$label = get_string('sendingviawhen', 'message', $labelparams);
$cellcontent = html_writer::label($label, $elementname, true, array('class' => 'accesshide'));
$cellcontent .= html_writer::checkbox($elementname, 1, $checked, '', array_merge(array('id' => $elementname), $disabled));
$cellcontent .= html_writer::checkbox($elementname, 1, $checked, '', array_merge(array('id' => $elementname, 'class' => 'notificationpreference'), $disabled));
$optioncell = new html_table_cell($cellcontent);
$optioncell->attributes['class'] = 'mdl-align';
}
@ -316,6 +321,10 @@ class core_message_renderer extends plugin_renderer_base {
$output .= html_writer::start_tag('div');
$output .= html_writer::table($table);
$output .= html_writer::end_tag('div');
$disableallcheckbox = $this->output->help_icon('disableall', 'message') . get_string('disableall', 'message') . html_writer::checkbox('disableall', 1, $notificationsdisabled, '', array('class'=>'disableallcheckbox'));
$output .= html_writer::nonempty_tag('div', $disableallcheckbox, array('class'=>'disableall'));
$output .= html_writer::end_tag('fieldset');
foreach ($processors as $processor) {

View File

@ -31,7 +31,7 @@ defined('MOODLE_INTERNAL') || die();
$version = 2011090700.00; // YYYYMMDD = weekly release date of this DEV branch
$version = 2011091200.00; // YYYYMMDD = weekly release date of this DEV branch
// RR = release increments - 00 in DEV branches
// .XX = incremental changes