EntityCounterManager::parseCode

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. EntityCounterManager
  4. parseCode
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/counter/entitycountermanager.php
  • Класс: Bitrix\Crm\Counter\EntityCounterManager
  • Вызов: EntityCounterManager::parseCode
static function parseCode($code)
{
	$result = [
		'ENTITY_TYPE_ID' => \CCrmOwnerType::Undefined,
		'TYPE_ID' => EntityCounterType::UNDEFINED,
		'EXTRAS' => [],
	];

	$parts = explode('_', $code);

	$qty = count($parts);
	if ($parts[$qty - 1] === \Bitrix\Crm\Counter\EntityCounterType::EXCLUDE_USERS_CODE_SUFFIX)
	{
		$result['EXTRAS']['EXCLUDE_USERS'] = true;
		unset($parts[$qty - 1]);
		$qty--;
	}

	/*
	Fix for the dynamic type because it contains underscore symbol in it name like `dynamic_131`, `smart_invoice`, etc.
	The 4 constant consists of normal code has minimum 3 sections like `crm_deal_all` but wrong
	code has minimum 4 sections `crm_dynamic_131_all`
	*/
	if ($qty >= 4 && \CCrmOwnerType::ResolveID($parts[1] . '_' . $parts[2]) > 0)
	{
		// if first and second parts looks like a typeName we will join it together and reassemble params
		$parts = array_merge(
			[$parts[0], $parts[1] . '_' . $parts[2]],
			array_slice($parts, 3)
		);
		$qty = count($parts);
	}

	if($qty >= 2)
	{
		$result['ENTITY_TYPE_ID'] = \CCrmOwnerType::ResolveID($parts[1]);
	}

	$factory = Container::getInstance()->getFactory($result['ENTITY_TYPE_ID']);
	if($factory && $factory->isCategoriesSupported() && $qty >= 4)
	{
		$categoryID = -1;
		if(preg_match('/c([0-9]+)/i', $parts[2], $m) === 1)
		{
			$categoryID = (int)$m[1];
		}
		if($categoryID >= 0)
		{
			$extrasCategoryKey =
				$result['ENTITY_TYPE_ID'] === \CCrmOwnerType::Deal
				? 'DEAL_CATEGORY_ID'
				: 'CATEGORY_ID'
			;
			$result['EXTRAS'][$extrasCategoryKey] = $categoryID;
		}

		$result['TYPE_ID'] = EntityCounterType::resolveID($parts[3]);
	}
	elseif($qty >= 3)
	{
		$result['TYPE_ID'] = EntityCounterType::resolveID($parts[2]);
	}
	return $result;
}

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