You are here

function simplenews_scheduler_get_newsletter_accounts in Simplenews Scheduler 6.2

1 call to simplenews_scheduler_get_newsletter_accounts()
_simplenews_scheduler_send_new_edition in ./simplenews_scheduler.module
Helper for hook_cron() to send a new edition.

File

./simplenews_scheduler.module, line 548
Simplenews Scheduler module allows a schedule to be set for sending (and resending) a Simplenews item.

Code

function simplenews_scheduler_get_newsletter_accounts($newsletter_tid) {

  // taken from the newsletter subscription list
  $query = '
    SELECT DISTINCT ss.snid, ss.*, u.name
    FROM {simplenews_subscriptions} ss
    LEFT JOIN {users} u
      ON ss.uid = u.uid
    INNER JOIN {simplenews_snid_tid} s
      ON ss.snid = s.snid
    AND s.tid = %d AND s.status = 1';
  $result = db_query($query, $newsletter_tid);

  // build the accounts array

  /* @param array $accounts  account objects to send the newsletter to.
   *   account = object (
   *     snid     = subscription id, or 0 if no subscription record exists.
   *     tids     = array(tid) array of newsletter tid's.
   *     uid      = user id, or 0 if subscriber is anonymous user.
   *     mail     = user email address.
   *     name     = <empty>. Added for compatibility with user account object.
   *     language = language object. User-preferred or default language.
   *
   */
  $accounts = array();
  while ($account = db_fetch_object($result)) {
    $account->tids = array(
      $newsletter_tid,
    );
    $accounts[] = $account;
  }
  return $accounts;
}