Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
workgroupsender.php
1<?php
2
11
18
20{
21 private ?array $subscribedUsers = null;
22
23 public function __construct()
24 {
25
26 }
27
31 public function send(array $pushList, array $notVisibleGroupsUsers): void
32 {
33 if (
35 || !Loader::includeModule('pull')
36 )
37 {
38 return;
39 }
40
41 $subscribedUsers = $this->getSubscribedUsers();
42
43 foreach ($pushList as $push)
44 {
45 $pushCommand = PushEventDictionary::getPushEventType($push['EVENT']);
46 $groupId = (int)$push['GROUP_ID'];
47 $userId = (int)($push['USER_ID'] ?? null);
48
49 if (empty($pushCommand))
50 {
51 continue;
52 }
53
54 $pushParams = [
55 'module_id' => 'socialnetwork',
56 'command' => $pushCommand,
57 'params' => [ 'GROUP_ID' => $groupId, 'USER_ID' => $userId ],
58 ];
59
60 $recipients = (
61 isset($notVisibleGroupsUsers[$groupId])
62 ? array_intersect($subscribedUsers, $notVisibleGroupsUsers[$groupId])
63 : $subscribedUsers
64 );
65
66 PushSender::sendPersonalEvent($recipients, $pushCommand, $pushParams);
67 }
68 }
69
70 public function sendForUserAddedAndRemoved(Event $event, array $notVisibleGroupsUsers): void
71 {
72 $eventData = $event->getData();
73 $groupId = $event->getGroupId();
74 $userId = $event->getUserId();
75
76 $pushParams = [
77 'module_id' => 'socialnetwork',
78 'command' => $event->getType(),
79 'params' => [ 'GROUP_ID' => $groupId, 'USER_ID' => $userId, ],
80 ];
81
82 if (($eventData['ROLE'] ?? null) === UserToGroupTable::ROLE_REQUEST)
83 {
84 PushService::addEvent([ $eventData['USER_ID'] ], $pushParams);
85 }
86 else
87 {
88 $subscribedUsers = $this->getSubscribedUsers();
89
90 if (!array_key_exists('USER_ID', $eventData))
91 {
92 $eventData['USER_ID'] = [];
93 }
94
95 if (!is_array($eventData['USER_ID']))
96 {
97 $eventData['USER_ID'] = [ $eventData['USER_ID'] ];
98 }
99
100 $recipients = (
101 isset($notVisibleGroupsUsers[$groupId])
102 ? array_intersect($subscribedUsers, array_merge($eventData['USER_ID'], $notVisibleGroupsUsers[$groupId]))
103 : $subscribedUsers
104 );
105
106 PushService::addEvent($recipients, $pushParams);
107 }
108 }
109
110 private function getSubscribedUsers(): array
111 {
112 if ($this->subscribedUsers === null)
113 {
114 $query = \Bitrix\Pull\Model\WatchTable::query();
115 $query->addSelect('USER_ID');
116 $query->where('TAG', PullDictionary::PULL_WORKGROUPS_TAG);
117 $this->subscribedUsers = array_column($query->fetchAll(), 'USER_ID');
118 }
119
120 return $this->subscribedUsers;
121 }
122}
static isModuleInstalled($moduleName)
static sendPersonalEvent(array $userIds, string $command='', array $eventData=[])
send(array $pushList, array $notVisibleGroupsUsers)
sendForUserAddedAndRemoved(Event $event, array $notVisibleGroupsUsers)