mdjnelson / moodle-mod_customcert

Enables the creation of dynamically generated certificates with complete customisation via the web browser.
https://moodle.org/plugins/mod_customcert
GNU General Public License v3.0
93 stars 159 forks source link

Missing data when sending certificates by emails due to minor bug in email_certificate_html.mustache #574

Closed baris83 closed 9 months ago

baris83 commented 1 year ago

The variable declared as "emailcertificatelinktext" in email_certificate_html.mustache is not correct as it is declared as "emailcertificatetext" in email_certificate.php.

email_certificate_html.mustache

{{{emailgreeting}}}

{{{emailbody}}}

<a href="{{emailcertificatelink}}">{{emailcertificatelinktext}}</a>.

email_certificate.php

if ($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');
        }

Also "emailcertificatelink" is not correct because "$this->cmid" in email_certificate.php returning course module context id instead of course module id.

Maybe the parameter "$customcert->contextid" below can be changed to "$context->instanceid" ?

email_certificate_task.php

if ($customcert->emailstudents) {
                    $renderable = new \mod_customcert\output\email_certificate(true, $userfullname, $courseshortname,
                        $coursefullname, $certificatename, $customcert->contextid);

                    $subject = get_string('emailstudentsubject', 'customcert', $info);
                    $message = $textrenderer->render($renderable);
                    $messagehtml = $htmlrenderer->render($renderable);
                    email_to_user($user, fullname($userfrom), html_entity_decode($subject), $message, $messagehtml,
                        $tempfile, $filename);
                }
mdjnelson commented 9 months ago

Thanks, pushing fix shortly.