54 '/#NAME#|#LAST_NAME#|#SECOND_NAME#|#NAME_SHORT#|#SECOND_NAME_SHORT#|\s|,/',
59 $this->options[
'nameTemplate'] = implode(
'', $matches[0]);
63 $this->options[
'nameTemplate'] = \CSite::getNameFormat(
false);
68 $this->options[
'onlyWithEmail'] =
$options[
'onlyWithEmail'];
71 if (isset(
$options[
'extranetUsersOnly']) && is_bool(
$options[
'extranetUsersOnly']))
73 $this->options[
'extranetUsersOnly'] =
$options[
'extranetUsersOnly'];
76 if (isset(
$options[
'intranetUsersOnly']) && is_bool(
$options[
'intranetUsersOnly']))
78 $this->options[
'intranetUsersOnly'] =
$options[
'intranetUsersOnly'];
81 if (isset(
$options[
'footerInviteIntranetOnly']) && is_bool(
$options[
'footerInviteIntranetOnly']))
83 $this->options[
'footerInviteIntranetOnly'] =
$options[
'footerInviteIntranetOnly'];
86 $this->options[
'showInvitationFooter'] =
true;
87 if (isset(
$options[
'showInvitationFooter']) && is_bool(
$options[
'showInvitationFooter']))
89 $this->options[
'showInvitationFooter'] =
$options[
'showInvitationFooter'];
92 $this->options[
'emailUsers'] =
false;
95 $this->options[
'emailUsers'] =
$options[
'emailUsers'];
98 $this->options[
'myEmailUsers'] =
true;
101 $this->options[
'myEmailUsers'] =
$options[
'myEmailUsers'];
104 if (isset(
$options[
'emailUsersOnly']) && is_bool(
$options[
'emailUsersOnly']))
106 $this->options[
'emailUsersOnly'] =
$options[
'emailUsersOnly'];
109 $this->options[
'networkUsers'] =
false;
112 $this->options[
'networkUsers'] =
$options[
'networkUsers'];
115 if (isset(
$options[
'networkUsersOnly']) && is_bool(
$options[
'networkUsersOnly']))
117 $this->options[
'networkUsersOnly'] =
$options[
'networkUsersOnly'];
120 $intranetInstalled = ModuleManager::isModuleInstalled(
'intranet');
121 $this->options[
'showLogin'] = $intranetInstalled;
122 $this->options[
'showEmail'] = $intranetInstalled;
124 $this->options[
'inviteEmployeeLink'] =
true;
125 if (isset(
$options[
'inviteEmployeeLink']) && is_bool(
$options[
'inviteEmployeeLink']))
127 $this->options[
'inviteEmployeeLink'] =
$options[
'inviteEmployeeLink'];
130 $this->options[
'inviteExtranetLink'] =
false;
131 if (isset(
$options[
'inviteExtranetLink']) && is_bool(
$options[
'inviteExtranetLink']))
133 $this->options[
'inviteExtranetLink'] =
$options[
'inviteExtranetLink'];
136 $this->options[
'inviteGuestLink'] =
false;
137 if (isset(
$options[
'inviteGuestLink']) && is_bool(
$options[
'inviteGuestLink']))
139 $this->options[
'inviteGuestLink'] =
$options[
'inviteGuestLink'];
145 $ids = static::prepareUserIds(
$options[
'userId']);
148 $this->options[
'userId'] = $ids;
155 $ids = static::prepareUserIds(
$options[
'!userId']);
158 $this->options[
'!userId'] = $ids;
165 $allowedFields = static::getAllowedFields();
166 foreach (
$options[
'selectFields'] as $field)
168 if (is_string($field) && array_key_exists($field, $allowedFields))
170 $selectFields[] = $field;
174 $this->options[
'selectFields'] = array_unique($selectFields);
177 $this->options[
'fillDialog'] =
true;
180 $this->options[
'fillDialog'] =
$options[
'fillDialog'];
236 if ($preloadedUsers->count() < self::MAX_USERS_IN_RECENT_TAB)
239 $entity = $dialog->
getEntity(static::ENTITY_ID);
242 $entity->setDynamicSearch(
false);
246 $recentUsers =
new EO_User_Collection();
249 $recentItems = $dialog->
getRecentItems()->getEntityItems(static::ENTITY_ID);
250 $recentIds = array_map(
'intval', array_keys($recentItems));
251 $this->fillRecentUsers($recentUsers, $recentIds, $preloadedUsers);
254 if ($recentUsers->count() < self::MAX_USERS_IN_RECENT_TAB)
257 $recentGlobalIds = [];
259 if (!empty($recentGlobalItems))
261 $recentGlobalIds = array_map(
'intval', array_keys($recentGlobalItems));
262 $recentGlobalIds = array_values(array_diff($recentGlobalIds, $recentUsers->getIdList()));
263 $recentGlobalIds = array_slice($recentGlobalIds, 0, self::MAX_USERS_IN_RECENT_TAB - $recentUsers->count());
266 $this->fillRecentUsers($recentUsers, $recentGlobalIds, $preloadedUsers);
270 foreach ($preloadedUsers as $preloadedUser)
272 $recentUsers->add($preloadedUser);
278 if ($this->options[
'showInvitationFooter'] && Loader::includeModule(
'intranet'))
280 $inviteEmployeeLink =
null;
281 $employeeInvitationAvailable = Invitation::canCurrentUserInvite();
282 $intranetUsersOnly = $this->options[
'intranetUsersOnly'] ??
false;
283 $footerInviteIntranetOnly = $this->options[
'footerInviteIntranetOnly'] ??
false;
284 $extranetInvitationAvailable = (
285 ModuleManager::isModuleInstalled(
'extranet')
286 && Option::get(
'extranet',
'extranet_site')
287 && !$intranetUsersOnly
288 && !$footerInviteIntranetOnly
292 $this->options[
'inviteEmployeeLink']
294 $employeeInvitationAvailable
295 || $extranetInvitationAvailable
300 $inviteEmployeeLink = UrlManager::getInstance()->create(
'getSliderContent', [
301 'c' =>
'bitrix:intranet.invitation',
302 'mode' => Router::COMPONENT_MODE_AJAX,
303 'analyticsLabel[source]' =>
'userProvider',
307 $inviteGuestLink =
null;
308 if ($this->options[
'inviteGuestLink'] && ModuleManager::isModuleInstalled(
'mail') && self::isIntranetUser())
310 $inviteGuestLink = UrlManager::getInstance()->create(
'getSliderContent', [
311 'c' =>
'bitrix:intranet.invitation.guest',
312 'mode' => Router::COMPONENT_MODE_AJAX,
316 if ($inviteEmployeeLink || $inviteGuestLink)
319 if ($dialog->
getFooter() ===
'BX.SocialNetwork.EntitySelector.Footer')
325 $footerOptions[
'inviteEmployeeLink'] = $inviteEmployeeLink;
326 $footerOptions[
'inviteGuestLink'] = $inviteGuestLink;
327 if ($inviteEmployeeLink)
329 $footerOptions[
'inviteEmployeeScope'] = ($employeeInvitationAvailable ?
'I' :
'').($extranetInvitationAvailable ?
'E' :
'');
332 $dialog->
setFooter(
'BX.SocialNetwork.EntitySelector.Footer', $footerOptions);
562 static $fields =
null;
564 if ($fields !==
null)
570 'lastName' =>
'LAST_NAME',
572 'secondName' =>
'SECOND_NAME',
576 'position',
'WORK_POSITION',
577 'lastLogin' =>
'LAST_LOGIN',
578 'dateRegister' =>
'DATE_REGISTER',
579 'lastActivityDate' =>
'LAST_ACTIVITY_DATE',
580 'online' =>
'IS_ONLINE',
581 'profession' =>
'PERSONAL_PROFESSION',
582 'www' =>
'PERSONAL_WWW',
583 'birthday' =>
'PERSONAL_BIRTHDAY',
584 'icq' =>
'PERSONAL_ICQ',
585 'phone' =>
'PERSONAL_PHONE',
586 'fax' =>
'PERSONAL_FAX',
587 'mobile' =>
'PERSONAL_MOBILE',
588 'pager' =>
'PERSONAL_PAGER',
589 'street' =>
'PERSONAL_STREET',
590 'city' =>
'PERSONAL_CITY',
591 'state' =>
'PERSONAL_STATE',
592 'zip' =>
'PERSONAL_ZIP',
593 'mailbox' =>
'PERSONAL_MAILBOX',
594 'country' =>
'PERSONAL_COUNTRY',
595 'timeZoneOffset' =>
'TIME_ZONE_OFFSET',
596 'company' =>
'WORK_COMPANY',
597 'workPhone' =>
'WORK_PHONE',
598 'workDepartment' =>
'WORK_DEPARTMENT',
599 'workPosition' =>
'WORK_POSITION',
600 'workCity' =>
'WORK_CITY',
601 'workCountry' =>
'WORK_COUNTRY',
602 'workStreet' =>
'WORK_STREET',
603 'workState' =>
'WORK_STATE',
604 'workZip' =>
'WORK_ZIP',
605 'workMailbox' =>
'WORK_MAILBOX',
608 foreach ($fields as $id => $dbName)
610 if (mb_strpos($dbName,
'PERSONAL_') === 0)
612 $fields[
'personal' . ucfirst($id)] = $dbName;
615 $fields[$dbName] = $dbName;
618 $intranetInstalled = ModuleManager::isModuleInstalled(
'intranet');
619 if ($intranetInstalled)
621 $userFields =
$GLOBALS[
'USER_FIELD_MANAGER']->GetUserFields(
'USER');
622 $allowedUserFields = [
623 'ufPhoneInner' =>
'UF_PHONE_INNER',
624 'ufDistrict' =>
'UF_DISTRICT',
625 'ufSkype' =>
'UF_SKYPE',
626 'ufSkypeLink' =>
'UF_SKYPE_LINK',
627 'ufZoom' =>
'UF_ZOOM',
628 'ufTwitter' =>
'UF_TWITTER',
629 'ufFacebook' =>
'UF_FACEBOOK',
630 'ufLinkedin' =>
'UF_LINKEDIN',
631 'ufXing' =>
'UF_XING',
632 'ufWebSites' =>
'UF_WEB_SITES',
633 'ufSkills' =>
'UF_SKILLS',
634 'ufInterests' =>
'UF_INTERESTS',
635 'ufEmploymentDate' =>
'UF_EMPLOYMENT_DATE',
638 foreach ($allowedUserFields as $id => $dbName)
640 if (array_key_exists($dbName, $userFields))
642 $fields[$id] = $dbName;
643 $fields[$dbName] = $dbName;
664 'ID',
'ACTIVE',
'LAST_NAME',
'NAME',
'SECOND_NAME',
'LOGIN',
'EMAIL',
'TITLE',
665 'PERSONAL_GENDER',
'PERSONAL_PHOTO',
'WORK_POSITION',
666 'CONFIRM_CODE',
'EXTERNAL_AUTH_ID'
671 $allowedFields = static::getAllowedFields();
672 foreach (
$options[
'selectFields'] as $field)
674 if (is_string($field) && array_key_exists($field, $allowedFields))
676 $selectFields[] = $allowedFields[$field];
681 $query = UserTable::query();
682 $query->setSelect(array_unique($selectFields));
684 $intranetInstalled = ModuleManager::isModuleInstalled(
'intranet');
685 if ($intranetInstalled)
687 $query->addSelect(
'UF_DEPARTMENT');
690 $activeUsers = array_key_exists(
'activeUsers',
$options) ?
$options[
'activeUsers'] :
true;
691 if (is_bool($activeUsers))
693 $query->where(
'ACTIVE', $activeUsers ?
'Y' :
'N');
696 if (isset(
$options[
'onlyWithEmail']) && is_bool(isset(
$options[
'onlyWithEmail'])))
698 $query->addFilter((
$options[
'onlyWithEmail'] ?
'!' :
'').
'EMAIL',
false);
701 if (isset(
$options[
'invitedUsers']) && is_bool(isset(
$options[
'invitedUsers'])))
703 $query->addFilter((
$options[
'invitedUsers'] ?
'!' :
'').
'CONFIRM_CODE',
false);
708 $query->registerRuntimeField(
711 \
Bitrix\Main\UserIndexTable::class,
712 Join::on(
'this.ID',
'ref.USER_ID'),
713 [
'join_type' =>
'INNER']
718 'USER_INDEX.SEARCH_USER_CONTENT',
719 Filter\Helper::matchAgainstWildcard(
720 Content::prepareStringToken(
$options[
'searchQuery']),
'*', 1
724 else if (!empty(
$options[
'searchByEmail']) && is_string(
$options[
'searchByEmail']))
726 $query->whereLike(
'EMAIL',
$options[
'searchByEmail'].
'%');
736 if ($intranetInstalled)
738 $emptyValue = serialize([]);
739 $emptyValue2 = serialize([0]);
744 (%s IS NOT NULL AND %s != \'' . $emptyValue .
'\' AND %s != \
'' . $emptyValue2 .
'\') AND
745 (%s IS NULL OR %s NOT IN (\
'' . implode(
'\', \
'', UserTable::getExternalUserTypes()) .
'\'))
749 [
'UF_DEPARTMENT',
'UF_DEPARTMENT',
'UF_DEPARTMENT',
'EXTERNAL_AUTH_ID',
'EXTERNAL_AUTH_ID'])
755 (%s IS NULL OR %s = \'' . $emptyValue .
'\' OR %s = \
'' . $emptyValue2 .
'\') AND
756 (%s IS NULL OR %s NOT IN (\
'' . implode(
'\', \
'', UserTable::getExternalUserTypes()) .
'\')), \
'Y\', \'N\'
758 [
'UF_DEPARTMENT',
'UF_DEPARTMENT',
'UF_DEPARTMENT',
'EXTERNAL_AUTH_ID',
'EXTERNAL_AUTH_ID'])
761 $query->registerRuntimeField(
764 InvitationTable::class,
765 Join::on(
'this.ID',
'ref.USER_ID')->where(
'ref.ORIGINATOR_ID', $currentUserId),
766 [
'join_type' =>
'LEFT']
772 $intranetUsersOnly = isset(
$options[
'intranetUsersOnly']) &&
$options[
'intranetUsersOnly'] ===
true;
773 $extranetUsersOnly = isset(
$options[
'extranetUsersOnly']) &&
$options[
'extranetUsersOnly'] ===
true;
774 $emailUsersOnly = isset(
$options[
'emailUsersOnly']) &&
$options[
'emailUsersOnly'] ===
true;
775 $networkUsersOnly = isset(
$options[
'networkUsersOnly']) &&
$options[
'networkUsersOnly'] ===
true;
793 $query->addFilter(
'UF_DEPARTMENT',
$options[
'departmentId']);
798 $query->where(
'EXTERNAL_AUTH_ID',
'email');
801 $query->whereNotNull(
'INVITATION.ID');
804 else if ($networkUsersOnly)
806 $query->where(
'EXTERNAL_AUTH_ID',
'replica');
808 else if ($intranetUsersOnly)
810 $query->where(
'IS_INTRANET_USER',
'Y');
812 else if ($extranetUsersOnly)
814 $query->where(
'IS_EXTRANET_USER',
'Y');
815 if ($extranetUsersQuery)
817 $query->whereIn(
'ID', $extranetUsersQuery);
822 $filter = Query::filter()->logic(
'or');
826 && !\CSocNetUser::isCurrentUserModuleAdmin()
829 $filter->where(
'IS_INTRANET_USER',
'Y');
833 $filter->addCondition(Query::filter()
835 ->whereNotIn(
'EXTERNAL_AUTH_ID', UserTable::getExternalUserTypes())
836 ->whereNull(
'EXTERNAL_AUTH_ID')
840 if ($emailUsers ===
true)
844 $filter->addCondition(Query::filter()
845 ->where(
'EXTERNAL_AUTH_ID',
'email')
846 ->whereNotNull(
'INVITATION.ID')
851 $filter->where(
'EXTERNAL_AUTH_ID',
'email');
855 if ($networkUsers ===
true)
857 $filter->where(
'EXTERNAL_AUTH_ID',
'replica');
860 if ($extranetUsersQuery)
862 $filter->whereIn(
'ID', $extranetUsersQuery);
863 $filter->addCondition(Query::filter()
864 ->where(Query::filter()
866 ->whereNull(
'EXTERNAL_AUTH_ID')
867 ->whereNot(
'EXTERNAL_AUTH_ID',
'email')
869 ->whereNotNull(
'INVITATION.ID')
873 $query->where($filter);
878 if ($intranetUsersOnly)
880 $query->where(
'IS_INTRANET_USER',
'Y');
882 else if ($extranetUsersOnly)
884 $query->where(
'IS_EXTRANET_USER',
'Y');
888 $query->addFilter(
'!=EXTERNAL_AUTH_ID', UserTable::getExternalUserTypes());
891 if ($extranetUsersQuery)
893 $query->whereIn(
'ID', $extranetUsersQuery);
903 $query->addFilter(
'!=EXTERNAL_AUTH_ID', UserTable::getExternalUserTypes());
906 $userIds = self::prepareUserIds(
$options[
'userId'] ?? []);
907 $notUserIds = self::prepareUserIds(
$options[
'!userId'] ?? []);
910 if (!empty($userIds))
912 $query->whereIn(
'ID', $userIds);
916 if (!empty($notUserIds))
918 $query->whereNotIn(
'ID', $notUserIds);
921 if (empty(
$options[
'order']) && count($userIds) > 1)
923 $query->registerRuntimeField(
926 'FIELD(%s, ' . implode(
',', $userIds) .
')',
931 $query->setOrder(
'ID_SEQUENCE');
935 $query->setOrder(
$options[
'order']);
939 $query->setOrder([
'LAST_NAME' =>
'asc']);
944 $query->setLimit(
$options[
'limit']);
946 elseif (empty($userIds))
948 $query->setLimit(100);
979 $extranetSiteId = Option::get(
'extranet',
'extranet_site');
980 $extranetSiteId = ($extranetSiteId && ModuleManager::isModuleInstalled(
'extranet') ? $extranetSiteId :
false);
984 || \CSocNetUser::isCurrentUserModuleAdmin()
990 $query = UserToGroupTable::query();
991 $query->addSelect(
new ExpressionField(
'DISTINCT_USER_ID',
'DISTINCT %s',
'USER.ID'));
993 $query->whereIn(
'ROLE', self::EXTRANET_ROLES);
994 $query->registerRuntimeField(
997 WorkgroupSiteTable::class,
998 Join::on(
'ref.GROUP_ID',
'this.GROUP_ID')->where(
'ref.SITE_ID', $extranetSiteId),
999 [
'join_type' =>
'INNER']
1003 $query->registerRuntimeField(
1006 UserToGroupTable::class,
1007 Join::on(
'ref.GROUP_ID',
'this.GROUP_ID')
1008 ->where(
'ref.USER_ID', $currentUserId)
1009 ->whereIn(
'ref.ROLE', self::EXTRANET_ROLES),
1010 [
'join_type' =>
'INNER']
1039 foreach ([
'name',
'lastName',
'secondName',
'email',
'login'] as $field)
1041 if (!empty($user->{
'get'.$field}()))
1043 $customData[$field] = $user->{
'get'.$field}();
1047 if (!empty($user->getPersonalGender()))
1049 $customData[
'gender'] = $user->getPersonalGender();
1052 if (!empty($user->getWorkPosition()))
1054 $customData[
'position'] = $user->getWorkPosition();
1057 $userType = self::getUserType($user);
1059 if ($user->getConfirmCode() && in_array($userType, [
'employee',
'integrator']))
1061 $customData[
'invited'] =
true;
1064 if (isset($options[
'selectFields']) && is_array($options[
'selectFields']))
1066 $userData = $user->collectValues();
1067 $allowedFields = static::getAllowedFields();
1068 foreach ($options[
'selectFields'] as $field)
1070 if (!is_string($field))
1075 $dbName = $allowedFields[$field] ??
null;
1076 $value = $userData[$dbName] ??
null;
1079 if ($field ===
'country' || $field ===
'workCountry')
1081 $value = \Bitrix\Main\UserUtils::getCountryValue([
'VALUE' => $value]);
1084 $customData[$field] = $value;
1089 if (isset($options[
'showLogin']) && $options[
'showLogin'] ===
false)
1091 unset($customData[
'login']);
1094 if (isset($options[
'showEmail']) && $options[
'showEmail'] ===
false)
1096 unset($customData[
'email']);
1100 'id' => $user->getId(),
1101 'entityId' => static::ENTITY_ID,
1102 'entityType' => $userType,
1103 'title' => self::formatUserName($user, $options),
1104 'avatar' => self::makeUserAvatar($user),
1105 'customData' => $customData,
1106 'tabs' => static::getTabsNames(),
1109 if (($userType ===
'employee' || $userType ===
'integrator') && Loader::includeModule(
'intranet'))
1111 $isOnVacation = UserAbsence::isAbsentOnVacation($user->getId());
1114 $item->getCustomData()->set(
'isOnVacation',
true);
1129 if (!$user->getActive())
1133 else if ($user->getExternalAuthId() ===
'email')
1137 else if ($user->getExternalAuthId() ===
'replica')
1141 else if (!in_array($user->getExternalAuthId(), UserTable::getExternalUserTypes()))
1143 if (ModuleManager::isModuleInstalled(
'intranet'))
1145 if (self::isIntegrator($user->getId()))
1147 $type =
'integrator';
1151 $ufDepartment = $user->getUfDepartment();
1153 empty($ufDepartment)
1154 || (is_array($ufDepartment) && count($ufDepartment) === 1 && (
int)$ufDepartment[0] === 0)
1180 return \CUser::formatName(
1181 !empty($options[
'nameTemplate']) ? $options[
'nameTemplate'] : \CSite::getNameFormat(
false),
1183 'NAME' => $user->getName(),
1184 'LAST_NAME' => $user->getLastName(),
1185 'SECOND_NAME' => $user->getSecondName(),
1186 'LOGIN' => $user->getLogin(),
1187 'EMAIL' => $user->getEmail(),
1188 'TITLE' => $user->getTitle(),