PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 1.0.93
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v1.0.93
2.10.0 2.10.01 2.9.1 2.9.0 2.8.1 2.8.0 2.7.7 2.7.5 2.7.0 2.6.01 2.6.0 2.5.0 2.4.01 trunk 1.0.90 1.0.91 1.0.92 1.0.93 1.0.94 1.0.95 1.0.96 1.0.97 1.0.98 1.0.99 1.1.0 All 77 releases
fluent-community / app / Http / Controllers / MembersController.php

MembersController.php in FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses 1.0.93, at app/Http/Controllers/MembersController.php

129 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCommunity\App\Http\Controllers;
4
5 use FluentCommunity\App\Models\BaseSpace;
6 use FluentCommunity\App\Models\User;
7 use FluentCommunity\App\Models\XProfile;
8 use FluentCommunity\App\Services\Helper;
9 use FluentCommunity\App\Services\ProfileHelper;
10 use FluentCommunity\Framework\Http\Request\Request;
11
12 class MembersController extends Controller
13 {
14 public function getMembers(Request $request)
15 {
16 $spaceSlug = $request->getSafe('space', 'sanitize_text_field');
17
18 $space = null;
19 if ($spaceSlug) {
20 $space = BaseSpace::where('slug', $spaceSlug)->first();
21 if (!$space || !Helper::isUserInSpace(get_current_user_id(), $space->id)) {
22 return $this->sendError([
23 'message' => __('Please join the space first to view the members', 'fluent-community'),
24 ]);
25 }
26 }
27
28 if (!$space) {
29 $spaceId = $request->getSafe('space_id', 'intval');
30 if ($spaceId) {
31 $space = BaseSpace::find($spaceId);
32 if (!$space || !Helper::isUserInSpace(get_current_user_id(), $space->id)) {
33 return $this->sendError([
34 'message' => 'Space not found',
35 ]);
36 }
37 }
38 }
39
40 $mention = $request->getSafe('mention', 'sanitize_text_field');
41 $members = XProfile::select(ProfileHelper::getXProfilePublicFields())
42 ->whereHas('user')
43 ->searchBy($request->getSafe('search', 'sanitize_text_field'));
44
45 if ($mention) {
46 $members = $members->where('user_id', '!=', get_current_user_id())
47 ->mentionBy($mention);
48 }
49
50 $shortBy = $request->getSafe('sort_by', 'sanitize_text_field', 'last_activity');
51
52 if ($shortBy == 'last_activity') {
53 $members = $members->orderBy('last_activity', 'DESC');
54 } else {
55 $members = $members->orderBy($shortBy, 'ASC');
56 }
57
58 $members = $members->orderBy('last_activity', 'DESC');
59
60 if ($space) {
61 $members = $members->whereHas('spaces', function ($query) use ($space) {
62 $query->where('space_id', $space->id);
63 });
64 }
65
66 $currentUser = $this->getUser();
67
68 if ($mention || !$currentUser || !$currentUser->isCommunityAdmin()) {
69 $members = $members->where('status', 'active');
70 } else {
71 $statuses = $request->getSafe('status', 'sanitize_text_field', 'active');
72 if ($statuses == 'in_active') {
73 $statuses = ['pending', 'blocked'];
74 } else {
75 $statuses = ['active'];
76 }
77
78 $members = $members->whereIn('status', $statuses);
79 }
80
81 do_action_ref_array('fluent_community/members_query_ref', [&$members, $request->all()]);
82
83 $members = $members->paginate();
84
85 if ($mention) {
86 return [
87 'members' => [
88 'data' => $members->items()
89 ]
90 ];
91 }
92
93 return [
94 'members' => $members
95 ];
96 }
97
98 public function patchMember(Request $request, $userId)
99 {
100 $currentUser = $this->getUser(true);
101 $currentUser->verifyCommunityPermission('delete_any_feed');
102
103 $newStatus = $request->getSafe('status', 'sanitize_text_field');
104
105 $wpUser = User::findOrFail($userId);
106
107 if ($wpUser->isCommunityAdmin() && $newStatus != 'active') {
108 return $this->sendError([
109 'message' => 'Sorry, you can not change status of another admin. Remove the user from moderators'
110 ]);
111 }
112
113 $xProfile = XProfile::findOrFail($userId);
114
115 $newStatus = $request->getSafe('status', 'sanitize_text_field');
116 $validStatuses = ['active', 'pending', 'blocked'];
117
118 if (in_array($newStatus, $validStatuses)) {
119 $xProfile->status = $newStatus;
120 $xProfile->save();
121 }
122
123 return [
124 'message' => __('Member status has been updated', 'fluent-community'),
125 'member' => $xProfile
126 ];
127 }
128 }
129