Commit 1afd01f3 authored by Francois Marier's avatar Francois Marier Committed by Gerrit Code Review
Browse files

Merge "Remove duplicate queries for logged-in user's admin/tutor groups"

parents 102797d1 6d0147d1
......@@ -61,30 +61,8 @@ else {
}
}
// @todo I'm not sure we actually need to distinguish the controlled
// & invite groups at this stage. Investigate whether we can just use
// group_get_user_groups to fetch all the user's groups, and work out
// whether the user has invite or add power for any of them.
$controlledgroups = count_records_sql("SELECT COUNT(g.id)
FROM {group} g
JOIN {group_member} gm ON (gm.group = g.id)
JOIN {grouptype_roles} gtr ON (gtr.grouptype = g.grouptype AND gtr.role = gm.role)
WHERE gm.member = ?
AND g.jointype = 'controlled'
AND (gm.role = 'admin' OR gtr.see_submitted_views = 1)
AND g.deleted = 0", array($USER->get('id')));
$invite = count_records_sql("SELECT COUNT(g.id)
FROM {group} g
JOIN {group_member} gm ON (gm.group = g.id)
WHERE gm.member = ?
AND gm.role = 'admin'
AND g.deleted = 0", array($USER->get('id')));
$admingroups = new StdClass;
$admingroups->controlled = $controlledgroups;
$admingroups->invite = $invite;
require_once('group.php');
$admingroups = (bool) group_get_user_admintutor_groups();
build_userlist_html($data, $page, $admingroups);
unset($data['data']);
......
......@@ -1744,6 +1744,17 @@ function group_get_user_groups($userid=null, $roles=null) {
return $groups;
}
function group_get_user_admintutor_groups() {
$groups = array();
foreach (group_get_user_groups() as $g) {
if ($g->role == 'admin' || $g->see_submitted_views) {
$groups[] = $g;
}
}
return $groups;
}
function group_get_member_ids($group, $roles=null) {
$rolesql = is_null($roles) ? '' : (' AND gm.role IN (' . join(',', array_map('db_quote', $roles)) . ')');
......
......@@ -56,14 +56,7 @@ if (!empty($options['myinstitutions'])) {
}
require_once(get_config('libroot').'group.php');
$admingroups = false;
foreach (group_get_user_groups() as $g) {
if ($g->role == 'admin' || $g->see_submitted_views) {
$admingroups = true;
break;
}
}
$admingroups = (bool) group_get_user_admintutor_groups();
build_userlist_html($data, 'find', $admingroups);
$searchform = array(
......
......@@ -42,28 +42,8 @@ $limit = 10;
$data = search_friend($filter, $limit, $offset);
$data['filter'] = $filter;
// @todo I'm not sure we actually need to distinguish the controlled
// & invite groups at this stage. Investigate whether we can just use
// group_get_user_groups to fetch all the user's groups, and work out
// whether the user has invite or add power for any of them.
$controlledgroups = count_records_sql("SELECT COUNT(g.id)
FROM {group} g
JOIN {group_member} gm ON (gm.group = g.id)
JOIN {grouptype_roles} gtr ON (gtr.grouptype = g.grouptype AND gtr.role = gm.role)
WHERE gm.member = ?
AND g.jointype = 'controlled'
AND (gm.role = 'admin' OR gtr.see_submitted_views = 1)
AND g.deleted = 0", array($USER->get('id')));
$invite = count_records_sql("SELECT COUNT(g.id)
FROM {group} g
JOIN {group_member} gm ON (gm.group = g.id)
WHERE gm.member = ?
AND gm.role = 'admin'
AND g.deleted = 0", array($USER->get('id')));
$admingroups = $controlledgroups || $invite;
require_once('group.php');
$admingroups = (bool) group_get_user_admintutor_groups();
build_userlist_html($data, 'myfriends', $admingroups);
$filterform = pieform(array(
......
......@@ -120,14 +120,7 @@ if (!empty($loggedinid) && $loggedinid != $userid) {
// Get all groups that the logged in user is an admin of, or where the logged in user
// has a role in the list of roles who are allowed to assess submitted views for the
// group's grouptype
if ($groups = get_records_sql_array("SELECT g.*
FROM {group} g
JOIN {group_member} gm ON (gm.group = g.id)
JOIN {grouptype_roles} gtr ON gtr.grouptype = g.grouptype AND gtr.role = gm.role
WHERE gm.member = ?
AND (gm.role = 'admin' OR gtr.see_submitted_views = 1)
AND g.deleted = 0", array($loggedinid))) {
if ($groups = group_get_user_admintutor_groups()) {
$invitelist = array(); // List of groups the displayed user can be invited to join
$controlledlist = array(); // List of groups the displayed user can be directly added to
......
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