You are here

function bat_event_save_state in Booking and Availability Management Tools for Drupal 7

Same name and namespace in other branches
  1. 8 modules/bat_event/bat_event.module \bat_event_save_state()

Parameters

array $event_state:

string $event_type:

4 calls to bat_event_save_state()
BatEventTypeController::import in modules/bat_event/bat_event.module
bat_booking_example_create_standard_event_states in modules/bat_booking/bat_booking_example/bat_booking_example.install
Creates the default event states.
bat_event_states_form_submit in modules/bat_event/bat_event.module
Form submit for event states management.
bat_event_update_7102 in modules/bat_event/bat_event.install
Generate machine names for the existing states.

File

modules/bat_event/bat_event.module, line 567
Manage Events - Events store the EventValue of a Unit over a period of time.

Code

function bat_event_save_state($event_state, $event_type) {
  if (!empty($event_state['id'])) {
    db_merge('bat_event_state')
      ->fields(array(
      'machine_name' => $event_state['machine_name'],
      'label' => $event_state['label'],
      'color' => $event_state['color'],
      'calendar_label' => $event_state['calendar_label'],
      'blocking' => $event_state['blocking'],
    ))
      ->condition('id', $event_state['id'])
      ->execute();
  }
  elseif (!empty($event_state['machine_name']) && bat_event_load_state_by_machine_name($event_state['machine_name'])) {
    db_merge('bat_event_state')
      ->fields(array(
      'label' => $event_state['label'],
      'color' => $event_state['color'],
      'calendar_label' => $event_state['calendar_label'],
      'blocking' => $event_state['blocking'],
    ))
      ->condition('machine_name', $event_state['machine_name'])
      ->execute();
  }
  else {
    $max_id = db_query("SELECT MAX(id) as max_id FROM {bat_event_state}")
      ->fetchCol();
    $event_state['id'] = reset($max_id) + 1;
    $event_state['event_type'] = $event_type;
    drupal_write_record('bat_event_state', $event_state);
  }
  drupal_static_reset('bat_event_get_states');
  drupal_static_reset('bat_event_load_state_by_machine_name');
}