@ -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,15 @@ 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')
$ids = Drupal::service('entity.query')
->getStorage('reserve_category')->getQuery();
->get('reserve_category')
$ids = $query->condition('status', TRUE)->accessCheck(FALSE)->execute();
->condition('status', TRUE)
//->sort('reserve_display_order', 'ASC')
->execute();
}
}
$cats = \Drupal::entityTypeManager()->getStorage('reserve_category')->loadMultiple($ids);
$cats = \Drupal::entityTypeManager()->getStorage('reserve_category')->loadMultiple($ids);
@ -58,16 +59,16 @@ function reserve_categories($ebundle = null) {
function reserve_entities($ebundle) {
function reserve_entities($ebundle) {
$entity_type = ebundle_split($ebundle, 'type');
$entity_type = ebundle_split($ebundle, 'type');
$bundle = ebundle_split($ebundle, 'bundle');
$bundle = ebundle_split($ebundle, 'bundle');
$query = \Drupal::service('entity_type.manager ')
$query = Drupal::service('entity.query ')
->getStorage ($entity_type)->getQuery();
->get($entity_type)
$query ->condition('status', TRUE);
->condition('status', TRUE);
if ($entity_type != $bundle) {
if ($entity_type != $bundle) {
$query->condition('type', $bundle);
$query->condition('type', $bundle);
}
}
//->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);
@ -278,7 +279,7 @@ function reserve_hours($option = NULL) {
}
}
// convert display to 24:00 format if required
// convert display to 24:00 format if required
if ($config->get('hour_format') == 1 ) {
if ($config->get('reserve_ hour_format')) {
$display = date('H:i', strtotime($display));
$display = date('H:i', strtotime($display));
}
}
@ -354,8 +355,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 +698,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 +707,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;
}
}
@ -803,8 +805,9 @@ function reserve_valid_lengths($rid, $ebundle, $yyyy_mmdd, $time, $id = NULL, $a
$start_time = $search_item['start_time'];
$start_time = $search_item['start_time'];
$conflicts_found = false;
$conflicts_found = false;
$query = \Drupal::service('entity_type.manager')
->getStorage('reserve_reservation')->getQuery()
$query = Drupal::service('entity.query')
->get('reserve_reservation')
->condition('reservation_date', $date . '%', 'LIKE')
->condition('reservation_date', $date . '%', 'LIKE')
->condition('reservation_time', $start_time)
->condition('reservation_time', $start_time)
->condition('reservable_id', $rid)
->condition('reservable_id', $rid)
@ -923,22 +926,24 @@ 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() ;
global $user ;
$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->id()) {
if ($user->uid) {
$ids = \Drupal::service('entity_type.manager')
$ids = \Drupal::service('entity.query')
->getStorage('reserve_reservation')->getQuery()
->get('reserve_reservation')
->accessCheck(FALSE)
->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);
}
}
if ($record_count < $max) {
if ($record_count < $max) {
return FALSE;
return FALSE;
}
}
@ -965,9 +970,9 @@ function reserve_user_reservations() {
if ($user->id()) {
if ($user->id()) {
$earliest_date = date('Y-m-d', strtotime(date('Y-m-d')));
$earliest_date = date('Y-m-d', strtotime(date('Y-m-d')));
$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')
->getStorage('reserve_reservation')->getQuery( )
$ids = \Drupal::service('entity.query' )
->accessCheck(TRUE )
->get('reserve_reservation' )
->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, '< =')
@ -1027,7 +1032,7 @@ function reserve_yyyymmdd($month, $day) {
*/
*/
function reserve_get_reserve_bundles() {
function reserve_get_reserve_bundles() {
$bundles = array();
$bundles = array();
$fieldmap = \Drupal::service('entity_field.manager' )->getFieldMap();
$fieldmap = \Drupal::entityManager( )->getFieldMap();
foreach ($fieldmap as $entity_type => $typedef) {
foreach ($fieldmap as $entity_type => $typedef) {
foreach ($typedef as $field) {
foreach ($typedef as $field) {
if ($field['type'] == 'reserve_category') {
if ($field['type'] == 'reserve_category') {
@ -1045,7 +1050,7 @@ function reserve_get_reserve_bundles() {
* OR specific field name if $ebundle is provided (e.g. node.room)
* OR specific field name if $ebundle is provided (e.g. node.room)
*/
*/
function reserve_category_fields($ebundle = NULL) {
function reserve_category_fields($ebundle = NULL) {
$fieldmap = \Drupal::service('entity_field.manager' )->getFieldMap();
$fieldmap = \Drupal::entityManager( )->getFieldMap();
$fields = [];
$fields = [];
foreach ($fieldmap as $entity_type => $typedef) {
foreach ($fieldmap as $entity_type => $typedef) {
foreach ($typedef as $name => $field) {
foreach ($typedef as $name => $field) {
@ -1066,9 +1071,8 @@ function reserve_category_fields($ebundle = NULL) {
function ebundle_split($ebundle, $part) {
function ebundle_split($ebundle, $part) {
$ebits = explode('.', $ebundle);
$ebits = explode('.', $ebundle);
if ($part == 'type' & & isset($ebits[0])) return $ebits[0];
if ($part == 'type') return $ebits[0];
if ($part == 'bundle' & & isset($ebits[1])) return $ebits[1];
if ($part == 'bundle') return $ebits[1];
return NULL;
}
}
/*
/*
@ -1093,7 +1097,7 @@ function reserve_which_year($month, $day) {
// determine if this year or next year
// determine if this year or next year
$yearnow = date('Y');
$yearnow = date('Y');
$absdaynow = date('z');
$absdaynow = date('z');
$absdaydefault = date('z', mktime(0, 0, 0, (int) $month, (int) $day, $yearnow));
$absdaydefault = date('z', mktime(0, 0, 0, $month, $day, $yearnow));
if ($absdaynow > $absdaydefault) {
if ($absdaynow > $absdaydefault) {
$year = $yearnow + 1;
$year = $yearnow + 1;
}
}
@ -1108,7 +1112,7 @@ function reserve_which_year($month, $day) {
* used for Allowed Values for Reservation.reservable_content_type field
* used for Allowed Values for Reservation.reservable_content_type field
*/
*/
function reserve_site_entity_types() {
function reserve_site_entity_types() {
$types = \Drupal::service('entity_type.repository' )->getEntityTypeLabels(TRUE);
$types = \Drupal::entityManager( )->getEntityTypeLabels(TRUE);
return $types['Content'];
return $types['Content'];
}
}
@ -1125,4 +1129,4 @@ function reserve_get_ebundle_category_field($ebundle) {
return $field;
return $field;
}
}
}
}
}
}