You are here

function _autologout_get_user_timeout in Automated Logout 7.4

Same name and namespace in other branches
  1. 6.4 autologout.module \_autologout_get_user_timeout()

Get a user's timeout in seconds.

Parameters

int $uid: (Optional) Provide a user's uid to get the timeout for. Default is the logged in user.

Return value

int The number of seconds the user can be idle for before being logged out. A value of 0 means no timeout.

10 calls to _autologout_get_user_timeout()
AutoLogoutByRoleTestCase::testAutoLogoutTimeoutByRoleWhenAuthenticatedRoleHasATimeoutAuthenticatedIsLargerThanRole in tests/autologout.test
Check the role timeout prescendence works when multiple roles have timeouts.
AutoLogoutByRoleTestCase::testAutoLogoutTimeoutByRoleWhenAuthenticatedRoleHasATimeoutAuthenticatedIsSmallerThanRole in tests/autologout.test
Check the role timeout prescendence works when multiple roles have timeouts.
AutoLogoutByRoleTestCase::testAutoLogoutTimeoutByRoleWhenRoleTimeoutIsGreaterThanStandard in tests/autologout.test
Check the role timeout has precedence over the basic timeout.
AutoLogoutByRoleTestCase::testAutologoutTimeoutByRoleWhenRoleTimeoutIsLessThanStandard in tests/autologout.test
Check the role timeout has precedence over the basic timeout.
AutologoutTestCase::assertAutotimeout in tests/autologout.test
Assert the timeout for a particular user.

... See full list

File

./autologout.module, line 612
Used to automagically log out a user after a preset time.

Code

function _autologout_get_user_timeout($uid = NULL) {
  if (is_null($uid)) {

    // If $uid is not provided, use the logged in user.
    global $user;
  }
  else {
    $user = user_load($uid);
  }
  if ($user->uid == 0) {

    // Anonymous doesn't get logged out.
    return 0;
  }
  if (is_numeric($user_timeout = variable_get('autologout_user_' . $user->uid, FALSE))) {

    // User timeout takes precedence.
    drupal_alter('autologout_timeout', $user_timeout);
    return $user_timeout;
  }

  // Get role timeouts for user.
  if (variable_get('autologout_role_logout', FALSE)) {
    $user_roles = $user->roles;
    $output = array();
    $timeouts = _autologout_get_role_timeout();
    foreach ($user_roles as $rid => $role) {
      if (isset($timeouts[$rid])) {
        $output[$rid] = $timeouts[$rid];
      }
    }

    // Assign the lowest timeout value to be session timeout value.
    if (!empty($output)) {

      // If one of the user's roles has a unique timeout, use this.
      $timeout = min($output);
      drupal_alter('autologout_timeout', $timeout);
      return $timeout;
    }
  }

  // If no user or role override exists, return the default timeout.
  $timeout = variable_get('autologout_timeout', 1800);
  drupal_alter('autologout_timeout', $timeout);
  return $timeout;
}