Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom email feature added #490

Open
wants to merge 1 commit into
base: MOODLE_311_STABLE
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 39 additions & 7 deletions classes/output/email_certificate.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,52 @@ public function export_for_template(\renderer_base $renderer) {
$info->courseshortname = $this->courseshortname;
$info->coursefullname = $this->coursefullname;

if ($this->isstudent) {
$studentpattern = '/\$studentname/';
$certificatepattern = '/\$certificatename/';
$coursepattern = '/\$coursename/';

$studentmessage = get_config('customcert', 'emailstudentmessage');

if($studentmessage != "" && $this->isstudent){

//replace all variables in email message
$studentmessage = preg_replace($studentpattern, $this->userfullname, $studentmessage);
$studentmessage = preg_replace($certificatepattern, $info->certificatename, $studentmessage);
$studentmessage = preg_replace($coursepattern, $info->coursefullname, $studentmessage);

$data->emailgreeting="";
$data->emailbody = $studentmessage;
$data->emailbodyplaintext = $studentmessage;
$data->emailcertificatelink = new \moodle_url('/mod/customcert/view.php', array('id' => $this->cmid));
$data->emailcertificatetext = get_string('emailstudentcertificatelinktext', 'customcert');
}elseif ($studentmessage == "" && $this->isstudent) {
$data->emailgreeting = get_string('emailstudentgreeting', 'customcert', $this->userfullname);
$data->emailbody = get_string('emailstudentbody', 'customcert', $info);
$data->emailbodyplaintext = get_string('emailstudentbodyplaintext', 'customcert', $info);
$data->emailcertificatelink = new \moodle_url('/mod/customcert/view.php', array('id' => $this->cmid));
$data->emailcertificatetext = get_string('emailstudentcertificatelinktext', 'customcert');
} else {
$data->emailgreeting = get_string('emailnonstudentgreeting', 'customcert');
$data->emailbody = get_string('emailnonstudentbody', 'customcert', $info);
$data->emailbodyplaintext = get_string('emailnonstudentbodyplaintext', 'customcert', $info);
$data->emailcertificatelink = new \moodle_url('/mod/customcert/view.php', array('id' => $this->cmid));
$data->emailcertificatetext = get_string('emailnonstudentcertificatelinktext', 'customcert');
}
$nonstudentmessage = get_config('customcert', 'emailnonstudentmessage');
if($nonstudentmessage!=""){

//replace all variables in email message
$nonstudentmessage = preg_replace($studentpattern, $this->userfullname, $nonstudentmessage);
$nonstudentmessage = preg_replace($certificatepattern, $info->certificatename, $nonstudentmessage);
$nonstudentmessage = preg_replace($coursepattern, $info->coursefullname, $nonstudentmessage);

$data->emailgreeting = "";
$data->emailbody = $nonstudentmessage;
$data->emailbodyplaintext = $nonstudentmessage;
$data->emailcertificatelink = new \moodle_url('/mod/customcert/view.php', array('id' => $this->cmid));
$data->emailcertificatetext = get_string('emailnonstudentcertificatelinktext', 'customcert');
}else{
$data->emailgreeting = get_string('emailnonstudentgreeting', 'customcert');
$data->emailbody = get_string('emailnonstudentbody', 'customcert', $info);
$data->emailbodyplaintext = get_string('emailnonstudentbodyplaintext', 'customcert', $info);
$data->emailcertificatelink = new \moodle_url('/mod/customcert/view.php', array('id' => $this->cmid));
$data->emailcertificatetext = get_string('emailnonstudentcertificatelinktext', 'customcert');
}
}
return $data;
}
}
4 changes: 4 additions & 0 deletions lang/en/customcert.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,12 @@
$string['emailnonstudentsubject'] = '{$a->coursefullname}: {$a->certificatename}';
$string['emailstudentbody'] = 'Attached is your certificate \'{$a->certificatename}\' for the course \'{$a->coursefullname}\'.';
$string['emailstudentbodyplaintext'] = 'Attached is your certificate \'{$a->certificatename}\' for the course \'{$a->coursefullname}\'.';
$string['emailnonstudentmessage'] = 'Template email sent to teachers and others listed';
$string['emailnonstudentmessage_help'] = 'Create message to be emailed to teachers and others listed above. If left blank default email will be sent. For emails customized to student use $studentname, $certificate, $coursename variables, for where the student name, certificate name, and course name should be replaced.';
$string['emailstudentcertificatelinktext'] = 'View certificate';
$string['emailstudentgreeting'] = 'Dear {$a}';
$string['emailstudentmessage'] = 'Template email sent to students';
$string['emailstudentmessage_help'] = 'Create message to be emailed to students. If left blank default email will be sent. For emails customized to student use $studentname, $certificate, $coursename variables, for where the student name, certificate name, and course name should be replaced.';
$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. <strong>Warning:</strong> Setting this to \'Yes\' before you have finished creating the certificate will email the student an incomplete certificate.';
Expand Down
4 changes: 4 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,14 @@

$settings->add(new admin_setting_configselect('customcert/emailstudents',
get_string('emailstudents', 'customcert'), get_string('emailstudents_help', 'customcert'), 0, $yesnooptions));
$settings->add(new admin_setting_configtextarea('customcert/emailstudentmessage',
get_string('emailstudentmessage', 'customcert'), get_string('emailstudentmessage_help', 'customcert'),"", PARAM_RAW, '60','8'));
$settings->add(new admin_setting_configselect('customcert/emailteachers',
get_string('emailteachers', 'customcert'), get_string('emailteachers_help', 'customcert'), 0, $yesnooptions));
$settings->add(new admin_setting_configtext('customcert/emailothers',
get_string('emailothers', 'customcert'), get_string('emailothers_help', 'customcert'), '', PARAM_TEXT));
$settings->add(new admin_setting_configtextarea('customcert/emailnonstudentmessage',
get_string('emailnonstudentmessage', 'customcert'), get_string('emailnonstudentmessage_help', 'customcert'),"", PARAM_RAW, '60','8'));
$settings->add(new admin_setting_configselect('customcert/verifyany',
get_string('verifycertificateanyone', 'customcert'), get_string('verifycertificateanyone_help', 'customcert'),
0, $yesnooptions));
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');

$plugin->version = 2021051702; // The current module version (Date: YYYYMMDDXX).
$plugin->version = 2022040503; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2021051700; // Requires this Moodle version (3.11).
$plugin->cron = 0; // Period for cron to check this module (secs).
$plugin->component = 'mod_customcert';
Expand Down