@php if (!function_exists('get_cert_data_print')) { function get_cert_data_print($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 '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')) : '-'; default: $customData = $peserta->custom_data ?? []; if (isset($customData[$key])) return $customData[$key]; $additionalData = $profile->additional_data ?? []; if (isset($additionalData[$key])) return $additionalData[$key]; return null; } } } if (!function_exists('image_to_base64_print')) { function image_to_base64_print($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 = $paper ?? 'A4'; $orientation = $orientation ?? 'landscape'; $widthCmCert = (float) data_get($certificateSetting, 'page.width_cm', 29.7); $heightCmCert = (float) data_get($certificateSetting, 'page.height_cm', 21); $pxPerCmDesigner = (float) data_get($certificateSetting, 'page.px_per_cm', 37.795); if ($pxPerCmDesigner <= 0) $pxPerCmDesigner = 37.795; $certificatesPerPage = max(1, (int)($cols * $rows)); @endphp
@foreach($participants->chunk($certificatesPerPage) as $pageIndex => $pageData) @if($pageIndex > 0)
@endif
@foreach($pageData as $peserta)
@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_print($path); break; } } } } @endphp @if($bgUrl) BG @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'); $value = ''; if ($dataKey === 'qr' || $dataKey === 'qr_code') { $qrValue = route('activity.verify-certificate', ['id' => $activity->id]) . '?certificate_id=' . urlencode((string) ($peserta->certificate_id ?? '')); } else { $value = get_cert_data_print($peserta, $dataKey, $activity); if ($value === null && isset($config['text'])) $value = $config['text']; } $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