You are here

function adsense_click_by_day in Google AdSense integration 5.3

Same name and namespace in other branches
  1. 5 adsense.module \adsense_click_by_day()
  2. 5.2 adsense.module \adsense_click_by_day()
  3. 6 contrib/adsense_click/adsense_click.logs.inc \adsense_click_by_day()
  4. 7 contrib/adsense_click/adsense_click.logs.inc \adsense_click_by_day()
1 string reference to 'adsense_click_by_day'
adsense_click_menu in contrib/adsense_click/adsense_click.module
Implementation of hook_menu().

File

contrib/adsense_click/adsense_click.logs.inc, line 65
Contains the functions to display the logs tracked by the adsense_click module.

Code

function adsense_click_by_day() {
  global $db_type;
  $header = array(
    array(
      'data' => t('Day'),
      'field' => 'day',
      'sort' => 'desc',
    ),
    array(
      'data' => t('Clicks'),
      'field' => 'count',
    ),
  );
  switch ($db_type) {
    case 'mysql':
    case 'mysqli':
      $sql_count = "SELECT COUNT(DISTINCT(FROM_UNIXTIME(timestamp, '%y-%m-%%d'))) FROM {adsense_clicks}";
      $sql = "SELECT FROM_UNIXTIME(timestamp, '%Y-%m-%%d') AS day, COUNT(*) AS count FROM {adsense_clicks} GROUP BY day" . tablesort_sql($header);
      break;
    case 'pgsql':
      $sql_count = "SELECT COUNT(DISTINCT(TO_CHAR(timestamp, 'YYYY-MM-DD'))) FROM {adsense_clicks}";
      $sql = "SELECT TO_CHAR(timestamp, 'YYYY-MM-DD') AS day, COUNT(*) AS count FROM {adsense_clicks} GROUP BY day" . tablesort_sql($header);
      break;
  }
  $result = pager_query($sql, 50, 0, $sql_count);
  while ($log = db_fetch_object($result)) {
    $rows[] = array(
      $log->day,
      array(
        'data' => $log->count,
        'align' => 'right',
      ),
    );
  }
  return theme('table', $header, $rows) . theme('pager', NULL, 50, 0);
}