DuplicateVolatileCriterion::checkIndex

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. DuplicateVolatileCriterion
  4. checkIndex
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/integrity/duplicatevolatilecriterion.php
  • Класс: Bitrix\Crm\Integrity\DuplicateVolatileCriterion
  • Вызов: DuplicateVolatileCriterion::checkIndex
static function checkIndex(array $params): bool
{
	$entityTypeId =
		isset($params['ENTITY_TYPE_ID'])
			? intval($params['ENTITY_TYPE_ID'])
			: CCrmOwnerType::Undefined
	;
	if ($entityTypeId !== CCrmOwnerType::Undefined
		&& $entityTypeId !== CCrmOwnerType::Lead
		&& $entityTypeId !== CCrmOwnerType::Contact
		&& $entityTypeId !== CCrmOwnerType::Company
	)
	{
		throw new NotSupportedException(
			"Entity type: '"
			. CCrmOwnerType::ResolveName($entityTypeId)
			. "' is not supported in current context"
		);
	}

	$volatileTypeId = isset($params['TYPE_ID']) ? intval($params['TYPE_ID']) : DuplicateIndexType::UNDEFINED;
	if(!static::isSupportedType($volatileTypeId))
	{
		throw new NotSupportedException(
			"Criterion type(s): '"
			. DuplicateIndexType::resolveName($volatileTypeId)
			. "' is not supported in current context"
		);
	}

	$userId = isset($params['USER_ID']) ? intval($params['USER_ID']) : 0;

	$scope = null;
	if (isset($params['SCOPE']))
	{
		$scope = $params['SCOPE'];
		if (!DuplicateIndexType::checkScopeValue($scope))
		{
			throw new ArgumentException("Parameter has invalid value", 'SCOPE');
		}
	}

	$filter = array(
		'=USER_ID' => $userId,
		'=ENTITY_TYPE_ID' => $entityTypeId,
		'=TYPE_ID' => $volatileTypeId
	);

	if ($scope !== null)
	{
		$filter['=SCOPE'] = $scope;
	}

	$listParams = array(
		'select' => array('USER_ID', 'TYPE_ID', 'ENTITY_TYPE_ID'),
		'order' => array('USER_ID'=>'ASC', 'TYPE_ID'=>'ASC', 'ENTITY_TYPE_ID'=>'ASC'),
		'filter' => $filter,
		'limit' => 1
	);

	$dbResult = DuplicateIndexTable::getList($listParams);

	return is_array($dbResult->fetch());
}

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