function availability_calendars_update_6200 in Availability Calendars 7.2
Same name and namespace in other branches
- 6.2 availability_calendars.install \availability_calendars_update_6200()
Add custom states (issue #306461)
File
- ./
availability_calendars.install, line 230 - Install, update and uninstall functions for the Availability Calendars module.
Code
function availability_calendars_update_6200(&$sandbox) {
// Change type of field status of table availability_calendars_day,
// as it (kind of) refers to the class field of the new states table
db_change_field('availability_calendars_day', 'status', 'status', array(
'type' => 'varchar',
'length' => 64,
));
// Add table to store configurable statuses
$tables = availability_calendars_schema();
//DRY: get table def from schema
$table_name = 'availability_calendars_states';
db_create_table($table_name, $tables[$table_name]);
// Add existing (hard-coded) states to the database
$states = array(
array(
'class' => 'calavailable',
'label' => 'Available',
'weight' => 1,
),
array(
'class' => 'calnotavailable',
'label' => 'Fully booked',
'weight' => 2,
),
array(
'class' => 'calnotavailableprov',
'label' => 'Provisionally booked',
'weight' => 3,
),
);
foreach ($states as $state) {
db_insert('availability_calendars_states')
->fields($state)
->execute();
}
// Update split statuses: the old way of assembling them did not work any more with configurable states and classes
$split_state_updates = array(
'calsplit cal-available_notavailable' => 'calsplit cal-calavailable_calnotavailable',
'calsplit cal-available_notavailableprov' => 'calsplit cal-calavailable_calnotavailableprov',
'calsplit cal-notavailable_available' => 'calsplit cal-calnotavailable_calavailable',
'calsplit cal-notavailable_notavailableprov' => 'calsplit cal-calnotavailable_calnotavailableprov',
'calsplit cal-notavailableprov_available' => 'calsplit cal-calnotavailableprov_calavailable',
'calsplit cal-notavailableprov_notavailable' => 'calsplit cal-calnotavailableprov_calnotavailable',
);
foreach ($split_state_updates as $state_update_old => $state_update_new) {
db_update('availability_calendars_day')
->fields(array(
'status' => $split_state_update_new,
))
->condition('status', $split_state_update_old)
->execute();
}
}