34 foreach ($data as $key => $row)
36 if (!in_array($key, $validFields,
true))
50 $workgroupsPushList = [];
52 $workgroupUserEventsList = [
62 foreach ($events as $event)
65 $eventType = $event->getType();
66 $relationKey = $event->getRelationKey();
68 if (in_array($eventType, $workgroupUserEventsList,
true))
72 $added[] = $relationKey;
76 $changed[] = $relationKey;
80 $deleted[] = $relationKey;
85 $added = array_diff($added, $deleted);
86 $changed = array_diff($changed, $added, $deleted);
87 $changed = $this->clearNotRealChanges($changed);
91 foreach ($events as $event)
94 $eventType = $event->getType();
95 $groupId = $event->getGroupId();
96 $userId = $event->getGroupId();
97 $relationKey = $event->getRelationKey();
99 $role = ($newFields[$relationKey] ??
null);
104 && !in_array($relationKey, $added,
true)
108 && !in_array($relationKey, $changed,
true)
115 $workgroupUserPushList[] = [
116 'EVENT' => $eventType,
117 'GROUP_ID' => $groupId,
118 'USER_ID' => $userId,
123 if (!empty($workgroupUserPushList))
125 $notVisibleGroupsUsers = $this->getNotVisibleGroupsUsers([
137 $relationKey = $this->getRelationKey();
142 && !isset($oldFields[$relationKey])
145 $oldFields[$relationKey] = UserToGroupTable::getList([
147 'USER_ID' => $this->getUserId(),
148 'GROUP_ID' => $this->getGroupId(),
152 'GROUP_VISIBLE' =>
'GROUP.VISIBLE',
163 foreach ($events as $event)
165 $relationKey = $event->getRelationKey();
169 && !isset($newFields[$relationKey])
172 $newFields[$relationKey] = UserToGroupTable::getList([
174 'USER_ID' => $event->getUserId(),
175 'GROUP_ID' => $event->getGroupId(),
179 'GROUP_VISIBLE' =>
'GROUP.VISIBLE',
188 private function getNotVisibleGroupsUsers(array $relationKeyList): array
192 if (empty($groupIds = $this->getNotVisibleGroupIds($relationKeyList)))
197 $relations = UserToGroupTable::getList([
198 'select' => [
'GROUP_ID',
'USER_ID' ],
200 '@GROUP_ID' => $groupIds,
203 ])->fetchCollection();
205 foreach ($relations as $relation)
207 $groupId = $relation->getGroupId();
208 $userId = $relation->getUserId();
210 if (!isset($userList[$groupId]))
212 $userList[$groupId] = [];
215 $userList[$groupId][] = $userId;
221 private function getNotVisibleGroupIds($relationKeyList): array
223 [ $added, $changed, $deleted ] = $relationKeyList;
228 $filter =
static function($relationKey) use ($newFields) {
229 return ($newFields[$relationKey][
'GROUP_VISIBLE'] ===
'N');
231 $changedFilter =
static function($relationKey) use ($oldFields, $newFields) {
233 $newFields[$relationKey][
'GROUP_VISIBLE'] ===
'N'
234 && $oldFields[$relationKey][
'GROUP_VISIBLE'] ===
'N'
237 $deletedFilter =
static function($relationKey) use ($oldFields) {
238 return ($oldFields[$relationKey][
'GROUP_VISIBLE'] ===
'N');
241 $relationKeyList = array_merge(
243 array_filter($changed, $changedFilter),
244 array_filter($deleted, $deletedFilter),
247 return array_map(
static function($relationKey) {
248 [ $groupId, ] = explode(
'_', $relationKey);
250 }, $relationKeyList);
253 private function clearNotRealChanges(array $changed): array
259 foreach ($changed as $key => $relationKey)
261 $changes = $this->getChanges($relationKey);
262 if (!array_intersect_key($changes, array_flip($realChanges)))
264 unset($changed[$key]);