activities_helper.php
1 year ago
agent_helper.php
1 year ago
auth_helper.php
1 year ago
blocks_helper.php
1 year ago
booking_helper.php
1 year ago
bricks_helper.php
1 year ago
bundles_helper.php
1 year ago
calendar_helper.php
1 year ago
carts_helper.php
1 year ago
connector_helper.php
1 year ago
csv_helper.php
1 year ago
customer_helper.php
1 year ago
database_helper.php
1 year ago
debug_helper.php
1 year ago
defaults_helper.php
1 year ago
elementor_helper.php
1 year ago
email_helper.php
1 year ago
encrypt_helper.php
1 year ago
events_helper.php
1 year ago
form_helper.php
1 year ago
icalendar_helper.php
1 year ago
image_helper.php
1 year ago
invoices_helper.php
1 year ago
license_helper.php
1 year ago
location_helper.php
1 year ago
marketing_systems_helper.php
1 year ago
meeting_systems_helper.php
1 year ago
menu_helper.php
1 year ago
meta_helper.php
1 year ago
migrations_helper.php
1 year ago
money_helper.php
1 year ago
notifications_helper.php
1 year ago
order_intent_helper.php
1 year ago
orders_helper.php
1 year ago
pages_helper.php
1 year ago
params_helper.php
1 year ago
payments_helper.php
1 year ago
price_breakdown_helper.php
1 year ago
process_jobs_helper.php
1 year ago
processes_helper.php
1 year ago
replacer_helper.php
1 year ago
resource_helper.php
1 year ago
roles_helper.php
1 year ago
router_helper.php
1 year ago
service_helper.php
1 year ago
sessions_helper.php
1 year ago
settings_helper.php
1 year ago
shortcodes_helper.php
1 year ago
sms_helper.php
1 year ago
steps_helper.php
1 year ago
stripe_connect_helper.php
1 year ago
styles_helper.php
1 year ago
support_topics_helper.php
1 year ago
time_helper.php
1 year ago
timeline_helper.php
1 year ago
transaction_helper.php
1 year ago
transaction_intent_helper.php
1 year ago
util_helper.php
1 year ago
version_specific_updates_helper.php
1 year ago
whatsapp_helper.php
1 year ago
work_periods_helper.php
1 year ago
wp_datetime.php
1 year ago
wp_user_helper.php
1 year ago
menu_helper.php
166 lines
| 1 | <?php |
| 2 | |
| 3 | class OsMenuHelper { |
| 4 | |
| 5 | public static array $side_menu_items; |
| 6 | |
| 7 | public static function get_menu_items_by_id($query){ |
| 8 | $menus = self::get_side_menu_items(); |
| 9 | foreach($menus as $menu_item){ |
| 10 | if(isset($menu_item['id']) && $menu_item['id'] == $query){ |
| 11 | if(isset($menu_item['children'])){ |
| 12 | // has sub items |
| 13 | return $menu_item['children']; |
| 14 | }else{ |
| 15 | // no sub items |
| 16 | return $menu_item['label']; |
| 17 | } |
| 18 | } |
| 19 | } |
| 20 | return false; |
| 21 | } |
| 22 | |
| 23 | public static function get_label_by_id($query){ |
| 24 | $menus = self::get_side_menu_items(); |
| 25 | foreach($menus as $menu_item){ |
| 26 | if(isset($menu_item['id']) && $menu_item['id'] == $query){ |
| 27 | return $menu_item['label']; |
| 28 | } |
| 29 | } |
| 30 | return false; |
| 31 | } |
| 32 | |
| 33 | public static function get_side_menu_items() { |
| 34 | if(isset(self::$side_menu_items)) return self::$side_menu_items; |
| 35 | $is_update_available = false; |
| 36 | $menus = []; |
| 37 | $user_role = OsAuthHelper::get_current_user()->backend_user_type; |
| 38 | switch($user_role){ |
| 39 | case LATEPOINT_USER_TYPE_ADMIN: |
| 40 | case LATEPOINT_USER_TYPE_CUSTOM: |
| 41 | // --------------- |
| 42 | // ADMINISTRATOR MENU |
| 43 | // --------------- |
| 44 | $menus = array( |
| 45 | array( 'id' => 'dashboard', 'label' => __( 'Dashboard', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-dashboard', 'link' => OsRouterHelper::build_link(['dashboard', 'index'])), |
| 46 | array( 'id' => 'calendar', 'label' => __( 'Calendar', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-calendar2', 'link' => OsRouterHelper::build_link(['calendars', 'view'])), |
| 47 | array( 'id' => 'appointments', 'label' => __( 'Appointments', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-box1', 'link' => OsRouterHelper::build_link(['bookings', 'index'])), |
| 48 | array( 'id' => 'orders', 'label' => __( 'Orders', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-book2', 'link' => OsRouterHelper::build_link(['orders', 'index'])), |
| 49 | array( 'id' => 'payments', 'label' => __( 'Payments', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-cart', 'link' => OsRouterHelper::build_link(['transactions', 'index'])), |
| 50 | array( 'id' => 'customers', 'label' => __( 'Customers', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-user1', 'link' => OsRouterHelper::build_link(['customers', 'index'])), |
| 51 | array('label' => '', 'small_label' => __('Resources', 'latepoint'), 'menu_section' => 'records'), |
| 52 | array( 'id' => 'services', 'label' => __( 'Services', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-folder', 'link' => OsRouterHelper::build_link(['services', 'index']), |
| 53 | 'children' => array( |
| 54 | array('id' => 'index','label' => __( 'Services', 'latepoint' ), 'icon' => '', 'link' => OsRouterHelper::build_link(['services', 'index'])), |
| 55 | array('id' => 'bundles','label' => __( 'Bundles', 'latepoint' ), 'icon' => '', 'link' => OsRouterHelper::build_link(['pro', 'bundles'])), |
| 56 | array('id' => 'categories','label' => __( 'Categories', 'latepoint' ), 'icon' => '', 'link' => OsRouterHelper::build_link(['pro', 'categories'])), |
| 57 | array('id' => 'service_extras','label' => __( 'Service Extras', 'latepoint' ), 'icon' => '', 'link' => OsRouterHelper::build_link(['pro', 'service_extras'])), |
| 58 | ) |
| 59 | ), |
| 60 | array( 'id' => 'agents', 'label' => __( 'Agents', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-user1', 'link' => OsRouterHelper::build_link(['default_agent', 'edit_form'])), |
| 61 | array( 'id' => 'locations', 'label' => __( 'Locations', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-map-marker', 'link' => OsRouterHelper::build_link(['pro', 'locations'])), |
| 62 | array('id' => 'coupons', 'label' => __( 'Coupons', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-tag1', 'link' => OsRouterHelper::build_link(['pro', 'coupons'])), |
| 63 | array('label' => '', 'small_label' => __('Settings', 'latepoint'), 'menu_section' => 'settings'), |
| 64 | array( 'id' => 'settings', 'show_notice' => $is_update_available, 'label' => __( 'Settings', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-cog1', 'link' => OsRouterHelper::build_link(['settings', 'general']), |
| 65 | 'children' => array( |
| 66 | array('id' => 'general', 'label' => __( 'General', 'latepoint' ), 'icon' => '', 'link' => OsRouterHelper::build_link(['settings', 'general'])), |
| 67 | array('id' => 'schedule', 'label' => __( 'Schedule', 'latepoint' ), 'icon' => '', 'link' => OsRouterHelper::build_link(['settings', 'work_periods'])), |
| 68 | array('id' => 'taxes', 'label' => __( 'Tax', 'latepoint' ), 'icon' => '', 'link' => OsRouterHelper::build_link(['pro', 'taxes'])), |
| 69 | array('id' => 'booking_form', 'label' => __( 'Booking Form', 'latepoint' ), 'icon' => '', 'link' => OsRouterHelper::build_link(['booking_form_settings', 'show'])), |
| 70 | array('id' => 'payments', 'label' => __( 'Payments', 'latepoint' ), 'icon' => '', 'link' => OsRouterHelper::build_link(['settings', 'payments'])), |
| 71 | array('id' => 'notifications', 'label' => __( 'Notifications', 'latepoint' ), 'icon' => '', 'link' => OsRouterHelper::build_link(['settings', 'notifications'])), |
| 72 | array('id' => 'roles', 'label' => __( 'Roles', 'latepoint' ), 'icon' => '', 'link' => OsRouterHelper::build_link(['pro', 'roles'])), |
| 73 | ) |
| 74 | ), |
| 75 | array( 'id' => 'processes', 'label' => __( 'Automation', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-play', 'link' => OsRouterHelper::build_link(['processes', 'index']), |
| 76 | 'children' => array( |
| 77 | array('label' => __('Workflows', 'latepoint'), 'icon' => '', 'link' => OsRouterHelper::build_link(['processes', 'index'])), |
| 78 | array('label' => __('Scheduled Jobs', 'latepoint'), 'icon' => '', 'link' => OsRouterHelper::build_link(['process_jobs', 'index'])), |
| 79 | array('label' => __('Activity Log', 'latepoint'), 'icon' => '', 'link' => OsRouterHelper::build_link(['activities', 'index'])), |
| 80 | ) |
| 81 | ), |
| 82 | array( 'id' => 'integrations', 'label' => __( 'Integrations', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-windows', 'link' => OsRouterHelper::build_link(['integrations', 'external_calendars']), |
| 83 | 'children' => array( |
| 84 | array('id' => 'calendars', 'label' => __( 'Calendars', 'latepoint' ), 'icon' => '', 'link' => OsRouterHelper::build_link(['integrations', 'external_calendars'])), |
| 85 | array('id' => 'meetings', 'label' => __( 'Meetings', 'latepoint' ), 'icon' => '', 'link' => OsRouterHelper::build_link(['integrations', 'external_meeting_systems'])), |
| 86 | array('id' => 'meetings', 'label' => __( 'Marketing', 'latepoint' ), 'icon' => '', 'link' => OsRouterHelper::build_link(['integrations', 'external_marketing_systems'])), |
| 87 | ) |
| 88 | ), |
| 89 | array( 'id' => 'form_fields', 'label' => __( 'Form Fields', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-browser', 'link' => OsRouterHelper::build_link(['form_fields', 'default_form_fields'])), |
| 90 | ); |
| 91 | break; |
| 92 | case LATEPOINT_USER_TYPE_AGENT: |
| 93 | // --------------- |
| 94 | // AGENT MENU |
| 95 | // --------------- |
| 96 | $menus = array( |
| 97 | array( 'id' => 'dashboard', 'label' => __( 'Dashboard', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-dashboard', 'link' => OsRouterHelper::build_link(['dashboard', 'index'])), |
| 98 | array( 'id' => 'calendar', 'label' => __( 'Calendar', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-calendar2', 'link' => OsRouterHelper::build_link(['calendars', 'view'])), |
| 99 | array( 'id' => 'appointments', 'label' => __( 'Appointments', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-box1', 'link' => OsRouterHelper::build_link(['bookings', 'index'])), |
| 100 | array( 'id' => 'orders', 'label' => __( 'Orders', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-book2', 'link' => OsRouterHelper::build_link(['orders', 'index'])), |
| 101 | array( 'id' => 'payments', 'label' => __( 'Payments', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-cart', 'link' => OsRouterHelper::build_link(['transactions', 'index'])), |
| 102 | array( 'id' => 'customers', 'label' => __( 'Customers', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-user1', 'link' => OsRouterHelper::build_link(['customers', 'index'])), |
| 103 | array( 'id' => 'services', 'label' => __( 'Services', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-folder', 'link' => OsRouterHelper::build_link(['services', 'index']), |
| 104 | 'children' => array( |
| 105 | array('id' => 'index','label' => __( 'Services', 'latepoint' ), 'icon' => '', 'link' => OsRouterHelper::build_link(['services', 'index'])), |
| 106 | array('id' => 'bundles','label' => __( 'Bundles', 'latepoint' ), 'icon' => '', 'link' => OsRouterHelper::build_link(['pro', 'bundles'])), |
| 107 | array('id' => 'categories','label' => __( 'Categories', 'latepoint' ), 'icon' => '', 'link' => OsRouterHelper::build_link(['pro', 'categories'])), |
| 108 | array('id' => 'service_extras','label' => __( 'Service Extras', 'latepoint' ), 'icon' => '', 'link' => OsRouterHelper::build_link(['pro', 'service_extras'])), |
| 109 | ) |
| 110 | ), |
| 111 | array( 'id' => 'locations', 'label' => __( 'Locations', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-map-marker', 'link' => OsRouterHelper::build_link(['pro', 'locations'])), |
| 112 | array( 'id' => 'settings', 'label' => __( 'Settings', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-cog1', 'link' => OsRouterHelper::build_link(['agents', 'edit_form'], array('id' => OsAuthHelper::get_logged_in_agent_id()) )) |
| 113 | ); |
| 114 | break; |
| 115 | } |
| 116 | /** |
| 117 | * Filters side menu items |
| 118 | * |
| 119 | * @since 4.7.0 |
| 120 | * @hook latepoint_side_menu |
| 121 | * |
| 122 | * @param {array} $menus Array of side menu items in a format ['id' => '', 'label' => '', 'icon' => '', 'link' => '', 'children' => [ ['label' => '', 'icon' => '', 'link' => ''] ] |
| 123 | * @returns {array} Filtered array of side menu items |
| 124 | */ |
| 125 | $menus = apply_filters('latepoint_side_menu', $menus, $user_role); |
| 126 | self::$side_menu_items = self::filter_by_user_capabilities($menus); |
| 127 | return self::$side_menu_items; |
| 128 | } |
| 129 | |
| 130 | public static function filter_by_user_capabilities(array $menus): array{ |
| 131 | $total_menu_items = count($menus); |
| 132 | for($i = 0; $i < $total_menu_items; $i++){ |
| 133 | if(!empty($menus[$i]['children'])){ |
| 134 | $menus[$i]['children'] = self::filter_by_user_capabilities($menus[$i]['children']); |
| 135 | } |
| 136 | if(!empty($menus[$i]['link'])){ |
| 137 | parse_str(wp_parse_url($menus[$i]['link'])['query'] ?? '',$params); |
| 138 | if(empty($params['route_name'])) continue; // not a controller__action route, could be custom URL |
| 139 | |
| 140 | $split_route_name = explode('__', $params['route_name']); |
| 141 | if(empty($split_route_name) || count($split_route_name) != 2) continue; // not a controller__action route, could be custom URL |
| 142 | |
| 143 | $controller_name = $split_route_name[0]; |
| 144 | $action = $split_route_name[1]; |
| 145 | |
| 146 | if(empty($controller_name) || empty($action)) continue; // not a controller__action route, could be custom URL |
| 147 | $controller_name = str_replace('_', '', ucwords($controller_name, '_')); |
| 148 | $controller_class_name = 'Os'.$controller_name.'Controller'; |
| 149 | $capabilities = OsRolesHelper::get_capabilities_required_for_controller_action($controller_class_name, $action); |
| 150 | if(!OsAuthHelper::get_current_user()->has_capability($capabilities)) unset($menus[$i]); |
| 151 | } |
| 152 | } |
| 153 | // clean out label items that have no actual items left after them |
| 154 | $menus = array_values($menus); |
| 155 | $total_menu_items = count($menus); |
| 156 | $clean_menu_items = []; |
| 157 | for($i = 0; $i < $total_menu_items; $i++){ |
| 158 | if(!empty($menus[$i]['small_label']) && (!empty($menus[$i + 1]['small_label']) || $i + 1 == $total_menu_items)){ |
| 159 | continue; |
| 160 | } |
| 161 | $clean_menu_items[] = $menus[$i]; |
| 162 | } |
| 163 | return $clean_menu_items; |
| 164 | } |
| 165 | |
| 166 | } |