function notifications_digest_build_long in Notifications 6.4
Same name and namespace in other branches
- 6.3 notifications_digest/notifications_digest.module \notifications_digest_build_long()
Digest multiple events in a single message, long format.
We use digest templates for subject, header, footer digest-subject digest-header digest-footer but the regular templates for the message body for each event event-[type]-[action]-main or event-[type]-main or event-main
Return value
array with messages ready to be sent
1 string reference to 'notifications_digest_build_long'
- notifications_digest_notifications in notifications_digest/
notifications_digest.module - Implementation of hook_notifications()
File
- notifications_digest/
notifications_digest.module, line 230 - Notifications digest module
Code
function notifications_digest_build_long($template, $events, $subscriptions, $module = 'notifications') {
$send_method = $template->method;
$destination = $template
->get_destination();
$account = $template
->get_user();
$language = $template
->get_language();
// Build a unique message from this template
$message = clone $template;
// Main texts of the message, get all in one replacement, then strip out the subject
$text['subject'] = notifications_digest_message_part('subject', $send_method, NULL, NULL, $language, $module);
$text['header'] = notifications_digest_message_part('header', $send_method, NULL, NULL, $language, $module);
$text['footer'] = notifications_digest_message_part('footer', $send_method, NULL, NULL, $language, $module);
$message->text_parts = $text;
// We dont pass a subscription object here, won't be too much use anyway
$text = messaging_template_text_replace($text, array(
'destination' => $destination,
'user' => $account,
'subscription' => NULL,
), $language);
$message->subject = $text['subject'];
// Build the message body as an array of event notifications
$body = array();
// Build up the digested list with text replacement, body as big array
// We need text replacement for each line because it depends on different objects
foreach ($events as $event) {
notifications_debug('Digesting long format', array(
'event' => $event,
));
$event_subscriptions = isset($subscriptions[$event->eid]) ? array_filter($subscriptions[$event->eid]) : array();
$message
->add_event($event, $event_subscriptions);
// We use the regular template for the events
$part = array();
$part[] = $event
->message_part('subject', $send_method, $language, $module);
$part[] = $event
->message_part('main', $send_method, $language, $module);
// Pass only the first subscription here
$subscription = $event_subscriptions ? notifications_load_subscription(current($event_subscriptions)) : NULL;
$objects = $event
->get_objects() + array(
'user' => $account,
'subscription' => $subscription,
'event' => $event,
);
$body = array_merge($body, messaging_template_text_replace($part, $objects, $language));
$message->text_parts['list'][$event->eid] = $part;
}
// Compose subject and body. All these lines have been text replaced, chance for theming
$message->body = theme('notifications_digest_long_body', $text['header'], $body, $text['footer']);
return array(
$message,
);
}