You are here

public function BatEventController::deleteEvent in Booking and Availability Management Tools for Drupal 7

Parameters

BatEvent $event:

1 call to BatEventController::deleteEvent()
BatEventController::delete in modules/bat_event/bat_event.module

File

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

Class

BatEventController
The Controller for BatEvent entities.

Code

public function deleteEvent(BatEvent $event) {
  $event_type = 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->target_entity_type . '_reference';

  // Check if the event had a unit associated with it and if so update the
  // availability calendar.
  if (field_get_items('bat_event', $event, $target_field_name) !== FALSE && isset($event->start_date) && isset($event->end_date)) {
    $event_target_entity_reference = field_get_items('bat_event', $event, $target_field_name);
    $target_entity_id = $event_target_entity_reference[0]['target_id'];

    // Load the referenced entity.
    if ($target_entity = entity_load_single($event_type->target_entity_type, $target_entity_id)) {
      $unit = new Unit($target_entity_id, $target_entity
        ->getEventDefaultValue($event->type));
      $this
        ->batStoreSave($unit, clone $event->start_date_object, clone $event->end_date_object, $event->type, $event_type->event_granularity, $unit
        ->getDefaultValue(), $event->event_id, TRUE);
    }
  }
}