PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 1.0.95
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v1.0.95
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.95, at app/Http/Controllers/MembersController.php

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