You are here

function _user_patterns_users_with_role in Patterns 7.2

Returns a list of usernames that belong to the given Role ID

Parameters

string $role Role ID to filter by:

Return value

array List of usernames that currently hold that role

1 call to _user_patterns_users_with_role()
user_patterns_export_all_role_users in patterns_components/components/user.inc
Returns a set of PATTERNS_CREATE actionswith the whole set of relationsps between users and roles currently stored in the system.

File

patterns_components/components/user.inc, line 726

Code

function _user_patterns_users_with_role($role) {
  $users_with_role = array();

  //Get rid and load users
  $role_info = user_role_load_by_name($role);
  $users = entity_load('user');

  //Filter all users that do not have the given role
  foreach ($users as $user) {
    if (array_key_exists($role_info->rid, $user->roles)) {
      array_push($users_with_role, $user->name);
    }
  }
  return $users_with_role;
}