You are here

function availability_calendars_schema in Availability Calendars 6.2

Same name and namespace in other branches
  1. 6 availability_calendars.install \availability_calendars_schema()
  2. 7.2 availability_calendars.install \availability_calendars_schema()

Implements hook_schema().

2 calls to availability_calendars_schema()
availability_calendars_update_6200 in ./availability_calendars.install
Add custom states (issue #306461)
availability_calendars_update_7204 in ./availability_calendars.install
Add a boolean field indicating if a state "is available" to the states table of Availability Calendars.

File

./availability_calendars.install, line 14
Install, update and uninstall functions for the Availability Calendars module.

Code

function availability_calendars_schema() {
  $schema = array();
  $schema['availability_calendars_day'] = array(
    'description' => 'The table with availability states per day.',
    'fields' => array(
      'nid' => array(
        'description' => 'The primary identifier for a node.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      // [#747036]: using date instead of separate fields allows for better querying
      // [#1083198]: Mysql, pgsql, mssql, and oracle support DATE type. Sqlite uses TEXT as type but has a lot of date functions
      // 'yyyy-mm-dd' (iso 8601) is accepted by mysql, pgsql, mssql, sqlite. For oracle I could not find this information.
      // The 'between' operator is inclusive on both sides on all databases: date between from and to  <=>  from <= date and date <= to
      'date' => array(
        'description' => 'Date of availability state.',
        'mysql_type' => 'DATE',
        'pgsql_type' => 'DATE',
        'sqlite_type' => 'TEXT',
        // SQLite does not have a DATE type
        'not null' => TRUE,
      ),
      'status' => array(
        'description' => 'The status.',
        'type' => 'varchar',
        'length' => 55,
      ),
    ),
    'primary key' => array(
      'nid',
      'date',
    ),
    'indexes' => array(
      'availability_calendars_availability_date' => array(
        'date',
        'nid',
      ),
    ),
  );
  $schema['availability_calendars_week'] = array(
    'description' => 'The table for calendar week notes.',
    'fields' => array(
      'nid' => array(
        'description' => 'The primary identifier for a node.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'year' => array(
        'description' => 'The number of the year.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'month' => array(
        'description' => 'The number of the month.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'week' => array(
        'description' => 'The number of the week.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'note' => array(
        'description' => 'The note.',
        'type' => 'varchar',
        'length' => 200,
      ),
    ),
    'primary key' => array(
      'nid',
      'year',
      'month',
      'week',
    ),
  );
  $schema['availability_calendars_states'] = array(
    'description' => 'Store classes and labels for the possible states in availability calendars',
    'fields' => array(
      'class' => array(
        'description' => 'The class used for this state',
        'type' => 'varchar',
        'length' => 24,
        'not null' => TRUE,
      ),
      'label' => array(
        'description' => 'The label as displayed to users for this state',
        'type' => 'varchar',
        'length' => 64,
        // should not be too long: will give display problems
        'not null' => TRUE,
      ),
      'weight' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
        'description' => 'The weight of this state',
      ),
      'is_available' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Boolean indicating whether this state is to be treated as available',
      ),
    ),
    'primary key' => array(
      'class',
    ),
  );
  return $schema;
}