Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
MembersManager.php
1<?php
2
4
7use Bitrix\Socialnetwork\EO_MemberToGroup_Collection;
8
9final class MembersManager
10{
15 public function updateInvitedUsers(int $spaceId, array $usersIds): void
16 {
17 $groupInviteCollection = $this->getGroupMembersCollection($spaceId);
18 $invitedUsers = [];
19 foreach ($groupInviteCollection as $member)
20 {
21 if ($member->isInvited())
22 {
23 $invitedUsers[] = $member->getUserId();
24 }
25 }
26
27 $inviteUsers = array_diff($usersIds, $invitedUsers);
28 $rejectInviteUsers = array_diff($invitedUsers, $usersIds);
29
30 $userId = Helper\User::getCurrentUserId();
31 $isAdmin = Helper\Workgroup::isCurrentUserModuleAdmin();
32
33 foreach ($inviteUsers as $inviteUserId)
34 {
35 $canInviteUser = \CSocNetUserPerms::CanPerformOperation($userId, $inviteUserId, 'invitegroup', $isAdmin);
36
37 if ($canInviteUser)
38 {
39 \CSocNetUserToGroup::SendRequestToJoinGroup(
40 $userId,
41 $inviteUserId,
42 $spaceId,
43 '',
44 );
45 }
46 }
47
48 foreach ($rejectInviteUsers as $rejectInviteUserId)
49 {
50 $userToGroup = [
51 'userId' => $rejectInviteUserId,
52 'groupId' => $spaceId,
53 ];
54
55 if (Helper\Workgroup\Access::canDeleteOutgoingRequest($userToGroup))
56 {
57 Helper\Workgroup::deleteOutgoingRequest($userToGroup);
58 }
59 }
60 }
61
62 public function getGroupMembersList(int $spaceId): array
63 {
64 $groupMembersList = [];
65
66 $groupInviteCollection = $this->getGroupMembersCollection($spaceId);
67 foreach ($groupInviteCollection as $member)
68 {
69 $groupMembersList[] = [
70 'id' => $member->getUserId(),
71 'invited' => $member->isInvited(),
72 'isAwaiting' => $member->isAwaiting(),
73 'isMember' => $member->isMember(),
74 ];
75 }
76
77 return $groupMembersList;
78 }
79
80 public function getGroupMembersCollection(int $spaceId): EO_MemberToGroup_Collection
81 {
82 return MemberToGroupTable::query()
83 ->setSelect(['USER_ID', 'ROLE', 'INITIATED_BY_TYPE'])
84 ->where('GROUP_ID', $spaceId)
85 ->exec()->fetchCollection();
86 }
87
88 public function canInviteUsers(int $spaceId): bool
89 {
90 $groupPermissions = Helper\Workgroup::getPermissions([
91 'groupId' => $spaceId,
92 ]);
93
94 return $groupPermissions['UserCanInitiate']
95 || $groupPermissions['UserCanModifyGroup']
96 || Helper\Workgroup::isCurrentUserModuleAdmin();
97 }
98}
updateInvitedUsers(int $spaceId, array $usersIds)