If you are tempted to ignore this because you are still on D6, these changes are A) likely to be back-ported to solve the many role issues here, and B) will definitely affect your ability to upgrade in the future.

Currently, User Badges does something I consider just plain wrong. When you assign a role badge, all users in that role currently are given that badge with a type field set to "role." Sounds okay, but the code to track what happens to the role is not working correctly (probably never has). Consequently, the best way to maintain role badges is to re-save the role badges twice.

It is not a problem to properly retrieve badges assigned to roles when badges are loaded. I would prefer to do that and rip almost all that current code out. By the way, the queries used to update users are not D7-friendly and are causing problems getting the 7.x branch stable.

I suspect that the main reason the module does it that way is because of allowing user weighting of badges (coupled with limiting how many are displayed).

In order to accommodate user weighting of badges with the slimming down of role badges, the best thing to do is to always put role badges at the end of the badge list, which means that they will be the first ones eliminated if using the limit count. That seems reasonable to me, but I have never used the limit or the user-weighting features on my sites. From the issue queue, I know there are people who do.

Comments, please.

Comments

Satori42’s picture

I use a progressive series of Roles for which I'd like to assign badges. For instance, Novice User -> Intermediate User -> Advanced User. Earning a different level requires getting other badges first, much like merit badges. So weighting them is kind of important. Specifically, grouping them is.

For instance, displaying the badge for the current level (Novice, Intermediate, Advanced). Then, displaying the merit badges they've already gotten, in a group immediately after that. Sort of the way forms have field groups.

I also use several different series of Roles, simultaneously. In addition to Novice -> Intermediate -> Advanced, users might also be involved in a few more sequences at the same time. Yet another reason for grouping.

I'm not sure Role Badges are even necessary, given the way Rules can assign Roles now. If Rules could also assign Badges just as easily, would there be much of a use case for needing them associated? If not, it would seem to ease the coding requirements significantly.

nancydru’s picture

There are two different weights in the UB module. The first is the admin assigned weights to badges in general. The second is an option to allow the user to personally alter the order in which his/her badges are displayed; I guess this is a way to deal with the badge display limit.

As far as I know, but have not tested, the first works. The second is now working in my development version and will be uploaded soon. It is the second where the conflict with role badges lies.

Richard Blackborder’s picture

It may make more sense to put the role badges at the front than at the end. Role badges (such as "moderator") are often not things that you would want to exclude. This is why there is an option to not count them towards the limit. They are also often not things you would want users rearranging and reprioritising, unlike the general collection of miscellaneous badges that a user might build over time on a website.

nancydru’s picture

I thought about adding a setting to put them either at the front of the list or at the back.

computerology’s picture

First thanks so much NancyDru for all of your hard work on this. I have been waiting with bated breath for this module to be stable on D7 since I installed D7.

To address soem of the above yes role badges should never be excluded, at least not by default.

The way I intend to use this module is that each role gets a badge which is basically the user's "rank" as determined by user points. Using Rules I will determine that when a user has user points added or subtracted that it will compare the value of the point total and assign the role to the user, which will hopefully automatically apply the new badge. A feature that I never really thought of using before is special merit badges, I never even contemplated that but it is a fantastic idea. I can use them kind of like medals.

So I guess the part that you want to ignore for now and fix last is the most important part for me. haha arent I lucky.

I wouldnt really worry too much about allowing the user to reorder their own badges. In pretty well any website with user commendations I cant imagine it being a feature that would bring much in value experience to the user at the expense of a lot of coding by yourself and the rest of the contributors. Most users would probably not even find that feature. Letting the admin set weightings for each badge type would be fine. As such all role badges could be assigned a weight of zero and then any other badges could be assigned weights depending on how important they are. For example a badge assigned to a user for being a member for one year, another for two years, and so on, the one year badge could be assigned a weight of 9, the two year a weight of 8, the three year a weight of 7 etc. so if the users' badges were piling up the oldest badges would automatically drop off the roster with a little planning by the admin of the website.

I think that a more productive and better bang for the buck would be to ensure the neccesary hooks were there so that the badges appear on the different content submitted by the user, such as comments, forum posts and node articles. Maybe thats already in there I dont know.

