Loop through users and/or roles

Events happening in the community are now at Drupal community events on www.drupal.org.
Posted by unwiredbrain on September 17, 2011 at 3:47pm

It is possible to loop through each registered user? What about user roles?

Here's a real use case.

I want to run a club; be it a book club or a night club, doesn't matter. Being a club, it must have members i.e. users with a particular user role applied ("member"). Each user membership lasts for a certain period of time ("membership period"), let it be one hour, 6 months or 20 years, doesn't matter.

[member] users have a field named "expiration" which contains the user creation timestamp with the [membership period] applied.

The best option would be defining a rule on cron execution that does the following:

  1. collect all the users that have the [member] role applied: call such collection "members".
  2. for each user of the [members] collection ("user")...
    1. compare the site current timestamp ("site") to its [expiration] timestamp:
    2. if [site] IS GREATER THAN [expiration] then the user must be expired, and some action is required (block user, send mail, warn administrators, etc.);
    3. if not, continue to the next user.

Is there a way to do this with Rules?

Comments

Use Ruleset and then schedule component evaluation

Posted by marcoscano on September 18, 2011 at 6:15am

Hi

I don't think you need to have this periodically ckeck loop. I would use instead a scheduled evaluation of a single ruleset. Here's how to do it:

1) Go to Rules/Components, create a "Ruleset" with the actions you need to perform on expiration
2) On user creation, create a new rule of type "Schedule component evaluation", and then choose the ruleset you just created

Once scheduled, the actions in the ruleset will be triggered the first time cron runs, after the scheduled date.

Hope it helps

Regards

Further explanations

Posted by unwiredbrain on September 18, 2011 at 3:34pm

First of all: tranks.

I choose «Add new component», pick «Rule set» as «Component plugin», then ...i get lost. Totally.

Unfortunately I'm not that skilled with Rules: I'm a newbie, actually :(
Could you provide more detailed instructions?

Thanks

Hi there You could try

Posted by marcoscano on September 18, 2011 at 4:34pm

Hi there

You could try watching http://nodeone.se/blogg/learn-rules-screencast-series-summed-up, especially chapters 10 to 12,they are specific about rules scheduler. These videos are on Drupal 6, but I'm sure you can get the idea and the concepts are the same to create and schedule rules.

In a near future you'll hopefully have also the option of having the up-to-date version of this tutorial, on

http://nodeone.se/node/984 (for Rules 2 - Drupal 7)

But apparently the chapters on components and rules scheduler are not yet published.

Good luck!

Regards

Rules

Group organizers

Group categories

Categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

AltStyle によって変換されたページ (->オリジナル) /