Various fixes in the Calendar controller

This commit is contained in:
Alex Tselegidis 2024-04-26 16:23:58 +02:00
parent a61701e2ad
commit e51f8ff377

View file

@ -50,7 +50,7 @@ class Calendar extends EA_Controller
* *
* @param string $appointment_hash Appointment hash. * @param string $appointment_hash Appointment hash.
*/ */
public function reschedule(string $appointment_hash) public function reschedule(string $appointment_hash): void
{ {
$this->index($appointment_hash); $this->index($appointment_hash);
} }
@ -64,7 +64,7 @@ class Calendar extends EA_Controller
* *
* @param string $appointment_hash Appointment hash. * @param string $appointment_hash Appointment hash.
*/ */
public function index(string $appointment_hash = '') public function index(string $appointment_hash = ''): void
{ {
session(['dest_url' => site_url('backend/index' . (!empty($appointment_hash) ? '/' . $appointment_hash : ''))]); session(['dest_url' => site_url('backend/index' . (!empty($appointment_hash) ? '/' . $appointment_hash : ''))]);
@ -176,7 +176,7 @@ class Calendar extends EA_Controller
/** /**
* Save appointment changes that are made from the backend calendar page. * Save appointment changes that are made from the backend calendar page.
*/ */
public function save_appointment() public function save_appointment(): void
{ {
try { try {
$customer_data = request('customer_data'); $customer_data = request('customer_data');
@ -209,6 +209,11 @@ class Calendar extends EA_Controller
'timezone', 'timezone',
'language', 'language',
'notes', 'notes',
'custom_field_1',
'custom_field_2',
'custom_field_3',
'custom_field_4',
'custom_field_5',
]); ]);
$customer['id'] = $this->customers_model->save($customer); $customer['id'] = $this->customers_model->save($customer);
@ -246,7 +251,6 @@ class Calendar extends EA_Controller
'notes', 'notes',
'color', 'color',
'status', 'status',
'notes',
'is_unavailability', 'is_unavailability',
'id_users_provider', 'id_users_provider',
'id_users_customer', 'id_users_customer',
@ -318,7 +322,7 @@ class Calendar extends EA_Controller
* Notification emails are send to both provider and customer and the delete action is executed to the Google * Notification emails are send to both provider and customer and the delete action is executed to the Google
* Calendar account of the provider, if the "google_sync" setting is enabled. * Calendar account of the provider, if the "google_sync" setting is enabled.
*/ */
public function delete_appointment() public function delete_appointment(): void
{ {
try { try {
if (cannot('delete', 'appointments')) { if (cannot('delete', 'appointments')) {
@ -376,7 +380,7 @@ class Calendar extends EA_Controller
/** /**
* Insert of update unavailability to database. * Insert of update unavailability to database.
*/ */
public function save_unavailability() public function save_unavailability(): void
{ {
try { try {
// Check privileges // Check privileges
@ -416,7 +420,7 @@ class Calendar extends EA_Controller
/** /**
* Delete an unavailability from database. * Delete an unavailability from database.
*/ */
public function delete_unavailability() public function delete_unavailability(): void
{ {
try { try {
if (cannot('delete', PRIV_APPOINTMENTS)) { if (cannot('delete', PRIV_APPOINTMENTS)) {
@ -448,7 +452,7 @@ class Calendar extends EA_Controller
/** /**
* Insert of update working plan exceptions to database. * Insert of update working plan exceptions to database.
*/ */
public function save_working_plan_exception() public function save_working_plan_exception(): void
{ {
try { try {
if (cannot('edit', PRIV_USERS)) { if (cannot('edit', PRIV_USERS)) {
@ -478,7 +482,7 @@ class Calendar extends EA_Controller
/** /**
* Delete a working plan exceptions time period to database. * Delete a working plan exceptions time period to database.
*/ */
public function delete_working_plan_exception() public function delete_working_plan_exception(): void
{ {
try { try {
$required_permissions = can('edit', PRIV_CUSTOMERS); $required_permissions = can('edit', PRIV_CUSTOMERS);
@ -506,7 +510,7 @@ class Calendar extends EA_Controller
* *
* This method will return all the calendar events within a specified period. * This method will return all the calendar events within a specified period.
*/ */
public function get_calendar_appointments_for_table_view() public function get_calendar_appointments_for_table_view(): void
{ {
try { try {
$required_permissions = can('view', PRIV_APPOINTMENTS); $required_permissions = can('view', PRIV_APPOINTMENTS);
@ -582,6 +586,12 @@ class Calendar extends EA_Controller
$response['unavailabilities'] = array_values($response['unavailabilities']); $response['unavailabilities'] = array_values($response['unavailabilities']);
} }
foreach ($response['unavailabilities'] as &$unavailability) {
$unavailability['provider'] = $this->providers_model->find($unavailability['id_users_provider']);
}
unset($unavailability);
// Add blocked periods to the response. // Add blocked periods to the response.
$start_date = request('start_date'); $start_date = request('start_date');
$end_date = request('end_date'); $end_date = request('end_date');
@ -599,7 +609,7 @@ class Calendar extends EA_Controller
* This method returns the database appointments and unavailability periods for the user selected date period and * This method returns the database appointments and unavailability periods for the user selected date period and
* record type (provider or service). * record type (provider or service).
*/ */
public function get_calendar_appointments() public function get_calendar_appointments(): void
{ {
try { try {
if (cannot('view', PRIV_APPOINTMENTS)) { if (cannot('view', PRIV_APPOINTMENTS)) {
@ -720,6 +730,8 @@ class Calendar extends EA_Controller
} }
} }
unset($unavailability);
$response['unavailabilities'] = array_values($response['unavailabilities']); $response['unavailabilities'] = array_values($response['unavailabilities']);
} }