Browse Source

start of d10 dev

d10-dev
Paul Pound 1 year ago
parent
commit
3faf3631c8
  1. 8
      reserve.inc
  2. 2
      reserve.info.yml
  3. 6
      reserve.module
  4. 7
      src/Controller/CalendarController.php
  5. 1
      src/Form/ReserveDailyHoursForm.php
  6. 5
      src/Form/ReserveDefaultHoursForm.php
  7. 2
      src/Form/ReserveSettingsForm.php
  8. 3
      src/Plugin/Field/FieldFormatter/ReserveCategoryFormatter.php
  9. 3
      src/Plugin/Field/FieldWidget/ReserveCategorySelect.php
  10. 46
      src/Tests/LoadTest.php

8
reserve.inc

@ -1,4 +1,5 @@
<?php <?php
use Drupal\field\Entity\FieldConfig;
/** /**
* @file * @file
* Classes and general Room Reservations helper functions. * Classes and general Room Reservations helper functions.
@ -21,7 +22,7 @@ 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 = \Drupal\field\Entity\FieldConfig::loadByName($entity_type, $bundle, $field)->getSettings(); $fconfig = FieldConfig::loadByName($entity_type, $bundle, $field)->getSettings();
$ids = array_filter($fconfig['categories']); $ids = array_filter($fconfig['categories']);
} }
else { else {
@ -696,7 +697,7 @@ function reserve_start_conflicts($room, $yyyy_mmdd, $time) {
) )
"; ";
$conflicts_found = FALSE; $conflicts_found = FALSE;
$conflicts_found = db_query($sql, array( $conflicts_found = \Drupal::database()->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'],
@ -705,8 +706,7 @@ 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']) ':date7' => $search_items[7]['date'], ':time7' => $search_items[7]['start_time'], ':length7' => $search_items[7]['length']))->rowCount();
)->rowCount();
return $conflicts_found; return $conflicts_found;
} }

2
reserve.info.yml

@ -2,7 +2,7 @@ name: Reserve
type: module type: module
description: Reservation system. description: Reservation system.
package: Reserve package: Reserve
core_version_requirement: ^8 || ^9 core_version_requirement: ^9.5 || ^10
dependencies: dependencies:
- drupal:views - drupal:views
- drupal:options - 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_SAVE_CONFIRMATION_MSG', t('Configuration settings have been saved'));
define ('RESERVE_RESET_CONFIRMATION_MSG', t('Configuration settings have been reset to their default values')); define ('RESERVE_RESET_CONFIRMATION_MSG', t('Configuration settings have been reset to their default values'));
module_load_include('inc', 'reserve', 'reserve'); include(dirname(__FILE__) . '/reserve.inc');
module_load_include('inc', 'reserve', 'reserve.series'); include(dirname(__FILE__) . '/reserve.series.inc');
module_load_include('inc', 'reserve', 'reservation'); include(dirname(__FILE__) . '/reservation.inc');
$GLOBALS['debug'] = false; $GLOBALS['debug'] = false;

7
src/Controller/CalendarController.php

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

1
src/Form/ReserveDailyHoursForm.php

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

5
src/Form/ReserveDefaultHoursForm.php

@ -5,8 +5,6 @@ namespace Drupal\reserve\Form;
use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
module_load_include('inc', 'reserve', 'reserve.admin');
/** /**
* Class ReserveCategorySettingsForm. * Class ReserveCategorySettingsForm.
* *
@ -235,7 +233,6 @@ class ReserveDefaultHoursForm extends ConfigFormBase {
*/ */
public function submitForm(array &$form, FormStateInterface $form_state) { public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state->getValues(); $values = $form_state->getValues();
$default_hours = array(); $default_hours = array();
if ($form_state->getTriggeringElement()['#name'] == 'save') { if ($form_state->getTriggeringElement()['#name'] == 'save') {
for ($day = 0; $day < 7; $day++) { for ($day = 0; $day < 7; $day++) {
@ -244,7 +241,7 @@ class ReserveDefaultHoursForm extends ConfigFormBase {
$default_hours[] = $values['day_' . $day]['second_shift_open_' . $day]; $default_hours[] = $values['day_' . $day]['second_shift_open_' . $day];
$default_hours[] = $values['day_' . $day]['second_shift_close_' . $day]; $default_hours[] = $values['day_' . $day]['second_shift_close_' . $day];
} }
$confirmation = t(RESERVE_SAVE_CONFIRMATION_MSG); $confirmation = RESERVE_SAVE_CONFIRMATION_MSG;
} }
if ($form_state->getTriggeringElement()['#name'] == 'reset') { if ($form_state->getTriggeringElement()['#name'] == 'reset') {
for ($day = 0; $day < 7; $day++) { 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'), '#title' => t('Time to show on calendar before/after open slots'),
'#type' => 'select', '#type' => 'select',
'#options' => array(0 => '0 hours', 1 => t('1 hour'), 2 => t('2 hours'), '3' => t('All day')), '#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('advanced_booking_admin') : 3, '#default_value' => $config->get('show_before_after_hours') ? $config->get('show_before_after_hours') : 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.'), '#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,6 +2,7 @@
namespace Drupal\reserve\Plugin\Field\FieldFormatter; namespace Drupal\reserve\Plugin\Field\FieldFormatter;
use Drupal\reserve\Entity\ReserveCategory;
use Drupal\Core\Field\FormatterBase; use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\FieldItemListInterface;
@ -35,7 +36,7 @@ class ReserveCategoryFormatter extends FormatterBase {
$element = []; $element = [];
foreach ($items as $delta => $item) { foreach ($items as $delta => $item) {
$category = \Drupal\reserve\Entity\ReserveCategory::load($item->cid); $category = ReserveCategory::load($item->cid);
// Render each element as markup. // Render each element as markup.
$element[$delta] = [ $element[$delta] = [
'#type' => 'markup', '#type' => 'markup',

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

@ -2,6 +2,7 @@
namespace Drupal\reserve\Plugin\Field\FieldWidget; namespace Drupal\reserve\Plugin\Field\FieldWidget;
use Drupal\reserve\Entity\ReserveCategory;
use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\WidgetBase; use Drupal\Core\Field\WidgetBase;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
@ -30,7 +31,7 @@ class ReserveCategorySelect extends WidgetBase {
$set = $items->getSettings()['categories']; $set = $items->getSettings()['categories'];
$ids = \Drupal::entityQuery('reserve_category')->sort('name', 'ASC')->execute(); $ids = \Drupal::entityQuery('reserve_category')->sort('name', 'ASC')->execute();
$categories = \Drupal\reserve\Entity\ReserveCategory::loadMultiple($ids); $categories = ReserveCategory::loadMultiple($ids);
$options = array(); $options = array();
foreach ($categories as $key => $cat) { foreach ($categories as $key => $cat) {
if (!in_array($key, $set)) continue; if (!in_array($key, $set)) continue;

46
src/Tests/LoadTest.php

@ -1,46 +0,0 @@
<?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