Thank you so much for all your hard work. Hopefully a stable D7 release will be available soon! I would try to help by coding and testing but I am so new to Drupal I'd probably just make a terrible mess. :-)

nancydru’s picture

Thank you for the comments.

There is another issue where they want badge levels. In your case, they want the year 1 badge to go away when the user reaches 2 years, and that one to go away when the user reaches 3 years. I'm not sure it's a good idea in this module, but certainly something to consider.

The reason the role badges is waiting is to gather comments like this and the code is very messy. Likeless and I have discussed it and both would prefer that the user_badges_user table not get an entry for role badges (as it does now), but rather to drive that directly off the users_roles table. This would greatly simply (as in "lighten") the code, but would require an update function for people who are currently using role badges, and I have not looked at how complicated that might be yet.

As an aside, have you looked at the userpoints_badges module? It sounds like you're doing custom code and that module may make that unnecessary.

computerology’s picture

well in the descriptor for that contributed module to User Points it describes the project as
""
userpoints_badges
Integrates Userpoints with the User Badges module.
""

So it sounds like I am still going to need to make use of User Badges and wait until it is ready.

I do have some other more complex stuff that I would like to do with User Badges and Roles making use of Rules, such as if a user's point score drops below a certain total they can no longer be the a member of an Organic Group, or if they drop below a different total they can no longer be an administrator of an Organic Group.

While I'm sure userpoints_badges could make the point total = badge for me a lot easier, I am going to be making a crapload of Rules anyways and while it isnt the simplest way of going about it I'd rather control everything from one place and maybe avoid some upgrade problems down the road by just using Rules.

I am only 3 months into using D7 though so maybe I'm totally wrong and crazy. ;-) I'll take all the advice I can get

nancydru’s picture

Okay. There is also an issue on integrating Rules upon which you may wish to comment.

computerology’s picture

Im not sure what issue you are referring to with integration of Rules, or if it applies to me.

I mainly intend to apply Rules to modify user's roles, and with the roles comes permissions. Provided user_badges allows role badges then in theory I can have Rules evaluate the userpoints value and then slam the user out of one role and into another; which should then give them the permissions of that role.

Most sites have 2-5 roles, like webmaster, junior webmaster, moderator, content contributor, etc. The way I intend to use Roles is much more complex, I estimate having around 25-30 roles. While the majority of them will have similar permissions standard to "registered user" for example, flipping on and off certain permissions in certain modules such as the ability to create an organic group or the ability to award user points, award user points pending approval from the next role up, or to approve content for example will be slightly different for each role.

Back to user badges... whats core (at least for me) is that I can have Rules flip a role and have user badges compatible with Roles so they automatically obtain a user badge based on their role. Secondarily having the ability to add additional badges based on a variety of online knowledge tests which can only be attempted by certain roles (this stuff is mostly outside of user_badges, other than the awarding of a user badge).

In effect what I want is a user to be able to have a role of Corporal with a corresponding user badge, with additional award badges like "Most Valuable Player" or "Qualification: Squad Communications". When they are promoted from Corporal to Sergeant, they will automatically lose the Corporal role badge and be awarded the Sergeant role badge, but keep the qualification badges.

Not sure if this helps you or confuses you. If it's any consolation I have 200 users who are chomping at the bit to see the results of their rank points and I'm waiting on this module to be D7 compatible. (Lol... no pressure. Man I wish I could help with the code). However on that note they're also waiting on an Organic Groups implementation as well and that is 110% my fault for not getting it popped in until the badges module is in place. I can't have squad leaders or senior officers who are rankless and for these guys, it's all about the patch insignia next to their name.

computerology’s picture

Ok I have set up userpoints_role and have some additional comments now that I am using it as like a lot of people, my core reason for wanting user_badges is for role badges

userpoints_role does not remove previous roles, it only adds them based on points. So if you are role 1, then progress to enough points for role 2, it will assign you role 2 in addition to role 1, a View that shows a user's role will show all the roles they have, such as 1,2,3,4,5. It does remove roles as the user no longer qualifies for them, if the user lost a bunch of points it may take away role 4 and 5 leaving the user with roles 1,2,3.

While in my particular case I'd love a feature in userpoints_role to be able to "flip to the next role" it just isnt in the cards for now as the maintainers consider this a feature rather than a bug.

