Rus
Eng
Работа с пользователями и группами пользователей в Битрикс через D7
Order site
By contacting me you will receive a reliable and knowledgeable contractor who will quickly and efficiently implement any task for you and your business.

All English-language materials have been translated fully automatically using the Google service

Getting the list of groups

  $ result = \ Bitrix \ Main \ GroupTable :: getList (array (
    'select' => array ('NAME', 'ID', 'STRING_ID', 'C_SORT'), // Name, identifier, character code, sorting
    'filter' => array ('! ID' => '1') // Get all groups except the admin group
));

while ($ arGroup = $ result-> fetch ()) {
// Process the result
}  

Getting the list of active user groups

So

  global $ USER;

\ Bitrix \ Main \ UserTable :: getUserGroupIds ($ USER-> GetID ());  

or so

  $ result = \ Bitrix \ Main \ UserGroupTable :: getList (array (
    'filter' => array ('USER_ID' => $ USER-> GetID (), 'GROUP.ACTIVE' => 'Y'),
    'select' => array ('GROUP_ID', 'GROUP_CODE' => 'GROUP.STRING_ID'), // select the group ID and group symbolic code
    'order' => array ('GROUP.C_SORT' => 'ASC'), // sort according to group sort
));

while ($ arGroup = $ result-> fetch ()) {
// Process the result
}

 

Getting the list of active users in the group

  $ result = \ Bitrix \ Main \ UserGroupTable :: getList (array (
    'filter' => array ('GROUP_ID' => 5, 'USER.ACTIVE' => 'Y'),
    'select' => array ('USER_ID', 'NAME' => 'USER.NAME', 'LAST_NAME' => 'USER.LAST_NAME'), // select the username, first and last name
    'order' => array ('USER.ID' => 'DESC'), // sort by user ID
));

while ($ arGroup = $ result-> fetch ()) {
    // Process the result
}  

Add user to group

  \ Bitrix \ Main \ UserGroupTable :: add (array (
"USER_ID" => $ REQUEST ['USER_ID'],
"GROUP_ID" => 5,
));  

Remove user from group

  \ Bitrix \ Main \ UserGroupTable :: delete (array (
"USER_ID" => $ REQUEST ['USER_ID'],
"GROUP_ID" => 5,
));  

Check if the user belongs to groups

  CSite :: InGroup (array (4,5))  

Get a user by ID

  $ dbUser = \ Bitrix \ Main \ UserTable :: getList (array (
'select' => array ('ID', 'NAME', 'PERSONAL_PHOTO', 'PERSONAL_WWW'),
'filter' => array ('ID' => $ USER-> GetID ())
));
if ($ arUser = $ dbUser-> fetch ()) {
print_r ($ arUser);
}  

Get user ID by EMAIL

  // D7
use Bitrix \ Main \ UserTable;

$ user = UserTable :: getList ([
    'select' => array ('ID'),
    'filter' => array ('EMAIL' => 'user @ mail')
]) -> fetch ();

echo $ user ['ID'];

// old
$ cUser = $ USER :: GetList (
    $ by = "ID",
    $ order = "desc",
    array (
        'EMAIL' => 'user @ mail'
    ),
    array (
        'SELECT' => array ('ID')
    )
) -> fetch ();

echo $ cUser ['ID'];  

Comments

There are no comments yet, you can be the first to leave it

Leave a comment

The site uses a comment pre-moderation system, so your message will be published only after approval by the moderator

You are replying to a user's comment

Send

FEEDBACK

Email me

Please message me to discuss the task. I work remotely and officially (as a self-employed professional); my hourly rate is 1,800 RUB, and I can dedicate 3–4 hours a day to the project. I respond quickly, and the consultation is free.

An error occurred while sending, please try again after a while
Message sent successfully

Phones

+7(993) 007-18-96

Email

info@tichiy.ru

Address

Россия, г. Москва

By submitting the form, you automatically confirm that you have read and accept the Privacy Policy site