You are here

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

Checks the availability.

If valid units exist an array keyed by valid unit ids containing unit and the states it holds during the requested period or a message as to what caused the failure.

Parameters

bool $confirmed: Whether include confirmed states or not.

Return value

array|int Bookable units remaining after the filter, error code otherwise.

File

modules/rooms_booking/includes/rooms_booking.availability_agent.inc, line 200
Contains the AvailabilityAgent.

Class

AvailabilityAgent
An AvailabilityAgent provides access to the availability functionality of Rooms and lets you query for availability, get pricing information and create products that can be bought.

Code

public function checkAvailability($confirmed = FALSE) {

  // Determine the types of rooms that qualify - the sleeping potential of the
  // sum of the rooms should satisfy the group size.
  // If no booking_parameters or no group size get all available units.
  if ($this->booking_parameters == array() || $this->booking_units == 0) {
    $results = $this
      ->applyAvailabilityFilter();
    if ($results == ROOMS_NO_ROOMS) {
      return ROOMS_NO_ROOMS;
    }
  }
  else {
    $this->rooms_results = array();
    foreach ($this->booking_parameters as $key => $parameter) {
      $adults = 0;
      $children = 0;
      if (isset($parameter['adults'])) {
        $adults = $parameter['adults'];
      }
      if (isset($parameter['children'])) {
        $children = $parameter['children'];
      }
      $this->rooms_results[$key] = $this
        ->applyAvailabilityFilter(array(), $adults, $children, $confirmed);
    }
    if (!empty($this->rooms_results)) {
      $this->valid_rooms_combination = array();

      // If a valid combination exist for booking request.
      if ($this
        ->searchForAvailability($this->rooms_results) == 1) {
        $results = array();
        foreach ($this->rooms_results as $result) {
          $results = $results + $result;
        }
      }
      else {
        return ROOMS_NO_ROOMS;
      }
    }
    else {
      return ROOMS_NO_ROOMS;
    }
  }

  // Of the rooms that fit the criteria lets see what availability we have.
  $units = $this
    ->getUnitsByPriceType($results);
  if (count($units) == 0) {
    return ROOMS_NO_ROOMS;
  }
  else {
    return $units;
  }
}