Index: accesslib.php =================================================================== RCS file: /cvsroot/moodle/moodle/lib/accesslib.php,v retrieving revision 1.421.2.63 diff -u -r1.421.2.63 accesslib.php --- accesslib.php 12 May 2008 15:28:31 -0000 1.421.2.63 +++ accesslib.php 13 May 2008 21:51:38 -0000 @@ -1095,7 +1095,7 @@ LEFT OUTER JOIN {$CFG->prefix}role_capabilities rc ON (rc.roleid=ra.roleid AND rc.contextid=ra.contextid) WHERE ra.userid = $userid AND ctx.contextlevel <= ".CONTEXT_COURSE." - ORDER BY ctx.depth, ctx.path"; + ORDER BY ctx.depth, ctx.path, ra.roleid"; $rs = get_recordset_sql($sql); // // raparents collects paths & roles we need to walk up @@ -1267,19 +1267,26 @@ ON ra.contextid=ctx.id WHERE ra.userid = $userid AND (ctx.path = '{$context->path}' OR ctx.path LIKE '{$context->path}/%') - ORDER BY ctx.depth, ctx.path"; + ORDER BY ctx.depth, ctx.path, ra.roleid"; $rs = get_recordset_sql($sql); - // - // Read in the RAs + // + // Read in the RAs, preventing duplicates // $localroles = array(); + $lastseen = ''; while ($ra = rs_fetch_next_record($rs)) { if (!isset($accessdata['ra'][$ra->path])) { $accessdata['ra'][$ra->path] = array(); } - array_push($accessdata['ra'][$ra->path], $ra->roleid); - array_push($localroles, $ra->roleid); + // only add if is not a repeat caused + // by capability join... + // (this check is cheaper than in_array()) + if ($lastseen !== $ra->path.':'.$ra->roleid) { + $lastseen = $ra->path.':'.$ra->roleid; + array_push($accessdata['ra'][$ra->path], $ra->roleid); + array_push($localroles, $ra->roleid); + } } rs_close($rs);