View source
<?php
function availability_calendar_schema() {
$schema = array();
$schema['availability_calendar_calendar'] = array(
'description' => 'Stores availability calendars.',
'fields' => array(
'cid' => array(
'description' => 'The primary identifier for an availability calendar.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'created' => array(
'description' => 'The Unix timestamp when the calendar was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'changed' => array(
'description' => 'The Unix timestamp when the calendar was most recently saved.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array(
'cid',
),
);
$schema['availability_calendar_availability'] = array(
'description' => 'Stores availability per availability calendar per day.',
'fields' => array(
'cid' => array(
'description' => 'The primary identifier for an availability calendar.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'date' => array(
'description' => 'Date of availability state.',
'mysql_type' => 'DATE',
'pgsql_type' => 'DATE',
'sqlsrv_type' => 'DATE',
'oracle_type' => 'DATE',
'sqlite_type' => 'TEXT',
'type' => 'char',
'length' => '10',
'not null' => TRUE,
),
'sid' => array(
'description' => 'The availability state.',
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
),
),
'primary key' => array(
'cid',
'date',
),
'indexes' => array(
'availability_calendar_availability_date' => array(
'date',
'sid',
),
),
'foreign keys' => array(
'availability_calendar_calendar' => array(
'table' => 'availability_calendar_calendar',
'columns' => array(
'cid' => 'cid',
),
),
'availability_calendar_state' => array(
'table' => 'availability_calendar_state',
'columns' => array(
'sid' => 'sid',
),
),
),
);
$schema['availability_calendar_state'] = array(
'description' => 'Stores defined availability calendar states.',
'fields' => array(
'sid' => array(
'description' => 'The identifier for a state.',
'type' => 'serial',
'size' => 'tiny',
'not null' => TRUE,
),
'css_class' => array(
'description' => 'The CSS class used for this state.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
),
'label' => array(
'description' => 'The label for this state.',
'type' => 'varchar',
'length' => 64,
),
'weight' => array(
'description' => 'The weight of this state.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'is_available' => array(
'description' => 'Boolean indicating whether this state is to be treated as available.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array(
'sid',
),
);
return $schema;
}
function availability_calendar_install() {
$t = get_t();
$states = array(
array(
'sid' => 1,
'css_class' => 'cal-nc',
'label' => 'Not communicated',
'weight' => 1,
'is_available' => 0,
),
array(
'sid' => 2,
'css_class' => 'cal-av',
'label' => 'Available',
'weight' => 2,
'is_available' => 1,
),
array(
'sid' => 3,
'css_class' => 'cal-na',
'label' => 'Fully booked',
'weight' => 3,
'is_available' => 0,
),
array(
'sid' => 4,
'css_class' => 'cal-opt',
'label' => 'Provisionally booked',
'weight' => 4,
'is_available' => 0,
),
);
if (FALSE) {
t('Not Communicated');
t('Available');
t('Fully booked');
t('Provisionally booked');
}
foreach ($states as $state) {
db_insert('availability_calendar_state')
->fields($state)
->execute();
}
variable_set('availability_calendar_styles_generate', 1);
$styles = array(
'table' => array(
'font-size' => 'smaller',
'color' => '#000000',
'background-color' => '',
'border-width' => '1px',
'border-color' => '#000000',
),
'caption' => array(
'font-weight' => 'bold',
'font-style' => 'inherit',
'font-size' => 'smaller',
),
'header' => array(
'height' => '',
'font-weight' => 'bold',
'font-style' => 'inherit',
'font-size' => 'inherit',
'text-align' => 'center',
),
'week_notes' => array(
'width' => '90px',
),
'days' => array(
'width' => '28px',
'height' => '28px',
'text-align' => 'center',
'vertical-align' => 'middle',
),
'states' => array(
'split-day' => '/',
),
);
$styles['states']['cal-nc'] = '#909090';
$styles['states']['cal-av'] = '#90ee90';
$styles['states']['cal-na'] = '#ffb6c1';
$styles['states']['cal-opt'] = '#ffffe0';
variable_set('availability_calendar_styles', $styles);
module_load_include('inc', 'availability_calendar', 'availability_calendar.styles');
availability_calendar_styles_generate();
$link = l($t('Availability Calendar') . ' ' . $t('Settings'), 'admin/config/content/availability-calendar/settings');
drupal_set_message($t("Please visit the '!link' page to define the set of availability states.", array(
'!link' => $link,
)), 'warning');
$link = l($t('Availability Calendar') . ' ' . $t('Styling'), 'admin/config/content/availability-calendar/styling');
drupal_set_message($t("Please visit the '!link' page to generate your own custom CSS file for Availability Calendar.", array(
'!link' => $link,
)), 'warning');
$link1 = l($t('Date and time'), 'admin/config/regional/date-time');
$link2 = l($t('Date and time') . ' - ' . $t('Localize'), 'admin/config/regional/date-time/locale');
drupal_set_message($t("Please visit the '!link1' and !link2 pages to define date formats for Availability Calendar.", array(
'!link1' => $link1,
'!link2' => $link2,
)), 'warning');
}
function availability_calendar_field_schema($field) {
if ($field['type'] == 'availability_calendar') {
return array(
'columns' => array(
'enabled' => array(
'type' => 'int',
'size' => 'tiny',
'default' => 1,
'not null' => TRUE,
),
'name' => array(
'type' => 'varchar',
'length' => 255,
'default' => '',
'not null' => TRUE,
),
'cid' => array(
'type' => 'int',
'not null' => TRUE,
),
),
'indexes' => array(
'cid' => array(
'cid',
),
),
'foreign keys' => array(
'cid' => array(
'table' => 'availability_calendar_calendar',
'columns' => array(
'cid' => 'cid',
),
),
),
);
}
return array();
}
function availability_calendar_uninstall() {
availability_calendar_variable_del_multiple('availability_calendar_');
file_unmanaged_delete_recursive('public://availability_calendar');
}
function availability_calendar_variable_del_multiple($name) {
db_delete('variable')
->condition('name', addcslashes($name, '%_') . '%', 'LIKE')
->execute();
cache_clear_all('variables', 'cache');
}
function availability_calendar_update_7301(&$sandbox) {
module_load_include('inc', 'availability_calendar', 'availability_calendar.styles');
availability_calendar_styles_generate();
}
function availability_calendar_update_7302(&$sandbox) {
$t = get_t();
module_load_include('inc', 'availability_calendar', 'availability_calendar.styles');
availability_calendar_styles_generate();
$link = l('CHANGELOG.txt', drupal_get_path('module', 'availability_calendar') . "/CHANGELOG.txt", array(
'language' => LANGUAGE_NONE,
));
drupal_set_message($t("Availability Calendar: please read the 'Incompatibilities with 7.x-3.x' section in '!link' for a list of actions (like clear caches, set date formats) you have to perform right now to keep this module working.", array(
'!link' => $link,
)), 'warning');
}