You are here

function push_notifications_send_message_bulk in Push Notifications 7

Send a simple message alert to all tokens in the database.

Parameters

string $message Message to be included in payload.:

string $target_group Defines the target group for this message.: Valid options are:

  • any
  • authenticated
  • anonymous

Return value

mixed Flag indicating if message delivery was successful.

File

./push_notifications.module, line 540
Push Notifications functionality.

Code

function push_notifications_send_message_bulk($message = '', $target_group = '') {
  if (empty($message)) {
    watchdog('push_notifications', t('Message cannot be empty'));
    return false;
  }

  // Get all tokens in the system.
  $tokens = push_notifications_get_tokens(array(
    'account_type' => $target_group,
  ), true);

  // Let modules modify the message before it is sent.
  foreach (module_implements('push_notifications_send_message') as $module) {
    $function = $module . '_push_notifications_send_message';
    $function($message, $type = 'bulk');
  }

  // Shorten the message characters / 8 bit.
  $message = truncate_utf8($message, PUSH_NOTIFICATIONS_APNS_PAYLOAD_SIZE_LIMIT, TRUE, TRUE);

  // Convert the payload into the correct format for delivery.
  $payload = array(
    'alert' => $message,
  );

  // Stop right here if none of these users have any tokens.
  if (empty($tokens)) {
    return FALSE;
  }

  // Send out alert.
  push_notifications_send_alert($tokens, $payload);
}