From 97f98c5118927554bda4574ead672d5448342421 Mon Sep 17 00:00:00 2001 From: Alex Tselegidis Date: Mon, 24 Jan 2022 21:57:17 +0100 Subject: [PATCH] All the user roles with access to the backend calendar page can filter by service (#956). --- application/controllers/Calendar.php | 14 ++++++++++++++ assets/js/utils/calendar_default_view.js | 20 -------------------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/application/controllers/Calendar.php b/application/controllers/Calendar.php index 7773796f..541036e0 100644 --- a/application/controllers/Calendar.php +++ b/application/controllers/Calendar.php @@ -98,6 +98,20 @@ class Calendar extends EA_Controller { $available_providers = $this->providers_model->get_available_providers(); + if ($role_slug === DB_SLUG_PROVIDER) + { + $available_providers = array_filter($available_providers, function ($available_provider) use ($user_id) { + return (int)$available_provider['id'] === (int)$user_id; + }); + } + + if ($role_slug === DB_SLUG_SECRETARY) + { + $available_providers = array_filter($available_providers, function ($available_provider) use ($secretary_providers) { + return in_array($available_provider['id'], $secretary_providers); + }); + } + $available_services = $this->services_model->get_available_services(); $calendar_view = request('view', $user['settings']['calendar_view']); diff --git a/assets/js/utils/calendar_default_view.js b/assets/js/utils/calendar_default_view.js index 07ffb3a8..b666cce3 100755 --- a/assets/js/utils/calendar_default_view.js +++ b/assets/js/utils/calendar_default_view.js @@ -1580,26 +1580,6 @@ App.Utils.CalendarDefaultView = (function () { .find('optgroup:eq(0)') .find('option[value="' + vars('user_id') + '"]') .prop('selected', true); - $selectFilterItem.prop('disabled', true); - } - - if (vars('role_slug') === App.Layouts.Backend.DB_SLUG_SECRETARY) { - // Remove the providers that are not connected to the secretary. - $selectFilterItem.find('optgroup:eq(1)').remove(); - - $selectFilterItem.find('option[type="provider"]').each((index, option) => { - const provider = vars('secretary_providers').find( - (secretaryProviderId) => Number($(option).val()) === Number(secretaryProviderId) - ); - - if (!provider) { - $(option).remove(); - } - }); - - if (!$selectFilterItem.find('option[type="provider"]').length) { - $selectFilterItem('optgroup[type="providers-group"]').remove(); - } } // Add the page event listeners.