Menu.php
152 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaBooking\Infrastructure\WP\config; |
| 4 | |
| 5 | use AmeliaBooking\Domain\Services\Settings\SettingsService; |
| 6 | use AmeliaBooking\Infrastructure\Licence\Licence; |
| 7 | use AmeliaBooking\Infrastructure\WP\Translations\BackendStrings; |
| 8 | |
| 9 | /** |
| 10 | * Class Menu |
| 11 | */ |
| 12 | class Menu |
| 13 | { |
| 14 | private SettingsService $settingsService; |
| 15 | |
| 16 | public function __construct(SettingsService $settingsService) |
| 17 | { |
| 18 | $this->settingsService = $settingsService; |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * @return array |
| 23 | */ |
| 24 | public function __invoke() |
| 25 | { |
| 26 | $defaultPageOnBackend = $this->settingsService->getSetting( |
| 27 | 'general', |
| 28 | 'defaultPageOnBackend' |
| 29 | ); |
| 30 | |
| 31 | $menuItems = [ |
| 32 | [ |
| 33 | 'parentSlug' => 'amelia', |
| 34 | 'pageTitle' => BackendStrings::get('dashboard'), |
| 35 | 'menuTitle' => BackendStrings::get('dashboard'), |
| 36 | 'capability' => 'amelia_read_dashboard', |
| 37 | 'menuSlug' => 'wpamelia-dashboard', |
| 38 | ], |
| 39 | [ |
| 40 | 'parentSlug' => 'amelia', |
| 41 | 'pageTitle' => BackendStrings::get('calendar'), |
| 42 | 'menuTitle' => BackendStrings::get('calendar'), |
| 43 | 'capability' => 'amelia_read_calendar', |
| 44 | 'menuSlug' => 'wpamelia-calendar', |
| 45 | ], |
| 46 | [ |
| 47 | 'parentSlug' => 'amelia', |
| 48 | 'pageTitle' => BackendStrings::get('bookings'), |
| 49 | 'menuTitle' => BackendStrings::get('bookings'), |
| 50 | 'capability' => 'amelia_read_appointments', |
| 51 | 'menuSlug' => 'wpamelia-bookings', |
| 52 | ], |
| 53 | [ |
| 54 | 'parentSlug' => 'amelia', |
| 55 | 'pageTitle' => BackendStrings::get('events'), |
| 56 | 'menuTitle' => BackendStrings::get('events'), |
| 57 | 'capability' => 'amelia_read_events', |
| 58 | 'menuSlug' => 'wpamelia-events', |
| 59 | ], |
| 60 | [ |
| 61 | 'parentSlug' => 'amelia', |
| 62 | 'pageTitle' => Licence::getLicence() === 'Lite' |
| 63 | ? BackendStrings::get('employee') |
| 64 | : BackendStrings::get('employees'), |
| 65 | 'menuTitle' => Licence::getLicence() === 'Lite' |
| 66 | ? BackendStrings::get('employee') |
| 67 | : BackendStrings::get('employees'), |
| 68 | 'capability' => 'amelia_read_employees', |
| 69 | 'menuSlug' => 'wpamelia-employees', |
| 70 | ], |
| 71 | [ |
| 72 | 'parentSlug' => 'amelia', |
| 73 | 'pageTitle' => BackendStrings::get('red_catalog'), |
| 74 | 'menuTitle' => BackendStrings::get('red_catalog'), |
| 75 | 'capability' => 'amelia_read_services', |
| 76 | 'menuSlug' => 'wpamelia-catalog', |
| 77 | ], |
| 78 | [ |
| 79 | 'parentSlug' => 'amelia', |
| 80 | 'pageTitle' => BackendStrings::get('locations'), |
| 81 | 'menuTitle' => BackendStrings::get('locations'), |
| 82 | 'capability' => 'amelia_read_locations', |
| 83 | 'menuSlug' => 'wpamelia-locations', |
| 84 | ], |
| 85 | [ |
| 86 | 'parentSlug' => 'amelia', |
| 87 | 'pageTitle' => BackendStrings::get('customers'), |
| 88 | 'menuTitle' => BackendStrings::get('customers'), |
| 89 | 'capability' => 'amelia_read_customers', |
| 90 | 'menuSlug' => 'wpamelia-customers', |
| 91 | ], |
| 92 | [ |
| 93 | 'parentSlug' => 'amelia', |
| 94 | 'pageTitle' => BackendStrings::get('finance'), |
| 95 | 'menuTitle' => BackendStrings::get('finance'), |
| 96 | 'capability' => 'amelia_read_finance', |
| 97 | 'menuSlug' => 'wpamelia-finance', |
| 98 | ], |
| 99 | [ |
| 100 | 'parentSlug' => 'amelia', |
| 101 | 'pageTitle' => BackendStrings::get('red_notifications'), |
| 102 | 'menuTitle' => BackendStrings::get('red_notifications'), |
| 103 | 'capability' => 'amelia_read_notifications', |
| 104 | 'menuSlug' => 'wpamelia-notifications', |
| 105 | ], |
| 106 | [ |
| 107 | 'parentSlug' => 'amelia', |
| 108 | 'pageTitle' => BackendStrings::get('customize'), |
| 109 | 'menuTitle' => BackendStrings::get('customize'), |
| 110 | 'capability' => 'amelia_read_customize', |
| 111 | 'menuSlug' => 'wpamelia-customize', |
| 112 | ], |
| 113 | [ |
| 114 | 'parentSlug' => 'amelia', |
| 115 | 'pageTitle' => BackendStrings::get('custom_fields_title'), |
| 116 | 'menuTitle' => BackendStrings::get('custom_fields_title'), |
| 117 | 'capability' => 'amelia_read_custom_fields', |
| 118 | 'menuSlug' => 'wpamelia-customfields', |
| 119 | ], |
| 120 | [ |
| 121 | 'parentSlug' => 'amelia', |
| 122 | 'pageTitle' => BackendStrings::get('red_features_integrations'), |
| 123 | 'menuTitle' => BackendStrings::get('red_features_integrations'), |
| 124 | 'capability' => 'amelia_read_settings', |
| 125 | 'menuSlug' => 'wpamelia-features-integrations', |
| 126 | ], |
| 127 | [ |
| 128 | 'parentSlug' => 'amelia', |
| 129 | 'pageTitle' => BackendStrings::get('settings'), |
| 130 | 'menuTitle' => BackendStrings::get('settings'), |
| 131 | 'capability' => 'amelia_read_settings', |
| 132 | 'menuSlug' => 'wpamelia-settings', |
| 133 | ], |
| 134 | [ |
| 135 | 'parentSlug' => 'amelia', |
| 136 | 'pageTitle' => BackendStrings::get('whats_new'), |
| 137 | 'menuTitle' => BackendStrings::get('whats_new'), |
| 138 | 'capability' => 'amelia_read_whats_new', |
| 139 | 'menuSlug' => 'wpamelia-whats-new', |
| 140 | ], |
| 141 | ]; |
| 142 | |
| 143 | $defaultPageKey = array_search($defaultPageOnBackend, array_column($menuItems, 'pageTitle'), true); |
| 144 | $defaultPagesElement = array_splice($menuItems, $defaultPageKey, 1); |
| 145 | |
| 146 | return array_merge( |
| 147 | $defaultPagesElement, |
| 148 | $menuItems, |
| 149 | ); |
| 150 | } |
| 151 | } |
| 152 |