10use Bitrix\Im\V2\Common\ContextCustomer;
32 'IDLE' =>
'STATUS.IDLE',
33 'DESKTOP_LAST_DATE' =>
'STATUS.DESKTOP_LAST_DATE',
34 'MOBILE_LAST_DATE' =>
'STATUS.MOBILE_LAST_DATE',
49 protected static string $loader = Loader::class;
75 if (isset(self::$userStaticCache[$id]))
77 return self::$userStaticCache[$id];
82 return self::$userStaticCache[$id];
87 return Locator::getContext()->getUser();
112 if ($userId === $this->
getId())
115 if ($result && isset($result[
'ID']))
117 $chatId = (int)$result[
'ID'];
122 $result = RelationTable::query()
123 ->setSelect([
'CHAT_ID'])
124 ->registerRuntimeField(
128 RelationTable::class,
129 Join::on(
'this.CHAT_ID',
'ref.CHAT_ID'),
130 [
'join_type' => Join::TYPE_INNER]
132 )->where(
'USER_ID', $this->
getId())
133 ->where(
'SELF.USER_ID', $userId)
134 ->where(
'MESSAGE_TYPE', \IM_MESSAGE_PRIVATE)
138 if ($result && isset($result[
'CHAT_ID']))
140 $chatId = (int)$result[
'CHAT_ID'];
144 if ($chatId !==
false)
146 $chat = PrivateChat::getInstance($chatId);
156 if (!$createIfNotExist)
163 $createResult = (
new PrivateChat())->add([
'FROM_USER_ID' => $this->
getId(),
'TO_USER_ID' => $userId]);
170 if (!$createResult->isSuccess())
175 return $createResult->getResult()[
'CHAT'];
178 final public function hasAccess(?
int $idOtherUser =
null): bool
180 $idOtherUser = $idOtherUser ?? Locator::getContext()->getUserId();
184 if (!$otherUser->isExist())
189 if ($this->
getId() === $idOtherUser)
194 if (isset($this->accessCache[$idOtherUser]))
196 return $this->accessCache[$idOtherUser];
201 return $this->accessCache[$idOtherUser];
206 if (!static::$moduleManager::isModuleInstalled(
'intranet'))
211 if ($otherUser->isExtranet())
213 $inGroup = \Bitrix\Im\Integration\Socialnetwork\Extranet::isUserInGroup($this->
getId(), $otherUser->getId());
232 $isContactPrivacy = (
233 \CIMSettings::GetPrivacy(\CIMSettings::PRIVACY_MESSAGE) === \CIMSettings::PRIVACY_RESULT_CONTACT
234 || \CIMSettings::GetPrivacy(\CIMSettings::PRIVACY_MESSAGE, $this->
getId()) === \CIMSettings::PRIVACY_RESULT_CONTACT
239 && static::$loader::includeModule(
'socialnetwork')
240 && \CSocNetUser::IsFriendsAllowed()
241 && !\CSocNetUserRelations::IsFriends($this->
getId(), $idOtherUser)
248 || $this->isOnlineDataWithStatusFilled)
254 $query = UserTable::query()
256 ->where(
'ID', $this->
getId())
260 $query->registerRuntimeField(
264 Join::on(
'this.ID',
'ref.USER_ID'),
265 [
'join_type' => Join::TYPE_LEFT]
270 $statusData = $query->fetch() ?: [];
276 return isset($this->userData[
'ID']) ? (int)$this->userData[
'ID'] :
null;
286 if (isset($option[
'USER_SHORT_FORMAT']) && $option[
'USER_SHORT_FORMAT'] ===
true)
289 'id' => $this->
getId(),
300 if (!isset($option[
'WITHOUT_ONLINE']) || $option[
'WITHOUT_ONLINE'] ===
false)
309 'id' => $this->
getId(),
322 'bot' => $this->
isBot(),
337 public function getArray(array $option = []): array
341 $converter =
new Converter(Converter::TO_SNAKE | Converter::TO_UPPER | Converter::KEYS);
346 $converter =
new Converter(Converter::TO_LOWER | Converter::KEYS);
351 $converter =
new Converter(Converter::TO_SNAKE | Converter::TO_LOWER | Converter::KEYS);
362 return $this->
getId() !==
null;
367 $this->idle = $onlineData[
'IDLE'] ??
null;
368 $this->lastActivityDate = $onlineData[
'LAST_ACTIVITY_DATE'] ??
null;
369 $this->mobileLastDate = $onlineData[
'MOBILE_LAST_DATE'] ??
null;
370 $this->desktopLastDate = $onlineData[
'DESKTOP_LAST_DATE'] ??
null;
373 $this->isOnlineDataWithStatusFilled =
true;
383 return $this->userData[
'NAME'] ??
null;
388 return $this->userData[
'FIRST_NAME'] ??
null;
393 return $this->userData[
'LAST_NAME'] ??
null;
398 $avatar = $this->userData[
'AVATAR'] ??
'';
400 return $forRest ? $this->prependPublicDomain($avatar) : $avatar;
405 $avatarHr = $this->userData[
'AVATAR_HR'] ??
'';
407 return $forRest ? $this->prependPublicDomain($avatarHr) : $avatarHr;
412 return $this->userData[
'BIRTHDAY'] ??
'';
417 return $this->userData[
'AVATAR_ID'] ?? 0;
422 return $this->userData[
'WORK_POSITION'] ??
null;
427 return $this->userData[
'PERSONAL_GENDER'] ===
'F' ?
'F' :
'M';
432 return $this->userData[
'EXTERNAL_AUTH_ID'] ??
'default';
437 return $this->userData[
'PERSONAL_WWW'] ??
'';
442 return $this->userData[
'EMAIL'] ??
'';
449 foreach ([self::PHONE_MOBILE, self::PHONE_WORK, self::PHONE_INNER] as $phoneType)
451 if (isset($this->userData[$phoneType]) && $this->userData[$phoneType])
453 $result[$phoneType] = $this->userData[$phoneType];
462 return $this->userData[
'COLOR'] ??
'';
467 return $this->userData[
'TIME_ZONE_OFFSET'] ??
'';
472 return $this->userData[
'LANGUAGE_ID'] ??
null;
477 return $this->userData[
'IS_EXTRANET'] ??
false;
482 return $this->userData[
'ACTIVE'] ===
'Y';
487 return $this->userData[
'ABSENT'] ??
null;
492 return $this->userData[
'IS_NETWORK'] ??
false;
497 return $this->userData[
'IS_BOT'] ??
false;
502 return $this->userData[
'IS_CONNECTOR'] ??
false;
508 (isset($this->userData[
'UF_DEPARTMENT']) && is_array($this->userData[
'UF_DEPARTMENT']))
509 ? $this->userData[
'UF_DEPARTMENT']
521 return $withStatus ? $this->isOnlineDataWithStatusFilled : $this->isOnlineDataWithStatusFilled ||
$this->isOnlineDataFilled;
528 return $this->userData[
'STATUS'] ??
'online';
579 if (Loader::includeModule(
'bitrix24'))
582 $USER instanceof \CUser
583 && $USER->isAuthorized()
585 && (
int)$USER->getId() === $this->getId()
592 $this->
isAdmin = \CBitrix24::isPortalAdmin($this->
getId());
598 $USER instanceof \CUser
599 && $USER->isAuthorized()
600 && (
int)$USER->getId() === $this->getId()
603 $this->
isAdmin = $USER->isAdmin();
609 $groups = UserTable::getUserGroupIds($this->
getId());
610 foreach ($groups as $groupId)
612 if ((
int)$groupId === 1)
626 if (!Loader::includeModule(
'socialnetwork') || (
int)$USER->getId() !== $this->getId())
631 return $this->
isAdmin() && \CSocNetUser::IsEnabledModuleAdmin();
636 private function prependPublicDomain(
string $url): string
638 if ($url !==
'' && mb_strpos($url,
'http') !== 0)
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
checkAccessWithoutCaching(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
hasAccess(?int $idOtherUser=null)
bool $isOnlineDataWithStatusFilled
getStatus(bool $real=false)
const ONLINE_DATA_SELECTED_FIELDS
getMobileLastDate(bool $real=false)
fillOnlineData(bool $withStatus=false)
static string $moduleManager
getArray(array $option=[])