312 if (isset($fields[
'TITLE']) && $fields[
'TITLE'] !== $this->chatName)
314 $result[
'TITLE'] = $fields[
'TITLE'];
317 if (isset($fields[
'VIDEOCONF'][
'PASSWORD']) && $fields[
'VIDEOCONF'][
'PASSWORD'] !== $this->
getPassword())
319 $result[
'VIDEOCONF'][
'PASSWORD'] = $fields[
'VIDEOCONF'][
'PASSWORD'];
322 if (isset($fields[
'VIDEOCONF'][
'INVITATION']) && $fields[
'VIDEOCONF'][
'INVITATION'] !== $this->
getInvitation())
324 $result[
'VIDEOCONF'][
'INVITATION'] = $fields[
'VIDEOCONF'][
'INVITATION'];
327 $newBroadcastMode = isset($fields[
'VIDEOCONF'][
'PRESENTERS']) && count($fields[
'VIDEOCONF'][
'PRESENTERS']) > 0;
330 $result[
'VIDEOCONF'][
'IS_BROADCAST'] = $newBroadcastMode ===
true ?
'Y' :
'N';
333 if ($newBroadcastMode)
336 $result[
'NEW_PRESENTERS'] = array_diff($fields[
'VIDEOCONF'][
'PRESENTERS'], $currentPresenters);
337 $result[
'DELETED_PRESENTERS'] = array_diff($currentPresenters, $fields[
'VIDEOCONF'][
'PRESENTERS']);
340 if (isset($fields[
'USERS']))
342 $currentUsers = array_map(
static function($user){
346 $result[
'NEW_USERS'] = array_diff($fields[
'USERS'], $currentUsers);
347 $result[
'DELETED_USERS'] = array_diff($currentUsers, $fields[
'USERS']);
357 if (!static::isEnvironmentConfigured())
359 return $result->addError(
362 'ENVIRONMENT_CONFIG_ERROR'
367 $validationResult = static::validateFields($fields);
368 if (!$validationResult->isSuccess())
370 return $result->addErrors($validationResult->getErrors());
372 $updateData = $validationResult->getData()[
'FIELDS'];
374 if (!isset($fields[
'ID']))
376 return $result->addError(
379 'CONFERENCE_ID_EMPTY'
385 if (empty($updateData))
389 $updateData[
'ID'] = $fields[
'ID'];
391 if (!isset($fields[
'PASSWORD']))
393 unset($updateData[
'VIDEOCONF'][
'PASSWORD']);
397 $chat = new \CIMChat($USER->GetID());
400 if ($updateData[
'TITLE'])
402 $renameResult = $chat->Rename($this->
getChatId(), $updateData[
'TITLE']);
406 return $result->addError(
409 'CONFERENCE_RENAMING_ERROR'
414 $this->chatName = $updateData[
'TITLE'];
418 if (isset($updateData[
'NEW_USERS']))
423 $currentUserCount = \CIMChat::getUserCount($this->chatId);
424 $newUserCount = $currentUserCount + count($updateData[
'NEW_USERS']);
425 if (isset($updateData[
'DELETED_USERS']))
427 $newUserCount -= count($updateData[
'DELETED_USERS']);
430 if ($newUserCount > $userLimit)
432 return $result->addError(
440 foreach ($updateData[
'NEW_USERS'] as $newUser)
442 $addingResult = $chat->AddUser($this->
getChatId(), $newUser);
446 return $result->addError(
457 if (isset($updateData[
'DELETED_USERS']))
459 foreach ($updateData[
'DELETED_USERS'] as $deletedUser)
461 $addingResult = $chat->DeleteUser($this->
getChatId(), $deletedUser);
465 return $result->addError(
468 'DELETING_USER_ERROR'
476 if (isset($updateData[
'VIDEOCONF']))
478 if (isset($updateData[
'VIDEOCONF'][
'IS_BROADCAST']))
480 \CIMChat::SetChatParams($this->
getChatId(), [
481 'ENTITY_DATA_1' => $updateData[
'VIDEOCONF'][
'IS_BROADCAST'] ===
'Y'? self::BROADCAST_MODE:
''
485 $updateResult = ConferenceTable::update($updateData[
'ID'], $updateData[
'VIDEOCONF']);
487 if (!$updateResult->isSuccess())
489 return $result->addErrors($updateResult->getErrors());
494 if (isset($updateData[
'NEW_PRESENTERS']) && !empty($updateData[
'NEW_PRESENTERS']))
497 foreach ($updateData[
'NEW_PRESENTERS'] as $newPresenter)
500 $setManagers[$newPresenter] =
true;
502 $chat->SetManagers($this->
getChatId(), $setManagers,
false);
505 if (isset($updateData[
'DELETED_PRESENTERS']) && !empty($updateData[
'DELETED_PRESENTERS']))
507 $removeManagers = [];
508 foreach ($updateData[
'DELETED_PRESENTERS'] as $deletedPresenter)
511 $removeManagers[$deletedPresenter] =
false;
513 $chat->SetManagers($this->
getChatId(), $removeManagers,
false);
517 if (isset($updateData[
'VIDEOCONF'][
'IS_BROADCAST']) && $updateData[
'VIDEOCONF'][
'IS_BROADCAST'] ===
'N')
520 foreach ($presentersList as $presenter)
527 $isPullNeeded = isset($updateData[
'VIDEOCONF'][
'IS_BROADCAST']) || isset($updateData[
'NEW_PRESENTERS']) || isset($updateData[
'DELETED_PRESENTERS']);
528 if ($isPullNeeded && Loader::includeModule(
"pull"))
530 $relations = \CIMChat::GetRelationById($this->
getChatId(),
false,
true,
false);
533 'command' =>
'conferenceUpdate',
536 'isBroadcast' => isset($updateData[
'VIDEOCONF'][
'IS_BROADCAST']) ? $updateData[
'VIDEOCONF'][
'IS_BROADCAST'] ===
'Y' :
'',
539 'extra' => \Bitrix\Im\Common::getPullExtra()
541 \Bitrix\Pull\Event::add(array_keys($relations), $pushMessage);
555 RelationTable::deleteByFilter([
'=CHAT_ID' => $this->
getChatId()]);
559 foreach ($presenters as $presenter)
561 $deleteRolesResult = ConferenceUserRoleTable::delete(
563 'CONFERENCE_ID' => $this->
getId(),
564 'USER_ID' => $presenter
568 if (!$deleteRolesResult->isSuccess())
570 return $result->addErrors($deleteRolesResult->getErrors());
575 $deleteConferenceResult = ConferenceTable::delete($this->
getId());
576 if (!$deleteConferenceResult->isSuccess())
578 return $result->addErrors($deleteConferenceResult->getErrors());
582 $deleteAliasResult = AliasTable::delete($this->
getAliasId());
583 if (!$deleteAliasResult->isSuccess())
585 return $result->addErrors($deleteAliasResult->getErrors());
589 $accessProvider = new \Bitrix\Im\Access\ChatAuthProvider;
590 $accessProvider->deleteChatCodes((
int)$this->
getChatId());
761 $result = new \Bitrix\Im\V2\Result();
763 if (!static::isEnvironmentConfigured()) {
764 return $result->addError(
767 'ENVIRONMENT_CONFIG_ERROR'
772 $validationResult = static::validateFields($fields);
774 if (!$validationResult->isSuccess())
776 return $result->addErrors($validationResult->getErrors());
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:
'';
783 if (isset($fields[
'AUTHOR_ID']))
785 $addData[
'AUTHOR_ID'] = (int)$fields[
'AUTHOR_ID'];
789 $currentUser = \Bitrix\Im\User::getInstance();
790 $addData[
'AUTHOR_ID'] = $currentUser->getId();
794 if (!isset($fields[
'MANAGERS']))
796 $addData[
'MANAGERS'] = [];
797 if ($addData[
'VIDEOCONF'][
'IS_BROADCAST'] ===
'Y')
799 foreach ($addData[
'VIDEOCONF'][
'PRESENTERS'] as $presenter)
801 $addData[
'MANAGERS'][$presenter] =
true;
806 $result->setData([
'FIELDS' => $addData]);
813 $conferenceFields = ConferenceTable::getRow(
815 'select' => self::getDefaultSelectFields(),
816 'runtime' => self::getRuntimeChatField(),
817 'filter' => [
'=ALIAS.ALIAS' =>
$alias,
'=ALIAS.ENTITY_TYPE' => static::ALIAS_TYPE]
821 if (!$conferenceFields)
826 return static::createWithArray($conferenceFields);
831 $conferenceFields = ConferenceTable::getRow(
833 'select' => self::getDefaultSelectFields(),
834 'runtime' => self::getRuntimeChatField(),
835 'filter' => [
'=ID' =>
$id,
'=ALIAS.ENTITY_TYPE' => static::ALIAS_TYPE]
839 if (!$conferenceFields)
844 return static::createWithArray($conferenceFields);
849 $instance =
new static();
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';
863 $instance->users = $instance->
getUsers();