3namespace Bitrix\Im\V2\Chat;
5use Bitrix\HumanResources\Repository\StructureRepository;
6use Bitrix\Im\Model\ChatTable;
8use Bitrix\Im\V2\Entity\User\User;
9use Bitrix\Im\V2\Integration\HumanResources\Structure;
10use Bitrix\Im\V2\Relation\AddUsersConfig;
11use Bitrix\Im\V2\Relation\Reason;
12use Bitrix\Im\V2\Result;
13use Bitrix\Im\V2\Service\Context;
14use Bitrix\Intranet\Settings\CommunicationSettings;
15use Bitrix\Main\Application;
16use Bitrix\Main\Data\Cache;
17use Bitrix\Main\Loader;
18use Bitrix\Main\Localization\Loc;
25 private const MESSAGE_COMPONENT_START =
'GeneralChannelCreationMessage';
33 return self::ENTITY_TYPE_GENERAL_CHANNEL;
38 return self::MANAGE_RIGHTS_MEMBER;
43 if (self::$wasSearched)
45 return self::$instance;
50 self::$instance = ($chat instanceof
NullChat) ?
null : $chat;
51 self::$wasSearched =
true;
53 return self::$instance;
58 if (isset(self::$idStaticCache))
60 return self::$idStaticCache;
63 $cache = static::getCache(self::ID_CACHE_ID);
65 $cachedId = $cache->getVars();
67 if ($cachedId !==
false)
69 self::$idStaticCache = $cachedId ?? 0;
71 return self::$idStaticCache;
76 ->where(
'TYPE', self::IM_TYPE_OPEN_CHANNEL)
77 ->where(
'ENTITY_TYPE', self::ENTITY_TYPE_GENERAL_CHANNEL)
81 self::$idStaticCache =
$result[
'ID'] ?? 0;
82 $cache->startDataCache();
83 $cache->endDataCache(self::$idStaticCache);
85 return self::$idStaticCache;
92 ->where(
'ENTITY_TYPE', self::ENTITY_TYPE_GENERAL_CHANNEL)
110 if ($generalChannel instanceof
self)
113 'CHAT_ID' => $generalChannel->getChatId(),
114 'CHAT' => $generalChannel,
118 $portalLanguage = self::getPortalLanguage();
121 'TYPE' => self::IM_TYPE_OPEN_CHANNEL,
122 'ENTITY_TYPE' => self::ENTITY_TYPE_GENERAL_CHANNEL,
124 'TITLE' => Loc::getMessage(
'IM_CHAT_GENERAL_CHANNEL_TITLE',
null, $portalLanguage),
125 'DESCRIPTION' => Loc::getMessage(
'IM_CHAT_GENERAL_CHANNEL_DESCRIPTION',
null, $portalLanguage),
136 private static function getPortalLanguage(): ?string
138 $defSite = CAllSite::GetDefSite();
139 if ($defSite ===
false)
144 $portalData = CAllSite::GetByID($defSite)->Fetch();
147 $languageId = $portalData[
'LANGUAGE_ID'];
148 if ($languageId !==
'')
164 if (
$user->isAdmin())
166 $managerIds[] =
$user->getId();
171 if (isset($generalChat))
173 foreach ($generalChat->getManagerList() as
$manager)
175 if (in_array((
int)
$manager, $userIds,
true))
182 $managerIds = array_unique($managerIds);
185 return parent::addUsers($userIds,
$config);
195 if (!\
Bitrix\
Main\Loader::includeModule(
'humanresources'))
200 $structure = (
new StructureRepository())->getByXmlId(\
Bitrix\HumanResources\Item\Structure::DEFAULT_STRUCTURE_XML_ID);
201 if (!isset($structure))
206 $rootNode = (new \Bitrix\HumanResources\Repository\NodeRepository())->getRootNodeByStructureId($structure->id);
207 if (!isset($rootNode))
212 $accessCode = $rootNode->accessCode;
213 preg_match(
'/D(\d+)/', $accessCode ??
'',
$matches);
221 'MESSAGE_TYPE' => self::IM_TYPE_OPEN_CHANNEL,
222 'TO_CHAT_ID' => $this->getChatId(),
224 'MESSAGE' => Loc::getMessage(
'IM_CHAT_GENERAL_CHANNEL_CREATE_WELCOME',
null, self::getPortalLanguage()),
228 'COMPONENT_ID' => self::MESSAGE_COMPONENT_START,
231 'SKIP_COUNTER_INCREMENTS' =>
'Y',
258 $structureNodes = Structure::splitEntities([[
'department', $chat->getCompanyStructureId()]]);
259 $chat->unlinkStructureNodes($structureNodes[1] ?? []);
269 (
new self())->
add([]);
274 if (self::get() !==
null)
279 if (!Structure::isSyncAvailable())
281 return "\\" . __METHOD__ .
'();';
291 if (!Loader::includeModule(
'im'))
301 $portalLanguage = self::getPortalLanguage();
303 ChatTable::update($chatId, [
304 'TITLE' => Loc::getMessage(
'IM_CHAT_GENERAL_CHANNEL_TITLE',
null, $portalLanguage),
305 'DESCRIPTION' => Loc::getMessage(
'IM_CHAT_GENERAL_CHANNEL_DESCRIPTION',
null, $portalLanguage),
314 $result[
'generalChannelCanPostList'] = self::getCanPostList();
315 $result[
'generalChannelCanPost'] = $this->getManageMessages();
316 $result[
'generalChannelShowManagersList'] = self::MANAGE_RIGHTS_MANAGERS;
317 $managerIds = $this->getRelationFacade()->getManagerOnly()->getUserIds();
318 $managers = array_map(
function ($managerId) {
319 return 'U' . $managerId;
322 if (!Loader::includeModule(
'intranet'))
327 if (method_exists(
'\Bitrix\Intranet\Settings\CommunicationSettings',
'processOldAccessCodes'))
329 $result[
'generalChannelManagersList'] = CommunicationSettings::processOldAccessCodes($managers);
333 $result[
'generalChannelManagersList'] = \IntranetConfigsComponent::processOldAccessCodes($managers);
342 $cacheTTL = 18144000;
343 $cacheDir = static::getCacheDir();
344 $cache->initCache($cacheTTL, $cacheId, $cacheDir);
349 private static function getCacheDir(): string
351 return '/bx/imc/general_channel';
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
needToSendGreetingMessages()
getRightsForIntranetConfig()
sendMessageUsersAdd(array $usersToAdd, AddUsersConfig $config)
add(array $params, ?Context $context=null)
static cleanGeneralChannelCache(string $cacheId)
getGeneralChannelIdWithoutCache()
sendBanner(?int $authorId=null)
addUsers(array $userIds, AddUsersConfig $config=new AddUsersConfig())
static getGeneralChannelId()
sendDescriptionMessage(?int $authorId=null)
sendGreetingMessage(?int $authorId=null)
getDefaultManageMessages()
static installGeneralChannel()
static deleteGeneralChannel()
static int $idStaticCache
getCache(string $moduleID)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']