diff --git a/classes/event/certificate_created.php b/classes/event/certificate_created.php new file mode 100644 index 0000000..adb94b3 --- /dev/null +++ b/classes/event/certificate_created.php @@ -0,0 +1,32 @@ +. + +/** + * This page lists all the instances of certificate in a particular course + * + * @package mod + * @subpackage certificate + * @copyright Mark Nelson + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace mod_certificate\event; + +defined('MOODLE_INTERNAL') || die(); + +class certificate_created extends \core\event\base { +} diff --git a/lib.php b/lib.php index dda5309..743142c 100644 --- a/lib.php +++ b/lib.php @@ -348,6 +348,7 @@ function certificate_get_post_actions() { */ function certificate_cron () { global $DB; + $sql = "select distinct cm.id as cmid, c.*, ce.id as certificateid, ce.name as certificatename from {certificate} ce inner join {course} c on c.id = ce.course @@ -379,6 +380,19 @@ function certificate_cron () { (certificate_get_course_time($course->id) >= ($certificate->requiredtime * 60))) { echo " generating issue certificate for {$student->firstname} {$student->lastname}..."; $certrecord = certificate_get_issue($course, $student, $certificate, $cm); + + $context = context_module::instance($cm->id); + + $event = \mod_certificate\event\certificate_created::create(array( + 'objectid' => $certrecord->id, + 'context' => $context, + 'other' => $certrecord) + ); + //$event->add_record_snapshot('course_modules', $this->cm); + //$event->add_record_snapshot('attendance_sessions', $session); + //$event->add_record_snapshot('attendance_log', $record); + $event->trigger(); + echo " Done! Certificate {$certrecord->code} generated!\n"; } else { echo " {$student->firstname} {$student->lastname} has not required course time. Skiped!\n";