@php // Helper function for user data if (!function_exists('get_cert_data')) { function get_cert_data($peserta, $key, $activity) { $user = optional($peserta->user); $profile = optional($user->profile); switch($key) { case 'name': return $user->name ?? '-'; case 'email': return $user->email ?? '-'; case 'certificate_id': return $peserta->certificate_id ?? '-'; case 'no_hp': return $profile->no_hp ?? '-'; case 'nik': return $profile->nik ?? '-'; case 'pekerjaan': return $profile->pekerjaan ?? '-'; case 'instansi': return $profile->instansi ?? '-'; case 'jabatan': return $profile->jabatan ?? '-'; case 'alamat': return $profile->alamat ?? '-'; case 'jenis_kelamin': return $profile->jenis_kelamin ?? '-'; case 'birth_place': return $profile->birth_place ?? '-'; case 'birth_date': return $profile->birth_date ? (is_string($profile->birth_date) ? $profile->birth_date : $profile->birth_date->format('d-m-Y')) : '-'; case 'province': return optional($profile->province)->name ?? $profile->other_province ?? '-'; case 'regency': return optional($profile->regency)->name ?? $profile->other_regency ?? '-'; case 'district': return optional($profile->district)->name ?? $profile->other_district ?? '-'; default: // Check custom data $customData = $peserta->custom_data ?? []; if (isset($customData[$key])) return $customData[$key]; // Fallback to profile additional data $additionalData = $profile->additional_data ?? []; if (isset($additionalData[$key])) return $additionalData[$key]; return null; } } } if (!function_exists('image_to_base64')) { function image_to_base64($path) { if (!file_exists($path) || !is_readable($path)) return null; $type = mime_content_type($path); $data = file_get_contents($path); return 'data:' . $type . ';base64,' . base64_encode($data); } } $paper = data_get($printSettings, 'paper', 'A4'); $orientation = data_get($printSettings, 'orientation', 'landscape'); $widthCmPage = 21; $heightCmPage = 29.7; if ($paper === 'A4') { $widthCmPage = 21; $heightCmPage = 29.7; } elseif ($paper === 'A3') { $widthCmPage = 29.7; $heightCmPage = 42; } elseif ($paper === 'F4') { $widthCmPage = 21.5; $heightCmPage = 33; } elseif ($paper === 'IDCARD') { $widthCmPage = 5.398; $heightCmPage = 8.56; } if ($orientation === 'landscape') { $tmp = $widthCmPage; $widthCmPage = $heightCmPage; $heightCmPage = $tmp; } $widthCmCert = (float) data_get($certificateSetting, 'page.width_cm', 29.7); $heightCmCert = (float) data_get($certificateSetting, 'page.height_cm', 21); // Scale factor between designer and final print $pxPerCmDesigner = (float) data_get($certificateSetting, 'page.px_per_cm', 37.795); if ($pxPerCmDesigner <= 0) $pxPerCmDesigner = 37.795; // How many certs per page $certificatesPerPage = max(1, (int)($cols * $rows)); @endphp @if(!empty($showHero))
{{ $activity->name ?? 'Sertifikat' }}
{{ $activity->location }} | {{ $activity->date }}
@endif @if(empty($showHero))
Verifikasi Sertifikat
@php $p = $participants->first(); @endphp @if($p) {{ optional($p->user)->name }} | ID: {{ $p->certificate_id }} @else Sertifikat tidak valid @endif
@endif
Download / Cetak Sertifikat
@foreach($participants->chunk($certificatesPerPage) as $pageIndex => $pageData) @if($pageIndex > 0)
@endif
@foreach($pageData as $peserta)
{{-- Background --}} @php $bgFile = data_get($certificateSetting, 'page.background'); $bgUrl = null; if ($bgFile) { if (str_starts_with($bgFile, 'http')) $bgUrl = $bgFile; else { $possiblePaths = [ public_path('storage/' . $bgFile), public_path('assets/images/certificate/' . $bgFile), public_path('assets/images/certificate/background/default/' . $bgFile) ]; foreach($possiblePaths as $path) { if (file_exists($path)) { $bgUrl = image_to_base64($path); break; } } } } // Default fallback if no background if (!$bgUrl) { $defaultDir = public_path('assets/images/certificate/background/default'); if (is_dir($defaultDir)) { $files = glob($defaultDir . '/*.{png,jpg,jpeg,webp}', GLOB_BRACE); if (!empty($files)) $bgUrl = image_to_base64($files[0]); } } @endphp @if($bgUrl)
@endif
@foreach($certificateSetting as $key => $config) @if($key === 'page' || $key === 'card' || !is_array($config) || !data_get($config, 'visible', true)) @continue @endif @php $dataKey = data_get($config, 'data_key'); $fieldType = data_get($config, 'fieldType'); $value = ''; if ($dataKey === 'qr' || $dataKey === 'qr_code') { $qrValue = route('activity.verify-certificate', ['id' => $activity->id]) . '?certificate_id=' . urlencode((string) ($peserta->certificate_id ?? '')); $value = 'QR'; // Placeholder } else { $value = get_cert_data($peserta, $dataKey, $activity); if ($value === null && isset($config['text'])) $value = $config['text']; } // Scale positions from px to final cm $left = (float)data_get($config, 'left', 0) / $pxPerCmDesigner; $top = (float)data_get($config, 'top', 0) / $pxPerCmDesigner; $width = (float)data_get($config, 'width', 100) / $pxPerCmDesigner; $height = (float)data_get($config, 'height', 40) / $pxPerCmDesigner; $fontSize = (float)data_get($config, 'size', 16) / $pxPerCmDesigner; @endphp
@if($dataKey === 'qr' || $dataKey === 'qr_code')
{!! QrCode::size(500)->format('svg')->generate($qrValue) !!}
@else {!! nl2br(e($value)) !!} @endif
@endforeach
@endforeach
@endforeach