1

I'd like to create a periodic summary email that gets sent to a specific role.

The summary email would include things such as:

  1. flagged content / users
  2. count new users
  3. count new nodes
  4. most viewed content
  5. flagged content / users

Item #1 is really the main goal - instead of send an email each time a user flags a user or node, I'd like to send a daily summary of all of the flagged entities.

How would you approach this?

2
  • Can you think of creating a view for such flagged content / users for (say) "current day"? If so, then there is a solution to do what you're asking about. In that case I'd be happy to post an appropriate answer. Commented Nov 21, 2017 at 14:30
  • Hey Pierre, I didn't think to use views - that would work for me. Please go ahead an share your solution.
    – ymdahi
    Commented Nov 21, 2017 at 18:19

1 Answer 1

1

Assuming you think of creating a view for such flagged content / users for (say) "current day", there is a solution to do what you're asking about. This solution uses the Rules, Views and Views Rules module, as further detailed below.

1. About the Views Rules module

The Views Rules module makes Views data available in Rules, enabling intuitive rule configuration for dynamic data. Some details from its project page:

... provides two types of elements in Rules, configured with a "Rules" view display:

  • Views loop: A views loop is similar to a regular Rules loop, but allows looping over rows of view results.

    enter image description here

  • Collect view result rows (action): This action collects each variable in all view result rows into list variables for use in Rules.

Tip: When selecting the data type for variables in the view, if the field is an entity identifier (e.g. Node ID), you can set the data type to the entity type (i.e. Node) to directly use the variable in Rules as an entity!

2. Create a view of display type 'Rules'

After you enable the Views Rules module, use Views to create a view of your "* flagged content / users*" (as in your question). Add of view of display type Rules (important, that's the key to make it work!). Here is how you can add such display:

enter image description here

Next configure the row variables, by using the link that says "edit field info", as shown here:

enter image description here

3. Create a Rule Component using the view of display type 'Rules'

Create a Rules Component, using these guidelines:

  • Add whatever Rules Conditions you might want (if any).
  • Some Rules Actions you'll need to create (add) for sure:
    • Create a variable, with no initial value, say you name it "eMail Summary" (machine name email_summary), which will be used in subsequent Rules Actions.
    • Add a Views loop (by using the link that says Add view loop), and select the "Rules" display created in the previous step. Configure the parameters and variable names. And for each views result contained in your Views loop (about some "flagged content / user", as in your question), perform a Rules Action like Set a data value, for the email_summary variable from the previous Rules Action. The actual value to be assigned, is the previous value of email_summary, to which you append the desired data about the Views result being processed. For this you can use the variables you configured at the end of the previous step (you may have to revisit the previous step to add more similar variables there if needed).
    • Add a Rules Action to Send an eMail to a selected role (as per your "periodic summary email that gets sent to a specific role"), whereas for the body of that eMail you simply use the value of the email_summary variable.

If you're not familiar enough with Rules to create and populate that email_summary variable, you may want to have a look at the Rules example included in my answer to "How to concatenate all token values of a list in a single field within a Rules loop?", in which a similar variable is used.

Try to execute your Rules Component "manually" (just to test), to unit-test if it works as desired. To do so, use the "execute" link to the right of the Rules Component (in the Rules UI).

4. Schedule the Rules Component for daily execution

Make sure you have the "Rules scheduler" enabled (a sub-module of Rules).

Improve your Rules Component from the previous step, by adding a Rules Action (as the last action to be performed) to Schedule a Rules Component, whereas the actual Rules Component to be scheduled is the Rules Component itself. You want it to be scheduled in "1 day from now" (to make it happen daily).

To execute this Rules Component the very first time, just execute your Rules Component "manually". To do so, use the "execute" link to the right of the Rules Component (in the Rules UI).

Assuming your QA-testing succeeded, and assuming your cron jobs are running also, the eMail should get created next time cron runs (after an amount of time, depending on the amount of time you configured in your Rules Component to get it rescheduled).

PS: The above addresses "Item #1" of your question, though it should be pretty forward to use a similar approach for the other items in your question.

2
  • awesome, thx mate - worked perfectly!
    – ymdahi
    Commented Nov 22, 2017 at 16:06
  • @ymdahi merci for the feecback! May I say "What else did you expect?" ... Next question? Commented Nov 22, 2017 at 16:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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