• Модуль: im
  • Путь к файлу: ~/bitrix/modules/im/classes/general/im_contact_list.php
  • Класс: CAllIMContactList
  • Вызов: CAllIMContactList::SearchUsers
function SearchUsers($searchText)
{
	$searchText = trim($searchText);
	if (mb_strlen($searchText) < 3)
	{
		$GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_CL_SEARCH_EMPTY"), "ERROR_SEARCH_EMPTY");
		return false;
	}

	$nameTemplate = self::GetUserNameTemplate(SITE_ID);
	$nameTemplateSite = CSite::GetNameFormat(false);

	$filter = BitrixMainUserUtils::getUserSearchFilter(Array('FIND'=> $searchText));
	$filter["=ACTIVE"] = "Y";
	$filter["=CONFIRM_CODE"] = false;
	$filter["=IS_REAL_USER"] = "Y";

	$bIntranetEnable = IsModuleInstalled('intranet');
	$bVoximplantEnable = IsModuleInstalled('voximplant');

	if (!$bIntranetEnable)
	{
		$arSettings = CIMSettings::GetDefaultSettings(CIMSettings::SETTINGS);
		if ($arSettings[CIMSettings::PRIVACY_SEARCH] == CIMSettings::PRIVACY_RESULT_ALL)
			$filter['!=UF_IM_SEARCH'] = CIMSettings::PRIVACY_RESULT_CONTACT;
		else
			$filter['=UF_IM_SEARCH'] = CIMSettings::PRIVACY_RESULT_ALL;
	}

	$select = Array(
		"ID", "LAST_NAME", "NAME", "SECOND_NAME", "LOGIN", "PERSONAL_PHOTO", "PERSONAL_BIRTHDAY", "WORK_POSITION", "PERSONAL_GENDER", "EXTERNAL_AUTH_ID", "TIME_ZONE_OFFSET", "ACTIVE", "UF_IM_SEARCH", "LAST_ACTIVITY_DATE",
		"COLOR" => "ST.COLOR", "STATUS" =>	"ST.STATUS", "IDLE" => "ST.IDLE", "MOBILE_LAST_DATE" => "ST.MOBILE_LAST_DATE", "DESKTOP_LAST_DATE" => "ST.DESKTOP_LAST_DATE",
	);
	if($bIntranetEnable)
		$select[] = 'UF_DEPARTMENT';
	if ($bVoximplantEnable)
		$select[] = 'UF_VI_PHONE';

	$bots = BitrixImBot::getListCache();

	$orm = BitrixMainUserTable::getList(Array(
		'select' => $select,
		'filter' => $filter,
		'runtime' => Array(
			new BitrixMainEntityReferenceField(
				'ST',
				'BitrixImModelStatusTable',
				array(
					"=ref.USER_ID" => "this.ID",
				),
				array("join_type"=>"LEFT")
			)
		),
		'order' => Array('LAST_NAME' => 'ASC')
	));
	$arUsers = Array();
	while ($arUser = $orm->fetch())
	{
		$arUser['PERSONAL_BIRTHDAY'] = $arUser['PERSONAL_BIRTHDAY'] instanceof BitrixMainTypeDate? $arUser['PERSONAL_BIRTHDAY']->format('d-m'): false;
		$arUser['LAST_ACTIVITY_DATE'] = $arUser['LAST_ACTIVITY_DATE'] instanceof BitrixMainTypeDateTime? $arUser['LAST_ACTIVITY_DATE']: false;

		$arUser = CIMStatus::prepareLastDate($arUser);

		$userExternalAuthId = $arUser['EXTERNAL_AUTH_ID']? $arUser['EXTERNAL_AUTH_ID']: 'default';
		if (
			$userExternalAuthId == BitrixImBot::EXTERNAL_AUTH_ID
			&& $bots[$arUser["ID"]]['TYPE'] == BitrixImBot::TYPE_NETWORK
			&& (
				$bots[$arUser["ITEM_ID"]]['CLASS'] == BitrixImBotBotSupport24::class
				|| $bots[$arUser["ITEM_ID"]]['CLASS'] == BitrixImBotBotPartner24::class
				|| $bots[$arUser["ITEM_ID"]]['CLASS'] == BitrixImBotBotSaleSupport24::class
			)
		)
		{
			$userExternalAuthId = 'support24';
		}

		$arUsers[$arUser["ID"]] = Array(
			'id' => $arUser["ID"],
			'name' => BitrixImUser::formatFullNameFromDatabase($arUser),
			'active' => $arUser['ACTIVE'] == 'Y',
			'first_name' => BitrixImUser::formatNameFromDatabase($arUser),
			'last_name' => $arUser['LAST_NAME'],
			'work_position' => $arUser['WORK_POSITION'],
			'color' => self::GetUserColor($arUser["ID"], $arUser['PERSONAL_GENDER'] == 'M'? 'M': 'F'),
			'avatar' => CIMChat::GetAvatarImage($arUser["PERSONAL_PHOTO"]),
			'birthday' => $arUser['PERSONAL_BIRTHDAY'],
			'gender' => $arUser['PERSONAL_GENDER'] == 'F'? 'F': 'M',
			'phone_device' => $bVoximplantEnable && $arUser['UF_VI_PHONE'] == 'Y',
			'extranet' => self::IsExtranet($arUser),
			'network' => $arUser['EXTERNAL_AUTH_ID'] == self::NETWORK_AUTH_ID || $arUser['EXTERNAL_AUTH_ID'] == BitrixImBot::EXTERNAL_AUTH_ID && $bots[$arUser["ID"]]['TYPE'] == BitrixImBot::TYPE_NETWORK,
			'bot' => $arUser['EXTERNAL_AUTH_ID'] == BitrixImBot::EXTERNAL_AUTH_ID,
			'tz_offset' => intval($arUser['TIME_ZONE_OFFSET']),
			'profile' => CIMContactList::GetUserPath($arUser["ID"]),
			'search_mark' => $searchText,
			'external_auth_id' => $userExternalAuthId,
			'status' => $arUser['STATUS'],
			'idle' => $arUser['IDLE'],
			'last_activity_date' => $arUser['LAST_ACTIVITY_DATE'],
			'mobile_last_date' => $arUser['MOBILE_LAST_DATE'],
			'desktop_last_date' => $arUser['DESKTOP_LAST_DATE'],
			'absent' => self::formatAbsentResult($arUser["ID"]),
		);
	}

	if (CModule::IncludeModule('imbot'))
	{
		$result = BitrixImBotBotNetwork::search($searchText);
		if ($result)
		{
			foreach ($result as $arLine)
			{
				$id = 'networkLines'.$arLine["CODE"];
				$arUsers[$id] = Array(
					'id' => $id,
					'name' => htmlspecialcharsbx($arLine["LINE_NAME"]),
					'work_position' => $arLine["LINE_DESC"]? htmlspecialcharsbx($arLine["LINE_DESC"]): GetMessage('IM_SEARCH_OL'),
					'color' => IMColor::getColor('GRAY'),
					'avatar' => empty($arLine['LINE_AVATAR'])? '/bitrix/js/im/images/blank.gif': $arLine['LINE_AVATAR'],
					'birthday' => false,
					'gender' => 'M',
					'phone_device' => false,
					'tz_offset' => 0,
					'extranet' => true,
					'network' => true,
					'bot' => true,
					'profile' => '',
					'select' => 'Y',
					'network_id' => $arLine["CODE"],
					'search_mark' => $searchText,
					'external_auth_id' => 'network',
					'status' => 'online',
					'idle' => false,
					'last_activity_date' => false,
					'mobile_last_date' => false,
					'desktop_last_date' => false,
					'absent' => false,
				);
			}
		}
	}

	return Array('users' => $arUsers);
}