|
@ -349,6 +349,13 @@ function certificate_get_post_actions() { |
|
|
function certificate_cron () { |
|
|
function certificate_cron () { |
|
|
global $DB; |
|
|
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 |
|
|
|
|
|
// inner join {course_modules} cm on cm.course = c.id and cm.instance = ce.id |
|
|
|
|
|
// where c.visible = 1 |
|
|
|
|
|
// order by c.id"; |
|
|
|
|
|
|
|
|
$sql = "select distinct cm.id as cmid, c.*, ce.id as certificateid, ce.name as certificatename |
|
|
$sql = "select distinct cm.id as cmid, c.*, ce.id as certificateid, ce.name as certificatename |
|
|
from {certificate} ce |
|
|
from {certificate} ce |
|
|
inner join {course} c on c.id = ce.course |
|
|
inner join {course} c on c.id = ce.course |
|
@ -367,6 +374,7 @@ function certificate_cron () { |
|
|
from {certificate_issues} ci |
|
|
from {certificate_issues} ci |
|
|
where ci.certificateid = ?) |
|
|
where ci.certificateid = ?) |
|
|
order by u.firstname"; |
|
|
order by u.firstname"; |
|
|
|
|
|
|
|
|
foreach ($courses as $course) { |
|
|
foreach ($courses as $course) { |
|
|
echo " Processing course {$course->fullname}, certificate: {$course->certificatename}...\n"; |
|
|
echo " Processing course {$course->fullname}, certificate: {$course->certificatename}...\n"; |
|
|
$students = $DB->get_records_sql($sql, array($course->id, $course->certificateid)); |
|
|
$students = $DB->get_records_sql($sql, array($course->id, $course->certificateid)); |
|
@ -380,17 +388,12 @@ function certificate_cron () { |
|
|
(certificate_get_course_time($course->id) >= ($certificate->requiredtime * 60))) { |
|
|
(certificate_get_course_time($course->id) >= ($certificate->requiredtime * 60))) { |
|
|
echo " generating issue certificate for {$student->firstname} {$student->lastname}..."; |
|
|
echo " generating issue certificate for {$student->firstname} {$student->lastname}..."; |
|
|
$certrecord = certificate_get_issue($course, $student, $certificate, $cm); |
|
|
$certrecord = certificate_get_issue($course, $student, $certificate, $cm); |
|
|
|
|
|
$context = context_course::instance($course->id); |
|
|
$context = context_module::instance($cm->id); |
|
|
|
|
|
|
|
|
|
|
|
$event = \mod_certificate\event\certificate_created::create(array( |
|
|
$event = \mod_certificate\event\certificate_created::create(array( |
|
|
'objectid' => $certrecord->id, |
|
|
'objectid' => $certrecord->id, |
|
|
'context' => $context, |
|
|
'context' => $context, |
|
|
'other' => $certrecord) |
|
|
'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(); |
|
|
$event->trigger(); |
|
|
|
|
|
|
|
|
echo " Done! Certificate {$certrecord->code} generated!\n"; |
|
|
echo " Done! Certificate {$certrecord->code} generated!\n"; |
|
|