- Модуль: crmmobile
- Путь к файлу: ~/bitrix/modules/crmmobile/lib/Controller/Category.php
- Класс: BitrixCrmMobileControllerCategory
- Вызов: Category::getCategoryById
private function getCategoryById(Factory $factory, int $categoryId): ?DtoCategory
{
$categoryNotFound = false;
$category = ($factory->isCategoriesSupported() ? $factory->getCategory($categoryId) : null);
if (!$category)
{
$categoryNotFound = true;
$category = $factory->createCategory([
'ID' => $categoryId,
'NAME' => "#{$categoryId}",
]);
}
if (!Container::getInstance()->getUserPermissions()->canViewItemsInCategory($category))
{
$this->addError(ErrorCode::getAccessDeniedError());
return null;
}
$categoriesEnabled = $factory->isCategoriesEnabled();
$stagesEnabled = $factory->isStagesEnabled();
$tunnelsEnabled = $categoriesEnabled && $stagesEnabled;
$stageObjects = $factory->getStages($categoryId);
$stageColors = $this->getStageColors($stageObjects);
$canUserEditCategory = Container::getInstance()->getUserPermissions()->canWriteConfig();
$filteredTunnelsByCategory = [];
if ($tunnelsEnabled && $canUserEditCategory)
{
$tunnelScheme = (new TunnelManager($factory->getEntityTypeId()))->getScheme();
$filteredTunnelsByCategory = array_reduce($tunnelScheme['stages'],
function ($acc, $stage) use ($factory, $categoryId, $stageColors) {
if ($stage['categoryId'] === $categoryId)
{
foreach ($stage['tunnels'] as $tunnel)
{
$tunnelData = $this->prepareTunnelData($factory, $tunnel, $stageColors);
if (!is_null($tunnelData))
{
$acc[$stage['stageId']][] = $tunnelData;
}
}
}
return $acc;
}, []);
}
$stagesBySemantics = $this->getStagesBySemantics($stageObjects, $filteredTunnelsByCategory, $stageColors);
if ($categoryNotFound && empty($stagesBySemantics))
{
$this->addError(ErrorCode::getNotFoundError());
return null;
}
$entityTypeId = $factory->getEntityTypeId();
$permissions = $this->getCategoryPermissions($entityTypeId, $categoryId);
return new DtoCategory([
'id' => $category->getId(),
'name' => $categoriesEnabled ? $category->getName() : $factory->getEntityDescriptionInPlural(),
'isDefault' => $category->getIsDefault(),
'editable' => $this->canUserEditCategory(),
'access' => $this->getAccess($permissions),
'categoriesSupported' => $factory->isCategoriesSupported(),
'categoriesEnabled' => $categoriesEnabled,
'stagesEnabled' => $stagesEnabled,
'tunnelsEnabled' => $tunnelsEnabled,
'processStages' => $stagesBySemantics[PhaseSemantics::PROCESS] ?? [],
'successStages' => $stagesBySemantics[PhaseSemantics::SUCCESS] ?? [],
'failedStages' => $stagesBySemantics[PhaseSemantics::FAILURE] ?? [],
'documentFields' => $this->getUsedDocumentFields($entityTypeId),
]);
}