From: toyomoyo Date: Tue, 12 Sep 2006 07:37:23 +0000 (+0000) Subject: added function get_role_users - returns all users assigned this role in this context... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=ab5c9044118f0a3b25d3f001a5690946c7455046;p=moodle.git added function get_role_users - returns all users assigned this role in this context (or higher) not very useful for participants list because of the count and paging. Could possibly expand it --- diff --git a/lib/accesslib.php b/lib/accesslib.php index 1e6199a5b2..e390dc47c1 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -1435,6 +1435,9 @@ function update_capabilities($component='moodle') { if (!insert_record('capabilities', $capability, false, 'id')) { return false; } + + global $db; + $db->debug= 999; // Do we need to assign the new capabilities to roles that have the // legacy capabilities moodle/legacy:* as well? if (isset($capdef['legacy']) && is_array($capdef['legacy']) && @@ -2124,4 +2127,34 @@ function get_users_by_capability($context, $capability, $fields='u.*', $sort='', } +/** + * gets all the users assigned this role in this context or higher + * @param int roleid + * @param int contextid + * @param bool parent if true, get list of users assigned in higher context too + * @return array() + */ +function get_role_users($roleid, $context, $parent=false) { + global $CFG; + + if ($parent) { + if ($contexts = get_parent_contexts($context)) { + $parentcontexts = 'r.contextid IN ('.implode(',', $contexts).')'; + } else { + $parentcontexts = ''; + } + } else { + $parentcontexts = ''; + } + + $SQL = "select u.* + from {$CFG->prefix}role_assignments r, + {$CFG->prefix}user u + where (r.contextid = $context->id $parentcontexts) + and r.roleid = $roleid + and u.id = r.userid"; // join now so that we can just use fullname() later + + return get_records_sql($SQL); +} + ?>