You are here

public function RoomsBookingController::delete_event in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7

1 call to RoomsBookingController::delete_event()
RoomsBookingController::delete in modules/rooms_booking/rooms_booking.module
Implements EntityAPIControllerInterface.

File

modules/rooms_booking/rooms_booking.module, line 1136
Manage Bookings - Bookings are tied to a customer profile and possible a Unit ID and Order ID.

Class

RoomsBookingController
The Controller for RoomsBooking entities.

Code

public function delete_event($booking) {

  // Check if the booking had a unit associated with it and if so update the
  // availability calendar.
  if (isset($booking->unit_id) && isset($booking->start_date) && isset($booking->end_date)) {
    $uc = new UnitCalendar($booking->unit_id);

    // We are not concerned with the state of the event id (confirmed or
    // unconfirmed here) because we will unlock it no matter what (we look for
    // absolute value).
    $event_id = rooms_availability_assign_id($booking->booking_id);

    // Create an event representing the event to remove.
    $start_date = $booking->start_date_object;
    $end_date = $booking->end_date_object;

    // Remove a day from end date to represent the actual event.
    $end_date
      ->sub(new DateInterval('P1D'));
    $be = new BookingEvent($booking->unit_id, $event_id, $start_date, $end_date);
    $uc
      ->removeEvents(array(
      $be,
    ));
  }
}