You are here

function invite_admin_overview in Invite 7.2

Same name and namespace in other branches
  1. 5.2 invite.module \invite_admin_overview()
  2. 6.2 invite_admin.inc \invite_admin_overview()

Return a list of all users that have invited someone.

1 string reference to 'invite_admin_overview'
invite_menu in ./invite.module
Implements hook_menu().

File

./invite.admin.inc, line 202
Administration functions for invite module.

Code

function invite_admin_overview() {
  $header = array(
    array(
      'data' => t('Username'),
      'field' => 'u1.name',
      'sort' => 'asc',
    ),
    array(
      'data' => t('Total'),
      'field' => 'invites',
    ),
    t('Successful'),
    t('Pending'),
    t('Expired'),
    t('Remaining'),
    t('Operations'),
  );
  $query = array();
  $result = db_select('invite', 'i')
    ->fields('i', array(
    'uid',
  ))
    ->extend('TableSort')
    ->extend('PagerDefault');
  $result
    ->innerJoin('users', 'u1', 'u1.uid = i.uid');
  $result
    ->fields('u1', array(
    'name',
  ));
  $result
    ->addExpression('COUNT(*)', 'invites');
  $count_query = db_select('invite', 'i');
  $count_query
    ->innerJoin('users', 'u1', 'u1.uid = i.uid');
  $count_query
    ->addExpression('COUNT(DISTINCT i.uid)', 'count');
  if (isset($_SESSION[INVITE_ADMIN_SESSION])) {
    $result
      ->innerJoin('users', 'u2', 'u2.uid = i.invitee');
    $result
      ->where("LOWER(u2.name) LIKE CONCAT('%', LOWER(:name), '%')", array(
      ':name' => $_SESSION[INVITE_ADMIN_SESSION],
    ));
    $count_query
      ->innerJoin('users', 'u2', 'u2.uid = i.invitee');
    $count_query
      ->where("LOWER(u2.name) LIKE CONCAT('%', LOWER(:name), '%')", array(
      ':name' => $_SESSION[INVITE_ADMIN_SESSION],
    ));
    $query = array(
      'filter' => $_SESSION[INVITE_ADMIN_SESSION],
    );
    unset($_SESSION[INVITE_ADMIN_SESSION]);
  }
  $result
    ->groupBy('i.uid');
  $result
    ->groupBy('u1.name');
  $result
    ->groupBy('u1.data');
  $result
    ->setCountQuery($count_query);
  $result
    ->orderByHeader($header);
  $result = $result
    ->execute()
    ->fetchAll();
  $invite_admin_filter_form = drupal_get_form('invite_admin_filter_form');
  $output = render($invite_admin_filter_form);
  $rows = array();
  foreach ($result as $row) {
    $account = user_load($row->uid);
    $cells = array();
    $cells[] = theme('username', array(
      'account' => $row,
      'name' => $row->name,
    ));
    $cells[] = $row->invites;
    $cells[] = invite_count($row->uid, 'accepted');
    $cells[] = invite_count($row->uid, 'pending');
    $cells[] = invite_count($row->uid, 'expired');
    $remaining = invite_get_remaining_invites($account);
    $cells[] = $remaining == INVITE_UNLIMITED ? '∞' : $remaining;
    $cells[] = l(t('details'), "admin/config/people/invite/details/{$row->uid}", array(
      'query' => $query,
    ));
    $rows[] = $cells;
  }
  $output .= theme('table', array(
    'header' => $header,
    'rows' => $rows,
    'attributes' => array(
      'id' => 'invite',
    ),
  ));
  if (!$rows) {
    $output .= t('No inviters found.');
  }
  else {
    $output .= theme('pager');
  }
  return $output;
}