You are here

function simplenews_count_subscriptions in Simplenews 7.2

Same name and namespace in other branches
  1. 8 simplenews.module \simplenews_count_subscriptions()
  2. 6.2 includes/simplenews.admin.inc \simplenews_count_subscriptions()
  3. 7 includes/simplenews.admin.inc \simplenews_count_subscriptions()

Count number of subscribers per newsletter list.

Parameters

$newsletter_id: The newsletter id.

Return value

Number of subscribers.

2 calls to simplenews_count_subscriptions()
SimpleNewsAdministrationTestCase::testSubscriptionManagement in tests/simplenews.test
Test newsletter subscription management.
simplenews_admin_issues in includes/simplenews.admin.inc
Form builder: Builds a list of newsletters with operations.
1 string reference to 'simplenews_count_subscriptions'
SimpleNewsAdministrationTestCase::testSubscriptionManagement in tests/simplenews.test
Test newsletter subscription management.

File

includes/simplenews.admin.inc, line 1662
Newsletter admin, subscription admin, simplenews settings

Code

function simplenews_count_subscriptions($newsletter_id) {
  $subscription_count =& drupal_static(__FUNCTION__);
  if (isset($subscription_count[$newsletter_id])) {
    return $subscription_count[$newsletter_id];
  }
  $query = db_select('simplenews_subscription', 'ss');
  $query
    ->leftJoin('simplenews_subscriber', 'sn', 'sn.snid = ss.snid');
  $query
    ->condition('newsletter_id', $newsletter_id)
    ->condition('sn.activated', 1)
    ->condition('status', SIMPLENEWS_SUBSCRIPTION_STATUS_SUBSCRIBED);
  $subscription_count[$newsletter_id] = $query
    ->countQuery()
    ->execute()
    ->fetchField();
  return $subscription_count[$newsletter_id];
}