You are here

public static function SwitchUserBlock::sortUserList in Devel 8.2

Same name and namespace in other branches
  1. 8.3 src/Plugin/Block/SwitchUserBlock.php \Drupal\devel\Plugin\Block\SwitchUserBlock::sortUserList()
  2. 8 src/Plugin/Block/SwitchUserBlock.php \Drupal\devel\Plugin\Block\SwitchUserBlock::sortUserList()
  3. 4.x src/Plugin/Block/SwitchUserBlock.php \Drupal\devel\Plugin\Block\SwitchUserBlock::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/Plugin/Block/SwitchUserBlock.php, line 282

Class

SwitchUserBlock
Provides a block for switching users.

Namespace

Drupal\devel\Plugin\Block

Code

public static function sortUserList(AccountInterface $a, AccountInterface $b) {
  $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;
}