You are here

ga_push_browser.module in GA Push 7

Drupal Module: GA Push (browser).

File

modules/browser/ga_push_browser.module
View source
<?php

/**
 * @file
 * Drupal Module: GA Push (browser).
 */

// @TODO: context integration.

/**
 * Implements hook_init().
 */
function ga_push_browser_init() {

  // @TODO: Use Context to add the GA Push Browser Events JS code.
  $query = new EntityFieldQuery();
  $result = $query
    ->entityCondition('entity_type', 'ga_push_browser_event')
    ->propertyCondition('status', 1)
    ->execute();
  $gapb_events = array();
  if (isset($result['ga_push_browser_event'])) {
    $gapb_events_nids = array_keys($result['ga_push_browser_event']);
    $gapb_events = ga_push_browser_event_load_multiple($gapb_events_nids);
    foreach ($gapb_events as $gapb_event) {
      $jsoptions[] = array(
        'selector' => $gapb_event->selector,
        'push' => array(
          $gapb_event->ga_category,
          $gapb_event->ga_action,
          $gapb_event->ga_label,
          $gapb_event->ga_value,
        ),
        'bind' => $gapb_event->bind,
      );
    }
    drupal_add_js(array(
      'ga_push_browser' => $jsoptions,
    ), 'setting');
  }
}

/**
 * Implements hook_entity_info().
 */
function ga_push_browser_entity_info() {
  return array(
    'ga_push_browser_event' => array(
      'label' => t('Ga Push Browser entity'),
      'description' => 'An entity type for Google Analytics Push Browser',
      'entity class' => 'GAPushBrowserEvent',
      'controller class' => 'GAPushBrowserEventController',
      'views controller class' => 'EntityDefaultViewsController',
      'base table' => 'ga_push_browser_event',
      'entity keys' => array(
        'id' => 'id',
      ),
      // Make use the class' label() and uri() implementation by default.
      'label callback' => 'entity_class_label',
      'uri callback' => 'entity_class_uri',
      'access callback' => 'ga_push_browser_event_access',
      'view modes' => array(
        'full' => array(
          'label' => t('Full content'),
          'custom settings' => FALSE,
        ),
      ),
    ),
  );
}

/**
 * Load a single record.
 */
function ga_push_browser_event_load($id, $reset = FALSE) {
  $event = ga_push_browser_event_load_multiple(array(
    $id,
  ), $reset);
  return reset($event);
}

/**
 * Load multiple records.
 */
function ga_push_browser_event_load_multiple($ids = array(), $conditions = array(), $reset = FALSE) {
  return entity_load('ga_push_browser_event', $ids, $conditions, $reset);
}

/**
 * Save the GA Push browser event entity.
 */
function ga_push_browser_event_save($ga_push_browser_event) {
  return entity_save('ga_push_browser_event', $ga_push_browser_event);
}

/**
 * Deletes one single browser event.
 *
 * @param int $ga_push_browser_event_id
 *   The ID of the GA Push browser event to delete.
 *
 * @return bool
 *   TRUE on success, FALSE otherwise.
 */
function ga_push_browser_delete($ga_push_browser_event_id) {
  return entity_delete('ga_push_browser_event', $ga_push_browser_event_id);
}

/**
 * Delete multiple GA Push browser events.
 *
 * @param int $ga_push_browser_event_ids
 *   Array of browser events id to delete.
 *
 * @return bool
 *   TRUE on success, FALSE otherwise.
 */
function ga_push_browser_delete_multiple($ga_push_browser_event_ids) {
  return entity_delete_multiple('ga_push_browser_event', $ga_push_browser_event_ids);
}

/**
 * Implements hook_menu().
 */
function ga_push_browser_menu() {
  $items['admin/config/system/ga-push/browser/add'] = array(
    'title' => 'Ga push: Add browser event',
    'page callback' => 'ga_push_browser_event_add',
    'access arguments' => array(
      'admin ga push',
    ),
    'description' => 'Global configuration of ga push.',
    'file' => 'ga_push_browser.forms.inc',
    'type' => MENU_LOCAL_ACTION,
    'weight' => 3,
  );
  $items['admin/config/system/ga-push/browser/%ga_push_browser_event/edit'] = array(
    'title' => 'Ga push: browser',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'ga_push_browser_event_form',
      5,
    ),
    'access arguments' => array(
      'admin ga push',
    ),
    'description' => 'Global configuration of ga push.',
    'file' => 'ga_push_browser.forms.inc',
    'type' => MENU_CALLBACK,
  );
  $items['admin/config/system/ga-push/browser/%ga_push_browser_event/delete'] = array(
    'title' => 'Delete',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'ga_push_browser_event_confirm_delete_form',
      5,
    ),
    'access arguments' => array(
      'admin ga push',
    ),
    'file' => 'ga_push_browser.forms.inc',
    'type' => MENU_LOCAL_TASK,
  );
  return $items;
}

/**
 * Control the access to the ga push browser event.
 *
 * @global type $user
 *
 * @param string $op
 *   Entity access operation.
 * @param object $event
 *   GA push browser event.
 * @param object $account
 *   User.
 * @param string $entity_type
 *   Entity type.
 *
 * @return bool
 *   Access.
 */
function ga_push_browser_event_access($op, $event, $account = NULL, $entity_type = NULL) {
  global $user;
  if (!isset($account)) {
    $account = $user;
  }
  return user_access('admin ga push', $account);
}

/**
 * Implements hook_views_api().
 */
function ga_push_browser_views_api() {
  return array(
    'api' => 3.0,
    'path' => drupal_get_path('module', 'ga_push_browser') . '/views',
  );
}

Functions

Namesort descending Description
ga_push_browser_delete Deletes one single browser event.
ga_push_browser_delete_multiple Delete multiple GA Push browser events.
ga_push_browser_entity_info Implements hook_entity_info().
ga_push_browser_event_access Control the access to the ga push browser event.
ga_push_browser_event_load Load a single record.
ga_push_browser_event_load_multiple Load multiple records.
ga_push_browser_event_save Save the GA Push browser event entity.
ga_push_browser_init Implements hook_init().
ga_push_browser_menu Implements hook_menu().
ga_push_browser_views_api Implements hook_views_api().