You are here

function hosting_site_count in Hostmaster (Aegir) 6

Returns a count of sites.

This is used by cron and statistics to batch the number of sites that are processed with each call. It is also used to generate the 'site count' per platform at /hosting/platforms

By default it only counts enabled sites.

Optionally can include an array of site statuses by which to consider in the count.

Parameters

$platform: (optional) A platform nid to only count sites on that specific platform.

$statuses: (optional) An array of site statuses (defined by their constants) by which to include such sites in the site count.

Return value

The number of sites matching the specified criteria.

2 calls to hosting_site_count()
hosting_cron_hosting_queues in modules/hosting/cron/hosting_cron.module
Implementation of hook_hosting_queues().
hosting_platform_listing in modules/hosting/platform/hosting_platform.module
Simple list for top level navigation.

File

modules/hosting/site/hosting_site.module, line 314

Code

function hosting_site_count($platform = NULL, $statuses = NULL) {
  if (is_null($statuses)) {
    $statuses = array(
      HOSTING_SITE_ENABLED,
    );
  }
  $args = array();
  $query = "SELECT count(nid) FROM {hosting_site}";
  $where = array();
  if (count($statuses)) {
    $where[] = '(status IN (' . db_placeholders($statuses) . '))';
    $args = array_merge($args, $statuses);
  }
  if (!is_null($platform)) {
    $where[] = "(platform = %d)";
    $args[] = $platform;
  }
  if (!empty($where)) {
    $query .= ' WHERE ' . implode(' AND ', $where);
  }
  return db_result(db_query($query, $args));
}