Skip to content

Commit dab874d

Browse files
committed
Fetched upstream changes
1 parent 9eddb48 commit dab874d

File tree

5 files changed

+42
-16
lines changed

5 files changed

+42
-16
lines changed

classes/template.php

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -320,30 +320,38 @@ 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)) {
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}') {
324330
// Use the custom cert name as the base filename (strip any trailing dot).
325331
$filename = rtrim(format_string($this->name, true, ['context' => $this->get_context()]), '.');
326332
} else {
333+
// Build filename from pattern substitutions.
334+
327335
// Get issue record for date (if issued); fallback to current date if not found.
328336
$issue = $DB->get_record('customcert_issues', [
329337
'userid' => $user->id,
330338
'customcertid' => $customcert->id,
331-
]);
339+
], '*', IGNORE_MISSING);
332340

333341
if ($issue && !empty($issue->timecreated)) {
334342
$issuedate = date('Y-m-d', $issue->timecreated);
335343
} else {
336344
$issuedate = date('Y-m-d');
337345
}
338346

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

341349
$values = [
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,
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,
347355
];
348356

349357
// Handle group if needed.
@@ -352,13 +360,13 @@ public function generate_pdf(bool $preview = false, ?int $userid = null, bool $r
352360
$groupnames = array_map(function($g) {
353361
return $g->name;
354362
}, $groups);
355-
$values['{GROUP_NAME}'] = implode(', ', $groupnames);
363+
$values['{GROUP}'] = implode(', ', $groupnames);
356364
} else {
357-
$values['{GROUP_NAME}'] = '';
365+
$values['{GROUP}'] = '';
358366
}
359367

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

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

db/upgrade.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ function xmldb_customcert_upgrade($oldversion) {
318318
upgrade_plugin_savepoint(true, 2024042210, 'mod', 'customcert');
319319
}
320320

321-
if ($oldversion < 2024042213) {
321+
if ($oldversion < 2025062100) {
322322
$table = new xmldb_table('customcert');
323323

324324
// Add 'usecustomfilename' field.
@@ -334,8 +334,7 @@ function xmldb_customcert_upgrade($oldversion) {
334334
}
335335

336336
// Savepoint reached.
337-
upgrade_mod_savepoint(true, 2024042213, 'customcert');
337+
upgrade_mod_savepoint(true, 2025062100, 'customcert');
338338
}
339-
340339
return true;
341340
}

lang/en/customcert.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2323
*/
2424

