Skip to content

Commit

Permalink
Add a permission to enable same-day bookings
Browse files Browse the repository at this point in the history
  • Loading branch information
acrollet committed Jul 9, 2018
1 parent b3490e0 commit 2b55039
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ function rooms_booking_availability_search_form_validate(&$form, &$form_state) {
$diff1 = $now->setTime(0, 0, 0)->diff($start_date);
$rooms_booking_start_date = variable_get('rooms_booking_start_date', 1);
// Check the difference in number of days.
if ($diff1->days < $rooms_booking_start_date) {
if ($diff1->days < $rooms_booking_start_date && !user_access('make same-day bookings')) {
form_set_error('rooms_date_range', t('Bookings must be made at least @count_days in advance.', array('@count_days' => format_plural($rooms_booking_start_date, '1 day', '@count days'))));
}

Expand Down
4 changes: 4 additions & 0 deletions modules/rooms_booking_manager/rooms_booking_manager.module
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ function rooms_booking_manager_permission() {
'title' => t('Book in advance without time limitation'),
'description' => t('Disregards any time limitations for advance bookings'),
),
'make same-day bookings' => array(
'title' => t('Make same-day bookings'),
'description' => t('Disregards the rooms booking start date limitations'),
),
);
return $permissions;
}
Expand Down
20 changes: 17 additions & 3 deletions rooms.module
Original file line number Diff line number Diff line change
Expand Up @@ -844,13 +844,20 @@ function rooms_date_range_fields($year = NULL, $month = NULL) {
$end_date_id = drupal_html_id('datepicker-end-date');
$end_date_selector = '#' . $start_date_id . ' .form-text';

$days_in_advance = '+' . variable_get('rooms_booking_start_date', 1) . 'd';
// Allow users with the "make same-day bookings" permission to make
// bookings starting on any day.
if (user_access('make same-day bookings')) {
$days_in_advance = '+0d';
}

// Specify the default datepicker parameters (see date_popup_element_info())
$datepicker_options = array(
'dateFormat' => date_popup_format_to_popup($date_format),
// Limit bookings to X days in advance, depending on the
// chosen configuration in your Rooms installation, defaults
// to one day in advance.
'minDate' => '+' . variable_get('rooms_booking_start_date', 1) . 'd',
'minDate' => $days_in_advance,
);

if ($year && $month) {
Expand All @@ -869,7 +876,7 @@ function rooms_date_range_fields($year = NULL, $month = NULL) {
}
else {
$datepicker_options += array(
'minDate' => '+' . variable_get('rooms_booking_start_date', 1) . 'd',
'minDate' => $days_in_advance,
);
}

Expand All @@ -888,6 +895,12 @@ function rooms_date_range_fields($year = NULL, $month = NULL) {
'#required' => TRUE,
);

$start_day = variable_get('rooms_booking_start_date', 1);
// Allow users with the "make same-day bookings" permission to make
// bookings starting on any day.
if (user_access('make same-day bookings')) {
$start_day = '0';
}
$date_range_fields['rooms_end_date'] = array(
'#prefix' => '<div class="end-date" id="' . $end_date_id . '">',
'#suffix' => '</div></div>',
Expand All @@ -907,12 +920,13 @@ function rooms_date_range_fields($year = NULL, $month = NULL) {
),
'js' => array(
drupal_get_path('module', 'rooms') . '/js/rooms_date_popup.js',

array(
'data' => array(
'rooms' => array(
'roomsStartYear' => $year,
'roomsStartMonth' => $month,
'roomsBookingStartDay' => variable_get('rooms_booking_start_date', 1),
'roomsBookingStartDay' => $start_day,
'roomsDateFormat' => date_popup_format_to_popup($date_format),

// Here we create a listing of all datepickers registered on the
Expand Down
1 change: 1 addition & 0 deletions rooms_ui.module
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ function rooms_booking_settings($form, &$form_state) {
$form['rooms_booking_settings']['rooms_booking_start_date'] = array(
'#type' => 'select',
'#title' => t('How soon a booking can start'),
'#description' => t('Users with the "Make same-day bookings" permission will not be affected by this setting.'),
'#options' => array(
'0' => t('Same day bookings'),
'1' => t('1 day in advance'),
Expand Down

0 comments on commit 2b55039

Please sign in to comment.