40 lines
1.4 KiB
PHP
40 lines
1.4 KiB
PHP
@php
|
|
$byCode = [];
|
|
foreach ($questions ?? [] as $question) {
|
|
if (isset($question->code)) {
|
|
$byCode[$question->code] = $question;
|
|
}
|
|
}
|
|
$submitted = $submitted_formdata ?? null;
|
|
$val = function ($code) use ($byCode, $submitted) {
|
|
if (is_object($submitted) && isset($submitted->{$code}) && $submitted->{$code} !== '' && $submitted->{$code} !== null) {
|
|
return $submitted->{$code};
|
|
}
|
|
if (is_array($submitted) && isset($submitted[$code]) && $submitted[$code] !== '' && $submitted[$code] !== null) {
|
|
return $submitted[$code];
|
|
}
|
|
if (isset($byCode[$code]->value) && $byCode[$code]->value !== '' && $byCode[$code]->value !== null) {
|
|
return $byCode[$code]->value;
|
|
}
|
|
return '';
|
|
};
|
|
$show = function ($code) use ($val) {
|
|
$value = $val($code);
|
|
return $value !== '' && $value !== null ? $value : '—';
|
|
};
|
|
$fileUrl = function ($url) {
|
|
$url = trim((string) $url);
|
|
if ($url === '') {
|
|
return '';
|
|
}
|
|
if (!preg_match('#^https?://#i', $url)) {
|
|
return rtrim((string) env('AWS_URL'), '/') . '/' . ltrim($url, '/');
|
|
}
|
|
return $url;
|
|
};
|
|
$isImageUrl = function ($url) {
|
|
$ext = strtolower(pathinfo((string) parse_url($url, PHP_URL_PATH), PATHINFO_EXTENSION));
|
|
return in_array($ext, ['jpg', 'jpeg', 'png', 'gif', 'webp'], true);
|
|
};
|
|
@endphp
|