You are here

ad_image.install in Advertisement 7

Ad_image module database schema.

File

image/ad_image.install
View source
<?php

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

/**
 * Implementation of hook_schema().
 */
function ad_image_schema() {
  $schema['ad_image'] = array(
    'description' => 'The ad_image table stores image information such as file ID, title, width, height of corresponding image ads.',
    'fields' => array(
      'aid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'fid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'url' => array(
        'type' => 'varchar',
        'length' => '255',
        'not null' => TRUE,
        'default' => '',
      ),
      'tooltip' => array(
        'type' => 'varchar',
        'length' => '255',
        'not null' => TRUE,
        'default' => '',
      ),
      'remote_image' => array(
        'type' => 'varchar',
        'length' => '255',
        'not null' => TRUE,
        'default' => '',
      ),
      'width' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'height' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'unique keys' => array(
      'aid' => array(
        'aid',
      ),
    ),
  );
  $schema['ad_image_format'] = array(
    'description' => 'The ad_image_format table stores dimensions for image ads.',
    'fields' => array(
      'gid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'min_width' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'max_width' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'min_height' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'max_height' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'max_size' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'gid',
    ),
  );
  return $schema;
}

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

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

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

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

/**
 * Implements hook_uninstall().
 */
function ad_image_uninstall() {
  $result = db_query('SELECT nid FROM {node} n WHERE n.type = :type', array(
    ':type' => 'distribution',
  ));
  $nids = array();
  foreach ($result as $row) {
    $nids[] = $row->nid;
  }

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

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

  // Purge all field infromation
  field_purge_batch(1000);

  // Delete all ad_image content.
  $result = db_query("SELECT aid FROM {ad_image}");
  foreach ($result as $row) {
    node_delete($row->aid);
  }
}
function _ad_image_installed_fields() {
  return array(
    'field_ad_image' => array(
      'translatable' => '0',
      'entity_types' => array(),
      'settings' => array(
        'uri_scheme' => 'public',
        'default_image' => 0,
      ),
      'indexes' => array(
        'fid' => array(
          0 => 'fid',
        ),
      ),
      'field_name' => 'field_ad_image',
      'type' => 'image',
      'module' => 'image',
      'active' => '1',
      'locked' => '0',
      'cardinality' => 1,
    ),
  );
}
function _ad_image_installed_instances() {
  $t = get_t();
  return array(
    'field_ad_image' => array(
      'label' => $t('Advertisement image'),
      'widget' => array(
        'weight' => '-4',
        'type' => 'image_image',
        'module' => 'image',
        'active' => 1,
        'settings' => array(
          'progress_indicator' => 'throbber',
          'preview_image_style' => 'thumbnail',
        ),
      ),
      'settings' => array(
        'file_directory' => '',
        'file_extensions' => 'png gif jpg jpeg',
        'max_filesize' => '',
        'max_resolution' => '',
        'min_resolution' => '',
        'alt_field' => 0,
        'title_field' => 0,
        'default_image' => 0,
        'user_register_form' => FALSE,
      ),
      'display' => array(
        'default' => array(
          'label' => 'hidden',
          'type' => 'image',
          'weight' => '0',
          'settings' => array(
            'image_style' => '',
            'image_link' => '',
          ),
          'module' => 'image',
        ),
        'teaser' => array(
          'label' => 'hidden',
          'type' => 'hidden',
          'weight' => '0',
          'settings' => array(),
        ),
      ),
      'required' => 0,
      'description' => '',
      'field_name' => 'field_ad_image',
      'entity_type' => 'node',
      'bundle' => 'ad',
    ),
  );
}