You are here

function notifications_process_message in Notifications 5

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

Creates a single message for a single event

Parameters

$account: Destination user account

$event: Event object which caused this notification

$subscriptions: Array of subscription ids

Return value

Message array

2 calls to notifications_process_message()
notifications_process_send in ./notifications.cron.inc
Message delivery.
Notifications_Templates_Tests::testNotificationsTemplateAPI in tests/notifications_templates.test
Play with creating, retrieving, deleting a pair subscriptions

File

./notifications.cron.inc, line 515

Code

function notifications_process_message($account, $event, $subscriptions, $send_method) {
  $info = notifications_event_text($event);

  // Create message. Do all this in one replacemente
  $text = array(
    'subject' => notifications_message_part('event', 'subject', $send_method, $event),
    'header' => notifications_message_part('event', 'header', $send_method, $event),
    'event' => notifications_message_part('event', 'main', $send_method, $event),
    'footer' => notifications_message_part('event', 'footer', $send_method, $event),
  );

  // We pass only the first subscription, which is at least something
  // @ TODO Handle nicely the case where there are more than one subscription
  if ($sid = array_shift($subscriptions)) {
    $subscription = notifications_load_subscription($sid);
  }
  else {
    $subscription = NULL;
  }
  $objects = array(
    'user' => $account,
    'event' => $event,
    'subscription' => $subscription,
  );
  $objects = array_merge($objects, $event->objects);
  $text = notifications_text_replace($text, $objects);

  // Get subject out of text and build the message array
  $subject = $text['subject'];
  unset($text['subject']);
  return array(
    'subject' => $subject,
    'body' => $text,
  );
}