diff --git a/application/config/constants.php b/application/config/constants.php index 1d57d408..6e42bd86 100644 --- a/application/config/constants.php +++ b/application/config/constants.php @@ -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 */ diff --git a/application/models/Appointments_model.php b/application/models/Appointments_model.php index bf8d60fe..98f659f2 100644 --- a/application/models/Appointments_model.php +++ b/application/models/Appointments_model.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('*')