You are here

function simplenews_subscriber_load_multiple in Simplenews 7

Same name and namespace in other branches
  1. 8 simplenews.module \simplenews_subscriber_load_multiple()
  2. 7.2 simplenews.module \simplenews_subscriber_load_multiple()

Loads simplenews subscriber objects.

Parameters

$snids: (Optional) Array of subscriber ID's.

$conditions: (Optional) Array of query conditions.

$reset: Reset the static cache.

Return value

Array of subscriber objects that match the given ID's/conditions.

Related topics

3 calls to simplenews_subscriber_load_multiple()
simplenews_subscriber_load in ./simplenews.module
Load a simplenews newsletter subscriber object.
simplenews_subscriber_load_by_mail in ./simplenews.module
Load a simplenews newsletter subscriber object.
simplenews_subscriber_load_by_uid in ./simplenews.module
Load a simplenews newsletter subscriber object.
1 string reference to 'simplenews_subscriber_load_multiple'
SimpleNewsAdministrationTestCase::testSubscriptionManagement in tests/simplenews.test
Test newsletter subscription management.

File

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

Code

function simplenews_subscriber_load_multiple($snids = array(), $conditions = array(), $reset = FALSE) {
  $subscribers =& drupal_static(__FUNCTION__, array());

  // Only cache if we load all records from the database.
  // @todo Caching could be improved.
  if (!$subscribers || $snids || $conditions || $reset) {
    $subscribers = array();
    $query = db_select('simplenews_subscriber', 'ss')
      ->fields('ss');
    if ($snids) {
      $query
        ->condition('snid', $snids);
    }
    if ($conditions) {
      foreach ($conditions as $key => $condition) {
        $query
          ->condition($key, $condition);
      }
    }
    $subscribers = $query
      ->execute()
      ->fetchAllAssoc('snid');
    if (!empty($subscribers)) {

      // Initialize default values and unserialize.
      foreach ($subscribers as $subscriber) {
        $subscriber->changes = unserialize($subscriber->changes);
        $subscriber->tids = array();
      }
      $query = db_select('simplenews_subscription', 'ss')
        ->fields('ss')
        ->condition('snid', array_keys($subscribers));
      foreach ($query
        ->execute() as $subscription) {
        if ($subscription->status == SIMPLENEWS_SUBSCRIPTION_STATUS_SUBSCRIBED) {
          $subscribers[$subscription->snid]->tids[$subscription->tid] = $subscription->tid;
        }
        $subscribers[$subscription->snid]->newsletter_subscription[$subscription->tid] = $subscription;
      }
    }
  }
  return $subscribers;
}