You are here

function notifications_lite_send in Notifications 6.4

Same name and namespace in other branches
  1. 5 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.

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
Helper function to send messages and do queue processing
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()) {
  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 = notifications_load_user($uid);
    $message = array(
      'type' => 'notifications-lite',
      'subject' => $subject,
      'body' => empty($body) ? $subject : $body,
      'language' => user_preferred_language($account),
    );
    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,
    ));
    $params = array(
      'type' => 'notifications-lite',
      'subject' => $subject,
      'body' => empty($body) ? $subject : $body,
    );
    return drupal_mail('notifications_lite', 'notifications-lite-' . $action, $account->mail, user_preferred_language($account), $params);
  }
}