function group_members_form in Group 7
Builds the group member overview table.
Parameters
int $pager_limit: The pager limit for the result page.
1 call to group_members_form()
- group_member_overview_form in admin/
group_membership.inc - Builds the group member overview form.
File
- admin/
group_membership.inc, line 237 - Group membership overview admin UI.
Code
function group_members_form(Group $group, $pager_limit) {
$options = array();
$header = array(
'membername' => array(
'data' => t('Member name'),
'field' => 'u.name',
'sort' => 'asc',
),
'status' => array(
'data' => t('Status'),
'field' => 'gm.status',
),
'roles' => t('Roles'),
'operations' => t('Operations'),
);
// Retrieve members.
$query = db_select('group_membership', 'gm')
->extend('PagerDefault')
->extend('TableSort');
$query
->join('users', 'u', 'gm.uid=u.uid');
$query
->addField('gm', 'mid');
$query
->condition('gm.gid', $group->gid);
$query
->condition('u.uid', 0, '<>');
$query
->orderByHeader($header);
$query
->limit($pager_limit);
// Retrieve all active filters.
$filters = isset($_SESSION['group_member_filters']) ? $_SESSION['group_member_filters'] : array();
// Allow other modules to alter the query by passing on the filters.
$query
->addTag('group_member_overview');
$query
->addMetaData('filters', $filters);
// Retrieve the membership status options.
$statuses = group_membership_status_types();
// Add the group memberships to the table.
foreach (group_membership_load_multiple($query
->execute()
->fetchCol()) as $group_membership) {
$wrapper = entity_metadata_wrapper('group_membership', $group_membership);
$options[$group_membership->mid] = array(
'membername' => l($wrapper->user
->label(), "group/{$group_membership->gid}/member/{$group_membership->uid}"),
'status' => $statuses[$group_membership->status],
);
$member_roles = array();
foreach ($wrapper->roles
->getIterator() as $group_role_wrapper) {
$member_roles[] = $group_role_wrapper
->label();
}
$options[$group_membership->mid]['roles'] = array(
'data' => array(
'#theme' => 'item_list__group_roles',
'#items' => $member_roles,
),
);
// Start with an empty operations array.
$options[$group_membership->mid]['operations'] = array();
// Gather all operation links.
$operations = module_invoke_all('group_member_operation_links', $group_membership);
if (count($operations) > 1) {
// Render an unordered list of operations links.
$options[$group_membership->mid]['operations'] = array(
'data' => array(
'#theme' => 'links__group_member_operation_links',
'#links' => $operations,
'#attributes' => array(
'class' => array(
'links',
'inline',
),
),
),
);
}
elseif (!empty($operations)) {
// Render the first and only operation as a link.
$link = reset($operations);
// Pass in $link as $options, they share the same keys.
$options[$group_membership->mid]['operations'] = l($link['title'], $link['href'], $link);
}
}
$form['members'] = array(
'#type' => 'tableselect',
'#header' => $header,
'#options' => $options,
'#empty' => t('No members available'),
);
// Transform into a table if the user can't perform any operations.
if (!group_access('administer members', $group)) {
unset($form['members']['#type'], $form['members']['#options']);
$form['members']['#theme'] = 'table';
$form['members']['#rows'] = $options;
}
return $form;
}