You are here

ad.install in Advertisement 7

Advertisement module database schema.

File

ad.install
View source
<?php

/**
 * @file
 * Advertisement module database schema.
 *
 */

/**
 * Ad module database schema.
 */
function ad_schema() {

  /**
   * The ad table stores administrative information about each ad.  The
   * actual ad itself can be found in the appropriate ad type table.
   */
  $schema['ads'] = array(
    'description' => 'The ad table stores administrative information about each ad.  The actual ad itself can be found in the appropriate ad type table.',
    'fields' => array(
      'aid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
        'description' => 'Unique ad ID. Equals to ad nid.',
      ),
      'uid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
        'description' => 'The {users}.uid that owns this node; initially, this is the user that created it.',
      ),
      'adstatus' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Ad status',
      ),
      'adtype' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Ad type',
      ),
      'redirect' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Ad redirect URL',
      ),
      'autoactivate' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
        'description' => 'Is ad autoactivating?',
      ),
      'autoactivated' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
        'description' => 'Is ad autoactivated?',
      ),
      'autoexpire' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
        'description' => 'Is ad autoexpiring?',
      ),
      'autoexpired' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
        'description' => 'Is ad autoexpired?',
      ),
      'activated' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
        'description' => 'Is ad activated?',
      ),
      'maxviews' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
        'description' => 'Maximum ad impressions',
      ),
      'maxclicks' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
        'description' => 'Maximum ad clicks',
      ),
      'expired' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
        'description' => 'Is ad expired?',
      ),
    ),
    'primary key' => array(
      'aid',
    ),
    'indexes' => array(
      'uid' => array(
        'uid',
      ),
      'autoactivate' => array(
        'autoactivate',
      ),
      'autoactivate' => array(
        'autoactivate',
      ),
    ),
  );

  /**
   * This table counts each time a given action occurs on an ad.  Actions
   * include when the ad is viewed, clicked, enabled and disabled.
   * Statistics are collected at an hourly granularity.
   *
   * The source column is used for tracking statistics for externally
   * hosted ads.
   *
   * Actions:
   *  'view', 'click', 'enable', 'disable'
   */
  $schema['ad_statistics'] = array(
    'description' => 'Stores ad statistics.',
    'fields' => array(
      'sid' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'description' => 'Statistics entry ID.',
      ),
      'aid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
        'description' => 'Ad id.',
      ),
      'date' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
        'description' => 'Date when action was made.',
      ),
      'action' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Actions: "view", "click", "enable", "disable".',
      ),
      'adgroup' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
        'default' => '',
        'description' => 'Ad group.',
      ),
      'hostid' => array(
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Host from which acion was made.',
      ),
      'count' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
        'description' => 'Count of actions triggered.',
      ),
      'extra' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Alow add-on modules to provide additional statistics granularity.',
      ),
    ),
    'primary key' => array(
      'sid',
    ),
    'indexes' => array(
      'aid_date_action' => array(
        'aid',
        'date',
        'action',
      ),
      'date' => array(
        'date',
      ),
      'action' => array(
        'action',
      ),
      'adgroup' => array(
        'adgroup',
      ),
      'hostid' => array(
        'hostid',
      ),
      'extra' => array(
        'extra',
      ),
    ),
  );

  /**
   * The ad_clicks table tracks when a given advertisement was clicked,
   * who clicked it (uid if any and IP address), and what page they were
   * on when they clicked it.
   */
  $schema['ad_clicks'] = array(
    'description' => 'The ad_clicks table tracks when a given advertisement was clicked, who clicked it (uid if any and IP address), and what page they were on when they clicked it.',
    'fields' => array(
      'cid' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'description' => 'Statistics entry ID.',
      ),
      'aid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
        'description' => 'Ad id.',
      ),
      'uid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
        'description' => '',
      ),
      'status' => array(
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
        'description' => '',
      ),
      'hostname' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Host from which acion was made.',
      ),
      'user_agent' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Clicker\'s browser agent.',
      ),
      'adgroup' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Ad group.',
      ),
      'hostid' => array(
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Host from which acion was made.',
      ),
      'url' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
        'default' => '',
        'description' => 'Clicked URL.',
      ),
      'timestamp' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
        'description' => 'Date when action was made.',
      ),
      'extra' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Alow add-on modules to provide additional statistics granularity.',
      ),
    ),
    'primary key' => array(
      'cid',
    ),
    'indexes' => array(
      'aid' => array(
        'aid',
      ),
      'status' => array(
        'status',
      ),
      'hostname' => array(
        'hostname',
      ),
      'user_agent' => array(
        'user_agent',
      ),
      'adgroup' => array(
        'adgroup',
      ),
      'hostid' => array(
        'hostid',
      ),
      'url' => array(
        'url',
      ),
      'extra' => array(
        'extra',
      ),
    ),
  );
  return $schema;
}

