Hi,

I am using the userpoints module with multiple categories, such as blog points, forum points, comment points, etc. Users receive points in these point categories when posting content and there different points are displayed correctly. I have assigned badges to each of these userpoint categories using the vocabulary setting, and assigning each badge to a userpoint category that is available when adding or editing a badge.

Unfortunately, users are awarded badges depending on their total points, rather than how many points they have in each category. For example, when a users total points reaches a certain amount, they are awarded all the badges worth that amount, regardless of the badge category setting. I have created a blog and assigned it 10 blog userpoints. I also have a forum badge and assigned it 5 userpoints. Users do not receive these badges when they reach the required amount of blog or forum points, but rather receive them both when their total points reach 15, regardless of the category they were earned in.

Is it possible to assign badges to userpoint categories, or can it only display badges for userpoint totals? Having the option to select a userpoint category on the add/edit badge page suggests it can, but it does not seem to work.

I sincerely appreciate any help you can provide,

Shane.

Comments

moosh101’s picture

Priority: Normal » Major
nancydru’s picture

I have never used UB with Userpoints, so I'll need some guidance on how you set this up, including UB settings and other modules involved.

moosh101’s picture

Hi,

Thanks for your reply. I have created a new issue with the authors of the User Points Contributed modules module, as this module allows badges to be awarded for points.

I think the code that causes badges to be assigned to all user points, rather than to user point categories is:

      // Iterate through each badge and assign any badge that passes the threshold 
      foreach ($badges as $badge) {
        if ($total_points >= $badge->userpoints_goal) {
          user_badges_user_add_badge($params['uid'], $badge->bid, t('Userpoints @bid', array('@bid' => $badge->bid)));
        }
      }

Many thanks,

Shane.

ANB’s picture

Status: Active » Needs review

Hi,

i fixed this issue by changing the following code

/**
 * When a userpoints badge is created or edited, a mass check is run on the users to see if they qualify for the new badge 
 */
function userpoints_badges_run_mass_badge_check($bid, $userpoints_goal) {
  db_query("DELETE FROM {user_badges_user} WHERE bid=%d", $bid);
  $resultset = db_query("SELECT uid FROM {userpoints} WHERE  uid > 0 GROUP BY uid HAVING SUM(points) >= %d", 
    $bid, $userpoints_goal);

to this:

/**
 * When a userpoints badge is created or edited, a mass check is run on the users to see if they qualify for the new badge 
 */
function userpoints_badges_run_mass_badge_check($bid, $userpoints_goal) {
  db_query("DELETE FROM {user_badges_user} WHERE bid=%d", $bid);
  $resultset = db_query("SELECT uid FROM {userpoints} 
  JOIN {user_badges_badges} USING (tid) WHERE bid = %d
  AND uid > 0 GROUP BY uid HAVING SUM(points) >= %d", 
    $bid, $userpoints_goal);

Maybe the community could test this. I'm not posting a patch-file because i'm new to the drupal developer-community.

shabana.navas’s picture

Status: Needs review » Closed (won't fix)

This is a Userpoints issue.