You are here

function bat_fullcalendar_ajax_event_status_change in Booking and Availability Management Tools for Drupal 7

The callback for the change_event_status widget of the event manager form.

1 string reference to 'bat_fullcalendar_ajax_event_status_change'
bat_fullcalendar_event_manager_form in modules/bat_fullcalendar/bat_fullcalendar.module
The Event Manager Form.

File

modules/bat_fullcalendar/bat_fullcalendar.module, line 280
Manages the display of FullCalendar and provides ways for other modules to easily modify it.

Code

function bat_fullcalendar_ajax_event_status_change($form, &$form_state) {
  global $user;
  $start_date = $form_state['values']['bat_start_date'];
  $end_date = $form_state['values']['bat_end_date'];
  $entity_id = $form_state['values']['entity_id'];
  $event_id = $form_state['values']['event_id'];
  $event_type = $form_state['values']['event_type'];
  $state_id = $form_state['values']['change_event_status'];
  $event = bat_event_create(array(
    'type' => $event_type,
  ));
  $event->created = REQUEST_TIME;
  $event->uid = $user->uid;
  $event->start_date = $start_date
    ->format('Y-m-d H:i');

  // Always subtract one minute from the end time. FullCalendar provides
  // start and end time with the assumption that the last minute is *excluded*
  // while BAT deals with times assuming that the last minute is included.
  $end_date
    ->sub(new DateInterval('PT1M'));
  $event->end_date = $end_date
    ->format('Y-m-d H:i');
  $event_type_entity = bat_event_type_load($event_type);

  // Construct target entity reference field name using this event type's target entity type.
  $target_field_name = 'event_' . $event_type_entity->target_entity_type . '_reference';
  $event->{$target_field_name}[LANGUAGE_NONE][0]['target_id'] = $entity_id;
  $event->event_state_reference[LANGUAGE_NONE][0]['state_id'] = $state_id;
  $event
    ->save();
  $state_options = bat_unit_state_options($event_type);
  $form['form_wrapper_bottom'] = array(
    '#prefix' => '<div>',
    '#markup' => t('New Event state is <strong>@state</strong>.', array(
      '@state' => $state_options[$state_id],
    )),
    '#suffix' => '</div>',
    '#weight' => 9,
  );
  return $form;
}