44
55use Carbon \Carbon ;
66use Illuminate \Support \Facades \Storage ;
7+ use Illuminate \Support \Str ;
78use Log ;
89use Symfony \Component \Process \Exception \ProcessFailedException ;
910use 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 /**
0 commit comments