#243199: User Badges Rules Integration doesn't really seem to have anything to do with Rules, so I'm creating a new issue.

This is the start of a "User badges rules integration" module that provides enhanced rules features not available using the core actions implemented by user badges. It provides:

  • A badge data type for rules
  • A "user was given a badge" event
  • A "user has badge" condition, with options to test for any/all from a list of badges

It does not re-implement the actions implemented by user badges.

I only needed the condition for my project, but I got carried away and added the data type and event. For the event to be useful a patch would need to be applied to user_badges.module to trigger it at the appropriate time. I never needed it so I don't have a patch for that. As a result the condition is well-tested, but the event and data type are not.

I'm not planning any more work on this, but I figured I'd share it in case someone else wanted to roll with it, extend it, whatever.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

BenK’s picture

Subscribing...

yeeloon’s picture

hi jcarnett,

can you please advice where should i paste the code into?

i try pasting the whole code into '/admin/rules/ie/import', but it showed 'Import failed'... Not very sure how to use it..

jcarnett’s picture

It's not an exported rule. You drop the files into the user badges module directory and it will show up as a separate module you can enable for additional rules integration. I wouldn't recommend it for anyone other than module developers.

yeeloon’s picture

jcarnett, is it ok for you to zip up the whole modified version of your user_badge module? sorry as i'm not technically savvy..

NancyDru’s picture

Would this give the ability to stop showing a badge after a certain time interval or date? I was about to create a request for that. We are using this to show awards and need those awards to go away after 6 months or so.

jcarnett’s picture

The event here with rules scheduler and the existing actions from the user badges module would allow that. The only piece missing is the actual triggering of that event, which would require a patch to the module. It's likely a very simple patch, but I didn't have the need or time to do anything else with this.

NancyDru’s picture

If someone wants to complete this, we will consider committing it.

yeeloon’s picture

can this be integrated into the dev module?

NancyDru’s picture

If we had a completed patch it could be.

jcmarco’s picture

Status: Needs work » Needs review
FileSize
7.26 KB

This patch adds full integration with rules.
> For the actions it uses the existing actions for adding or removing user badges.
(it fixes as well problems with deleting and adding user badges from actions)

> Add two events integrated with the module. For adding and removing user badges.
(it fixes errors when adding or deleting existing badges)

> Condition for detecting existing badges for a user.

The rules are integrated with the existing tokens.
(fix problem with no returning values to token, and removed listing the module tokens into the full site token list as this tokens only work in the rules/actions context)

Magnus’s picture

Works fine by me. I'll let another user review if before changing it to RTBC. One minor thing I saw would be the comments. Some, but not all have capitalized sentences with punctuation. (http://drupal.org/coding-standards#comment)

jcmarco’s picture

Thank you for the review, here is an updated patch with standardized comments for this patch.

(it would be needed open a new issue for checking the coding standards in all the former module code).

poopertropper’s picture

Is this being added into Badges?

NancyDru’s picture

Probably

poopertropper’s picture

Sounds great

Q2U’s picture

Glad you're on the case Nancy...I too would like to see this functionality committed to User Badges. Thanks for all your hard work.

poopertropper’s picture

Is this patch in the current dev snap shot?

Media Crumb’s picture

Can't wait for this!

Media Crumb’s picture

Was this added in or is it still awaiting review?

NancyDru’s picture

Still waiting for reviews and RTBC, since I don't have any sites with Rules.

martin.l’s picture

We have a website www.whami.com which uses Rules heavily. I tested the condition in the patch and it implemented it on our website. I works fine.

I think you can commit the patch into the dev-Version.

stuhannaford’s picture

Just applied patch to latest dev version and can confirm that it works for the purpose I needed:

Add rule so that once an Ubercart role has expired, the badge associated with that role is automatically removed also.

Thanks!

Magnus’s picture

Status: Needs review » Reviewed & tested by the community

No errors so far so I change this to RTBC.

drupalninja99’s picture

i dont see the rules files in dev

NancyDru’s picture

Thanks for the reviews. I'd like to get a new official release out before I commit this. The change to Git is slowing me down.

drupalninja99’s picture

ok bc i have an old version of the module and the rules arent firing correctly.

jamesgrobertson’s picture

Category: feature » bug
Status: Reviewed & tested by the community » Needs work

I applied the patch to the 6.x-1.x-dev version, but am now getting an error:

user warning: Duplicate entry '17-1-user' for key 1 query: INSERT INTO user_badges_user (uid, bid, type) VALUES (1, 17, 'user') in /var/www/vhosts/m.ladolcedc.org/httpdocs/La-Dolce-DC/sites/all/modules/user_badges/user_badges.module on line 749.

I'm using rules to give a badge based on userpoints, and then using the new "user was given a badge" condition to display a message and send an e-mail after the badge has been given. The badge is still given, but I get the error. Any thoughts?

ao5357’s picture

In preparing a fairly robust badge system for a project, I found that the userbadge data type silently fails (or at least is not passed to conditions from events). However, I really needed to know which badge was getting awarded when the user_badges_badge_given event fired.

Attached you'll find the shoddy workaround. I got rid of the data type altogether and passed just the bid (as type 'value') from the event to the condition. This allows for a condition "Badge user is receiving." I also added a condition "User badge count" that allows actions based on the number of badges the user possesses before the event (also, the labels for the badges events were inaccurate in this respect: the user object passed is the user before the badge is awarded).

Sorry I don't have this as a patch (my git-fu is not strong) — the .module file only differs in that the event invocation passes the bid instead of a full userbadge object. The rules.inc might be worth diff-ing.

Media Crumb’s picture

Was wondering if this was ever committed to the latest User Badges and if not what is the most up to date version of this patch. Thanks

brunorios1’s picture

+1

Desi Raaj’s picture

Any chance this making its way to D7?

NancyDru’s picture

Eventually. It's not even in D6 yet.

Desi Raaj’s picture

k thank you, I'll wait and see

ao5357’s picture

Here's a patch against the current dev branch of the changes from my earlier ZIP file. I haven't tested the Rules actions in the dev configuration, though.

adamtong’s picture

I also want to have this rule integration in D7 too.

Thank you.

shabana.navas’s picture

Category: feature » bug

I have committed the patch in #34, by ao5357. Please continue to test this and let me know if everything works well. Once, I get everybody's okay, I will add this to the D7 version as well. So, user_badges version 6 is now officially integrated with Rules! Thanks ao5357 for the patch.

shabana.navas’s picture

Category: bug » feature
Status: Needs work » Patch (to be ported)
shabana.navas’s picture

Category: bug » feature
Status: Patch (to be ported) » Needs review
shabana.navas’s picture

Changing status to needs review so others can review this and offer their feedback.

shabana.navas’s picture

Issue summary: View changes
Status: Needs review » Fixed

Added to dev version and released a production version (6.x-2.0) based on this.

Status: Fixed » Closed (fixed)

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