function _privatemsg_limits_get_amount in Privatemsg 6.2
Same name and namespace in other branches
- 7.2 privatemsg_limits/privatemsg_limits.module \_privatemsg_limits_get_amount()
- 7 privatemsg_limits/privatemsg_limits.module \_privatemsg_limits_get_amount()
Loads the maximum value of a treshold value, takes roles into account.
Parameters
string $name Unique part of the name:
user $account User object:
Return value
int 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 232 - 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',
);
$result = db_query('SELECT r.rid, r.name FROM {role} r INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid = %d', $account->uid);
while ($role = db_fetch_object($result)) {
$account->roles[$role->rid] = $role->name;
}
}
$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;
}