mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-12-26 00:23:33 +03:00
Do not allow appointments being created with duration less than the predefined minimum (#805).
This commit is contained in:
parent
8f1e82019f
commit
dbc45f6b27
2 changed files with 15 additions and 5 deletions
|
@ -87,5 +87,7 @@ define('CALENDAR_VIEW_TABLE', 'table');
|
|||
define('AVAILABILITIES_TYPE_FLEXIBLE', 'flexible');
|
||||
define('AVAILABILITIES_TYPE_FIXED', 'fixed');
|
||||
|
||||
define('EVENT_MINIMUM_DURATION', 5); // Minutes
|
||||
|
||||
/* End of file constants.php */
|
||||
/* Location: ./application/config/constants.php */
|
||||
|
|
|
@ -63,13 +63,12 @@ class Appointments_Model extends CI_Model {
|
|||
{
|
||||
$this->load->helper('data_validation');
|
||||
|
||||
// If a appointment id is given, check whether the record exists
|
||||
// in the database.
|
||||
// If a appointment id is given, check whether the record exists in the database.
|
||||
if (isset($appointment['id']))
|
||||
{
|
||||
$num_rows = $this->db->get_where('appointments',
|
||||
['id' => $appointment['id']])->num_rows();
|
||||
if ($num_rows == 0)
|
||||
$num_rows = $this->db->get_where('appointments', ['id' => $appointment['id']])->num_rows();
|
||||
|
||||
if ($num_rows === 0)
|
||||
{
|
||||
throw new Exception('Provided appointment id does not exist in the database.');
|
||||
}
|
||||
|
@ -86,6 +85,15 @@ class Appointments_Model extends CI_Model {
|
|||
throw new Exception('Appointment end datetime is invalid.');
|
||||
}
|
||||
|
||||
// Ensure the appointment lasts longer than the minimum duration (in minutes).
|
||||
$diff = (strtotime($appointment['end_datetime']) - strtotime($appointment['start_datetime'])) / 60;
|
||||
|
||||
if ($diff < EVENT_MINIMUM_DURATION)
|
||||
{
|
||||
throw new Exception('The appointment duration is less than the minimum duration ('
|
||||
. EVENT_MINIMUM_DURATION . ' minutes).');
|
||||
}
|
||||
|
||||
// Check if the provider's id is valid.
|
||||
$num_rows = $this->db
|
||||
->select('*')
|
||||
|
|
Loading…
Reference in a new issue