Skip to content

Commit 2c57067

Browse files
authored
Merge pull request #3283 from codeeu/dev
cert generator backend
2 parents 41641c8 + 8755a9c commit 2c57067

17 files changed

+1015
-13
lines changed

app/CertificateExcellence.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Carbon\Carbon;
66
use Illuminate\Support\Facades\Storage;
7+
use Illuminate\Support\Str;
78
use Log;
89
use Symfony\Component\Process\Exception\ProcessFailedException;
910
use Symfony\Component\Process\Process;
@@ -22,22 +23,32 @@ class CertificateExcellence
2223
private $number_of_activities;
2324
private $type;
2425

25-
public function __construct($edition, $name_for_certificate, $type = 'excellence', $number_of_activities = 0)
26+
/**
27+
* @param int $edition e.g. 2025
28+
* @param string $name_for_certificate
29+
* @param string $type 'excellence' or 'super-organiser'
30+
* @param int $number_of_activities For super-organiser only
31+
* @param int|null $user_id When set (backend generation), used for unique filenames instead of auth
32+
* @param string|null $user_email When set (backend generation), used in template instead of auth user
33+
*/
34+
public function __construct($edition, $name_for_certificate, $type = 'excellence', $number_of_activities = 0, $user_id = null, $user_email = null)
2635
{
2736
$this->edition = $edition;
2837
$this->name_of_certificate_holder = $name_for_certificate;
29-
$this->email_of_certificate_holder = auth()->user()->email ?? '';
30-
$this->personalized_template_name = $edition . '-' . auth()->id();
38+
$this->email_of_certificate_holder = $user_email ?? (auth()->check() ? (auth()->user()->email ?? '') : '');
39+
$effectiveUserId = $user_id ?? (auth()->check() ? auth()->id() : 0);
40+
$random = Str::random(10);
41+
$this->personalized_template_name = $edition . '-' . $effectiveUserId . '-' . $random;
3142
$this->resource_path = resource_path() . '/latex';
3243
$this->pdflatex = config('codeweek.pdflatex_path');
33-
$this->id = auth()->id() . '-' . str_random(10);
44+
$this->id = $effectiveUserId . '-' . $random;
3445
$this->number_of_activities = $number_of_activities;
3546
$this->type = $type ?: 'excellence';
3647

3748
// e.g. "excellence-2025.tex" or "super-organiser-2025.tex"
3849
$this->templateName = "{$this->type}-{$this->edition}.tex";
3950

40-
Log::info('User ID ' . auth()->id() . " generating {$this->type} certificate with name: " . $name_for_certificate);
51+
Log::info('Generating ' . $this->type . ' certificate for user_id ' . $effectiveUserId . ' with name: ' . $name_for_certificate);
4152
}
4253

4354
/**

app/Excellence.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ class Excellence extends Model
5050
'type',
5151
'name_for_certificate',
5252
'certificate_url',
53+
'certificate_generation_error',
5354
'notified_at',
55+
'certificate_sent_error',
5456
];
5557

5658
/**

0 commit comments

Comments
 (0)