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
|
@ -68,7 +68,9 @@ class Availability {
|
||||||
$available_hours = $this->generate_available_hours($date, $service, $available_periods);
|
$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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -610,4 +612,33 @@ class Availability {
|
||||||
|
|
||||||
return array_values($available_hours);
|
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']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -84,6 +84,21 @@
|
||||||
</small>
|
</small>
|
||||||
</div>
|
</div>
|
||||||
</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>
|
</fieldset>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -836,7 +836,8 @@ body .form-horizontal .controls {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
#business-logic #book-advance-timeout {
|
#business-logic #book-advance-timeout,
|
||||||
|
#business-logic #future-booking-limit {
|
||||||
width: 100px;
|
width: 100px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue