PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / 1.10.01
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution v1.10.01
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 1.7.2 All 33 releases
fluent-booking / app / Http / Controllers / AdminController.php

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

141 lines 4.3 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 $queryArgs = [
29 'role__not_in' => ['subscriber'],
30 'number' => 50,
31 'fields' => ['ID', 'user_email', 'display_name'],
32 'search' => '*' . $search_term . '*'
33 ];
34
35 $metaQueryArgs = [
36 'role__not_in' => ['subscriber'],
37 'number' => 50,
38 'fields' => ['ID', 'user_email', 'display_name'],
39 /* phpcs:disable WordPress.DB.SlowDBQuery.slow_db_query_meta_query */
40 'meta_query' => [
41 'relation' => 'OR',
42 [
43 'key' => 'first_name',
44 'value' => $search_term,
45 'compare' => 'LIKE'
46 ],
47 [
48 'key' => 'last_name',
49 'value' => $search_term,
50 'compare' => 'LIKE'
51 ]
52 ],
53 ];
54
55 $metaQueryArgs = apply_filters('fluent_booking/user_search_meta_query_arguments', $metaQueryArgs, $search_term);
56
57 $queryResult = get_users($queryArgs);
58 $metaQueryResult = get_users($metaQueryArgs);
59
60 $users = array_unique(array_merge($queryResult, $metaQueryResult), SORT_REGULAR);
61
62 $hosts = [];
63 $pushedIds = [];
64 $calendarUserIds = Calendar::where('type', 'simple')->pluck('user_id')->toArray();
65 foreach ($users as $user) {
66 $pushedIds[] = $user->ID;
67 $hosts[] = [
68 'id' => $user->ID,
69 'label' => $user->display_name . ' (' . $user->user_email . ')',
70 'avatar' => Helper::fluentBookingUserAvatar($user->user_email, $user),
71 'disabled' => in_array($user->ID, $calendarUserIds)
72 ];
73 }
74
75 if ($selectedId = $request->get('selected_id')) {
76 if (!in_array($selectedId, $pushedIds)) {
77 $user = get_user_by('ID', $selectedId);
78 if ($user) {
79 $hosts[] = [
80 'id' => $user->ID,
81 'label' => $user->display_name . ' (' . $user->user_email . ')',
82 'avatar' => Helper::fluentBookingUserAvatar($user->user_email, $user),
83 'disabled' => in_array($user->ID, $calendarUserIds)
84 ];
85 }
86 }
87 }
88
89 return [
90 'hosts' => $hosts
91 ];
92 }
93
94 public function getOtherHosts(Request $request)
95 {
96 if (!current_user_can('list_users')) {
97 return [
98 'hosts' => []
99 ];
100 }
101
102 $currentUserId = get_current_user_id();
103
104 $calendars = Calendar::with(['user'])
105 ->where('user_id', '!=', $currentUserId)
106 ->where('type', 'simple')
107 ->get();
108
109 $allHosts = [];
110
111 foreach ($calendars as $calendar) {
112 $userName = __('Deleted User', 'fluent-booking');
113 if ($calendar->user) {
114 $userName = $calendar->user->full_name;
115 }
116
117 if ($currentUserId == $calendar->user_id) {
118 $userName = __('My Meetings', 'fluent-booking');
119 }
120
121 $allHosts[] = [
122 'id' => (string)$calendar->user_id,
123 'label' => $userName
124 ];
125 }
126
127 return [
128 'hosts' => $allHosts
129 ];
130 }
131
132 public function getAllHosts(Request $request)
133 {
134 $allHosts = Calendar::getAllHosts();
135
136 return [
137 'hosts' => $allHosts
138 ];
139 }
140 }
141