It is a very nice and polished module. Thank you very much for it!

Problem/Motivation

Analogically to #3427811: Allow to set a specifc number of days in advance the booking can be made, would it be possible to restrict visible booking dates by a number of days in the future?

As an example, please picture a clinic where a booking calendar has been set for a whole year but patients can only make an appointment for the upcoming two weeks. Every new day, reveals a new possible date to book an appointment, following all other settings (exclude weekdays, etc.).

This setting would also affect the Month/Year calendar selection for the end user e.g. the end date of the booking calendar is set in 1 year and the number of visible booking days is set to 14 days from the current date. Users can only see the current Month/Year until the 14 days period reaches the next month, allowing them to switch between the current and next month.

The end date value is not very flexible in that regard, as is it forces staff to create new calendars each time the old has ended or to renew them.

Proposed resolution

Please add a new option to hide booking dates beyond a number of days set in this field.

Comments

zimny created an issue. See original summary.

zimny’s picture

Looking at the commit from the linked reference in my previous comment, I have slightly modified rfmarcelino's original code to match my needs and after some testing and to my surprise I wanted to let you know that it works and does exactly what I wanted.

I am not sure yet how to apply those commits, so please see below the attached code. Feel free to do the testing and possibly push it to the future updates. I am quite sure it can come handy.

WebformBookingController.php

    // Adjusting end date based on 'days_visible' if set.
    if (isset($config['#days_visible']) && is_numeric($config['#days_visible'])) {
      $visibleDate = (new \DateTime())->modify('+' . $config['#days_visible'] . ' days');
      if ($actualEndDate > $visibleDate) {
        $actualEndDate = $visibleDate;
      }
    }

WebformBooking.php

protected function defineDefaultProperties() {
 $properties = parent::defineDefaultProperties() + [
...
      'days_visable' => '0',
...

    // Days visable.
    $form['appointment_settings']['days_visible'] = [
      '#type' => 'number',
      '#title' => $this->t('Days Visiblee'),
      '#default_value' => $this->getDefaultProperty('days_visible'),
      '#description' => $this->t('Number of days from now a booking can be made'),
    ];

I think that at this stage we still have to create a condition that takes into account the original "Days in Advance" setting to ensure that those two not interfere with each other, i.e. "Days in Advance" number can not be higher than "Days Visible".
What do you think?

avpaderno’s picture

Issue summary: View changes
avpaderno’s picture

avpaderno’s picture

Issue summary: View changes

rfmarcelino’s picture

@zimny, thank you for your feedback.
Now available on dev:
composer require 'drupal/webform_booking:1.0.x-dev@dev'

rfmarcelino’s picture

Status: Active » Needs review
rfmarcelino’s picture

Status: Needs review » Fixed

Released as part of 1.0.13

rfmarcelino’s picture

Status: Fixed » Closed (fixed)
zimny’s picture

This functionality is broken for all releases starting from 1.0.13. For 1.0.13 the fix is simple but for the 1.1* versions it is not that easy to make it to work.

@rfmarcelino, can you please look into it when you have a second?

rfmarcelino’s picture

Status: Closed (fixed) » Needs review
StatusFileSize
new30.64 KB

Hi @zimmy
Just sent a fix to dev. Please test it out and lete me know if it's also working for you.
Visible days

zimny’s picture

I can confirm this issue is no more in the last dev release. It can be pushed to the next stable.

@rfmarcelino, thanks!

rfmarcelino’s picture

Released in 1.1.2

rfmarcelino’s picture

Status: Needs review » Fixed
rfmarcelino’s picture

Status: Fixed » Closed (fixed)