S
S
Sp1keazyYT2018-07-05 15:14:27
1C-Bitrix
Sp1keazyYT, 2018-07-05 15:14:27

How to take from the sample the user group with the maximum id in which the user is located?

Hello. CUser::GetUserGroupList($USER_ID); - returns a list of all groups the user is a member of, where $USER_ID is the user's id. It is necessary through variables to display the name of the user group in which the user is located, and if the user is in several groups, then the name of only one group is displayed, which is the highest of all by ID. How to do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kudis, 2018-07-05
@Sp1keazyYT

What's the problem?
Let's assume that your

highest of all by ID
is the one with the maximum id, then for the user with $id = 1:
$obGroups = CUser::GetUserGroupList(1);

$maxGroupId = 0;
while ($arGroup = $obGroups->Fetch()) {
    if ($maxGroupId < $arGroup['GROUP_ID']) {
        $maxGroupId = $arGroup['GROUP_ID'];
    }
}
$obMaxGroup = CGroup::GetByID($maxGroupId);
if ($arMaxGroup = $obMaxGroup->Fetch()) {
    var_dump($arMaxGroup);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question