Timely and reliable tracking of course completions is essential in our use case. It would be very useful to send an email to an admin email address every time a course take or re-take status changes to 'Completed'. Thus notification of course completions is more fail safe if LMS admins have record of course completions both in their email and with online reports. It is paramount that we do not lose successful course completions.

I propose a call to drupal_mail_send($message) whenever a course registration status changes to 'Completed' whether pass or fail. An optional "Notification Email Address" could be added to admin/settings/scorm_cloud/settings. If the field is set, emails are sent. If the field is blank, emails are not sent.

The code could be something like...

$registration = array containing information about the course registration;
if ($registration->status_before_launch != $registration->status_after_launch &&
$registration->status_after_launch == "completed" &&
valid_email_address($scorm_cloud_email) ) {
profile_load_profile(&$user); // this is needed to load $user with the admin defined profile fields
$message['id'] = "course_notification";
$message['to'] = $scorm_cloud_email; // value from admin/settings/scorm_cloud/settings
$message['subject'] = $site_name . ": " . $user->email . " completed course " . $registration->coursename;
$message['body'] = "
USER: " . print_r($user,TRUE) . "

COURSE: " . print_r($registration,TRUE)
drupal_mail_send($message);
}

Comments

ronan’s picture

Status: Active » Postponed (maintainer needs more info)

This feels like something that would be better handled using triggers and actions (or the rules module). We could add some triggers to the module which fire after a completion of a course. That would allow you to configure an action to send an email at that point. That would keep the emailing logic out of this module and keep the coupling looser. Does this sound like it would meet your needs?

webservant316’s picture

Most certainly.

I haven't used triggers much, so could the email be customized to include information from the user, user profile, course, and course registration results? I see 'trigger' is a module available within core so that would be preferred if possible rather than a dependency to the rules module. Either way a dependency would need to be added.

ronan’s picture

Title: send email notification to admin when courses are completed » Add an action trigger for course completion
Status: Postponed (maintainer needs more info) » Fixed

I've added core a core action trigger when a course is completed.

webservant316’s picture

cool. I'll try it tomorrow.

webservant316’s picture

email works great. thanks!

One small glitch... the tokens
[scorm-cloud-registration-complete]
[scorm-cloud-registration-success]

Return HTML in the text email
scorm-cloud-registration-complete-complete">Complete
scorm-cloud-registration-success-passed">Passed

However the raw version of those two tokens work fine and the other tokens that I did use
[scorm-cloud-registration-complete-raw]
[scorm-cloud-registration-success-raw]

webservant316’s picture

last glitch fixed, tested, and should be available with the next development package in 24 hours.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.