You are here

function user_expire_report in User Expire 7

View a list of all users with an expiration date.

1 string reference to 'user_expire_report'
user_expire_menu in ./user_expire.module
Implements hook_menu().

File

./user_expire.admin.inc, line 10
Administrative pages for User expire module.

Code

function user_expire_report() {
  $header = array(
    'username' => array(
      'data' => t('Username'),
      'field' => 'u.name',
    ),
    'access' => array(
      'data' => t('Last access'),
      'field' => 'u.access',
    ),
    'expiration' => array(
      'data' => t('Expiration'),
      'field' => 'expiration',
      'sort' => 'asc',
    ),
  );
  $rows = array();
  $query = db_select('user_expire', 'ue');
  $query
    ->join('users', 'u', 'ue.uid = u.uid');
  $query = $query
    ->extend('PagerDefault')
    ->extend('TableSort');
  $query
    ->fields('u', array(
    'uid',
    'name',
    'access',
  ))
    ->fields('ue', array(
    'expiration',
  ))
    ->limit(50)
    ->orderByHeader($header);
  $accounts = $query
    ->execute();
  foreach ($accounts as $account) {
    $rows[$account->uid] = array(
      'username' => theme('username', array(
        'account' => $account,
      )),
      'access' => $account->access ? t('@time ago', array(
        '@time' => format_interval(REQUEST_TIME - $account->access),
      )) : t('never'),
      'expiration' => t('@time from now', array(
        '@time' => format_interval($account->expiration - REQUEST_TIME),
      )),
    );
  }
  return theme('table', array(
    'header' => $header,
    'rows' => $rows,
  ));
}