You are here

function statistics_recent_hits in Drupal 7

Same name and namespace in other branches
  1. 4 modules/statistics.module \statistics_recent_hits()
  2. 5 modules/statistics/statistics.module \statistics_recent_hits()
  3. 6 modules/statistics/statistics.admin.inc \statistics_recent_hits()

Page callback: Displays the "recent hits" page.

This displays the pages with recent hits in a given time interval that haven't been flushed yet. The flush interval is set on the statistics settings form, but is dependent on cron running.

Return value

A render array containing information about the most recent hits.

1 string reference to 'statistics_recent_hits'
statistics_menu in modules/statistics/statistics.module
Implements hook_menu().

File

modules/statistics/statistics.admin.inc, line 18
Admin page callbacks for the Statistics module.

Code

function statistics_recent_hits() {
  $header = array(
    array(
      'data' => t('Timestamp'),
      'field' => 'a.timestamp',
      'sort' => 'desc',
    ),
    array(
      'data' => t('Page'),
      'field' => 'a.path',
    ),
    array(
      'data' => t('User'),
      'field' => 'u.name',
    ),
    array(
      'data' => t('Operations'),
    ),
  );
  $query = db_select('accesslog', 'a', array(
    'target' => 'slave',
  ))
    ->extend('PagerDefault')
    ->extend('TableSort');
  $query
    ->join('users', 'u', 'a.uid = u.uid');
  $query
    ->fields('a', array(
    'aid',
    'timestamp',
    'path',
    'title',
    'uid',
  ))
    ->fields('u', array(
    'name',
  ))
    ->limit(30)
    ->orderByHeader($header);
  $result = $query
    ->execute();
  $rows = array();
  foreach ($result as $log) {
    $rows[] = array(
      array(
        'data' => format_date($log->timestamp, 'short'),
        'class' => array(
          'nowrap',
        ),
      ),
      _statistics_format_item($log->title, $log->path),
      theme('username', array(
        'account' => $log,
      )),
      l(t('details'), "admin/reports/access/{$log->aid}"),
    );
  }
  $build['statistics_table'] = array(
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#empty' => t('No statistics available.'),
  );
  $build['statistics_pager'] = array(
    '#theme' => 'pager',
  );
  return $build;
}