Minor refactoring for the appointments page

This commit is contained in:
alextselegidis 2021-11-12 17:09:31 +01:00
parent eb64b6c7ef
commit d2be2327e8

View file

@ -52,12 +52,11 @@ class Appointments extends EA_Controller {
* @param string $appointment_hash The appointment hash identifier. * @param string $appointment_hash The appointment hash identifier.
*/ */
public function index(string $appointment_hash = '') public function index(string $appointment_hash = '')
{
try
{ {
if ( ! is_app_installed()) if ( ! is_app_installed())
{ {
redirect('installation'); redirect('installation');
return; return;
} }
@ -84,20 +83,19 @@ class Appointments extends EA_Controller {
$timezones = $this->timezones->to_array(); $timezones = $this->timezones->to_array();
// Remove the data that are not needed inside the $available_providers array. // Remove the data that are not needed inside the $available_providers array.
foreach ($available_providers as $index => $provider) foreach ($available_providers as &$available_provider)
{ {
$stripped_data = [ $this->providers_model->only($available_provider, [
'id' => $provider['id'], 'id',
'first_name' => $provider['first_name'], 'first_name',
'last_name' => $provider['last_name'], 'last_name',
'services' => $provider['services'], 'services',
'timezone' => $provider['timezone'] 'timezone'
]; ]);
$available_providers[$index] = $stripped_data;
} }
// If an appointment hash is provided then it means that the customer is trying to edit a registered // If an appointment hash is provided then it means that the customer is trying to edit a registered appointment
// appointment record. // record.
if ($appointment_hash !== '') if ($appointment_hash !== '')
{ {
// Load the appointments data and enable the manage mode of the page. // Load the appointments data and enable the manage mode of the page.
@ -108,13 +106,11 @@ class Appointments extends EA_Controller {
if (empty($results)) if (empty($results))
{ {
// The requested appointment was not found in the database. // The requested appointment was not found in the database.
$view = [ $this->load->layout('layouts/message/message_layout', 'pages/booking/booking_message_page', [
'message_title' => lang('appointment_not_found'), 'message_title' => lang('appointment_not_found'),
'message_text' => lang('appointment_does_not_exist_in_db'), 'message_text' => lang('appointment_does_not_exist_in_db'),
'message_icon' => base_url('assets/img/error.png') 'message_icon' => base_url('assets/img/error.png')
]; ]);
$this->load->layout('layouts/message/message_layout', 'pages/booking/booking_message_page', $view);
return; return;
} }
@ -130,15 +126,13 @@ class Appointments extends EA_Controller {
$hours = floor($book_advance_timeout / 60); $hours = floor($book_advance_timeout / 60);
$minutes = ($book_advance_timeout % 60); $minutes = ($book_advance_timeout % 60);
$view = [ $this->load->layout('layouts/message/message_layout', 'pages/booking/booking_message_page', [
'message_title' => lang('appointment_locked'), 'message_title' => lang('appointment_locked'),
'message_text' => strtr(lang('appointment_locked_message'), [ 'message_text' => strtr(lang('appointment_locked_message'), [
'{$limit}' => sprintf('%02d:%02d', $hours, $minutes) '{$limit}' => sprintf('%02d:%02d', $hours, $minutes)
]), ]),
'message_icon' => base_url('assets/img/error.png') 'message_icon' => base_url('assets/img/error.png')
]; ]);
$this->load->layout('layouts/message/message_layout', 'pages/booking/booking_message_page', $view);
return; return;
} }
@ -151,7 +145,7 @@ class Appointments extends EA_Controller {
$customer_token = md5(uniqid(mt_rand(), TRUE)); $customer_token = md5(uniqid(mt_rand(), TRUE));
// Save the token for 10 minutes. // Cache the token for 10 minutes.
$this->cache->save('customer-token-' . $customer_token, $customer['id'], 600); $this->cache->save('customer-token-' . $customer_token, $customer['id'], 600);
} }
else else
@ -165,8 +159,7 @@ class Appointments extends EA_Controller {
$customer = []; $customer = [];
} }
// Load the book appointment view. $this->load->layout('layouts/booking/booking_layout', 'pages/booking/booking_page', [
$view = [
'available_services' => $available_services, 'available_services' => $available_services,
'available_providers' => $available_providers, 'available_providers' => $available_providers,
'company_name' => $company_name, 'company_name' => $company_name,
@ -188,14 +181,7 @@ class Appointments extends EA_Controller {
'privacy_policy_content' => $privacy_policy_content, 'privacy_policy_content' => $privacy_policy_content,
'timezones' => $timezones, 'timezones' => $timezones,
'display_any_provider' => $display_any_provider, 'display_any_provider' => $display_any_provider,
]; ]);
}
catch (Throwable $e)
{
$view['exceptions'][] = $e;
}
$this->load->layout('layouts/booking/booking_layout', 'pages/booking/booking_page', $view);
} }
/** /**