Documentation

GetUserRoles

string
CMain::GetUserRoles(
 string module_id,
 mixed groups = false,
 string use_default_role = "Y",
 string max_role_for_super_admin = "Y",
 string site_id=false
)

The method returns an array of roles assigned to a specific set of groups (by default - group of the current user).

Generally, each module has specific role descriptors. A unique set of roles can be assigned to the module using the GetModuleRightList method of a class named by the module ID. For example, the Support module exposes method support::GetModuleRightList() defined in the file /bitrix/modules/support/install/index.php. Roles are usually assigned using the module settings form.

Note. For any module, the role of the maximum level of permission (module administrator) is always indicated with the symbol W, while the role of the minimum level of permission - indicated with the symbol D (deny).

Non-static method.

Parameters

ParameterDescription Available from version
module_id Module ID.
groups Array of groups for which the roles are to be retrieved. Setting this parameter to false assumes the array of groups of the current user.
Optional parameter; false by default.
use_default_role If set to "Y", the default role is taken into consideration to determine the required role.
Optional parameter; false by default.
max_role_for_super_admin If set to "Y" and groups = false, array of roles with mandatory enabled role with maximum level of access permissions - "W" always will be returned to the user, who is a member of administrator group (group #1).
Optional parameter. By default value is "Y".
site_id Site ID. Optional parameter; false by default.

See Also

  • CMain::GetUserRight
  • CModule::GetModuleRightList

    Examples of use

    <?
    // obtain the array of roles of the current user in the Support module
    $arRoles = $APPLICATION->GetUserRoles("support");
    
    if(in_array("R",$arRoles)) 
        $strNote = "You can post questions to the techsupport.";
    
    if(in_array("T",$arRoles)) 
        $strNote = "You are the techsupport team member.";
    
    if(in_array("V",$arRoles)) 
        $strNote = "You are allowed to view tickets but not modify them.";
    
    if(in_array("W",$arRoles)) 
        $strNote = "You are the techsupport administrator.";
    
    if ($arRoles==array("D"))
        $APPLICATION->AuthForm("Access denied.");
    
    ShowNote($strNote);
    ?>


    © «Bitrix24», 2001-2022
    Up