• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/integrity/duplicatepersoncriterion.php
  • Класс: Bitrix\Crm\Integrity\DuplicatePersonCriterion
  • Вызов: DuplicatePersonCriterion::find
public function find($entityTypeID = \CCrmOwnerType::Undefined, $limit = 50)
{
	$lastName = static::prepareCode($this->lastName);
	$name = static::prepareCode($this->name);
	$secondName = static::prepareCode($this->secondName);

	if($lastName === '')
	{
		//Invalid Operation?
		return null;
	}

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

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

	$listParams = array(
		'select' =>array('ENTITY_TYPE_ID', 'ENTITY_ID'),
		'order' => array(
			'ENTITY_TYPE_ID' => $this->sortDescendingByEntityTypeId ? 'DESC' : 'ASC',
			'ENTITY_ID' => 'ASC'
		),
		'filter' => array('=LAST_NAME' => $lastName)
	);

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

	if($name !== '')
	{
		$listParams['filter']['=NAME'] = $name;
	}

	if($secondName !== '')
	{
		$listParams['filter']['=SECOND_NAME'] = $secondName;
	}

	if($limit > 0)
	{
		$listParams['limit'] = $limit;
	}

	$listParams = $this->applyEntityCategoryFilter($entityTypeID, $listParams);

	$dbResult = DuplicatePersonMatchCodeTable::getList($listParams);
	$entities = array();
	while($fields = $dbResult->fetch())
	{
		$entityTypeID = isset($fields['ENTITY_TYPE_ID']) ? intval($fields['ENTITY_TYPE_ID']) : 0;
		$entityID = isset($fields['ENTITY_ID']) ? intval($fields['ENTITY_ID']) : 0;

		if(\CCrmOwnerType::IsDefined($entityTypeID) && $entityID > 0)
		{
			$entities[] = new DuplicateEntity($entityTypeID, $entityID);
		}
	}
	return !empty($entities) ? new Duplicate($this, $entities) : null;
}