You are here

public function RoleExpireApiService::getExpired in Role Expire 8

Same name and namespace in other branches
  1. 2.x src/RoleExpireApiService.php \Drupal\role_expire\RoleExpireApiService::getExpired()

Get all records that should be expired.

Parameters

int $time: Optional. The time to check, if not set it will check current time.

Return value

array All expired roles.

File

src/RoleExpireApiService.php, line 237

Class

RoleExpireApiService
Class RoleExpireApiService.

Namespace

Drupal\role_expire

Code

public function getExpired($time = '') {
  $return = [];
  if (!$time) {
    date_default_timezone_set(date_default_timezone_get());
    $time = \Drupal::time()
      ->getRequestTime();
  }
  $query = $this->database
    ->select('role_expire', 'n');
  $query
    ->fields('n', [
    'rid',
    'uid',
    'expiry_timestamp',
  ]);
  $query
    ->condition('n.expiry_timestamp', $time, '<=');
  $result = $query
    ->execute()
    ->fetchAll();
  foreach ($result as $row) {
    $return[] = $row;
  }
  return $return;
}