- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/integrity/bankdetaildedupedatasource.php
- Класс: Bitrix\Crm\Integrity\BankDetailDedupeDataSource
- Вызов: BankDetailDedupeDataSource::calculateEntityCount
public function calculateEntityCount(DuplicateCriterion $criterion, array $options = null)
{
$entityTypeID = $this->getEntityTypeID();
$enablePermissionCheck = $this->isPermissionCheckEnabled();
$userID = $this->getUserID();
$query = new Main\Entity\Query(DuplicateBankDetailMatchCodeTable::getEntity());
$query->addSelect('QTY');
$query->registerRuntimeField('', new Main\Entity\ExpressionField('QTY', 'COUNT(*)'));
$query->addFilter('=ENTITY_TYPE_ID', $entityTypeID);
if($enablePermissionCheck)
{
$permissionSql = $this->preparePermissionSql();
if($permissionSql === false)
{
//Access denied;
return 0;
}
if(is_string($permissionSql) && $permissionSql !== '')
{
$query->addFilter('@ENTITY_ID', new Main\DB\SqlExpression($permissionSql));
}
}
$matches = $criterion->getMatches();
$countryId = isset($matches['BD_COUNTRY_ID']) ? (int)$matches['BD_COUNTRY_ID'] : 0;
if($countryId <= 0)
{
throw new Main\ArgumentException("Parameter 'BD_COUNTRY_ID' is required.", 'matches');
}
$fieldName = isset($matches['BD_FIELD_NAME']) ? $matches['BD_FIELD_NAME'] : '';
if($fieldName === '')
{
throw new Main\ArgumentException("Parameter 'BD_FIELD_NAME' is required.", 'matches');
}
$value = isset($matches['VALUE']) ? $matches['VALUE'] : '';
if($value === '')
{
throw new Main\ArgumentException("Parameter 'VALUE' is required.", 'matches');
}
$query->addFilter('=BD_COUNTRY_ID', $countryId);
$query->addFilter('=BD_FIELD_NAME', $fieldName);
$query->addFilter('=VALUE', $value);
$rootEntityID = 0;
if(is_array($options) && isset($options['ROOT_ENTITY_ID']))
{
$rootEntityID = (int)$options['ROOT_ENTITY_ID'];
}
if($rootEntityID > 0)
{
$query->addFilter('!ENTITY_ID', $rootEntityID);
$query->addFilter(
'!@ENTITY_ID',
DuplicateIndexMismatch::prepareQueryField($criterion, $entityTypeID, $rootEntityID, $userID)
);
}
$query = DedupeDataSource::registerRuntimeFieldsByParams($query, $this->getParams());
$limit = 0;
if(is_array($options) && isset($options['LIMIT']))
{
$limit = (int)$options['LIMIT'];
}
if($limit > 0)
{
$query->setLimit($limit);
}
$dbResult = $query->exec();
$fields = $dbResult->fetch();
return is_array($fields) && isset($fields['QTY']) ? intval($fields['QTY']) : 0;
}