You are here

function push_notifications_find_token in Push Notifications 8

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

File

./push_notifications.module, line 117
Contains push_notifications.module 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();
}