You are here

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

Given an array of RoomEvents the calendar is updated with regards to the events that are relevant to the Unit this calendar refers to

Parameters

RoomsEventInterface[] $events: An array of events to update the calendar with

Return value

array An array of response on whether event updates were successful or not

Overrides RoomsCalendar::updateCalendar

1 call to UnitCalendar::updateCalendar()
UnitCalendar::removeEvents in modules/rooms_availability/includes/rooms_availability.unit_calendar.inc
Given an array of events removes events from the calendar setting the value to the default.

File

modules/rooms_availability/includes/rooms_availability.unit_calendar.inc, line 345
Class UnitCalendar Handles querying and updating the availability information relative to a single bookable unit.

Class

UnitCalendar
@file Class UnitCalendar Handles querying and updating the availability information relative to a single bookable unit.

Code

public function updateCalendar($events) {
  $response = array();

  // First check that none of the events supplied are blocked by an existing
  // event with a locked status.
  $monthly_events = array();
  foreach ($events as $event) {

    // Make sure event refers to the unit for this calendar.
    if ($event->unit_id == $this->unit_id) {

      // Check if event is not blocked by a locked event.
      if (!$this
        ->eventBlocked($event)) {

        // If the event is in the same month span just queue to be added.
        if ($event
          ->sameMonth()) {
          $monthly_events[] = $event;
        }
        else {

          // Check if multi-year - if not just create monthly events.
          if ($event
            ->sameYear()) {
            $monthly_events_tmp = $event
              ->transformToMonthlyEvents();
            $monthly_events = array_merge($monthly_events, $monthly_events_tmp);
          }
          else {

            // Else transform to single years and then to monthly.
            $yearly_events = $event
              ->transformToYearlyEvents();
            foreach ($yearly_events as $ye) {
              $monthly_events_tmp = $ye
                ->transformToMonthlyEvents();
              $monthly_events = array_merge($monthly_events, $monthly_events_tmp);
            }
          }
        }
      }
      else {
        $response[$event->id] = ROOMS_BLOCKED;
      }
    }
    else {
      $response[$event->id] = ROOMS_WRONG_UNIT;
    }
  }
  foreach ($monthly_events as $event) {
    $this
      ->addMonthEvent($event);
    $response[$event->id] = ROOMS_UPDATED;
  }
  module_invoke_all('rooms_availability_update', $response, $events);
  return $response;
}