You are here

function push_notifications_find_token in Push Notifications 7

Same name and namespace in other branches
  1. 8 push_notifications.module \push_notifications_find_token()

Determine if this user has already stored a token in the database. The same device token can be registered for multiple users, because multiple users can login from the same device.

Parameters

$token: Device Token.

$uid: User ID.

$exclude: Set this to true to find (at least one) other user(s) who have this token stored. Optional, defaults to false.

Return value

User ID of token, if found.

1 call to push_notifications_find_token()
_push_notifications_service_create_device_token in includes/push_notifications.service.inc
Service callback to store a device token.

File

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

Code

function push_notifications_find_token($token = '', $uid = '', $exclude = FALSE) {
  if ($token == '') {
    return FALSE;
  }
  $query = db_select('push_notifications_tokens', 'pnt');
  $query
    ->fields('pnt', array(
    'token',
  ));
  $query
    ->condition('pnt.token', $token);
  if ($exclude) {
    $query
      ->condition('pnt.uid', $uid, '!=');
    $query
      ->range(0, 1);
  }
  else {
    $query
      ->condition('pnt.uid', $uid);
  }
  $result = $query
    ->execute();
  return $result
    ->fetchField();
}