function SwitchUserListHelper::sortUserList

Helper callback for uasort() to sort accounts by last access.

Parameters

\Drupal\Core\Session\AccountInterface $a: First account.

\Drupal\Core\Session\AccountInterface $b: Second account.

Return value

int Result of comparing the last access times:

  • -1 if $a was more recently accessed
  • 0 if last access times compare equal
  • 1 if $b was more recently accessed

File

src/SwitchUserListHelper.php, line 190

Class

SwitchUserListHelper
Switch user helper service.

Namespace

Drupal\devel

Code

public static function sortUserList(AccountInterface $a, AccountInterface $b) : int {
    $a_access = (int) $a->getLastAccessedTime();
    $b_access = (int) $b->getLastAccessedTime();
    if ($a_access === $b_access) {
        return 0;
    }
    // User never access to site.
    if ($a_access === 0) {
        return 1;
    }
    return $a_access > $b_access ? -1 : 1;
}