You are here

function simplenews_count_subscriptions in Simplenews 8

Same name and namespace in other branches
  1. 6.2 includes/simplenews.admin.inc \simplenews_count_subscriptions()
  2. 7.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.

3 calls to simplenews_count_subscriptions()
SimplenewsAdministrationTest::testSubscriptionManagement in src/Tests/SimplenewsAdministrationTest.php
Test newsletter subscription management.
SpoolStorage::addFromEntity in src/Spool/SpoolStorage.php
Add the newsletter node to the mail spool.
SpoolStorage::issueSummary in src/Spool/SpoolStorage.php
Returns a summary of key newsletter issue parameters.
1 string reference to 'simplenews_count_subscriptions'
SimplenewsAdministrationTest::testSubscriptionManagement in src/Tests/SimplenewsAdministrationTest.php
Test newsletter subscription management.

File

./simplenews.module, line 1017
Simplenews node handling, sent email, newsletter block and general hooks

Code

function simplenews_count_subscriptions($newsletter_id) {
  $subscription_count =& drupal_static(__FUNCTION__);
  if (isset($subscription_count[$newsletter_id])) {
    return $subscription_count[$newsletter_id];
  }

  // @todo: entity query + aggregate
  $query = \Drupal::database()
    ->select('simplenews_subscriber__subscriptions', 'ss');
  $query
    ->leftJoin('simplenews_subscriber', 'sn', 'sn.id = ss.entity_id');
  $query
    ->condition('subscriptions_target_id', $newsletter_id)
    ->condition('sn.status', SubscriberInterface::ACTIVE)
    ->condition('ss.subscriptions_status', SIMPLENEWS_SUBSCRIPTION_STATUS_SUBSCRIBED);
  $subscription_count[$newsletter_id] = $query
    ->countQuery()
    ->execute()
    ->fetchField();
  return $subscription_count[$newsletter_id];
}