You are here

analyticdata.inc in Analytics 6

Class definition for analytics.

File

includes/analyticdata.inc
View source
<?php

/**
 * @file
 * Class definition for analytics.
 */
class AnalyticData {
  public $analytic;
  public $event_id;

  /**
   * Public constructor.
   *
   * @param $event_id integer ID of the event.
   */
  public function __construct($event_id = NULL) {
    if ($event_id != NULL) {
      $this
        ->setEventId($event_id);
    }
  }

  /**
   * Setter for event ID.
   *
   * @param $event_id
   */
  public function setEventId($event_id) {
    $this->event_id = $event_id;
    $this->analytic = new Analytic();
    $this->analytic
      ->setEventId($event_id);
  }

  /**
   * Count the total number of instances of this event.
   *
   * @return integer
   */
  public function getCountEventInstance($case = 'all', $condition = NULL) {
    $query = db_select('analytics_event_instance', 'aei')
      ->fields('aei')
      ->condition('event_id', $this->event_id);
    switch ($case) {
      case 'all':
      case 'default':
        break;
      case 'daily':
        if ($condition == NULL) {
          $condition = time();
        }
        $query
          ->condition('date', array(
          date('Y-m-d', $condition),
          date('Y-m-d', $condition + 86400),
        ), 'BETWEEN');
        break;
      case 'weekly':
        if ($condition == NULL) {
          $condition = time();
        }
        $query
          ->condition('week', array(
          date('W', $condition),
          date('W', $condition + 604800),
        ), 'BETWEEN');
        break;
    }
    $count = $query
      ->countQuery()
      ->execute()
      ->fetchField();
    return $count;
  }

  /**
   * Return the name of an event.
   *
   * @return string
   */
  public function getEventName() {
    $name = db_select('analytics_events', 'ae')
      ->fields('ae', array(
      'event_name',
    ))
      ->condition('id', $this->event_id)
      ->range(0, 1)
      ->execute()
      ->fetchField();
    return $name;
  }

  /**
   * Return a list of properties.
   */
  public function getPropertyList() {
    $result = $this->analytic
      ->getProperties();
    $properties = array();
    foreach ($result as $property) {
      $properties[$property['property_instance_id']] = $property['property_name'];
    }
    return $properties;
  }

  /**
   * Return the daily data for an event.
   */
  public function getDailyHistoryEventInstance($start_date = NULL) {
    if ($start_date == NULL) {
      $start_date = strtotime(date('Y-m-d'));
    }
    $data = array();
    for ($i = 6; $i >= 0; $i--) {
      $date = $start_date - 86400 * $i;
      $query = db_select('analytics_event_instance', 'aei')
        ->fields('aei')
        ->condition('event_id', $this->event_id)
        ->condition('date', array(
        date('Y-m-d', $date),
        date('Y-m-d', $date + 86400),
      ), 'BETWEEN');
      $data[$date] = $query
        ->countQuery()
        ->execute()
        ->fetchField();
    }
    return $data;
  }

}

Classes

Namesort descending Description
AnalyticData @file Class definition for analytics.