You are here

function adsense_click_top_pages in Google AdSense integration 7

Same name and namespace in other branches
  1. 5.3 contrib/adsense_click/adsense_click.logs.inc \adsense_click_top_pages()
  2. 5 adsense.module \adsense_click_top_pages()
  3. 5.2 adsense.module \adsense_click_top_pages()
  4. 6 contrib/adsense_click/adsense_click.logs.inc \adsense_click_top_pages()

Click top pages.

1 string reference to 'adsense_click_top_pages'
adsense_click_menu in contrib/adsense_click/adsense_click.module
Implements hook_menu().

File

contrib/adsense_click/adsense_click.logs.inc, line 62
Functions to display the logs tracked by the adsense_click module.

Code

function adsense_click_top_pages() {
  $header = array(
    array(
      'data' => t('Path'),
      'field' => 'ads.path',
    ),
    array(
      'data' => t('Clicks'),
      'field' => 'count',
      'sort' => 'desc',
    ),
    array(
      'data' => t('Last'),
      'field' => 'last',
    ),
  );
  $rows = array();

  // Create our base query.
  $query = db_select('adsense_clicks', 'ads');
  $query = $query
    ->extend('PagerDefault')
    ->extend('TableSort');
  $query
    ->fields('ads', array(
    'path',
    'title',
  ))
    ->groupBy('path')
    ->limit(50)
    ->orderByHeader($header);
  $query
    ->addExpression('COUNT(*)', 'count');
  $query
    ->addExpression('MAX(timestamp)', 'last');
  $result = $query
    ->execute();
  foreach ($result as $log) {
    $rows[] = array(
      array(
        'data' => _adsense_click_format_path($log->path, $log->title),
      ),
      array(
        'data' => $log->count,
        'align' => 'right',
      ),
      array(
        'data' => format_date($log->last, 'small'),
        'nowrap' => 'nowrap',
      ),
    );
  }
  return theme('table', array(
    'header' => $header,
    'rows' => $rows,
  )) . theme('pager');
}