3namespace Bitrix\Im\V2\Chat;
5use Bitrix\Im\Model\ChatTable;
8use Bitrix\Im\V2\Entity\User\User;
9use Bitrix\Im\V2\Relation;
10use Bitrix\Im\V2\Result;
11use Bitrix\Im\V2\Service\Context;
12use Bitrix\Intranet\Settings\CommunicationSettings;
13use Bitrix\Main\Application;
14use Bitrix\Main\Config\Option;
15use Bitrix\Main\Data\Cache;
16use Bitrix\Main\Loader;
17use Bitrix\Main\Localization\Loc;
18use Bitrix\Main\Type\DateTime;
29 private const MESSAGE_COMPONENT_START =
'GeneralChatCreationMessage';
38 return self::IM_TYPE_OPEN;
43 return self::ENTITY_TYPE_GENERAL;
48 if ($this->getId() ===
null || $this->getId() === 0)
53 if ($this->getManageMessages() === Chat::MANAGE_RIGHTS_NONE)
58 $userId ??= $this->getContext()->getUserId();
59 if ($this->getManageMessages() === Chat::MANAGE_RIGHTS_MEMBER)
64 if ($this->getAuthorId() ===
$userId)
69 if ($this->getManageMessages() === Chat::MANAGE_RIGHTS_OWNER)
79 return Option::get(
'im', self::DISABLE_GENERAL_CHAT_OPTION,
'N') ===
'N';
84 $cache = static::getCache(self::MANAGERS_CACHE_ID);
86 $cachedManagerList = $cache->getVars();
88 if ($cachedManagerList !==
false)
90 return $cachedManagerList;
93 $managerList = $this->getRelationFacade()->getManagerOnly()->getUserIds();
95 $cache->startDataCache();
96 $cache->endDataCache($managerList);
105 return parent::changeManagers($userIds, $isManager, $sendPush);
110 if (self::$wasSearched)
112 return self::$instance;
115 $chatId = static::getGeneralChatId();
117 self::$instance = ($chat instanceof
NullChat) ?
null : $chat;
118 self::$wasSearched =
true;
120 return self::$instance;
125 if (!static::isEnable())
130 if (isset(self::$idStaticCache))
132 return self::$idStaticCache;
135 $cache = static::getCache(self::ID_CACHE_ID);
137 $cachedId = $cache->getVars();
139 if ($cachedId !==
false)
141 self::$idStaticCache = $cachedId ?? 0;
143 return self::$idStaticCache;
148 ->where(
'TYPE', Chat::IM_TYPE_OPEN)
149 ->where(
'ENTITY_TYPE', Chat::ENTITY_TYPE_GENERAL)
153 self::$idStaticCache =
$result[
'ID'] ?? 0;
154 $cache->startDataCache();
155 $cache->endDataCache(self::$idStaticCache);
157 return self::$idStaticCache;
162 static::cleanGeneralChatCache(self::MANAGERS_CACHE_ID);
164 return parent::setManagers($managerIds);
174 if (isset(self::$resultFind))
176 return self::$resultFind;
181 $row = ChatTable::query()
182 ->setSelect([
'ID',
'TYPE',
'ENTITY_TYPE',
'ENTITY_ID'])
183 ->where(
'ENTITY_TYPE', self::ENTITY_TYPE_GENERAL)
185 ->setOrder([
'ID' =>
'DESC'])
192 'ID' => (
int)$row[
'ID'],
193 'TYPE' => $row[
'TYPE'],
194 'ENTITY_TYPE' => $row[
'ENTITY_TYPE'],
195 'ENTITY_ID' => $row[
'ENTITY_ID'],
209 if ($generalChatResult->hasResult())
211 $generalChat =
new GeneralChat([
'ID' => $generalChatResult->getResult()[
'ID']]);
213 'CHAT_ID' => $generalChat->getChatId(),
214 'CHAT' => $generalChat,
218 $installUsers = $this->getUsersForInstall();
220 $portalLanguage = self::getPortalLanguage();
223 'TYPE' => self::IM_TYPE_OPEN,
224 'ENTITY_TYPE' => self::ENTITY_TYPE_GENERAL,
226 'TITLE' => Loc::getMessage(
'IM_CHAT_GENERAL_TITLE',
null, $portalLanguage),
227 'DESCRIPTION' => Loc::getMessage(
'IM_CHAT_GENERAL_DESCRIPTION_MSGVER_1',
null, $portalLanguage),
229 'USER_COUNT' =>
count($installUsers),
233 $chat->setExtranet(
false);
236 if (!$chat->getChatId())
242 if (Loader::includeModule(
'bitrix24'))
244 $adminIds = \CBitrix24::getAllAdminId();
247 foreach ($installUsers as
$user)
250 $relation->setChatId($chat->getChatId());
251 $relation->setUserId((
int)
$user[
'ID']);
252 $relation->setManager(in_array((
int)
$user[
'ID'], $adminIds,
true));
253 $relation->setMessageType(self::IM_TYPE_OPEN);
264 'CHAT_ID' => $chat->getChatId(),
270 self::cleanCache($chat->getChatId());
271 $chat->isFilledNonCachedData =
false;
276 private static function getPortalLanguage(): ?string
278 $defSite = CAllSite::GetDefSite();
279 if ($defSite ===
false)
284 $portalData = CAllSite::GetByID($defSite)->Fetch();
287 $languageId = $portalData[
'LANGUAGE_ID'];
288 if ($languageId !==
'')
309 if (Loader::includeModule(
'pull'))
311 \CPullStack::AddShared([
313 'command' =>
'generalChatId',
335 if (Loader::includeModule(
'pull'))
337 \CPullStack::AddShared([
339 'command' =>
'generalChatId',
347 static::cleanGeneralChatCache(self::ID_CACHE_ID);
348 static::cleanGeneralChatCache(self::MANAGERS_CACHE_ID);
357 || !self::getGeneralChatId()
358 || !Loader::includeModule(
'intranet')
369 INNER JOIN b_user_field F ON F.ENTITY_ID = 'USER' AND F.FIELD_NAME = 'UF_DEPARTMENT'
370 INNER JOIN b_utm_user UF ON
372 AND UF.VALUE_ID = U.ID
377 AND F.ENTITY_ID = 'USER'
378 AND F.FIELD_NAME = 'UF_DEPARTMENT'
389 private function getUsersForInstall():
array
392 $types = implode(
"', '", $externalUserTypes);
393 if (Loader::includeModule(
'intranet'))
399 INNER JOIN b_user_field F ON F.ENTITY_ID = 'USER' AND F.FIELD_NAME = 'UF_DEPARTMENT'
400 INNER JOIN b_utm_user UF ON
402 AND UF.VALUE_ID = U.ID
406 AND (U.EXTERNAL_AUTH_ID IS NULL OR U.EXTERNAL_AUTH_ID NOT IN ('{$types}') )
407 AND F.ENTITY_ID = 'USER'
408 AND F.FIELD_NAME = 'UF_DEPARTMENT'
418 AND (U.EXTERNAL_AUTH_ID IS NULL OR U.EXTERNAL_AUTH_ID NOT IN ('{$types}') )
429 'MESSAGE_TYPE' => self::IM_TYPE_CHAT,
430 'TO_CHAT_ID' => $this->getChatId(),
432 'MESSAGE' => Loc::getMessage(
'IM_CHAT_GENERAL_CREATE_WELCOME',
null, self::getPortalLanguage()),
436 'COMPONENT_ID' => self::MESSAGE_COMPONENT_START,
439 'SKIP_COUNTER_INCREMENTS' =>
'Y',
447 case self::GENERAL_MESSAGE_TYPE_JOIN:
448 return (
bool)\COption::GetOptionString(
"im",
"general_chat_message_join");
449 case self::GENERAL_MESSAGE_TYPE_LEAVE:
450 return (
bool)\COption::GetOptionString(
"im",
"general_chat_message_leave");
458 $result[
'generalChatCanPostList'] = self::getCanPostList();
459 $result[
'generalChatCanPost'] = $this->getManageMessages();
460 $result[
'generalChatShowManagersList'] = self::MANAGE_RIGHTS_MANAGERS;
461 $managerIds = $this->getRelationFacade()->getManagerOnly()->getUserIds();
462 $managers = array_map(
function ($managerId) {
463 return 'U' . $managerId;
465 Loader::includeModule(
'intranet');
466 if (method_exists(
'\Bitrix\Intranet\Settings\CommunicationSettings',
'processOldAccessCodes'))
468 $result[
'generalChatManagersList'] = CommunicationSettings::processOldAccessCodes($managers);
472 $result[
'generalChatManagersList'] = \IntranetConfigsComponent::processOldAccessCodes($managers);
480 $accessCodes = parent::getAccessCodesForDiskFolder();
485 $driver = \Bitrix\Disk\Driver::getInstance();
486 $rightsManager = $driver->getRightsManager();
488 'ACCESS_CODE' => $departmentCode,
489 'TASK_ID' => $rightsManager->getTaskIdByName($rightsManager::TASK_READ)
504 return $generalChat->deleteChat();
509 if ($this->getContext()->getUserId() > 0)
511 parent::sendMessageUsersAdd($usersToAdd,
$config);
516 if (!self::getAutoMessageStatus(self::GENERAL_MESSAGE_TYPE_JOIN))
522 foreach ($usersToAdd as
$userId)
524 $userCodes[] =
"[USER={$userId}][/USER]";
526 $userCodesString = implode(
', ', $userCodes);
528 if (
count($usersToAdd) > 1)
530 $messageText = Loc::getMessage(
"IM_CHAT_GENERAL_JOIN_PLURAL", [
'#USER_NAME#' => $userCodesString]);
535 $genderModifier =
$user->getGender() ===
'F' ?
'_F' :
'';
536 $messageText = Loc::getMessage(
'IM_CHAT_GENERAL_JOIN' . $genderModifier, [
'#USER_NAME#' => $userCodesString]);
539 \CIMChat::AddMessage([
540 "TO_CHAT_ID" => $this->getId(),
541 "MESSAGE" => $messageText,
542 "FROM_USER_ID" => $this->getContext(),
544 "RECENT_ADD" =>
$config->skipRecent ?
'N' :
'Y',
546 "CODE" =>
'CHAT_JOIN',
547 "NOTIFY" => $this->getEntityType() === self::ENTITY_TYPE_LINE?
'Y':
'N',
550 "SKIP_USER_CHECK" =>
'Y',
556 if (!self::getAutoMessageStatus(self::GENERAL_MESSAGE_TYPE_LEAVE))
568 return Loc::getMessage(
569 "IM_CHAT_GENERAL_LEAVE_{$user->getGender()}",
576 if (!Loader::includeModule(
'im'))
586 $portalLanguage = self::getPortalLanguage();
588 ChatTable::update($chatId, [
589 'TITLE' => Loc::getMessage(
'IM_CHAT_GENERAL_TITLE',
null, $portalLanguage),
590 'DESCRIPTION' => Loc::getMessage(
'IM_CHAT_GENERAL_DESCRIPTION_MSGVER_1',
null, $portalLanguage),
599 $result = parent::updateStateAfterRelationsAdd($usersToAdd);
613 $cacheTTL = 18144000;
614 $cacheDir = static::getCacheDir();
615 $cache->initCache($cacheTTL, $cacheId, $cacheDir);
620 private static function getCacheDir(): string
622 return '/bx/imc/general_chat';
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
static raiseChat(\Bitrix\Im\V2\Chat $chat, RelationCollection $relations, ?DateTime $lastActivity=null)
getRightsForIntranetConfig()
static cleanGeneralChatCache(string $cacheId)
sendMessageUsersAdd(array $usersToAdd, Relation\AddUsersConfig $config)
updateStateAfterRelationsAdd(array $usersToAdd)
add(array $params, ?Context $context=null)
hasManageMessagesAccess(?int $userId=null)
const GENERAL_MESSAGE_TYPE_JOIN
sendBanner(?int $authorId=null)
static getGeneralChatId()
getUserDeleteMessageText(int $deletedUserId)
changeManagers(array $userIds, bool $isManager, bool $sendPush=true)
static getAutoMessageStatus(string $type)
static find(array $params=[], ?Context $context=null)
getAccessCodesForDiskFolder()
const DISABLE_GENERAL_CHAT_OPTION
const GENERAL_MESSAGE_TYPE_LEAVE
sendMessageUserDelete(int $userId, Relation\DeleteUserConfig $config)
disableUserDeleteMessage(bool $skipRecent=false)
getManagerList(bool $fullList=true)
canJoinGeneralChat(int $userId)
setManagers(array $managerIds)
static linkGeneralChat(?int $chatId=null)
static deleteGeneralChat()
static unlinkGeneralChat()
static Result $resultFind
static int $idStaticCache
static getConnection($name="")
fetch(\Bitrix\Main\Text\Converter $converter=null)
static getExternalUserTypes()
static GetTopDepartmentCode()
getCache(string $moduleID)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
htmlspecialcharsback($str)
</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."%"
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']