You are here

function hosting_quota_get_all_info in Hostmaster (Aegir) 6

Get the rendered usage and info for all resources

Parameters

$client int: The nid of the client node

$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 array of info about the clients quotas

1 call to hosting_quota_get_all_info()
hosting_quota_nodeapi in modules/hosting/quota/hosting_quota.module
Implements hook_nodeapi().

File

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

Code

function hosting_quota_get_all_info($client, $start = NULL, $end = NULL) {
  static $quota_info;
  if (!isset($quota_info)) {
    $quota_info = array();

    // 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")));
    }
    $all_resources = module_invoke_all('hosting_quota_resource');
    foreach ($all_resources as $resource_name => $resource_data) {

      // First read in the info from the resource
      $quota_info[$resource_name] = $resource_data;

      // We have to format this way to to dependencies in quota imps
      $resource = array(
        $resource_name => $resource_data,
      );

      // Get usage info
      $quota_info[$resource_name]['usage'] = hosting_quota_get_usage($client, $resource, $start, $end);

      // Fetch info about the quota limit directly from the db
      $quota_info[$resource_name]['limit'] = db_result(db_query('SELECT value FROM {hosting_client_quota} WHERE client = %d AND resource = "%s"', $client, $resource_name));

      // Render both limits and usage
      $quota_info[$resource_name]['rendered usage'] = hosting_quota_resource_render($resource, $quota_info[$resource_name]['usage']);
      $quota_info[$resource_name]['rendered limit'] = hosting_quota_resource_render($resource, $quota_info[$resource_name]['limit']);
    }
  }
  return $quota_info;
}