/**
 * Implements hook_install().
 */
function ad_install() {

  // Ensure the forum node type is available.
  node_types_rebuild();

  // Create fields
  foreach (_ad_installed_fields() as $field) {
    field_create_field($field);
  }

  // Associate our fields with our content types
  foreach (_ad_installed_instances() as $instance) {
    field_create_instance($instance);
  }
}

/**
 * Allow complete uninstallation of the ad module.
 */
function ad_uninstall() {

  // Delete all ad content.
  $result = db_query("SELECT nid FROM {node} WHERE type = 'ad'");
  while ($node = $result
    ->fetch()) {
    node_delete($node->nid);
    variable_del("ad_autoactivate_warning_{$node->nid}");
  }

  // Delete all remaining ad module variables.
  $variables = array(
    'ad_cron_timestamp',
    'ad_link_target',
    'ad_cache',
    'ad_cache_file',
    'adserve',
    'ad_group_vid',
    'ad_groups',
    'ad_validate_url',
    'ad_display',
  );
  foreach ($variables as $variable) {
    variable_del($variable);
  }
  db_query("DELETE FROM {variable} WHERE name LIKE 'ad_block_quantity_%'");

  // Delete field instances
  $fields = _ad_installed_instances();
  foreach ($fields as $field) {
    field_delete_instance($field);
  }

  // Delete field definitions
  $fields = array_keys(_ad_installed_fields());
  foreach ($fields as $field) {
    field_delete_field($field);
  }

  // Purge all field infromation
  field_purge_batch(1000);
}
function _ad_installed_fields() {
  return array(
    'field_ad_group' => array(
      'translatable' => '0',
      'entity_types' => array(),
      'settings' => array(
        'allowed_values' => array(
          0 => array(
            'vocabulary' => 'ad_group',
            'parent' => '0',
          ),
        ),
      ),
      'indexes' => array(
        'tid' => array(
          0 => 'tid',
        ),
      ),
      'field_name' => 'field_ad_group',
      'type' => 'taxonomy_term_reference',
      'module' => 'taxonomy',
      'active' => '1',
      'locked' => '0',
      'cardinality' => '-1',
      'columns' => array(
        'tid' => array(
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => FALSE,
        ),
      ),
    ),
  );
}
function _ad_installed_instances() {
  $t = get_t();
  return array(
    'field_ad_group' => array(
      'label' => $t('Ad group'),
      'widget' => array(
        'weight' => '-3',
        'type' => 'options_select',
        'module' => 'options',
        'active' => 1,
        'settings' => array(),
      ),
      'settings' => array(
        'user_register_form' => FALSE,
      ),
      'display' => array(
        'default' => array(
          'label' => 'above',
          'type' => 'taxonomy_term_reference_link',
          'settings' => array(),
          'module' => 'taxonomy',
          'weight' => 1,
        ),
        'teaser' => array(
          'type' => 'hidden',
          'label' => 'above',
          'settings' => array(),
          'weight' => 0,
        ),
      ),
      'required' => 0,
      'description' => '',
      'default_value' => NULL,
      'field_name' => 'field_ad_group',
      'entity_type' => 'node',
      'bundle' => 'ad',
    ),
  );
}

Functions

Namesort descending Description
ad_install Implements hook_install().
ad_schema Ad module database schema.
ad_uninstall Allow complete uninstallation of the ad module.
_ad_installed_fields
_ad_installed_instances