• Модуль: crmmobile
  • Путь к файлу: ~/bitrix/modules/crmmobile/lib/Controller/Category.php
  • Класс: BitrixCrmMobileControllerCategory
  • Вызов: Category::setAction
public function setAction(Factory $factory, int $categoryId): array
{
	$userPermissions = Container::getInstance()->getUserPermissions();

	$entityTypeId = $factory->getEntityTypeId();

	$canRead = false;
	if ($categoryId >= 0)
	{
		$canRead = $userPermissions->checkReadPermissions($entityTypeId, 0, $categoryId);
	}

	if (!$canRead)
	{
		$categoriesCollection = $this->getCategoriesCollection($factory);
		$category = array_shift($categoriesCollection);
		if (!$category)
		{
			return [
				'categoryId' => null,
			];
		}

		$categoryId = $category->getId();
		$canRead = true;
	}

	if ($entityTypeId === CCrmOwnerType::Deal && $categoryId >= 0)
	{
		CUserOptions::SetOption('crm', 'current_deal_category', $categoryId);
	}
	else if (CCrmOwnerType::isPossibleDynamicTypeId($entityTypeId) && $categoryId >= 0)
	{
		$optionName = 'current_' . mb_strtolower($factory->getEntityName()) . '_category';
		CUserOptions::SetOption('crm', $optionName, $categoryId);
	}

	$entity = Entity::getInstance(CCrmOwnerType::ResolveName($entityTypeId));
	$userId = (int)$this->getCurrentUser()->getId();

	$searchRestriction = BitrixCrmRestrictionRestrictionManager::getSearchLimitRestriction();
	$infoHelperId = $searchRestriction->getMobileInfoHelperId();

	return [
		'permissions' => [
			'add' => $userPermissions->checkAddPermissions($entityTypeId, $categoryId),
			'read' => $canRead,
			'delete' => $userPermissions->checkDeletePermissions($entityTypeId, 0, $categoryId),
			'update' => $userPermissions->checkUpdatePermissions($entityTypeId, 0, $categoryId),
		],
		'link' => $entity->getDesktopLink($categoryId),
		'counters' => $entity->getCounters($userId, $categoryId),
		'categoryId' => $categoryId,
		'sortType' => $this->getSortType($entityTypeId, $categoryId),
		'restrictions' => [
			'search' => [
				'isExceeded' => $searchRestriction->isExceeded($entityTypeId),
				'infoHelperId' => $infoHelperId,
			],
		],
	];
}