I'm creating a membership-based site in D7, using Date, Calendar, and Entity Registration (which was very easy to setup). Only authenticated users may register for an event.
I'm trying to limit the number of events an authenticated user may register for during a certain time period (probably by month or by quarter), and I'm stuck. I created a field called 'Registration Count' for user accounts. And I created a rule that increments the counter when the user registers for an event.
But I'm trying to figure out:
- How do I prevent a registration based on the user's current registration count? I got as far as creating a rule that is triggered prior to a registration and checked his current registration count. And I can display a warning, but the registration still goes through. Isn't there an action I can assign that would halt the registration?
- How can I reset the registration counter field for all user accounts back to zero at a certain interval? I can't find access to user fields on that broad level.
Adding more details:
I have a node type called "Event". My registrations are entities. This is out-of-the-box functionality for the Entity Registration module, and it was very simple to get it up and running.
Each user has a field called field-registration-count. When a user registers for an event, I have a rule set up as follows:
- Event: After saving a new registration
- Action: Set value site:current-user:field-registration-count, add offset 1. This increments the user's registration count by 1.
I have another rule:
- Event: Before saving a registration
- Condition: site:current-user:field-registration-count > 2
- Actions: Page redirect, and then Show a Message on Site
On the third registration, the page redirect happens as expected, and the message is displayed, but the registration is still saved. Based on the provided event named "Before Registration", I think I'm tapping in a the right time; I just can't find an action to cancel the registration itself
Note: When a user actually registers, it doesn't create a node. The Entity Registration module creates an entity type instead, and each registration is an entity.