DuplicateRequisiteCriterion::bulkRegister

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. DuplicateRequisiteCriterion
  4. bulkRegister
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/integrity/duplicaterequisitecriterion.php
  • Класс: Bitrix\Crm\Integrity\DuplicateRequisiteCriterion
  • Вызов: DuplicateRequisiteCriterion::bulkRegister
static function bulkRegister($entityTypeID, $entityID, array $data, $isRaw = true)
{
	if(!is_int($entityTypeID))
	{
		throw new Main\ArgumentTypeException('entityTypeID', 'integer');
	}

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

	if(!$isRaw)
	{
		$effectiveData = $data;
	}
	else
	{
		$effectiveData = array();
		foreach($data as $countryId => $fields)
		{
			if(is_array($fields))
			{
				foreach ($fields as $fieldName => $values)
				{
					if (is_array($values))
					{
						$effectiveData[$countryId][$fieldName] =
							self::prepareCodes($countryId, $fieldName, $values);
					}
				}
			}
		}
	}

	DuplicateRequisiteMatchCodeTable::bulkReplaceValues($entityTypeID, $entityID, $effectiveData);

	$typesToUnregister = array();
	$scopesToUnregister = array();
	foreach (self::getFieldsMap() as $countryId => $fields)
	{
		$scope = EntityRequisite::formatDuplicateCriterionScope($countryId);
		if (is_array($effectiveData[$countryId] ?? null) && !empty($effectiveData[$countryId]))
		{
			foreach ($fields as $fieldName)
			{
				$typeID = DuplicateIndexType::resolveID($fieldName);
				if (is_array($effectiveData[$countryId][$fieldName] ?? null)
					&& !empty($effectiveData[$countryId][$fieldName]))
				{
					DuplicateEntityMatchHash::unregisterEntity($entityTypeID, $entityID, $typeID, $scope);
					foreach($effectiveData[$countryId][$fieldName] as $value)
					{
						DuplicateEntityMatchHash::register(
							$entityTypeID, $entityID, $typeID,
							self::prepareMatchHash(array(
								'RQ_COUNTRY_ID' => $countryId,
								'RQ_FIELD_NAME' => $fieldName,
								'VALUE' => $value
							)),
							true, $scope
						);
					}
				}
				else
				{
					if (!is_array($typesToUnregister[$scope] ?? null))
					{
						$typesToUnregister[$scope] = [];
					}
					$typesToUnregister[$scope][] = $typeID;
				}
			}
		}
		else
		{
			if (!is_array($scopesToUnregister[$scope] ?? null))
			{
				$scopesToUnregister[$scope] = [];
			}
			foreach ($fields as $fieldName)
			{
				$typeID = DuplicateIndexType::resolveID($fieldName);
				$scopesToUnregister[$scope][] = $typeID;
			}
		}
	}
	foreach ($typesToUnregister as $scope => $types)
	{
		DuplicateEntityMatchHash::unregisterEntity($entityTypeID, $entityID, $types, $scope);
	}
	foreach ($scopesToUnregister as $scope => $types)
	{
		DuplicateEntityMatchHash::unregisterEntity($entityTypeID, $entityID, $types, $scope);
	}
}

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