Skip to content

Commit

Permalink
Minor formatting changes (#531)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjnelson committed Sep 11, 2024
1 parent c058d0e commit 769f653
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
17 changes: 9 additions & 8 deletions classes/task/email_certificate_task.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function get_name() {
*/
public function execute() {
global $DB;

$customdata = $this->get_custom_data();

$issueid = $customdata->issueid;
Expand All @@ -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]);

Expand All @@ -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');
Expand All @@ -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.
Expand Down
23 changes: 15 additions & 8 deletions classes/task/issue_certificates_task.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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) {
Expand All @@ -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;
}
Expand Down

0 comments on commit 769f653

Please sign in to comment.