You are here

function invite_max_invites in Invite 5

Return max number of invites a user may send.

Parameters

$uid: A user id.

Return value

The number of invites the user may send.

1 call to invite_max_invites()
invite_form in ./invite.module
Generate the invite form.

File

./invite.module, line 925
Allows your users to send and track invitations to join your site.

Code

function invite_max_invites($uid = NULL) {
  global $user;
  $account = is_null($uid) ? $user : user_load(array(
    'uid' => $uid,
  ));
  if ($account->uid == 1) {
    return INVITE_UNLIMITED_INVITES;
  }
  $max = 0;
  foreach (user_roles(0, 'send invitations') as $role) {
    $role_no_space = str_replace(' ', '_', $role);
    if (in_array($role, $account->roles)) {
      $role_max = variable_get('invite_maxnum_' . $role_no_space, INVITE_UNLIMITED_INVITES);
      if ($role_max == INVITE_UNLIMITED_INVITES) {
        return INVITE_UNLIMITED_INVITES;
      }
      if ($role_max > $max) {
        $max = $role_max;
      }
    }
  }
  return $max;
}