hosting_site.quota.inc

Quota-relaled hooks for the Hosting site module.

Functions

File

site/hosting_site.quota.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Quota-relaled hooks for the Hosting site module.
  5. */
  6. /**
  7. * Implements hook_hosting_quota_resource().
  8. */
  9. function hosting_site_hosting_quota_resource() {
  10. $resources = array();
  11. $resources['sites'] = array(
  12. 'title' => t('Sites'),
  13. 'description' => t('The number of sites this client can have provisioned under them at any one time. Set to 0 for unlimited.'),
  14. 'module' => 'hosting_site',
  15. );
  16. return $resources;
  17. }
  18. /**
  19. * Implements hook_hosting_quota_get_usage().
  20. */
  21. function hosting_site_hosting_quota_get_usage($client, $resource, $start = NULL, $end = NULL) {
  22. if (hosting_get_client($client) && $resource == 'sites') {
  23. return db_query("SELECT count(*) FROM {hosting_site} WHERE client = :client AND status <> :status", array(':client' => $client, ':status' => HOSTING_SITE_DELETED))->fetchField();
  24. }
  25. }
  26. /**
  27. * Implements hook_hosting_quota_resource_render().
  28. */
  29. function hosting_site_hosting_quota_resource_render($resource, $usage) {
  30. return t('@usage sites', array('@usage' => $usage));
  31. }
  32. /**
  33. * Check for quotas and return an appropriate error message to the site creation form
  34. */
  35. function hosting_site_quota_exceeded($node) {
  36. $client = hosting_get_client_by_uname($node->client);
  37. $client = node_load($client->nid, NULL, TRUE);
  38. $usage = hosting_site_hosting_quota_get_usage($client->nid, 'sites');
  39. $limit = $client->quota['sites']['limit'];
  40. if ($usage >= $limit && !empty($limit)) {
  41. return t('@client has reached their site quota of @sites. No new sites can be added unless an existing site is deleted or the site quota is increased.', array('@client' => $client->title, '@sites' => $limit));
  42. }
  43. return FALSE;
  44. }