You are here

function notifications_process_compose in Notifications 6.2

Same name and namespace in other branches
  1. 6.3 notifications.cron.inc \notifications_process_compose()

Message composition.

Processes everything, included templating and digestion and sends message/s.

Adds some more information into $message['notifications'] that may be used by other modules

Parameters

$account: User account to send the notification to

$events: Array of loaded event objects to be processed

$subscriptions: Array of arrays of subscription ids (sids) for each event(eid)

Return value

array() Array of messages ready for sending out

1 call to notifications_process_compose()
NotificationsTemplatesTests::testNotificationsTemplates in tests/notifications_templates.test
Play with creating, retrieving, deleting a pair subscriptions

File

./notifications.cron.inc, line 421

Code

function notifications_process_compose($account, $events, $subscriptions, $send_method, $send_interval, $module = 'notifications') {
  notifications_log('Processing for sending', array(
    'method' => $send_method,
    'interval' => $send_interval,
    'module' => $module,
    'events' => count($events),
  ));

  // Digest if send_interval > 0 (not immediate sending)
  if ($digest = notifications_digest_method($send_interval)) {
    $function = $digest['digest callback'];

    // It can be digested in more than one message by some other digest plug-in
    $messages = $function($account, $events, $subscriptions, $send_interval, $send_method, $module);
  }
  else {
    $sender_option = variable_get('notifications_sender', 0);
    foreach ($events as $event) {
      $message = notifications_process_message($account, $event, $subscriptions[$event->eid], $send_method);

      // We pass on the full information so it can be used by modules implementing some of the hooks
      $message['notifications'] = array(
        'events' => array(
          $event,
        ),
        'subscriptions' => $subscriptions,
      );

      // Optional sender, if chosen will be the user account who produced the event
      // It will be up to the sending method modules what to do with this information.
      if ($sender_option) {
        $sender = notifications_load_user($event->uid);
        $message['sender_name'] = $sender->name;
        if ($sender_option == 2) {
          $message['sender_account'] = $sender;
        }
      }
      $messages[] = $message;
    }
  }
  return $messages;
}