But back to user_badges

The above does present somewhat of a design conundrum. A user with the administrator role should show the administrator badge. However the administrator may due to the userpoints_role module (provided it isnt omitted from gaining points in that modules settings) have badges for the "administrator" role as well as all other roles, which in my case would be in excess of 10 badges. Users with less points would have less roles, but still even having three or four badges displayed simultaneously will make any kind of node or comment display look pretty ugly unless they are very small.

I think that there may be a few ways to skin this cat. I dont know drupal's vars well enough to know what on earth I'm talking about here, so some of this may be impossible. No cats were harmed in the production of these options. ;-)

A - Automatically assign a weighting to the role badge based on how recently the role was applied. I am not sure if drupal tracks this, but it would be a simple way to automatically weight role badges using fields contained in the core itself. D7 seems to track the date and time of almost everything so maybe this is possible and might avoid creating a whole new array. If this is possible then user_badges could in theory simply have an option to display the N latest role badges a user has obtained. A value of zero would mean display badges for all roles. An alternate to sorting by "time assigned" may be a more clunky but equally clean use of just sorting by the role ID. Drupal core sorts roles in the order they were created in the permissions menu and when editing user accounts always in the same fashion. I imagine this is by role ID, with zero being unauthenticated, 1 being authenticated user, 2 being administrator, and then after that any role that you create.

B - A seeming make work project for the maintainers and website admins, is to assign a role badge weighting for each role badge (and likely every badge), which would make the heaviest sink and the lightest float to the top. Again the option to display the N lightest role badges or 0 to display every badge. This would mean a new array for the sort handled within user_badges

I may be out to lunch but A seems easier and more easily portable since it makes use of a core var thats already in the system someplace and likely will stay there.

As I have read in the above, role badges seem to be working when the user role ID is pulled but not when the user role name is pulled? If you used the role ID for your weighting, you could in theory just use that core var set for everything making it more easily portable down the road.

computerology’s picture

Is there any more traction on this D7 port?

Would it be possible to toss some $ to the maintainers to expidite this including role badges for D7? Any idea how much I'd need to toss in, for how long to get this finished? I'm not made of money or anything, but I did put up $50 to get a bug fixed in userpoints_role and I'm good on my word.

I could post it on drupal jobs but if the maintainers already know the code and are already working on it it may be faster than having someone else get up to speed on the source.

SebCorbin’s picture

Oh hai, I'm the new co-maintainer of the D7 branch :)

My point of view:
As NancyDru said, the current system of storing role badges is baaaaad. We need to get that out.

My 2 cents:
I'm willing to associate roles with a (I think we agree that multiple user badges for one role is useless) user badge and a weight.
I'm talking about global weight, the same that is used for normal badges.

Example
Let's say we have

Badge name Weight
Wicked soldier 1
Elite sniper 2

as badges and

Role Badge name Weight
Authenticated user Soldier 0
Administrator Veteran 3

as role badges

John is a simple user that has the wicked soldier badge.
Michael is an admin that has the elite sniper badge.

The results would be

John: Soldier, Wicked Soldier
Michael: Soldier, Elite sniper, Veteran

Does that sound good?

nancydru’s picture

Pretty good. I would think, however, that most (at least I) would want the role badge to be either first or last in the list. Thanks for trying to straighten this out.

indyana’s picture

As far as I am concerned, you would want role badges displayed always. Site admins could control this from their side by always making role badges the lightest, but the users shouldn't be able to override it with their own custom order. In my opinion, the user-ordering of badges is more of a special feature and not necessary functionality. I've never been a member of a site where I could order my badges, and it never bothered me... As an admin, I would want role badges to always appear on a user and not give them the option to "hide" a role badge by reordering their badges.

It seems like this intersects with a few other issues floating around. For example, being able to group badges and allow users to only select x number from each group, or having badge groups that users can and cannot select from. Generally, it seems like there should be groups/types of badges that the user can order in their badge collection and also groups that do not allow reordering and always appear first (like role badges).

shabana.navas’s picture

Status: Active » Fixed

Version 7.x-2.x takes care of this issue. Please upgrade to the latest version of this module, which is, 7.x-3.x-dev.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.