Browse files

Merged branch 'MDL-26960-for-20_STABLE' of git://git.luns.net.uk/mood…

…le with changes
  • Loading branch information...
2 parents 6160c17 + df01a82 commit c1d93d47e960af78f95252fccd4dd1f6babef54c Sam Hemelryk committed Jun 13, 2011
Showing with 18 additions and 6 deletions.
  1. +15 −1 lib/messagelib.php
  2. +3 −5 message/edit.php
View
16 lib/messagelib.php
@@ -230,9 +230,23 @@ function message_update_providers($component='moodle') {
/**
* Returns the active providers for the current user, based on capability
+ *
+ * @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 requested user, 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);
@@ -242,7 +256,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
}
}
View
8 message/edit.php
@@ -90,13 +90,14 @@
$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();
$possiblestates = array('loggedin', 'loggedoff');
foreach ( $providers as $providerid => $provider){
foreach ($possiblestates as $state){
@@ -156,8 +157,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 $providerid => $provider){
foreach (array('loggedin', 'loggedoff') as $state){
$linepref = get_user_preferences('message_provider_'.$provider->component.'_'.$provider->name.'_'.$state, '', $user->id);
@@ -211,7 +210,6 @@
/// Settings table...
echo '<fieldset id="providers" class="clearfix">';
echo '<legend class="ftoggler">'.get_string('providers_config', 'message').'</legend>';
-$providers = message_get_my_providers();
$processors = $DB->get_records('message_processors', null, 'name DESC');
$number_procs = count($processors);
echo '<table cellpadding="2"><tr><td>&nbsp;</td>'."\n";

0 comments on commit c1d93d4

Please sign in to comment.