Commit 88f6e29f authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Add search box & pagination to adminster groups page


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent 43e6dd1b
......@@ -27,33 +27,73 @@
define('INTERNAL', 1);
define('ADMIN', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'admin');
define('SECTION_PAGE', 'groups');
define('TITLE', 'Groups');
define('MENUITEM', 'managegroups/groups');
if (!$USER->get('admin')) {
//User not an admin, redirect away
redirect(get_config('wwwroot'));
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
define('TITLE', get_string('administergroups', 'admin'));
require_once('group.php');
require_once('searchlib.php');
$query = param_variable('query', '');
$offset = param_integer('offset', 0);
$limit = param_integer('limit', 10);
$searchform = pieform(array(
'name' => 'search',
'method' => 'post',
'renderer' => 'oneline',
'elements' => array(
'query' => array(
'type' => 'text',
'defaultvalue' => $query,
),
'search' => array(
'type' => 'submit',
'value' => get_string('search'),
),
),
));
function search_submit(Pieform $form, $values) {
redirect(get_config('wwwroot') . 'admin/groups/groups.php?query=' . urlencode($values['query']));
}
$groups = get_records_sql_array(
"SELECT g.id,g.name,g.grouptype,g.jointype,g.public AS visible,
(SELECT COUNT(*) FROM {group_member} gm WHERE gm.group=g.id) AS members,
(SELECT COUNT(*) FROM {group_member} gm WHERE gm.group=g.id AND gm.role='admin') AS admins
FROM {group} g WHERE g.deleted = 0 ORDER BY g.id DESC", array()
);
foreach ($groups as &$group) {
$group->type = get_string('name', 'grouptype.' . $group->grouptype) . ', ' . get_string('membershiptype.'.$group->jointype, 'group');
$group->visible = $group->visible ? 'Public' : 'Private';
$groups = search_group($query, $limit, $offset, 'all');
if ($ids = array_map(create_function('$a', 'return intval($a->id);'), $groups['data'])) {
// Member & admin counts
$ids = join(',', $ids);
$counts = get_records_sql_assoc("
SELECT m.group, COUNT(m.member) AS members, SUM((m.role = 'admin')::int) AS admins
FROM {group_member} m
WHERE m.group IN ($ids)
GROUP BY m.group",
array()
);
}
foreach ($groups['data'] as &$group) {
$group->visibility = $group->public ? get_string('Public', 'group') : get_string('Members', 'group');
$group->admins = empty($counts[$group->id]->admins) ? 0 : $counts[$group->id]->admins;
$group->members = empty($counts[$group->id]->members) ? 0 : $counts[$group->id]->members;
}
$pagination = build_pagination(array(
'url' => get_config('wwwroot') . 'admin/groups/groups.php?query=' . $query,
'count' => $groups['count'],
'limit' => $limit,
'offset' => $offset,
'resultcounttextsingular' => get_string('group', 'group'),
'resultcounttextplural' => get_string('groups', 'group'),
));
$smarty = smarty();
$smarty->assign('PAGEHEADING', TITLE);
$smarty->assign('searchform', $searchform);
$smarty->assign('groups', $groups);
$smarty->assign('PAGEHEADING', get_string('administergroups', 'admin'));
$smarty->assign('siteadmin', true);
$smarty->assign('pagination', $pagination);
$smarty->display('admin/groups/groups.tpl');
?>
......@@ -69,6 +69,7 @@ $string['publiclyviewablegroup'] = 'Publicly Viewable Group?';
$string['publiclyviewablegroupdescription'] = 'Allow people who are not logged-in to view this group, including the forums?';
$string['Type'] = 'Type';
$string['publiclyvisible'] = 'Publicly visible';
$string['Public'] = 'Public';
$string['usersautoadded'] = 'Users auto-added?';
$string['usersautoaddeddescription'] = 'Automatically put all new users into this group?';
$string['groupcategory'] = 'Group category';
......
......@@ -616,7 +616,7 @@ class PluginSearchInternal extends PluginSearch {
$count = get_field_sql('SELECT COUNT(*) '.$sql, $values);
if ($count > 0) {
$sql = 'SELECT id, name, description, grouptype, jointype, ctime, mtime ' . $sql . ' ORDER BY name';
$sql = 'SELECT id, name, description, grouptype, jointype, public, ctime, mtime ' . $sql . ' ORDER BY name';
$data = get_records_sql_array($sql, $values, $offset, $limit);
}
......
{auto_escape off}
{include file="header.tpl"}
{$searchform|safe}
<table id="adminstitutionslist" class="fullwidth">
<thead>
<tr>
......@@ -14,19 +14,19 @@
</tr>
</thead>
<tbody>
{foreach from=$groups item=group}
{foreach from=$groups.data item=group}
<tr class="{cycle values='r0,r1'}">
<td>{$group->name}</td>
<td class="center">{$group->members}</td>
<td class="center">{$group->admins}</td>
<td class="center">{$group->type}</td>
<td class="center">{$group->visible}</td>
<td class="center">{str tag=name section=grouptype.$group->grouptype}: {str tag=membershiptype.$group->jointype section=group}</td>
<td class="center">{$group->visibility}</td>
<td class="center"><a href="{$WWWROOT}admin/groups/manage.php?id={$group->id}">{str tag="groupmanage" section="admin"}</a></td>
<td class="center"><a href="{$WWWROOT}admin/groups/delete.php?id={$group->id}">{str tag="groupdelete" section="admin"}</a></td>
</tr>
{/foreach}
</tbody>
</table>
{$pagination.html|safe}
{include file="footer.tpl"}
{/auto_escape}
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