Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
sharingconference.php
1<?php
2
4
9
11{
12 private const CONFERENCE_PATH = 'video/';
13 private const CONFERENCE_TYPE = 'VIDEOCONF';
15 private EventLink $eventLink;
16
20 public function __construct(EventLink $eventLink)
21 {
22 $this->eventLink = $eventLink;
23 }
24
32 public function getConferenceChatId(): ?int
33 {
34 if (!$this->checkPossibilityOfCreatingLink())
35 {
36 return null;
37 }
38
39 if ($this->eventLink->getConferenceId())
40 {
41 return $this->getConferenceChatIdByAlias($this->eventLink->getConferenceId());
42 }
43
44 $conference = $this->createConference();
45
46 if (!$conference)
47 {
48 return null;
49 }
50
51 Analytics::getInstance()->sendChatCreated($this->eventLink, Analytics::MANAGER_STARTED);
52
53 $this->eventLink->setConferenceId($conference->getData()['ALIAS_DATA']['ALIAS']);
54
55 (new EventLinkMapper())->update($this->eventLink);
56
57 return $conference->getData()['CHAT_ID'];
58 }
59
66 public function getConferenceLink(): ?string
67 {
68 if (!$this->checkPossibilityOfCreatingLink())
69 {
70 return null;
71 }
72
73 if ($this->eventLink->getConferenceId())
74 {
75 return $this->getConferenceUrl($this->eventLink->getConferenceId());
76 }
77
78 $conference = $this->createConference();
79
80 if (!$conference)
81 {
82 return null;
83 }
84
85 Analytics::getInstance()->sendChatCreated($this->eventLink, Analytics::CLIENT_STARTED);
86
87 $this->eventLink->setConferenceId($conference->getData()['ALIAS_DATA']['ALIAS']);
88
89 (new EventLinkMapper())->update($this->eventLink);
90
91 return $this->getConferenceUrl($this->eventLink->getConferenceId());
92 }
93
94 private function createConference()
95 {
96 $event = \CCalendarEvent::GetList([
97 'arFilter' => [
98 'ID' => $this->eventLink->getObjectId(),
99 ],
100 'fetchAttendees' => true,
101 'checkPermissions' => false,
102 ]);
103
104 $event = $event[0] ?? false;
105 if (
106 !$event
107 || !in_array(
108 $event['EVENT_TYPE'] ?? null,
109 [Dictionary::EVENT_TYPE['shared_crm'], Dictionary::EVENT_TYPE['shared']],
110 true
111 )
112 )
113 {
114 return false;
115 }
116
117 $attendeesId = [];
118 $attendeesCodes = $event['ATTENDEE_LIST'] ?? [];
119 foreach ($attendeesCodes as $attendee)
120 {
121 if (
122 isset($attendee['id'])
123 && in_array($attendee['status'] ?? null, Dictionary::MEETING_STATUS, true)
124 && $attendee['status'] !== Dictionary::MEETING_STATUS['No']
125 && $attendee['status'] !== Dictionary::MEETING_STATUS['Host']
126 )
127 {
128 $attendeesId[] = $attendee['id'];
129 }
130 }
131
132 if (empty($attendeesId))
133 {
134 return null;
135 }
136
137 $conference = \Bitrix\Im\Call\Conference::add([
138 'USERS' => $attendeesId,
139 'TITLE' => $event['NAME'],
140 'AUTHOR_ID' => $attendeesId[0],
141 ]);
142
143 if ($conference->getErrors())
144 {
145 return null;
146 }
147
148 return $conference;
149 }
150
158 private function getConferenceChatIdByAlias(string $alias): ?int
159 {
160 $aliasInfo = \Bitrix\Im\Model\AliasTable::query()
161 ->setSelect(['*'])
162 ->where('ALIAS', $alias)
163 ->where('ENTITY_TYPE', self::CONFERENCE_TYPE)
164 ->exec()->fetch()
165 ;
166
167 if (!$aliasInfo)
168 {
169 return null;
170 }
171
172 return (int)$aliasInfo['ENTITY_ID'];
173 }
174
179 private function checkPossibilityOfCreatingLink(): bool
180 {
181 return !(!Loader::includeModule('im') || !Loader::includeModule('voximplant'));
182 }
183
188 private function getConferenceUrl($conferenceId): string
189 {
190 $serverPath = \CCalendar::GetServerPath();
191
192 return $serverPath . '/' . self::CONFERENCE_PATH . $conferenceId;
193 }
194}