- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/controller/entity.php
- Класс: Bitrix\Crm\Controller\Entity
- Вызов: Entity::expandItems
static function expandItems(
array &$items,
int $entityTypeId,
int $categoryId,
int $limit = self::ITEMS_LIMIT
): void
{
$map = [];
foreach ($items as $item)
{
$storedEntityTypeId = isset($item['ENTITY_TYPE_ID']) ? (int)$item['ENTITY_TYPE_ID'] : 0;
$storedEntityId = isset($item['ENTITY_ID']) ? (int)$item['ENTITY_ID'] : 0;
$storedCategoryId = isset($item['CATEGORY_ID']) ? (int)$item['CATEGORY_ID'] : 0;
if (
$storedEntityId <= 0
|| $entityTypeId !== $storedEntityTypeId
|| $categoryId !== $storedCategoryId
|| !\CCrmOwnerType::IsDefined($storedEntityTypeId)
)
{
continue;
}
$map["{$storedEntityTypeId}:{$storedEntityId}:{$storedCategoryId}"] = $item;
}
$userPermissions = \CCrmPerms::GetCurrentUserPermissions();
$entityIDs = null;
if($entityTypeId === \CCrmOwnerType::Lead)
{
$entityIDs = \CCrmLead::GetTopIDs($limit, 'DESC', $userPermissions);
}
elseif($entityTypeId === \CCrmOwnerType::Contact)
{
$entityIDs = \CCrmContact::GetTopIDsInCategory($categoryId, $limit, 'DESC', $userPermissions);
}
elseif($entityTypeId === \CCrmOwnerType::Company)
{
$entityIDs = \CCrmCompany::GetTopIDsInCategory($categoryId, $limit, 'DESC', $userPermissions);
}
elseif($entityTypeId === \CCrmOwnerType::Deal)
{
$entityIDs = \CCrmDeal::GetTopIDs($limit, 'DESC', $userPermissions);
}
elseif($entityTypeId === \CCrmOwnerType::Order)
{
$orders = Order::getList([
'select' => ['ID'],
'limit' => $limit
])->fetchCollection();
$entityIDs = $orders->getIdList();
}
elseif(\CCrmOwnerType::isUseFactoryBasedApproach($entityTypeId))
{
$factory = Container::getInstance()->getFactory($entityTypeId);
if ($factory)
{
$list = $factory->getItemsFilteredByPermissions([
'order' => ['ID' => 'DESC'],
'limit' => $limit
]);
foreach ($list as $item)
{
$entityIDs[] = $item->getId();
}
}
}
if(!is_array($entityIDs))
{
return;
}
foreach($entityIDs as $entityId)
{
$key = "{$entityTypeId}:{$entityId}:{$categoryId}";
if(isset($map[$key]))
{
continue;
}
$map[$key] = [
'ENTITY_TYPE_ID' => $entityTypeId,
'ENTITY_ID' => (int)$entityId,
'CATEGORY_ID' => $categoryId,
];
}
$items = array_values($map);
}