function visitors_top_pages in Visitors 8
Same name and namespace in other branches
- 7.2 reports/top_pages.inc \visitors_top_pages()
- 7 reports/top_pages.inc \visitors_top_pages()
- 7.0 reports/top_pages.inc \visitors_top_pages()
Display top pages report.
Return value
string top pages report html source
1 string reference to 'visitors_top_pages'
- visitors_menu in ./
visitors.module - Menu callback. Prints a listing of active nodes on the site.
File
- reports/
top_pages.inc, line 14 - Top pages report for the visitors module.
Code
function visitors_top_pages() {
$date_format = variable_get('date_format_short_custom', 'Y-m-d H:i:s');
$items_per_page = variable_get('visitors_lines_per_page', 10);
$header = array(
array(
'data' => t('#'),
),
array(
'data' => t('URL'),
'field' => 'visitors_url',
),
array(
'data' => t('Count'),
'field' => 'count',
'sort' => 'desc',
),
);
$query = db_select('visitors', 'v')
->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender')
->extend('Drupal\\Core\\Database\\Query\\TableSortExtender');
$query
->addExpression('COUNT(visitors_id)', 'count');
$query
->addExpression('MIN(visitors_title)', 'visitors_title');
$query
->addExpression('MIN(visitors_url)', 'visitors_url');
$query
->fields('v', array(
'visitors_path',
));
visitors_date_filter_sql_condition($query);
$query
->groupBy('visitors_path');
$query
->orderByHeader($header);
$query
->limit($items_per_page);
$count_query = db_select('visitors', 'v');
$count_query
->addExpression('COUNT(DISTINCT visitors_path)');
visitors_date_filter_sql_condition($count_query);
$query
->setCountQuery($count_query);
$results = $query
->execute();
$rows = array();
$page = isset($_GET['page']) ? $_GET['page'] : '';
$i = 0 + $page * $items_per_page;
foreach ($results as $data) {
$rows[] = array(
++$i,
check_plain($data->visitors_title) . '<br/>' . l($data->visitors_path, $data->visitors_url),
$data->count,
);
}
$output = visitors_date_filter();
$output .= theme('table', array(
'header' => $header,
'rows' => $rows,
));
$output .= theme('pager', array(
'quantity' => $items_per_page,
));
return $output;
}