You are here

function notifications_lite_send in Notifications 6.3

Same name and namespace in other branches
  1. 5 notifications_lite/notifications_lite.module \notifications_lite_send()
  2. 6.4 notifications_lite/notifications_lite.module \notifications_lite_send()
  3. 6 notifications_lite/notifications_lite.module \notifications_lite_send()
  4. 6.2 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 or user account 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.

3 calls to notifications_lite_send()
NotificationsBasicTests::testNotificationsBasicAPI in tests/notifications_api.test
Play with creating, retrieving, deleting a pair subscriptions
NotificationsLiteTests::sendLiteMessages in tests/notifications_lite.test
NotificationsLiteTests::testNotificationsLite in tests/notifications_lite.test
Test simple sending cases

File

notifications_lite/notifications_lite.module, line 41
Simple notifications API

Code

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

  // Determine user account and build message array
  if (is_object($uid)) {
    $account = $uid;
  }
  elseif (function_exists('messaging_load_user')) {
    $account = messaging_load_user($uid);
  }
  else {
    $account = user_load(array(
      'uid' => $uid,
    ));
  }
  $language = user_preferred_language($account);
  $message = notifications_lite_build($subject, $body, $action, $language, $params);
  $accounts = array(
    $account,
  );

  // Send using the first available option
  if (module_exists('notifications')) {

    // So we have the full Notifications system enabled
    return notifications_lite_notifications_post($accounts, $message, $params);
  }
  elseif (module_exists('messaging')) {

    // We just have the Messaging system, that's something
    return notifications_lite_messaging_post($accounts, $message, $params);
  }
  else {

    // We don't have anything else so we use Drupal's mail
    return notifications_lite_drupal_post($accounts, $message, $params);
  }
}