• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/binding/contactcompany.php
  • Класс: Bitrix\Crm\Binding\ContactCompanyTable
  • Вызов: ContactCompanyTable::prepareFilterJoinSqlByTitle
static function prepareFilterJoinSqlByTitle($entityTypeID, $entityTitle, $tableAlias)
{
	if(!is_int($entityTypeID))
	{
		$entityTypeID = (int)$entityTypeID;
	}

	if(!\CCrmOwnerType::IsDefined($entityTypeID))
	{
		throw new Main\ArgumentOutOfRangeException('entityTypeID',
			\CCrmOwnerType::FirstOwnerType,
			\CCrmOwnerType::LastOwnerType
		);
	}

	if(!is_string($entityTitle))
	{
		$entityTitle = (string)$entityTitle;
	}

	if($entityTitle === '')
	{
		return '';
	}

	$where = new \CSQLWhere();

	$entityTitle = $where->ForLIKE($entityTitle);

	if($entityTypeID === \CCrmOwnerType::Company)
	{
		return "INNER JOIN (
			SELECT CC.CONTACT_ID FROM b_crm_contact_company CC INNER JOIN b_crm_company C 
				ON C.ID = CC.COMPANY_ID AND C.TITLE LIKE '{$entityTitle}%' ESCAPE '!' GROUP BY CC.CONTACT_ID
		) CC ON {$tableAlias}.ID = CC.CONTACT_ID";
	}

	$entityTypeName = \CCrmOwnerType::ResolveName($entityTypeID);
	throw new Main\NotSupportedException("Entity type: '{$entityTypeName}' is not supported in current context");
}