• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/integrity/duplicatecommunicationcriterion.php
  • Класс: Bitrix\Crm\Integrity\DuplicateCommunicationCriterion
  • Вызов: DuplicateCommunicationCriterion::checkIndex
static function checkIndex(array $params)
{
	$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 Main\NotSupportedException("Entity type: '".\CCrmOwnerType::ResolveName($entityTypeID)."' is not supported in current context");
	}

	$typeID = isset($params['TYPE_ID']) ? intval($params['TYPE_ID']) : DuplicateIndexType::UNDEFINED;
	if(
		$typeID !== DuplicateIndexType::COMMUNICATION_PHONE
		&& $typeID !== DuplicateIndexType::COMMUNICATION_EMAIL
		&& $typeID !== DuplicateIndexType::COMMUNICATION_SLUSER
	)
	{
		throw new Main\NotSupportedException("Criterion type(s): '".DuplicateIndexType::resolveName($typeID)."' 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 Main\ArgumentException("Parameter has invalid value", 'SCOPE');
		}
	}

	$filter = array(
		'=USER_ID' => $userID,
		'=ENTITY_TYPE_ID' => $entityTypeID,
		'=TYPE_ID' => $typeID
	);
	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 = Entity\DuplicateIndexTable::getList($listParams);
	return is_array($dbResult->fetch());
}