You are here

function notifications_process_digest_short in Notifications 6.2

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

Digest multiple events in a single message, short format.

Return value

array with messages ready to be sent

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

File

./notifications.cron.inc, line 779

Code

function notifications_process_digest_short($account, $events, $subscriptions, $send_interval, $send_method, $module = 'notifications') {

  // Compile list of events for each object
  $list = array();

  // Build up the digested list with text replacement
  // We need text replacement for each line because it depends on different objects
  foreach ($events as $event) {
    notifications_log('Digesting short format', array(
      'event' => $event,
    ));
    $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,
    );

    // $info = notifications_event_types($event->type, $event->action);
    $digest = nofitications_digest_event_info($event);
    $digest_type = $digest['type'];
    $digest_value = $digest['value'];
    if (!isset($list[$digest_type][$digest_value]['group'])) {
      $group = array(
        'title' => notifications_digest_group($digest, 'title', $send_method),
        'footer' => notifications_digest_group($digest, 'closing', $send_method),
      );

      // The objects passed here for tokens will be the ones from the first event only
      $list[$digest_type][$digest_value]['group'] = messaging_text_replace($group, $objects);
      notifications_log('Digesting object', array(
        'type' => $digest_type,
        'value' => $digest_value,
      ));
    }

    // Check duplicate notifications for the same event so we do some deduping
    if (!isset($list[$digest_type][$digest_value]['line'][$event->eid])) {
      $line = notifications_digest_line($event, $send_method, $objects);
      $objects['event'] = $event;
      $list[$digest_type][$digest_value]['line'][$event->eid] = messaging_text_replace($line, $objects);
    }
  }

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

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

  // Compose body. All these lines have been text replaced
  $body = theme('notifications_digest_short_body', $text, $list);

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