Commit ca0201de authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Get all user info in group admins query (bug #845279)



This will reduce the number of queries required by display_name calls
over group admins on the find groups and my groups pages.  Moving this
into a separate function will also enable the same query to be used in
other places such as the groupinfo block.

Change-Id: I3ca81dbce87f42e00ed57caeaa4ba6aed0230009
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent 4526d828
......@@ -1187,6 +1187,29 @@ function group_get_default_artefact_permissions($groupid) {
return $permissions;
}
// Retrieve a list of group admins
function group_get_admins($groupids) {
$groupids = array_map('intval', $groupids);
if (empty($groupids)) {
return array();
}
$groupadmins = get_records_sql_array('
SELECT m.group, m.member, u.id, u.username, u.firstname, u.lastname, u.preferredname, u.email, u.profileicon
FROM {group_member} m JOIN {usr} u ON u.id = m.member
WHERE m.group IN (' . implode(',', db_array_to_ph($groupids)) . ")
AND m.role = 'admin'",
$groupids
);
if (!$groupadmins) {
$groupadmins = array();
}
return $groupadmins;
}
/**
* Sets up groups for display in mygroups.php and find.php
*
......@@ -1200,25 +1223,15 @@ function group_prepare_usergroups_for_display($groups, $returnto='mygroups') {
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 "group", "member"
FROM {group_member}
WHERE "group" IN (' . implode(',', db_array_to_ph($groupids)) . ")
AND \"role\" = 'admin'", $groupids);
if (!$groupadmins) {
$groupadmins = array();
}
}
$groupadmins = group_get_admins($groupids);
$i = 0;
foreach ($groups as $group) {
$group->admins = array();
foreach ($groupadmins as $admin) {
if ($admin->group == $group->id) {
$group->admins[] = $admin->member;
$group->admins[] = $admin;
}
}
if ($group->membershiptype == 'member') {
......
<h3><a href="{$WWWROOT}group/view.php?id={$group->id}">{$group->name}</a></h3>
<h6>{foreach name=admins from=$group->admins item=id}<a href="{$WWWROOT}user/view.php?id={$id}">{$id|display_name}</a>{if !$.foreach.admins.last}, {/if}{/foreach}</h6>
<h6>{foreach name=admins from=$group->admins item=user}<a href="{$WWWROOT}user/view.php?id={$user->id}">{$user|display_name}</a>{if !$.foreach.admins.last}, {/if}{/foreach}</h6>
<div class="inline s"> - {$group->settingsdescription}
{$group->description|str_shorten_html:100:true|safe}</div>
{if $group->membercount}
......
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