12 private const CONFERENCE_PATH =
'video/';
13 private const CONFERENCE_TYPE =
'VIDEOCONF';
22 $this->eventLink = $eventLink;
34 if (!$this->checkPossibilityOfCreatingLink())
39 if ($this->eventLink->getConferenceId())
41 return $this->getConferenceChatIdByAlias($this->eventLink->getConferenceId());
44 $conference = $this->createConference();
53 $this->eventLink->setConferenceId($conference->getData()[
'ALIAS_DATA'][
'ALIAS']);
57 return $conference->getData()[
'CHAT_ID'];
68 if (!$this->checkPossibilityOfCreatingLink())
73 if ($this->eventLink->getConferenceId())
75 return $this->getConferenceUrl($this->eventLink->getConferenceId());
78 $conference = $this->createConference();
87 $this->eventLink->setConferenceId($conference->getData()[
'ALIAS_DATA'][
'ALIAS']);
91 return $this->getConferenceUrl($this->eventLink->getConferenceId());
94 private function createConference()
96 $event = \CCalendarEvent::GetList([
98 'ID' => $this->eventLink->getObjectId(),
100 'fetchAttendees' =>
true,
101 'checkPermissions' =>
false,
104 $event = $event[0] ??
false;
108 $event[
'EVENT_TYPE'] ??
null,
109 [Dictionary::EVENT_TYPE[
'shared_crm'], Dictionary::EVENT_TYPE[
'shared']],
118 $attendeesCodes = $event[
'ATTENDEE_LIST'] ?? [];
119 foreach ($attendeesCodes as $attendee)
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']
128 $attendeesId[] = $attendee[
'id'];
132 if (empty($attendeesId))
137 $conference = \Bitrix\Im\Call\Conference::add([
138 'USERS' => $attendeesId,
139 'TITLE' => $event[
'NAME'],
140 'AUTHOR_ID' => $attendeesId[0],
143 if ($conference->getErrors())
158 private function getConferenceChatIdByAlias(
string $alias): ?int
160 $aliasInfo = \Bitrix\Im\Model\AliasTable::query()
162 ->where(
'ALIAS', $alias)
163 ->where(
'ENTITY_TYPE', self::CONFERENCE_TYPE)
172 return (
int)$aliasInfo[
'ENTITY_ID'];
179 private function checkPossibilityOfCreatingLink(): bool
181 return !(!Loader::includeModule(
'im') || !Loader::includeModule(
'voximplant'));
188 private function getConferenceUrl($conferenceId): string
190 $serverPath = \CCalendar::GetServerPath();
192 return $serverPath .
'/' . self::CONFERENCE_PATH . $conferenceId;