@foreach ($components as $component) @php $type = $component['type'] ?? ''; @endphp @if($type === 'columns' && isset($component['columns']) && is_array($component['columns'])) {{-- Handle columns layout: each column has its own components --}} @foreach ($component['columns'] as $column) @if(isset($column['components']) && is_array($column['components'])) @include('backend.form_builder.pdf.components', ['components' => $column['components']]) @endif @endforeach @elseif($type === 'table' && isset($component['rows']) && is_array($component['rows'])) {{-- Handle table layout: rows > cells > components --}} @foreach ($component['rows'] as $row) @foreach ($row as $cell) @if(isset($cell['components']) && is_array($cell['components'])) @include('backend.form_builder.pdf.components', ['components' => $cell['components']]) @endif @endforeach @endforeach @elseif($type === 'container' && isset($component['components']) && is_array($component['components'])) {{-- Container: submission data is nested under the container key --}} @php $containerKey = $component['key'] ?? ''; $containerData = $submissionData[$containerKey] ?? []; @endphp @if(!empty($containerData) && is_array($containerData)) @include('backend.form_builder.pdf.components', [ 'components' => $component['components'], 'submissionData' => $containerData, ]) @endif @elseif($type === 'tabs' && isset($component['components']) && is_array($component['components'])) {{-- Tabs: each tab has its own components array --}} @foreach ($component['components'] as $tab) @if(isset($tab['components']) && is_array($tab['components'])) @include('backend.form_builder.pdf.components', ['components' => $tab['components']]) @endif @endforeach @elseif(isset($component['components']) && is_array($component['components'])) {{-- Recursively handle nested components (panels, fieldsets, wells, etc.) --}} @include('backend.form_builder.pdf.components', ['components' => $component['components']]) @else @php $key = $component['key'] ?? ''; $value = $submissionData[$key] ?? ''; $type = $component['type'] ?? ''; $label = $component['label'] ?? ucfirst($key); $isButton = $type === 'button'; @endphp @if (!empty($key) && isset($submissionData[$key]) && !$isButton) {{ $label }} @if ($type === 'survey') @php // Survey data is stored as an array of [question => value] if (is_array($value)) { echo implode('
', array_map( function($q, $a) { return "$q: " . (is_array($a) ? implode(', ', $a) : $a); }, array_keys($value), $value )); } else { echo $value; // Fallback if not an array } @endphp @elseif ($type === 'file') {{-- File Handling - Show download links instead of embedding to avoid MPDF limits --}} @if (is_array($value) && !isset($value['url'])) @php $fileIndex = 0; $totalFiles = count($value); @endphp @foreach ($value as $file) @php $displayName = $totalFiles > 1 ? 'Download File ' . ($fileIndex + 1) : 'Download File'; $downloadUrl = isset($submissionId) ? route('submissions.download_attachment', ['id' => $submissionId, 'field' => $key, 'index' => $fileIndex]) : ($file['url'] ?? '#'); @endphp {{ $displayName }}
@php $fileIndex++; @endphp @endforeach @else @php $downloadUrl = isset($submissionId) ? route('submissions.download_attachment', ['id' => $submissionId, 'field' => $key, 'index' => 0]) : ($value['url'] ?? '#'); @endphp Download File @endif @elseif ($type === 'signature') {{-- Handle Signature Pad Image --}} @if (!empty($value)) @php // Ensure the value is a proper data URL $imageSrc = strpos($value, 'data:image') === 0 ? $value : 'data:image/png;base64,' . $value; @endphp @endif @elseif ($type === 'checkbox' || ($type === 'select' && ($component['multiple'] ?? false))) {{-- Checkbox or Multi-Select --}} @php $values = is_array($value) ? $value : [$value]; $labels = []; foreach ($values as $val) { $labels[] = Helper::getFormioLabelFromValue($val, $component); } echo implode(', ', $labels); @endphp @elseif ($type === 'selectboxes') {{-- Select Boxes (checkboxes stored as object) --}} @php $selected = is_array($value) || is_object($value) ? array_keys(array_filter((array)$value)) : []; $labels = []; foreach ($selected as $val) { $labels[] = Helper::getFormioLabelFromValue($val, $component); } echo implode(', ', $labels); @endphp @elseif (($type === 'radio' || $type === 'select') && isset($component['data']['values'])) {{-- For radio or single select fields, display the label from the definition --}} {!! Helper::getFormioLabelFromValue($value, $component) !!} @elseif ($type === 'datagrid' && is_array($value)) {{-- DataGrid Table --}} @foreach ($component['components'] ?? [] as $col) @endforeach @foreach ($value as $row) @foreach ($component['components'] ?? [] as $col) @php $colKey = $col['key'] ?? ''; $colVal = $row[$colKey] ?? ''; $colType = $col['type'] ?? ''; @endphp @endforeach @endforeach
{{ $col['label'] ?? $col['key'] }}
@if($colType === 'checkbox' || ($colType === 'select' && ($col['multiple'] ?? false))) @php $colValues = is_array($colVal) ? $colVal : [$colVal]; $colLabels = []; foreach ($colValues as $val) { $colLabels[] = Helper::getFormioLabelFromValue($val, $col); } echo implode(', ', $colLabels); @endphp @elseif($colType === 'selectboxes') @php $selectedCol = is_array($colVal) || is_object($colVal) ? array_keys(array_filter((array)$colVal)) : []; $colLabels = []; foreach ($selectedCol as $val) { $colLabels[] = Helper::getFormioLabelFromValue($val, $col); } echo implode(', ', $colLabels); @endphp @elseif($colType === 'textarea') {!! nl2br(e($colVal)) !!} @else {!! $colVal !!} @endif
@elseif ($type === 'editgrid' && is_array($value)) {{-- EditGrid Table (same rendering as DataGrid) --}} @foreach ($component['components'] ?? [] as $col) @endforeach @foreach ($value as $row) @foreach ($component['components'] ?? [] as $col) @php $colKey = $col['key'] ?? ''; $colVal = $row[$colKey] ?? ''; $colType = $col['type'] ?? ''; @endphp @endforeach @endforeach
{{ $col['label'] ?? $col['key'] }}
@if($colType === 'checkbox' || ($colType === 'select' && ($col['multiple'] ?? false))) @php $colValues = is_array($colVal) ? $colVal : [$colVal]; $colLabels = []; foreach ($colValues as $val) { $colLabels[] = Helper::getFormioLabelFromValue($val, $col); } echo implode(', ', $colLabels); @endphp @elseif($colType === 'selectboxes') @php $selectedCol = is_array($colVal) || is_object($colVal) ? array_keys(array_filter((array)$colVal)) : []; $colLabels = []; foreach ($selectedCol as $val) { $colLabels[] = Helper::getFormioLabelFromValue($val, $col); } echo implode(', ', $colLabels); @endphp @elseif($colType === 'textarea') {!! nl2br(e($colVal)) !!} @elseif($colType === 'file' && is_array($colVal)) @foreach ($colVal as $colFile) {{ $colFile['name'] ?? 'File' }}
@endforeach @else {!! is_array($colVal) ? e(json_encode($colVal)) : $colVal !!} @endif
@elseif (in_array($type, ['datetime', 'time'])) {{-- DateTime / Time - Format nicely --}} @php try { $formatted = \Carbon\Carbon::parse($value)->format('d-m-Y h:i A'); if ($type === 'time') { $formatted = \Carbon\Carbon::parse($value)->format('h:i A'); } } catch (\Exception $e) { $formatted = $value; } @endphp {{ $formatted }} @elseif ($type === 'day') {{-- Day component - stored as DD/MM/YYYY or similar --}} @php try { $formatted = \Carbon\Carbon::parse($value)->format('d-m-Y'); } catch (\Exception $e) { $formatted = $value; } @endphp {{ $formatted }} @elseif ($type === 'address') {{-- Address component - display formatted address --}} @php if (is_array($value)) { $formattedAddress = $value['formatted_address'] ?? $value['address'] ?? implode(', ', array_filter([ $value['address1'] ?? '', $value['address2'] ?? '', $value['city'] ?? '', $value['state'] ?? '', $value['zip'] ?? $value['postcode'] ?? '', $value['country'] ?? '', ])); echo e($formattedAddress); } else { echo e($value); } @endphp @elseif ($type === 'currency' || $type === 'number') {{-- Number/Currency --}} @php if ($type === 'currency') { $prefix = $component['prefix'] ?? '$'; echo e($prefix . number_format((float)$value, 2)); } else { echo e($value); } @endphp @elseif ($type === 'textarea') {!! nl2br(e($value)) !!} @else {!! $value !!} @endif @endif @endif @endforeach