Commit 3c3a158e authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Fix My Groups, Find Groups for mysql

parent e6215dc7
......@@ -85,11 +85,10 @@ if ($groups['data']) {
foreach ($groups['data'] as $group) {
$groupids[] = $group->id;
}
$groups['data'] = get_records_sql_array(
"SELECT g.id, g.name, g.description, g.jointype, t.membershiptype, COUNT(gm.member) AS membercount, COUNT(gmr.member) AS requests,
(SELECT gm.member FROM {group_member} gm JOIN {usr} u ON (u.id = gm.member AND u.deleted = 0) WHERE gm.group = g.id ORDER BY member LIMIT 1) AS member1,
(SELECT gm.member FROM {group_member} gm JOIN {usr} u ON (u.id = gm.member AND u.deleted = 0) WHERE gm.group = g.id ORDER BY member LIMIT 1 OFFSET 1) AS member2,
(SELECT gm.member FROM {group_member} gm JOIN {usr} u ON (u.id = gm.member AND u.deleted = 0) WHERE gm.group = g.id ORDER BY member LIMIT 1 OFFSET 2) AS member3
$groups['data'] = get_records_sql_assoc(
"SELECT g.id, g.name, g.description, g.jointype, t.membershiptype,
COUNT(gm.member) AS membercount,
COUNT(gmr.member) AS requests
FROM {group} g
LEFT JOIN {group_member} gm ON (gm.group = g.id)
LEFT JOIN {group_member_request} gmr ON (gmr.group = g.id)
......@@ -111,10 +110,26 @@ if ($groups['data']) {
INNER JOIN {group_member_request} gmr ON (gmr.group = g.id AND gmr.member = ?)
) t ON t.id = g.id
WHERE g.id IN (" . implode($groupids, ',') . ')
GROUP BY 1, 2, 3, 4, 5, 8, 9
GROUP BY g.id, g.name, g.description, g.jointype, t.membershiptype
ORDER BY g.name',
array($USER->get('id'), $USER->get('id'), $USER->get('id'), $USER->get('id'))
);
if ($groups['data']) {
// Get 3 members from each group in a separate query -- mysql doesn't like including them as subqueries with limit 1 in the above query
$members = get_records_sql_array("
SELECT m1.group, m1.member, u.* FROM {group_member} m1
INNER JOIN {usr} u ON (m1.member = u.id AND u.deleted = 0)
WHERE 3 > (
SELECT COUNT(m2.member)
FROM {group_member} m2
WHERE m1.group = m2.group AND m2.member < m1.member
)
AND m1.group IN (" . implode($groupids, ',') . ')', array());
foreach ($members as $m) {
$groups['data'][$m->group]->members[] = (object) array('id' => $m->id, 'name' => display_name($m));
}
}
$groups['data'] = array_values($groups['data']);
}
group_prepare_usergroups_for_display($groups['data'], 'find');
......
......@@ -148,10 +148,7 @@ $count = count_records_sql('SELECT COUNT(*) FROM {group} g ' . $sql . ' WHERE g.
// gets the groups filtered by above
// and the first three members by id
$sql = 'SELECT g.id, g.name, g.description, g.jointype, g.grouptype, t.membershiptype, t.reason, t.role, COUNT(gm.member) AS membercount, COUNT(gmr.member) AS requests,
(SELECT gm.member FROM {group_member} gm JOIN {usr} u ON (u.id = gm.member AND u.deleted = 0) WHERE gm.group = g.id ORDER BY member LIMIT 1) AS member1,
(SELECT gm.member FROM {group_member} gm JOIN {usr} u ON (u.id = gm.member AND u.deleted = 0) WHERE gm.group = g.id ORDER BY member LIMIT 1 OFFSET 1) AS member2,
(SELECT gm.member FROM {group_member} gm JOIN {usr} u ON (u.id = gm.member AND u.deleted = 0) WHERE gm.group = g.id ORDER BY member LIMIT 1 OFFSET 2) AS member3
$sql = 'SELECT g.id, g.name, g.description, g.jointype, g.grouptype, t.membershiptype, t.reason, t.role, COUNT(gm.member) AS membercount, COUNT(gmr.member) AS requests
FROM {group} g
LEFT JOIN {group_member} gm ON (gm.group = g.id)
LEFT JOIN {group_member_request} gmr ON (gmr.group = g.id)' .
......@@ -160,7 +157,25 @@ $sql = 'SELECT g.id, g.name, g.description, g.jointype, g.grouptype, t.membershi
GROUP BY g.id, g.name, g.description, g.jointype, g.grouptype, t.membershiptype, t.reason, t.role
ORDER BY g.name';
$groups = get_records_sql_array($sql, $values, $offset, $groupsperpage);
$groups = get_records_sql_assoc($sql, $values, $offset, $groupsperpage);
if ($groups) {
// Get 3 members from each group in a separate query -- mysql doesn't like including them as subqueries with limit 1 in the above query
$members = get_records_sql_array("
SELECT m1.group, m1.member, u.* FROM {group_member} m1
INNER JOIN {usr} u ON (m1.member = u.id AND u.deleted = 0)
WHERE 3 > (
SELECT COUNT(m2.member)
FROM {group_member} m2
WHERE m1.group = m2.group AND m2.member < m1.member
)
AND m1.group IN (" . join(',', array_keys($groups)) . ")", array());
foreach ($members as $m) {
$groups[$m->group]->members[] = (object) array('id' => $m->id, 'name' => display_name($m));
}
}
$groups = array_values($groups);
$pagination = build_pagination(array(
'url' => get_config('wwwroot') . 'group/mygroups.php?filter=' . $filter,
......
......@@ -3,10 +3,10 @@
{$group->description}
<ul>
<li id="groupmembers">{str tag="memberslist" section="group"}
{if $group->member1}<a href="{$WWWROOT}user/view.php?id={$group->member1|escape}" class="links-members">{$group->member1|display_name|escape}</a>{/if}
{if $group->member2}, <a href="{$WWWROOT}user/view.php?id={$group->member2|escape}" class="links-members">{$group->member2|display_name|escape}</a>{/if}
{if $group->member3}, <a href="{$WWWROOT}user/view.php?id={$group->member3|escape}" class="links-members">{$group->member3|display_name|escape}</a>{/if}
{if $group->membercount > 3}<a href="{$WWWROOT}group/view.php?id={$group->id|escape}&amp;#members" class="links-members">...</a>{/if}
{foreach name=members from=$group->members item=member}
<a href="{$WWWROOT}user/view.php?id={$member->id|escape}" class="links-members">{$member->name|escape}</a>{if !$smarty.foreach.members.last}, {/if}
{/foreach}
{if $group->membercount > 3}<a href="{$WWWROOT}group/members.php?id={$group->id|escape}" class="links-members">...</a>{/if}
</li>
{include file="group/groupuserstatus.tpl" group=$group returnto='find'}
......
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