3namespace Bitrix\Im\V2\Entity\User;
6use Bitrix\Im\Integration\Socialnetwork\Extranet;
7use Bitrix\Im\Model\RelationTable;
8use Bitrix\Im\Model\StatusTable;
9use Bitrix\Im\V2\Chat\ChatError;
10use Bitrix\Im\V2\Chat\FavoriteChat;
11use Bitrix\Im\V2\Chat\PrivateChat;
12use Bitrix\Im\V2\Common\ContextCustomer;
13use Bitrix\Im\V2\Entity\Department\Departments;
14use Bitrix\Im\V2\Rest\RestEntity;
15use Bitrix\Im\V2\Result;
16use Bitrix\Im\V2\Service\Locator;
17use Bitrix\Main\Engine\Response\Converter;
18use Bitrix\Main\Loader;
19use Bitrix\Main\ModuleManager;
20use Bitrix\Main\ORM\Fields\Relations\Reference;
21use Bitrix\Main\ORM\Query\Join;
22use Bitrix\Main\SystemException;
23use Bitrix\Main\Type\DateTime;
24use Bitrix\Main\UserTable;
36 'IDLE' =>
'STATUS.IDLE',
37 'DESKTOP_LAST_DATE' =>
'STATUS.DESKTOP_LAST_DATE',
38 'MOBILE_LAST_DATE' =>
'STATUS.MOBILE_LAST_DATE',
53 protected static string $loader = Loader::class;
79 if (isset(self::$userStaticCache[$id]))
81 return self::$userStaticCache[$id];
86 return self::$userStaticCache[$id];
91 return Locator::getContext()->getUser();
101 $user =
new static();
126 $result = RelationTable::query()
127 ->setSelect([
'CHAT_ID'])
128 ->registerRuntimeField(
132 RelationTable::class,
133 Join::on(
'this.CHAT_ID',
'ref.CHAT_ID'),
134 [
'join_type' => Join::TYPE_INNER]
136 )->where(
'USER_ID', $this->
getId())
137 ->where(
'SELF.USER_ID', $userId)
144 $chatId = (int)
$result[
'CHAT_ID'];
148 if ($chatId !==
false)
150 $chat = PrivateChat::getInstance($chatId);
160 if (!$createIfNotExist)
167 $createResult = (
new PrivateChat())->add([
'FROM_USER_ID' => $this->
getId(),
'TO_USER_ID' => $userId]);
174 if (!$createResult->isSuccess())
179 return $createResult->getResult()[
'CHAT'];
185 $idOtherUser ??= Locator::getContext()->getUserId();
188 if (!$otherUser->isExist())
193 if ($this->
getId() === $idOtherUser)
198 if (isset($this->accessCache[$idOtherUser]))
200 return $this->accessCache[$idOtherUser];
205 return $this->accessCache[$idOtherUser];
212 if (!static::$moduleManager::isModuleInstalled(
'intranet'))
222 if ($otherUser->isExtranet())
243 $isContactPrivacy = (
250 && static::$loader::includeModule(
'socialnetwork')
251 && \CSocNetUser::IsFriendsAllowed()
259 || $this->isOnlineDataWithStatusFilled)
264 $select = $withStatus ? self::ONLINE_DATA_SELECTED_FIELDS : self::ONLINE_DATA_SELECTED_FIELDS_WITHOUT_STATUS;
265 $query = UserTable::query()
267 ->where(
'ID', $this->
getId())
271 $query->registerRuntimeField(
275 Join::on(
'this.ID',
'ref.USER_ID'),
276 [
'join_type' => Join::TYPE_LEFT]
281 $statusData =
$query->fetch() ?: [];
288 $this->isOnlineDataWithStatusFilled =
false;
293 return isset($this->userData[
'ID']) ? (int)$this->userData[
'ID'] :
null;
303 if (isset(
$option[
'USER_SHORT_FORMAT']) &&
$option[
'USER_SHORT_FORMAT'] ===
true)
306 'id' => $this->
getId(),
310 'type' => $this->
getType()->value,
319 if (!isset(
$option[
'WITHOUT_ONLINE']) ||
$option[
'WITHOUT_ONLINE'] ===
false)
328 'id' => $this->
getId(),
341 'bot' => $this->
isBot(),
353 'type' => $this->
getType()->value,
362 $converter =
new Converter(Converter::TO_SNAKE | Converter::TO_UPPER | Converter::KEYS);
367 $converter =
new Converter(Converter::TO_LOWER | Converter::KEYS);
372 $converter =
new Converter(Converter::TO_SNAKE | Converter::TO_LOWER | Converter::KEYS);
376 if ((
$option[
'JSON'] ??
'N') ===
'Y')
388 return $this->
getId() !==
null;
393 $this->idle = $onlineData[
'IDLE'] ??
null;
394 $this->lastActivityDate = $onlineData[
'LAST_ACTIVITY_DATE'] ??
null;
395 $this->mobileLastDate = $onlineData[
'MOBILE_LAST_DATE'] ??
null;
396 $this->desktopLastDate = $onlineData[
'DESKTOP_LAST_DATE'] ??
null;
399 $this->isOnlineDataWithStatusFilled =
true;
409 return $this->userData[
'NAME'] ??
null;
414 return $this->userData[
'FIRST_NAME'] ??
null;
419 return $this->userData[
'LAST_NAME'] ??
null;
424 $avatar = $this->userData[
'AVATAR'] ??
'';
426 return $forRest ? $this->prependPublicDomain($avatar) : $avatar;
431 $avatarHr = $this->userData[
'AVATAR_HR'] ??
'';
433 return $forRest ? $this->prependPublicDomain($avatarHr) : $avatarHr;
438 return $this->userData[
'BIRTHDAY'] ??
'';
443 return $this->userData[
'AVATAR_ID'] ?? 0;
448 return $this->userData[
'WORK_POSITION'] ??
null;
453 return $this->userData[
'PERSONAL_GENDER'] ===
'F' ?
'F' :
'M';
458 return $this->userData[
'EXTERNAL_AUTH_ID'] ??
'default';
468 return $this->userData[
'PERSONAL_WWW'] ??
'';
473 return $this->userData[
'EMAIL'] ??
'';
480 foreach ([self::PHONE_MOBILE, self::PHONE_WORK, self::PHONE_INNER, self::PERSONAL_PHONE] as $phoneType)
482 if (isset($this->userData[$phoneType]) && $this->userData[$phoneType])
484 $result[mb_strtolower($phoneType)] = $this->userData[$phoneType];
495 if (isset($this->userData[
'UF_ZOOM']) && !empty($this->userData[
'UF_ZOOM']))
497 $result[
'zoom'] = $this->userData[
'UF_ZOOM'];
500 if (isset($this->userData[
'UF_SKYPE_LINK']) && !empty($this->userData[
'UF_SKYPE_LINK']))
502 $result[
'skype'] = $this->userData[
'UF_SKYPE_LINK'];
504 elseif (isset($this->userData[
'UF_SKYPE']) && !empty($this->userData[
'UF_SKYPE']))
506 $result[
'skype'] =
'skype://' . $this->userData[
'UF_SKYPE'];
518 return Loader::includeModule(
'voximplant') && $this->userData[
'UF_VI_PHONE'] ===
'Y';
523 return $this->userData[
'COLOR'] ??
'';
528 return $this->userData[
'LANGUAGE_ID'] ??
null;
533 return $this->userData[
'IS_EXTRANET'] ??
false;
543 return $this->userData[
'ACTIVE'] ===
'Y';
548 return $this->userData[
'ABSENT'] ??
null;
553 return $this->userData[
'IS_NETWORK'] ??
false;
558 return $this->userData[
'IS_BOT'] ??
false;
563 return $this->userData[
'IS_CONNECTOR'] ??
false;
569 (isset($this->userData[
'UF_DEPARTMENT']) && is_array($this->userData[
'UF_DEPARTMENT']))
570 ? $this->userData[
'UF_DEPARTMENT']
582 return $withStatus ? $this->isOnlineDataWithStatusFilled : $this->isOnlineDataWithStatusFilled ||
$this->isOnlineDataFilled;
589 return $this->userData[
'STATUS'] ??
'online';
597 return $this->userData[
'TIME_ZONE'] ??
'';
639 return UserType::USER;
650 if (Loader::includeModule(
'bitrix24'))
653 $USER instanceof \CUser
654 &&
$USER->isAuthorized()
656 && (
int)
$USER->getId() === $this->getId()
663 $this->
isAdmin = \CBitrix24::isPortalAdmin($this->
getId());
669 $USER instanceof \CUser
670 &&
$USER->isAuthorized()
671 && (
int)
$USER->getId() === $this->getId()
683 if ((
int)$groupId === 1)
697 if (!Loader::includeModule(
'socialnetwork') || (
int)
$USER->getId() !== $this->getId())
702 return $this->
isAdmin() && \CSocNetUser::IsEnabledModuleAdmin();
707 private function prependPublicDomain(
string $url): string
709 if (
$url !==
'' && mb_strpos(
$url,
'http') !== 0)
721 if (Loader::includeModule(
'bitrix24'))
723 $adminIds = \CBitrix24::getAllAdminId();
727 $res = \CGroup::getGroupUserEx(1);
728 while ($row =
$res->fetch())
730 $adminIds[] = (int)$row[
"USER_ID"];
734 $resultAdminIds = [];
735 foreach ($adminIds as $adminId)
738 if (!
$user->isExtranet() &&
$user->isActive())
740 $resultAdminIds[] = (int)$adminId;
744 return !empty($resultAdminIds) ? (int)min($resultAdminIds) : 0;
749 unset(self::$userStaticCache[$id]);
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
static formatLegacyJson(array $result)
static find(array $params=[], ?Context $context=null)
static getRestEntityName()
getIdle(bool $real=false)
DateTime $lastActivityDate
hasAccessBySocialNetwork(int $idOtherUser)
toRestFormat(array $option=[])
getAvatarHr(bool $forRest=true)
static initByArray(array $userData)
isOnlineDataFilled(bool $withStatus)
const ONLINE_DATA_SELECTED_FIELDS_WITHOUT_STATUS
checkAccessInternal(self $otherUser)
setOnlineData(array $onlineData, bool $withStatus)
getAvatar(bool $forRest=true)
static getInstance(?int $id)
getChatWith(int $userId, bool $createIfNotExist=true)
static array $userStaticCache
getDesktopLastDate(bool $real=false)
DateTime $desktopLastDate
static clearStaticCache(int $id)
bool $isOnlineDataWithStatusFilled
getStatus(bool $real=false)
const ONLINE_DATA_SELECTED_FIELDS
getMobileLastDate(bool $real=false)
fillOnlineData(bool $withStatus=false)
checkAccess(?int $idOtherUser=null)
static string $moduleManager
getArray(array $option=[])
static IsFriends($firstUserID, $secondUserID)
const PRIVACY_RESULT_CONTACT
static GetPrivacy($type, $userId=false)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)