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