function user_badges_get_badges in User Badges 5
Same name and namespace in other branches
- 6.2 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 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 returned values for 'select' are just badge names
7 calls to user_badges_get_badges()
- user_badges_for_uid in ./
user_badges.module - Returns HTML representation of user badges for given uid
- user_badges_page_form in ./
user_badges.module - Form to assign badges to users.
- user_badges_products_page in ./
user_badges.module - user_badges_roles_form in ./
user_badges.module - user_badges_settings_page in ./
user_badges.module
File
- ./
user_badges.module, line 546 - @brief User Badges module file
Code
function user_badges_get_badges($uid) {
$badges = array();
if ($uid == 'all' || $uid == 'select') {
$sql = db_query('
SELECT b.bid, b.weight, b.name, b.image, b.href
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
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 b.weight, b.name', $uid);
}
else {
$limit = variable_get('user_badges_showone', 0) ? ' LIMIT 1 ' : '';
$sql = db_query('
SELECT DISTINCT b.bid, b.weight, b.name, b.image, b.href
FROM {user_badges_badges} b INNER JOIN {user_badges_user} u ON b.bid = u.bid
WHERE u.uid = %d
ORDER BY b.weight, b.name
%s', $uid, $limit);
}
}
while ($badge = db_fetch_object($sql)) {
if ($uid == 'select') {
$badges[$badge->bid] = $badge->name;
}
else {
$badges[$badge->bid] = $badge;
}
}
return $badges;
}