• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/userutils.php
  • Класс: BitrixMainUserUtils
  • Вызов: UserUtils::getAdminSearchFilter
static function getAdminSearchFilter(array $fields)
{
	$result = array();

	if (UserIndexTable::getEntity()->fullTextIndexEnabled('SEARCH_ADMIN_CONTENT'))
	{
		$find = '';
		if (array_key_exists('FIND', $fields))
		{
			$find = trim($fields['FIND']);

			if (SearchContent::isIntegerToken($find))
			{
				$find = SearchContent::prepareIntegerToken($find);
			}
			else
			{
				$find = SearchContent::prepareStringToken($find);
			}
		}
		else
		{
			$validFields = Array('ID' => 1, 'NAME' => 1, 'LAST_NAME' => 1, 'SECOND_NAME' => 1, 'WORK_POSITION' => 1, 'EMAIL' => 1, 'LOGIN' => 1);
			foreach ($fields as $key => $value)
			{
				if (isset($validFields[$key]) && $validFields[$key])
				{
					if (SearchContent::isIntegerToken($value))
					{
						$find .= ' '.SearchContent::prepareIntegerToken($value);
					}
					else
					{
						$find .= ' '.SearchContent::prepareStringToken($value);
					}
					$find = trim($find);
				}
			}
		}

		if (SearchContent::canUseFulltextSearch($find, SearchContent::TYPE_MIXED))
		{
			$result['*INDEX.SEARCH_ADMIN_CONTENT'] = $find;
		}
	}
	else
	{
		$helper = Application::getConnection()->getSqlHelper();
		if (array_key_exists('FIND', $fields))
		{
			$find = trim($fields['FIND']);
			$find = explode(' ', $find);
			foreach ($find as $findWord)
			{
				if (!$findWord)
				{
					continue;
				}

				$intResult = Array('LOGIC' => 'OR');
				$validFields = Array('ID', 'NAME', 'LAST_NAME', 'SECOND_NAME', 'WORK_POSITION', 'LOGIN', 'EMAIL');
				foreach ($validFields as $key)
				{
					if ($key == 'ID')
					{
						$intResult['=ID'] = intval($findWord);
					}
					else if ($key == 'LOGIN' || $key == 'EMAIL')
					{
						$intResult['%='.$key] = $helper->forSql($findWord).'%';
					}
					else
					{
						$intResult['%=INDEX.'.$key] = $helper->forSql($findWord).'%';
					}
				}
				$result[] = $intResult;
			}
			if (!empty($result))
			{
				$result['LOGIC'] = 'AND';
				$result = Array($result);
			}
		}
		else
		{
			$validFields = Array('ID' => 1, 'NAME' => 1, 'LAST_NAME' => 1, 'SECOND_NAME' => 1, 'WORK_POSITION' => 1, 'LOGIN' => 1, 'EMAIL' => 1);
			foreach ($fields as $key => $value)
			{
				if (!$value)
				{
					continue;
				}
				if (isset($validFields[$key]))
				{
					if ($key == 'ID')
					{
						$result['=ID'] = intval($value);
					}
					else if ($key == 'LOGIN' || $key == 'EMAIL')
					{
						$result['%='.$key] = $helper->forSql($value).'%';
					}
					else
					{
						$result['%=INDEX.'.$key] = $helper->forSql($value).'%';
					}
				}
			}
		}
	}

	return $result;
}