You are here

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

Given a date range returns an array of RoomEvents. The heavy lifting really takes place in the getRawDayData function - here we are simply acting as a factory for event objects

Parameters

$start_date: The starting date

$end_date: The end date of our range

Return value

RoomsEventInterface[] An array of BookingEvent objects

Overrides RoomsCalendar::getEvents

File

modules/rooms_availability/includes/rooms_availability.unit_calendar.inc, line 91
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 getEvents(DateTime $start_date, DateTime $end_date) {

  // Get the raw day results.
  $results = $this
    ->getRawDayData($start_date, $end_date);
  $events = array();
  foreach ($results[$this->unit_id] as $year => $months) {
    foreach ($months as $mid => $month) {

      // The event array returns the start days for each event within a month.
      $start_days = array_keys($month['states']);
      foreach ($month['states'] as $state) {

        // Create a booking event.
        $start = $state['start_day'];
        $end = $state['end_day'];
        $sd = new DateTime("{$year}-{$mid}-{$start}");
        $ed = new DateTime("{$year}-{$mid}-{$end}");
        $bookingevent_class = variable_get('rooms_bookingevent_class', 'BookingEvent');
        $event = new $bookingevent_class($this->unit_id, $state['state'], $sd, $ed);
        $events[] = $event;
      }
    }
  }
  return $events;
}