#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.
Comment | File | Size | Author |
---|---|---|---|
#34 | user_badges-rules_integration-782430-34.patch | 9.57 KB | ao5357 |
#28 | user_badges_rules_edits_051611bpcz.zip | 10.6 KB | ao5357 |
#12 | user_badges_rules_full_2.patch | 7.26 KB | jcmarco |
#10 | user_badges_rules_full.patch | 7.26 KB | jcmarco |
user_badges_rules.tar_.gz | 1.33 KB | jcarnett |
Comments
Comment #1
BenK CreditAttribution: BenK commentedSubscribing...
Comment #2
yeeloon CreditAttribution: yeeloon commentedhi 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..
Comment #3
jcarnett CreditAttribution: jcarnett commentedIt'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.
Comment #4
yeeloon CreditAttribution: yeeloon commentedjcarnett, is it ok for you to zip up the whole modified version of your user_badge module? sorry as i'm not technically savvy..
Comment #5
NancyDruWould 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.
Comment #6
jcarnett CreditAttribution: jcarnett commentedThe 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.
Comment #7
NancyDruIf someone wants to complete this, we will consider committing it.
Comment #8
yeeloon CreditAttribution: yeeloon commentedcan this be integrated into the dev module?
Comment #9
NancyDruIf we had a completed patch it could be.
Comment #10
jcmarco CreditAttribution: jcmarco commentedThis 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)
Comment #11
Magnus CreditAttribution: Magnus commentedWorks 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)
Comment #12
jcmarco CreditAttribution: jcmarco commentedThank 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).
Comment #13
poopertropper CreditAttribution: poopertropper commentedIs this being added into Badges?
Comment #14
NancyDruProbably
Comment #15
poopertropper CreditAttribution: poopertropper commentedSounds great
Comment #16
Q2U CreditAttribution: Q2U commentedGlad you're on the case Nancy...I too would like to see this functionality committed to User Badges. Thanks for all your hard work.
Comment #17
poopertropper CreditAttribution: poopertropper commentedIs this patch in the current dev snap shot?
Comment #18
Media Crumb CreditAttribution: Media Crumb commentedCan't wait for this!
Comment #19
Media Crumb CreditAttribution: Media Crumb commentedWas this added in or is it still awaiting review?
Comment #20
NancyDruStill waiting for reviews and RTBC, since I don't have any sites with Rules.
Comment #21
martin.l CreditAttribution: martin.l commentedWe 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.
Comment #22
stuhannaford CreditAttribution: stuhannaford commentedJust 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!
Comment #23
Magnus CreditAttribution: Magnus commentedNo errors so far so I change this to RTBC.
Comment #24
drupalninja99 CreditAttribution: drupalninja99 commentedi dont see the rules files in dev
Comment #25
NancyDruThanks 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.
Comment #26
drupalninja99 CreditAttribution: drupalninja99 commentedok bc i have an old version of the module and the rules arent firing correctly.
Comment #27
jamesgrobertson CreditAttribution: jamesgrobertson commentedI 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?
Comment #28
ao5357 CreditAttribution: ao5357 commentedIn 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.
Comment #29
Media Crumb CreditAttribution: Media Crumb commentedWas 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
Comment #30
brunorios1 CreditAttribution: brunorios1 commented+1
Comment #31
Desi Raaj CreditAttribution: Desi Raaj commentedAny chance this making its way to D7?
Comment #32
NancyDruEventually. It's not even in D6 yet.
Comment #33
Desi Raaj CreditAttribution: Desi Raaj commentedk thank you, I'll wait and see
Comment #34
ao5357 CreditAttribution: ao5357 commentedHere'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.
Comment #35
adamtong CreditAttribution: adamtong commentedI also want to have this rule integration in D7 too.
Thank you.
Comment #36
shabana.navas CreditAttribution: shabana.navas commentedI 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.
Comment #37
shabana.navas CreditAttribution: shabana.navas commentedComment #38
shabana.navas CreditAttribution: shabana.navas commentedComment #39
shabana.navas CreditAttribution: shabana.navas commentedChanging status to needs review so others can review this and offer their feedback.
Comment #40
shabana.navas CreditAttribution: shabana.navas commentedAdded to dev version and released a production version (6.x-2.0) based on this.