You are here

function userpoints_get_max_points in User Points 6

Same name and namespace in other branches
  1. 5.3 userpoints.module \userpoints_get_max_points()
  2. 7.2 userpoints.module \userpoints_get_max_points()
  3. 7 userpoints.module \userpoints_get_max_points()

Parameters

uid: user id of the user to get or lose the points:

Return value

number of max points in that user's account

1 call to userpoints_get_max_points()
UserpointsTestCase::testBasicCall in tests/userpoints_api.test

File

./userpoints.module, line 530

Code

function userpoints_get_max_points($uid = NULL, $tid = NULL) {
  static $max = array();

  // Check if uid is passed as a parameter
  if (!$uid) {

    // It is not, so we use the currently logged in user's uid
    global $user;
    $uid = $user->uid;
  }

  // Check if a term id is passed as a parameter
  if (!$tid) {

    // It is not, so get the default term id
    $tid = userpoints_get_default_tid();
  }

  // Check if we have already cached the maximum for the user/term combination on previous calls
  if (!isset($max[$uid][$tid])) {

    // We did not cache it
    if ($tid == 'all') {

      // There is no term id, so we use "all"
      $max[$uid][$tid] = db_result(db_query('SELECT SUM(max_points) FROM {userpoints} WHERE uid = %d', $uid));
    }
    else {

      // A term ID is specified, so fetch its maximum points
      $max[$uid][$tid] = db_result(db_query('SELECT max_points FROM {userpoints} WHERE uid = %d AND tid = %d', $uid, $tid));
    }
  }

  // Return
  return $max[$uid][$tid];
}