You are here

function _simpleads_get_statistics in SimpleAds 7

Helper function. Returns stats for given table name.

1 call to _simpleads_get_statistics()
_simpleads_stat_tab in ./simpleads.stat.inc
Callback for Ad Statistics page.

File

./simpleads.stat.inc, line 313
SimpleAds Statistics.

Code

function _simpleads_get_statistics($table, $nid) {
  $stats = array();
  if ($table == 'simpleads_clicks') {
    $stats['Yesterday'] = db_query("SELECT IFNULL(SUM(sc.clicks), 0) FROM {simpleads_stats} sc\n      WHERE STR_TO_DATE(sc.date, '%Y%m%d') <= NOW() AND STR_TO_DATE(sc.date, '%Y%m%d') >= CURDATE()- 1\n      AND sc.nid = :nid", array(
      ':nid' => $nid,
    ))
      ->fetchField() . '/' . db_query("SELECT IFNULL(SUM(sc.clicks_unique), 0) FROM {simpleads_stats} sc\n      WHERE STR_TO_DATE(sc.date, '%Y%m%d') <= NOW() AND STR_TO_DATE(sc.date, '%Y%m%d') >= CURDATE() - 1\n      AND sc.nid = :nid", array(
      ':nid' => $nid,
    ))
      ->fetchField();
    $stats['Last Week'] = db_query("SELECT IFNULL(SUM(sc.clicks), 0) FROM {simpleads_stats} sc\n      WHERE STR_TO_DATE(sc.date, '%Y%m%d') <= NOW() AND STR_TO_DATE(sc.date, '%Y%m%d') >= SUBDATE(NOW(), INTERVAL 1 WEEK)\n      AND sc.nid = :nid", array(
      ':nid' => $nid,
    ))
      ->fetchField() . '/' . db_query("SELECT IFNULL(SUM(sc.clicks_unique), 0) FROM {simpleads_stats} sc\n      WHERE STR_TO_DATE(sc.date, '%Y%m%d') <= NOW() AND STR_TO_DATE(sc.date, '%Y%m%d') >= SUBDATE(NOW(), INTERVAL 1 WEEK)\n      AND sc.nid = :nid", array(
      ':nid' => $nid,
    ))
      ->fetchField();
    $stats['Last Month'] = db_query("SELECT IFNULL(SUM(sc.clicks), 0) FROM {simpleads_stats} sc\n      WHERE STR_TO_DATE(sc.date, '%Y%m%d') <= NOW() AND STR_TO_DATE(sc.date, '%Y%m%d') >= SUBDATE(NOW(), INTERVAL 1 MONTH)\n      AND sc.nid = :nid", array(
      ':nid' => $nid,
    ))
      ->fetchField() . '/' . db_query("SELECT IFNULL(SUM(sc.clicks_unique), 0) FROM {simpleads_stats} sc\n      WHERE STR_TO_DATE(sc.date, '%Y%m%d') <= NOW() AND STR_TO_DATE(sc.date, '%Y%m%d') >= SUBDATE(NOW(), INTERVAL 1 MONTH)\n      AND sc.nid = :nid", array(
      ':nid' => $nid,
    ))
      ->fetchField();
    $stats['3 Months'] = db_query("SELECT IFNULL(SUM(sc.clicks), 0) FROM {simpleads_stats} sc\n      WHERE STR_TO_DATE(sc.date, '%Y%m%d') <= NOW() AND STR_TO_DATE(sc.date, '%Y%m%d') >= SUBDATE(NOW(), INTERVAL 3 MONTH)\n      AND sc.nid = :nid", array(
      ':nid' => $nid,
    ))
      ->fetchField() . '/' . db_query("SELECT IFNULL(SUM(sc.clicks_unique), 0) FROM {simpleads_stats} sc\n      WHERE STR_TO_DATE(sc.date, '%Y%m%d') <= NOW() AND STR_TO_DATE(sc.date, '%Y%m%d') >= SUBDATE(NOW(), INTERVAL 3 MONTH)\n      AND sc.nid = :nid", array(
      ':nid' => $nid,
    ))
      ->fetchField();
    $stats['6 Months'] = db_query("SELECT IFNULL(SUM(sc.clicks), 0) FROM {simpleads_stats} sc\n      WHERE STR_TO_DATE(sc.date, '%Y%m%d') <= NOW() AND STR_TO_DATE(sc.date, '%Y%m%d') >= SUBDATE(NOW(), INTERVAL 6 MONTH)\n      AND sc.nid = :nid", array(
      ':nid' => $nid,
    ))
      ->fetchField() . '/' . db_query("SELECT IFNULL(SUM(sc.clicks_unique), 0) FROM {simpleads_stats} sc\n      WHERE STR_TO_DATE(sc.date, '%Y%m%d') <= NOW() AND STR_TO_DATE(sc.date, '%Y%m%d') >= SUBDATE(NOW(), INTERVAL 6 MONTH)\n      AND sc.nid = :nid", array(
      ':nid' => $nid,
    ))
      ->fetchField();
    $stats['1 year'] = db_query("SELECT IFNULL(SUM(sc.clicks), 0) FROM {simpleads_stats} sc\n      WHERE STR_TO_DATE(sc.date, '%Y%m%d') <= NOW() AND STR_TO_DATE(sc.date, '%Y%m%d') >= SUBDATE(NOW(), INTERVAL 1 YEAR)\n      AND sc.nid = :nid", array(
      ':nid' => $nid,
    ))
      ->fetchField() . '/' . db_query("SELECT IFNULL(SUM(sc.clicks_unique), 0) FROM {simpleads_stats} sc\n      WHERE STR_TO_DATE(sc.date, '%Y%m%d') <= NOW() AND STR_TO_DATE(sc.date, '%Y%m%d') >= SUBDATE(NOW(), INTERVAL 1 YEAR)\n      AND sc.nid = :nid", array(
      ':nid' => $nid,
    ))
      ->fetchField();
    $stats['All Time'] = db_query("SELECT IFNULL(SUM(sc.clicks), 0) FROM {simpleads_stats} sc WHERE sc.nid = :nid", array(
      ':nid' => $nid,
    ))
      ->fetchField() . '/' . db_query("SELECT IFNULL(SUM(sc.clicks_unique), 0) FROM {simpleads_stats} sc WHERE sc.nid = :nid", array(
      ':nid' => $nid,
    ))
      ->fetchField();
  }
  if ($table == 'simpleads_impressions') {
    $stats['Yesterday'] = db_query("SELECT IFNULL(SUM(sc.impressions), 0) FROM {simpleads_stats} sc\n      WHERE STR_TO_DATE(sc.date, '%Y%m%d') <= CURDATE() AND STR_TO_DATE(sc.date, '%Y%m%d') >= SUBDATE(CURDATE(), INTERVAL 1 DAY)\n      AND sc.nid = :nid", array(
      ':nid' => $nid,
    ))
      ->fetchField() . '/' . db_query("SELECT IFNULL(SUM(sc.impressions_unique), 0) FROM {simpleads_stats} sc\n      WHERE STR_TO_DATE(sc.date, '%Y%m%d') <= CURDATE() AND STR_TO_DATE(sc.date, '%Y%m%d') >= SUBDATE(CURDATE(), INTERVAL 1 DAY)\n      AND sc.nid = :nid", array(
      ':nid' => $nid,
    ))
      ->fetchField();
    $stats['Last Week'] = db_query("SELECT IFNULL(SUM(sc.impressions), 0) FROM {simpleads_stats} sc\n      WHERE STR_TO_DATE(sc.date, '%Y%m%d') <= NOW() AND STR_TO_DATE(sc.date, '%Y%m%d') >= SUBDATE(NOW(), INTERVAL 1 WEEK)\n      AND sc.nid = :nid", array(
      ':nid' => $nid,
    ))
      ->fetchField() . '/' . db_query("SELECT IFNULL(SUM(sc.impressions_unique), 0) FROM {simpleads_stats} sc\n      WHERE STR_TO_DATE(sc.date, '%Y%m%d') <= NOW() AND STR_TO_DATE(sc.date, '%Y%m%d') >= SUBDATE(NOW(), INTERVAL 1 WEEK)\n      AND sc.nid = :nid", array(
      ':nid' => $nid,
    ))
      ->fetchField();
    $stats['Last Month'] = db_query("SELECT IFNULL(SUM(sc.impressions), 0) FROM {simpleads_stats} sc\n      WHERE STR_TO_DATE(sc.date, '%Y%m%d') <= NOW() AND STR_TO_DATE(sc.date, '%Y%m%d') >= SUBDATE(NOW(), INTERVAL 1 MONTH)\n      AND sc.nid = :nid", array(
      ':nid' => $nid,
    ))
      ->fetchField() . '/' . db_query("SELECT IFNULL(SUM(sc.impressions_unique), 0) FROM {simpleads_stats} sc\n      WHERE STR_TO_DATE(sc.date, '%Y%m%d') <= NOW() AND STR_TO_DATE(sc.date, '%Y%m%d') >= SUBDATE(NOW(), INTERVAL 1 MONTH)\n      AND sc.nid = :nid", array(
      ':nid' => $nid,
    ))
      ->fetchField();
    $stats['3 Months'] = db_query("SELECT IFNULL(SUM(sc.impressions), 0) FROM {simpleads_stats} sc\n      WHERE STR_TO_DATE(sc.date, '%Y%m%d') <= NOW() AND STR_TO_DATE(sc.date, '%Y%m%d') >= SUBDATE(NOW(), INTERVAL 3 MONTH)\n      AND sc.nid = :nid", array(
      ':nid' => $nid,
    ))
      ->fetchField() . '/' . db_query("SELECT IFNULL(SUM(sc.impressions_unique), 0) FROM {simpleads_stats} sc\n      WHERE STR_TO_DATE(sc.date, '%Y%m%d') <= NOW() AND STR_TO_DATE(sc.date, '%Y%m%d') >= SUBDATE(NOW(), INTERVAL 3 MONTH)\n      AND sc.nid = :nid", array(
      ':nid' => $nid,
    ))
      ->fetchField();
    $stats['6 Months'] = db_query("SELECT IFNULL(SUM(sc.impressions), 0) FROM {simpleads_stats} sc\n      WHERE STR_TO_DATE(sc.date, '%Y%m%d') <= NOW() AND STR_TO_DATE(sc.date, '%Y%m%d') >= SUBDATE(NOW(), INTERVAL 6 MONTH)\n      AND sc.nid = :nid", array(
      ':nid' => $nid,
    ))
      ->fetchField() . '/' . db_query("SELECT IFNULL(SUM(sc.impressions_unique), 0) FROM {simpleads_stats} sc\n      WHERE STR_TO_DATE(sc.date, '%Y%m%d') <= NOW() AND STR_TO_DATE(sc.date, '%Y%m%d') >= SUBDATE(NOW(), INTERVAL 6 MONTH)\n      AND sc.nid = :nid", array(
      ':nid' => $nid,
    ))
      ->fetchField();
    $stats['1 year'] = db_query("SELECT IFNULL(SUM(sc.impressions), 0) FROM {simpleads_stats} sc\n      WHERE STR_TO_DATE(sc.date, '%Y%m%d') <= NOW() AND STR_TO_DATE(sc.date, '%Y%m%d') >= SUBDATE(NOW(), INTERVAL 1 YEAR)\n      AND sc.nid = :nid", array(
      ':nid' => $nid,
    ))
      ->fetchField() . '/' . db_query("SELECT IFNULL(SUM(sc.impressions_unique), 0) FROM {simpleads_stats} sc\n      WHERE STR_TO_DATE(sc.date, '%Y%m%d') <= NOW() AND STR_TO_DATE(sc.date, '%Y%m%d') >= SUBDATE(NOW(), INTERVAL 1 YEAR)\n      AND sc.nid = :nid", array(
      ':nid' => $nid,
    ))
      ->fetchField();
    $stats['All Time'] = db_query("SELECT IFNULL(SUM(sc.impressions), 0) FROM {simpleads_stats} sc WHERE sc.nid = :nid", array(
      ':nid' => $nid,
    ))
      ->fetchField() . '/' . db_query("SELECT IFNULL(SUM(sc.impressions_unique), 0) FROM {simpleads_stats} sc WHERE sc.nid = :nid", array(
      ':nid' => $nid,
    ))
      ->fetchField();
  }
  t('Yesterday');
  t('Last Week');
  t('Last Month');
  t('3 Months');
  t('6 Months');
  t('1 year');
  t('All Time');
  return $stats;
}