Skip to content

Commit

Permalink
MDL-22232 messaging: added the ability to temporarily disable notific…
Browse files Browse the repository at this point in the history
…ations to a particular user
  • Loading branch information
andyjdavis authored and Sam Hemelryk committed Sep 12, 2011
1 parent 90d14d0 commit a6f388c
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 10 deletions.
2 changes: 2 additions & 0 deletions lang/en/message.php
Expand Up @@ -44,6 +44,8 @@
$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';
Expand Down
11 changes: 9 additions & 2 deletions lib/db/upgrade.php
Expand Up @@ -6669,9 +6669,16 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2011070101.09);
}

if ($oldversion < 2011070101.10) {
//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, 2011070101.10);
}

return true;
}


//TODO: AFTER 2.0 remove the column user->emailstop and the user preference "message_showmessagewindow"
3 changes: 2 additions & 1 deletion lib/messagelib.php
Expand Up @@ -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
Expand All @@ -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)) {
Expand Down
13 changes: 11 additions & 2 deletions message/edit.php
Expand Up @@ -28,6 +28,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) {
Expand Down Expand Up @@ -68,6 +69,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) {
Expand Down Expand Up @@ -99,13 +101,20 @@
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 {
Expand Down Expand Up @@ -185,7 +194,7 @@
// 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;
Expand Down
24 changes: 24 additions & 0 deletions message/module.js
Expand Up @@ -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();
}
15 changes: 12 additions & 3 deletions message/renderer.php
Expand Up @@ -210,9 +210,11 @@ public function manage_defaultmessageoutputs($processors, $providers, $preferenc
* @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();'));

Expand Down Expand Up @@ -281,7 +283,10 @@ public function manage_messagingoptions($processors, $providers, $preferences, $
$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]);
Expand All @@ -304,7 +309,7 @@ public function manage_messagingoptions($processors, $providers, $preferences, $
);
$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';
}
Expand All @@ -316,6 +321,10 @@ public function manage_messagingoptions($processors, $providers, $preferences, $
$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) {
Expand Down
4 changes: 2 additions & 2 deletions version.php
Expand Up @@ -31,8 +31,8 @@



$version = 2011070101.09; // 20110701 = branching date YYYYMMDD - do not modify!
// RR = release version - do not change in weeklies
$version = 2011070101.10; // 20110701 = branching date YYYYMMDD - do not modify!
// RR = release increments - 00 in DEV branches
// .XX = incremental changes

$release = '2.1.1+ (Build: 20110907)'; // Human-friendly version name
Expand Down

0 comments on commit a6f388c

Please sign in to comment.