diff --git a/application/controllers/Booking.php b/application/controllers/Booking.php index ef237e3e..d9a965f0 100755 --- a/application/controllers/Booking.php +++ b/application/controllers/Booking.php @@ -189,126 +189,6 @@ class Booking extends EA_Controller { ]); } - /** - * Cancel an existing appointment. - * - * This method removes an appointment from the company's schedule. In order for the appointment to be deleted, the - * hash string must be provided. The customer can only cancel the appointment if the edit time period is not over - * yet. - * - * @param string $appointment_hash This appointment hash identifier. - */ - public function cancel(string $appointment_hash) - { - try - { - $exceptions = []; - - $occurrences = $this->appointments_model->get(['hash' => $appointment_hash]); - - if (empty($occurrences)) - { - throw new Exception('No record matches the provided hash.'); - } - - $appointment = $occurrences[0]; - - $provider = $this->providers_model->find($appointment['id_users_provider']); - - $customer = $this->customers_model->find($appointment['id_users_customer']); - - $service = $this->services_model->find($appointment['id_services']); - - $settings = [ - 'company_name' => setting('company_name'), - 'company_email' => setting('company_email'), - 'company_link' => setting('company_link'), - 'date_format' => setting('date_format'), - 'time_format' => setting('time_format') - ]; - - $this->appointments_model->delete($appointment['id']); - - $this->synchronization->sync_appointment_deleted($appointment, $provider); - - $this->notifications->notify_appointment_deleted($appointment, $service, $provider, $customer, $settings); - } - catch (Throwable $e) - { - $exceptions[] = $e; - } - - $this->load->view('pages/booking_message', [ - 'message_title' => lang('appointment_cancelled_title'), - 'message_text' => lang('appointment_cancelled'), - 'message_icon' => base_url('assets/img/success.png'), - 'exceptions' => $exceptions - ]); - } - - /** - * Display the appointment registration success page. - * - * @param string $appointment_hash The appointment hash identifier. - * - * @throws Exception - */ - public function book_success(string $appointment_hash) - { - $occurrences = $this->appointments_model->get(['hash' => $appointment_hash]); - - if (empty($occurrences)) - { - redirect('appointments'); // The appointment does not exist. - - return; - } - - $appointment = $occurrences[0]; - - unset($appointment['notes']); - - $customer = $this->customers_model->find($appointment['id_users_customer']); - - $provider = $this->providers_model->find($appointment['id_users_provider']); - - $service = $this->services_model->find($appointment['id_services']); - - $company_name = setting('company_name'); - - $exceptions = $this->session->flashdata('book_success') ?? []; - - $this->load->view('pages/booking_success', [ - 'page_title' => lang('success'), - 'appointment_data' => $appointment, - 'provider_data' => [ - 'id' => $provider['id'], - 'first_name' => $provider['first_name'], - 'last_name' => $provider['last_name'], - 'email' => $provider['email'], - 'timezone' => $provider['timezone'], - ], - 'customer_data' => [ - 'id' => $customer['id'], - 'first_name' => $customer['first_name'], - 'last_name' => $customer['last_name'], - 'email' => $customer['email'], - 'timezone' => $customer['timezone'], - ], - 'service_data' => $service, - 'company_name' => $company_name, - 'exceptions' => $exceptions, - 'scripts' => [ - 'https://apis.google.com/js/client.js', - asset_url('assets/vendor/datejs/date.min.js'), - asset_url('assets/vendor/moment/moment.min.js'), - asset_url('assets/vendor/moment-timezone/moment-timezone-with-data.min.js'), - asset_url('assets/js/frontend_book_success.js'), - asset_url('assets/js/general_functions.js') - ] - ]); - } - /** * Get the available appointment hours for the selected date. * diff --git a/application/controllers/Booking_cancellation.php b/application/controllers/Booking_cancellation.php new file mode 100755 index 00000000..d1455aa4 --- /dev/null +++ b/application/controllers/Booking_cancellation.php @@ -0,0 +1,94 @@ + + * @copyright Copyright (c) 2013 - 2020, Alex Tselegidis + * @license https://opensource.org/licenses/GPL-3.0 - GPLv3 + * @link https://easyappointments.org + * @since v1.5.0 + * ---------------------------------------------------------------------------- */ + +/** + * Booking cancellation controller. + * + * Handles the booking cancellation related operations. + * + * @package Controllers + */ +class Booking_cancellation extends EA_Controller { + /** + * Booking constructor. + */ + public function __construct() + { + parent::__construct(); + + $this->load->model('appointments_model'); + $this->load->model('providers_model'); + $this->load->model('services_model'); + $this->load->model('customers_model'); + + $this->load->library('synchronization'); + $this->load->library('notifications'); + } + + /** + * Cancel an existing appointment. + * + * This method removes an appointment from the company's schedule. In order for the appointment to be deleted, the + * hash string must be provided. The customer can only cancel the appointment if the edit time period is not over + * yet. + * + * @param string $appointment_hash This appointment hash identifier. + */ + public function of(string $appointment_hash) + { + try + { + $exceptions = []; + + $occurrences = $this->appointments_model->get(['hash' => $appointment_hash]); + + if (empty($occurrences)) + { + throw new Exception('No record matches the provided hash.'); + } + + $appointment = $occurrences[0]; + + $provider = $this->providers_model->find($appointment['id_users_provider']); + + $customer = $this->customers_model->find($appointment['id_users_customer']); + + $service = $this->services_model->find($appointment['id_services']); + + $settings = [ + 'company_name' => setting('company_name'), + 'company_email' => setting('company_email'), + 'company_link' => setting('company_link'), + 'date_format' => setting('date_format'), + 'time_format' => setting('time_format') + ]; + + $this->appointments_model->delete($appointment['id']); + + $this->synchronization->sync_appointment_deleted($appointment, $provider); + + $this->notifications->notify_appointment_deleted($appointment, $service, $provider, $customer, $settings); + } + catch (Throwable $e) + { + $exceptions[] = $e; + } + + $this->load->view('pages/booking_message', [ + 'message_title' => lang('appointment_cancelled_title'), + 'message_text' => lang('appointment_cancelled'), + 'message_icon' => base_url('assets/img/success.png'), + 'exceptions' => $exceptions + ]); + } +} diff --git a/application/controllers/Booking_confirmation.php b/application/controllers/Booking_confirmation.php new file mode 100755 index 00000000..f1b432cb --- /dev/null +++ b/application/controllers/Booking_confirmation.php @@ -0,0 +1,97 @@ + + * @copyright Copyright (c) 2013 - 2020, Alex Tselegidis + * @license https://opensource.org/licenses/GPL-3.0 - GPLv3 + * @link https://easyappointments.org + * @since v1.5.0 + * ---------------------------------------------------------------------------- */ + +/** + * Booking confirmation controller. + * + * Handles the booking confirmation related operations. + * + * @package Controllers + */ +class Booking_confirmation extends EA_Controller { + /** + * Booking constructor. + */ + public function __construct() + { + parent::__construct(); + + $this->load->model('appointments_model'); + $this->load->model('providers_model'); + $this->load->model('services_model'); + $this->load->model('customers_model'); + } + + /** + * Display the appointment registration success page. + * + * @param string $appointment_hash The appointment hash identifier. + * + * @throws Exception + */ + public function of(string $appointment_hash) + { + $occurrences = $this->appointments_model->get(['hash' => $appointment_hash]); + + if (empty($occurrences)) + { + redirect('appointments'); // The appointment does not exist. + + return; + } + + $appointment = $occurrences[0]; + + unset($appointment['notes']); + + $customer = $this->customers_model->find($appointment['id_users_customer']); + + $provider = $this->providers_model->find($appointment['id_users_provider']); + + $service = $this->services_model->find($appointment['id_services']); + + $company_name = setting('company_name'); + + $exceptions = $this->session->flashdata('book_success') ?? []; + + $this->load->view('pages/booking_confirmation', [ + 'page_title' => lang('success'), + 'appointment_data' => $appointment, + 'provider_data' => [ + 'id' => $provider['id'], + 'first_name' => $provider['first_name'], + 'last_name' => $provider['last_name'], + 'email' => $provider['email'], + 'timezone' => $provider['timezone'], + ], + 'customer_data' => [ + 'id' => $customer['id'], + 'first_name' => $customer['first_name'], + 'last_name' => $customer['last_name'], + 'email' => $customer['email'], + 'timezone' => $customer['timezone'], + ], + 'service_data' => $service, + 'company_name' => $company_name, + 'exceptions' => $exceptions, + 'scripts' => [ + 'https://apis.google.com/js/client.js', + asset_url('assets/vendor/datejs/date.min.js'), + asset_url('assets/vendor/moment/moment.min.js'), + asset_url('assets/vendor/moment-timezone/moment-timezone-with-data.min.js'), + asset_url('assets/js/frontend_book_success.js'), + asset_url('assets/js/general_functions.js') + ] + ]); + } +} diff --git a/application/views/components/booking_cancellation_frame.php b/application/views/components/booking_cancellation_frame.php index 00481104..b04b8233 100644 --- a/application/views/components/booking_cancellation_frame.php +++ b/application/views/components/booking_cancellation_frame.php @@ -12,7 +12,7 @@