You are here

function invite_get_remaining_invites in Invite 6.2

Same name and namespace in other branches
  1. 5.2 invite.module \invite_get_remaining_invites()
  2. 7.2 invite.module \invite_get_remaining_invites()

Calculate the remaining invites of a user.

Parameters

$account: A user object.

Return value

The number of remaining invites.

2 calls to invite_get_remaining_invites()
invite_admin_overview in ./invite_admin.inc
Return a list of all users that have invited someone.
invite_form in ./invite.module
Generate the invite forms.

File

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

Code

function invite_get_remaining_invites($account) {
  if ($account->uid == 1) {
    return INVITE_UNLIMITED;
  }

  // Check user property for remaining invites.
  $data = unserialize($account->data);
  if (isset($data['invites'])) {
    $remaining = $data['invites'];
  }
  else {
    $remaining = invite_get_role_limit($account);
    if ($remaining > 0) {

      // Legacy support.
      $sent = db_result(db_query("SELECT COUNT(*) FROM {invite} WHERE uid = %d", $account->uid));
      $remaining = max($remaining - $sent, 0);
      if ($sent > 0) {

        // Update user property for faster lookup next time.
        user_save($account, array(
          'invites' => $remaining,
        ));
      }
    }
  }
  return $remaining;
}