Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
spaceservice.php
1<?php
2
4
9
11{
12 public const SUPPORTED_EVENTS = [
13 'invite',
14 'onAfterCalendarEventDelete',
15 'onCalendarEventCommentAdd',
16 ];
17
21 public static function isAvailable(): bool
22 {
23 if (
24 !class_exists(\Bitrix\Socialnetwork\Space\Service::class)
25 || !Loader::includeModule('socialnetwork')
26 )
27 {
28 return false;
29 }
30
31 return \Bitrix\Socialnetwork\Space\Service::isAvailable();
32 }
33
34 public function addEvent(string $type, array $data): void
35 {
36 if (!static::isAvailable())
37 {
38 return;
39 }
40
41 if (!in_array($type, self::SUPPORTED_EVENTS, true))
42 {
43 return;
44 }
45
46 // enrich payload
47 $data['RECEPIENTS'] = $this->getRecipientIds($data);
48 Service::addEvent($this->mapTaskToSpaceEvent($type), $data);
49 }
50
51 private function mapTaskToSpaceEvent(string $type): string
52 {
53 $map = [
55 'onAfterCalendarEventDelete' => EventDictionary::EVENT_SPACE_CALENDAR_EVENT_DEL,
56 'onCalendarEventCommentAdd' => EventDictionary::EVENT_SPACE_CALENDAR_EVENT_COMMENT_ADD,
57 ];
58
60 }
61
62 private function getRecipientIds(array $data): array
63 {
64 if (isset($data['TO_USER_ID']))
65 {
66 return [$data['TO_USER_ID']];
67 }
68
69 if (is_array($data['ATTENDEE_LIST'] ?? null))
70 {
71 return $this->getRecipientFromAttendeeList($data['ATTENDEE_LIST']);
72 }
73
74 return [];
75 }
76
77 private function getRecipientFromAttendeeList(array $attendeeList): array
78 {
79 $recipients = [];
80
81 foreach ($attendeeList as $attendee)
82 {
83 if (!empty($attendee['id']))
84 {
85 $recipients[] = (int)$attendee['id'];
86 }
87 }
88
89 return $recipients;
90 }
91}
static addEvent(string $type, array $data)
Definition service.php:44