I have a Drupal 7 site, and I'd like to set up something like badges (from Stack Overflow) or achievements (from World of Warcraft); we have a bunch of set triggers, and if you do that, then you get the badge. The "ranks" often seen in forum software would fall under this heading ("Quiet" for someone who has posted 25 or fewer posts; "Chatty" for 25-100; etc.), but you could also attach other criteria, like length of time on the site ("Old Timer" if you have an account more than three years old, perhaps), or more specific things ("Posting Spree" if you make 10 comments in an hour).

The User Badges module looks like it should work for this, but it only works for Drupal 6. I downloaded it to see if I could help upgrade it to Drupal 7, but I don't have anywhere near the understanding of the project to take that on. Then, it occurred to me that perhaps I could use a custom content type and the Rules module to create the same effect.

I started with an example of "Well Read." I want a user to get this badge when she reads 10 articles. I started a rule with an event of "Content is viewed." I'm not sure what to use for the conditions to see if the user has previously viewed 9 other articles, though.

Specifically, can you tell me what I would need to finish this rule? More generally, does this sound like a viable approach to accomplish this?

Comments

Ayesh’s picture

First, I think, you need to understand what User Badges module does. UB is the module which introduce "badge" to system. Also, Rules modules integrates with UB module. So we can't have same functionality of User Badges module without User Badges modules.

Anyway, if you want to add a rule with reading statistics, make sure that Statistics module is enabled. Actually I haven't tried this approach. You could use User Points and Userpoints NC modules to grant user points for each action(such as reading a post). User Points integrates with Rules greatly.

jefgodesky’s picture

Thanks for your reply, Ayesh. I'd love to use the User Badges module, but I'm using Drupal 7. User Badges only works with Drupal 6. I took a look to see if I could help update it, but it's a bigger problem than I can really handle.

So, I started looking at Rules with a custom "Badge" content type to see if I could create the functionality of the badge, without having to wait for a Drupal 7 port of the User Badges module. Since I can't use the User Badges module, its integration with Rules is really not something I can use, either.

I'm not sure why that would preclude creating a user badge with some clever configuration, though. If I can create a node of the content type "Badge," and then set up a rule that has the right conditions to match the requirements of that badge, and then have that rule create a user reference that links the user and the badge, then that should provide everything I need. After that, I just need to set up some Views to take advantage of that information.

Thanks for the tip about the Statistics module. I turned it on, but I'm not seeing any new options for conditions on my Rule that might allow me to take advantage of it. I'll try looking for another module that might provide that.

jefgodesky’s picture

To put this a little more simply: is there a way to use data from the Tracker core module, for the conditions for a Rule?

jefgodesky’s picture

I've gotten as far as setting up User Points as a way to track how many articles a user has read, by awarding 1 point in a particular taxonomy term anytime she accesses a node of type "Article."

The Rules and Views Integration module looked like it might have the answer for me, but it doesn't look like anyone has worked on it in a while, and I don't see any issue there for a Drupal 7 port.

I have a View that will display all of those transactions, so if I could do something like set a condition on my Rule for when the number of rows returned by my view is equal to or greater than 10, I'd have everything I need. But it looks like I still don't have that crucial piece to bring it all together. Any suggestions?

jefgodesky’s picture

I think, if I can set up Rules that use conditions based on User Points in particular categories, I could get this all working that way. Unfortunately, I seem to be missing the User Points conditions for my Rules that the documentation says I should have. Since this is a more specific problem, I started a new thread on this.

jefgodesky’s picture

I managed to put this together, using User Points, Rules, Flags, and Views. I did need to use some patches for User Points and Flags to upgrade the Rules integration for Drupal 7.

I set up a custom content type called "Badge," and flags called "Viewed" and "Awarded." I don't display either of those flags to users; they exist solely for Rules and Views. The "Viewed" flag tells me that a user has looked at an article before; the "Awarded" flag only goes onto "Badge" nodes, telling me which users have won that badge.

I set up a rule to measure site activity. In the case of this example:

  • Event: Content is viewed.
  • Condition: NOT Node is flagged. This checks the "Viewed" flag, so a user only gets a point when they view the article for the first time, instead of every time they view it.
  • Action: Grant points to a user.
  • Action: Flag a node.

Then, I have a rule that awards the badge based on that activity:

  • Event: User was awarded points.
  • Condition: Check how many points a user has This was the condition that I added to User Points with my patch, so I don't know whether or not it will make it into the User Points module.
  • Action: Fetch entity by id I use this to load the badge to award.
  • Action: Flag a node.

Then, you can use Views to display all the badges that a particular user has won, or all the users who have won a particular badge, etc.

With this approach, I expect to set up many other badges that will trigger off of other sorts of behavior. The taxonomy for user points will help track many different types of actions, any of which could have an array of badges associated with it.

Morbus Iff’s picture

You might also want to check out Achievements: http://drupal.org/project/achievements

jefgodesky’s picture

Now that it's out, absolutely! I was going through all this before you'd posted anything for that project. It looks really awesome, I'm very excited about implementing it.

Pierre.Vriens’s picture

I know, 5 years later, but still ... have a look at the Goals module. If you prefer SE (as in the question), then you may also want to look at http://drupal.stackexchange.com/questions/197711 ...

Disclosure: I'm the maintainer of Goals ...