CAllCrmLead::PrepareFilter

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CAllCrmLead
  4. PrepareFilter
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_lead.php
  • Класс: \CAllCrmLead
  • Вызов: CAllCrmLead::PrepareFilter
static function PrepareFilter(&$arFilter, $arFilter2Logic = null)
{
	if(!is_array($arFilter2Logic))
	{
		$arFilter2Logic = array('TITLE', 'NAME', 'LAST_NAME', 'SECOND_NAME', 'POST', 'ADDRESS', 'COMMENTS', 'COMPANY_TITLE');
	}

	// converts data from filter
	if (isset($arFilter['FIND_list']) && !empty($arFilter['FIND']))
	{
		if ($arFilter['FIND_list'] == 't_n_ln')
		{
			$find = $arFilter['FIND'];
			$arFilter['__INNER_FILTER'] = array(
				'LOGIC' => 'OR',
				'%TITLE' => $find,
				'$NAME' => $find,
				'%LAST_NAME' => $find,
				'%COMPANY_TITLE' => $find
			);
		}
		else
		{
			$arFilter[mb_strtoupper($arFilter['FIND_list'])] = $arFilter['FIND'];
		}
		unset($arFilter['FIND_list'], $arFilter['FIND']);
	}

	static $arImmutableFilters = array(
		'FM', 'ID', 'CURRENCY_ID',
		'ASSIGNED_BY_ID', 'CREATED_BY_ID', 'MODIFY_BY_ID',
		'PRODUCT_ROW_PRODUCT_ID',
		'HAS_PHONE', 'HAS_EMAIL', 'HAS_IMOL',
		'WEBFORM_ID',
		'SEARCH_CONTENT',
		'FILTER_ID', 'FILTER_APPLIED', 'PRESET_ID'
	);

	foreach ($arFilter as $k => $v)
	{
		if(in_array($k, $arImmutableFilters, true))
		{
			continue;
		}

		$arMatch = array();

		if(in_array($k, array('PRODUCT_ID', 'STATUS_ID', 'SOURCE_ID', 'COMPANY_ID', 'CONTACT_ID')))
		{
			// Bugfix #23121 - to suppress comparison by LIKE
			$arFilter['='.$k] = $v;
			unset($arFilter[$k]);
		}
		elseif($k === 'ORIGINATOR_ID')
		{
			// HACK: build filter by internal entities
			$arFilter['=ORIGINATOR_ID'] = $v !== '__INTERNAL' ? $v : null;
			unset($arFilter[$k]);
		}
		elseif($k === 'ADDRESS'
			|| $k === 'ADDRESS_2'
			|| $k === 'ADDRESS_CITY'
			|| $k === 'ADDRESS_REGION'
			|| $k === 'ADDRESS_PROVINCE'
			|| $k === 'ADDRESS_POSTAL_CODE'
			|| $k === 'ADDRESS_COUNTRY')
		{
			$arFilter["=%{$k}"] = "{$v}%";
			unset($arFilter[$k]);
		}
		elseif (preg_match('/(.*)_from$/i'.BX_UTF_PCRE_MODIFIER, $k, $arMatch))
		{
			if($v <> '')
			{
				$arFilter['>='.$arMatch[1]] = $v;
			}
			unset($arFilter[$k]);
		}
		elseif (preg_match('/(.*)_to$/i'.BX_UTF_PCRE_MODIFIER, $k, $arMatch))
		{
			if($v <> '')
			{
				if (($arMatch[1] == 'DATE_CREATE' || $arMatch[1] == 'DATE_MODIFY' || $arMatch[1] == 'DATE_CLOSED')
					&& !preg_match('/\d{1,2}:\d{1,2}(:\d{1,2})?$/'.BX_UTF_PCRE_MODIFIER, $v))
				{
					$v = CCrmDateTimeHelper::SetMaxDayTime($v);
				}
				$arFilter['<='.$arMatch[1]] = $v;
			}
			unset($arFilter[$k]);
		}
		elseif (in_array($k, $arFilter2Logic))
		{
			// Bugfix #26956 - skip empty values in logical filter
			$v = trim($v);
			if($v !== '')
			{
				$arFilter['?'.$k] = $v;
			}
			unset($arFilter[$k]);
		}
		elseif($k === 'STATUS_CONVERTED')
		{
			if($v !== '')
			{
				$arFilter[$v === 'N' ? '!@STATUS_ID' : '@STATUS_ID'] = array('JUNK', 'CONVERTED');
			}
			unset($arFilter['STATUS_CONVERTED']);
		}
		elseif ($k != 'ID' && $k != 'LOGIC' && $k != '__INNER_FILTER' && mb_strpos($k, 'UF_') !== 0 && preg_match('/^[^\=\%\?\>\<]{1}/', $k) === 1)
		{
			$arFilter['%'.$k] = $v;
			unset($arFilter[$k]);
		}
	}
}

Добавить комментарий