@ -1,4 +1,4 @@
<?php
<?php
/**
/**
* Reservation CRUD for supporting Series
* Reservation CRUD for supporting Series
@ -39,7 +39,7 @@ function reserve_reserve_reservation_insert($entity) {
$ebundle = $rtype . '.' . \Drupal::entityTypeManager()
$ebundle = $rtype . '.' . \Drupal::entityTypeManager()
->getStorage($rtype)->load($rid)->bundle();
->getStorage($rtype)->load($rid)->bundle();
$day = date('l', strtotime($start));
$day = date('l', strtotime($start));
$msg = '';
$msg = '';
switch ($repeat_type) {
switch ($repeat_type) {
// every day until....
// every day until....
@ -48,7 +48,7 @@ function reserve_reserve_reservation_insert($entity) {
$back = '-1 day';
$back = '-1 day';
$msg = t('You have booked every day from %start until %end', array('%start' => $start_yyyy_mm_dd, '%end' => $end));
$msg = t('You have booked every day from %start until %end', array('%start' => $start_yyyy_mm_dd, '%end' => $end));
break;
break;
// this day of the week until..
// this day of the week until..
case 2:
case 2:
$skip = '+7 day';
$skip = '+7 day';
@ -70,7 +70,7 @@ function reserve_reserve_reservation_insert($entity) {
$failed = array();
$failed = array();
while (strtotime($date) < = strtotime($back, strtotime($end))) {
while (strtotime($date) < = strtotime($back, strtotime($end))) {
$date = date('Y-m-d', strtotime($skip, strtotime($date)));
$date = date('Y-m-d', strtotime($skip, strtotime($date)));
// must check to see if next booking is available
// must check to see if next booking is available
// the first one we don't check as we could not have picked it if it wasn't
// the first one we don't check as we could not have picked it if it wasn't
if (reserve_is_slot_free($rid, $ebundle, $date, $time, $length)) {
if (reserve_is_slot_free($rid, $ebundle, $date, $time, $length)) {
@ -111,12 +111,12 @@ function reserve_reserve_reservation_update($entity) {
}
}
$sid = $entity->reservation_series_id->getString();
$sid = $entity->reservation_series_id->getString();
// if not part of a Series or special single only url -> do nothing
// if not part of a Series or special single only url -> do nothing
if (!$sid || isset($_GET['single'])) {
if (!$sid || isset($_GET['single'])) {
return;
return;
}
}
// reservation details
// reservation details
$start = $entity->reservation_date->getString();
$start = $entity->reservation_date->getString();
$time = $entity->reservation_time->getString();
$time = $entity->reservation_time->getString();
@ -130,6 +130,7 @@ function reserve_reserve_reservation_update($entity) {
// grab all reservations in this series except the one being submitted
// grab all reservations in this series except the one being submitted
$ids = \Drupal::service('entity_type.manager')
$ids = \Drupal::service('entity_type.manager')
->getStorage('reserve_reservation')->getQuery()
->getStorage('reserve_reservation')->getQuery()
->accessCheck(TRUE)
->condition('status', TRUE)
->condition('status', TRUE)
->condition('reservation_series_id', $sid)
->condition('reservation_series_id', $sid)
->condition('id', $entity->id(), '!=')
->condition('id', $entity->id(), '!=')
@ -162,7 +163,7 @@ function reserve_reserve_reservation_update($entity) {
if (count($failed)) {
if (count($failed)) {
$dates = Markup::create('< br > ' . implode('< br > ', $failed));
$dates = Markup::create('< br > ' . implode('< br > ', $failed));
\Drupal::messenger()->addStatus(t('NOTE: The following dates did not have their length changed due to scheduling conflicts: %dates', array('%dates' => $dates)));
\Drupal::messenger()->addStatus(t('NOTE: The following dates did not have their length changed due to scheduling conflicts: %dates', array('%dates' => $dates)));
}
}
}
}
/**
/**
@ -183,6 +184,7 @@ function _reserve_series_delete($entity) {
// grab all reservations in this series
// grab all reservations in this series
$ids = \Drupal::service('entity_type.manager')
$ids = \Drupal::service('entity_type.manager')
->getStorage('reserve_reservation')->getQuery()
->getStorage('reserve_reservation')->getQuery()
->accessCheck(TRUE)
->condition('reservation_series_id', $sid)
->condition('reservation_series_id', $sid)
->execute();
->execute();
$results = \Drupal::entityTypeManager()->getStorage('reserve_reservation')->loadMultiple($ids);
$results = \Drupal::entityTypeManager()->getStorage('reserve_reservation')->loadMultiple($ids);
@ -190,5 +192,5 @@ function _reserve_series_delete($entity) {
$result->delete();
$result->delete();
}
}
$title = $entity->get('name')->getString();
$title = $entity->get('name')->getString();
\Drupal::messenger()->addStatus(t('The reservation series @title was deleted.', array('@title' => $title)));
\Drupal::messenger()->addStatus(t('The reservation series @title was deleted.', array('@title' => $title)));
}
}