You are here

function _privatemsg_limits_get_amount in Privatemsg 7

Same name and namespace in other branches
  1. 6.2 privatemsg_limits/privatemsg_limits.module \_privatemsg_limits_get_amount()
  2. 7.2 privatemsg_limits/privatemsg_limits.module \_privatemsg_limits_get_amount()

Loads the maximum value of a threshold value, takes roles into account.

Parameters

$name: Unique part of the name.

$account: User object to get the limit for.

Return value

A specific number or 0 for unlimited.

3 calls to _privatemsg_limits_get_amount()
privatemsg_limits_form_privatemsg_list_alter in privatemsg_limits/privatemsg_limits.module
Implements hook_form_FORM_ID_alter().
privatemsg_limits_privatemsg_block_message in privatemsg_limits/privatemsg_limits.module
Implements hook_privatemsg_block_message().
privatemsg_limits_privatemsg_message_validate in privatemsg_limits/privatemsg_limits.module
Implements hook_privatemsg_message_validate().

File

privatemsg_limits/privatemsg_limits.module, line 235
Privatemsg Quota module

Code

function _privatemsg_limits_get_amount($name, $account) {

  // Don't limit uid 1.
  if ($account->uid == 1) {
    return 0;
  }

  // $account might not be a fully loaded user account, fetch the roles in that
  // case.
  // @todo: Remove once privatemsg_user_load_multiple() is implemented.
  if (!isset($account->roles)) {
    $account->roles = array(
      DRUPAL_AUTHENTICATED_RID => 'authenticated user',
    );
    $account->roles += db_query('SELECT r.rid, r.name FROM {role} r INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid = :uid', array(
      ':uid' => $account->uid,
    ))
      ->fetchAllKeyed();
  }
  $role_max = 0;
  foreach ($account->roles as $id => $role) {
    $new_max = variable_get("privatemsg_limits_{$name}_role_" . $id, NULL);
    if ($new_max == 'unlimited') {
      return 0;
    }
    if ($new_max > $role_max) {
      $role_max = $new_max;
    }
  }
  if ($role_max == 0) {
    return variable_get('privatemsg_limits_' . $name, 0);
  }
  return $role_max;
}