You are here

function notifications_process_digest_long in Notifications 5

Same name and namespace in other branches
  1. 6 notifications.cron.inc \notifications_process_digest_long()
  2. 6.2 notifications.cron.inc \notifications_process_digest_long()

Digest multiple events in a single message, long format.

Return value

array with messages ready to be sent

1 string reference to 'notifications_process_digest_long'
notifications_notifications in ./notifications.module
Implementation of notifications_hook()

File

./notifications.cron.inc, line 441

Code

function notifications_process_digest_long($account, $events, $subscriptions, $send_interval, $send_method) {

  // 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_log($event, 'digesting');

    // We use the regular template for the events
    $part = notifications_message_part('event', 'main', $send_method, $event);

    // Pass only the first subscription here
    $sid = is_array($subscriptions[$event->eid]) ? array_shift($subscriptions[$event->eid]) : 0;
    $subscription = $sid ? notifications_load_subscription($sid) : NULL;
    $objects = $event->objects + array(
      'user' => $account,
      'subscription' => $subscription,
    );
    $body[] = notifications_text_replace($part, $objects);
  }

  // Create message. Do all this in one replacement, then strip out the subject
  $text['subject'] = notifications_message_part('digest', 'subject', $send_method);
  $text['header'] = notifications_message_part('digest', 'header', $send_method);
  $text['footer'] = notifications_message_part('digest', 'footer', $send_method);

  // We dont pass a subscription object here, won't be too much use anyway
  $text = notifications_text_replace($text, array(
    'user' => $account,
    'subscription' => NULL,
  ));

  // Compose body. All these lines have been text replaced
  $body = theme('notifications_digest_long_body', $text['header'], $body, $text['footer']);

  // Build the final digested message, and return in an array
  $message = array(
    'subject' => $text['subject'],
    'body' => $body,
    'events' => $events,
    'subscriptions' => $subscriptions,
    'digest' => 'long',
  );
  return array(
    $message,
  );
}