You are here

function hosting_site_count in Hosting 6.2

Same name and namespace in other branches
  1. 5 site/hosting_site.module \hosting_site_count()
  2. 7.4 site/hosting_site.module \hosting_site_count()
  3. 7.3 site/hosting_site.module \hosting_site_count()

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.

3 calls to hosting_site_count()
hosting_cron_hosting_queues in cron/hosting_cron.module
Implementation of hook_hosting_queues().
hosting_platform_listing in platform/hosting_platform.module
Simple list for top level navigation.
views_handler_field_hosting_platform_sites::render in platform/views_handler_field_hosting_platform_sites.inc

File

site/hosting_site.module, line 458

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));
}