From 769f653777b98c078cfd971a97d2d41d26b8b17e Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Sat, 31 Aug 2024 15:49:22 +0100 Subject: [PATCH] Minor formatting changes (#531) --- classes/task/email_certificate_task.php | 17 +++++++++-------- classes/task/issue_certificates_task.php | 23 +++++++++++++++-------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/classes/task/email_certificate_task.php b/classes/task/email_certificate_task.php index 73e6a185..adb0c3f5 100644 --- a/classes/task/email_certificate_task.php +++ b/classes/task/email_certificate_task.php @@ -48,6 +48,7 @@ public function get_name() { */ public function execute() { global $DB; + $customdata = $this->get_custom_data(); $issueid = $customdata->issueid; @@ -57,7 +58,7 @@ public function execute() { FROM {customcert} c JOIN {customcert_templates} ct ON c.templateid = ct.id JOIN {course} co ON c.course = co.id - WHERE c.id = :id"; + WHERE c.id = :id"; $customcert = $DB->get_record_sql($sql, ['id' => $customcertid]); @@ -79,12 +80,12 @@ public function execute() { $coursefullname = format_string($customcert->coursefullname, true, ['context' => $context]); $certificatename = format_string($customcert->name, true, ['context' => $context]); - // Used to create the email subject. - $info = new \stdClass(); - $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; + // Used to create the email subject. + $info = new \stdClass(); + $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 the information about the user and the certificate issue. $userfields = helper::get_all_user_name_fields('u'); @@ -93,7 +94,7 @@ public function execute() { JOIN {user} u ON ci.userid = u.id WHERE ci.customcertid = :customcertid - AND ci.id = :issueid"; + AND ci.id = :issueid"; $user = $DB->get_record_sql($sql, ['customcertid' => $customcertid, 'issueid' => $issueid]); // Create a directory to store the PDF we will be sending. diff --git a/classes/task/issue_certificates_task.php b/classes/task/issue_certificates_task.php index 1bb7d79b..f82cd5fc 100644 --- a/classes/task/issue_certificates_task.php +++ b/classes/task/issue_certificates_task.php @@ -60,10 +60,14 @@ public function execute() { $sql = "SELECT c.*, ct.id as templateid, ct.name as templatename, ct.contextid, co.id as courseid, co.fullname as coursefullname, co.shortname as courseshortname FROM {customcert} c - JOIN {customcert_templates} ct ON c.templateid = ct.id - JOIN {course} co ON c.course = co.id - JOIN {course_categories} cat ON co.category = cat.id - LEFT JOIN {customcert_issues} ci ON c.id = ci.customcertid"; + JOIN {customcert_templates} ct + ON c.templateid = ct.id + JOIN {course} co + ON c.course = co.id + JOIN {course_categories} cat + ON co.category = cat.id + LEFT JOIN {customcert_issues} ci + ON c.id = ci.customcertid"; // Add conditions to exclude certificates from hidden courses. $sql .= " WHERE (c.emailstudents = :emailstudents @@ -77,6 +81,7 @@ public function execute() { // Exclude certificates from hidden courses. $sql .= " AND co.visible = 1 AND cat.visible = 1"; } + // Add condition based on certificate execution period. if ($certificateexecutionperiod > 0) { // Include courses with no end date or end date greater than the specified period. @@ -92,12 +97,12 @@ public function execute() { // When we get to the end of the list, reset the offset. set_config('certificate_offset', !empty($customcerts) ? $offset + $certificatesperrun : 0, 'customcert'); + if (empty($customcerts)) { return; } foreach ($customcerts as $customcert) { - // Check if the certificate is hidden, quit early. $cm = get_course_and_cm_from_instance($customcert->id, 'customcert', $customcert->course)[1]; if (!$cm->visible) { @@ -107,9 +112,11 @@ public function execute() { // Do not process an empty certificate. $sql = "SELECT ce.* FROM {customcert_elements} ce - JOIN {customcert_pages} cp ON cp.id = ce.pageid - JOIN {customcert_templates} ct ON ct.id = cp.templateid - WHERE ct.contextid = :contextid"; + JOIN {customcert_pages} cp + ON cp.id = ce.pageid + JOIN {customcert_templates} ct + ON ct.id = cp.templateid + WHERE ct.contextid = :contextid"; if (!$DB->record_exists_sql($sql, ['contextid' => $customcert->contextid])) { continue; }