You are here

public function AutologoutController::ajaxGetRemainingTime in Automated Logout 8

AJAX callback that returns the time remaining for this user is logged out.

1 string reference to 'AutologoutController::ajaxGetRemainingTime'
autologout.routing.yml in ./autologout.routing.yml
autologout.routing.yml

File

src/Controller/AutologoutController.php, line 108

Class

AutologoutController
Returns responses for autologout module routes.

Namespace

Drupal\autologout\Controller

Code

public function ajaxGetRemainingTime() {
  $req = \Drupal::requestStack()
    ->getCurrentRequest();
  $active = $req
    ->get('uactive');
  $response = new AjaxResponse();
  if (isset($active) && $active === "false") {
    $response
      ->addCommand(new ReplaceCommand('#timer', 0));
    $response
      ->addCommand(new SettingsCommand([
      'time' => 0,
    ]));
    return $response;
  }
  $time_remaining_ms = $this->autoLogoutManager
    ->getRemainingTime() * 1000;

  // Reset the timer.
  $markup = $this->autoLogoutManager
    ->createTimer();
  $response
    ->addCommand(new ReplaceCommand('#timer', $markup));
  $response
    ->addCommand(new SettingsCommand([
    'time' => $time_remaining_ms,
  ]));
  return $response;
}