You are here

function ad_report_bargraph in Advertisement 6.2

Same name and namespace in other branches
  1. 5.2 report/ad_report.module \ad_report_bargraph()
  2. 5 report/ad_report.module \ad_report_bargraph()
  3. 6.3 report/ad_report.module \ad_report_bargraph()
  4. 6 report/ad_report.module \ad_report_bargraph()
  5. 7 report/ad_report.module \ad_report_bargraph()

Page to display ad with bargraph.

1 call to ad_report_bargraph()
ad_report_bargraph_handler in report/ad_report.module

File

report/ad_report.module, line 700
Provides comprehensive charts and reports about advertising statistics.

Code

function ad_report_bargraph($node, $url, $start = 0, $end = 0, $data = array()) {
  $output = '';
  $start_time = strtotime($start);
  $end_time = strtotime($end);
  $elapse = $end_time - $start_time;
  if ($start && $end && $elapse > 0 && $start > 0 && $end > 0) {
    if ($elapse > 86400 * 100) {

      // months
      $segment = 2678400;
    }
    else {
      if ($elapse > 86400 * 5) {

        // days
        $segment = 86400;
      }
      else {

        // hours
        $segment = 3600;
      }
    }
    $max = 0;
    $elements = round($elapse / $segment, 0);
    $space = _ad_report_size($elements);
    $s = $space;
    for ($i = $start_time; $i < $end_time; $i += $segment) {
      $start_date = _ad_report_format_date_db($i);
      $end_date = _ad_report_format_date_db($i + $segment);
      if ($data['i']) {
        $imp = (int) db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date >= %d AND date <= %d", $node->nid, $start_date, $end_date));
        if ($imp > $max) {
          $max = $imp;
        }
        $impressions[] = $imp ? $imp : '0';
      }
      if ($data['c']) {
        $cli = (int) db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'click' AND date >= %d AND date <= %d", $node->nid, $start_date, $end_date));
        if ($cli > $max) {
          $max = $cli;
        }
        $clicks[] = $cli ? $cli : '0';
      }
      if ($s++ >= $space) {
        if ($segment == 3600) {
          $labels[] = date('M j ga', $i);
        }
        else {
          $labels[] = date('M j', $i);
        }
        $s = 0;
      }
      else {
        $labels[] = '';
      }
    }
    $values = array();
    if (!empty($impressions)) {
      $values['impressions'] = $impressions;
    }
    if (!empty($clicks)) {
      $values['clicks'] = $clicks;
    }
    if (!empty($values)) {
      $values['#max'] = $max;
      $values['#labels'] = $labels;
      $values['#title'] = $node->title;
      $values['#node'] = $node;
    }
    $output .= ad_report_generate_bargraph($values);
  }
  $start_date = _ad_report_get_date_from_path($start);
  $end_date = _ad_report_get_date_from_path($end);
  $output .= drupal_get_form('ad_report_range_form', $node, $url, $start_date, $end_date, $data);
  return $output;
}