You are here

function notifications_process_message in Notifications 6

Same name and namespace in other branches
  1. 5 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()
NotificationsTemplatesTests::testNotificationsTemplates in tests/notifications_templates.test
Play with creating, retrieving, deleting a pair subscriptions
notifications_process_send in ./notifications.cron.inc
Message delivery.

File

./notifications.cron.inc, line 404

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 = messaging_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,
  );
}