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

martinkollubke’s picture

Same here. I would like to assign certain badges and roles to users based on the points they earned during the current week.

1kenthomas’s picture

Assigned: Unassigned » 1kenthomas

I may be willing to program. Self-assigning for now.

REF: http://drupal.org/node/883862#comment-3428272

EndEd’s picture

Subscribing

elbym’s picture

subscribung

MacRonin’s picture

Subscribing

MasterChief’s picture

I subscribe too, i don't understand why userpoints badges doesn't have this feature, it's useless without it!

1kenthomas’s picture

Status: Active » Fixed

This is possible in current -dev versions.

MasterChief’s picture

Status: Fixed » Active

I just verify and it's not possible to choose the category!

zhuoyan’s picture

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)));
            }
          }
        }
      }
  }
}
dzhebarov’s picture

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.

albert volkman’s picture

Project: User Points Contributed modules » Userpoints Badges
Version: 6.x-1.x-dev »
Component: Code: userpoints_badges » Code
Issue summary: View changes
albert volkman’s picture

Version: » 7.x-1.x-dev
Assigned: 1kenthomas » Unassigned
Status: Active » Closed (won't fix)

Is there still interest in this request? If so, please re-open.

drusite’s picture

Yes, there is an interest in this request and it seems that this feature is not present in the latest version for drupal 7. By the way, the above code doesn't work.