DuplicatePersonCriterion::prepareSearchQuery

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

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

	$query = new Main\Entity\Query(DuplicatePersonMatchCodeTable::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();
	if($this->useStrictComparison)
	{
		$filter['=LAST_NAME'] = self::prepareCode($this->lastName);
	}
	else
	{
		$filter['%LAST_NAME'] = new Main\DB\SqlExpression('?s', self::prepareCode($this->lastName).'%');
	}

	if($this->name !== '')
	{
		if($this->useStrictComparison)
		{
			$filter['=NAME'] = self::prepareCode($this->name);
		}
		else
		{
			$filter['%NAME'] = new Main\DB\SqlExpression('?s', self::prepareCode($this->name).'%');
		}
	}

	if($this->secondName !== '')
	{
		if($this->useStrictComparison)
		{
			$filter['=SECOND_NAME'] = self::prepareCode($this->secondName);
		}
		else
		{
			$filter['%SECOND_NAME'] = new Main\DB\SqlExpression('?s', self::prepareCode($this->secondName).'%');
		}
	}

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

	$query->setFilter($filter);

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

	return $query;
}

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