function rooms_booking_manager_results_page in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7
Constructs the booking results page following an availability search.
Parameters
DateTime $start_date: Start date for the search.
DateTime $end_date: End date for the search.
int $booking_units: In how many units are we to accommodate them.
Return value
string The themed result page string.
1 string reference to 'rooms_booking_manager_results_page'
- rooms_booking_manager_menu in modules/
rooms_booking_manager/ rooms_booking_manager.module - Implements hook_menu().
File
- modules/
rooms_booking_manager/ rooms_booking_manager.module, line 414 - Rooms Booking Manager brings together all the pieces required to find a room and book it - including the DrupalCommerce integration
Code
function rooms_booking_manager_results_page(DateTime $start_date, DateTime $end_date, $booking_units = 1, $single_day_bookings = FALSE) {
// Validate the dates.
$errors = rooms_check_dates_validity($start_date, $end_date, TRUE, $single_day_bookings);
// Check validity of the rest of the booking parameters that are stored in
// $_GET. Again this is to ensure that any direct links were structured
// appropriately.
$booking_parameters = rooms_booking_manager_retrieve_booking_parameters($booking_units, $_GET);
// The array of content to render.
$content = array();
// Add dates information to template.
if (!empty($start_date) && !empty($end_date)) {
$content['start_date'] = $start_date;
$content['end_date'] = $end_date;
$content['nights'] = $end_date
->diff($start_date)->days;
}
if (empty($errors) && is_array($booking_parameters)) {
$content['booking_results'] = 1;
$unit_types = array();
$type = '';
if (isset($_GET['type'])) {
$type = check_plain($_GET['type']);
if ($_GET['type'] == 'all') {
$types = variable_get('rooms_unit_type_selector', array());
foreach ($types as $element) {
$unit_types[] = $element;
}
}
else {
$type = check_plain($_GET['type']);
if (rooms_unit_type_load($type) !== FALSE) {
$unit_types[] = $type;
}
}
}
// Get all the units.
$agent = new AvailabilityAgent($start_date, $end_date, $booking_parameters, $booking_units, array_keys(array_filter(variable_get('rooms_valid_availability_states', drupal_map_assoc(array(
ROOMS_AVAILABLE,
ROOMS_ON_REQUEST,
))))), $unit_types);
$units_per_type = $agent
->checkAvailability();
// Give other modules a chance to change the search results.
drupal_alter('rooms_booking_results', $units_per_type, $start_date, $end_date, $booking_parameters);
// If we don't have any useful result to show just display a failure message
// and the search form.
if ($units_per_type == ROOMS_NO_ROOMS || $units_per_type == ROOMS_SIZE_FAILURE) {
$content['booking_results'] = 0;
// Add the search availability form.
module_load_include('inc', 'rooms_booking_manager', 'rooms_booking_manager.availability_search');
$booking_search_form = drupal_get_form('rooms_booking_availability_search_form_page');
// Alter the page title.
drupal_set_title(variable_get_value('rooms_booking_manager_create_your_booking'));
// Store and clean old messages.
$old_messages = drupal_get_messages();
// Create a warning message.
drupal_set_message(variable_get_value('rooms_booking_manager_warning_no_units_available'), 'warning');
// Show the themed warning message inside our form.
$content['no_results'] = array(
'#prefix' => '<div class="no-booking-data">',
'#markup' => theme('status_messages'),
'#suffix' => '</div>',
);
// Restore old messages.
$_SESSION['messages'] = $old_messages;
$content['booking_search_form'] = $booking_search_form;
}
elseif (variable_get('rooms_presentation_style', ROOMS_PER_TYPE) == ROOMS_PER_TYPE) {
// Alter the page title.
drupal_set_title(variable_get_value('rooms_booking_manager_select_your_stay'));
$content = rooms_booking_manager_present_types($units_per_type, $content, $start_date, $end_date, $booking_parameters, $booking_units, $type);
}
elseif (variable_get('rooms_presentation_style', ROOMS_PER_TYPE) == ROOMS_INDIVIDUAL) {
// Alter the page title.
drupal_set_title(variable_get_value('rooms_booking_manager_select_your_stay'));
$content = rooms_booking_manager_present_individual_rooms($units_per_type, $content, $start_date, $end_date, $booking_parameters);
}
}
else {
drupal_set_message(t('Perform a search to get availability information'));
drupal_goto('booking');
exit;
}
$type = '';
if (isset($_GET['type'])) {
$type = check_plain($_GET['type']);
if ($type == '' || rooms_unit_type_load($type) === FALSE) {
$type = '';
}
}
if ($content['booking_results']) {
$content['change_search'] = drupal_get_form('rooms_booking_manager_change_search_form', $start_date, $end_date, $booking_parameters, $booking_units, $type);
}
return theme('rooms_booking_results', $content);
}