You are here

function notifications_lite_send in Notifications 5

Same name and namespace in other branches
  1. 6.4 notifications_lite/notifications_lite.module \notifications_lite_send()
  2. 6 notifications_lite/notifications_lite.module \notifications_lite_send()
  3. 6.2 notifications_lite/notifications_lite.module \notifications_lite_send()
  4. 6.3 notifications_lite/notifications_lite.module \notifications_lite_send()

Sends out a notification for a user

This is all it takes for a module to send out some notification for a user.

However, a real event is produced so other modules may want to provide secondary subscriptions and notifications for these simple events

Parameters

$uid: User id for destination

$subject: Notification subject

$body: Optional notification body

$action: Optional action name, so other modules can define specific message parts for their actions

$params: Optional array of additional parameters to be stored with the event. For example, one could store the sender of a message, as otherwise this information might not be easily retrievable during message sending on cron. Only available when the full notification system is used and not just the messaging module.

Note: Even when notifications module is enabled, the 'send interval' will be always immediate (0) for this kind of messages.

File

notifications_lite/notifications_lite.module, line 43
Simple notifications API

Code

function notifications_lite_send($uid, $subject, $body = '', $action = 'default', $params = array()) {
  if (module_exists('notifications')) {

    // So we have the full Notifications system enabled
    return notifications_lite_add_to_queue($uid, $subject, $body, $action, $params);
  }
  elseif (module_exists('messaging')) {

    // We just have the Messaging system, that's something
    $account = messaging_load_user($uid);
    $message = array(
      'type' => 'notifications-lite',
      'subject' => $subject,
      'body' => empty($body) ? $subject : $body,
    );
    return messaging_message_send_user($account, $message);
  }
  else {

    // We don't have anything else so we use Drupal's mail
    $account = user_load(array(
      'uid' => $uid,
    ));
    return drupal_mail('notifications-lite-' . $action, $account->mail, $subject, empty($body) ? $subject : $body);
  }
}