Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
conference.php
1<?php
2
3namespace Bitrix\Im\Call;
4
23use CBitrix24;
24
26{
27 /* codes sync with im/install/js/im/const/src/call.js:25 */
28 public const ERROR_USER_LIMIT_REACHED = "userLimitReached";
29 public const ERROR_BITRIX24_ONLY = "bitrix24only";
30 public const ERROR_DETECT_INTRANET_USER = "detectIntranetUser";
31 public const ERROR_KICKED_FROM_CALL = "kickedFromCall";
32 public const ERROR_WRONG_ALIAS = "wrongAlias";
33
34 public const STATE_NOT_STARTED = "notStarted";
35 public const STATE_ACTIVE = "active";
36 public const STATE_FINISHED = "finished";
37
38 public const ALIAS_TYPE = 'VIDEOCONF';
39 public const BROADCAST_MODE = 'BROADCAST';
40
41 public const PRESENTERS_LIMIT = 4;
42 public const BROADCAST_USER_LIMIT = 500;
43 public const ROLE_PRESENTER = 'presenter';
44 public const AVAILABLE_PARAMS = [
45 'ID',
46 'TITLE',
47 'PASSWORD_NEEDED',
48 'PASSWORD',
49 'USERS',
50 'BROADCAST_MODE',
51 'PRESENTERS',
52 'INVITATION',
53 ];
54
55 protected $id;
56 protected $alias;
57 protected $aliasId;
58 protected $chatId;
59 protected $password;
60 protected $invitation;
61 protected $startDate;
62 protected $chatName;
63 protected $hostName;
64 protected $hostId;
65 protected $users;
66 protected $broadcastMode;
67 protected $speakers;
68
69 protected function __construct()
70 {
71 }
72
73 public function getId()
74 {
75 return $this->id;
76 }
77
78 public function getAliasId()
79 {
80 return $this->aliasId;
81 }
82
83 public function getAlias()
84 {
85 return $this->alias;
86 }
87
88 public function getStartDate()
89 {
90 return $this->startDate;
91 }
92
93 public function getChatId()
94 {
95 return $this->chatId;
96 }
97
98 public function getChatName()
99 {
100 return $this->chatName;
101 }
102
103 public function getHostName()
104 {
105 return $this->hostName;
106 }
107
108 public function getHostId()
109 {
110 return $this->hostId;
111 }
112
113 public function isPasswordRequired(): bool
114 {
115 return $this->password !== '';
116 }
117
118 public function getPassword()
119 {
120 return $this->password;
121 }
122
123 public function getInvitation()
124 {
125 return $this->invitation;
126 }
127
128 public function getUsers(): array
129 {
130 $users = Chat::getUsers($this->getChatId(), ['SKIP_EXTERNAL' => true]);
131
132 return array_map(static function($user){
133 return [
134 'id' => $user['id'],
135 'title' => $user['name'],
136 'avatar' => $user['avatar']
137 ];
138 }, $users);
139 }
140
141 public function getOwnerId(): ?int
142 {
143 $authorId = Chat::getOwnerById(Dialog::getDialogId($this->getChatId()));
144
145 return $authorId;
146 }
147
148 public function getUserLimit(): int
149 {
150 if ($this->isBroadcast())
151 {
153 }
154 else if (Call::isCallServerEnabled())
155 {
157 }
158 else
159 {
160 return (int)Option::get('im', 'turn_server_max_users');
161 }
162 }
163
164 public function isBroadcast(): bool
165 {
167 }
168
169 public function getPresentersList(): array
170 {
171 $result = [];
172
173 $presenters = \Bitrix\Im\Model\ConferenceUserRoleTable::getList(
174 [
175 'select' => ['USER_ID'],
176 'filter' => [
177 '=CONFERENCE_ID' => $this->getId(),
178 '=ROLE' => self::ROLE_PRESENTER
179 ]
180 ]
181 )->fetchAll();
182
183 foreach ($presenters as $presenter)
184 {
185 $result[] = (int)$presenter['USER_ID'];
186 }
187
188 return $result;
189 }
190
191 public function getPresentersInfo(): array
192 {
193 $result = [];
194 $presenters = $this->getPresentersList();
195
196 foreach ($presenters as $presenter)
197 {
198 $presenterInfo = \Bitrix\Im\User::getInstance($presenter)->getArray();
199 $result[] = array_change_key_case($presenterInfo, CASE_LOWER);
200 }
201
202 return $result;
203 }
204
205 public function isPresenter(int $userId): bool
206 {
207 $presenters = $this->getPresentersList();
208
209 return in_array($userId, $presenters, true);
210 }
211
212 public function makePresenter(int $userId): \Bitrix\Main\ORM\Data\AddResult
213 {
214 return \Bitrix\Im\Model\ConferenceUserRoleTable::add(
215 [
216 'CONFERENCE_ID' => $this->getId(),
217 'USER_ID' => $userId,
218 'ROLE' => self::ROLE_PRESENTER
219 ]
220 );
221 }
222
223 public function deletePresenter(int $userId): \Bitrix\Main\ORM\Data\DeleteResult
224 {
225 return \Bitrix\Im\Model\ConferenceUserRoleTable::delete(
226 [
227 'CONFERENCE_ID' => $this->getId(),
228 'USER_ID' => $userId
229 ]
230 );
231 }
232
233 public function isActive(): bool
234 {
235 //TODO
236 return true;
237 }
238
239 public function isFinished(): bool
240 {
241 return $this->getStatus() === static::STATE_FINISHED;
242 }
243
244 public function getStatus(): string
245 {
246 //todo
247 if (!($this->startDate instanceof DateTime))
248 {
250 }
251
252 $now = time();
253 $startTimestamp = $this->startDate->getTimestamp();
254
255 //TODO: active and finished
256 if ($startTimestamp > $now)
257 {
259 }
260
262 }
263
264 public function getPublicLink(): string
265 {
266 return Common::getPublicDomain().'/video/'.$this->alias;
267 }
268
269 public function canUserEdit($userId): bool
270 {
271 if (Loader::includeModule('bitrix24'))
272 {
273 $isAdmin = CBitrix24::IsPortalAdmin($userId);
274 }
275 else
276 {
277 $user = new \CUser();
278 $arGroups = $user::GetUserGroup($userId);
279 $isAdmin = in_array(1, $arGroups, true);
280 }
281
282// return ($this->getStatus() !== static::STATE_FINISHED) &&
283 return ($isAdmin || $this->getHostId() === $userId);
284 }
285
286 public function canUserDelete($userId): bool
287 {
288 if (Loader::includeModule('bitrix24'))
289 {
290 $isAdmin = CBitrix24::IsPortalAdmin($userId);
291 }
292 else
293 {
294 $user = new \CUser();
295 $arGroups = $user::GetUserGroup($userId);
296 $isAdmin = in_array(1, $arGroups, true);
297 }
298
299 return $isAdmin || $this->getHostId() === $userId;
300 }
301
302 protected function setFields(array $fields): bool
303 {
304 //set instance fields after update
305 return true;
306 }
307
308 protected function getChangedFields(array $fields): array
309 {
310 $result = [];
311
312 if (isset($fields['TITLE']) && $fields['TITLE'] !== $this->chatName)
313 {
314 $result['TITLE'] = $fields['TITLE'];
315 }
316
317 if (isset($fields['VIDEOCONF']['PASSWORD']) && $fields['VIDEOCONF']['PASSWORD'] !== $this->getPassword())
318 {
319 $result['VIDEOCONF']['PASSWORD'] = $fields['VIDEOCONF']['PASSWORD'];
320 }
321
322 if (isset($fields['VIDEOCONF']['INVITATION']) && $fields['VIDEOCONF']['INVITATION'] !== $this->getInvitation())
323 {
324 $result['VIDEOCONF']['INVITATION'] = $fields['VIDEOCONF']['INVITATION'];
325 }
326
327 $newBroadcastMode = isset($fields['VIDEOCONF']['PRESENTERS']) && count($fields['VIDEOCONF']['PRESENTERS']) > 0;
328 if ($this->isBroadcast() !== $newBroadcastMode)
329 {
330 $result['VIDEOCONF']['IS_BROADCAST'] = $newBroadcastMode === true ? 'Y' : 'N';
331 }
332
333 if ($newBroadcastMode)
334 {
335 $currentPresenters = $this->getPresentersList();
336 $result['NEW_PRESENTERS'] = array_diff($fields['VIDEOCONF']['PRESENTERS'], $currentPresenters);
337 $result['DELETED_PRESENTERS'] = array_diff($currentPresenters, $fields['VIDEOCONF']['PRESENTERS']);
338 }
339
340 if (isset($fields['USERS']))
341 {
342 $currentUsers = array_map(static function($user){
343 return $user['id'];
344 }, $this->users);
345
346 $result['NEW_USERS'] = array_diff($fields['USERS'], $currentUsers);
347 $result['DELETED_USERS'] = array_diff($currentUsers, $fields['USERS']);
348 }
349
350 return $result;
351 }
352
353 public function update(array $fields = []): Result
354 {
355 $result = new Result();
356
357 if (!static::isEnvironmentConfigured())
358 {
359 return $result->addError(
360 new Error(
361 Loc::getMessage('IM_CALL_CONFERENCE_ERROR_ENVIRONMENT_CONFIG'),
362 'ENVIRONMENT_CONFIG_ERROR'
363 )
364 );
365 }
366
367 $validationResult = static::validateFields($fields);
368 if (!$validationResult->isSuccess())
369 {
370 return $result->addErrors($validationResult->getErrors());
371 }
372 $updateData = $validationResult->getData()['FIELDS'];
373
374 if (!isset($fields['ID']))
375 {
376 return $result->addError(
377 new Error(
378 Loc::getMessage('IM_CALL_CONFERENCE_ERROR_ID_NOT_PROVIDED'),
379 'CONFERENCE_ID_EMPTY'
380 )
381 );
382 }
383
384 $updateData = $this->getChangedFields($updateData);
385 if (empty($updateData))
386 {
387 return $result;
388 }
389 $updateData['ID'] = $fields['ID'];
390
391 if (!isset($fields['PASSWORD']))
392 {
393 unset($updateData['VIDEOCONF']['PASSWORD']);
394 }
395
396 global $USER;
397 $chat = new \CIMChat($USER->GetID());
398
399 //Chat update
400 if ($updateData['TITLE'])
401 {
402 $renameResult = $chat->Rename($this->getChatId(), $updateData['TITLE']);
403
404 if (!$renameResult)
405 {
406 return $result->addError(
407 new Error(
408 Loc::getMessage('IM_CALL_CONFERENCE_ERROR_RENAMING_CHAT'),
409 'CONFERENCE_RENAMING_ERROR'
410 )
411 );
412 }
413
414 $this->chatName = $updateData['TITLE'];
415 }
416
417 //Adding users
418 if (isset($updateData['NEW_USERS']))
419 {
420 //check user count
421 $userLimit = $this->getUserLimit();
422
423 $currentUserCount = \CIMChat::getUserCount($this->chatId);
424 $newUserCount = $currentUserCount + count($updateData['NEW_USERS']);
425 if (isset($updateData['DELETED_USERS']))
426 {
427 $newUserCount -= count($updateData['DELETED_USERS']);
428 }
429
430 if ($newUserCount > $userLimit)
431 {
432 return $result->addError(
433 new Error(
434 Loc::getMessage('IM_CALL_CONFERENCE_ERROR_MAX_USERS'),
435 'USER_LIMIT_ERROR'
436 )
437 );
438 }
439
440 foreach ($updateData['NEW_USERS'] as $newUser)
441 {
442 $addingResult = $chat->AddUser($this->getChatId(), $newUser);
443
444 if (!$addingResult)
445 {
446 return $result->addError(
447 new Error(
448 Loc::getMessage('IM_CALL_CONFERENCE_ERROR_ADDING_USERS'),
449 'ADDING_USER_ERROR'
450 )
451 );
452 }
453 }
454 }
455
456 //Deleting users
457 if (isset($updateData['DELETED_USERS']))
458 {
459 foreach ($updateData['DELETED_USERS'] as $deletedUser)
460 {
461 $addingResult = $chat->DeleteUser($this->getChatId(), $deletedUser);
462
463 if (!$addingResult)
464 {
465 return $result->addError(
466 new Error(
467 Loc::getMessage('IM_CALL_CONFERENCE_ERROR_DELETING_USERS'),
468 'DELETING_USER_ERROR'
469 )
470 );
471 }
472 }
473 }
474
475 //Conference update
476 if (isset($updateData['VIDEOCONF']))
477 {
478 if (isset($updateData['VIDEOCONF']['IS_BROADCAST']))
479 {
480 \CIMChat::SetChatParams($this->getChatId(), [
481 'ENTITY_DATA_1' => $updateData['VIDEOCONF']['IS_BROADCAST'] === 'Y'? self::BROADCAST_MODE: ''
482 ]);
483 }
484
485 $updateResult = ConferenceTable::update($updateData['ID'], $updateData['VIDEOCONF']);
486
487 if (!$updateResult->isSuccess())
488 {
489 return $result->addErrors($updateResult->getErrors());
490 }
491 }
492
493 //update presenters
494 if (isset($updateData['NEW_PRESENTERS']) && !empty($updateData['NEW_PRESENTERS']))
495 {
496 $setManagers = [];
497 foreach ($updateData['NEW_PRESENTERS'] as $newPresenter)
498 {
499 $this->makePresenter($newPresenter);
500 $setManagers[$newPresenter] = true;
501 }
502 $chat->SetManagers($this->getChatId(), $setManagers, false);
503 }
504
505 if (isset($updateData['DELETED_PRESENTERS']) && !empty($updateData['DELETED_PRESENTERS']))
506 {
507 $removeManagers = [];
508 foreach ($updateData['DELETED_PRESENTERS'] as $deletedPresenter)
509 {
510 $this->deletePresenter($deletedPresenter);
511 $removeManagers[$deletedPresenter] = false;
512 }
513 $chat->SetManagers($this->getChatId(), $removeManagers, false);
514 }
515
516 // delete presenters if we change mode to normal
517 if (isset($updateData['VIDEOCONF']['IS_BROADCAST']) && $updateData['VIDEOCONF']['IS_BROADCAST'] === 'N')
518 {
519 $presentersList = $this->getPresentersList();
520 foreach ($presentersList as $presenter)
521 {
522 $this->deletePresenter($presenter);
523 }
524 }
525
526 // send pull
527 $isPullNeeded = isset($updateData['VIDEOCONF']['IS_BROADCAST']) || isset($updateData['NEW_PRESENTERS']) || isset($updateData['DELETED_PRESENTERS']);
528 if ($isPullNeeded && Loader::includeModule("pull"))
529 {
530 $relations = \CIMChat::GetRelationById($this->getChatId(), false, true, false);
531 $pushMessage = [
532 'module_id' => 'im',
533 'command' => 'conferenceUpdate',
534 'params' => [
535 'chatId' => $this->getChatId(),
536 'isBroadcast' => isset($updateData['VIDEOCONF']['IS_BROADCAST']) ? $updateData['VIDEOCONF']['IS_BROADCAST'] === 'Y' : '',
537 'presenters' => $this->getPresentersList()
538 ],
539 'extra' => \Bitrix\Im\Common::getPullExtra()
540 ];
541 \Bitrix\Pull\Event::add(array_keys($relations), $pushMessage);
542 }
543
544 return $result;
545 }
546
547 public function delete(): Result
548 {
549 $result = new Result();
550
551 //hide chat
552 \CIMChat::hide($this->getChatId());
553
554 //delete relations
555 RelationTable::deleteByFilter(['=CHAT_ID' => $this->getChatId()]);
556
557 //delete roles
558 $presenters = $this->getPresentersList();
559 foreach ($presenters as $presenter)
560 {
561 $deleteRolesResult = ConferenceUserRoleTable::delete(
562 [
563 'CONFERENCE_ID' => $this->getId(),
564 'USER_ID' => $presenter
565 ]
566 );
567
568 if (!$deleteRolesResult->isSuccess())
569 {
570 return $result->addErrors($deleteRolesResult->getErrors());
571 }
572 }
573
574 //delete conference
575 $deleteConferenceResult = ConferenceTable::delete($this->getId());
576 if (!$deleteConferenceResult->isSuccess())
577 {
578 return $result->addErrors($deleteConferenceResult->getErrors());
579 }
580
581 //delete alias
582 $deleteAliasResult = AliasTable::delete($this->getAliasId());
583 if (!$deleteAliasResult->isSuccess())
584 {
585 return $result->addErrors($deleteAliasResult->getErrors());
586 }
587
588 //delete access codes
589 $accessProvider = new \Bitrix\Im\Access\ChatAuthProvider;
590 $accessProvider->deleteChatCodes((int)$this->getChatId());
591
592 return $result;
593 }
594
595 protected static function validateFields(array $fields): \Bitrix\Im\V2\Result
596 {
597 $result = new \Bitrix\Im\V2\Result();
598 $validatedFields = [];
599
600 $fields = array_change_key_case($fields, CASE_UPPER);
601
602 if (isset($fields['TITLE']) && is_string($fields['TITLE']))
603 {
604 $fields['TITLE'] = trim($fields['TITLE']);
605 $validatedFields['TITLE'] = $fields['TITLE'];
606 }
607
608 if (isset($fields['PASSWORD']) && is_string($fields['PASSWORD']) && $fields['PASSWORD'] !== '')
609 {
610 $fields['PASSWORD'] = trim($fields['PASSWORD']);
611
612 if (strlen($fields['PASSWORD']) < 3)
613 {
614 return $result->addError(
615 new Error(
616 Loc::getMessage('IM_CALL_CONFERENCE_ERROR_PASSWORD_LENGTH_NEW'),
617 'PASSWORD_SHORT_ERROR'
618 )
619 );
620 }
621
622 $validatedFields['VIDEOCONF']['PASSWORD'] = $fields['PASSWORD'];
623 }
624 else
625 {
626 $validatedFields['VIDEOCONF']['PASSWORD'] = $fields['VIDEOCONF']['PASSWORD'] ?? '';
627 }
628
629 if (isset($fields['INVITATION']) && is_string($fields['INVITATION']))
630 {
631 $fields['INVITATION'] = trim($fields['INVITATION']);
632
633 if (strlen($fields['INVITATION']) > 255)
634 {
635 return $result->addError(
636 new Error(
637 Loc::getMessage('IM_CALL_CONFERENCE_ERROR_INVITATION_LENGTH'),
638 'INVITATION_LONG_ERROR'
639 )
640 );
641 }
642
643 $validatedFields['VIDEOCONF']['INVITATION'] = $fields['INVITATION'];
644 }
645 elseif (isset($fields['VIDEOCONF']['INVITATION']) && is_string($fields['VIDEOCONF']['INVITATION']))
646 {
647 $validatedFields['VIDEOCONF']['INVITATION'] = $fields['VIDEOCONF']['INVITATION'];
648 }
649
650 if (isset($fields['USERS']) && is_array($fields['USERS']))
651 {
652 $validatedFields['USERS'] = [];
653 foreach ($fields['USERS'] as $userId)
654 {
655 $validatedFields['USERS'][] = (int)$userId;
656 }
657 }
658
659 if (isset($fields['BROADCAST_MODE']) && $fields['BROADCAST_MODE'] === true && Settings::isBroadcastingEnabled())
660 {
661 if (count($fields['PRESENTERS']) === 0)
662 {
663 return $result->addError(
664 new Error(
665 Loc::getMessage('IM_CALL_CONFERENCE_ERROR_NO_PRESENTERS'),
666 'PRESENTERS_EMPTY_ERROR'
667 )
668 );
669 }
670
671 if (count($fields['PRESENTERS']) > self::PRESENTERS_LIMIT)
672 {
673 return $result->addError(
674 new Error(
675 Loc::getMessage('IM_CALL_CONFERENCE_ERROR_TOO_MANY_PRESENTERS'),
676 'PRESENTERS_TOO_MANY_ERROR'
677 )
678 );
679 }
680
681 $validatedFields['VIDEOCONF']['IS_BROADCAST'] = 'Y';
682 $validatedFields['VIDEOCONF']['PRESENTERS'] = [];
683 foreach ($fields['PRESENTERS'] as $userId)
684 {
685 $validatedFields['USERS'][] = (int)$userId;
686 $validatedFields['VIDEOCONF']['PRESENTERS'][] = (int)$userId;
687 }
688 }
689 else
690 {
691 $validatedFields['VIDEOCONF']['IS_BROADCAST'] = 'N';
692 }
693
694 if (isset($fields['ALIAS_DATA']))
695 {
696 if (static::isAliasCorrect($fields['ALIAS_DATA']))
697 {
698 $validatedFields['VIDEOCONF']['ALIAS_DATA'] = $fields['ALIAS_DATA'];
699 }
700 else
701 {
702 return $result->addError(
703 new Error(
704 Loc::getMessage('IM_CALL_CONFERENCE_ERROR_ALIAS'),
705 'WRONG_ALIAS_ERROR'
706 )
707 );
708 }
709 }
710 else
711 {
712 if (isset($fields['VIDEOCONF']['ALIAS_DATA']))
713 {
714 $validatedFields['VIDEOCONF']['ALIAS_DATA'] = $fields['VIDEOCONF']['ALIAS_DATA'];
715 }
716 else
717 {
718 $validatedFields['VIDEOCONF']['ALIAS_DATA'] = Alias::addUnique([
719 "ENTITY_TYPE" => Alias::ENTITY_TYPE_VIDEOCONF,
720 "ENTITY_ID" => 0
721 ]);
722 }
723 }
724
725 $result->setData(['FIELDS' => $validatedFields]);
726
727 return $result;
728 }
729
730 public static function add(array $fields = []): Result
731 {
732 $result = self::prepareParamsForAdd($fields);
733
734 if (!$result->isSuccess())
735 {
736 return $result;
737 }
738
739 $addData = $result->getData()['FIELDS'];
740
741 $result = ChatFactory::getInstance()->addChat($addData);
742 if (!$result->isSuccess() || !$result->hasResult())
743 {
744 return $result->addError(
745 new Error(
746 Loc::getMessage('IM_CALL_CONFERENCE_ERROR_CREATING'),
747 'CREATION_ERROR'
748 )
749 );
750 }
751
752 $chatResult = $result->getResult();
753 return $result->setData([
754 'CHAT_ID' => $chatResult['CHAT_ID'],
755 'ALIAS_DATA' => $addData['VIDEOCONF']['ALIAS_DATA']
756 ]);
757 }
758
759 public static function prepareParamsForAdd(array $fields): \Bitrix\Im\V2\Result
760 {
761 $result = new \Bitrix\Im\V2\Result();
762
763 if (!static::isEnvironmentConfigured()) {
764 return $result->addError(
765 new Error(
766 Loc::getMessage('IM_CALL_CONFERENCE_ERROR_ENVIRONMENT_CONFIG'),
767 'ENVIRONMENT_CONFIG_ERROR'
768 )
769 );
770 }
771
772 $validationResult = static::validateFields($fields);
773
774 if (!$validationResult->isSuccess())
775 {
776 return $result->addErrors($validationResult->getErrors());
777 }
778
779 $addData = $validationResult->getData()['FIELDS'];
780 $addData['ENTITY_TYPE'] = static::ALIAS_TYPE;
781 $addData['ENTITY_DATA_1'] = $addData['VIDEOCONF']['IS_BROADCAST'] === 'Y'? static::BROADCAST_MODE: '';
782
783 if (isset($fields['AUTHOR_ID']))
784 {
785 $addData['AUTHOR_ID'] = (int)$fields['AUTHOR_ID'];
786 }
787 else
788 {
789 $currentUser = \Bitrix\Im\User::getInstance();
790 $addData['AUTHOR_ID'] = $currentUser->getId();
791 }
792
793
794 if (!isset($fields['MANAGERS']))
795 {
796 $addData['MANAGERS'] = [];
797 if ($addData['VIDEOCONF']['IS_BROADCAST'] === 'Y')
798 {
799 foreach ($addData['VIDEOCONF']['PRESENTERS'] as $presenter)
800 {
801 $addData['MANAGERS'][$presenter] = true;
802 }
803 }
804 }
805
806 $result->setData(['FIELDS' => $addData]);
807
808 return $result;
809 }
810
811 public static function getByAlias(string $alias)
812 {
813 $conferenceFields = ConferenceTable::getRow(
814 [
815 'select' => self::getDefaultSelectFields(),
816 'runtime' => self::getRuntimeChatField(),
817 'filter' => ['=ALIAS.ALIAS' => $alias, '=ALIAS.ENTITY_TYPE' => static::ALIAS_TYPE]
818 ]
819 );
820
821 if (!$conferenceFields)
822 {
823 return false;
824 }
825
826 return static::createWithArray($conferenceFields);
827 }
828
829 public static function getById(int $id): ?Conference
830 {
831 $conferenceFields = ConferenceTable::getRow(
832 [
833 'select' => self::getDefaultSelectFields(),
834 'runtime' => self::getRuntimeChatField(),
835 'filter' => ['=ID' => $id, '=ALIAS.ENTITY_TYPE' => static::ALIAS_TYPE]
836 ]
837 );
838
839 if (!$conferenceFields)
840 {
841 return null;
842 }
843
844 return static::createWithArray($conferenceFields);
845 }
846
847 public static function createWithArray(array $fields): Conference
848 {
849 $instance = new static();
850
851 $instance->id = (int)$fields['ID'];
852 $instance->alias = $fields['ALIAS_CODE'];
853 $instance->aliasId = $fields['ALIAS_PRIMARY'];
854 $instance->chatId = (int)$fields['CHAT_ID'];
855 $instance->password = $fields['PASSWORD'];
856 $instance->invitation = $fields['INVITATION'];
857 $instance->startDate = $fields['CONFERENCE_START'];
858 $instance->chatName = $fields['CHAT_NAME'];
859 $instance->hostName = $fields['HOST_NAME']." ".$fields['HOST_LAST_NAME'];
860 $instance->hostId = $fields['HOST'];
861 $instance->broadcastMode = $fields['IS_BROADCAST'] === 'Y';
862
863 $instance->users = $instance->getUsers();
864
865 return $instance;
866 }
867
868 public static function getAll(array $queryParams): ArrayResult
869 {
870 $result = [];
871 $list = ConferenceTable::getList($queryParams);
872
873 while ($item = $list->fetch())
874 {
875 $result[] = $item;
876 }
877
878 $dbResult = new ArrayResult($result);
879 $dbResult->setCount($list->getCount());
880
881 return $dbResult;
882 }
883
884 public static function getStatusList(): array
885 {
886 return [static::STATE_NOT_STARTED, static::STATE_ACTIVE, static::STATE_FINISHED];
887 }
888
889 public static function getDefaultSelectFields(): array
890 {
891 return [
892 'ID',
893 'CONFERENCE_START',
894 'PASSWORD',
895 'INVITATION',
896 'IS_BROADCAST',
897 'ALIAS_PRIMARY' => 'ALIAS.ID',
898 'ALIAS_CODE' => 'ALIAS.ALIAS',
899 'CHAT_ID' => 'ALIAS.ENTITY_ID',
900 'HOST' => 'CHAT.AUTHOR.ID',
901 'HOST_NAME' => 'CHAT.AUTHOR.NAME',
902 'HOST_LAST_NAME' => 'CHAT.AUTHOR.LAST_NAME',
903 'CHAT_NAME' => 'CHAT.TITLE'
904 ];
905 }
906
907 public static function getRuntimeChatField(): array
908 {
909 return [
910 new Entity\ReferenceField(
911 'CHAT', 'Bitrix\Im\Model\ChatTable', ['=this.CHAT_ID' => 'ref.ID']
912 ),
913 new Entity\ReferenceField(
914 'RELATION', 'Bitrix\Im\Model\RelationTable', ['=this.CHAT_ID' => 'ref.CHAT_ID'], ['join_type' => 'inner']
915 )
916 ];
917 }
918
919 public static function removeTemporaryAliases(): string
920 {
921 AliasTable::deleteByFilter(
922 [
923 '=ENTITY_TYPE' => Alias::ENTITY_TYPE_VIDEOCONF,
924 '=ENTITY_ID' => 0
925 ],
926 1000
927 );
928
929 return __METHOD__. '();';
930 }
931
932 private static function isAliasCorrect($aliasData): bool
933 {
934 return isset($aliasData['ID'], $aliasData['ALIAS']) && Alias::getByIdAndCode($aliasData['ID'], $aliasData['ALIAS']);
935 }
936
937 private static function isEnvironmentConfigured(): bool
938 {
939 return (
940 \Bitrix\Main\Loader::includeModule('pull')
941 && \CPullOptions::GetPublishWebEnabled()
943 );
944 }
945}
static getByIdAndCode($id, $code)
Definition alias.php:164
const ENTITY_TYPE_VIDEOCONF
Definition alias.php:13
static addUnique(array $fields)
Definition alias.php:55
static getMaxCallServerParticipants()
Definition call.php:653
static isCallServerEnabled()
Definition call.php:873
getChangedFields(array $fields)
static createWithArray(array $fields)
static validateFields(array $fields)
update(array $fields=[])
static getAll(array $queryParams)
static add(array $fields=[])
static getById(int $id)
static prepareParamsForAdd(array $fields)
static getByAlias(string $alias)
static getUsers($chatId, $options=[])
Definition chat.php:787
static getOwnerById($dialogId)
Definition chat.php:1385
static getPublicDomain()
Definition common.php:8
static getDialogId(int $chatId, $userId=null)
Definition dialog.php:48
static isBroadcastingEnabled()
Definition settings.php:37
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29