You are here

function party_simplenews_subscriber_load_by_pid in Party 8.2

Load a subscriber by party_id

Parameters

$pid Party:

$ref The field ref of the email field. Normally takes the form: DATA_SET_NAME__ENTITY_ID__FIELD_NAME__DELTA

4 calls to party_simplenews_subscriber_load_by_pid()
party_simplenews_entity_delete in modules/party_simplenews/party_simplenews.module
Implements hook_entity_delete()
party_simplenews_entity_update in modules/party_simplenews/party_simplenews.module
Implements hook_entity_update.
party_simplenews_party_subscription_settings_view in modules/party_simplenews/party_simplenews.module
Implements hook_party_subscription_settings_view()
party_subscription_settings_edit_form in modules/party_simplenews/party_subscription_settings.api.inc
Party subscription settings edit form

File

modules/party_simplenews/party_simplenews.module, line 111
Main module file for Party Simplenews integration

Code

function party_simplenews_subscriber_load_by_pid($party = NULL, $ref = NULL) {
  $query = db_select('party_simplenews_subscriber', 'pss');
  $query
    ->leftJoin('simplenews_subscriber', 'ss', 'pss.snid = ss.snid');
  $query
    ->fields('ss', array(
    'snid',
  ))
    ->fields('pss', array(
    'party_id',
    'party_field_ref',
  ));
  if (!empty($party)) {
    $query
      ->condition('pss.party_id', $party);
  }
  if (!empty($ref)) {
    $query
      ->condition('pss.party_field_ref', $ref);
  }
  $extras = $query
    ->execute()
    ->fetchAllAssoc('snid');
  if (empty($extras)) {
    return FALSE;
  }
  $subscribers = simplenews_subscriber_load_multiple(array_keys($extras));
  foreach ($subscribers as $subscriber) {
    $subscriber->party_id = $extras[$subscriber->snid]->party_id;
    $subscriber->party_field_ref = $extras[$subscriber->snid]->party_field_ref;
  }
  if (!empty($ref)) {
    return $subscribers ? reset($subscribers) : FALSE;
  }
  return $subscribers ? $subscribers : FALSE;
}