PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / 2.5.0
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution v2.5.0
2.5.0 2.4.0 2.3.0 2.2.5 2.2.0 2.1.2 2.1.1 trunk 1.10.0 1.10.01 1.10.02 1.5.0 1.5.01 1.5.02 1.5.1 1.5.10 1.5.20 1.5.21 1.5.22 1.5.23 1.5.24 1.5.25 1.6.0 1.7.0 1.7.1 All 34 releases
fluent-booking / app / Http / Controllers / AdminController.php

AdminController.php in Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution 2.5.0, at app/Http/Controllers/AdminController.php

147 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentBooking\App\Http\Controllers;
4
5 use FluentBooking\App\Models\Calendar;
6 use FluentBooking\Framework\Http\Request\Request;
7 use FluentBooking\App\Services\Helper;
8
9 class AdminController extends Controller
10 {
11 public function getRemainingHosts(Request $request)
12 {
13 if (!current_user_can('list_users')) {
14 $user = get_user_by('ID', get_current_user_id());
15 return [
16 'hosts' => [
17 [
18 'is_own' => true,
19 'id' => $user->ID,
20 'label' => $user->display_name . ' (' . $user->user_email . ')'
21 ]
22 ]
23 ];
24 }
25
26 $search_term = sanitize_text_field($request->get('search'));
27
28 // The total is never used, and counting it forces a full scan of every matching user
29 $baseArgs = [
30 'role__not_in' => ['subscriber'],
31 'number' => 50,
32 'fields' => ['ID', 'user_email', 'display_name'],
33 'count_total' => false
34 ];
35
36 if ($search_term === '') {
37 $users = get_users(apply_filters('fluent_booking/user_search_meta_query_arguments', $baseArgs, $search_term));
38 } else {
39 $queryArgs = array_merge($baseArgs, [
40 'search' => '*' . $search_term . '*'
41 ]);
42
43 $metaQueryArgs = array_merge($baseArgs, [
44 /* phpcs:disable WordPress.DB.SlowDBQuery.slow_db_query_meta_query */
45 'meta_query' => [
46 'relation' => 'OR',
47 [
48 'key' => 'first_name',
49 'value' => $search_term,
50 'compare' => 'LIKE'
51 ],
52 [
53 'key' => 'last_name',
54 'value' => $search_term,
55 'compare' => 'LIKE'
56 ]
57 ],
58 ]);
59
60 $metaQueryArgs = apply_filters('fluent_booking/user_search_meta_query_arguments', $metaQueryArgs, $search_term);
61
62 $queryResult = get_users($queryArgs);
63 $metaQueryResult = get_users($metaQueryArgs);
64
65 $users = array_unique(array_merge($queryResult, $metaQueryResult), SORT_REGULAR);
66 }
67
68 $hosts = [];
69 $pushedIds = [];
70 $calendarUserIds = Calendar::where('type', 'simple')->pluck('user_id')->toArray();
71 foreach ($users as $user) {
72 $pushedIds[] = $user->ID;
73 $hosts[] = [
74 'id' => $user->ID,
75 'label' => $user->display_name . ' (' . $user->user_email . ')',
76 'avatar' => Helper::fluentBookingUserAvatar($user->user_email, $user),
77 'disabled' => in_array($user->ID, $calendarUserIds)
78 ];
79 }
80
81 if ($selectedId = $request->get('selected_id')) {
82 if (!in_array($selectedId, $pushedIds)) {
83 $user = get_user_by('ID', $selectedId);
84 if ($user) {
85 $hosts[] = [
86 'id' => $user->ID,
87 'label' => $user->display_name . ' (' . $user->user_email . ')',
88 'avatar' => Helper::fluentBookingUserAvatar($user->user_email, $user),
89 'disabled' => in_array($user->ID, $calendarUserIds)
90 ];
91 }
92 }
93 }
94
95 return [
96 'hosts' => $hosts
97 ];
98 }
99
100 public function getOtherHosts(Request $request)
101 {
102 if (!current_user_can('list_users')) {
103 return [
104 'hosts' => []
105 ];
106 }
107
108 $currentUserId = get_current_user_id();
109
110 $calendars = Calendar::with(['user'])
111 ->where('user_id', '!=', $currentUserId)
112 ->where('type', 'simple')
113 ->get();
114
115 $allHosts = [];
116
117 foreach ($calendars as $calendar) {
118 $userName = __('Deleted User', 'fluent-booking');
119 if ($calendar->user) {
120 $userName = $calendar->user->full_name;
121 }
122
123 if ($currentUserId == $calendar->user_id) {
124 $userName = __('My Meetings', 'fluent-booking');
125 }
126
127 $allHosts[] = [
128 'id' => (string)$calendar->user_id,
129 'label' => $userName
130 ];
131 }
132
133 return [
134 'hosts' => $allHosts
135 ];
136 }
137
138 public function getAllHosts(Request $request)
139 {
140 $allHosts = Calendar::getAllHosts();
141
142 return [
143 'hosts' => $allHosts
144 ];
145 }
146 }
147