Documentation

SetUserGroup

CUser::SetUserGroup(    int user_id,
   array groups
);

The method assigns a user_id to a number of groups. The assignment is stored in the database but does not affect the already authorized user_id state. Non-static method.

Parameters

Parameter Description
user_id User ID.
groups Array with ID values for user groups.

See Also

Examples of use

<?
// assign a user ID=10 to a group with ID=5
$arGroups = CUser::GetUserGroup(10);
$arGroups[] = 5;
CUser::SetUserGroup(10, $arGroups);
?>

If the period of activity within a group is also required to be changed, the groups array will have the following value:

$arGroups = array(
  array(
  'GROUP_ID' => 5,
  'DATE_ACTIVE_FROM'=>'01.02.2009',
  'DATE_ACTIVE_TO'=>'02.02.2009'
  ),
  array(
  'GROUP_ID' => 6,
  'DATE_ACTIVE_FROM'=>'01.03.2009',
  'DATE_ACTIVE_TO'=>'02.03.2009'
  )
);

Adding a group via "single string" (where array(4,5,6) - array of added groups.):

CUser::SetUserGroup($userID, array_merge(CUser::GetUserGroup($userID), array(4,5,6)));


© «Bitrix24», 2001-2022
Up