You are here

function hosting_quota_get_usage in Hosting 6.2

Same name and namespace in other branches
  1. 7.4 quota/hosting_quota.module \hosting_quota_get_usage()
  2. 7.3 quota/hosting_quota.module \hosting_quota_get_usage()

Get the usage for the specified resource

This function does not always return a human readable value - in some cases the value may be in bits or bytes, and needs the appropriate hook_hosting_quota_render_resource function to be called in order to be readable.

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

An integer representing the quota usage

2 calls to hosting_quota_get_usage()
hosting_quota_admin_client_list in quota/hosting_quota.admin.inc
Page callback for admin/hosting/quotas
hosting_quota_get_all_info in quota/hosting_quota.module
Get the rendered usage and info for all resources

File

quota/hosting_quota.module, line 94
Implement quota's for the resource used by client.

Code

function hosting_quota_get_usage($client, $resource, $start = NULL, $end = NULL) {
  $quota_usage = 0;

  // 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 the resource info if necessary
  if (!is_array($resource)) {
    $resource = hosting_quota_get($resource);
  }
  $resource_name = key($resource);
  $resource = $resource[$resource_name];

  // We're finally ready to fetch the usage info!
  if ($resource['module']) {
    $quota_usage = module_invoke($resource['module'], 'hosting_quota_get_usage', $client, $resource_name, $start, $end);
  }
  return $quota_usage;
}