]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-12451, in get_users_by_capability(), defaultroleid bit fixes
authortoyomoyo <toyomoyo>
Thu, 6 Dec 2007 03:57:05 +0000 (03:57 +0000)
committertoyomoyo <toyomoyo>
Thu, 6 Dec 2007 03:57:05 +0000 (03:57 +0000)
lib/accesslib.php

index 65f365caf2245b8ae288ab9543bb107bd67ab633..a2b9ac63b30fcb9ecd43f57a6c66db262a674374 100755 (executable)
@@ -4212,14 +4212,26 @@ function get_users_by_capability($context, $capability, $fields='', $sort='',
         $view=false, $useviewallgroups=false) {
     global $CFG;
 
+/// Sorting out exceptions
+    $exceptionsql = $exceptions ? "AND u.id NOT IN ($exceptions)" : '';
+
 /// check for front page course, and see if default front page role has the required capability
+/// if it does, we can just return all users, and we do not need to check further, just return all users
 
-    // TODO This bit will break if $fields, $sort or sort are not passed in, and also it ignores $exceptions. There may be other problems too.
     $frontpagectx = get_context_instance(CONTEXT_COURSE, SITEID);
     if (!empty($CFG->defaultfrontpageroleid) && ($context->id == $frontpagectx->id || strstr($context->path, '/'.$frontpagectx->id.'/'))) {
+        
         $roles = get_roles_with_capability($capability, CAP_ALLOW, $context);
+        // if this condition is satisfied, then everyone is selected, no need to check further
         if (in_array($CFG->defaultfrontpageroleid, array_keys($roles))) {
-            return get_records_sql("SELECT $fields FROM {$CFG->prefix}user u ORDER BY $sort", $limitfrom, $limitnum); 
+            if (empty($fields)) {
+                $fields = 'u.*';
+            }
+        
+            if (empty($sort)) {
+                $sort = 'u.lastaccess';
+            }
+            return get_records_sql("SELECT $fields FROM {$CFG->prefix}user u $exceptionsql ORDER BY $sort", $limitfrom, $limitnum); 
         }
     }
 
@@ -4245,9 +4257,6 @@ function get_users_by_capability($context, $capability, $fields='', $sort='',
         $groupsql = '';
     }
 
-/// Sorting out exceptions
-    $exceptionsql = $exceptions ? "AND u.id NOT IN ($exceptions)" : '';
-
 /// Set up default fields
     if (empty($fields)) {
         $fields = 'u.*, ul.timeaccess as lastaccess, ra.hidden';