- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/integrity/duplicatelist.php
- Класс: Bitrix\Crm\Integrity\DuplicateList
- Вызов: DuplicateList::getTotalEntityCount
static function getTotalEntityCount($userID, $entityTypeID, array $typeIDs, $scope)
{
$subQuery = Entity\DuplicateEntityMatchHashTable::query();
$indexJoinConditions = array(
'=this.MATCH_HASH' => 'ref.MATCH_HASH',
'=this.ENTITY_TYPE_ID' => 'ref.ENTITY_TYPE_ID',
'=this.TYPE_ID' => 'ref.TYPE_ID',
'=ref.USER_ID' => new Main\DB\SqlExpression('?i', $userID),
'=ref.ENTITY_TYPE_ID' => new Main\DB\SqlExpression('?i', $entityTypeID),
'=ref.SCOPE' => new Main\DB\SqlExpression('?s', $scope)
);
if (!empty($typeIDs))
{
$indexJoinConditions['@ref.TYPE_ID'] = new Main\DB\SqlExpression(implode(', ', $typeIDs));
}
$subQuery
->addSelect('ENTITY_ID')
->registerRuntimeField('',
new Main\Entity\ReferenceField('I',
Entity\DuplicateIndexTable::getEntity(),
$indexJoinConditions,
array('join_type' => 'INNER')
)
)
->addGroup('ENTITY_ID');
// workaround for correct filter typed contacts/companies by category ID
if (in_array($entityTypeID, [CCrmOwnerType::Contact, CCrmOwnerType::Company], true))
{
$subQuery->registerRuntimeField('', DedupeDataSource::getCategoryReferenceField($entityTypeID, 0));
}
$query = new Main\Entity\Query($subQuery);
$query
->registerRuntimeField('', new Main\Entity\ExpressionField('CNT', 'COUNT(*)'))
->addSelect('CNT');
$dbResult = $query->exec();
$fields = $dbResult->fetch();
return is_array($fields) && isset($fields['CNT']) ? (int)$fields['CNT'] : 0;
}