• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/integrity/duplicatepersoncriterion.php
  • Класс: Bitrix\Crm\Integrity\DuplicatePersonCriterion
  • Вызов: DuplicatePersonCriterion::register
static function register($entityTypeID, $entityID, $lastName, $name, $secondName, $isRaw = true)
{
	if(!is_int($entityTypeID))
	{
		throw new Main\ArgumentTypeException('entityTypeID', 'integer');
	}

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

	if(!is_string($lastName))
	{
		throw new Main\ArgumentTypeException('lastName', 'string');
	}

	if(!is_string($name))
	{
		throw new Main\ArgumentTypeException('name', 'string');
	}

	if(!is_string($secondName))
	{
		throw new Main\ArgumentTypeException('secondName', 'string');
	}

	if($isRaw)
	{
		$lastName = self::prepareCode($lastName);
		$name = self::prepareCode($name);
		$secondName = self::prepareCode($secondName);
	}

	self::unregister($entityTypeID, $entityID);

	if($lastName !== '')
	{
		DuplicatePersonMatchCodeTable::add(
			array(
				'ENTITY_TYPE_ID' => $entityTypeID,
				'ENTITY_ID' => $entityID,
				'NAME' => $name,
				'SECOND_NAME' => $secondName,
				'LAST_NAME' => $lastName
			)
		);

		$matches = array('LAST_NAME' => $lastName);
		if($name !== '')
		{
			$matches['NAME'] = $name;
		}
		if($secondName !== '')
		{
			$matches['SECOND_NAME'] = $secondName;
		}

		DuplicateEntityMatchHash::unregisterEntity($entityTypeID, $entityID, DuplicateIndexType::PERSON);

		DuplicateEntityMatchHash::register(
			$entityTypeID,
			$entityID,
			DuplicateIndexType::PERSON,
			self::prepareMatchHash($matches),
			true
		);

		if(isset($matches['SECOND_NAME']))
		{
			unset($matches['SECOND_NAME']);
			DuplicateEntityMatchHash::register(
				$entityTypeID,
				$entityID,
				DuplicateIndexType::PERSON,
				self::prepareMatchHash($matches),
				false
			);
		}

		if(isset($matches['NAME']))
		{
			unset($matches['NAME']);
			DuplicateEntityMatchHash::register(
				$entityTypeID,
				$entityID,
				DuplicateIndexType::PERSON,
				self::prepareMatchHash($matches),
				false
			);
		}
	}
}