Browse Source

updated so daily and open limits work

d9
ppound 3 years ago
parent
commit
a8d6753add
  1. 31
      reservation.inc
  2. 14
      reserve.inc

31
reservation.inc

@ -18,7 +18,7 @@ function reserve_form_reserve_reservation_form_alter(array &$form, FormStateInte
// Retrieve an array which contains the path pieces. // Retrieve an array which contains the path pieces.
$current_path = \Drupal::service('path.current')->getPath(); $current_path = \Drupal::service('path.current')->getPath();
$path_args = explode('/', $current_path); $path_args = explode('/', $current_path);
// for case of std reservation add form - this should likely be blocked; but leave for development // for case of std reservation add form - this should likely be blocked; but leave for development
if (count($path_args) <= 3) return; if (count($path_args) <= 3) return;
@ -62,7 +62,34 @@ function reserve_form_reserve_reservation_form_alter(array &$form, FormStateInte
$yyyymmdd = date('Y-m-d', strtotime($year . '-' . $month . '-' . $day)); $yyyymmdd = date('Y-m-d', strtotime($year . '-' . $month . '-' . $day));
$d = $yyyymmdd . ' 00:00:00'; $d = $yyyymmdd . ' 00:00:00';
} }
if(reserve_daily_max_exceeded($yyyymmdd)) {
$form = array();
$form['message'] = [
'#type' => 'markup',
'#weight' => -25,
'#markup' => '
<div class="messages__wrapper layout-container">
<div role="contentinfo" aria-label="Warning message" class="messages messages--warning">' .
'You have exceeded the max number of daily bookings. Unable to add reservation'.
'</div></div>',
];
return;
}
$config = \Drupal::config('reserve.settings');
$max_per_user = $config->get('reservations_per_user');
if(count(reserve_user_reservations()) > $max_per_user){
$form = array();
$form['message'] = [
'#type' => 'markup',
'#weight' => -25,
'#markup' => '
<div class="messages__wrapper layout-container">
<div role="contentinfo" aria-label="Warning message" class="messages messages--warning">' .
'You have exceeded your max number of open bookings. Unable to add reservation'.
'</div></div>',
];
return;
}
$entity = \Drupal::entityTypeManager()->getStorage($entity_type)->load($eid); $entity = \Drupal::entityTypeManager()->getStorage($entity_type)->load($eid);
$bundle = $entity->bundle(); $bundle = $entity->bundle();
$date = date('l, M d, Y', strtotime($d)); $date = date('l, M d, Y', strtotime($d));

14
reserve.inc

@ -923,24 +923,22 @@ function reserve_valid_lengths($rid, $ebundle, $yyyy_mmdd, $time, $id = NULL, $a
* FALSE - the maximum has not been exceeded. * FALSE - the maximum has not been exceeded.
*/ */
function reserve_daily_max_exceeded($yyyy_mmdd) { function reserve_daily_max_exceeded($yyyy_mmdd) {
global $user; $user = \Drupal::currentUser();
$config = \Drupal::config('reserve.settings'); $config = \Drupal::config('reserve.settings');
$max = $config->get('reservations_per_day'); $max = $config->get('reservations_per_day');
if (!$max) { if (!$max) {
return FALSE; return FALSE;
} }
$record_count = 0; $record_count = 0;
if ($user->uid) { if ($user->id()) {
$ids = \Drupal::service('entity_type.manager') $ids = \Drupal::service('entity_type.manager')
->getStorage('reserve_reservation')->getQuery() ->getStorage('reserve_reservation')->getQuery()
->condition('user_id', $user->id) ->condition('user_id', $user->id())
->condition('reservation_date', 'value', $yyyy_mmdd . '%', 'like') ->condition('reservation_date', $yyyy_mmdd . '%', 'like')
->execute(); ->execute();
$record_count = count($ids); $record_count = count($ids);
} }
debug($record_count, 'pp-record-count', TRUE);
if ($record_count < $max) { if ($record_count < $max) {
return FALSE; return FALSE;
} }

Loading…
Cancel
Save