- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/counter/lighter/lighterqueries.php
- Класс: Bitrix\Crm\Counter\Lighter\LighterQueries
- Вызов: LighterQueries::queryEntitiesData
public function queryEntitiesData(GroupedBindings $groupedBindings): array
{
$result = [];
foreach ($groupedBindings as $ownerTypeId => $binding)
{
$ownerIds = array_column($binding, 'OWNER_ID');
$factory = Container::getInstance()->getFactory($ownerTypeId);
if (!$factory)
{
continue;
}
if (!$factory->isCountersEnabled())
{
continue;
}
$categoryIdFieldName = $factory->getEntityFieldNameByMap(Item::FIELD_NAME_CATEGORY_ID);
$assignedByFiledName = $factory->getEntityFieldNameByMap(Item::FIELD_NAME_ASSIGNED);
$select = [
Item::FIELD_NAME_ID,
];
if ($factory->isFieldExists(Item::FIELD_NAME_ASSIGNED))
{
$select[] = $assignedByFiledName;
}
if ($factory->isFieldExists(Item::FIELD_NAME_CATEGORY_ID))
{
$select[] = $categoryIdFieldName;
}
$entities = $factory->getDataClass()::query()
->setSelect($select)
->whereIn('ID', $ownerIds)
->fetchAll();
foreach ($entities as $entity)
{
$category = $entity[$categoryIdFieldName] ?? null;
if ($category !== null)
{
$category = (int)$category;
}
$ownerId = (int)$entity[Item::FIELD_NAME_ID];
$result[] = [
'OWNER_TYPE_ID' => $ownerTypeId,
'OWNER_ID' => $ownerId,
'CATEGORY_ID' => $category,
'ASSIGNED_ID' => (int)$entity[$assignedByFiledName],
'ACTIVITY_IDS' => $binding[$ownerId]['ACTIVITY_IDS'] ?? [],
];
}
}
return $result;
}