Is there a wat to automatically send email to user when Suspended or unenrolled ?

Is there a wat to automatically send email to user when Suspended or unenrolled ?

by David Hoeffel -
Number of replies: 3

Hi all,

I was wondering if there already was an existing functionnality to automatically send an e-mail to a user, when he is Suspended form a course ?

Is this also possible for an unenrollment ?

Thanks a lot for your answers ! big grin

Average of ratings: -
In reply to David Hoeffel

Re: Is there a waY to automatically send email to user when Suspended or unenrolled ?

by David Hoeffel -

Oops...I forgot to mention the Moodle version I'm using, here it goes :

Moodle 2.2.1+ (Build: 20120119)

In reply to David Hoeffel

Re: Is there a wat to automatically send email to user when Suspended or unenrolled ?

by Patrick Pollet -

Write local event trapping functions for events 'user_enrolled', 'user_unenrolled' or 'user_enrol_modified' (for suspending/unsuspending) . These events are sent by function  enrol_user , update_user_enrol and unenrol_user (in lib/enrollib.php) that are ultimately called by all types of enrolments plugins.

Your handlers will receive as parameter an object like these   (the format below is due to the fact that I always 'var dump' in a log file the parameters on my local event handlers for debugging purposes) :

1335540440 : processing user enrolled local event@insalyon : Array
(
[enrolid] => 4
[status] => 0
[userid] => 83
[timestart] => 1335477600
[timeend] => 0
[modifierid] => 3
[timecreated] => 1335540439
[timemodified] => 1335540439
[id] => 841
[courseid] => 3
[enrol] => manual
)

or 

1335540534 : processing user enrol modified local event@insalyon : Array
(
[id] => 841
[status] => 1    <-- status = 1 means suspended 0 unsuspended 
[enrolid] => 4
[userid] => 83
[timestart] => 1335477600
[timeend] => 0
[modifierid] => 3
[timecreated] => 1335540439
[timemodified] => 1335540439
[courseid] => 3
[enrol] =>
)

or 

1335540557 : processing user unenrolled local event@insalyon : Array
(
[id] => 841
[status] => 1
[enrolid] => 4
[userid] => 83
[timestart] => 1335477600
[timeend] => 0
[modifierid] => 3
[timecreated] => 1335540439
[timemodified] => 1335540439
[courseid] => 3
[enrol] => manual
[lastenrol] => 1
)

 

enrolid is the id of a record in table mdl_enrol from which you can retrieve the target course (from its courseid) to personnalize the mail.

Within your handler functions, do all testing/querying you want with these fields...and finally call if needed Moodle function email_to_user() 

For details see http://docs.moodle.org/dev/Events_API  http://docs.moodle.org/dev/Local_plugins  and http://xref.moodle.org/nav.html?_functions/index.html 

Cheers

Average of ratings: Useful (2)