- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_document.php
- Класс: \CCrmDocument
- Вызов: CCrmDocument::GetAllowableUserGroups
static function GetAllowableUserGroups($documentType)
{
$documentType = trim($documentType);
if ($documentType == '')
return false;
$arDocumentID = static::GetDocumentInfo($documentType);
if ($arDocumentID !== false)
$documentType = $arDocumentID['TYPE'];
$arResult = [
static::GROUP_AUTHOR => GetMessage('CRM_DOCUMENT_AUTHOR'),
static::GROUP_RESPONSIBLE_HEAD => GetMessage('CRM_DOCUMENT_RESPONSIBLE_HEAD'),
];
$arGroupsID = array(1);
$arUsersID = array();
$arRelations = CCrmPerms::GetEntityRelations($documentType, BX_CRM_PERM_SELF);
foreach($arRelations as $relation)
{
$preffix = mb_substr($relation, 0, 1);
if($preffix === 'G')
{
$arGroupsID[] = intval(mb_substr($relation, 1));
}
elseif($preffix === 'U')
{
$arUsersID[] = mb_substr($relation, 1);
}
}
//Crutch for Bitrix24 context (user group management is not supported)
if(IsModuleInstalled('bitrix24'))
{
if (!isset(static::$b24employeeGroupId))
{
$siteID = CSite::GetDefSite();
$dbResult = CGroup::GetList(
'',
'',
[
'STRING_ID' => 'EMPLOYEES_' . $siteID,
'STRING_ID_EXACT_MATCH' => 'Y',
]
);
$arEmployeeGroup = $dbResult->fetch();
static::$b24employeeGroupId = (int) ($arEmployeeGroup['ID'] ?? 0);
}
if(!in_array(static::$b24employeeGroupId, $arGroupsID, true))
{
$arGroupsID[] = static::$b24employeeGroupId;
}
}
if(!empty($arGroupsID))
{
$dbGroupList = CGroup::GetListEx(array('NAME' => 'ASC'), array('ID' => $arGroupsID));
while ($arGroup = $dbGroupList->Fetch())
{
$arResult[$arGroup['ID']] = $arGroup['NAME'];
}
}
if(isset(self::$UNGROUPED_USERS[$documentType]))
{
unset(self::$UNGROUPED_USERS[$documentType]);
}
self::$UNGROUPED_USERS[$documentType] = $arUsersID;
if(!empty($arUsersID))
{
//Group with empty name will be hidden in group list
$arResult['ungrouped'] = '';
//$arResult['ungrouped'] = GetMessage('CRM_DOCUMENT_UNGROUPED_USERS');
}
return $arResult;
}