You are here

public function UnitPricingCalendar::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

2 calls to UnitPricingCalendar::getEvents()
UnitPricingCalendar::calculatePrice in modules/rooms_pricing/includes/rooms_pricing.unit_pricing_calendar.inc
Given a date range determine the cost of the room over that period.
UnitPricingCalendar::updateCalendar in modules/rooms_pricing/includes/rooms_pricing.unit_pricing_calendar.inc
Given an array of RoomEvents the calendar is updated with regards to the events that are relevant to the Unit this calendar refers to

File

modules/rooms_pricing/includes/rooms_pricing.unit_pricing_calendar.inc, line 216
Contains UnitPricingCalendar.

Class

UnitPricingCalendar
Handles querying and updating the pricing 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) {

      // Event array gives us 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}");
        $amount = commerce_currency_amount_to_decimal($state['state'], commerce_default_currency());
        $event = new PricingEvent($this->unit_id, $amount, $sd, $ed);
        $events[] = $event;
      }
    }
  }
  return $events;
}