tags:

views:

872

answers:

1

Hi,

I may be missing something blindingly obvious here (I hope so).....I am creating a module in Drupal 6 that consists of some triggers and actions. in it's simplest form it consists of:

  1. An action which checks for some criteria (event that needs to be triggered once a month per user)
  2. A trigger which is fired for each user that the criteria is true for

I would like as much as possible to be managed through the triggers / actions interface in Drupal as the site admin is not a developer. The plan is to use the cron trigger to fire the action in 1. which will then fire a trigger for each user. The site admin will then be able to create a Send Email action through the actions interface and hook it up to the trigger from 2.

The part I can't get my head around is how the recipient of the email will be specified - the user trigger will be fired from an action run by cron (i.e. not in any user context) - how can I pass in a variable that can be used here?

Thanks,

+1  A: 

Triggers fire actions not the other way around.

The user that you pass to actions_do dosn't have to be the logged in user. You can query for the users that you want to email and loop thrhough them doing user_load and then an actions_do

something like

foreach ($user_ids as $uid) {
  $context_user = user_load(array('uid' => $uid));
  $context = array(
    'hook' => 'myhook',
    'op' => $op,
    'user' => $context_user,
  );
  actions_do(array_keys($aids), $context_user, $context);
}
Jeremy French
ok so no real need for the action to fire new triggers, it could just do the actions directly. How would the 'send email' action be created from within the interface to use the context_user as the email address though?
Macros
I'll have to look into it to be sure, but in the above code as far as the action is concerned it is just dealing with the $user context, so it shoudn't be any different.
Jeremy French
Finally got around to looking back at this code - worked great along with the token module to send tokenized emails.
Macros

related questions