Skip to content

Commit 06af2ac

Browse files
committed
Fixed issue with language strings not matching logic for placeholders (#684)
Also did some minor changes.
1 parent 349a4b4 commit 06af2ac

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

classes/template.php

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -320,38 +320,30 @@ public function generate_pdf(bool $preview = false, ?int $userid = null, bool $r
320320
$pdf->SetAutoPageBreak(true, 0);
321321

322322
// Get filename pattern from global settings.
323-
if (!empty($customcert->usecustomfilename) && !empty($customcert->customfilenamepattern)) {
324-
$filenamepattern = $customcert->customfilenamepattern;
325-
} else {
326-
$filenamepattern = '{DEFAULT}';
327-
}
328-
329-
if (empty($filenamepattern) || $filenamepattern === '{DEFAULT}') {
323+
if (empty($customcert->usecustomfilename) || empty($customcert->customfilenamepattern)) {
330324
// Use the custom cert name as the base filename (strip any trailing dot).
331325
$filename = rtrim(format_string($this->name, true, ['context' => $this->get_context()]), '.');
332326
} else {
333-
// Build filename from pattern substitutions.
334-
335327
// Get issue record for date (if issued); fallback to current date if not found.
336328
$issue = $DB->get_record('customcert_issues', [
337329
'userid' => $user->id,
338330
'customcertid' => $customcert->id,
339-
], '*', IGNORE_MISSING);
331+
]);
340332

341333
if ($issue && !empty($issue->timecreated)) {
342334
$issuedate = date('Y-m-d', $issue->timecreated);
343335
} else {
344336
$issuedate = date('Y-m-d');
345337
}
346338

347-
$course = $DB->get_record('course', ['id' => $customcert->course], '*', IGNORE_MISSING);
339+
$course = $DB->get_record('course', ['id' => $customcert->course]);
348340

349341
$values = [
350-
'{FIRST NAME}' => $user->firstname ?? '',
351-
'{LAST NAME}' => $user->lastname ?? '',
352-
'{COURSE SHORT NAME}' => $course ? $course->shortname : '',
353-
'{COURSE FULL NAME}' => $course ? $course->fullname : '',
354-
'{DATE}' => $issuedate,
342+
'{FIRST_NAME}' => $user->firstname ?? '',
343+
'{LAST_NAME}' => $user->lastname ?? '',
344+
'{COURSE_SHORT_NAME}' => $course ? $course->shortname : '',
345+
'{COURSE_FULL_NAME}' => $course ? $course->fullname : '',
346+
'{ISSUE_DATE}' => $issuedate,
355347
];
356348

357349
// Handle group if needed.
@@ -360,13 +352,13 @@ public function generate_pdf(bool $preview = false, ?int $userid = null, bool $r
360352
$groupnames = array_map(function($g) {
361353
return $g->name;
362354
}, $groups);
363-
$values['{GROUP}'] = implode(', ', $groupnames);
355+
$values['{GROUP_NAME}'] = implode(', ', $groupnames);
364356
} else {
365-
$values['{GROUP}'] = '';
357+
$values['{GROUP_NAME}'] = '';
366358
}
367359

368360
// Replace placeholders with actual values.
369-
$filename = strtr($filenamepattern, $values);
361+
$filename = strtr($customcert->customfilenamepattern, $values);
370362

371363
// Remove trailing dot to avoid "..pdf" issues.
372364
$filename = rtrim($filename, '.');

lang/en/customcert.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@
238238
239239
Enabling this option may improve the performance of the scheduled task by offloading email processing to ad-hoc tasks.';
240240
$string['usecustomfilename'] = 'Use custom file name pattern';
241-
$string['usecustomfilename_help'] = 'If enabled, you can define a custom file name pattern for certificates using placeholders such as {FIRST NAME}, {LAST NAME}, {GROUP}, {COUSRE SHORT NAME}, {DATE}.';
241+
$string['usecustomfilename_help'] = 'If enabled, you can define a custom file name pattern for certificates using placeholders. The placeholders are {FIRST_NAME}, {LAST_NAME}, {GROUP_NAME}, {COURSE_SHORT_NAME}, {COURSE_FULL_NAME} and {ISSUE_DATE}.';
242242
$string['userlanguage'] = 'Use user preferences';
243243
$string['userlanguage_help'] = 'You can force the language of the certificate to override the user\'s language preferences.';
244244
$string['verified'] = 'Verified';

0 commit comments

Comments
 (0)