You are here

function userpoints_get_current_points in User Points 6

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. 7.2 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'.

$reset: Reset the static cache.

Return value

Number of current points in that user's account. No return value if $reset is passed.

11 calls to userpoints_get_current_points()
UserpointsTestCase::testBasicCall in tests/userpoints_api.test
UserpointsTestCase::testExpiration in tests/userpoints_api.test
userpoints_block in ./userpoints.module
userpoints_list_my_userpoints in ./userpoints.module
userpoints_rules_amount in ./userpoints_rules.rules.inc
Condition: check current Userpoints

... See full list

File

./userpoints.module, line 501

Code

function userpoints_get_current_points($uid = NULL, $tid = NULL, $reset = FALSE) {
  static $points = array();
  if ($reset) {
    $points = array();
    return;
  }
  if (!$uid) {
    global $user;
    $uid = $user->uid;
  }
  if (!$tid) {
    $tid = userpoints_get_default_tid();
  }
  if (!isset($points[$uid][$tid])) {
    if ($tid == 'all') {
      $points[$uid][$tid] = (int) db_result(db_query('SELECT SUM(points) FROM {userpoints} WHERE uid = %d', $uid));
    }
    else {
      $points[$uid][$tid] = (int) db_result(db_query('SELECT points FROM {userpoints} WHERE uid = %d AND tid = %d', $uid, $tid));
    }
  }
  return $points[$uid][$tid];
}