3namespace Bitrix\Socialnetwork\Integration\UI\EntitySelector;
5use Bitrix\Extranet\Enum\User\ExtranetRole;
6use Bitrix\Extranet\Model\ExtranetUserTable;
7use Bitrix\Extranet\Service\ServiceContainer;
8use Bitrix\HumanResources\Service\Container;
9use Bitrix\HumanResources\Util\StructureHelper;
10use Bitrix\Intranet\Integration\Mail\EmailUser;
11use Bitrix\Intranet\Internals\InvitationTable;
12use Bitrix\Intranet\Invitation;
13use Bitrix\Intranet\UserAbsence;
14use Bitrix\Main\Application;
15use Bitrix\Main\Config\Option;
16use Bitrix\Main\Engine\Router;
17use Bitrix\Main\Engine\UrlManager;
18use Bitrix\Main\Entity\Query;
19use Bitrix\Main\EO_User;
20use Bitrix\Main\EO_User_Collection;
21use Bitrix\Main\Loader;
22use Bitrix\Main\ModuleManager;
23use Bitrix\Main\ORM\Fields\ExpressionField;
24use Bitrix\Main\ORM\Query\Filter;
25use Bitrix\Main\ORM\Fields\Relations\Reference;
26use Bitrix\Main\ORM\Query\Join;
27use Bitrix\Main\Search\Content;
28use Bitrix\Main\UserTable;
29use Bitrix\Socialnetwork\Collab\CollabFeature;
30use Bitrix\Socialnetwork\Integration\HumanResources\EmployeeHelper;
31use Bitrix\Socialnetwork\UserToGroupTable;
32use Bitrix\Socialnetwork\WorkgroupSiteTable;
33use Bitrix\UI\EntitySelector\BaseProvider;
34use Bitrix\UI\EntitySelector\Dialog;
35use Bitrix\UI\EntitySelector\Item;
36use Bitrix\UI\EntitySelector\SearchQuery;
53 parent::__construct();
62 '/#NAME#|#LAST_NAME#|#SECOND_NAME#|#NAME_SHORT#|#SECOND_NAME_SHORT#|\s|,/',
67 $this->options[
'nameTemplate'] = implode(
'',
$matches[0]);
71 $this->options[
'nameTemplate'] = \CSite::getNameFormat(
false);
74 $this->options[
'analyticsSource'] =
'userProvider';
75 if (isset(
$options[
'analyticsSource']))
77 $this->options[
'analyticsSource'] =
$options[
'analyticsSource'];
82 $this->options[
'onlyWithEmail'] =
$options[
'onlyWithEmail'];
85 if (isset(
$options[
'extranetUsersOnly']) && is_bool(
$options[
'extranetUsersOnly']))
87 $this->options[
'extranetUsersOnly'] =
$options[
'extranetUsersOnly'];
90 if (isset(
$options[
'intranetUsersOnly']) && is_bool(
$options[
'intranetUsersOnly']))
92 $this->options[
'intranetUsersOnly'] =
$options[
'intranetUsersOnly'];
95 if (isset(
$options[
'footerInviteIntranetOnly']) && is_bool(
$options[
'footerInviteIntranetOnly']))
97 $this->options[
'footerInviteIntranetOnly'] =
$options[
'footerInviteIntranetOnly'];
100 $this->options[
'showInvitationFooter'] =
true;
101 if (isset(
$options[
'showInvitationFooter']) && is_bool(
$options[
'showInvitationFooter']))
103 $this->options[
'showInvitationFooter'] =
$options[
'showInvitationFooter'];
106 $this->options[
'emailUsers'] =
false;
109 $this->options[
'emailUsers'] =
$options[
'emailUsers'];
112 $this->options[
'myEmailUsers'] =
true;
115 $this->options[
'myEmailUsers'] =
$options[
'myEmailUsers'];
118 if (isset(
$options[
'emailUsersOnly']) && is_bool(
$options[
'emailUsersOnly']))
120 $this->options[
'emailUsersOnly'] =
$options[
'emailUsersOnly'];
123 $this->options[
'networkUsers'] =
false;
126 $this->options[
'networkUsers'] =
$options[
'networkUsers'];
129 if (isset(
$options[
'networkUsersOnly']) && is_bool(
$options[
'networkUsersOnly']))
131 $this->options[
'networkUsersOnly'] =
$options[
'networkUsersOnly'];
134 $intranetInstalled = ModuleManager::isModuleInstalled(
'intranet');
135 $this->options[
'showLogin'] = $intranetInstalled;
136 $this->options[
'showEmail'] = $intranetInstalled;
138 $this->options[
'inviteEmployeeLink'] =
true;
139 if (isset(
$options[
'inviteEmployeeLink']) && is_bool(
$options[
'inviteEmployeeLink']))
141 $this->options[
'inviteEmployeeLink'] =
$options[
'inviteEmployeeLink'];
144 $this->options[
'inviteExtranetLink'] =
false;
145 if (isset(
$options[
'inviteExtranetLink']) && is_bool(
$options[
'inviteExtranetLink']))
147 $this->options[
'inviteExtranetLink'] =
$options[
'inviteExtranetLink'];
150 $this->options[
'inviteGuestLink'] =
false;
151 if (isset(
$options[
'inviteGuestLink']) && is_bool(
$options[
'inviteGuestLink']))
153 $this->options[
'inviteGuestLink'] =
$options[
'inviteGuestLink'];
156 $this->options[
'lockGuestLinkFeatureId'] =
'';
157 if (isset(
$options[
'lockGuestLinkFeatureId']) && is_string(
$options[
'lockGuestLinkFeatureId']))
159 $this->options[
'lockGuestLinkFeatureId'] =
$options[
'lockGuestLinkFeatureId'];
162 $this->options[
'lockGuestLink'] =
false;
165 $this->options[
'lockGuestLink'] =
$options[
'lockGuestLink'];
168 $this->options[
'collabers'] =
true;
171 $this->options[
'collabers'] =
$options[
'collabers'];
177 $ids = static::prepareUserIds(
$options[
'userId']);
180 $this->options[
'userId'] = $ids;
187 $ids = static::prepareUserIds(
$options[
'!userId']);
190 $this->options[
'!userId'] = $ids;
198 foreach (
$options[
'selectFields'] as $field)
200 if (is_string($field) && array_key_exists($field,
$allowedFields))
206 $this->options[
'selectFields'] = array_unique(
$selectFields);
209 $this->options[
'fillDialog'] =
true;
212 $this->options[
'fillDialog'] =
$options[
'fillDialog'];
215 $this->options[
'maxUsersInRecentTab'] = static::MAX_USERS_IN_RECENT_TAB;
216 if (isset(
$options[
'maxUsersInRecentTab']) && is_int(
$options[
'maxUsersInRecentTab']))
218 $this->options[
'maxUsersInRecentTab'] = max(
220 min(
$options[
'maxUsersInRecentTab'], static::MAX_USERS_IN_RECENT_TAB),
224 $this->options[
'searchLimit'] = static::SEARCH_LIMIT;
227 $this->options[
'searchLimit'] = max(1, min(
$options[
'searchLimit'], static::SEARCH_LIMIT));
233 if (!
$GLOBALS[
'USER']->isAuthorized())
238 $intranetInstalled = ModuleManager::isModuleInstalled(
'intranet');
239 if ($intranetInstalled)
244 return \Bitrix\Socialnetwork\ComponentHelper::getModuleUsed();
249 return $this->
getOption(
'fillDialog',
true);
268 'ignoreUserWhitelist' =>
true,
269 'activeUsers' =>
null,
283 if ($preloadedUsers->count() < $this->options[
'maxUsersInRecentTab'])
286 $entity = $dialog->getEntity(static::ENTITY_ID);
289 $entity->setDynamicSearch(
false);
296 $recentItems = $dialog->getRecentItems()->getEntityItems(static::ENTITY_ID);
297 $recentIds = array_map(
'intval', array_keys($recentItems));
298 $this->fillRecentUsers($recentUsers, $recentIds, $preloadedUsers);
301 if ($recentUsers->count() < $this->options[
'maxUsersInRecentTab'])
303 $recentGlobalItems = $dialog->getGlobalRecentItems()->getEntityItems(static::ENTITY_ID);
304 $recentGlobalIds = [];
306 if (!empty($recentGlobalItems))
308 $recentGlobalIds = array_map(
'intval', array_keys($recentGlobalItems));
309 $recentGlobalIds = array_values(array_diff($recentGlobalIds, $recentUsers->getIdList()));
310 $recentGlobalIds = array_slice($recentGlobalIds, 0, $this->options[
'maxUsersInRecentTab'] - $recentUsers->count());
313 $this->fillRecentUsers($recentUsers, $recentGlobalIds, $preloadedUsers);
317 foreach ($preloadedUsers as $preloadedUser)
319 $recentUsers->add($preloadedUser);
325 if ($this->options[
'showInvitationFooter'] && Loader::includeModule(
'intranet'))
327 $inviteEmployeeLink =
null;
328 $employeeInvitationAvailable = Invitation::canCurrentUserInvite();
329 $intranetUsersOnly = $this->options[
'intranetUsersOnly'] ??
false;
330 $footerInviteIntranetOnly = $this->options[
'footerInviteIntranetOnly'] ?? CollabFeature::isOn();
331 $extranetInvitationAvailable = (
332 ModuleManager::isModuleInstalled(
'extranet')
333 && Option::get(
'extranet',
'extranet_site')
334 && !$intranetUsersOnly
335 && !$footerInviteIntranetOnly
339 $this->options[
'inviteEmployeeLink']
341 $employeeInvitationAvailable
342 || $extranetInvitationAvailable
344 && self::isIntranetUser()
348 $inviteEmployeeLink = UrlManager::getInstance()->create(
'getSliderContent', [
349 'c' =>
'bitrix:intranet.invitation',
350 'mode' => Router::COMPONENT_MODE_AJAX,
351 'analyticsLabel[source]' => $this->options[
'analyticsSource'],
352 'analyticsLabel[tool]' =>
'Invitation',
353 'analyticsLabel[category]' =>
'invitation',
354 'analyticsLabel[event]' =>
'drawer_open',
355 'analyticsLabel[c_section]' => $this->options[
'analyticsSource'],
359 $inviteGuestLink =
null;
360 if ($this->options[
'inviteGuestLink'] && ModuleManager::isModuleInstalled(
'mail') && self::isIntranetUser())
362 $inviteGuestLink = UrlManager::getInstance()->create(
'getSliderContent', [
363 'c' =>
'bitrix:intranet.invitation.guest',
364 'mode' => Router::COMPONENT_MODE_AJAX,
368 if ($inviteEmployeeLink || $inviteGuestLink)
371 if ($dialog->getFooter() ===
'BX.SocialNetwork.EntitySelector.Footer')
374 $footerOptions = $dialog->getFooterOptions() ?? [];
377 $footerOptions[
'inviteEmployeeLink'] = $inviteEmployeeLink;
378 $footerOptions[
'inviteGuestLink'] = $inviteGuestLink;
379 if ($inviteEmployeeLink)
381 $footerOptions[
'inviteEmployeeScope'] = ($employeeInvitationAvailable ?
'I' :
'').($extranetInvitationAvailable ?
'E' :
'');
384 if ($inviteGuestLink && $this->options[
'lockGuestLink'])
386 $footerOptions[
'lockGuestLink'] =
true;
387 $footerOptions[
'lockGuestLinkFeatureId'] = $this->options[
'lockGuestLinkFeatureId'] ??
'';
390 $dialog->setFooter(
'BX.SocialNetwork.EntitySelector.Footer', $footerOptions);
398 'order' => [
'ID' =>
'asc'],
399 'limit' => $this->options[
'maxUsersInRecentTab'],
403 private function fillRecentUsers(
409 if (
count($recentIds) < 1)
414 $ids = array_values(array_diff($recentIds, $preloadedUsers->getIdList()));
418 foreach ($users as
$user)
420 $preloadedUsers->add(
$user);
424 foreach ($recentIds as $recentId)
426 $user = $preloadedUsers->getByPrimary($recentId);
429 $recentUsers->add(
$user);
436 $atom =
'=_0-9a-z+~\'!\$&*^`|\\#%/?{}-';
437 $isEmailLike = (bool)preg_match(
'#^['.$atom.
']+(\\.['.$atom.
']+)*@#i', $searchQuery->
getQuery());
442 'searchByEmail' => $searchQuery->
getQuery(),
443 'myEmailUsers' =>
false,
444 'limit' => $this->options[
'searchLimit'],
450 'searchQuery' => $searchQuery->
getQuery(),
451 'limit' => $this->options[
'searchLimit'],
455 $limitExceeded = ($this->options[
'searchLimit'] <=
count(
$items));
461 $dialog->addItems(
$items);
468 $user = UserTable::getById($item->
getId())->fetchObject();
469 if (
$user &&
$user->getExternalAuthId() ===
'email' && Loader::includeModule(
'intranet'))
471 EmailUser::invite(
$user->getId());
481 $ignoreUserWhitelist = isset(
$options[
'ignoreUserWhitelist']) &&
$options[
'ignoreUserWhitelist'] ===
true;
482 if (!empty($dialogOptions[
'userId']) && !$ignoreUserWhitelist)
484 $options[
'userId'] = $dialogOptions[
'userId'];
487 static $usersCache = [];
489 $cacheKey = md5(serialize(
$options));
491 if (!isset($usersCache[$cacheKey]))
493 $usersCache[$cacheKey] = static::getUsers(
$options);
496 return $usersCache[$cacheKey];
511 return self::hasUserRole(
$userId,
'intranet');
516 return self::hasUserRole(
$userId,
'extranet');
524 private static function hasUserRole(?
int $userId,
string $role): bool
531 if (!isset($roles[$role]) || !ModuleManager::isModuleInstalled(
'intranet'))
546 $userId === self::getCurrentUserId()
547 && \CSocNetUser::isCurrentUserModuleAdmin()
553 if (isset($roles[$role][
$userId]))
558 $cacheId =
'UserRole:'.$role;
559 $cachePath =
'/external_user_info/'.substr(md5(
$userId),-2).
'/'.
$userId.
'/';
560 $cache = Application::getInstance()->getCache();
563 if ($cache->initCache($ttl, $cacheId, $cachePath))
565 $roles[$role][
$userId] = (bool)$cache->getVars();
569 $cache->startDataCache();
571 $taggedCache = Application::getInstance()->getTaggedCache();
572 $taggedCache->startTagCache($cachePath);
573 $taggedCache->registerTag(
'USER_NAME_'.
$userId);
574 $taggedCache->endTagCache();
578 '=IS_REAL_USER' =>
true,
581 if ($role ===
'intranet')
583 $filter[
'!UF_DEPARTMENT'] =
false;
585 else if ($role ===
'extranet')
587 $filter[
'UF_DEPARTMENT'] =
false;
591 UserTable::getList([
'select' => [
'ID'],
'filter' =>
$filter])
592 ->fetchCollection()->count() === 1
595 $cache->endDataCache($roles[$role][
$userId]);
605 if ($integrators ===
null)
608 if (Loader::includeModule(
'bitrix24'))
610 $integrators = array_fill_keys(\
Bitrix\
Bitrix24\Integrator::getIntegratorsId(),
true);
623 return isset($integrators[
$userId]);
636 'lastName' =>
'LAST_NAME',
638 'secondName' =>
'SECOND_NAME',
642 'position',
'WORK_POSITION',
643 'lastLogin' =>
'LAST_LOGIN',
644 'dateRegister' =>
'DATE_REGISTER',
645 'lastActivityDate' =>
'LAST_ACTIVITY_DATE',
646 'online' =>
'IS_ONLINE',
647 'profession' =>
'PERSONAL_PROFESSION',
648 'www' =>
'PERSONAL_WWW',
649 'birthday' =>
'PERSONAL_BIRTHDAY',
650 'icq' =>
'PERSONAL_ICQ',
651 'phone' =>
'PERSONAL_PHONE',
652 'fax' =>
'PERSONAL_FAX',
653 'mobile' =>
'PERSONAL_MOBILE',
654 'pager' =>
'PERSONAL_PAGER',
655 'street' =>
'PERSONAL_STREET',
656 'city' =>
'PERSONAL_CITY',
657 'state' =>
'PERSONAL_STATE',
658 'zip' =>
'PERSONAL_ZIP',
659 'mailbox' =>
'PERSONAL_MAILBOX',
660 'country' =>
'PERSONAL_COUNTRY',
661 'timeZoneOffset' =>
'TIME_ZONE_OFFSET',
662 'company' =>
'WORK_COMPANY',
663 'workPhone' =>
'WORK_PHONE',
664 'workDepartment' =>
'WORK_DEPARTMENT',
665 'workPosition' =>
'WORK_POSITION',
666 'workCity' =>
'WORK_CITY',
667 'workCountry' =>
'WORK_COUNTRY',
668 'workStreet' =>
'WORK_STREET',
669 'workState' =>
'WORK_STATE',
670 'workZip' =>
'WORK_ZIP',
671 'workMailbox' =>
'WORK_MAILBOX',
674 foreach (
$fields as $id => $dbName)
676 if (mb_strpos($dbName,
'PERSONAL_') === 0)
678 $fields[
'personal' . ucfirst($id)] = $dbName;
684 $intranetInstalled = ModuleManager::isModuleInstalled(
'intranet');
685 if ($intranetInstalled)
687 $userFields =
$GLOBALS[
'USER_FIELD_MANAGER']->GetUserFields(
'USER');
688 $allowedUserFields = [
689 'ufPhoneInner' =>
'UF_PHONE_INNER',
690 'ufDistrict' =>
'UF_DISTRICT',
691 'ufSkype' =>
'UF_SKYPE',
692 'ufSkypeLink' =>
'UF_SKYPE_LINK',
693 'ufZoom' =>
'UF_ZOOM',
694 'ufTwitter' =>
'UF_TWITTER',
695 'ufFacebook' =>
'UF_FACEBOOK',
696 'ufLinkedin' =>
'UF_LINKEDIN',
697 'ufXing' =>
'UF_XING',
698 'ufWebSites' =>
'UF_WEB_SITES',
699 'ufSkills' =>
'UF_SKILLS',
700 'ufInterests' =>
'UF_INTERESTS',
701 'ufEmploymentDate' =>
'UF_EMPLOYMENT_DATE',
704 foreach ($allowedUserFields as $id => $dbName)
706 if (array_key_exists($dbName, $userFields))
724 return $result->fetchCollection();
730 'ID',
'ACTIVE',
'LAST_NAME',
'NAME',
'SECOND_NAME',
'LOGIN',
'EMAIL',
'TITLE',
731 'PERSONAL_GENDER',
'PERSONAL_PHOTO',
'WORK_POSITION',
732 'CONFIRM_CODE',
'EXTERNAL_AUTH_ID',
738 foreach (
$options[
'selectFields'] as $field)
740 if (is_string($field) && array_key_exists($field,
$allowedFields))
747 $query = UserTable::query();
750 $intranetInstalled = ModuleManager::isModuleInstalled(
'intranet');
751 if ($intranetInstalled)
753 $query->addSelect(
'UF_DEPARTMENT');
756 $activeUsers = array_key_exists(
'activeUsers',
$options) ?
$options[
'activeUsers'] :
true;
757 if (is_bool($activeUsers))
759 $query->where(
'ACTIVE', $activeUsers ?
'Y' :
'N');
762 if (isset(
$options[
'onlyWithEmail']) && is_bool(isset(
$options[
'onlyWithEmail'])))
764 $query->addFilter((
$options[
'onlyWithEmail'] ?
'!' :
'').
'EMAIL',
false);
767 if (isset(
$options[
'invitedUsers']) && is_bool(isset(
$options[
'invitedUsers'])))
769 $query->addFilter((
$options[
'invitedUsers'] ?
'!' :
'').
'CONFIRM_CODE',
false);
774 $query->registerRuntimeField(
778 Join::on(
'this.ID',
'ref.USER_ID'),
779 [
'join_type' =>
'INNER'],
784 'USER_INDEX.SEARCH_USER_CONTENT',
785 Filter\Helper::matchAgainstWildcard(
786 Content::prepareStringToken(
$options[
'searchQuery']),
'*', 1,
790 else if (!empty(
$options[
'searchByEmail']) && is_string(
$options[
'searchByEmail']))
802 if ($intranetInstalled)
804 $emptyValue = serialize([]);
805 $emptyValue2 = serialize([0]);
810 (%s IS NOT NULL AND %s != \'' . $emptyValue .
'\' AND %s != \
'' . $emptyValue2 .
'\') AND
811 (%s IS NULL OR %s NOT IN (\
'' . implode(
'\', \
'', UserTable::getExternalUserTypes()) .
'\'))
815 [
'UF_DEPARTMENT',
'UF_DEPARTMENT',
'UF_DEPARTMENT',
'EXTERNAL_AUTH_ID',
'EXTERNAL_AUTH_ID']),
821 (%s IS NULL OR %s = \'' . $emptyValue .
'\' OR %s = \
'' . $emptyValue2 .
'\') AND
822 (%s IS NULL OR %s NOT IN (\
'' . implode(
'\', \
'', UserTable::getExternalUserTypes()) .
'\'))
826 [
'UF_DEPARTMENT',
'UF_DEPARTMENT',
'UF_DEPARTMENT',
'EXTERNAL_AUTH_ID',
'EXTERNAL_AUTH_ID']),
829 $query->registerRuntimeField(
832 InvitationTable::class,
833 Join::on(
'this.ID',
'ref.USER_ID')->where(
'ref.ORIGINATOR_ID', $currentUserId),
834 [
'join_type' =>
'LEFT'],
840 $intranetUsersOnly = isset(
$options[
'intranetUsersOnly']) &&
$options[
'intranetUsersOnly'] ===
true;
841 $extranetUsersOnly = isset(
$options[
'extranetUsersOnly']) &&
$options[
'extranetUsersOnly'] ===
true;
842 $emailUsersOnly = isset(
$options[
'emailUsersOnly']) &&
$options[
'emailUsersOnly'] ===
true;
843 $networkUsersOnly = isset(
$options[
'networkUsersOnly']) &&
$options[
'networkUsersOnly'] ===
true;
866 $query->where(
'EXTERNAL_AUTH_ID',
'email');
869 $query->whereNotNull(
'INVITATION.ID');
872 else if ($networkUsersOnly)
874 $query->where(
'EXTERNAL_AUTH_ID',
'replica');
876 else if ($intranetUsersOnly)
878 $query->where(
'IS_INTRANET_USER',
'Y');
880 else if ($extranetUsersOnly)
882 $query->where(
'IS_EXTRANET_USER',
'Y');
883 if ($extranetUsersQuery)
885 $query->whereIn(
'ID', $extranetUsersQuery);
890 $filter = Query::filter()->logic(
'or');
894 && !\CSocNetUser::isCurrentUserModuleAdmin()
897 $filter->where(
'IS_INTRANET_USER',
'Y');
901 $filter->addCondition(Query::filter()
903 ->whereNotIn(
'EXTERNAL_AUTH_ID', UserTable::getExternalUserTypes())
904 ->whereNull(
'EXTERNAL_AUTH_ID'),
908 if ($emailUsers ===
true)
912 $filter->addCondition(Query::filter()
913 ->where(
'EXTERNAL_AUTH_ID',
'email')
914 ->whereNotNull(
'INVITATION.ID'),
919 $filter->where(
'EXTERNAL_AUTH_ID',
'email');
923 if ($networkUsers ===
true)
925 $filter->where(
'EXTERNAL_AUTH_ID',
'replica');
928 if ($extranetUsersQuery)
930 $filter->whereIn(
'ID', $extranetUsersQuery);
931 $filter->addCondition(Query::filter()
932 ->where(Query::filter()
934 ->whereNull(
'EXTERNAL_AUTH_ID')
935 ->whereNot(
'EXTERNAL_AUTH_ID',
'email'),
937 ->whereNotNull(
'INVITATION.ID'),
946 if ($intranetUsersOnly)
948 $query->where(
'IS_INTRANET_USER',
'Y');
950 else if ($extranetUsersOnly)
952 $query->where(
'IS_EXTRANET_USER',
'Y');
956 $query->addFilter(
'!=EXTERNAL_AUTH_ID', UserTable::getExternalUserTypes());
959 if ($extranetUsersQuery)
961 $query->whereIn(
'ID', $extranetUsersQuery);
971 $query->addFilter(
'!=EXTERNAL_AUTH_ID', UserTable::getExternalUserTypes());
974 if (!(
$options[
'collabers'] ??
true) && Loader::includeModule(
'extranet'))
976 $query->registerRuntimeField(
979 ExtranetUserTable::class,
980 Join::on(
'this.ID',
'ref.USER_ID'),
981 [
'join_type' => Join::TYPE_LEFT]
984 $query->addFilter(
'!=EXTRANET_USER.ROLE', ExtranetRole::Collaber->value);
987 $userIds = self::prepareUserIds(
$options[
'userId'] ?? []);
988 $notUserIds = self::prepareUserIds(
$options[
'!userId'] ?? []);
991 if (!empty($userIds))
993 $query->whereIn(
'ID', $userIds);
997 if (!empty($notUserIds))
999 $query->whereNotIn(
'ID', $notUserIds);
1005 ($usersCount =
count($userIds)) > 1
1008 $helper = Application::getConnection()->getSqlHelper();
1009 $expression = $helper->getOrderByIntField(
'%s', $userIds,
false);
1013 array_fill(0, $usersCount,
'ID'),
1016 ->registerRuntimeField($field)
1017 ->setOrder($field->getName());
1025 $query->setOrder([
'LAST_NAME' =>
'asc']);
1040 private static function prepareUserIds(
$items):
array
1053 $ids = array_unique($ids);
1065 $extranetSiteId = Option::get(
'extranet',
'extranet_site');
1066 $extranetSiteId = ($extranetSiteId && ModuleManager::isModuleInstalled(
'extranet') ? $extranetSiteId :
false);
1070 || \CSocNetUser::isCurrentUserModuleAdmin()
1076 $query = UserToGroupTable::query();
1079 $query->whereIn(
'ROLE', self::EXTRANET_ROLES);
1080 $query->registerRuntimeField(
1083 WorkgroupSiteTable::class,
1084 Join::on(
'ref.GROUP_ID',
'this.GROUP_ID')->where(
'ref.SITE_ID', $extranetSiteId),
1085 [
'join_type' =>
'INNER'],
1089 $query->registerRuntimeField(
1092 UserToGroupTable::class,
1093 Join::on(
'ref.GROUP_ID',
'this.GROUP_ID')
1094 ->where(
'ref.USER_ID', $currentUserId)
1095 ->whereIn(
'ref.ROLE', self::EXTRANET_ROLES),
1096 [
'join_type' =>
'INNER'],
1106 $users = static::getUsers(
$options);
1108 return $users->count() ? $users->getAll()[0] :
null;
1119 foreach ($users as
$user)
1130 foreach ([
'name',
'lastName',
'secondName',
'email',
'login'] as $field)
1132 if (!empty(
$user->{
'get'.$field}()))
1134 $customData[$field] =
$user->{
'get'.$field}();
1138 if (!empty(
$user->getPersonalGender()))
1140 $customData[
'gender'] =
$user->getPersonalGender();
1143 if (!empty(
$user->getWorkPosition()))
1145 $customData[
'position'] =
$user->getWorkPosition();
1148 $userType = self::getUserType(
$user);
1150 if (
$user->getConfirmCode() && in_array($userType, [
'employee',
'integrator']))
1152 $customData[
'invited'] =
true;
1157 $userData =
$user->collectValues();
1159 foreach (
$options[
'selectFields'] as $field)
1161 if (!is_string($field))
1167 $value = $userData[$dbName] ??
null;
1170 if ($field ===
'country' || $field ===
'workCountry')
1196 'id' =>
$user->getId(),
1197 'entityId' => static::ENTITY_ID,
1198 'entityType' => $userType,
1200 'avatar' => self::makeUserAvatar(
$user),
1202 'tabs' => static::getTabsNames(),
1205 if (($userType ===
'employee' || $userType ===
'integrator') && Loader::includeModule(
'intranet'))
1207 $isOnVacation = UserAbsence::isAbsentOnVacation(
$user->getId());
1210 $item->getCustomData()->set(
'isOnVacation',
true);
1219 return [static::ENTITY_ID];
1225 if (!
$user->getActive())
1229 else if (
$user->getExternalAuthId() ===
'email')
1233 else if (
$user->getExternalAuthId() ===
'replica')
1237 else if (!in_array(
$user->getExternalAuthId(), UserTable::getExternalUserTypes()))
1239 if (ModuleManager::isModuleInstalled(
'intranet') || ModuleManager::isModuleInstalled(
'extranet'))
1241 if (self::isIntegrator(
$user->getId()))
1243 $type =
'integrator';
1246 Loader::includeModule(
'extranet')
1247 && ServiceContainer::getInstance()->getCollaberService()->isCollaberById(
$user->getId())
1252 else if (ModuleManager::isModuleInstalled(
'intranet'))
1254 $ufDepartment =
$user->getUfDepartment();
1256 empty($ufDepartment)
1257 || (is_array($ufDepartment) &&
count($ufDepartment) === 1 && (
int)$ufDepartment[0] === 0)
1283 return \CUser::formatName(
1284 !empty(
$options[
'nameTemplate']) ?
$options[
'nameTemplate'] : \CSite::getNameFormat(
false),
1286 'NAME' =>
$user->getName(),
1287 'LAST_NAME' =>
$user->getLastName(),
1288 'SECOND_NAME' =>
$user->getSecondName(),
1289 'LOGIN' =>
$user->getLogin(),
1290 'EMAIL' =>
$user->getEmail(),
1291 'TITLE' =>
$user->getTitle(),
1300 if (empty(
$user->getPersonalPhoto()))
1305 $avatar = \CFile::resizeImageGet(
1306 $user->getPersonalPhoto(),
1307 [
'width' => 100,
'height' => 100],
1312 return !empty($avatar[
'src']) ? $avatar[
'src'] :
null;
1320 ? self::getExtranetUserUrl(
$userId)
1321 : self::getIntranetUserUrl(
$userId)
1327 $extranetSiteId = Option::get(
'extranet',
'extranet_site');
1328 $userPage = Option::get(
'socialnetwork',
'user_page',
false, $extranetSiteId);
1331 $userPage =
'/extranet/contacts/personal/';
1334 return $userPage.
'user/' . (
$userId !==
null ?
$userId :
'#id#') .
'/';
1339 $userPage = Option::get(
'socialnetwork',
'user_page',
false,
SITE_ID);
1343 $userPage = $siteDir .
'company/personal/';
1346 return $userPage.
'user/' . (
$userId !==
null ?
$userId :
'#id#') .
'/';
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
static getCountryValue(array $params=[])
static employeesToDepartment(EO_User_Collection $usersCollection)
static formatUserName(EO_User $user, array $options=[])
getUserItems(array $options=[])
getPreloadedUsersCollection()
handleBeforeItemSave(Item $item)
static getAllowedFields()
getUserCollection(array $options=[])
static getUser(int $userId, array $options=[])
static getExtranetUsersQuery(int $currentUserId)
static isIntegrator(int $userId=null)
__construct(array $options=[])
static isExtranetUser(int $userId=null)
prepareOptions(array $options=[])
static getUserUrl(?int $userId=null)
static getUserType(EO_User $user)
static isIntranetUser(int $userId=null)
fillDialog(Dialog $dialog)
static getQuery(array $options=[])
static getCurrentUserId()
static makeUserAvatar(EO_User $user)
static makeItem(EO_User $user, array $options=[])
static getUsers(array $options=[])
static getIntranetUserUrl(?int $userId=null)
static getExtranetUserUrl(?int $userId=null)
makeUserItems(EO_User_Collection $users, array $options=[])
const MAX_USERS_IN_RECENT_TAB
getSelectedItems(array $ids)
doSearch(SearchQuery $searchQuery, Dialog $dialog)
static makeItems(EO_User_Collection $users, array $options=[])
getOption(string $option, $defaultValue=null)
setCacheable(bool $flag=true)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
const BX_RESIZE_IMAGE_EXACT
const SITE_DIR(!defined('LANG'))
$GLOBALS['____1690880296']
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
</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."%"