1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
calendarpreprocessor.php
См. документацию.
1<?php
2
3namespace Bitrix\Socialnetwork\Integration\Calendar\RecentActivity;
4
5use Bitrix\Main\Loader;
6use Bitrix\Main\Type\Collection;
7use Bitrix\Socialnetwork\Internals\EventService\EventDictionary;
8use Bitrix\Socialnetwork\Internals\EventService\Push\PushEventDictionary;
9use Bitrix\Socialnetwork\Space\List\RecentActivity\Dictionary;
10use Bitrix\Socialnetwork\Space\List\RecentActivity\Event\PreProcessor\AbstractPreProcessor;
11use Bitrix\Socialnetwork\Space\List\RecentActivity\Event\Trait\AttendeeCodeTrait;
12
14{
15 use AttendeeCodeTrait;
16
17 public function isAvailable(): bool
18 {
19 return Loader::includeModule('calendar');
20 }
21
22 protected function getTypeId(): string
23 {
24 return Dictionary::ENTITY_TYPE['calendar'];
25 }
26
27 public function process(): void
28 {
29 switch ($this->event->getType())
30 {
31 case EventDictionary::EVENT_SPACE_CALENDAR_EVENT_UPD:
32 $this->onEventUpdate();
33 break;
34 default:
35 break;
36 }
37 }
38
39 private function onEventUpdate(): void
40 {
41 $data = $this->event->getData();
42 $eventId = (int)($data['ID'] ?? null);
43
44 if ($eventId <= 0)
45 {
46 return;
47 }
48
49 $attendeesCodesBeforeUpdate = $this->getArrayValueFromEventData('ATTENDEES_CODES_BEFORE_UPDATE');
50 $attendeesCodesAfterUpdate = $this->getArrayValueFromEventData('ATTENDEES_CODES_AFTER_UPDATE');
51 $attendeesBeforeUpdate = $this->getArrayValueFromEventData('ATTENDEES_BEFORE_UPDATE');
52 $attendeesAfterUpdate = $this->getArrayValueFromEventData('ATTENDEES_AFTER_UPDATE');
53
54 if (
55 !is_array($attendeesCodesBeforeUpdate)
56 || !is_array($attendeesCodesAfterUpdate)
57 || !is_array($attendeesBeforeUpdate)
58 || !is_array($attendeesAfterUpdate)
59 )
60 {
61 return;
62 }
63
64 Collection::normalizeArrayValuesByInt($attendeesBeforeUpdate);
65 Collection::normalizeArrayValuesByInt($attendeesAfterUpdate);
66
67 $this->processRemovedFromAttendeesSpaces(
68 $eventId,
69 $attendeesCodesBeforeUpdate,
70 $attendeesCodesAfterUpdate,
71 $attendeesBeforeUpdate,
72 );
73
74 $this->processRemovedFromAttendeesUsers($eventId, $attendeesBeforeUpdate, $attendeesAfterUpdate);
75 }
76
77 private function processRemovedFromAttendeesSpaces(
78 int $eventId,
79 array $attendeesCodesBeforeUpdate,
80 array $attendeesCodesAfterUpdate,
81 array $attendeesBeforeUpdate,
82 ): void
83 {
84 if ($eventId <= 0)
85 {
86 return;
87 }
88
89 sort($attendeesCodesBeforeUpdate);
90 sort($attendeesCodesAfterUpdate);
91
92 if ($attendeesCodesBeforeUpdate === $attendeesCodesAfterUpdate)
93 {
94 return;
95 }
96
97 $removedAttendeesCodes = array_diff($attendeesCodesBeforeUpdate, $attendeesCodesAfterUpdate);
98
99 $spaceIdsToReload = [];
100 foreach ($removedAttendeesCodes as $attendeeCode)
101 {
102 $spaceId = $this->getGroupIdFromAttendeeCode($attendeeCode);
103 if ($spaceId > 0)
104 {
105 $this->service->deleteBySpaceId($spaceId, $this->getTypeId(), $eventId);
106 $spaceIdsToReload[] = $spaceId;
107 }
108 }
109
110 $this->pushEvent(
111 $attendeesBeforeUpdate,
112 PushEventDictionary::EVENT_SPACE_RECENT_ACTIVITY_REMOVE_FROM_SPACE,
113 ['spaceIdsToReload' => $spaceIdsToReload],
114 );
115 }
116
117 private function processRemovedFromAttendeesUsers(int $eventId, array $attendeesBeforeUpdate, array $attendeesAfterUpdate): void
118 {
119 if ($attendeesBeforeUpdate === $attendeesAfterUpdate)
120 {
121 return;
122 }
123
124 $lostAccessUsers = array_values(array_diff($attendeesBeforeUpdate, $attendeesAfterUpdate));
125
126 if (empty($lostAccessUsers))
127 {
128 return;
129 }
130
131 \Bitrix\Socialnetwork\Internals\EventService\Service::addEvent(
132 EventDictionary::EVENT_SPACE_CALENDAR_EVENT_REMOVE_USERS,
133 [
134 'ID' => $eventId,
135 'RECEPIENTS' => $lostAccessUsers,
136 ]
137 );
138 }
139
140 private function getArrayValueFromEventData(string $code): ?array
141 {
142 $data = $this->event->getData();
143
144 return is_array($data[$code]) ? $data[$code] : null;
145 }
146}
pushEvent(array $recipients, string $eventType, array $params)
Определения AbstractPreProcessor.php:22
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195