Compare commits

..

No commits in common. 'd10-dev' and '4.0.x-roblib' have entirely different histories.

  1. 46
      reservation.inc
  2. 14
      reserve.inc
  3. 2
      reserve.info.yml
  4. 6
      reserve.module
  5. 2
      reserve.series.inc
  6. 7
      src/Controller/CalendarController.php
  7. 1
      src/Form/ReserveDailyHoursForm.php
  8. 5
      src/Form/ReserveDefaultHoursForm.php
  9. 2
      src/Form/ReserveSettingsForm.php
  10. 3
      src/Plugin/Field/FieldFormatter/ReserveCategoryFormatter.php
  11. 3
      src/Plugin/Field/FieldType/ReserveCategory.php
  12. 6
      src/Plugin/Field/FieldWidget/ReserveCategorySelect.php
  13. 46
      src/Tests/LoadTest.php

46
reservation.inc

@ -8,7 +8,6 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Link;
use Drupal\Core\Url;
use Drupal\Core\StringTranslation\TranslatableMarkup;
function reserve_form_reserve_reservation_form_alter(array &$form, FormStateInterface $form_state) {
// params either passed in on url - CREATE
@ -80,15 +79,33 @@ function reserve_form_reserve_reservation_form_alter(array &$form, FormStateInte
$d = $yyyymmdd . ' 00:00:00';
if (reserve_daily_max_exceeded($yyyymmdd) && !$book_extended) {
$daily_exceeded_message = t('You have exceeded the max number of daily bookings. Unable to add reservation.');
reserve_set_modal_message($form, $daily_exceeded_message);
$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">' .
t('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
&& !$book_extended) {
$max_reservations_exceeded_message = t('You have exceeded your max number of open bookings. Unable to add reservation.');
reserve_set_modal_message($form, $max_reservations_exceeded_message);
$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">' .
t('You have exceeded your max number of open bookings. Unable to add reservation.') .
'</div></div>',
];
return;
}
}
$entity = \Drupal::entityTypeManager()->getStorage($entity_type)->load($eid);
@ -100,9 +117,9 @@ function reserve_form_reserve_reservation_form_alter(array &$form, FormStateInte
// set default Group Name as name of current user
$form['name']['widget'][0]['value']['#required'] = TRUE;
/*$form['name']['widget'][0]['value']['#default_value'] = $form['name']['widget'][0]['value']['#default_value'] ?
$form['name']['widget'][0]['value']['#default_value'] = $form['name']['widget'][0]['value']['#default_value'] ?
$form['name']['widget'][0]['value']['#default_value'] :
\Drupal::currentUser()->getDisplayName();*/
\Drupal::currentUser()->getDisplayName();
// set values taken from URL
$form['reservation_date']['widget'][0]['value']['#default_value'] = DrupalDateTime::createFromTimestamp(strtotime($yyyymmdd));
@ -279,21 +296,6 @@ function reserve_return_to_home_page($form, FormStateInterface $form_state) {
$form_state->setRedirectUrl($url);
}
function reserve_set_modal_message(&$form, $message) {
$form['message'] = [
'#type' => 'markup',
'#weight' => -25,
'#markup' => '
<div class="messages__wrapper layout-container">
<div role="contentinfo" aria-label="Warning message" class="messages messages--warning">' .
$message .
'</div></div>',
];
$form['message']['#errors'] = TRUE;
$form['actions']['submit']['#attributes']['disabled'] = 'disabled';
$form['actions']['submit']['#access'] = FALSE;
}
/**
* Custom submit handler for login form.
*/

14
reserve.inc

@ -1,5 +1,4 @@
<?php
use Drupal\field\Entity\FieldConfig;
/**
* @file
* Classes and general Room Reservations helper functions.
@ -22,13 +21,13 @@ function reserve_categories($ebundle = null) {
$entity_type = ebundle_split($ebundle, 'type');
$bundle = ebundle_split($ebundle, 'bundle');
$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']);
}
else {
$query = \Drupal::service('entity_type.manager')
->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);
@ -67,7 +66,7 @@ function reserve_entities($ebundle) {
}
//->sort('reservations_display_order', 'ASC')
$ids = $query->accessCheck(FALSE)->execute();
$ids = $query->execute();
$entities = \Drupal::entityTypeManager()->getStorage($entity_type)->loadMultiple($ids);
@ -697,7 +696,7 @@ function reserve_start_conflicts($room, $yyyy_mmdd, $time) {
)
";
$conflicts_found = FALSE;
$conflicts_found = \Drupal::database()->query($sql, array(
$conflicts_found = db_query($sql, array(
':room' => $room,
':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'],
@ -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'],
':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'],
':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;
}
@ -933,7 +933,6 @@ function reserve_daily_max_exceeded($yyyy_mmdd) {
if ($user->id()) {
$ids = \Drupal::service('entity_type.manager')
->getStorage('reserve_reservation')->getQuery()
->accessCheck(FALSE)
->condition('user_id', $user->id())
->condition('reservation_date', $yyyy_mmdd . '%', 'like')
->execute();
@ -967,7 +966,6 @@ function reserve_user_reservations() {
$latest_date = date('Y-m-d', strtotime("now +13 days"));
$ids = \Drupal::service('entity_type.manager')
->getStorage('reserve_reservation')->getQuery()
->accessCheck(TRUE)
->condition('user_id', $user->id())
->condition('reservation_date', $earliest_date, '>=')
->condition('reservation_date', $latest_date, '<=')

2
reserve.info.yml

@ -2,7 +2,7 @@ name: Reserve
type: module
description: Reservation system.
package: Reserve
core_version_requirement: ^9.5 || ^10
core_version_requirement: ^8 || ^9
dependencies:
- drupal:views
- drupal:options

6
reserve.module

@ -16,9 +16,9 @@ use Drupal\Core\Form\FormStateInterface;
define ('RESERVE_SAVE_CONFIRMATION_MSG', t('Configuration settings have been saved'));
define ('RESERVE_RESET_CONFIRMATION_MSG', t('Configuration settings have been reset to their default values'));
include(dirname(__FILE__) . '/reserve.inc');
include(dirname(__FILE__) . '/reserve.series.inc');
include(dirname(__FILE__) . '/reservation.inc');
module_load_include('inc', 'reserve', 'reserve');
module_load_include('inc', 'reserve', 'reserve.series');
module_load_include('inc', 'reserve', 'reservation');
$GLOBALS['debug'] = false;

2
reserve.series.inc

@ -130,7 +130,6 @@ function reserve_reserve_reservation_update($entity) {
// grab all reservations in this series except the one being submitted
$ids = \Drupal::service('entity_type.manager')
->getStorage('reserve_reservation')->getQuery()
->accessCheck(TRUE)
->condition('status', TRUE)
->condition('reservation_series_id', $sid)
->condition('id', $entity->id(), '!=')
@ -184,7 +183,6 @@ function _reserve_series_delete($entity) {
// grab all reservations in this series
$ids = \Drupal::service('entity_type.manager')
->getStorage('reserve_reservation')->getQuery()
->accessCheck(TRUE)
->condition('reservation_series_id', $sid)
->execute();
$results = \Drupal::entityTypeManager()->getStorage('reserve_reservation')->loadMultiple($ids);

7
src/Controller/CalendarController.php

@ -1,7 +1,6 @@
<?php
namespace Drupal\reserve\Controller;
use Drupal\field\Entity\FieldConfig;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Drupal\Core\Link;
@ -335,7 +334,7 @@ class CalendarController extends ControllerBase {
$extended = \Drupal::currentUser()->hasPermission('add reservations extended');
$config = \Drupal::config('reserve.settings');
$category_field = reserve_category_fields($ebundle);
$clearimg = '<img src="' . base_path() . \Drupal::service('extension.list.module')->getPath('reserve') . '/images/clear.png" />';
$clearimg = '<img src="' . base_path() . drupal_get_path('module', 'reserve') . '/images/clear.png" />';
$modal = ['attributes' => [
'class' => ['use-ajax'],
'data-dialog-type' => 'modal',
@ -372,12 +371,12 @@ class CalendarController extends ControllerBase {
$variables['#calendar-text'] = $config->get('calendar_text');
$variables['#reserve_room_instructions_text'] = $config->get('reserve_instructions') ? $config->get('reserve_instructions') :
t('To make a reservation, click on the desired time/day in the calendar below. You will be asked to login.');
$variables['#arrow'] = base_path() . \Drupal::service('extension.list.module')->getPath('reserve') . '/images/arrow-icon.png';
$variables['#arrow'] = base_path() . drupal_get_path('module', 'reserve') . '/images/arrow-icon.png';
$variables['#date'] = \Drupal::service('date.formatter')->format(strtotime($month . ' ' . $xday . ', ' . $year), 'custom', 'l, F d, Y');
$variables['#date_picker'] = \Drupal::formBuilder()->getForm('Drupal\reserve\Form\CalendarDatePicker');
$field = reserve_category_fields($ebundle);
$fconfig = FieldConfig::loadByName($entity_type, $bundle, $field)->getSettings();
$fconfig = \Drupal\field\Entity\FieldConfig::loadByName($entity_type, $bundle, $field)->getSettings();
$variables['#calendar_header'] = $fconfig['calendar_header'];
$variables['#reservation_instructions'] = $fconfig['reservation_instructions'];

1
src/Form/ReserveDailyHoursForm.php

@ -5,6 +5,7 @@ namespace Drupal\reserve\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
module_load_include('inc', 'reserve', 'reserve.admin');
/**
* Class ReserveCategorySettingsForm.

5
src/Form/ReserveDefaultHoursForm.php

@ -5,6 +5,8 @@ namespace Drupal\reserve\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
module_load_include('inc', 'reserve', 'reserve.admin');
/**
* Class ReserveCategorySettingsForm.
*
@ -233,6 +235,7 @@ class ReserveDefaultHoursForm extends ConfigFormBase {
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state->getValues();
$default_hours = array();
if ($form_state->getTriggeringElement()['#name'] == 'save') {
for ($day = 0; $day < 7; $day++) {
@ -241,7 +244,7 @@ class ReserveDefaultHoursForm extends ConfigFormBase {
$default_hours[] = $values['day_' . $day]['second_shift_open_' . $day];
$default_hours[] = $values['day_' . $day]['second_shift_close_' . $day];
}
$confirmation = RESERVE_SAVE_CONFIRMATION_MSG;
$confirmation = t(RESERVE_SAVE_CONFIRMATION_MSG);
}
if ($form_state->getTriggeringElement()['#name'] == 'reset') {
for ($day = 0; $day < 7; $day++) {

2
src/Form/ReserveSettingsForm.php

@ -114,7 +114,7 @@ class ReserveSettingsForm extends ConfigFormBase {
'#title' => t('Time to show on calendar before/after open slots'),
'#type' => 'select',
'#options' => array(0 => '0 hours', 1 => t('1 hour'), 2 => t('2 hours'), '3' => t('All day')),
'#default_value' => $config->get('show_before_after_hours') ? $config->get('show_before_after_hours') : 3,
'#default_value' => $config->get('show_before_after_hours') ? $config->get('advanced_booking_admin') : 3,
'#description' => t('The number of hours before the first and last open slots for the day that are shown on the calendar. The default is to display the entire day.'),
);

3
src/Plugin/Field/FieldFormatter/ReserveCategoryFormatter.php

@ -2,7 +2,6 @@
namespace Drupal\reserve\Plugin\Field\FieldFormatter;
use Drupal\reserve\Entity\ReserveCategory;
use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Field\FieldItemListInterface;
@ -36,7 +35,7 @@ class ReserveCategoryFormatter extends FormatterBase {
$element = [];
foreach ($items as $delta => $item) {
$category = ReserveCategory::load($item->cid);
$category = \Drupal\reserve\Entity\ReserveCategory::load($item->cid);
// Render each element as markup.
$element[$delta] = [
'#type' => 'markup',

3
src/Plugin/Field/FieldType/ReserveCategory.php

@ -64,8 +64,7 @@ class ReserveCategory extends FieldItemBase implements FieldItemInterface {
*/
public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
// get a list of all Reserve Categories
$ids = \Drupal::entityQuery('reserve_category')->accessCheck(TRUE)
->sort('name', 'ASC')->execute();
$ids = \Drupal::entityQuery('reserve_category')->sort('name', 'ASC')->execute();
$categories = \Drupal\reserve\Entity\ReserveCategory::loadMultiple($ids);
$options = array();
foreach ($categories as $cat) {

6
src/Plugin/Field/FieldWidget/ReserveCategorySelect.php

@ -2,7 +2,6 @@
namespace Drupal\reserve\Plugin\Field\FieldWidget;
use Drupal\reserve\Entity\ReserveCategory;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\WidgetBase;
use Drupal\Core\Form\FormStateInterface;
@ -30,9 +29,8 @@ class ReserveCategorySelect extends WidgetBase {
// get a list of all Reserve Categories for this bundle
$set = $items->getSettings()['categories'];
$ids = \Drupal::entityQuery('reserve_category')->accessCheck(TRUE)
->sort('name', 'ASC')->execute();
$categories = ReserveCategory::loadMultiple($ids);
$ids = \Drupal::entityQuery('reserve_category')->sort('name', 'ASC')->execute();
$categories = \Drupal\reserve\Entity\ReserveCategory::loadMultiple($ids);
$options = array();
foreach ($categories as $key => $cat) {
if (!in_array($key, $set)) continue;

46
src/Tests/LoadTest.php

@ -0,0 +1,46 @@
<?php
namespace Drupal\reserve\Tests;
use Drupal\Core\Url;
use Drupal\simpletest\WebTestBase;
/**
* Simple test to ensure that main page loads with module enabled.
*
* @group reserve
*/
class LoadTest extends WebTestBase{
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['reserve'];
/**
* A user with permission to administer site configuration.
*
* @var \Drupal\user\UserInterface
*/
protected $user;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->user = $this->drupalCreateUser(['administer site configuration']);
$this->drupalLogin($this->user);
}
/**
* Tests that the home page loads with a 200 response.
*/
public function testLoad() {
$this->drupalGet(Url::fromRoute('<front>'));
$this->assertResponse(200);
}
}
Loading…
Cancel
Save