From 07276d46a6354464ad2d3d31c6298de5fa6c60e0 Mon Sep 17 00:00:00 2001 From: Alex Tselegidis Date: Mon, 4 May 2020 20:59:37 +0200 Subject: [PATCH] Code changes on automatically end_datetime assignment via the REST API --- application/controllers/api/v1/Appointments.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/application/controllers/api/v1/Appointments.php b/application/controllers/api/v1/Appointments.php index c7953947..c549d355 100644 --- a/application/controllers/api/v1/Appointments.php +++ b/application/controllers/api/v1/Appointments.php @@ -125,14 +125,15 @@ class Appointments extends API_V1_Controller { } // Generate end_datetime based on service duration if this field is not defined - if (!isset($appointment['end_datetime'])) + 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'); + $end_datetime = new DateTime($appointment['start_datetime']); + $end_datetime->add(new DateInterval('PT' . $service['duration'] . 'M')); + $appointment['end_datetime'] = $end_datetime->format('Y-m-d H:i:s'); } }