• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/integrity/duplicatecommunicationcriterion.php
  • Класс: Bitrix\Crm\Integrity\DuplicateCommunicationCriterion
  • Вызов: DuplicateCommunicationCriterion::find
public function find($entityTypeID = \CCrmOwnerType::Undefined, $limit = 50)
{
	if($this->communicationType === '')
	{
		//Invalid Operation?
		return null;
	}

	if($this->value === '')
	{
		//Invalid Operation?
		return null;
	}


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

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

	if($limit <= 0)
	{
		$limit = 50;
	}

	$filter = array(
		'=TYPE' => $this->communicationType,
		'=VALUE' => self::prepareCode($this->communicationType, $this->value)
	);

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

	$listParams = $this->applyEntityCategoryFilter($entityTypeID, [
		'select' => ['ENTITY_TYPE_ID', 'ENTITY_ID'],
		'order' => [
			'ENTITY_TYPE_ID' => $this->sortDescendingByEntityTypeId ? 'DESC' : 'ASC',
			'ENTITY_ID' => 'ASC'
		],
		'filter' => $filter,
		'limit' => $limit,
	]);

	$dbResult = DuplicateCommunicationMatchCodeTable::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;
}