- Модуль: crmmobile
- Путь к файлу: ~/bitrix/modules/crmmobile/lib/Controller/Category.php
- Класс: BitrixCrmMobileControllerCategory
- Вызов: Category::getCategoryList
private function getCategoryList(Factory $factory): ?DtoCategoryList
{
$categories = [];
$restrictions = [];
$canUserEditCategory = $this->canUserEditCategory();
$sortedTunnelsByCategory = [];
if ($canUserEditCategory)
{
$tunnelScheme = (new TunnelManager($factory->getEntityTypeId()))->getScheme();
$sortedTunnelsByCategory = array_reduce($tunnelScheme['stages'],
function ($acc, $stage) use ($factory) {
foreach ($stage['tunnels'] as $tunnel)
{
$tunnelData = $this->prepareTunnelData($factory, $tunnel);
if ($tunnelData)
{
$acc[$stage['categoryId']][] = $tunnelData;
}
}
return $acc;
}, []);
}
$categoriesCollection = $this->getCategoriesCollection($factory);
foreach ($categoriesCollection as $category)
{
$categoryId = $category->getId();
$categoryData = [
'id' => $categoryId,
'name' => $category->getName(),
'sort' => $category->getSort(),
'isDefault' => $category->getIsDefault(),
'tunnels' => $sortedTunnelsByCategory[$categoryId] ?? [],
];
if (CounterEntityCounterFactory::isEntityTypeSupported($factory->getEntityTypeId()))
{
$categoryData['counter'] = CounterEntityCounterFactory::create(
$factory->getEntityTypeId(),
CounterEntityCounterType::ALL,
$this->getCurrentUser()->getId(),
['DEAL_CATEGORY_ID' => $categoryId]
)->getValue();
}
$categories[] = $categoryData;
}
if ($factory->getEntityName() === CCrmOwnerType::DealName)
{
$dealCategoryLimitRestriction = RestrictionManager::getDealCategoryLimitRestriction();
if ($dealCategoryLimitRestriction)
{
$restrictions[] = [
'id' => $dealCategoryLimitRestriction->getMobileInfoHelperId(),
'name' => $dealCategoryLimitRestriction->getName(),
'isExceeded' => $dealCategoryLimitRestriction->isExceeded(),
];
}
}
return new DtoCategoryList([
'categories' => $categories,
'restrictions' => $restrictions,
'canUserEditCategory' => $canUserEditCategory,
]);
}