#126 Use the course full name in emails

This commit is contained in:
Mark Nelson 2017-11-11 15:11:55 +08:00
parent 750a787214
commit 759df979c8
3 changed files with 25 additions and 14 deletions

View file

@ -44,6 +44,11 @@ class email_certificate implements \renderable, \templatable {
*/
public $userfullname;
/**
* @var string The course short name.
*/
public $courseshortname;
/**
* @var string The course full name.
*/
@ -64,13 +69,15 @@ class email_certificate implements \renderable, \templatable {
*
* @param bool $isstudent Are we emailing the student?
* @param string $userfullname The name of the user who owns the certificate.
* @param string $coursefullname The name of the course.
* @param string $courseshortname The short name of the course.
* @param string $coursefullname The full name of the course.
* @param string $certificatename The name of the certificate.
* @param string $cmid The course module id.
*/
public function __construct($isstudent, $userfullname, $coursefullname, $certificatename, $cmid) {
public function __construct($isstudent, $userfullname, $courseshortname, $coursefullname, $certificatename, $cmid) {
$this->isstudent = $isstudent;
$this->userfullname = $userfullname;
$this->courseshortname = $courseshortname;
$this->coursefullname = $coursefullname;
$this->certificatename = $certificatename;
$this->cmid = $cmid;
@ -89,6 +96,7 @@ class email_certificate implements \renderable, \templatable {
$info = new \stdClass();
$info->userfullname = $this->userfullname;
$info->certificatename = $this->certificatename;
$info->courseshortname = $this->courseshortname;
$info->coursefullname = $this->coursefullname;
if ($this->isstudent) {

View file

@ -51,7 +51,7 @@ class email_certificate_task extends \core\task\scheduled_task {
// Get all the certificates that have requested someone get emailed.
$sql = "SELECT c.*, ct.id as templateid, ct.name as templatename, ct.contextid, co.id as courseid,
co.shortname as coursename
co.fullname as coursefullname, co.shortname as courseshortname
FROM {customcert} c
JOIN {customcert_templates} ct
ON c.templateid = ct.id
@ -78,12 +78,15 @@ class email_certificate_task extends \core\task\scheduled_task {
$userfrom = get_admin();
}
$coursename = format_string($customcert->coursename, true, array('context' => $context));
$courseshortname = format_string($customcert->courseshortname, true, array('context' => $context));
$coursefullname = format_string($customcert->coursefullname, true, array('context' => $context));
$certificatename = format_string($customcert->name, true, array('context' => $context));
// Used to create the email subject.
$info = new \stdClass;
$info->coursename = $coursename;
$info->coursename = $courseshortname; // Added for BC, so users who have edited the string don't lose this value.
$info->courseshortname = $courseshortname;
$info->coursefullname = $coursefullname;
$info->certificatename = $certificatename;
// Get a list of all the issues.
@ -166,7 +169,7 @@ class email_certificate_task extends \core\task\scheduled_task {
$filecontents = $template->generate_pdf(false, $user->id, true);
// Set the name of the file we are going to send.
$filename = $coursename . '_' . $certificatename;
$filename = $courseshortname . '_' . $certificatename;
$filename = \core_text::entities_to_utf8($filename);
$filename = strip_tags($filename);
$filename = rtrim($filename, '.');
@ -177,8 +180,8 @@ class email_certificate_task extends \core\task\scheduled_task {
file_put_contents($tempfile, $filecontents);
if ($customcert->emailstudents) {
$renderable = new \mod_customcert\output\email_certificate(true, $userfullname, $coursename,
$certificatename, $customcert->contextid);
$renderable = new \mod_customcert\output\email_certificate(true, $userfullname, $courseshortname,
$coursefullname, $certificatename, $customcert->contextid);
$subject = get_string('emailstudentsubject', 'customcert', $info);
$message = $textrenderer->render($renderable);
@ -187,8 +190,8 @@ class email_certificate_task extends \core\task\scheduled_task {
}
if ($customcert->emailteachers) {
$renderable = new \mod_customcert\output\email_certificate(false, $userfullname, $coursename,
$certificatename, $customcert->contextid);
$renderable = new \mod_customcert\output\email_certificate(false, $userfullname, $courseshortname,
$coursefullname, $certificatename, $customcert->contextid);
$subject = get_string('emailnonstudentsubject', 'customcert', $info);
$message = $textrenderer->render($renderable);
@ -204,8 +207,8 @@ class email_certificate_task extends \core\task\scheduled_task {
foreach ($others as $email) {
$email = trim($email);
if (validate_email($email)) {
$renderable = new \mod_customcert\output\email_certificate(false, $userfullname, $coursename,
$certificatename, $customcert->contextid);
$renderable = new \mod_customcert\output\email_certificate(false, $userfullname,
$courseshortname, $coursefullname, $certificatename, $customcert->contextid);
$subject = get_string('emailnonstudentsubject', 'customcert', $info);
$message = $textrenderer->render($renderable);

View file

@ -65,11 +65,11 @@ $string['elementwidth_help'] = 'Specify the width of the element - \'0\' means t
$string['emailnonstudentbody'] = 'Attached is the certificate \'{$a->certificatename}\' for \'{$a->userfullname}\' for the course \'{$a->coursefullname}\'.';
$string['emailnonstudentcertificatelinktext'] = 'View certificate report';
$string['emailnonstudentgreeting'] = 'Hi';
$string['emailnonstudentsubject'] = '{$a->coursename}: {$a->certificatename}';
$string['emailnonstudentsubject'] = '{$a->coursefullname}: {$a->certificatename}';
$string['emailstudentbody'] = 'Attached is your certificate \'{$a->certificatename}\' for the course \'{$a->coursefullname}\'.';
$string['emailstudentcertificatelinktext'] = 'View certificate';
$string['emailstudentgreeting'] = 'Dear {$a}';
$string['emailstudentsubject'] = '{$a->coursename}: {$a->certificatename}';
$string['emailstudentsubject'] = '{$a->coursefullname}: {$a->certificatename}';
$string['emailstudents'] = 'Email students';
$string['emailstudents_help'] = 'If set this will email the students a copy of the certificate when it becomes available.';
$string['emailteachers'] = 'Email teachers';