You are here

function userpoints_get_current_points in User Points 7.2

Same name and namespace in other branches
  1. 5.3 userpoints.module \userpoints_get_current_points()
  2. 5 userpoints.module \userpoints_get_current_points()
  3. 5.2 userpoints.module \userpoints_get_current_points()
  4. 6 userpoints.module \userpoints_get_current_points()
  5. 7 userpoints.module \userpoints_get_current_points()

Get current points of a user.

Parameters

$uid: User ID of the user to get or lose the points.

$tid: Term ID to get points for, or 'all'.

Return value

Number of current points in that user's account.

Related topics

11 calls to userpoints_get_current_points()
UserpointsAdminTestCase::testAddEditPoints in ./userpoints.test
UserpointsBaseTestCase::addPoints in ./userpoints.test
Add points through the admin form.
UserpointsBaseTestCase::verifyPoints in ./userpoints.test
Verify the current and optionally max points in a specific category.
UserpointsServiceTestCase::testAddRetrievePoints in userpoints_service/userpoints_service.test
Basic tests for granting and retreiving points through a service.
UserpointsTransaction::getMessage in ./userpoints.transaction.inc
A message that can be displayed to the current user.

... See full list

File

./userpoints.module, line 623

Code

function userpoints_get_current_points($uid = NULL, $tid = NULL) {
  $points = drupal_static(__FUNCTION__, array());
  if (!$uid) {
    global $user;
    $uid = $user->uid;
  }

  // 0 is a valid value for the Uncategorized category.
  if (!isset($tid)) {
    $tid = userpoints_get_default_tid();
  }
  if (!isset($points[$uid][$tid])) {
    if ($tid === 'all') {
      $points[$uid][$tid] = (int) db_query('SELECT points FROM {userpoints_total} WHERE uid = :uid', array(
        ':uid' => $uid,
      ))
        ->fetchField();
    }
    else {
      $points[$uid][$tid] = (int) db_query('SELECT points FROM {userpoints} WHERE uid = :uid AND tid = :tid', array(
        ':uid' => $uid,
        ':tid' => $tid,
      ))
        ->fetchField();
    }
  }
  return $points[$uid][$tid];
}