function dblog_top

7.x dblog.admin.inc dblog_top($type)

Page callback: Shows the most frequent log messages of a given event type.

Messages are not truncated on this page because events detailed herein do not have links to a detailed view.

Parameters

string $type: Type of database log events to display (e.g., 'search').

Return value

array A build array in the format expected by drupal_render().

See also

dblog_menu()

3 string references to 'dblog_top'
dblog_menu in drupal/modules/dblog/dblog.module
Implements hook_menu().
drupal-6.bare.database.php in drupal/modules/simpletest/tests/upgrade/drupal-6.bare.database.php
Bare installation of Drupal 6.17, for test purposes.
drupal-6.filled.database.php in drupal/modules/simpletest/tests/upgrade/drupal-6.filled.database.php
Filled installation of Drupal 6.17, for test purposes.

File

drupal/modules/dblog/dblog.admin.inc, line 102
Administrative page callbacks for the Database Logging module.

Code

function dblog_top($type) {

  $header = array(
    array(
      'data' => t('Count'),
      'field' => 'count',
      'sort' => 'desc',
    ),
    array(
      'data' => t('Message'),
      'field' => 'message',
    ),
  );
  $count_query = db_select('watchdog');
  $count_query->addExpression('COUNT(DISTINCT(message))');
  $count_query->condition('type', $type);

  $query = db_select('watchdog', 'w')->extend('PagerDefault')->extend('TableSort');
  $query->addExpression('COUNT(wid)', 'count');
  $query = $query->fields('w', array('message', 'variables'))->condition('w.type', $type)->groupBy('message')->groupBy('variables')->limit(30)->orderByHeader($header);
  $query->setCountQuery($count_query);
  $result = $query->execute();

  $rows = array();
  foreach ($result as $dblog) {
    $rows[] = array($dblog->count, theme('dblog_message', array('event' => $dblog)));
  }

  $build['dblog_top_table'] = array(
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#empty' => t('No log messages available.'),
  );
  $build['dblog_top_pager'] = array('#theme' => 'pager');

  return $build;
}