@php
$labCategoryPackageId = null;
if($questionsWithAnswers && $questionsWithAnswers->isNotEmpty() && $questionsWithAnswers->first() && isset($questionsWithAnswers->first()->LAB_CATEGORY_PACKAGE_ID)) {
$labCategoryPackageId = $questionsWithAnswers->first()->LAB_CATEGORY_PACKAGE_ID;
}
$questionnaire = null;
if($labCategoryPackageId) {
$questionnaire = \App\Models\PROFILEQUESTIONNAIRE::withoutGlobalScope('isDeleted')->where('TEST_IDS', 'LIKE', '%' . $labCategoryPackageId . '%')
->where('PROFILE_ID', session('profile_id'))
->first();
}
$questionsByCategory = collect();
if($questionsWithAnswers) {
$questionsByCategory = $questionsWithAnswers->groupBy(function($item) use ($lang) {
$catName = $item->question && isset($item->question->category) ? $item->question->category->NAME_EN : 'General Information';
if (isset($lang) && $lang === 'ar') {
$arName = $item->question && isset($item->question->category) ? ($item->question->category->NAME_AR ?: $item->question->category->NAME_EN) : 'معلومات عامة';
return $arName;
}
return $catName;
})->sortBy(function($questions, $categoryName) {
return $categoryName === 'General Information' || $categoryName === 'معلومات عامة' ? 0 : 1;
});
}
@endphp
@if ($questionnaire)
@endif
@foreach($questionsByCategory as $categoryName => $questions)
{{ isset($lang) && $lang === 'ar' ? ($questionnaire->NAME_AR ?: $questionnaire->NAME_EN) : $questionnaire->NAME_EN }}
Generated: {{ date('Y-m-d H:i:s') }}
@if ($categoryName !== 'General Information')
@endif
@php $count = 0; @endphp
@foreach($questions as $key => $questionAnswer)
@php
// Check if this is a SELECT or MULTIPLE_SELECT with more than 2 options
$isWideQuestion = false;
if (isset($questionAnswer->question) && $questionAnswer->question &&
($questionAnswer->question->TYPE == 'SELECT' || $questionAnswer->question->TYPE == 'MULTIPLE_SELECT')) {
$optionsCount = isset($questionAnswer->question->options) ? $questionAnswer->question->options->count() : 0;
$isWideQuestion = ($optionsCount > 2);
}
// Start a new row if needed
if ($count % 2 == 0 || $isWideQuestion) {
echo '
@endforeach
@if(isset($questionAnswer->question) && $questionAnswer->question && ($questionAnswer->question->TYPE == 'SELECT' || $questionAnswer->question->TYPE == 'MULTIPLE_SELECT'))
@php
$selectedOptionIds = [];
if (!empty($questionAnswer->OPTION_ID)) {
$selectedOptionIds = is_array($questionAnswer->OPTION_ID)
? $questionAnswer->OPTION_ID
: json_decode($questionAnswer->OPTION_ID, true) ?? [];
} elseif (!empty($questionAnswer->ANSWER)) {
$selectedOptionIds = explode(',', $questionAnswer->ANSWER);
}
$allOptions = isset($questionAnswer->question) && $questionAnswer->question && isset($questionAnswer->question->options) ? $questionAnswer->question->options : collect();
$optionsCount = $allOptions->count();
@endphp
@php $hasSelectedOption = false; @endphp
@if($optionsCount > 0)
@foreach($allOptions->chunk(3) as $optionChunk)
@if(!$hasSelectedOption)
@foreach($optionChunk as $option)
@php
$isSelected = in_array($option->ID, $selectedOptionIds)
|| in_array($option->NAME_EN, $selectedOptionIds);
if ($isSelected) {
$hasSelectedOption = true;
}
@endphp
@if($isSelected)
@endforeach
{{ isset($lang) && $lang === 'ar' ? ($option->NAME_AR ?: $option->NAME_EN) : $option->NAME_EN }}
@endif
@endforeach
No answer provided
@endif
@else
No options available
@endif
@elseif(isset($questionAnswer->question) && $questionAnswer->question && $questionAnswer->question->TYPE == 'FILE')
@if(!empty($questionAnswer->ANSWER) && str_starts_with($questionAnswer->ANSWER, '/'))
@php
$attachments = explode(',', $questionAnswer->ANSWER);
@endphp
@foreach($attachments as $attachment)
@if(str_starts_with($attachment, '/'))
@php
$fileExtension = strtolower(pathinfo($attachment, PATHINFO_EXTENSION));
$isImage = in_array($fileExtension, ['jpg', 'jpeg', 'png', 'gif']);
$fileName = str_replace('/reservations-questionnaire-attachment/', '', $attachment);
@endphp
@if($isImage)
{{ $fileName }}
No files attached
@endif
@elseif(isset($questionAnswer->question) && $questionAnswer->question && $questionAnswer->question->TYPE == 'DOWNLOAD_FILE')
@if(isset($questionAnswer->question) && $questionAnswer->question && !empty($questionAnswer->question->FILE_PATH))
@php
$fileUrl = 'https://s3.eu-west-1.amazonaws.com/blazma.com' . $questionAnswer->question->FILE_PATH;
$fileExt = strtolower(pathinfo($questionAnswer->question->FILE_PATH, PATHINFO_EXTENSION));
@endphp
@if(in_array($fileExt, ['jpg', 'jpeg', 'png', 'gif']))
No file available
@endif
@elseif(!empty($questionAnswer->ANSWER))
{{ $questionAnswer->ANSWER }}
@else
No answer provided
@endif
|
@php
// Increment count
$count++;
// If it's a wide question, start a new row after it
if ($isWideQuestion) {
$count = $count % 2 == 0 ? $count : $count + 1;
echo '@endif |