How can I set a reminder for a specific user to be triggered on a specific date (in a Drupal 7 site)?
Example: I want to remind the user regarding particular event such as hepB vaccination day.
Any suggestions?
How can I set a reminder for a specific user to be triggered on a specific date (in a Drupal 7 site)?
Example: I want to remind the user regarding particular event such as hepB vaccination day.
Any suggestions?
Use the Rules module together with Rules Scheduler
(a sub-module of it), as explained in the 3 steps below. These steps are based on a date field which is added to the user profile, so that for each user you can indicate an appropriate date.
Add a field to the "user" entity with machine name (say) field_next_appointment
. Allow only 1 date (to store the "next" appointment), but don't make it required.
Here is the Rules Component to be created (in Rules export format, just import it in your own environment via copy-paste, which you can do using the "Import rule" link located at admin/config/workflow/rules
):
{ "rules_send_email_notification" : {
"LABEL" : "Send eMail notification",
"PLUGIN" : "action set",
"OWNER" : "rules",
"REQUIRES" : [ "rules" ],
"USES VARIABLES" : { "user_to_notify" : { "label" : "User to be notified", "type" : "user" } },
"ACTION SET" : [
{ "mail" : {
"to" : [ "user-to-notify:mail" ],
"subject" : "Friendly reminder about your upcoming event",
"message" : "This is a reminder about the upcoming event that you have an upcoming event on [user-to-notify:field_next_appointment] ...",
"from" : "[site:mail]",
"language" : [ "" ]
}
}
]
}
}
Obviously, the Subject and Content of the eMail may need review / tuning, while you might also want to use some other From eMail ID.
Here is the Rule to be created, in Rules export format (just import it in your own environment via copy-paste, which you can do using the "Import rule" link located at admin/config/workflow/rules
):
{ "rules_on_new_user_event_registration" : {
"LABEL" : "On new user event registration",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules", "rules_scheduler" ],
"ON" : { "user_update" : [] },
"IF" : [
{ "entity_has_field" : { "entity" : [ "account" ], "field" : "field_next_appointment" } }
],
"DO" : [
{ "schedule_delete" : {
"component" : "rules_send_email_notification",
"task" : "[account:name]"
}
},
{ "schedule" : {
"component" : "rules_send_email_notification",
"date" : {
"select" : "account:field-next-appointment",
"date_offset" : { "value" : 259200 }
},
"identifier" : "[account:name]",
"param_user_to_notify" : [ "account" ]
}
}
]
}
}
Note that the above rule refers to the Rules Component from the previous step.
Also note the machine name of field_next_appointment
in this rule, which is the field's machine name created in Step 1 (if in step 1 you used another machine name, then also replace the machine name field_next_appointment
in this rule with the machine name of the field created in Step 1 (if you don't have such field yet, or the field names don't match, then the import of the above rule might not work).
The schedule_delete
that is part of this rule is to ensure that previously "scheduled" reminders will get removed when updating the data field (so that it only triggers 1 reminder, and with the most recent date).
The date_offset (=259200) in the above rule corresponds to "3 days in advance", which may need review / tuning.
If needed, you could also use the Field Permissions module to set field-level permissions to edit, view and create fields on any entity.
Instead of just sending an eMail (as in the Rules Component), you could replace that by a more advanced option using the Message module (which has great integrations with the Rules module also). Here is an quote about that module (from its project page):
... enables logging and displaying system events in a number of different use cases. Events that are recorded over time are sometimes call activity streams. Exportable messages subtypes can be created for different use cases with custom fields and display (view) modes.
Note: Using Rules to send an email X days after a user registers also contains quite some details that may help you.
There is also the Date Reminder module. Here is a quote about this module (from its project page, bold markup added here):
... allows a registered user to request an email reminder to be sent at a specified time before an event. Generally these would be calendar events, but any node type that has a CCK datetime can support reminders.
However I think that module is not going to answer your question, because:
Using the Date Reminder module will be helpful for you. Some details about it (from its project page):
- When reminders are enabled for a node, registered users (with the appropriate privilege) can request reminders to be sent before each occurrence of the date/time. The user specifies how long before the date/time to send the reminder.
- When reminders are enabled for a node type, anyone who can edit the node can enable or disable reminders for that node.
- Reminders are sent using the Messaging system. The usual reminder method is email, but other messaging transports should work. (Well, not Drupal 7. The Drupal 7 version just uses straight email.)
- System administrator can control:
- Which node types allow reminders, and which date field (if there are several) in a type to use as the basis of reminders.
- Which (registered) users can request reminders.
- Which users can request reminders to arbitrary email addresses instead of their own.
- Which users can see or administer other users' reminders.
- Content of reminder messages.
- If and how long reminders should be kept after last date occurrence.
- The list of allowed lead times for reminders from which users can select.
An effort is under way to move much of the documentation here to the Date Reminder section of the Site Builders Guide. Currently that document is very incomplete, but watch there. Information on this module page will gradually be moving there.
You can create a cron job to execute a specific task at a scheduled time, as explained also in the article Managing Cron Jobs with PHP.