1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
AddMemberTrait.php
См. документацию.
1<?php
2
4
11use CSocNetUserToGroup;
12
13trait AddMemberTrait
14{
15 private function addMembers(
16 int $groupId,
17 int $initiatorId,
18 string $role,
19 ?string $initiatedByType,
20 int ...$members,
22 {
23 $handlerResult = new HandlerResult();
24
25 if (empty($members))
26 {
27 return $handlerResult;
28 }
29
30 $handlerResult->setGroupChanged();
31
32 foreach ($members as $userId)
33 {
34 $user = [
35 'USER_ID' => $userId,
36 'GROUP_ID' => $groupId,
37 'ROLE' => $role,
38 'DATE_CREATE' => new DateTime(),
39 'DATE_UPDATE' => new DateTime(),
40 'INITIATED_BY_TYPE' => $initiatedByType ?? UserToGroupTable::INITIATED_BY_GROUP,
41 'INITIATED_BY_USER_ID' => $initiatorId,
42 ];
43
44 $result = CSocNetUserToGroup::Add($user, true, true, true);
45 if ($result === false)
46 {
47 $handlerResult->addApplicationError();
48 }
49 }
50
51 return $handlerResult;
52 }
53
54 private function deleteMembers(int $groupId, int...$members): HandlerResult
55 {
56 $handlerResult = new HandlerResult();
57
58 if (empty($members))
59 {
60 return $handlerResult;
61 }
62
63 $relations = UserToGroupTable::query()
64 ->setSelect(['ID'])
65 ->where('GROUP_ID', $groupId)
66 ->whereIn('USER_ID', $members)
67 ->exec()
68 ->fetchAll();
69
70 $relations = array_column($relations, 'ID');
71
72 foreach ($relations as $relationId)
73 {
74 $result = CSocNetUserToGroup::Delete($relationId, false, true, true, true);
75 if ($result === false)
76 {
77 $handlerResult->addApplicationError();
78 }
79 }
80
81 return $handlerResult;
82 }
83
84 private function inviteMembers(int $groupId, int $initiatorId, int ...$members): HandlerResult
85 {
86 $handlerResult = new HandlerResult();
87
88 if (empty($members))
89 {
90 return $handlerResult;
91 }
92
93 $invitationService = ServiceLocator::getInstance()->get('socialnetwork.collab.invitation.service');
94
95 $handlerResult->setGroupChanged();
96
97 foreach ($members as $userId)
98 {
99 $user = [
100 'USER_ID' => $userId,
101 'GROUP_ID' => $groupId,
102 'ROLE' => UserRole::REQUEST,
103 'DATE_CREATE' => new DateTime(),
104 'DATE_UPDATE' => new DateTime(),
105 'INITIATED_BY_TYPE' => UserToGroupTable::INITIATED_BY_GROUP,
106 'INITIATED_BY_USER_ID' => $initiatorId,
107 ];
108
109 $result = CSocNetUserToGroup::Add($user, true, true, true);
110 if ($result === false)
111 {
112 $handlerResult->addApplicationError();
113 }
114
115 $command = (new InvitationCommand())
116 ->setInitiatorId($initiatorId)
117 ->setRecipientId($userId)
118 ->setCollabId($groupId)
119 ->setRelationId($result)
120 ;
121
122 $invitationResult = $invitationService->send($command);
123
124 $handlerResult->merge($invitationResult);
125 }
126
127 return $handlerResult;
128 }
129}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static Add($arFields, bool $skipCheckFields=false, bool $skipStatistics=false, bool $delayEvents=false)
Определения user_group.php:15
$result
Определения get_property_values.php:14
$user
Определения mysql_to_pgsql.php:33