Visitor management app with SSO, kiosk, badges, reports, and Gitea CI deploy to frontdesk.ladill.com. Co-authored-by: Cursor <cursoragent@cursor.com>
44 lines
1.3 KiB
PHP
44 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Frontdesk;
|
|
|
|
use App\Models\Organization;
|
|
use App\Models\Visit;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class BadgeRenderService
|
|
{
|
|
public function __construct(
|
|
protected QrCodeService $qrCodes,
|
|
) {}
|
|
|
|
/** @return array<string, mixed> */
|
|
public function templateFor(Organization $organization): array
|
|
{
|
|
return array_merge(config('frontdesk.default_badge_template', []), $organization->settings['badge_template'] ?? []);
|
|
}
|
|
|
|
public function renderHtml(Visit $visit, bool $autoPrint = false): string
|
|
{
|
|
$visit->load(['visitor', 'host', 'organization']);
|
|
|
|
return view('frontdesk.badges.render', [
|
|
'visit' => $visit,
|
|
'template' => $this->templateFor($visit->organization),
|
|
'photoUrl' => $this->photoUrl($visit),
|
|
'qrSvg' => $visit->qr_token ? $this->qrCodes->svg($visit, 120) : null,
|
|
'autoPrint' => $autoPrint,
|
|
'preview' => false,
|
|
])->render();
|
|
}
|
|
|
|
public function photoUrl(Visit $visit): ?string
|
|
{
|
|
$path = $visit->photo_path ?? $visit->visitor?->photo_path;
|
|
|
|
return $path && Storage::disk('public')->exists($path)
|
|
? Storage::disk('public')->url($path)
|
|
: null;
|
|
}
|
|
}
|