You are here

public function ForcePasswordChangeMapper::getNonPendingUserIds in Force Password Change 2.0.x

Same name and namespace in other branches
  1. 8 src/Mapper/ForcePasswordChangeMapper.php \Drupal\force_password_change\Mapper\ForcePasswordChangeMapper::getNonPendingUserIds()

Retrieve the User IDs of all users in the given role without a pending forced password change.

Parameters

bool|string $rid: The Role ID of the role to be checked. Set to FALSE to retrieve the UIDs of all authenticated users.

Return value

array An array of User IDs for users in the given role who do not have a pending forced password change.

Overrides ForcePasswordChangeMapperInterface::getNonPendingUserIds

File

src/Mapper/ForcePasswordChangeMapper.php, line 147

Class

ForcePasswordChangeMapper

Namespace

Drupal\force_password_change\Mapper

Code

public function getNonPendingUserIds($rid = FALSE) {
  $query = $this->connection
    ->select('users', 'u')
    ->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender');
  $query
    ->join('users_field_data', 'ufd', 'ufd.uid = u.uid AND ufd.status = :one', [
    ':one' => 1,
  ]);
  $alias = $query
    ->leftJoin('users_data', 'ud', 'ud.uid = u.uid AND ud.module = :force_password_change AND ud.name = :pending_force AND ud.value = :one', [
    ':force_password_change' => 'force_password_change',
    ':pending_force' => 'pending_force',
    ':one' => 1,
  ]);
  $query
    ->addField('u', 'uid');
  $query
    ->addTag('force_password_change_pending_users')
    ->limit(100)
    ->condition('u.uid', 0, '!=')
    ->isNull('ud.uid');
  if ($rid) {
    $alias2 = $query
      ->join('user__roles', 'ur', 'ur.entity_id = ud.uid');
    $query
      ->condition($alias2 . '.roles_target_id', $rid);
  }
  return $query
    ->execute()
    ->fetchCol();
}