mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-11-25 09:23:08 +03:00
Automatically populate the appointment end datetime based on service duration in API.
This commit is contained in:
parent
b834869fd3
commit
05ab0db079
1 changed files with 14 additions and 0 deletions
|
@ -110,6 +110,8 @@ class Appointments extends API_V1_Controller {
|
||||||
*/
|
*/
|
||||||
public function post()
|
public function post()
|
||||||
{
|
{
|
||||||
|
$this->load->model('services_model');
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Insert the appointment to the database.
|
// Insert the appointment to the database.
|
||||||
|
@ -122,6 +124,18 @@ class Appointments extends API_V1_Controller {
|
||||||
unset($appointment['id']);
|
unset($appointment['id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generate end_datetime based on service duration if this field is not defined
|
||||||
|
if (!isset($appointment['end_datetime']))
|
||||||
|
{
|
||||||
|
$service = $this->services_model->get_row($appointment['id_services']);
|
||||||
|
if (isset($service['duration']))
|
||||||
|
{
|
||||||
|
$endTime = new DateTime($appointment['start_datetime']);
|
||||||
|
$endTime->add(new DateInterval('PT' . $service['duration'] . 'M'));
|
||||||
|
$appointment['end_datetime'] = $endTime->format('Y-m-d H:i:s');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$id = $this->appointments_model->add($appointment);
|
$id = $this->appointments_model->add($appointment);
|
||||||
|
|
||||||
// Fetch the new object from the database and return it to the client.
|
// Fetch the new object from the database and return it to the client.
|
||||||
|
|
Loading…
Reference in a new issue