Drupal 获取当前用户积分


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

参数

$uid: 用户ID

$tid: 积分的Term ID或者'all'。

返回值

该用户的目前积分数。

标签: