You are here

function role_expire_rules_action_set_role_expire_to_longest in Role Expire 7

Action: Set expire time for role to longest attached to this user. Defaults to the current time.

File

./role_expire.rules.inc, line 133
Rules integration for the role expire module.

Code

function role_expire_rules_action_set_role_expire_to_longest($account, $rid, $timestamp) {

  // Set an invalid timestamp to allow for comparisons without warnings.
  $timestamp = -1;
  foreach ($account->roles as $id => $name) {
    $this_ts = role_expire_get_user_role_expiry_time($account->uid, $id);
    if (!empty($this_ts)) {
      $timestamp = $this_ts > $timestamp ? $this_ts : $timestamp;
    }
  }

  // If there were no valid timestamps for comparison, use the current time.
  if ($timestamp == -1) {
    $timestamp = time();
  }
  role_expire_write_record($account->uid, $rid, $timestamp);
}