statistics_top_pages
- Versions
- 4.6 – 7
statistics_top_pages()
Menu callback; presents the "top pages" page.
Code
modules/statistics/statistics.admin.inc, line 53
<?php
function statistics_top_pages() {
$header = array(
array('data' => t('Hits'), 'field' => 'hits', 'sort' => 'desc'),
array('data' => t('Page'), 'field' => 'path'),
array('data' => t('Average page generation time'), 'field' => 'average_time'),
array('data' => t('Total page generation time'), 'field' => 'total_time')
);
$query = db_select('accesslog', array('target' => 'slave'))->extend('PagerDefault')->extend('TableSort');
$query->addExpression('COUNT(path)', 'hits');
// MAX(title) avoids having empty node titles which otherwise causes duplicates in the top pages list
$query->addExpression('MAX(title)', 'title');
$query->addExpression('AVG(timer)', 'average_time');
$query->addExpression('SUM(timer)', 'total_time');
$query
->fields('accesslog', array('path'))
->groupBy('path')
->limit(30)
->orderByHeader($header);
$count_query = db_select('accesslog', array('target' => 'slave'));
$count_query->addExpression('COUNT(DISTINCT path)');
$query->setCountQuery($count_query);
$result = $query->execute();
$rows = array();
foreach ($result as $page) {
$rows[] = array($page->hits, _statistics_format_item($page->title, $page->path), t('%time ms', array('%time' => round($page->average_time))), format_interval(round($page->total_time / 1000)));
}
if (empty($rows)) {
$rows[] = array(array('data' => t('No statistics available.'), 'colspan' => 4));
}
drupal_set_title(t('Top pages in the past %interval', array('%interval' => format_interval(variable_get('statistics_flush_accesslog_timer', 259200)))), PASS_THROUGH);
$build['statistics_top_pages_table'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
);
$build['statistics_top_pages_pager'] = array('#theme' => 'pager');
return $build;
}
?>Login or register to post comments 