• Модуль: iblock
  • Путь к файлу: ~/bitrix/modules/iblock/classes/general/iblockelement.php
  • Класс: CAllIBlockElement
  • Вызов: CAllIBlockElement::getUniqueMnemonicCode
public function getUniqueMnemonicCode(string $code, ?int $elementId, int $iblockId, array $options = []): ?string
{
	if ($code === '')
	{
		return false;
	}
	if ($iblockId <= 0)
	{
		return null;
	}

	if (!$this->isExistsMnemonicCode($code, $elementId, $iblockId))
	{
		return $code;
	}

	$checkSimilar = ($options['CHECK_SIMILAR'] ?? 'N') === 'Y';

	$list = [];
	$iterator = IblockElementTable::getList([
		'select' => [
			'ID',
			'CODE',
		],
		'filter' => static::getPublicElementsOrmFilter([
			'=IBLOCK_ID' => $iblockId,
			'%=CODE' => $code . '%',
		]),
	]);
	while ($row = $iterator->fetch())
	{
		if ($checkSimilar && $elementId === (int)$row['ID'])
		{
			return null;
		}
		$list[$row['CODE']] = true;
	}
	unset($iterator, $row);

	if (isset($list[$code]))
	{
		$code .= '_';
		$i = 1;
		while (isset($list[$code . $i]))
		{
			$i++;
		}

		$code .= $i;
	}
	unset($list);

	return $code;
}