CCrmPerms::ResolvePermissionEntityType

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CCrmPerms
  4. ResolvePermissionEntityType
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_perms.php
  • Класс: \CCrmPerms
  • Вызов: CCrmPerms::ResolvePermissionEntityType
static function ResolvePermissionEntityType($entityType, $entityID, array $parameters = null)
{
	if(!is_integer($entityID))
	{
		$entityID = (int)$entityID;
	}

	$entityTypeId = \CCrmOwnerType::ResolveID($entityType);
	$factory = Container::getInstance()->getFactory($entityTypeId);
	if (!$factory || !$factory->isCategoriesSupported())
	{
		return $entityType;
	}

	$categoryID = is_array($parameters) && isset($parameters['CATEGORY_ID'])
		? (int)$parameters['CATEGORY_ID'] : -1;

	if($categoryID < 0 && $entityID > 0)
	{
		if ($factory instanceof \Bitrix\Crm\Service\Factory\Deal)
		{
			//todo temporary decision while Deal Factory does not support work with items.
			$categoryID = CCrmDeal::GetCategoryID($entityID);
		}
		else
		{
			$items = $factory->getItems([
				'select' => [\Bitrix\Crm\Item::FIELD_NAME_CATEGORY_ID],
				'filter' => [
					'=ID' => $entityID
				],
				'limit' => 1,
			]);
			if (isset($items[0]))
			{
				$categoryID = $items[0]->getCategoryId();
			}
		}
	}

	return \Bitrix\Crm\Service\UserPermissions::getPermissionEntityType($entityTypeId, $categoryID);
}

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