function hosting_quota_check in Hosting 7.4
Same name and namespace in other branches
- 6.2 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
bool|null True if the limit is higher than usage, false otherwise, or null if the resource could not be checked
1 call to hosting_quota_check()
- hosting_site_quota_exceeded in site/
hosting_site.quota.inc - Check for quotas and return an appropriate error message to the site creation form.
File
- quota/
hosting_quota.module, line 210 - 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_name = $resource;
$resource = hosting_quota_get($resource);
}
// Get usage and limit for the selected resource
if ($resource['module']) {
if (user_access("bypass all quotas")) {
return TRUE;
}
if (user_access("bypass resource {$resource_name} limit")) {
return TRUE;
}
$resource_usage = module_invoke($resource['module'], 'hosting_quota_get_usage', $client, $resource_name, $start, $end);
$resource_limit = db_query('SELECT value FROM {hosting_client_quota} WHERE client = :client AND resource = :resource', array(
':client' => $client,
':resource' => $resource_name,
))
->fetchField();
// Return the appropriate values
if ($resource_limit > $resource_usage) {
return TRUE;
}
else {
return FALSE;
}
}
return NULL;
}