function mass_pwreset_get_uids_by_selected_roles in Mass Password Reset 8
Same name and namespace in other branches
- 2.x mass_pwreset.module \mass_pwreset_get_uids_by_selected_roles()
Return uids from a list of roles.
Excludes current uid and uid 1.
Parameters
array $roles: An array of select roles.
1 call to mass_pwreset_get_uids_by_selected_roles()
- MassPasswordResetForm::validateForm in src/
Form/ MassPasswordResetForm.php - Form validation handler.
File
- ./
mass_pwreset.module, line 40 - Reset user passwords and optionally notify users.
Code
function mass_pwreset_get_uids_by_selected_roles($roles = array()) {
// Do not include current logged in user.
$current_uid = \Drupal::currentUser()
->id();
$db = \Drupal::database();
$query = $db
->select('users', 'u');
$query
->innerJoin('user__roles', 'ur', 'u.uid = ur.entity_id');
$query
->fields('u', [
'uid',
]);
$query
->condition('ur.roles_target_id', $roles, 'IN');
$query
->condition('u.uid', [
1,
$current_uid,
], 'NOT IN');
$query
->orderBy('u.uid');
$query
->distinct();
return $query
->execute()
->fetchCol();
}