CAllCrmQuote::__AfterPrepareSql

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CAllCrmQuote
  4. __AfterPrepareSql
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_quote.php
  • Класс: \CAllCrmQuote
  • Вызов: CAllCrmQuote::__AfterPrepareSql
static function __AfterPrepareSql(/*CCrmEntityListBuilder*/ $sender, $arOrder, $arFilter, $arGroupBy, $arSelectFields)
{
	$sqlData = array('FROM' => array(), 'WHERE' => array());
	if(isset($arFilter['SEARCH_CONTENT']) && $arFilter['SEARCH_CONTENT'] !== '')
	{
		$tableAlias = $sender->GetTableAlias();
		$queryWhere = new CSQLWhere();
		$queryWhere->SetFields(
			array(
				'SEARCH_CONTENT' => array(
					'FIELD_NAME' => "{$tableAlias}.SEARCH_CONTENT",
					'FIELD_TYPE' => 'string',
					'JOIN' => false
				)
			)
		);
		$options = [];
		if (isset($arFilter['__ENABLE_SEARCH_CONTENT_PHONE_DETECTION']))
		{
			$options['ENABLE_PHONE_DETECTION'] = $arFilter['__ENABLE_SEARCH_CONTENT_PHONE_DETECTION'];
			unset($arFilter['__ENABLE_SEARCH_CONTENT_PHONE_DETECTION']);
		}
		$query = $queryWhere->GetQuery(
			Crm\Search\SearchEnvironment::prepareEntityFilter(
				CCrmOwnerType::Quote,
				array(
					'SEARCH_CONTENT' => Crm\Search\SearchEnvironment::prepareSearchContent($arFilter['SEARCH_CONTENT'], $options)
				)
			)
		);
		if($query !== '')
		{
			$sqlData['WHERE'][] = $query;
		}
	}

	// Applying filter by PRODUCT_ID

	// Applying filter by PRODUCT_ID
	$operationInfo = Crm\UI\Filter\EntityHandler::findFieldOperation('PRODUCT_ROW_PRODUCT_ID', $arFilter);
	if(is_array($operationInfo))
	{
		$prodID = (int)$operationInfo['CONDITION'];
		if($prodID > 0 && $operationInfo['OPERATION'] === '=')
		{
			$tableAlias = $sender->GetTableAlias();
			$sqlData['WHERE'][] = "{$tableAlias}.ID IN (SELECT DP.OWNER_ID from b_crm_product_row DP where DP.OWNER_TYPE = 'Q' and DP.OWNER_ID = {$tableAlias}.ID and DP.PRODUCT_ID = {$prodID})";
		}
	}

	$operationInfo = Crm\UI\Filter\EntityHandler::findFieldOperation('ASSOCIATED_CONTACT_ID', $arFilter);
	if(is_array($operationInfo))
	{
		if($operationInfo['OPERATION'] === '=')
		{
			$sqlData['FROM'][] = QuoteContactTable::prepareFilterJoinSql(
				CCrmOwnerType::Contact,
				$operationInfo['CONDITION'],
				$sender->GetTableAlias()
			);
		}
	}

	Tracking\UI\Filter::buildFilterAfterPrepareSql(
		$sqlData,
		$arFilter,
		\CCrmOwnerType::Quote,
		$sender->GetTableAlias()
	);

	$result = array();
	if(!empty($sqlData['FROM']))
	{
		$result['FROM'] = implode(' ', $sqlData['FROM']);
	}
	if(!empty($sqlData['WHERE']))
	{
		$result['WHERE'] = implode(' AND ', $sqlData['WHERE']);
	}

	return !empty($result) ? $result : false;
}

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