You are here

public function RestfulRateLimitBase::getLimit in RESTful 7

Get the rate limit. Returns the highest rate limit for the current account.

Parameters

\stdClass $account: The account object for the user making the request.

Return value

int

1 method overrides RestfulRateLimitBase::getLimit()
RestfulRateLimitGlobal::getLimit in plugins/rate_limit/RestfulRateLimitGlobal.class.php
All limits are the same for the global limit. Return the first one.

File

plugins/rate_limit/RestfulRateLimitBase.php, line 71
Contains \RestfulRateLimitBase

Class

RestfulRateLimitBase
@file Contains \RestfulRateLimitBase

Code

public function getLimit(\stdClass $account = NULL) {

  // If the user is anonymous.
  if (empty($account->roles)) {
    return $this->limits['anonymous user'];
  }

  // If the user is logged then return the best limit for all the roles the
  // user has.
  $max_limit = 0;
  foreach ($account->roles as $rid => $role) {
    if (!isset($this->limits[$role])) {

      // No limit configured for this role.
      continue;
    }
    if ($this->limits[$role] < $max_limit && $this->limits[$role] != \RestfulRateLimitManager::UNLIMITED_RATE_LIMIT) {

      // The limit is smaller than one previously found.
      continue;
    }

    // This is the highest limit for the current user given all their roles.
    $max_limit = $this->limits[$role];
  }
  return $max_limit;
}