You are here

function userpoints_get_max_points in User Points 7

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

Gets the number of maximal points of that user.

Parameters

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

Return value

Number of max points in that user's account.

6 calls to userpoints_get_max_points()
UserpointsAPITestCase::testBasicCall in tests/userpoints_api.test
Call userpoints_userpointsapi() with just points.
UserpointsBaseTestCase::verifyPoints in tests/userpoints_api.test
Verify the current and optionally max points in a specific category.
UserpointsServiceTestCase::testAddRetrievePoints in ./userpoints_service.test
Basic tests for granting and retreiving points through a service.
userpoints_service_get in ./userpoints_service.inc
Get the number of points of a given user.
userpoints_tokens in ./userpoints.module
Implements hook_tokens().

... See full list

1 string reference to 'userpoints_get_max_points'
UserpointsBaseTestCase::verifyPoints in tests/userpoints_api.test
Verify the current and optionally max points in a specific category.

File

./userpoints.module, line 756

Code

function userpoints_get_max_points($uid = NULL, $tid = NULL) {
  $max = drupal_static(__FUNCTION__, 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 (!isset($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 select the total.
      $max[$uid][$tid] = db_query('SELECT max_points FROM {userpoints_total} WHERE uid = :uid', array(
        ':uid' => $uid,
      ))
        ->fetchField();
    }
    else {

      // A term ID is specified, so fetch its maximum points.
      $max[$uid][$tid] = db_query('SELECT max_points FROM {userpoints} WHERE uid = :uid AND tid = :tid', array(
        ':uid' => $uid,
        ':tid' => $tid,
      ))
        ->fetchField();
    }
  }

  // Return the cached value.
  return $max[$uid][$tid];
}