public function test_certificate_email_others() { global $DB, $USER; $certificate = $this->generator->create_instance(array('course' => $this->course->id)); $coursemodule = get_coursemodule_from_instance('certificate', $certificate->id); $certificateissues = certificate_get_issue($this->course, $USER, $certificate, $coursemodule); $certificate->emailothers = "joeshmoe@shmoe.shmoe, harperseallooksdogerthandoge@doge.doge"; $emailarray = explode(',', $certificate->emailothers); unset_config('noemailever'); $sink = $this->redirectEmails(); certificate_email_others($this->course, $certificate, $certificateissues, $coursemodule); $messages = $sink->get_messages(); $this->assertEquals(count($emailarray), count($messages)); foreach ($emailarray as $email) { $emailisarecipient = false; foreach ($messages as $message) { if ($emailisarecipient = trim($email) == trim($message->to)) { break; } } $this->assertTrue($emailisarecipient); } }
/** * Inserts preliminary user data when a certificate is viewed. * Prevents form from issuing a certificate upon browser refresh. * * @param stdClass $course * @param stdClass $user * @param stdClass $certificate * @param stdClass $cm * @return stdClass the newly created certificate issue */ function certificate_get_issue($course, $user, $certificate, $cm) { global $DB; // Check if there is an issue already, should only ever be one if ($certissue = $DB->get_record('certificate_issues', array('userid' => $user->id, 'certificateid' => $certificate->id))) { return $certissue; } // Create new certificate issue record $certissue = new stdClass(); $certissue->certificateid = $certificate->id; $certissue->userid = $user->id; $certissue->code = certificate_generate_code(); $certissue->timecreated = time(); $certissue->id = $DB->insert_record('certificate_issues', $certissue); // Email to the teachers and anyone else certificate_email_teachers($course, $certificate, $certissue, $cm); certificate_email_others($course, $certificate, $certissue, $cm); return $certissue; }
/** * Inserts final user data when a certificate is created. * * @param stdClass $course * @param stdClass $certificate * @param stdClass $certrecord * @param stdClass $cm */ function certificate_issue($course, $certificate, $certrecord, $cm) { global $USER, $DB; if ($certificate->printgrade) { if ($certificate->printgrade == 1) { $grade = certificate_print_course_grade($course); } else { if ($certificate->printgrade > 1) { $grade = certificate_print_mod_grade($course, $certificate->printgrade); } } if ($certificate->gradefmt == 1) { $certrecord->reportgrade = $grade->percentage; } if ($certificate->gradefmt == 2) { $certrecord->reportgrade = $grade->points; } if ($certificate->gradefmt == 3) { $certrecord->reportgrade = $grade->letter; } } $date = certificate_generate_date($certificate, $course); $certrecord->certdate = $date; $DB->update_record('certificate_issues', $certrecord); certificate_email_teachers($course, $certificate, $certrecord, $cm); certificate_email_others($course, $certificate, $certrecord, $cm); }
function certificate_issue($course, $certificate, $certrecord, $cm) { if ($certificate->printgrade > 0) { if ($certificate->printgrade == 1) { $grade = certificate_print_course_grade($course); } else { if ($certificate->printgrade > 1) { $grade = certificate_print_mod_grade($course, $certificate->printgrade); } } if ($certificate->gradefmt == 1) { $certrecord->reportgrade = addslashes($grade->percentage); } if ($certificate->gradefmt == 2) { $certrecord->reportgrade = addslashes($grade->points); } if ($certificate->gradefmt == 3) { $certrecord->reportgrade = addslashes($grade->letter); } } $date = certificate_generate_date($certificate, $course); $certrecord->certdate = $date; update_record('certificate_issues', addslashes_object($certrecord)); certificate_email_teachers($course, $certificate, $certrecord, $cm); certificate_email_others($course, $certificate, $certrecord, $cm); }