Commit 64c97603 authored by Nigel McNie's avatar Nigel McNie Committed by Nigel McNie
Browse files

Make "My Groups" page work again, at least when the dropdown is set to all groups.

Renamed setup_groups to a more descriptive name.

Took away the check that means group owners can't leave groups for a bit. The implementation of this will need revisiting.
parent a64cdeb8
......@@ -93,22 +93,25 @@ else if ($filter == 'request') {
}
else { // all or some other text
$filter = 'all';
$sql = '
$sql = "
INNER JOIN (
SELECT g.id, \'owner\' AS type
SELECT g.id, 'admin' AS membershiptype
FROM {group} g
WHERE g.owner = ?
UNION SELECT g.id, \'member\' AS type
INNER JOIN {group_member} gm ON (gm.group = g.id AND gm.member = ?)
INNER JOIN {group_role_instance} gri ON (gri.group = g.id AND gri.roletype = 'admin' AND gri.id = gm.roleinstance)
UNION
SELECT g.id, 'member' AS membershiptype
FROM {group} g
INNER JOIN {group_member} gm ON (g.id = gm.group AND gm.member = ?)
WHERE g.owner != gm.member
UNION SELECT g.id, \'invite\' AS type
INNER JOIN {group_role_instance} gri ON (gri.group = g.id AND gri.roletype != 'admin' AND gri.id = gm.roleinstance)
UNION
SELECT g.id, 'invite' AS membershiptype
FROM {group} g
INNER JOIN {group_member_invite} gmi ON (gmi.group = g.id AND gmi.member = ?)
UNION SELECT g.id, \'request\' AS type
UNION SELECT g.id, 'request' AS membershiptype
FROM {group} g
INNER JOIN {group_member_request} gmr ON (gmr.group = g.id AND gmr.member = ?)
) t ON t.id = g.id';
) t ON t.id = g.id";
$values = array($USER->get('id'), $USER->get('id'), $USER->get('id'), $USER->get('id'));
}
......@@ -143,7 +146,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.owner, g.jointype, t.type, COUNT(gm.member) AS membercount, COUNT(gmr.member) AS requests,
$sql = '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
......@@ -152,7 +155,7 @@ $sql = 'SELECT g.id, g.name, g.description, g.owner, g.jointype, t.type, COUNT(g
LEFT JOIN {group_member_request} gmr ON (gmr.group = g.id)' .
$sql . '
WHERE g.deleted = ?
GROUP BY 1, 2, 3, 4, 5, 6, 9, 10
GROUP BY 1, 2, 3, 4, 5, 8, 9
ORDER BY g.name';
$groups = get_records_sql_array($sql, $values, $offset, $groupsperpage);
......@@ -166,7 +169,7 @@ $pagination = build_pagination(array(
'resultcounttextplural' => get_string('groups', 'group'),
));
setup_groups($groups, 'mygroups');
group_prepare_usergroups_for_display($groups, 'mygroups');
$smarty = smarty();
$smarty->assign('groups', $groups);
......
......@@ -990,10 +990,19 @@ function xmldb_core_upgrade($oldversion=0) {
// "group" INTEGER NOT NULL REFERENCES "group"(id),
// roletype TEXT NOT NULL
// );
// ALTER TABLE "group_member" ADD roleinstance;
//
// -- this is for safety, this table is populated at group create time only
// alter table group_role_instance add unique (id, "group", roletype);
//
// -- this is for the next foreign key
// alter table group_role_instance add unique (id, "group");
//
// -- this makes sure a user can't be in group 1 with a roleinstance from group 2
// alter table group_member add foreign key ("group", roleinstance) references group_role_instance ("group", id);
//
// unperformed yet:
//
// ALTER TABLE "group_member" ADD roleinstance FK group_role_instance(id);
// ?? ALTER TABLE "group_member" RENAME member TO usr;
}
......
......@@ -44,9 +44,7 @@ function group_user_can_leave($group, $userid=null) {
}
}
if ($group->owner == $userid) {
return false;
}
// TODO: disallow users from leaving if they are the only administrator in the group
if ($group->jointype == 'controlled') {
return false;
......@@ -336,18 +334,39 @@ function delete_group($groupid) {
}
/**
* function to set up groups for display in mygroups.php and find.php
* Sets up groups for display in mygroups.php and find.php
*
* @param array $groups
* @param array $groups Initial group data, including the current user's
* membership type in each group. See mygroups.php for
* the query to build this information.
* @param string $returnto Where forms generated for display should be told to return to
*/
function setup_groups($groups, $returnto='mygroups') {
function group_prepare_usergroups_for_display($groups, $returnto='mygroups') {
if (!$groups) {
return;
}
// Retrieve a list of all the group admins, for placing in each $group object
$groupadmins = array();
$groupids = array_map(create_function('$a', 'return $a->id;'), $groups);
if ($groupids) {
$groupadmins = get_records_sql_array("SELECT gm.group, gm.member
FROM {group_member} gm
INNER JOIN {group_role_instance} gri ON (gri.group = gm.group AND gri.id = gm.roleinstance)
WHERE gm.group IN (" . implode(',', db_array_to_ph($groupids)) . ")
AND gri.roletype = 'admin'", $groupids);
}
$i = 0;
foreach ($groups as $group) {
$group->admins = array();
foreach ($groupadmins as $admin) {
if ($admin->group == $group->id) {
$group->admins[] = $admin->member;
}
}
$group->description = str_shorten($group->description, 100, true);
if ($group->type == 'member') {
if ($group->membershiptype == 'member') {
$group->canleave = group_user_can_leave($group->id);
}
else if ($group->jointype == 'open') {
......@@ -366,7 +385,7 @@ function setup_groups($groups, $returnto='mygroups') {
)
));
}
else if ($group->type == 'invite') {
else if ($group->membershiptype == 'invite') {
$group->invite = pieform(array(
'name' => 'invite' . $i++,
'renderer' => 'oneline',
......@@ -391,7 +410,7 @@ function setup_groups($groups, $returnto='mygroups') {
)
));
}
else if ($group->type == 'owner' && $group->requests > 1) {
else if ($group->membershiptype == 'admin' && $group->requests > 1) {
$group->requests = array($group->requests);
}
}
......
<h3><a href="{$WWWROOT}group/view.php?id={$group->id|escape}">{$group->name|escape}</a></h3>
<h6><a href="{$WWWROOT}user/view.php?id={$group->owner|escape}">{$group->owner|display_name|escape}</a></h6>
<h6>{foreach name=admins from=$group->admins item=id}<a href="{$WWWROOT}user/view.php?id={$id|escape}">{$id|display_name|escape}</a>{if !$smarty.foreach.admins.last}, {/if}{/foreach}</h6>
{$group->description}
<ul>
<li id="groupmembers">{str tag="memberslist" section="group"}
......
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