From a8d6753add179d6f7f52d8eba7f0d4080a045d07 Mon Sep 17 00:00:00 2001 From: ppound Date: Mon, 23 Aug 2021 15:28:47 -0300 Subject: [PATCH] updated so daily and open limits work --- reservation.inc | 31 +++++++++++++++++++++++++++++-- reserve.inc | 14 ++++++-------- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/reservation.inc b/reservation.inc index 77fb8b0..325d0df 100644 --- a/reservation.inc +++ b/reservation.inc @@ -18,7 +18,7 @@ function reserve_form_reserve_reservation_form_alter(array &$form, FormStateInte // Retrieve an array which contains the path pieces. $current_path = \Drupal::service('path.current')->getPath(); $path_args = explode('/', $current_path); - + // for case of std reservation add form - this should likely be blocked; but leave for development 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)); $d = $yyyymmdd . ' 00:00:00'; } - + if(reserve_daily_max_exceeded($yyyymmdd)) { + $form = array(); + $form['message'] = [ + '#type' => 'markup', + '#weight' => -25, + '#markup' => ' +
+
', + ]; + 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' => ' +
+
', + ]; + return; + } $entity = \Drupal::entityTypeManager()->getStorage($entity_type)->load($eid); $bundle = $entity->bundle(); $date = date('l, M d, Y', strtotime($d)); diff --git a/reserve.inc b/reserve.inc index 9224708..9077517 100644 --- a/reserve.inc +++ b/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. */ function reserve_daily_max_exceeded($yyyy_mmdd) { - global $user; + $user = \Drupal::currentUser(); $config = \Drupal::config('reserve.settings'); - $max = $config->get('reservations_per_day'); if (!$max) { return FALSE; } - $record_count = 0; - if ($user->uid) { - $ids = \Drupal::service('entity_type.manager') + if ($user->id()) { + $ids = \Drupal::service('entity_type.manager') ->getStorage('reserve_reservation')->getQuery() - ->condition('user_id', $user->id) - ->condition('reservation_date', 'value', $yyyy_mmdd . '%', 'like') + ->condition('user_id', $user->id()) + ->condition('reservation_date', $yyyy_mmdd . '%', 'like') ->execute(); $record_count = count($ids); } - + debug($record_count, 'pp-record-count', TRUE); if ($record_count < $max) { return FALSE; }