Handling of unlimit and empty quota
Max_Headroom - December 31, 2008 - 12:10
| Project: | User Quota |
| Version: | 6.x-1.0-beta1 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Description
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
<?php
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?

#1
code error in previous listing:
<?phpfunction 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;
}
}
?>
#2
This is a potential problem with the module.
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?
#3
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.