From a65cfba54d6bc069ec1ce807ca9c60512ef7872b Mon Sep 17 00:00:00 2001 From: mjollnir_ Date: Fri, 19 Dec 2008 08:45:44 +0000 Subject: [PATCH] MDL-17692: count_role_users now accepts an int or an array of ints for roleid - this is now consistent with get_role_users. (Merged from MOODLE_19_STABLE) --- lib/accesslib.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/accesslib.php b/lib/accesslib.php index 481cc646cf..0b525f7a4c 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -5325,7 +5325,7 @@ function get_role_users($roleid, $context, $parent=false, $fields='', /** * Counts all the users assigned this role in this context or higher - * @param int roleid + * @param int roleid (can also be an array of ints!) * @param int contextid * @param bool parent if true, get list of users assigned in higher context too * @return count @@ -5343,12 +5343,22 @@ function count_role_users($roleid, $context, $parent=false) { $parentcontexts = ''; } + if ($roleid) { + list($rids, $params) = $DB->get_in_or_equal($roleid, SQL_PARAMS_QM); + $roleselect = "AND r.roleid $rids"; + } else { + $params = array(); + $roleselect = ''; + } + + array_unshift($params, $context->id); + $sql = "SELECT count(u.id) FROM {role_assignments} r JOIN {user} u ON u.id = r.userid WHERE (r.contextid = ? $parentcontexts) - AND r.roleid = ? AND u.deleted = 0"; - $params = array($context->id, $roleid); + $roleselect + AND u.deleted = 0"; return $DB->count_records_sql($sql, $params); } -- 2.39.5