You are here

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

Searches for availability inside a set of bookable units.

This function is used to recursively iterate over sets of rooms identifying whether there is a solution across the sets that has at least one option in each set.

Parameters

array $rooms_results: Bookable units to perform the search.

1 call to AvailabilityAgent::searchForAvailability()
AvailabilityAgent::checkAvailability in modules/rooms_booking/includes/rooms_booking.availability_agent.inc
Checks the availability.

File

modules/rooms_booking/includes/rooms_booking.availability_agent.inc, line 143
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

private function searchForAvailability($rooms_results) {
  $rooms_results_keys = array_keys($rooms_results);
  $el_key = array_shift($rooms_results_keys);
  if (!isset($rooms_results[$el_key])) {
    return 0;
  }
  $candidate_keys = array_keys($rooms_results[$el_key]);
  if (empty($candidate_keys)) {
    return 0;
  }
  foreach ($candidate_keys as $c_key) {
    $tmp_rooms_results = $rooms_results;
    foreach ($tmp_rooms_results as $key => $value) {
      if (isset($tmp_rooms_results[$key][$c_key]) && $key != $el_key) {
        unset($tmp_rooms_results[$key][$c_key]);
      }
    }

    // Combination fails, rollback and try a new combination.
    if (empty($tmp_rooms_results[$el_key])) {
      return 0;
    }
    $this->valid_rooms_combination[] = $tmp_rooms_results[$el_key][$c_key];
    unset($tmp_rooms_results[$el_key]);
    if (empty($tmp_rooms_results)) {
      return 1;
    }

    // Call recursively this function.
    $return = $this
      ->searchForAvailability($tmp_rooms_results);
    if ($return == 1) {
      return $return;
    }
  }
}