• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/integrity/duplicatecommunicationcriterion.php
  • Класс: Bitrix\Crm\Integrity\DuplicateCommunicationCriterion
  • Вызов: DuplicateCommunicationCriterion::prepareSearchQuery
public function prepareSearchQuery($entityTypeID = \CCrmOwnerType::Undefined, array $select = null, array $order = null, $limit = 0)
{
	if($this->communicationType === '')
	{
		throw new Main\InvalidOperationException('The field "communicationType" is not assigned.');
	}

	if($this->value === '')
	{
		throw new Main\InvalidOperationException('The field "value" is not assigned.');
	}

	if(!is_int($entityTypeID))
	{
		throw new Main\ArgumentTypeException('entityTypeID', 'integer');
	}

	$query = new Main\Entity\Query(DuplicateCommunicationMatchCodeTable::getEntity());
	if(!is_array($select))
	{
		$select = array();
	}
	if(empty($select))
	{
		$select = array('ENTITY_TYPE_ID', 'ENTITY_ID');
	}
	$query->setSelect($select);

	if(is_array($order) && !empty($order))
	{
		$query->setOrder($order);
	}

	$filter = array('=TYPE' => $this->communicationType,);
	$value = self::prepareCode($this->communicationType, $this->value);
	if($this->useStrictComparison)
	{
		$filter['=VALUE'] = $value;
	}
	else
	{
		$filter['%VALUE'] = new Main\DB\SqlExpression('?s', $value.'%');
	}

	if(\CCrmOwnerType::IsDefined($entityTypeID))
	{
		$filter['ENTITY_TYPE_ID'] = $entityTypeID;
	}

	$query->setFilter($filter);

	if($limit > 0)
	{
		$query->setLimit($limit);
	}

	return $query;
}