PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / 1.7.2
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution v1.7.2
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.7.2, at app/Http/Controllers/AdminController.php

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