function hosting_quota_check in Hosting 6.2
Same name and namespace in other branches
- 7.4 quota/hosting_quota.module \hosting_quota_check()
- 7.3 quota/hosting_quota.module \hosting_quota_check()
Quickly check if a given quota has been exceeded
Parameters
$client int: The nid of the client node
$resource string: The machine name of the resource, or a resource as returned by hosting_quota_get
$start string: Optional start date of the checking perios, defaults to 1st of last month
$end string: Optional end date of the checked period, defaults to 1st of this month
Return value
True if the limit is higher than usage, false otherwise, or null if the resource could not be checked
File
- quota/
hosting_quota.module, line 174 - Implement quota's for the resource used by client.
Code
function hosting_quota_check($client, $resource, $start = NULL, $end = NULL) {
// Set up some default dates for the last month if necessary
if (!$start || !$end) {
$end = date('Y-m-d', mktime(0, 0, 0, date("m"), 1, date("Y")));
$start = date('Y-m-d', mktime(0, 0, 0, date("m") - 1, 1, date("Y")));
}
// Get info about the resource if necessary
if (!is_array($resource)) {
$resource = hosting_quota_get($resource);
}
$resource_name = key($resource);
$resource = $resource[$resource_name];
// Get usage and limit for the selected resource
if ($resource['module']) {
$resource_usage = module_invoke($resource['module'], 'hosting_quota_get_usage');
$resource_limit = db_result(db_query('SELECT value FROM {hosting_client_quota} WHERE client = %d AND resource = "%s"', $client, $resource_name));
// Return the appropriate values
if ($resource_limit > $resource_usage) {
return TRUE;
}
else {
return FALSE;
}
}
return NULL;
}