23 return \Bitrix\Intranet\Invitation::canListDelete();
32 $userId = (int)$event->getParameter(
'userId');
34 return self::sendMessageToGeneralChat($userId, [
36 '#USER_NAME#' => self::getUserBlock($userId)
49 $originatorId = (int)$event->getParameter(
'originatorId');
50 $users = (array)$event->getParameter(
'userId');
52 if (!self::isEmployee($originatorId))
58 $result = \Bitrix\Intranet\UserTable::getList([
62 'select' => [
'ID',
'USER_TYPE',
'EMAIL']
65 while ($row = $result->fetch())
67 if ($row[
'USER_TYPE'] ===
'employee')
72 'originator_id' => $originatorId,
73 'can_resend' => !empty($row[
'EMAIL'])
79 if (empty($userForSend))
84 self::sendInviteEvent($userForSend);
86 $userForSend = array_map(
function($user) {
87 return self::getUserBlock($user[
'ID']);
90 return self::sendMessageToGeneralChat($originatorId, [
92 '#USER_NAME#' => self::getUserBlock($originatorId),
93 '#USERS#' => implode(
', ', $userForSend)
107 $originatorId = (int)$event->getParameter(
'originatorId');
108 $users = (array)$event->getParameter(
'userId');
110 if (!self::isEmployee($originatorId))
116 $result = \Bitrix\Intranet\UserTable::getList([
120 'select' => [
'ID',
'USER_TYPE',
'EMAIL']
123 while ($row = $result->fetch())
125 if ($row[
'USER_TYPE'] ===
'employee')
130 'originator_id' => $originatorId,
131 'can_resend' => !empty($row[
'EMAIL'])
137 self::sendInviteEvent($userForSend);
139 $users = array_map(
function($userId) {
140 return self::getUserBlock($userId);
143 return self::sendMessageToGeneralChat($originatorId, [
145 '#USER_NAME#' => self::getUserBlock($originatorId),
146 '#USERS#' => implode(
', ', $users)
160 if (!\COption::GetOptionString(
"im",
"general_chat_message_admin_rights",
true))
165 $originatorId = (int)$event->getParameter(
'originatorId');
166 $users = (array)$event->getParameter(
'userId');
167 $type = (string)$event->getParameter(
'type');
169 $users = array_map(
function($userId) {
170 return self::getUserBlock($userId);
173 $originatorGender =
'M';
174 if ($originatorId > 0)
176 $dbUser = \CUser::GetList(
'',
'', [
'ID_EQUAL_EXACT' => $originatorId], array(
'FIELDS' => [
'PERSONAL_GENDER']));
177 if ($user = $dbUser->Fetch())
179 $originatorGender = $user[
"PERSONAL_GENDER"] ==
'F'?
'F':
'M';
184 $type ===
'setAdminRigths'
185 ?
'IM_INT_USR_SET_ADMIN_RIGTHS_'.$originatorGender
186 :
'IM_INT_USR_REMOVE_ADMIN_RIGTHS_'.$originatorGender
189 return self::sendMessageToGeneralChat($originatorId, [
191 '#USER_NAME#' => self::getUserBlock($originatorId),
192 '#USERS#' => implode(
', ', $users)
206 $userId = (int)$params[
'ID'];
208 if (!self::isEmployee($userId))
213 \CIMContactList::SetRecent([
'ENTITY_ID' => $userId]);
225 $userData = $params[
'user_fields'];
227 if (in_array($userData[
'EXTERNAL_AUTH_ID'], \
Bitrix\Main\UserTable::getExternalUserTypes()))
232 if ($userData[
'LAST_LOGIN'])
237 $userId = (int)$userData[
'ID'];
238 if ($userData[
'LAST_ACTIVITY_DATE'])
243 if (!self::isEmployee($userId))
248 \CUser::SetLastActivityDate($userId);
250 \CIMContactList::SetRecent(Array(
'ENTITY_ID' => $userId));
252 if (self::isCountOfUsersExceededForPersonalNotify())
254 if (!\CIMChat::GetGeneralChatAutoMessageStatus(\CIMChat::GENERAL_MESSAGE_TYPE_JOIN))
259 return self::sendMessageToGeneralChat($userId, [
262 "CODE" =>
'USER_JOIN_GENERAL',
267 self::sendInviteEvent([[
272 $orm = \Bitrix\Main\UserTable::getList([
276 '=IS_REAL_USER' =>
'Y',
277 '!=UF_DEPARTMENT' =>
false
280 while($row = $orm->fetch())
282 if ($row[
'ID'] == $userId)
287 $viewCommonUsers = (bool)\CIMSettings::GetSetting(\CIMSettings::SETTINGS,
'viewCommonUsers', $row[
'ID']);
288 if (!$viewCommonUsers)
294 "TO_USER_ID" => $row[
'ID'],
295 "FROM_USER_ID" => $userId,
298 "RECENT_SKIP_AUTHOR" =>
'Y',
299 "MESSAGE_OUT" => IM_MAIL_SKIP,
301 "CODE" =>
'USER_JOIN',
309 private static function sendInviteEvent(array $users): bool
311 if (!\
Bitrix\Main\Loader::includeModule(
'pull'))
321 $onlineUsers = \Bitrix\Im\Helper::getOnlineIntranetUsers();
322 foreach ($users as $user)
324 \Bitrix\Pull\Event::add($onlineUsers, [
326 'command' =>
'userInvite',
329 'userId' => $user[
'ID'],
330 'invited' => $user[
'INVITED'],
341 private static function sendMessageToGeneralChat(
int $fromUserId, array $params): bool
343 $chatId = \CIMChat::GetGeneralChatId();
347 $params = array_merge($params, [
348 "TO_CHAT_ID" => $chatId,
349 "FROM_USER_ID" => $fromUserId,
350 "MESSAGE_OUT" => IM_MAIL_SKIP,
351 "SKIP_USER_CHECK" =>
'Y',
354 $result = \CIMChat::AddMessage($params);
356 return $result !==
false;
359 private static function getUserBlock(
int $userId): string
361 return '[USER='.$userId.
'][/USER]';
364 private static function isEmployee(
int $userId): bool
366 if (isset(self::$isEmployee[$userId]))
368 return self::$isEmployee[
$userId];
371 if (!\
Bitrix\Main\Loader::includeModule(
'intranet'))
376 $result = \Bitrix\Intranet\UserTable::getList([
380 'select' => [
'ID',
'USER_TYPE']
384 self::$isEmployee[
$userId] = $result[
'USER_TYPE'] ===
'employee';
386 return self::$isEmployee[
$userId];
396 $option = Option::get(
'im',
'contact_list_birthday');
404 $today = (
new DateTime())->format(
'm-d');
405 if ($option ===
'department')
407 $cacheId =
'birthday_'.$today.
'_'.$USER->GetID();
411 $cacheId =
'birthday_'.$today;
414 $cache = \Bitrix\Main\Data\Cache::createInstance();
415 if($cache->initCache(86400, $cacheId,
'/bx/im/birthday/'))
417 return $cache->getVars();
420 $user = \CUser::getById($USER->GetId())->Fetch();
424 '=BIRTHDAY_DATE' => $today,
425 '=IS_REAL_USER' =>
true,
427 if ($option ===
'department')
429 $filter[
'=UF_DEPARTMENT'] = $user[
'UF_DEPARTMENT'];
433 $filter[
'!=UF_DEPARTMENT'] =
false;
436 $connection = \Bitrix\Main\Application::getConnection();
437 $helper = $connection->getSqlHelper();
440 $users = UserTable::getList([
444 new ExpressionField(
'BIRTHDAY_DATE', str_replace(
'PERSONAL_BIRTHDAY',
'%s', str_replace(
'%',
'%%', $helper->formatDate(
'MM-DD',
'PERSONAL_BIRTHDAY'))),
'PERSONAL_BIRTHDAY')
449 foreach ($users as $user)
451 $result[] = \Bitrix\Im\User::getInstance($user[
'ID'])->getArray([
'SKIP_ONLINE' =>
'Y',
'JSON' =>
'Y']);
454 $cache->forceRewriting(
true);
455 $cache->startDataCache();
456 $cache->endDataCache($result);
461 private static function isCountOfUsersExceededForPersonalNotify(): bool
463 $count = UserTable::query()
465 ->where(
'ACTIVE',
true)
466 ->where(
'IS_REAL_USER',
true)
467 ->whereNotNull(
'LAST_LOGIN')
468 ->setLimit(self::INVITE_MAX_USER_NOTIFY + 1)
478 $eventManager = \Bitrix\Main\EventManager::getInstance();
479 $eventManager->registerEventHandlerCompatible(
'main',
'OnAfterUserAuthorize',
'im', self::class,
'onInviteAccepted');
480 $eventManager->registerEventHandlerCompatible(
'intranet',
'OnRegisterUser',
'im', self::class,
'onInviteSend');
481 $eventManager->registerEventHandler(
'intranet',
'OnCopyRegisterUrl',
'im', self::class,
'onInviteLinkCopied');
482 $eventManager->registerEventHandler(
'intranet',
'onUserInvited',
'im', self::class,
'onUserInvited');
483 $eventManager->registerEventHandler(
'intranet',
'onUserAdded',
'im', self::class,
'onUserAdded');
484 $eventManager->registerEventHandler(
'intranet',
'onUserAdminRights',
'im', self::class,
'onUserAdminRights');
489 $eventManager = \Bitrix\Main\EventManager::getInstance();
490 $eventManager->unRegisterEventHandler(
'main',
'OnAfterUserAuthorize',
'im', self::class,
'onInviteAccepted');
491 $eventManager->unRegisterEventHandler(
'intranet',
'OnRegisterUser',
'im', self::class,
'onInviteSend');
492 $eventManager->unRegisterEventHandler(
'intranet',
'OnCopyRegisterUrl',
'im', self::class,
'onInviteLinkCopied');
493 $eventManager->unRegisterEventHandler(
'intranet',
'onUserInvited',
'im', self::class,
'onUserInvited');
494 $eventManager->unRegisterEventHandler(
'intranet',
'onUserAdded',
'im', self::class,
'onUserAdded');
495 $eventManager->unRegisterEventHandler(
'intranet',
'onUserAdminRights',
'im', self::class,
'onUserAdminRights');
static getMessage($code, $replace=null, $language=null)
static isModuleInstalled($moduleName)