Rekapitulasi Jawaban Pertanyaan Radio
@php
$totalResponses = $responses->count();
@endphp
@foreach($questions as $qIdx => $question)
@if($question->question_type === 'radio')
{{ $question->question_text }}
| Pilihan |
Jumlah |
Persentase |
@php
$optionCounts = array_fill_keys($question->options_array, 0);
foreach($responses as $response) {
$answers = is_array($response->answers) ? $response->answers : json_decode($response->answers, true);
$ans = $answers[$question->id] ?? null;
if($ans !== null && isset($optionCounts[$ans])) {
$optionCounts[$ans]++;
}
}
@endphp
@foreach($question->options_array as $option)
| {{ $option }} |
{{ $optionCounts[$option] }} |
@if($totalResponses > 0)
{{ number_format(($optionCounts[$option] / $totalResponses) * 100, 1) }}%
@else
0%
@endif
|
@endforeach
Total Responden: {{ $totalResponses }}
@endif
@endforeach
@if($questions->where('question_type', 'radio')->count() === 0)
Tidak ada pertanyaan radio pada survey ini.
@endif
Jawaban Lainnya
@foreach($questions as $question)
@if(in_array($question->question_type, ['checkbox', 'text']))
{{ $question->question_text }}
@php
$allAnswers = [];
foreach($responses as $response) {
$answers = is_array($response->answers) ? $response->answers : json_decode($response->answers, true);
$ans = $answers[$question->id] ?? null;
if($ans !== null) {
if($question->question_type === 'checkbox' && is_array($ans)) {
foreach($ans as $item) {
$allAnswers[] = $item;
}
} else {
$allAnswers[] = $ans;
}
}
}
@endphp
@forelse($allAnswers as $ans)
- {{ $ans }}
@empty
- Belum ada jawaban
@endforelse
@endif
@endforeach
@if($questions->whereIn('question_type', ['checkbox','text'])->count() === 0)
Tidak ada pertanyaan checkbox atau text pada survey ini.
@endif