Here is how I think it should work (but this is not how it currently works !)
- When you create a new certificate instance in a course you enter an "Expiration date" and "Days to email before expiration" (no change here this is how it is working now). This data is related to a certificate so it would be saved in the mdl_certificate table. It can be changed by editing the certificate. The only modifications I would do would be to add settings (checkboxes) to activate or not the expiration date and sending of emails features.
- When a student get a new certificate, the expiration date would be copied from the mdl_certificate table to the mdl_certificate_issues table, so it would be related to just this user and just this certificate. A new column in that table would also indicate if this student has been mailed about the expiration of this certificate or not. This is brand new code that don't currently exist and would have to be written.
- The cron running periodically would search for certificates issues about to expire and send mails accordingly. This is just a modification of the existing code to look for the expiration date on a certificate issue basis (not certificate basis) and from the mdl_certificate_issues table (not mdl_certificate). I would also change some of the existing code (for instance it currently use the php mail function to send mails witch is very bad, it should use the Moodle way of sending mails).
- The certificate_expiry_users block would work the same as it does now, the only difference is that expiration date would be fetched on a certificate issue basis not certificate
How it would work ?
student A follow the 2013 course and the course has a certificate set to expire on 2014 December 31th, and mails to be send 4 days before expiration.
when he get his certificate, this date is copied on the line for this issue and this student and 0 for mail send
on 2014 January 1st, the course is reset for a new year and expiration date is changed to 2015 December 31h. Student A is not affected at all by this change.
if another student B follow this course and get the certificate, the new date is copied for him.
on 2014 December 27th, when the cron is run, student A get a mail that his certificate is about to expire and mail send is set to 1 for this certificate issue. Student B don't get any mail.
If student A follow a new course he will get a new certificate issue with a new expiration date.
Do you follow my explanations and does it suit your client needs ?
I would also be interested to hear from other users of the certificate module and from Mark too.