@ -1,5 +1,4 @@
<?php
<?php
use Drupal\field\Entity\FieldConfig;
/**
/**
* @file
* @file
* Classes and general Room Reservations helper functions.
* Classes and general Room Reservations helper functions.
@ -22,13 +21,13 @@ function reserve_categories($ebundle = null) {
$entity_type = ebundle_split($ebundle, 'type');
$entity_type = ebundle_split($ebundle, 'type');
$bundle = ebundle_split($ebundle, 'bundle');
$bundle = ebundle_split($ebundle, 'bundle');
$field = reserve_category_fields($ebundle);
$field = reserve_category_fields($ebundle);
$fconfig = FieldConfig::loadByName($entity_type, $bundle, $field)->getSettings();
$fconfig = \Drupal\field\Entity\ FieldConfig::loadByName($entity_type, $bundle, $field)->getSettings();
$ids = array_filter($fconfig['categories']);
$ids = array_filter($fconfig['categories']);
}
}
else {
else {
$query = \Drupal::service('entity_type.manager')
$query = \Drupal::service('entity_type.manager')
->getStorage('reserve_category')->getQuery();
->getStorage('reserve_category')->getQuery();
$ids = $query->condition('status', TRUE)->accessCheck(FALSE)-> execute();
$ids = $query->condition('status', TRUE)->execute();
}
}
$cats = \Drupal::entityTypeManager()->getStorage('reserve_category')->loadMultiple($ids);
$cats = \Drupal::entityTypeManager()->getStorage('reserve_category')->loadMultiple($ids);
@ -67,7 +66,7 @@ function reserve_entities($ebundle) {
}
}
//->sort('reservations_display_order', 'ASC')
//->sort('reservations_display_order', 'ASC')
$ids = $query->accessCheck(FALSE)-> execute();
$ids = $query->execute();
$entities = \Drupal::entityTypeManager()->getStorage($entity_type)->loadMultiple($ids);
$entities = \Drupal::entityTypeManager()->getStorage($entity_type)->loadMultiple($ids);
@ -354,8 +353,8 @@ function reserve_facility_hours($date, $reset = FALSE) {
$year = substr($month, 0, 4);
$year = substr($month, 0, 4);
$mo_hours = reserve_default_monthly_hours($year, $m);
$mo_hours = reserve_default_monthly_hours($year, $m);
}
}
$start = ($day - 1) * 5;
$start = ($day - 1) * 5;
$first_shift_open = $mo_hours[$start + 1];
$first_shift_open = $mo_hours[$start + 1];
$first_shift_close = $mo_hours[$start + 2];
$first_shift_close = $mo_hours[$start + 2];
$second_shift_open = $mo_hours[$start + 3];
$second_shift_open = $mo_hours[$start + 3];
@ -697,7 +696,7 @@ function reserve_start_conflicts($room, $yyyy_mmdd, $time) {
)
)
";
";
$conflicts_found = FALSE;
$conflicts_found = FALSE;
$conflicts_found = \Drupal::database()-> query($sql, array(
$conflicts_found = db_ query($sql, array(
':room' => $room,
':room' => $room,
':date0' => $search_items[0]['date'], ':time0' => $search_items[0]['start_time'], ':length0' => $search_items[0]['length'],
':date0' => $search_items[0]['date'], ':time0' => $search_items[0]['start_time'], ':length0' => $search_items[0]['length'],
':date1' => $search_items[1]['date'], ':time1' => $search_items[1]['start_time'], ':length1' => $search_items[1]['length'],
':date1' => $search_items[1]['date'], ':time1' => $search_items[1]['start_time'], ':length1' => $search_items[1]['length'],
@ -706,7 +705,8 @@ function reserve_start_conflicts($room, $yyyy_mmdd, $time) {
':date4' => $search_items[4]['date'], ':time4' => $search_items[4]['start_time'], ':length4' => $search_items[4]['length'],
':date4' => $search_items[4]['date'], ':time4' => $search_items[4]['start_time'], ':length4' => $search_items[4]['length'],
':date5' => $search_items[5]['date'], ':time5' => $search_items[5]['start_time'], ':length5' => $search_items[5]['length'],
':date5' => $search_items[5]['date'], ':time5' => $search_items[5]['start_time'], ':length5' => $search_items[5]['length'],
':date6' => $search_items[6]['date'], ':time6' => $search_items[6]['start_time'], ':length6' => $search_items[6]['length'],
':date6' => $search_items[6]['date'], ':time6' => $search_items[6]['start_time'], ':length6' => $search_items[6]['length'],
':date7' => $search_items[7]['date'], ':time7' => $search_items[7]['start_time'], ':length7' => $search_items[7]['length']))->rowCount();
':date7' => $search_items[7]['date'], ':time7' => $search_items[7]['start_time'], ':length7' => $search_items[7]['length'])
)->rowCount();
return $conflicts_found;
return $conflicts_found;
}
}
@ -923,7 +923,7 @@ 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) {
$user = \Drupal::currentUser();
$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) {
@ -933,7 +933,6 @@ function reserve_daily_max_exceeded($yyyy_mmdd) {
if ($user->id()) {
if ($user->id()) {
$ids = \Drupal::service('entity_type.manager')
$ids = \Drupal::service('entity_type.manager')
->getStorage('reserve_reservation')->getQuery()
->getStorage('reserve_reservation')->getQuery()
->accessCheck(FALSE)
->condition('user_id', $user->id())
->condition('user_id', $user->id())
->condition('reservation_date', $yyyy_mmdd . '%', 'like')
->condition('reservation_date', $yyyy_mmdd . '%', 'like')
->execute();
->execute();
@ -967,7 +966,6 @@ function reserve_user_reservations() {
$latest_date = date('Y-m-d', strtotime("now +13 days"));
$latest_date = date('Y-m-d', strtotime("now +13 days"));
$ids = \Drupal::service('entity_type.manager')
$ids = \Drupal::service('entity_type.manager')
->getStorage('reserve_reservation')->getQuery()
->getStorage('reserve_reservation')->getQuery()
->accessCheck(TRUE)
->condition('user_id', $user->id())
->condition('user_id', $user->id())
->condition('reservation_date', $earliest_date, '>=')
->condition('reservation_date', $earliest_date, '>=')
->condition('reservation_date', $latest_date, '< =')
->condition('reservation_date', $latest_date, '< =')