public function UserExpireReport::listOfUsers in User Expire 8
1 string reference to 'UserExpireReport::listOfUsers'
File
- src/
Controller/ UserExpireReport.php, line 67
Class
- UserExpireReport
- Report controller of User Expire module.
Namespace
Drupal\user_expire\ControllerCode
public function listOfUsers() {
$header = [
'username' => [
'data' => $this
->t('Username'),
'field' => 'u.name',
],
'access' => [
'data' => $this
->t('Last access'),
'field' => 'u.access',
],
'expiration' => [
'data' => $this
->t('Expiration'),
'field' => 'expiration',
'sort' => 'asc',
],
];
$rows = [];
$query = $this->database
->select('user_expire', 'ue');
$query
->join('users_field_data', 'u', 'ue.uid = u.uid');
$query = $query
->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender')
->extend('Drupal\\Core\\Database\\Query\\TableSortExtender');
$query
->fields('u', [
'uid',
'name',
'access',
])
->fields('ue', [
'expiration',
])
->limit(50)
->orderByHeader($header);
$accounts = $query
->execute();
foreach ($accounts as $account) {
$username = [
'#theme' => 'username',
'#account' => $this
->entityTypeManager()
->getStorage('user')
->load($account->uid),
];
$rows[$account->uid] = [
'username' => render($username),
'access' => $account->access ? $this
->t('@time ago', [
'@time' => $this->dateFormatter
->formatInterval($this->time
->getRequestTime() - $account->access),
]) : $this
->t('never'),
'expiration' => $this
->t('@time from now', [
'@time' => $this->dateFormatter
->formatInterval($account->expiration - $this->time
->getRequestTime()),
]),
];
}
$table = [
'#theme' => 'table',
'#rows' => $rows,
'#header' => $header,
];
return $table;
}