Miscellaneous fixes and refactoring on Appointments.php

This commit is contained in:
alextselegidis 2021-11-12 17:23:43 +01:00
parent 548bc04c88
commit 2d1c7c0f7a

View file

@ -197,6 +197,8 @@ class Appointments extends EA_Controller {
{ {
try try
{ {
$exceptions = [];
$occurrences = $this->appointments_model->get(['hash' => $appointment_hash]); $occurrences = $this->appointments_model->get(['hash' => $appointment_hash]);
if (empty($occurrences)) if (empty($occurrences))
@ -231,18 +233,12 @@ class Appointments extends EA_Controller {
$exceptions[] = $e; $exceptions[] = $e;
} }
$view = [ $this->load->layout('layouts/message/message_layout', 'pages/booking/booking_message_page', [
'message_title' => lang('appointment_cancelled_title'), 'message_title' => lang('appointment_cancelled_title'),
'message_text' => lang('appointment_cancelled'), 'message_text' => lang('appointment_cancelled'),
'message_icon' => base_url('assets/img/success.png') 'message_icon' => base_url('assets/img/success.png'),
]; 'exceptions' => $exceptions
]);
if (isset($exceptions))
{
$view['exceptions'] = $exceptions;
}
$this->load->layout('layouts/message/message_layout', 'pages/booking/booking_message_page', $view);
} }
/** /**
@ -259,6 +255,7 @@ class Appointments extends EA_Controller {
if (empty($occurrences)) if (empty($occurrences))
{ {
redirect('appointments'); // The appointment does not exist. redirect('appointments'); // The appointment does not exist.
return; return;
} }
@ -274,9 +271,9 @@ class Appointments extends EA_Controller {
$company_name = setting('company_name'); $company_name = setting('company_name');
$exceptions = $this->session->flashdata('book_success'); $exceptions = $this->session->flashdata('book_success') ?? [];
$view = [ $this->load->layout('layouts/message/message_layout', 'pages/booking/booking_success_page', [
'appointment_data' => $appointment, 'appointment_data' => $appointment,
'provider_data' => [ 'provider_data' => [
'id' => $provider['id'], 'id' => $provider['id'],
@ -294,14 +291,8 @@ class Appointments extends EA_Controller {
], ],
'service_data' => $service, 'service_data' => $service,
'company_name' => $company_name, 'company_name' => $company_name,
]; 'exceptions' => $exceptions
]);
if ($exceptions)
{
$view['exceptions'] = $exceptions;
}
$this->load->layout('layouts/message/message_layout', 'pages/booking/booking_success_page', $view);
} }
/** /**
@ -321,9 +312,7 @@ class Appointments extends EA_Controller {
// Do not continue if there was no provider selected (more likely there is no provider in the system). // Do not continue if there was no provider selected (more likely there is no provider in the system).
if (empty($provider_id)) if (empty($provider_id))
{ {
$this->output json_response([]);
->set_content_type('application/json')
->set_output(json_encode([]));
return; return;
} }
@ -362,20 +351,13 @@ class Appointments extends EA_Controller {
$response = $this->availability->get_available_hours($selected_date, $service, $provider, $exclude_appointment_id); $response = $this->availability->get_available_hours($selected_date, $service, $provider, $exclude_appointment_id);
} }
json_response($response);
} }
catch (Throwable $e) catch (Throwable $e)
{ {
$this->output->set_status_header(500); json_exception($e);
$response = [
'message' => $e->getMessage(),
'trace' => config('debug') ? $e->getTrace() : []
];
} }
$this->output
->set_content_type('application/json')
->set_output(json_encode($response));
} }
/** /**
@ -441,18 +423,22 @@ class Appointments extends EA_Controller {
{ {
$customer['address'] = ''; $customer['address'] = '';
} }
if ( ! array_key_exists('city', $customer)) if ( ! array_key_exists('city', $customer))
{ {
$customer['city'] = ''; $customer['city'] = '';
} }
if ( ! array_key_exists('zip_code', $customer)) if ( ! array_key_exists('zip_code', $customer))
{ {
$customer['zip_code'] = ''; $customer['zip_code'] = '';
} }
if ( ! array_key_exists('notes', $customer)) if ( ! array_key_exists('notes', $customer))
{ {
$customer['notes'] = ''; $customer['notes'] = '';
} }
if ( ! array_key_exists('phone_number', $customer)) if ( ! array_key_exists('phone_number', $customer))
{ {
$customer['address'] = ''; $customer['address'] = '';
@ -477,11 +463,9 @@ class Appointments extends EA_Controller {
// Validate the CAPTCHA string. // Validate the CAPTCHA string.
if ($require_captcha && $captcha_phrase !== $captcha) if ($require_captcha && $captcha_phrase !== $captcha)
{ {
$this->output json_response([
->set_content_type('application/json') 'captcha_verification' => FALSE
->set_output(json_encode([ ]);
'captcha_verification' => FALSE
]));
return; return;
} }
@ -521,20 +505,13 @@ class Appointments extends EA_Controller {
'appointment_id' => $appointment['id'], 'appointment_id' => $appointment['id'],
'appointment_hash' => $appointment['hash'] 'appointment_hash' => $appointment['hash']
]; ];
json_response($response);
} }
catch (Throwable $e) catch (Throwable $e)
{ {
$this->output->set_status_header(500); json_exception($e);
$response = [
'message' => $e->getMessage(),
'trace' => config('debug') ? $e->getTrace() : []
];
} }
$this->output
->set_content_type('application/json')
->set_output(json_encode($response));
} }
/** /**
@ -661,21 +638,12 @@ class Appointments extends EA_Controller {
} }
} }
$response = $unavailable_dates; json_response($unavailable_dates);
} }
catch (Throwable $e) catch (Throwable $e)
{ {
$this->output->set_status_header(500); json_exception($e);
$response = [
'message' => $e->getMessage(),
'trace' => config('debug') ? $e->getTrace() : []
];
} }
$this->output
->set_content_type('application/json')
->set_output(json_encode($response));
} }
/** /**
@ -706,6 +674,4 @@ class Appointments extends EA_Controller {
return $provider_list; return $provider_list;
} }
} }