Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-22232 messaging: added the ability to temporarily disable notific…

…ations to a particular user
  • Loading branch information...
commit bb3546f3c2844d47da9b69b80dd8696aa88a8a2b 1 parent 5d2db8a
@andyjdavis andyjdavis authored
View
2  lang/en/message.php
@@ -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';
View
12 lib/db/upgrade.php
@@ -6696,8 +6696,16 @@ function xmldb_main_upgrade($oldversion) {
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
3  lib/messagelib.php
@@ -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
13 message/edit.php
@@ -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) {
@@ -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) {
@@ -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 {
@@ -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;
View
24 message/module.js
@@ -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
15 message/renderer.php
@@ -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();'));
@@ -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]);
@@ -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';
}
@@ -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) {
View
2  version.php
@@ -31,7 +31,7 @@
-$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
Please sign in to comment.
Something went wrong with that request. Please try again.