Y
Y
Yuriy2019-07-12 11:45:45
1C-Bitrix
Yuriy, 2019-07-12 11:45:45

Bitrix CUser::GetList how to select all users except administrators?

The documentation says that there is no complex filtering logic for GROUPS_ID, i.e. just an array with the desired groups.
And how to exclude the desired group from the sample? for example, you need a list of users that does not include Administrators?

$filterUser = array(
   "ACTIVE" => 'Y',
 // "!GROUPS_ID"=>[1] -- так не будет фильтровать
);
$userResult = CUser::GetList(($by="NAME"), ($order="ASC"), $filterUser);

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
serginhold, 2019-07-12
@yous

this is the moment when you do not need to use the ancient api, there is \Bitrix\Main\UserGroupTable

A
Alexey Ukolov, 2019-07-12
@alexey-m-ukolov

Select the identifiers of all groups, remove the identifier of the administrator group from the resulting array, filter by the remaining ones.

Y
Yaroslav Alexandrov, 2019-07-12
@alexyarik

The output is an array without admins

<?
global $USER;
        $users = CUser::GetList(
            ($by="id"),
            ($order="desc"),
            array(),
            array("SELECT" => array('*'))
        );	
          $userArray = array();
$arrayGroupIds = array();
      while ($user = $users->Fetch()) {
if (in_array(1, CUser::GetUserGroup($user['ID'])))
{
} else {
      $userArray [] =$user;
}
        }
?>

D
DTX, 2017-10-09
@alex_kovalevv

Is it so hard to link to regex101???
So make it lazy
Upd:
https://regex101.com/r/0oIjRA/1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question