function party_simplenews_party_subscription_settings_view in Party 8.2
Implements hook_party_subscription_settings_view()
File
- modules/
party_simplenews/ party_simplenews.module, line 508 - Main module file for Party Simplenews integration
Code
function party_simplenews_party_subscription_settings_view($entity) {
$party = party_subscription_settings_get_party($entity);
$entity->content['subscriptions'] = array(
'#type' => 'fieldset',
'#title' => t('Newsletters'),
);
// Collect newsletter to which the current user is subscribed.
// 'hidden' newsletters are not listed.
$newsletters = simplenews_category_get_visible();
$subscribers = party_simplenews_subscriber_load_by_pid($party->pid);
// For each newsletter, ascertain if the party is subscribed to it
foreach ($newsletters as $newsletter) {
$subscribed_emails = array();
// In theory, a Party could be subscribed to a newsletter multiple times,
// Iterate over all the party's subscribers and check if they're subscribed to
// the newsletter.
foreach ($subscribers as $subscriber) {
if (isset($subscriber->newsletter_subscription[$newsletter->tid]) && $subscriber->newsletter_subscription[$newsletter->tid]->status == TRUE) {
$subscribed_emails[] = $subscriber->mail;
}
}
// If atleast one of the party's addresses is subscribed to the newsletter
// add the newsletter to the list of links with a list of subscribed emails
// next to it.
if (!empty($subscribed_emails)) {
$emails = ' <small>(' . implode($subscribed_emails, ',') . ')</small>';
$links[] = l(_simplenews_newsletter_name($newsletter), 'taxonomy/term/' . $newsletter->tid) . $emails;
}
}
if (empty($links)) {
$entity->content['subscriptions']['subscriptions'] = array(
'#title' => t('Subscribed to'),
'#markup' => t('None'),
);
}
else {
$entity->content['subscriptions']['subscriptions'] = array(
'#theme' => 'item_list',
'#type' => 'item_list',
'#title' => t('Subscribed to'),
'#items' => $links,
);
}
}