- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/integrity/duplicatecommunicationcriterion.php
- Класс: Bitrix\Crm\Integrity\DuplicateCommunicationCriterion
- Вызов: DuplicateCommunicationCriterion::getRegisteredCodes
static function getRegisteredCodes($entityTypeID, $entityID, $enablePermissionCheck = false, $userID = 0, $limit = 50)
{
if(!is_int($entityTypeID))
{
throw new Main\ArgumentTypeException('entityTypeID', 'integer');
}
if(!is_int($entityID))
{
throw new Main\ArgumentTypeException('entityID', 'integer');
}
if(!is_int($userID))
{
throw new Main\ArgumentTypeException('userID', 'integer');
}
if(!is_bool($enablePermissionCheck))
{
throw new Main\ArgumentTypeException('enablePermissionCheck', 'boolean');
}
if(!is_int($limit))
{
throw new Main\ArgumentTypeException('limit', 'integer');
}
$query = new Main\Entity\Query(DuplicateCommunicationMatchCodeTable::getEntity());
$query->addSelect('TYPE');
$query->addSelect('VALUE');
$query->addFilter('=ENTITY_TYPE_ID', $entityTypeID);
$query->addFilter('=ENTITY_ID', $entityID);
if($enablePermissionCheck && $userID > 0)
{
$permissions = isset($params['PERMISSIONS']) ? $params['PERMISSIONS'] : null;
if($permissions === null)
{
$permissions = \CCrmPerms::GetUserPermissions($userID);
}
$permissionSql = \CCrmPerms::BuildSql(
\CCrmOwnerType::ResolveName($entityTypeID),
'',
'READ',
array('RAW_QUERY' => true, 'PERMS'=> $permissions)
);
if($permissionSql === false)
{
//Access denied;
return array();
}
elseif($permissionSql !== '')
{
$query->addFilter('@ENTITY_ID', new Main\DB\SqlExpression($permissionSql));
}
}
if($limit > 0)
{
$query->setLimit($limit);
}
$dbResult = $query->exec();
$results = array();
while($fields = $dbResult->fetch())
{
$type = isset($fields['TYPE']) ? $fields['TYPE'] : '';
$value = isset($fields['VALUE']) ? $fields['VALUE'] : '';
if(!isset($results[$type]))
{
$results[$type] = array();
}
$results[$type][] = $value;
}
return $results;
}