]> git.mjollnir.org Git - moodle.git/commitdiff
Just a small change to make this function a bit more robust, there's still a bug...
authormoodler <moodler>
Fri, 21 Sep 2007 04:33:50 +0000 (04:33 +0000)
committermoodler <moodler>
Fri, 21 Sep 2007 04:33:50 +0000 (04:33 +0000)
lib/accesslib.php

index bd4585311c8592608b29861ff8677223d93848a3..44a2299ba3e845c712c14aee1d087d3b32e4089c 100755 (executable)
@@ -1383,25 +1383,30 @@ function get_user_access_bycontext($userid, $context, $accessdata=NULL) {
     }
 
     // We will want overrides for all of them
-    $roleids  = implode(',',array_merge($courseroles,$localroles));
+    $whereroles = '';
+    if ($roleids  = implode(',',array_merge($courseroles,$localroles))) {
+        $whereroles = "rc.roleid IN ($roleids) AND";
+    }
     $sql = "SELECT ctx.path, rc.roleid, rc.capability, rc.permission
             FROM {$CFG->prefix}role_capabilities rc
             JOIN {$CFG->prefix}context ctx
              ON rc.contextid=ctx.id
-            WHERE (rc.roleid IN ($roleids)
-                    AND (ctx.id={$context->id} OR ctx.path LIKE '{$context->path}/%'))
+            WHERE ($whereroles
+                    (ctx.id={$context->id} OR ctx.path LIKE '{$context->path}/%'))
                     $wherelocalroles
             ORDER BY ctx.depth ASC, ctx.path DESC, rc.roleid ASC ";
 
-    $rs = get_recordset_sql($sql);
-
-    if ($rs->RecordCount()) {
-        while ($rd = rs_fetch_next_record($rs)) {
-            $k = "{$rd->path}:{$rd->roleid}";
-            $accessdata['rdef'][$k][$rd->capability] = $rd->permission;
+    if ($rs = get_recordset_sql($sql)) {
+        if ($rs->RecordCount()) {
+            while ($rd = rs_fetch_next_record($rs)) {
+                $k = "{$rd->path}:{$rd->roleid}";
+                $accessdata['rdef'][$k][$rd->capability] = $rd->permission;
+            }
         }
+        rs_close($rs);
+    } else {
+        debugging('Bad SQL encountered!');
     }
-    rs_close($rs);
 
     // TODO: compact capsets?