MDL-49613 access: count_role_users gives unexpected results

The count_role_users function in lib/accesslib.php gives the wrong results if a user has the
same role at multiple levels in a context path.

For example a user is a coursecreator on a course and the category that the course is in,
in this case they would be counted twice, rather than being recognised as the same user.

This change will make the function only count unique users.
This commit is contained in:
Neill Magill
2015-04-22 09:34:45 +01:00
parent 3a92084c6b
commit 9d72ae249c
+1 -1
View File
@@ -4232,7 +4232,7 @@ function count_role_users($roleid, context $context, $parent = false) {
array_unshift($params, $context->id);
$sql = "SELECT COUNT(u.id)
$sql = "SELECT COUNT(DISTINCT u.id)
FROM {role_assignments} r
JOIN {user} u ON u.id = r.userid
WHERE (r.contextid = ? $parentcontexts)