/** * Alerts others by email of received certificates. First checks * whether the option to email others is set for this certificate. * Uses the email_teachers info. * Code suggested by Eloy Lafuente */ function certificate_email_others($course, $certificate, $certrecord, $cm) { global $USER, $CFG, $DB; if ($certificate->emailothers) { $student = $certrecord->studentname; $others = explode(',', $certificate->emailothers); if ($others) { $strawarded = get_string('awarded', 'certificate'); foreach ($others as $other) { $other = trim($other); if (validate_email($other)) { $destination = new stdClass(); $destination->email = $other; $info = new stdClass(); $info->student = $student; $info->course = format_string($course->fullname, true); $info->certificate = format_string($certificate->name, true); $info->url = $CFG->wwwroot . '/mod/certificate/report.php?id=' . $cm->id; $from = $student; $postsubject = $strawarded . ': ' . $info->student . ' -> ' . $certificate->name; $posttext = certificate_email_teachers_text($info); $posthtml = certificate_email_teachers_html($info); @email_to_user($destination, $from, $postsubject, $posttext, $posthtml); // If it fails, oh well, too bad. } } } } }
public function test_certificate_email_teachers_html() { global $CFG, $USER; $certificate = $this->generator->create_instance(array('course' => $this->course->id)); $coursemodule = get_coursemodule_from_instance('certificate', $certificate->id); certificate_get_issue($this->course, $USER, $certificate, $coursemodule); $info = new stdClass(); $info->student = fullname($USER); $info->course = format_string($this->course->fullname, true); $info->certificate = format_string($certificate->name, true); $info->url = $CFG->wwwroot . '/mod/certificate/report.php?id=' . $coursemodule->id; // Just ensure that there is a message. $this->assertGreaterThan(0, strlen(certificate_email_teachers_html($info))); }
function certificate_email_teachers($certificate) { global $course, $USER, $CFG; if ($certificate->emailteachers == 0) { // No need to do anything return; } $certrecord = certificate_get_issue($course, $USER, $certificate->id); $student = $certrecord->studentname; $cm = get_coursemodule_from_instance("certificate", $certificate->id, $course->id); if (groupmode($course, $cm) == SEPARATEGROUPS) { // Separate groups are being used if (!($group = user_group($course->id, $user->id))) { // Try to find a group $group->id = 0; // Not in a group, never mind } $teachers = get_group_teachers($course->id, $group->id); // Works even if not in group } else { $teachers = get_course_teachers($course->id); } if ($teachers) { $strcertificates = get_string('modulenameplural', 'certificate'); $strcertificate = get_string('modulename', 'certificate'); $strawarded = get_string('awarded', 'certificate'); foreach ($teachers as $teacher) { unset($info); $info->student = $student; $info->course = format_string($course->fullname, true); $info->certificate = format_string($certificate->name, true); $info->url = $CFG->wwwroot . '/mod/certificate/report.php?id=' . $cm->id; $from = $student; $postsubject = $strawarded . ': ' . $info->student . ' -> ' . $certificate->name; $posttext = certificate_email_teachers_text($info); $posthtml = certificate_email_teachers_html($info); $posthtml = $teacher->mailformat == 1 ? certificate_email_teachers_html($info) : ''; @email_to_user($teacher, $from, $postsubject, $posttext, $posthtml); // If it fails, oh well, too bad. set_field("certificate_issues", "mailed", "1", "certificateid", $certificate->id, "userid", $USER->id); } } }