Bitrix Site Manager

CMain::GetUserRoles

string
CMain::GetUserRoles(
 string module_id,
 mixed groups = false,
 string use_default = "Y",
 string max_for_admin = "Y"
)

The method GetUserRight returns array of roles (in the form of a string) assigned to a number of groups (group of a current user by default) for the specified module. The role descriptor returned is meaningful for the specified module.

Generally, each module has specific role descriptors. A unique set of roles can be assigned to the module using the method GetModuleRightList 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, 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 - with D (deny).

Parameters

ParameterDescription
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; false by default.
use_default If set to "Y", the default role is taken into consideration to determine the required role.
Optional; "Y" by default.
max_for_admin If set to "Y" and the parameter groups is false, the role of the maximum permission level (W) is always included in the returned array of roles.
Optional; "Y" by default.

See Also

Example



<?
// 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);
?>