DuplicateVolatileCriterion::find

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. DuplicateVolatileCriterion
  4. find
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/integrity/duplicatevolatilecriterion.php
  • Класс: Bitrix\Crm\Integrity\DuplicateVolatileCriterion
  • Вызов: DuplicateVolatileCriterion::find
public function find($entityTypeID = CCrmOwnerType::Undefined, $limit = 50): ?Duplicate
{
	if ($this->getVolatileTypeId() === DuplicateIndexType::UNDEFINED)
	{
		return null;
	}

	if ($this->getValue() === '')
	{
		return null;
	}

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

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

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

	$filter = [
		'=TYPE_ID' => $this->getVolatileTypeId(),
		'=VALUE' => $this->getValue(),
	];

	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,
	]);

	$res = DuplicateVolatileMatchCodeTable::getList($listParams);
	$entities = [];
	while ($row = $res->fetch())
	{
		$entityTypeID = (int)($row['ENTITY_TYPE_ID'] ?? 0);
		$entityId = (int)($row['ENTITY_ID'] ?? 0);

		if (CCrmOwnerType::IsDefined($entityTypeID) && $entityId > 0)
		{
			$entities[] = new DuplicateEntity($entityTypeID, $entityId);
		}
	}

	return !empty($entities) ? new Duplicate($this, $entities) : null;
}

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