forked from mirrors/easyappointments
Add new setting for limiting new public bookings in the future (#1203).
This commit is contained in:
parent
bc80d2c6e0
commit
3d8d5afa4c
4 changed files with 115 additions and 21 deletions
|
@ -16,7 +16,7 @@
|
|||
* Availability library.
|
||||
*
|
||||
* Handles availability related functionality.
|
||||
*
|
||||
*
|
||||
* @package Libraries
|
||||
*/
|
||||
class Availability {
|
||||
|
@ -68,7 +68,9 @@ class Availability {
|
|||
$available_hours = $this->generate_available_hours($date, $service, $available_periods);
|
||||
}
|
||||
|
||||
return $this->consider_book_advance_timeout($date, $available_hours, $provider);
|
||||
$available_hours = $this->consider_book_advance_timeout($date, $available_hours, $provider);
|
||||
|
||||
return $this->consider_future_booking_limit($date, $available_hours, $provider);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -93,14 +95,14 @@ class Availability {
|
|||
|
||||
// Get the provider's working plan exceptions.
|
||||
$working_plan_exceptions_json = $provider['settings']['working_plan_exceptions'];
|
||||
|
||||
|
||||
$working_plan_exceptions = $working_plan_exceptions_json ? json_decode($provider['settings']['working_plan_exceptions'], TRUE) : NULL;
|
||||
|
||||
$escaped_provider_id = $this->CI->db->escape($provider['id']);
|
||||
|
||||
$escaped_date = $this->CI->db->escape($date);
|
||||
|
||||
$where = 'id_users_provider = ' . $escaped_provider_id
|
||||
|
||||
$escaped_date = $this->CI->db->escape($date);
|
||||
|
||||
$where = 'id_users_provider = ' . $escaped_provider_id
|
||||
. ' AND DATE(start_datetime) <= ' . $escaped_date . ' AND DATE(end_datetime) >= ' . $escaped_date;
|
||||
|
||||
// Sometimes it might be necessary to exclude an appointment from the calculation (e.g. when editing an
|
||||
|
@ -108,7 +110,7 @@ class Availability {
|
|||
if ($exclude_appointment_id)
|
||||
{
|
||||
$escaped_exclude_appointment_id = $this->CI->db->escape($exclude_appointment_id);
|
||||
$where .= ' AND id != ' . $escaped_exclude_appointment_id;
|
||||
$where .= ' AND id != ' . $escaped_exclude_appointment_id;
|
||||
}
|
||||
|
||||
$appointments = array_values(
|
||||
|
@ -304,8 +306,8 @@ class Availability {
|
|||
*/
|
||||
protected function generate_available_hours(
|
||||
string $date,
|
||||
array $service,
|
||||
array $empty_periods
|
||||
array $service,
|
||||
array $empty_periods
|
||||
): array
|
||||
{
|
||||
$available_hours = [];
|
||||
|
@ -351,9 +353,9 @@ class Availability {
|
|||
*/
|
||||
protected function consider_multiple_attendants(
|
||||
string $date,
|
||||
array $service,
|
||||
array $provider,
|
||||
int $exclude_appointment_id = NULL
|
||||
array $service,
|
||||
array $provider,
|
||||
int $exclude_appointment_id = NULL
|
||||
): array
|
||||
{
|
||||
$unavailability_events = $this->CI->appointments_model->get([
|
||||
|
@ -610,4 +612,33 @@ class Availability {
|
|||
|
||||
return array_values($available_hours);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove times if succeed the future booking limit.
|
||||
*
|
||||
* @param string $selected_date
|
||||
* @param array $available_hours
|
||||
* @param array $provider
|
||||
*
|
||||
* @return array|mixed
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function consider_future_booking_limit(string $selected_date, array $available_hours, array $provider): array
|
||||
{
|
||||
$provider_timezone = new DateTimeZone($provider['timezone']);
|
||||
|
||||
$future_booking_limit = setting('future_booking_limit'); // in days
|
||||
|
||||
$threshold = new DateTime('+' . $future_booking_limit . ' days', $provider_timezone);
|
||||
|
||||
$selected_date_time = new DateTime($selected_date);
|
||||
|
||||
if ($threshold < $selected_date_time)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
return $threshold > $selected_date_time ? $available_hours : [];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Easy!Appointments - Open Source Web Scheduler
|
||||
*
|
||||
* @package EasyAppointments
|
||||
* @author A.Tselegidis <alextselegidis@gmail.com>
|
||||
* @copyright Copyright (c) 2013 - 2020, Alex Tselegidis
|
||||
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
||||
* @link http://easyappointments.org
|
||||
* @since v1.4.0
|
||||
* ---------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* @property CI_DB_query_builder $db
|
||||
* @property CI_DB_forge $dbforge
|
||||
*/
|
||||
class Migration_Add_future_booking_limit_setting extends CI_Migration {
|
||||
/**
|
||||
* Upgrade method.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
if ( ! $this->db->get_where('settings', ['name' => 'future_booking_limit'])->num_rows())
|
||||
{
|
||||
$this->db->insert('settings', [
|
||||
'name' => 'future_booking_limit',
|
||||
'value' => '90' // days
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Downgrade method.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
if ($this->db->get_where('settings', ['name' => 'future_booking_limit'])->num_rows())
|
||||
{
|
||||
$this->db->delete('settings', ['name' => 'future_booking_limit']);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -27,11 +27,11 @@
|
|||
|
||||
<table class="working-plan table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?= lang('day') ?></th>
|
||||
<th><?= lang('start') ?></th>
|
||||
<th><?= lang('end') ?></th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><?= lang('day') ?></th>
|
||||
<th><?= lang('start') ?></th>
|
||||
<th><?= lang('end') ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><!-- Dynamic Content --></tbody>
|
||||
</table>
|
||||
|
@ -69,9 +69,9 @@
|
|||
</thead>
|
||||
<tbody><!-- Dynamic Content --></tbody>
|
||||
</table>
|
||||
|
||||
|
||||
<h4><?= lang('book_advance_timeout') ?></h4>
|
||||
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="book-advance-timeout" class="form-label">
|
||||
<?= lang('timeout_minutes') ?>
|
||||
|
@ -84,6 +84,21 @@
|
|||
</small>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h4><?= lang('future_booking_limit') ?></h4>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="future-booking-limit" class="form-label">
|
||||
<?= lang('limit_days') ?>
|
||||
</label>
|
||||
<input id="future-booking-limit" data-field="future_booking_limit" class="form-control"
|
||||
type="number" min="15">
|
||||
<div class="form-text text-muted">
|
||||
<small>
|
||||
<?= lang('future_booking_limit_hint') ?>
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -836,7 +836,8 @@ body .form-horizontal .controls {
|
|||
cursor: pointer;
|
||||
}
|
||||
|
||||
#business-logic #book-advance-timeout {
|
||||
#business-logic #book-advance-timeout,
|
||||
#business-logic #future-booking-limit {
|
||||
width: 100px;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue