Commit d851e88b authored by Nigel McNie's avatar Nigel McNie Committed by Nigel McNie
Browse files

Removed get_associated_groups, moved its queries to the user view page and...

Removed get_associated_groups, moved its queries to the user view page and fixed its queries for the new schema.

This function is not used anywhere else, so it's safe to remove.
parent c0a6f70c
......@@ -157,64 +157,6 @@ function get_requested_group($userid=0) {
WHERE gmr.member = ? AND g.deleted = ?', array($userid, 0));
}
/**
* all groups this user is associated with at all
* either member, invited or requested.
*
* @param int $userid (optional, defaults to $USER id)
* @param boolean $all (optional defaults to true) whether to include requested and invited groups
* @return array of group db rows (with type=member|invite|request)
*/
function get_associated_groups($userid=0, $all=true) {
$userid = optional_userid($userid);
if (!$all) {
$sql = "SELECT g.*, a.type FROM {group} g JOIN (
SELECT gm.group, 'member' AS type
FROM {group_member} gm
JOIN {group} ON owner != ? AND id = gm.group
WHERE gm.member = ? AND gm.tutor = 0
UNION
SELECT gm.group, 'member' AS type
FROM {group_member} gm
JOIN {group} ON owner != ? AND id = gm.group
WHERE gm.member = ? AND gm.tutor = 1
UNION
SELECT g.id, 'owner' AS type
FROM {group} g WHERE g.owner = ?
) AS a ON a.group = g.id
WHERE g.deleted = 0
ORDER BY g.name";
return get_records_sql_assoc($sql, array($userid, $userid, $userid, $userid, $userid));
}
$sql = "SELECT g.*, a.type FROM {group} g JOIN (
SELECT gm.group, 'invite' AS type
FROM {group_member_invite} gm WHERE gm.member = ?
UNION
SELECT gm.group, 'request' AS type
FROM {group_member_request} gm WHERE gm.member = ?
UNION
SELECT gm.group, 'member' AS type
FROM {group_member} gm
JOIN {group} ON owner != ? AND id = gm.group
WHERE gm.member = ? AND gm.tutor = 0
UNION
SELECT gm.group, 'member' AS type
FROM {group_member} gm
JOIN {group} ON owner != ? AND id = gm.group
WHERE gm.member = ? AND gm.tutor = 1
UNION
SELECT g.id, 'owner' AS type
FROM {group} g WHERE g.owner = ?
) AS a ON a.group = g.id
WHERE g.deleted = 0
ORDER BY g.name";
return get_records_sql_assoc($sql, array($userid, $userid, $userid, $userid, $userid, $userid, $userid));
}
/**
* gets groups the user is a tutor in, or the user owns
......
......@@ -143,12 +143,21 @@ if ($views) {
}
// Group stuff
if (!$userassocgroups = get_associated_groups($userid, false)) {
$userassocgroups = array();
}
$sql = "SELECT
g.*, gm.role
FROM
{group} g
JOIN {group_member} gm ON (gm.group = g.id)
WHERE
gm.member = ?
AND g.deleted = 0
ORDER BY
g.name";
$userassocgroups = (array) get_records_sql_assoc($sql, array($userid));
foreach ($userassocgroups as $group) {
$group->description = str_shorten($group->description, 100, true);
$group->roledesc = get_string($group->role, 'grouptype.' . $group->grouptype);
}
if (is_postgres()) {
......@@ -200,13 +209,28 @@ else {
}
$smarty = smarty();
$allusergroups = get_associated_groups($userid);
$sql = "SELECT g.*, a.type FROM {group} g JOIN (
SELECT gm.group, 'invite' AS type
FROM {group_member_invite} gm WHERE gm.member = ?
UNION
SELECT gm.group, 'request' AS type
FROM {group_member_request} gm WHERE gm.member = ?
UNION
SELECT gm.group, gm.role AS type
FROM {group_member} gm
WHERE gm.member = ?
) AS a ON a.group = g.id
WHERE g.deleted = 0
ORDER BY g.name";
$allusergroups = (array)get_records_sql_assoc($sql, array($userid, $userid, $userid));
if ($loggedinid != $userid) {
// Get the logged in user's "invite only" groups
if ($groups = get_owned_groups($loggedinid, 'invite')) {
$invitelist = array();
foreach ($groups as $group) {
if ($allusergroups && array_key_exists($group->id, $allusergroups)) {
if (array_key_exists($group->id, $allusergroups)) {
continue;
}
$invitelist[$group->id] = $group->name;
......
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