public function UnitCalendar::stateAvailability in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7
Given a set of states (e.g. the desired states to accept a booking) we compare against the states the unit is actually in.
If the unit is in any state that is not in the list of desired states it means there is a mismatch - hence no availability.
Parameters
DateTime $start_date: The starting date for the search.
DateTime $end_date: The end date for the search.
array $states: The states we are interested in.
Return value
bool Returns true if the date range provided does not have states other than the ones we are interested in
Overrides UnitCalendarInterface::stateAvailability
File
- modules/
rooms_availability/ includes/ rooms_availability.unit_calendar.inc, line 55 - Class UnitCalendar Handles querying and updating the availability information relative to a single bookable unit.
Class
- UnitCalendar
- @file Class UnitCalendar Handles querying and updating the availability information relative to a single bookable unit.
Code
public function stateAvailability(DateTime $start_date, DateTime $end_date, array $states = array()) {
// Get all states in the date range.
$existing_states = $this
->getStates($start_date, $end_date);
// Look at the difference between existing states and states to check.
$diff = array_diff($existing_states, $states);
$valid = count($diff) > 0 ? FALSE : TRUE;
return $valid;
}