Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
workgroupusersender.php
1<?php
2
11
15
17{
18
19 public function __construct()
20 {
21
22 }
23
27 public function send(array $pushList, array $notVisibleGroupsUsers): void
28 {
29 if (
31 || !Loader::includeModule('pull')
32 )
33 {
34 return;
35 }
36
37 $tagList = [];
38 foreach ($pushList as $push)
39 {
40 $tagList[] = PullDictionary::PULL_WORKGROUP_USERS_TAG_PREFIX . '_' . (int)$push['GROUP_ID'];
41 }
42
43 $tagList = array_unique($tagList);
44
45 $query = \Bitrix\Pull\Model\WatchTable::query();
46 $query->addSelect('USER_ID');
47 $query->addSelect('TAG');
48 $query->whereIn('TAG', $tagList);
49 $records = $query->fetchAll();
50
51 $subscribedUsers = [];
52 foreach ($records as $record)
53 {
54 if (!preg_match('/^'. PullDictionary::PULL_WORKGROUP_USERS_TAG_PREFIX . '(\d+)$/i', $record['TAG'], $matches))
55 {
56 continue;
57 }
58
59 $groupId = (int)$matches[1];
60
61 if (!isset($subscribedUsers[$groupId]))
62 {
63 $subscribedUsers[$groupId] = [];
64 }
65
66 $subscribedUsers[$groupId][] = (int)$record['USER_ID'];
67 }
68
69 foreach ($pushList as $push)
70 {
71 $pushCommand = PushEventDictionary::getPushEventType($push['EVENT']);
72 $groupId = (int)$push['GROUP_ID'];
73 $userId = (int)$push['USER_ID'];
74 $role = (int)$push['ROLE'];
75
76 $pushParams = [
77 'module_id' => 'socialnetwork',
78 'command' => $pushCommand,
79 'params' => [ 'GROUP_ID' => $groupId ],
80 ];
81
83 {
84 $recipients = [ $userId ];
85 }
86 elseif (!empty($subscribedUsers[$groupId]))
87 {
88 $recipients = (
89 isset($notVisibleGroupsUsers[$groupId])
90 ? array_intersect($subscribedUsers[$groupId], $notVisibleGroupsUsers[$groupId])
91 : $subscribedUsers[$groupId]
92 );
93 }
94
95 PushSender::sendPersonalEvent($recipients, $pushCommand, $pushParams);
96 }
97 }
98}
static isModuleInstalled($moduleName)
static sendPersonalEvent(array $userIds, string $command='', array $eventData=[])