- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/activity/lightcounter/actcounterlighttimerepo.php
- Класс: Bitrix\Crm\Activity\LightCounter\ActCounterLightTimeRepo
- Вызов: ActCounterLightTimeRepo::activitiesWithLightTimeByEntityIds
public function activitiesWithLightTimeByEntityIds(int $entityTypeId, array $entityIds): array
{
if (empty($entityIds))
{
return [];
}
$queryBuilder = ActivityTable::query()
->addSelect('ID')
->addSelect('COMPLETED')
->addSelect('B.OWNER_ID', 'BIND_OWNER_ID')
->addSelect('B.OWNER_TYPE_ID', 'BIND_OWNER_TYPE_ID')
->addSelect('RESPONSIBLE_ID')
->addSelect('DEADLINE')
->registerRuntimeField(
'',
new ReferenceField('B',
ActivityBindingTable::getEntity(),
[
'=ref.ACTIVITY_ID' => 'this.ID',
]
)
)
->registerRuntimeField(
'',
new ReferenceField('LT',
ActCounterLightTimeTable::getEntity(),
[
'=ref.ACTIVITY_ID' => 'this.ID',
]
)
)
->whereIn('B.OWNER_ID', $entityIds)
->where('B.OWNER_TYPE_ID', '=', $entityTypeId);
// If LIGHT_COUNTER_AT not filled yet by update agent then will use activate counter before 15 minutes to deadline
if ($this->isTransitionalMode)
{
$queryBuilder
->registerRuntimeField(new ExpressionField(
'LIGHT_COUNTER_AT',
'COALESCE(crm_activity_lt.LIGHT_COUNTER_AT, DATE_SUB(DEADLINE, interval 15 minute))'
)
)
->addSelect('LIGHT_COUNTER_AT');
}
else
{
$queryBuilder
->addSelect('LT.LIGHT_COUNTER_AT', 'LIGHT_COUNTER_AT');
}
return $queryBuilder->fetchAll();
}