Hi
Currently, if no quota has been set for a user, he has unlimited quotas, because there is no entry in the database yet.
When quotas are given, he has x amount and an entry is made in the database.
When he used up his quota, he blocked as he now have an entry in the database with 0 quotas.

There is no way that a user can be given unlimited quotas again, unless the entry in the database is deleted (currently manually).

I'm busy making some add ons to this module for use on a web page, which I will share when I'm done.
I want to propose the following:
All users with no set quotas (no db entries) are blocked.
Users with say +1000 quotas are unlimited

function user_quota_get_limit($type, $user = FALSE) {
  if (!$user) {
    global $user;
  }
  $limit = db_result(db_query("SELECT current_limit FROM {user_quota} WHERE uid = %d AND type = '%s'", $user->uid, $type));
  if (is_numeric($limit)) {
    if ($limit >= 1000) {
      return 'unlimited'
    }
    else {
    return $limit;
  }
  else {
    return 0;
  }
}

Your thoughts?

Comments

Max_Headroom’s picture

code error in previous listing:

function user_quota_get_limit($type, $user = FALSE) {
  if (!$user) {
    global $user;
  }
  $limit = db_result(db_query("SELECT current_limit FROM {user_quota} WHERE uid = %d AND type = '%s'", $user->uid, $type));
  if (is_numeric($limit)) {
    if ($limit >= 1000) {
      return 'unlimited';
    }
    else {
      return $limit;
    }
  }
  else {
    return 0;
  }
}
greggles’s picture

All users with no set quotas (no db entries) are blocked.

This is a potential problem with the module.

Users with say +1000 quotas are unlimited

I don't really like this solution much :/

Here are the potential solutions I can think of:

1. We make it admin configurable whether users without a record are blocked or not.
2. We change the quota column to a varchar and either store a number, in which case they are limited, or we store the word unlimited in which case they are unlimited...

Thoughts?

Max_Headroom’s picture

I don't really like this solution much :/

Actually me neither ;)

I would suggest creating a status column, where you can set a users' status to Blocked, Active, Unlimited. That way you have more control without affecting a users quota.

greggles’s picture

Yeah, a new status column sounds good to me.

Unlimited makes sense. But why do we need "blocked" and "active"? Why not just "limited/unlimited" as the two options?