You are here

function notifications_process_send in Notifications 6

Same name and namespace in other branches
  1. 5 notifications.cron.inc \notifications_process_send()
  2. 6.2 notifications.cron.inc \notifications_process_send()
  3. 6.3 notifications.cron.inc \notifications_process_send()

Message delivery.

Processes everything, included 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)

3 calls to notifications_process_send()
NotificationsTemplatesTests::testNotificationsTemplates in tests/notifications_templates.test
Play with creating, retrieving, deleting a pair subscriptions
notifications_process_queue in ./notifications.cron.inc
Process subscriptions queue
notifications_process_rows in ./notifications.cron.inc
Process rows given query conditions

File

./notifications.cron.inc, line 353

Code

function notifications_process_send($account, $events, $subscriptions, $send_method, $send_interval) {
  notifications_log('Processing for sending', array(
    'method' => $send_method,
    'interval' => $send_interval,
    '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);
  }
  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;
    }
  }

  // Now send messages, not if testing enabled
  $test = notifications_process('option', 'test');
  foreach ($messages as $message) {
    notifications_process('count', 'send');
    notifications_log('Sending out', array(
      'method' => $send_method,
      'message' => $message,
    ));
    if (!$test) {
      notifications_message_send($account, $message, $send_method);
    }
  }
  return $messages;
}