Merged branch 'MDL-26960' of git://git.luns.net.uk/moodle with changes

This commit is contained in:
Sam Hemelryk
2011-06-13 15:06:19 +08:00
2 changed files with 19 additions and 6 deletions
+16 -1
View File
@@ -354,10 +354,25 @@ function message_set_default_message_preference($component, $messagename, $filep
/**
* Returns the active providers for the current user, based on capability
*
* This function has been deprecated please use {@see message_get_providers_for_user()} instead.
*
* @deprecated since 2.1
* @todo Remove in 2.2
* @return array of message providers
*/
function message_get_my_providers() {
global $USER;
return message_get_providers_for_user($USER->id);
}
/**
* Returns the active providers for the user specified, based on capability
*
* @param int $userid id of user
* @return array of message providers
*/
function message_get_providers_for_user($userid) {
global $DB;
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
@@ -367,7 +382,7 @@ function message_get_my_providers() {
// Remove all the providers we aren't allowed to see now
foreach ($providers as $providerid => $provider) {
if (!empty($provider->capability)) {
if (!has_capability($provider->capability, $systemcontext)) {
if (!has_capability($provider->capability, $systemcontext, $userid)) {
unset($providers[$providerid]); // Not allowed to see this
}
}
+3 -5
View File
@@ -91,13 +91,14 @@ if ($user->id == $USER->id) {
$PAGE->navigation->extend_for_user($user);
}
// Fetch message providers
$providers = message_get_providers_for_user($user->id);
/// Save new preferences if data was submitted
if (($form = data_submitted()) && confirm_sesskey()) {
$preferences = array();
/// Set all the preferences for all the message providers
$providers = message_get_my_providers();
foreach ($providers as $provider) {
$componentproviderbase = $provider->component.'_'.$provider->name;
foreach (array('loggedin', 'loggedoff') as $state) {
@@ -142,7 +143,6 @@ $preferences = new stdClass();
$preferences->userdefaultemail = $user->email;//may be displayed by the email processor
/// Get providers preferences
$providers = message_get_my_providers();
foreach ($providers as $provider) {
foreach (array('loggedin', 'loggedoff') as $state) {
$linepref = get_user_preferences('message_provider_'.$provider->component.'_'.$provider->name.'_'.$state, '', $user->id);
@@ -182,8 +182,6 @@ if ($course->id != SITEID) {
// Grab the renderer
$renderer = $PAGE->get_renderer('core', 'message');
// Fetch message providers
$providers = message_get_my_providers();
// Fetch default (site) preferences
$defaultpreferences = get_message_output_default_preferences();