function user_badges_get_badges in User Badges 6.2
Same name and namespace in other branches
- 5 user_badges.module \user_badges_get_badges()
- 6 user_badges.module \user_badges_get_badges()
- 7.4 user_badges.module \user_badges_get_badges()
- 7 user_badges.module \user_badges_get_badges()
- 7.2 user_badges.module \user_badges_get_badges()
- 7.3 user_badges.module \user_badges_get_badges()
Return array of user badges where keys are badge ids (bid) and values are object containing badge info.
Parameters
$uid: if $uid is a user id, returns badges for that user. if $uid is 'all', returns all badges. if $uid is 'select', returns badges for form_select options.
$options array of options.: $options['nolimit'] : if TRUE, the limit clause will not be applied for a user returned values for 'select' are just badge names.
16 calls to user_badges_get_badges()
- user_badges_action_add_badge_by_name in ./
user_badges.rules.inc - Implements a Rules action. Adds a badge to the current user, by the textual name of the badge.
- user_badges_action_remove_badge_by_name in ./
user_badges.rules.inc - Implements a Rules action. Removes a badge from the current user, by the textual name of the badge.
- user_badges_add_badge_action in ./
user_badges.module - Implementsa Drupal action. Adds a badge to the current user.
- user_badges_add_badge_action_form in ./
user_badges.module - user_badges_badge_count in ./
user_badges.rules.inc - Test the user_badges_badge_count condition
File
- ./
user_badges.module, line 783 - @brief User Badges module file
Code
function user_badges_get_badges($uid, $options = array()) {
static $badges = array(), $past_uid, $past_options;
if (isset($badges[$uid])) {
return $badges[$uid];
}
// Do this so we don't return NULL.
$badges[$uid] = array();
if (empty($past_uid) || $past_uid !== $uid || $past_options !== $options) {
$past_uid = $uid;
if ($uid == 'all' || $uid == 'select') {
$sql = db_query('SELECT b.bid, b.weight, b.name, b.image, b.href,
b.unhideable, b.fixedweight, b.doesnotcounttolimit, b.tid
FROM {user_badges_badges} b
ORDER BY b.weight, b.name');
}
else {
$usr = db_result(db_query('SELECT COUNT(uid) FROM {users} WHERE uid = %d AND status = 0', $uid));
if ($usr && variable_get('user_badges_showblocked', 0)) {
$sql = db_query('SELECT DISTINCT b.bid, b.weight, b.name, b.image, b.href,
b.unhideable, b.fixedweight, b.doesnotcounttolimit, u.userweight, b.tid,
CASE WHEN b.fixedweight = 1 THEN b.weight ELSE COALESCE(u.userweight,b.weight) END coalescedweight
FROM {user_badges_badges} b
INNER JOIN {user_badges_user} u ON b.bid = u.bid
INNER JOIN {user_badges_roles} r ON b.bid = r.bid
WHERE u.uid = %d AND r.rid = 0
ORDER BY coalescedweight, b.name', $uid);
}
else {
$query = 'SELECT DISTINCT b.bid, b.weight, b.name, b.image, b.href,
b.unhideable, b.fixedweight, b.doesnotcounttolimit, u.userweight, b.tid,
CASE WHEN b.fixedweight = 1 THEN b.weight ELSE COALESCE(u.userweight,b.weight) END coalescedweight
FROM {user_badges_badges} b
INNER JOIN {user_badges_user} u ON b.bid = u.bid
WHERE u.uid = %d
ORDER BY coalescedweight, b.name
';
$sql = db_query($query, $uid);
}
}
// Should we limit the badges returned?
if (!$options['nolimit'] && variable_get('user_badges_showone', 0)) {
$limit = variable_get('user_badges_showone', 1);
}
else {
// Set to -1 for no limit.
$limit = -1;
}
while ($badge = db_fetch_object($sql)) {
// Display the badge if there's no limit or if the badge is unhideable or if we are within our limit.
if ($limit != 0 || $badge->unhideable == 1) {
if ($uid == 'select') {
$badges[$uid][$badge->bid] = $badge->name;
$badges[$badge->bid]['#attributes'] = array(
'class' => 'badge ' . _user_badges_class($badge),
);
}
else {
$badges[$uid][$badge->bid] = $badge;
$badges[$uid][$badge->bid]->class = 'badge ' . _user_badges_class($badge);
}
//Count down our limit, unless the badge doesn't count towards it
if (!$badge->doesnotcounttolimit) {
$limit--;
}
}
}
}
return $badges[$uid];
}