You are here

function role_watchdog_history in Role Watchdog 7

Same name and namespace in other branches
  1. 6.2 role_watchdog.pages.inc \role_watchdog_history()
  2. 6 role_watchdog.pages.inc \role_watchdog_history()
  3. 7.2 role_watchdog.pages.inc \role_watchdog_history()

Display tab page from menu callback.

Parameters

$account: User object.

1 string reference to 'role_watchdog_history'
role_watchdog_menu in ./role_watchdog.module
Implements hook_menu().

File

./role_watchdog.pages.inc, line 14
User page callbacks for the role_watchdog module.

Code

function role_watchdog_history($account) {
  $output = '';
  $rows = $rows2 = array();
  $roles = user_roles();
  $view_profile = user_access('access user profiles');
  $header = array(
    array(
      'data' => t('Date'),
      'style' => 'width: 25%;',
    ),
    array(
      'data' => t('Role'),
      'style' => 'width: 30%;',
    ),
    array(
      'data' => t('Change'),
      'style' => 'width: 15%;',
    ),
    array(
      'data' => t('User'),
      'style' => 'width: 40%;',
    ),
  );
  $query = db_select('role_watchdog', 'rw');
  $query
    ->innerJoin('users', 'u', 'rw.uid = u.uid');
  $result = $query
    ->extend('PagerDefault')
    ->limit(variable_get('role_watchdog_pager', 50))
    ->fields('rw', array(
    'hid',
    'rid',
    'uid',
    'action',
    'stamp',
  ))
    ->fields('u', array(
    'name',
  ))
    ->condition('rw.aid', $account->uid)
    ->condition('rw.rid', ROLE_WATCHDOG_NO_ROLE, '<>')
    ->orderBy('rw.stamp', 'DESC')
    ->execute()
    ->fetchAllAssoc('hid');
  foreach ($result as $hid => $row) {
    $rows[] = array(
      format_date($row->stamp),
      $roles[$row->rid],
      $row->action ? t('added by') : t('removed by'),
      $view_profile ? l($row->name, 'user/' . $row->uid) : $row->name,
    );
  }
  if (sizeof($rows)) {
    $output .= theme('table', array(
      'header' => $header,
      'rows' => $rows,
      'attributes' => array(
        'style' => 'width: 99%;',
      ),
    ));
    $output .= theme('pager', array(
      'tags' => NULL,
    ));
  }
  return $output ? $output : t('No role history found.');
}