Posted by sonofmarx on June 3, 2009 at 12:35am
Jump to:
| Project: | User Points Contributed modules |
| Version: | 6.x-1.x-dev |
| Component: | Code: userpoints_badges |
| Category: | feature request |
| Priority: | normal |
| Assigned: | 1kenthomas |
| Status: | active |
Issue Summary
I know that a feature request will accomplish next to nothing but I couldn't resist.
What I am looking for is a way to make the userpoints badges module present a select for the userpoint term. I would like to be able to offer several different badges in several different categories of userpoints.
I think that my users would appreciate that sort of recognition for different activities.
Does anyone have any suggestions about how to incorporate this functionality?
Thank you for any help you can offer.
Comments
#1
Same here. I would like to assign certain badges and roles to users based on the points they earned during the current week.
#2
I may be willing to program. Self-assigning for now.
REF: http://drupal.org/node/883862#comment-3428272
#3
Subscribing
#4
subscribung
#5
Subscribing
#6
I subscribe too, i don't understand why userpoints badges doesn't have this feature, it's useless without it!
#7
This is possible in current -dev versions.
#8
I just verify and it's not possible to choose the category!
#9
Sorry but I didn't have the time to find out how to create a patch without using GIT, but I have made amendments to the code to cater userpoint goals for different categories.
function userpoints_badges_get_badges($select = 'normal', $tid=NULL) {
static $userpoints_badges_list;
if (!isset($userpoints_badges_list)) {
$userpoints_badges_list = array('normal' => array(), 'select' => array());
$sql=NULL;
if(!$tid){
$sql = db_query('SELECT b.bid, b.weight, b.name, b.image, u.userpoints_goal FROM {user_badges_badges} b INNER JOIN {userpoints_badges} u ON b.bid=u.bid ORDER BY b.weight, b.name');
}else{
$sql = db_query('SELECT b.bid, b.weight, b.name, b.image, u.userpoints_goal FROM {user_badges_badges} b INNER JOIN {userpoints_badges} u ON b.bid=u.bid WHERE b.tid=%d ORDER BY b.weight, b.name', $tid);
}
while ($badge = db_fetch_object($sql)) {
$userpoints_badges_list['select']["badge-$badge->bid"] = $badge->name;
$userpoints_badges_list['normal']["badge-$badge->bid"] = $badge;
}
}
return $userpoints_badges_list[$select];
}
function userpoints_badges_userpoints($op, $params = array()) {
switch ($op) {
case 'setting':
$group = 'userpoints_badges';
$form[$group] = array(
'#type' => 'item',
'#value' => t('Go to !link to edit userpoint badges', array('!link' => l(t('Userpoints Badges Settings'), 'admin/user/user_badges')))
);
return $form;
case 'points after':
//$badges = userpoints_badges_get_badges();
$userpoint_categories = taxonomy_get_tree(userpoints_get_vid());
foreach($userpoint_categories as $cat){
$total_points = userpoints_get_current_points($params['uid'], $cat->tid);
$badges = userpoints_badges_get_badges('normal', $cat->tid);
foreach ($badges as $badge) {
if ($total_points >= $badge->userpoints_goal) {
if (!db_result(db_query('SELECT uid FROM {user_badges_user} WHERE bid=%d AND uid=%d', $badge->bid, $params['uid']))) {
user_badges_user_add_badge($params['uid'], $badge->bid, t('Userpoints @bid', array('@bid' => $badge->bid)));
}
}
}
}
}
}
#10
Great, but in order to get in working for me i had to make a small change. I had to change:
function userpoints_badges_get_badges($select = 'normal', $tid=NULL) {static $userpoints_badges_list;
if (!isset($userpoints_badges_list)) {
...
To this:
function userpoints_badges_get_badges($select = 'normal', $tid=NULL) {if (!isset($userpoints_badges_list)) {
...
I noticed that the "static $userpoints_badges_list" gets the first value and assigns the same badges to all the categories.
Thanks for the code once more and I hope I was able to help.