@php
$hasRows = $data->isNotEmpty();
$cleanText = fn ($value) => Str::of(strip_tags((string) $value))->squish();
$optionsFor = function ($question) {
return collect(is_array($question->content) ? $question->content : [])
->filter(fn ($option) => is_array($option) && filled(data_get($option, 'text')))
->values();
};
$answerFor = function ($question) use ($cleanText) {
$content = is_array($question->content) ? $question->content : [];
$answer = data_get($content, 'answer')
?? data_get($content, 'answers')
?? data_get($content, 'correct_answer')
?? data_get($content, 'correctAnswer');
if (is_array($answer)) {
$answer = collect($answer)->filter(fn ($value) => filled($value))->implode(', ');
}
return filled($answer) ? $cleanText($answer) : 'N/A';
};
$hintFor = function ($question) use ($cleanText) {
$content = is_array($question->content) ? $question->content : [];
$hint = data_get($content, 'hint') ?? data_get($content, 'hints');
if (is_array($hint)) {
$hint = collect($hint)->filter(fn ($value) => filled($value))->implode(', ');
}
return filled($hint) ? $cleanText($hint) : null;
};
$hasFillMeta = function ($question) {
$content = is_array($question->content) ? $question->content : [];
return filled(data_get($content, 'answer'))
|| filled(data_get($content, 'answers'))
|| filled(data_get($content, 'correct_answer'))
|| filled(data_get($content, 'correctAnswer'))
|| filled(data_get($content, 'hint'))
|| filled(data_get($content, 'hints'));
};
$isMultiChoice = fn ($question) => Str::contains((string) $question->type, ['multi', 'checkbox']);
$isSingleChoice = fn ($question) => Str::contains((string) $question->type, ['single', 'radio']);
$isFillBlank = fn ($question) => Str::contains((string) $question->type, ['fill', 'blank']);
@endphp
@if($hasRows)
@foreach($data as $item)
| {{ ($data->currentPage() - 1) * $data->perPage() + $loop->iteration }} |
@endforeach
@foreach($data as $item)
@php
$children = $item->relationLoaded('children') ? $item->children : collect();
$options = $optionsFor($item);
$isScenario = $children->isNotEmpty();
$showFillAnswer = !$isScenario && ($isFillBlank($item) || ($options->isEmpty() && $hasFillMeta($item)));
@endphp
{{ ($data->currentPage() - 1) * $data->perPage() + $loop->iteration }}.
@php
$questionText = $cleanText($item->question);
$isLong = Str::length($questionText) > 100;
@endphp
@if($isLong)
{{ Str::limit($questionText, 100) }}
{{ $questionText }}
@else
{{ $questionText }}
@endif
@if($isScenario)
@foreach($children as $child)
@php
$childOptions = $optionsFor($child);
$childIsMultiChoice = $isMultiChoice($child) || $childOptions->filter(fn ($option) => filter_var(data_get($option, 'is_correct'), FILTER_VALIDATE_BOOLEAN))->count() > 1;
@endphp
{{ ($data->currentPage() - 1) * $data->perPage() + $loop->parent->iteration }}.{{ $loop->iteration }} {{ $cleanText($child->question) }}
@if($childOptions->isNotEmpty())
@foreach($childOptions as $option)
@php
$isCorrect = filter_var(data_get($option, 'is_correct'), FILTER_VALIDATE_BOOLEAN);
@endphp
@include('pages.admin.question.partials.option-marker', [
'checked' => $isCorrect,
'shape' => 'checkbox',
])
{{ $cleanText(data_get($option, 'text')) }}
@endforeach
@elseif($isFillBlank($child))
Answer - {{ $answerFor($child) }}
@if($hintFor($child))
Hint - {{ $hintFor($child) }}
@endif
@endif
@endforeach
@elseif($options->isNotEmpty())
@php
$useCheckbox = $isMultiChoice($item) || $options->filter(fn ($option) => filter_var(data_get($option, 'is_correct'), FILTER_VALIDATE_BOOLEAN))->count() > 1;
@endphp
@foreach($options as $option)
@php
$isCorrect = filter_var(data_get($option, 'is_correct'), FILTER_VALIDATE_BOOLEAN);
@endphp
@include('pages.admin.question.partials.option-marker', [
'checked' => $isCorrect,
'shape' => 'checkbox',
])
{{ $cleanText(data_get($option, 'text')) }}
@endforeach
@elseif($showFillAnswer)
Answer - {{ $answerFor($item) }}
@if($hintFor($item))
Hint - {{ $hintFor($item) }}
@endif
@endif
@endforeach
@endif
@if($data->isEmpty() && ($totalQuestions ?? 0) > 0)
{{ __('pages/admin/question.no_data_available.title') }}
{{ __('pages/admin/question.no_results_filtered') }}
{{ __('buttons.filter.clear') }}
@endif
{{ $data->links('components.ajax-pagination') }}