major update

This commit is contained in:
2026-03-04 15:56:58 +01:00
parent 16759a2732
commit 8f4dd5840d
478 changed files with 24313 additions and 8201 deletions

View File

@@ -6,24 +6,30 @@ use Dompdf\Dompdf;
use Dompdf\Options;
use Endroid\QrCode\QrCode;
use Endroid\QrCode\Writer\PngWriter;
use MintyPHP\Service\Branding\BrandingServicesFactory;
use MintyPHP\Service\Branding\BrandingLogoService;
use Throwable;
use ZipArchive;
class UserAccessPdfService
{
public function __construct(
private readonly UserAccessTemplateService $userAccessTemplateService,
private readonly BrandingLogoService $brandingLogoService
) {
}
// Returns PDF bytes for one user; empty string means rendering failed.
public static function renderUserAccessPdf(array $user): string
public function renderUserAccessPdf(array $user): string
{
if (!class_exists(Dompdf::class) || !class_exists(Options::class)) {
return '';
}
$context = UserAccessTemplateService::buildContext($user);
$context = $this->userAccessTemplateService->buildContext($user);
$locale = (string) ($context['locale'] ?? '');
$vars = is_array($context['vars'] ?? null) ? $context['vars'] : [];
$vars['pdf_title'] = self::buildPdfTitle($locale);
$vars['app_logo_url'] = self::resolveLogoDataUri();
$vars['app_logo_url'] = $this->resolveLogoDataUri();
$vars['login_qr_data_uri'] = self::buildLoginQrDataUri((string) ($vars['login_url'] ?? ''));
$vars['generated_at'] = gmdate('Y-m-d H:i:s') . ' UTC';
@@ -49,7 +55,7 @@ class UserAccessPdfService
// Creates one PDF per user and packs them into a temp ZIP file.
// Caller is responsible for deleting the returned ZIP path after download.
public static function renderUsersAccessZip(array $users): array
public function renderUsersAccessZip(array $users): array
{
if (!class_exists(ZipArchive::class) || !$users) {
return ['path' => '', 'filename' => '', 'count' => 0];
@@ -72,7 +78,7 @@ class UserAccessPdfService
if (!is_array($user)) {
continue;
}
$pdf = self::renderUserAccessPdf($user);
$pdf = $this->renderUserAccessPdf($user);
if ($pdf === '') {
continue;
}
@@ -163,18 +169,17 @@ class UserAccessPdfService
return $html;
}
private static function resolveLogoDataUri(): string
private function resolveLogoDataUri(): string
{
$path = '';
$mime = '';
$logoService = (new BrandingServicesFactory())->createBrandingLogoService();
// Prefer tenant/app branding logo first.
if ($logoService->hasLogo()) {
$logoPath = $logoService->findLogoPath(128);
if ($this->brandingLogoService->hasLogo()) {
$logoPath = $this->brandingLogoService->findLogoPath(128);
if ($logoPath && is_file($logoPath)) {
$path = $logoPath;
$mime = $logoService->detectMime($logoPath);
$mime = $this->brandingLogoService->detectMime($logoPath);
}
}