You are here

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

Adds an event to the calendar

Parameters

RoomsEventInterface $event: An an event of type BookingEvent

Overrides RoomsCalendarInterface::addMonthEvent

2 calls to RoomsCalendar::addMonthEvent()
UnitCalendar::updateCalendar in modules/rooms_availability/includes/rooms_availability.unit_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
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

includes/rooms.calendar.inc, line 38

Class

RoomsCalendar
Handles querying and updating the availability information relative to a single bookable unit.

Code

public function addMonthEvent(RoomsEventInterface $event) {

  // First check if the month exists and do an update if so
  if ($this
    ->monthDefined($event
    ->startMonth(), $event
    ->startYear())) {
    $partial_month_row = $this
      ->preparePartialMonthArray($event);
    $update = db_update($this->base_table)
      ->condition('unit_id', $this->unit_id)
      ->condition('month', $event
      ->startMonth())
      ->condition('year', $event
      ->startYear())
      ->fields($partial_month_row)
      ->execute();
  }
  else {

    // Prepare the days array
    $days = $this
      ->prepareFullMonthArray($event);
    $month_row = array(
      'unit_id' => $this->unit_id,
      'year' => $event
        ->startYear(),
      'month' => $event
        ->startMonth(),
    );
    $month_row = array_merge($month_row, $days);
    $insert = db_insert($this->base_table)
      ->fields($month_row);
    $insert
      ->execute();
  }
}