25+
$string['Upper/lower/digits'] = '6aOdbLEuoC (Upper/lower/digits random string)';
2526
$string['activity'] = 'Activity';
2627
$string['addcertpage'] = 'Add page';
2728
$string['addelement'] = 'Add element';
@@ -65,6 +66,8 @@
6566
$string['customcertsettings'] = 'Custom certificate settings';
6667
$string['customfilenamepattern'] = 'Custom file name pattern';
6768
$string['customfilenamepattern_help'] = 'Enter the pattern for naming certificate files. You can use placeholders such as {firstname}, {lastname}, {group}, {coursename}, {date}.';
69+
$string['custompattern'] = 'First name, Last name, Course short name, Issue date';
70+
$string['defaultpattern'] = 'Default (certificate name)';
6871
$string['deletecertpage'] = 'Delete page';
6972
$string['deleteconfirm'] = 'Delete confirmation';
7073
$string['deleteelement'] = 'Delete element';
@@ -73,10 +76,14 @@
7376
$string['deleteissuedcertificates'] = 'Delete issued certificates';
7477
$string['deletepageconfirm'] = 'Are you sure you want to delete this certificate page?';
7578
$string['deletetemplateconfirm'] = 'Are you sure you want to delete this certificate template?';
79+
$string['deliveryoption'] = 'Delivery option';
80+
$string['deliveryoption_help'] = 'Choose how the certificate should be delivered to users.';
7681
$string['deliveryoptiondownload'] = 'Send to the browser and force a file download';
7782
$string['deliveryoptioninline'] = 'Send the file inline to the browser';
7883
$string['deliveryoptions'] = 'Delivery options';
7984
$string['description'] = 'Description';
85+
$string['digits-with-hyphens'] = '0123-4567-8901 (Digits with hyphens)';
86+
$string['download'] = 'Force download';
8087
$string['downloadallissuedcertificates'] = 'Download all issued certificates';
8188
$string['downloadallsitecertificates'] = 'Download all site certificates';
8289
$string['downloadallsitecertificatesdesc'] = 'This will download all the certificates on the site in a zip file.';
@@ -125,6 +132,8 @@
125132
$string['eventtemplatedeleted'] = 'Custom certificate template deleted';
126133
$string['eventtemplateupdated'] = 'Custom certificate template updated';
127134
$string['exampledatawarning'] = 'Some of these values may just be an example to ensure positioning of the elements is possible.';
135+
$string['filenamepattern'] = 'File name pattern (legacy)';
136+
$string['filenamepattern_help'] = 'Choose the pattern for naming certificate files (legacy setting).';
128137
$string['font'] = 'Font';
129138
$string['font_help'] = 'The font used when generating this element.';
130139
$string['fontcolour'] = 'Colour';
@@ -137,6 +146,7 @@
137146
$string['height_help'] = 'This is the height of the certificate PDF in mm. For reference an A4 piece of paper is 297mm high and a letter is 279mm high.';
138147
$string['includeinnotvisiblecourses'] = 'Include certificates in hidden courses';
139148
$string['includeinnotvisiblecourses_desc'] = 'Certificates from hidden courses are not proccesed by default. If you want to include them, enable this setting.';
149+
$string['inline'] = 'Display inline';
140150
$string['invalidcode'] = 'Invalid code supplied.';
141151
$string['invalidcolour'] = 'Invalid colour chosen, please enter a valid HTML colour name, or a six-digit, or three-digit hexadecimal colour.';
142152
$string['invalidelementwidthorheightnotnumber'] = 'Please enter a valid number.';
@@ -241,7 +251,7 @@
241251
242252
Enabling this option may improve the performance of the scheduled task by offloading email processing to ad-hoc tasks.';
243253
$string['usecustomfilename'] = 'Use custom file name pattern';
244-
$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}.';
254+
$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}.';
245255
$string['userlanguage'] = 'Use user preferences';
246256
$string['userlanguage_help'] = 'You can force the language of the certificate to override the user\'s language preferences.';
247257
$string['verified'] = 'Verified';

mod_form.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ public function definition() {
7777
$mform->addHelpButton('customfilenamepattern', 'customfilenamepattern', 'customcert');
7878
$mform->disabledIf('customfilenamepattern', 'usecustomfilename', 'notchecked');
7979

80+
if ($this->current) {
81+
if (property_exists($this->current, 'usecustomfilename')) {
82+
$mform->setDefault('usecustomfilename', $this->current->usecustomfilename);
83+
}
84+
if (property_exists($this->current, 'customfilenamepattern')) {
85+
$mform->setDefault('customfilenamepattern', $this->current->customfilenamepattern);
86+
}
87+
}
88+
8089
if (has_capability('mod/customcert:manageemailstudents', $this->get_context())) {
8190
$mform->addElement('selectyesno', 'emailstudents', get_string('emailstudents', 'customcert'));
8291
$mform->setDefault('emailstudents', get_config('customcert', 'emailstudents'));

version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

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

27-
$plugin->version = 2024042213; // The current module version (Date: YYYYMMDDXX).
27+
$plugin->version = 2025062100; // The current module version (Date: YYYYMMDDXX).
2828
$plugin->requires = 2024042200; // Requires this Moodle version (4.4).
2929
$plugin->cron = 0; // Period for cron to check this module (secs).
3030
$plugin->component = 'mod_customcert';

0 commit comments

Comments
 (0)