You are here

public function ForcePasswordChangeMapper::getPendingUserIds 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::getPendingUserIds()

Retrieve the User IDs of all users in the given role with 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 have a pending forced password change.

Overrides ForcePasswordChangeMapperInterface::getPendingUserIds

File

src/Mapper/ForcePasswordChangeMapper.php, line 124

Class

ForcePasswordChangeMapper

Namespace

Drupal\force_password_change\Mapper

Code

public function getPendingUserIds($rid = FALSE) {
  $query = $this->connection
    ->select('users_data', 'ud')
    ->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender');
  $query
    ->join('users_field_data', 'ufd', 'ufd.uid = ud.uid AND ufd.status = :one', [
    ':one' => 1,
  ]);
  $query
    ->addField('ud', 'uid');
  $query
    ->addTag('force_password_change_pending_users')
    ->limit(20)
    ->condition('ud.module', 'force_password_change')
    ->condition('ud.name', 'pending_force')
    ->condition('ud.value', 1);

  // If the role is anything other than the authenticated
  // users role, we need to limit the users to the members of that role.
  if ($rid) {
    $alias = $query
      ->join('user__roles', 'ur', 'ur.entity_id = ud.uid');
    $query
      ->condition($alias . '.roles_target_id', $rid);
  }
  return $query
    ->execute()
    ->fetchCol();
}