You are here

function userpoints_get_max_points in User Points 7.2

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

Related topics

5 calls to userpoints_get_max_points()
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.
UserpointsTransactionController::updateTotalsCategory in ./userpoints.transaction.inc
Update the totals of a specific category.
userpoints_service_get in userpoints_service/userpoints_service.inc
Get the number of points of a given user.
userpoints_tokens in ./userpoints.module
Implements hook_tokens().
1 string reference to 'userpoints_get_max_points'
UserpointsBaseTestCase::verifyPoints in ./userpoints.test
Verify the current and optionally max points in a specific category.

File

./userpoints.module, line 655

Code

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

  // Checks 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;
  }

  // Checks 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();
  }

  // Checks 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];
}