You are here

function rooms_booking_edit_form_get_rooms in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7

Returns a set of available units given a unit type, start and end dates.

It makes special provisions for the currently selected unit - to consider that as "available" as well.

Parameters

string $unit_type: The unit type.

RoomsBooking $current_booking: The current booking.

DateTime $start_date: Start date.

DateTime $end_date: End date.

int $group_size: Group size.

int $group_size_children: Number of children in the group.

array $children_age: Children age array.

Return value

array|int Array containing available units or integer to indicate error code.

1 call to rooms_booking_edit_form_get_rooms()
rooms_booking_edit_form in modules/rooms_booking/rooms_booking.admin.inc
Form callback: create or edit a booking.

File

modules/rooms_booking/rooms_booking.admin.inc, line 1070
Rooms editing UI.

Code

function rooms_booking_edit_form_get_rooms($unit_type, $current_booking, $start_date, $end_date, $group_size = 1, $group_size_children = 0, $children_age = array()) {

  // Set the unit types,
  $unit_types = array(
    $unit_type,
  );
  $current_booking_state = '';
  $bookable_units = array();

  // The current unit for this booking should also return as available.
  if (isset($current_booking->booking_status) && isset($current_booking->booking_id)) {
    $current_booking_state = rooms_availability_assign_id($current_booking->booking_id, $current_booking->booking_status);
  }
  $valid_states = array_keys(array_filter(variable_get('rooms_valid_availability_states', drupal_map_assoc(array(
    ROOMS_AVAILABLE,
    ROOMS_ON_REQUEST,
  )))));
  if (variable_get('rooms_price_calculation', ROOMS_PER_NIGHT) == ROOMS_PER_PERSON) {
    $booking_parameters = array(
      array(
        'adults' => $group_size,
        'children' => $group_size_children,
        'childrens_age' => $children_age,
      ),
    );
  }
  else {
    $booking_parameters = array(
      array(
        'adults' => $group_size,
        'children' => $group_size_children,
      ),
    );
  }
  if (!empty($current_booking->booking_id)) {
    $ac = new AvailabilityAgent($start_date, $end_date, $booking_parameters, 1, array_merge($valid_states, array(
      rooms_availability_assign_id($current_booking->booking_id, '0'),
      rooms_availability_assign_id($current_booking->booking_id),
    )), $unit_types);
  }
  else {
    $ac = new AvailabilityAgent($start_date, $end_date, $booking_parameters, 1, array_merge($valid_states, array(
      $current_booking_state,
    )), $unit_types);
  }
  $available_units = $ac
    ->checkAvailability(TRUE);
  if (is_array($available_units)) {
    foreach ($available_units as $type => $units_per_price) {
      foreach ($units_per_price as $price => $units) {
        foreach ($units as $unit_id => $unit) {
          if (rooms_unit_access('update', $unit['unit'])) {
            $bookable_units[$type][$price][$unit_id] = $unit;
          }
        }
      }
    }
  }
  return empty($bookable_units) ? ROOMS_NO_ROOMS : $bookable_units;
}