Use the "array_values" method in both available-provider filtering conditions to avoid issues with missing keys

This commit is contained in:
Alex Tselegidis 2023-01-14 10:16:32 +01:00
parent cfe88f8901
commit dfacdc901a

View file

@ -101,16 +101,16 @@ class Calendar extends EA_Controller {
if ($role_slug === DB_SLUG_PROVIDER) if ($role_slug === DB_SLUG_PROVIDER)
{ {
$available_providers = array_filter($available_providers, function ($available_provider) use ($user_id) { $available_providers = array_values(array_filter($available_providers, function ($available_provider) use ($user_id) {
return (int)$available_provider['id'] === (int)$user_id; return (int)$available_provider['id'] === (int)$user_id;
}); }));
} }
if ($role_slug === DB_SLUG_SECRETARY) if ($role_slug === DB_SLUG_SECRETARY)
{ {
$available_providers = array_filter($available_providers, function ($available_provider) use ($secretary_providers) { $available_providers = array_values(array_filter($available_providers, function ($available_provider) use ($secretary_providers) {
return in_array($available_provider['id'], $secretary_providers); return in_array($available_provider['id'], $secretary_providers);
}); }));
} }
$available_services = $this->services_model->get_available_services(); $available_services = $this->services_model->get_available_services();
@ -129,7 +129,7 @@ class Calendar extends EA_Controller {
'timezones' => $this->timezones->to_array(), 'timezones' => $this->timezones->to_array(),
'privileges' => $privileges, 'privileges' => $privileges,
'calendar_view' => $calendar_view, 'calendar_view' => $calendar_view,
'available_providers' => array_values($available_providers), // Strip keys to prevent unintended array-to-object conversion 'available_providers' => $available_providers,
'available_services' => $available_services, 'available_services' => $available_services,
'secretary_providers' => $secretary_providers, 'secretary_providers' => $secretary_providers,
'edit_appointment' => $edit_appointment, 'edit_appointment' => $edit_appointment,