1

I am currently making a site that will implement a system of volume licenses and I am using a system of checking user registration info to check for certain rules. My rule works like this

i. On the event of a new user being generated

ii. Check for two conditions present in the user registration info

Check one AND Check two

iii. Grant the user a certain permissions role.

Problem: I need this rule to only work for X amount of users they have added with X being the amount of users that is allowed for with their volume license. I do not know a way nor can I find a way to check against how many times a rule is ran and then disables the rule if a certain number of users have received a role this way. Any ideas?

0

When the rule is ran a certain role is granted to the user. So in your rule's condition add a PHP (or any other way) and check for the number of users who have this role.

| improve this answer | |
0

With php filter enabled rules support PHP logic. You can store the number of times the Rule has successfully run in a variable using variable_set and get how many times it's run by variable_get. This way your Rule can track the status of this rule.

Another option I would consider is using a module like Data or the Relation module, or even a simple content type and using Rabbit Hole to hide the content type. Then in either a Data table or your custom content type add a field that is number_of_volume_licenses. Rules can then read and write this field like any other system content, you could track 1 or many of these volume licenses.

| improve this answer | |
  • How would I get the amount of times my rules has ran in php though? I am unfortunately a very novice Drupal and php dev doing something that seems rather challenging – Lucas Raley Jul 9 '15 at 16:15
  • Every time the rule completes add +1 to the accumulating variable. – tenken Jul 9 '15 at 16:38
  • I am going to do $ruleIteration=0; variable_set($ruleIteration $ruleIteration++) Which I am thinking should work as an action for when the rule runs. And then I am going to have a condition that checks that value, probably worded as variable_get('ruleIteration') < X – Lucas Raley Jul 9 '15 at 16:51
  • That sounds essentially correct. Just play with it but you have the idea. – tenken Jul 9 '15 at 17:04
  • I think that I have it to where it should work now to test it though, I have to make X amount of user accounts so that may take a while. – Lucas Raley Jul 9 '15 at 17:13
0

Try using the Flag module and the "Fetch overall flag count" functionality. Excerpt from comment #14 in issue #1396196:

'Fetch overall flag count' gets the total count of items flagged within a flag. It is not just the count of the total number of nodes that are flagged, but it grabs every entity type flagged within a flag, including nodes.

Here are some more suggestions related to it:

  1. Create a flag, say "Licensed user", to be used for "users" (not nodes ...).

  2. Expand the existing "Check one AND Check two" with something like "... AND 'Fetch overall flag count (for flag = Licensed user)' is less then X"

  3. Add an extra action to the rule that already contains your existing action (="Grant the user a certain permissions role."). The extra action = "Set flag 'Licensed user' for this user".

| improve this answer | |
  • The options for conditions of a rule don't seem to show fetch overall flag count. There is an option in actions for this but what I can gather that isn't exactly what I need. All I get for checking flagged user is the condition option 'user has flagged count' but I don't think it is that either. That add condition gives me the interface of choose a flag to check for which I can set to my 'licensed user' flag which only flags users with the bulk user role.(I think) and I use account as the data selector and X is < as the check but I don't think setting it up like I think will do it. – Lucas Raley Jul 9 '15 at 15:53
0

If I was to set up something like this, I would try this first - there is a caveat attached to this, as it is incomplete and requires some more information from you:

  • create a content type for the license, adding whatever relevant information you want displayed to the end user, as well as a count field for licensed users - perhaps two fields, total granted, total left for easier reading

  • Using permissions, restrict editing of this content type to admin only

  • Create the nodes as licenses are granted and fill out the number of licensed users

  • Use Rules to check the user count field quantity is above 0, and upon registration, decrease the total number left by one

It is in almost any answer a requirement that you decide how you relate the data, be it a flag, this method, something custom, etc. When a user is registering, how do they know which license to use (presuming you allow multiple licenses to be active at once)? you would need to include a reference to that in the Rule, regardless of your approach, or you won't know which license is being affected.

The nice thing about this approach is that it is quite simple in design, and allows a license information page to be created for the user to view status information about the license - it could include things like a list of the users for that license, etc. You could also use access control modules to restrict who can actually view the license page (owner)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.