Browse Source

Criando evento para os certificados

master
Matheus456 6 years ago
parent
commit
ad43a18967
  1. 10
      classes/event/certificate_created.php
  2. 15
      lib.php
  3. 3
      locallib.php

10
classes/event/certificate_created.php

@ -29,4 +29,14 @@ namespace mod_certificate\event;
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
class certificate_created extends \core\event\base { class certificate_created extends \core\event\base {
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->data['objecttable'] = 'certificate';
}
} }

15
lib.php

@ -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";

3
locallib.php

@ -366,7 +366,10 @@ function certificate_get_issue($course, $user, $certificate, $cm) {
// Create new certificate issue record // Create new certificate issue record
$certissue = new stdClass(); $certissue = new stdClass();
$certissue->certificateid = $certificate->id; $certissue->certificateid = $certificate->id;
$certissue->user = $user->username;
$certissue->course = $certificate->course;
$certissue->userid = $user->id; $certissue->userid = $user->id;
$certissue->gradefmt = $certificate->gradefmt;
$certissue->code = certificate_generate_code(); $certissue->code = certificate_generate_code();
$certissue->timecreated = time(); $certissue->timecreated = time();
$certissue->id = $DB->insert_record('certificate_issues', $certissue); $certissue->id = $DB->insert_record('certificate_issues', $certissue);

Loading…
Cancel
Save