Commit 01d515c3 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Move role filtering out of group_get_user_groups query



This will make it easier to add more filtering in preparation for
bug #845287.

Change-Id: I78df2ba14a9a4c1ee6a12a3a13e0eb88f05ca935
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent bd155fc5
......@@ -1738,26 +1738,33 @@ function group_get_user_groups($userid=null, $roles=null) {
$userid = $USER->get('id');
}
if (empty($roles) && isset($usergroups[$userid])) {
return $usergroups[$userid];
if (!isset($usergroups[$userid])) {
$groups = get_records_sql_array("
SELECT g.id, g.name, gm.role, g.jointype, g.request, g.grouptype, gtr.see_submitted_views, g.category
FROM {group} g
JOIN {group_member} gm ON (gm.group = g.id)
JOIN {grouptype_roles} gtr ON (g.grouptype = gtr.grouptype AND gm.role = gtr.role)
WHERE gm.member = ?
AND g.deleted = 0
ORDER BY g.name, gm.role = 'admin' DESC, gm.role, g.id",
array($userid)
);
$usergroups[$userid] = $groups ? $groups : array();
}
if (!$groups = get_records_sql_array(
"SELECT g.id, g.name, gm.role, g.jointype, g.request, g.grouptype, gtr.see_submitted_views, g.category
FROM {group} g
JOIN {group_member} gm ON (gm.group = g.id)
JOIN {grouptype_roles} gtr ON (g.grouptype = gtr.grouptype AND gm.role = gtr.role)
WHERE gm.member = ?
AND g.deleted = 0 " . (is_array($roles) ? (' AND gm.role IN (' . join(',', array_map('db_quote', $roles)) . ')') : '') . "
ORDER BY g.name, gm.role = 'admin' DESC, gm.role, g.id", array($userid))) {
$groups = array();
if (empty($roles)) {
return $usergroups[$userid];
}
if (empty($roles)) {
$usergroups[$userid] = $groups;
$filtered = array();
foreach ($usergroups[$userid] as $g) {
if (in_array($g->role, $roles)) {
$filtered[] = $g;
}
}
return $groups;
return $filtered;
}
function group_get_user_admintutor_groups() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment