Skip to content

Commit

Permalink
message MDL-18977 made the message preference default setting code a …
Browse files Browse the repository at this point in the history
…little more sophisticated to accomodate some requests
  • Loading branch information
Andrew Davis committed Oct 27, 2010
1 parent ea738b8 commit 6955409
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions lib/messagelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,18 +283,34 @@ function message_uninstall($component) {
function message_set_default_message_preferences($user) {
global $DB;

$onlineprocessor = 'email';
$defaultonlineprocessor = 'email';
$defaultofflineprocessor = 'email';
$offlineprocessortouse = $onlineprocessortouse = null;

//look for the pre-2.0 preference if it exists
$oldpreference = get_user_preferences('message_showmessagewindow', 0, $user->id);
if (!empty($oldpreference)) {
$onlineprocessor = 'popup';
$defaultonlineprocessor = 'popup';
}

$providers = $DB->get_records('message_providers');
$preferences = array();

foreach ($providers as $providerid => $provider) {
$preferences['message_provider_'.$provider->component.'_'.$provider->name.'_loggedin'] = $onlineprocessor;
$preferences['message_provider_'.$provider->component.'_'.$provider->name.'_loggedoff'] = 'email';

//force some specific defaults for some types of message
if ($provider->name=='instantmessage') {
$onlineprocessortouse = 'popup';
$offlineprocessortouse = 'email,popup';
} else if ($provider->name=='posts') { //forum posts
$offlineprocessortouse = $onlineprocessortouse = 'email';
} else {
$onlineprocessortouse = $defaultonlineprocessor;
$offlineprocessortouse = $defaultofflineprocessor;
}

$preferences['message_provider_'.$provider->component.'_'.$provider->name.'_loggedin'] = $onlineprocessortouse;
$preferences['message_provider_'.$provider->component.'_'.$provider->name.'_loggedoff'] = $offlineprocessortouse;
}
return set_user_preferences($preferences, $user->id);
}

0 comments on commit 6955409

Please sign in to comment.