Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
workgrouprequestssender.php
1<?php
2
11
17
19{
20
21 public function __construct()
22 {
23
24 }
25
29 public function send(array $pushList): void
30 {
31 if (
33 || !Loader::includeModule('pull')
34 )
35 {
36 return;
37 }
38
39 $this->sendPersonalPush($pushList);
40 }
41
45 protected function sendPersonalPush(array $pushList = []): void
46 {
47 $workgroupIdList = [];
48
49 foreach ($pushList as $push)
50 {
51 if (!in_array($push['EVENT'], [
52 Counter\Event\EventDictionary::EVENT_WORKGROUP_USER_ADD,
53 Counter\Event\EventDictionary::EVENT_WORKGROUP_USER_UPDATE,
54 Counter\Event\EventDictionary::EVENT_WORKGROUP_USER_DELETE,
55 ], true)
56 )
57 {
58 continue;
59 }
60
61 $workgroupIdList[] = $push['GROUP_ID'];
62 }
63
64 $workgroupIdList = array_unique($workgroupIdList);
65 if (empty($workgroupIdList))
66 {
67 return;
68 }
69
70 $userIdList = $this->getRecipients($workgroupIdList);
71
72 foreach ($workgroupIdList as $workgroupId)
73 {
74 if (empty($userIdList[$workgroupId]))
75 {
76 continue;
77 }
78
79 (new PushSender())->sendUserCounters($userIdList[$workgroupId], [
80 'workgroupId' => $workgroupId,
81 'values' => $this->getWorkgroupCounters($workgroupId),
82 ]);
83 }
84 }
85
86 protected function getWorkgroupCounters($workgroupId): array
87 {
88 return [];
89 }
90
95 protected function getRecipients(array $groupIdList = []): array
96 {
97 $result = [];
98
99 if (empty($groupIdList))
100 {
101 return $result;
102 }
103
104 $userIdList = [];
105
106 $res = WorkgroupTable::query()
107 ->setSelect([
108 'ID',
109 'INITIATE_PERMS'
110 ])
111 ->setFilter([
112 '@ID' => $groupIdList,
113 ])
114 ->exec();
115
116 while ($workgroupFields = $res->fetch())
117 {
118 $roleFilterValue = $this->getRoleFilterValue($workgroupFields['INITIATE_PERMS']);
119
120 $resRelation = UserToGroupTable::query()
121 ->setSelect([
122 'GROUP_ID',
123 'USER_ID',
124 ])
125 ->setFilter([
126 '@ROLE' => $roleFilterValue,
127 'GROUP_ID' => (int)$workgroupFields['ID'],
128 'USER.ACTIVE' => true,
129 ])
130 ->exec();
131
132 $userIdList[(int)$workgroupFields['ID']] = [];
133 while ($relationFields = $resRelation->fetch())
134 {
135 $userIdList[(int)$workgroupFields['ID']][] = (int)$relationFields['USER_ID'];
136 }
137 }
138
139 return $userIdList;
140 }
141
142 protected function getRoleFilterValue($initiatePermsValue): array
143 {
145 }
146}
static isModuleInstalled($moduleName)