@extends('layouts.template') @section('title', 'Kuesioner Soal') @section('custom_css') @endsection @section('content') @php $listHal = $daftarHal ?? collect([$hal]); $posisiAktif = $listHal->search($hal); if ($posisiAktif === false) { $posisiAktif = 0; } $totalHalaman = $totalHal ?? $listHal->count(); $progressPercentage = $totalHalaman > 0 ? round((($posisiAktif + 1) / max($totalHalaman, 1)) * 100) : 100; $halSebelumnya = $posisiAktif > 0 ? $listHal[$posisiAktif - 1] : null; $halBerikut = ($posisiAktif < $listHal->count() - 1) ? $listHal[$posisiAktif + 1] : null; $isHalTerakhir = $halBerikut === null; $formLocked = $formLocked ?? false; $prefillJawaban = $prefillJawaban ?? []; $existingJawaban = $existingJawaban ?? []; @endphp

Kuesioner

{{ $soal->judul_soal ?? 'Daftar Soal' }}

← Daftar Judul Halaman {{ $hal }}
Progres Halaman {{ $progressPercentage }}%
@if ($hal === $halPertama)
{{ $soal->judul_soal ?? '-' }}
{!! $soal->keterangan_soal !!}
@endif @if ($errors->any()) @endif @if ($formLocked)
Anda sudah mengisi kuesioner ini. Jawaban di bawah ditampilkan dalam mode baca.
@endif
Daftar Pertanyaan
Halaman {{ $hal }} dari {{ $listHal->count() }}
@csrf @php $questionCounter = 0; @endphp @forelse ($soal->soalDetail as $detail) @php $detailConfig = json_decode($detail->soal, true) ?? []; $pertanyaan = $detailConfig['soal'] ?? 'Pertanyaan tidak tersedia'; $type = $detailConfig['type'] ?? 'option'; $optionsRaw = $detailConfig['options'] ?? []; if (is_array($optionsRaw)) { $options = $optionsRaw; } elseif ($type === 'option_with_range' && is_string($optionsRaw)) { $options = [$optionsRaw]; } else { $options = []; } $autoSelect = ($type === 'option' && count($options) == 1) ? true : false; if (!is_array($options)) { $options = []; } $optionValues = collect($options)->map(function ($value) { return is_scalar($value) ? (string) $value : ''; })->all(); $existingAnswer = $existingJawaban[$detail->id] ?? null; $prefillAnswer = $prefillJawaban[$detail->id] ?? null; $hasDefaultAnswer = array_key_exists('default', $detailConfig); $defaultAnswer = $hasDefaultAnswer ? $detailConfig['default'] : null; $currentAnswer = old('jawaban.' . $detail->id, $existingAnswer ?? $prefillAnswer); if (($currentAnswer === null || $currentAnswer === '') && $hasDefaultAnswer) { $currentAnswer = $defaultAnswer; } $existingOtherAnswer = $existingAnswer && !in_array($existingAnswer, $optionValues, true) ? $existingAnswer : null; $prefillOtherAnswer = $prefillAnswer && !in_array($prefillAnswer, $optionValues, true) ? $prefillAnswer : null; $oldOtherAnswer = old('jawaban_lainnya.' . $detail->id, $existingOtherAnswer ?? $prefillOtherAnswer); $hasCurrentAnswer = $currentAnswer !== null && $currentAnswer !== ''; $isCustomCurrentAnswer = $hasCurrentAnswer && !in_array($currentAnswer, $optionValues, true); if (!$oldOtherAnswer && $isCustomCurrentAnswer) { $oldOtherAnswer = $currentAnswer; } $showLainnya = $isCustomCurrentAnswer || (is_string($currentAnswer) && stripos($currentAnswer, 'lainnya') !== false) || (!empty($oldOtherAnswer)); $detailHal = $detail->hal ?? $listHal->first(); $isVisible = $detailHal == $hal; $optionsCount = is_array($options) ? count($options) : 0; $hasLainnyaOption = collect($options)->contains(function ($optionItem) { return is_string($optionItem) && stripos($optionItem, 'lainnya') !== false; }); if (!$hasLainnyaOption && $type === 'option_with_other') { $options[] = 'Lainnya'; $optionsCount = count($options); $hasLainnyaOption = true; } $isConsentQuestion = !empty($detailConfig['persetujuan_form']); $shouldForceLainnyaSelection = $hasLainnyaOption && $showLainnya; $dualFormConfig = $detailConfig['dual_form'] ?? null; $useDualForm = $type === 'dual_form' || (!empty($dualFormConfig) && $dualFormConfig !== false); $dualYearOld = null; $dualMonthOld = null; $questionNumber = $detailConfig['no'] ?? ''; $rangeMin = null; $rangeMax = null; $rangeStep = 1; $rangeDefault = null; $rangeTicks = []; if ($useDualForm && $currentAnswer) { if (preg_match('/([0-9]+)\\s*\\(Tahun\\)/i', $currentAnswer, $matchYear)) { $dualYearOld = $matchYear[1]; } if (preg_match('/([0-9]+)\\s*\\(Bulan\\)/i', $currentAnswer, $matchMonth)) { $dualMonthOld = $matchMonth[1]; } } if ($type === 'option_with_range' && !empty($options)) { $rangeSource = $options[0]; if (is_array($rangeSource)) { $rangeSource = $rangeSource['range'] ?? (isset($rangeSource['min'], $rangeSource['max']) ? $rangeSource['min'] . '-' . $rangeSource['max'] : null); } if (is_string($rangeSource) && preg_match('/(-?[0-9]+(?:[\\.,][0-9]+)?)\\s*-\\s*(-?[0-9]+(?:[\\.,][0-9]+)?)/', $rangeSource, $rangeMatch)) { $rangeMin = (float) str_replace(',', '.', $rangeMatch[1]); $rangeMax = (float) str_replace(',', '.', $rangeMatch[2]); if ($rangeMin > $rangeMax) { [$rangeMin, $rangeMax] = [$rangeMax, $rangeMin]; } $rangeUsesDecimal = (fmod($rangeMin, 1) !== 0.0) || (fmod($rangeMax, 1) !== 0.0); $rangeStep = $rangeUsesDecimal ? 0.1 : 1; if (is_numeric($currentAnswer)) { $numericAnswer = (float) $currentAnswer; $rangeDefault = min(max($numericAnswer, $rangeMin), $rangeMax); } else { $rangeDefault = $rangeMin; } if ($rangeDefault === null) { $rangeDefault = $rangeMin; } $rangeSpan = max($rangeMax - $rangeMin, 1); $startTick = (int) ceil($rangeMin); $endTick = (int) floor($rangeMax); for ($v = $startTick; $v <= $endTick; $v++) { $position = (($v - $rangeMin) / $rangeSpan) * 100; $rangeTicks[] = [ 'value' => $v, // nilai asli 'label' => ($v === 1 || $v % 10 === 0) ? $v : null, // label hanya 1 & kelipatan 10 'position' => max(0, min(100, $position)), ]; } } } $rangeMinDisplay = ($rangeMin !== null && floor($rangeMin) == $rangeMin) ? (int) $rangeMin : $rangeMin; $rangeMaxDisplay = ($rangeMax !== null && floor($rangeMax) == $rangeMax) ? (int) $rangeMax : $rangeMax; $rangeDefaultDisplay = ($rangeDefault !== null && floor($rangeDefault) == $rangeDefault) ? (int) $rangeDefault : $rangeDefault; @endphp
@if ($questionNumber !== null) {{ $questionNumber }} @endif
{{ $pertanyaan }}
@if ($isConsentQuestion)

Pertanyaan persetujuan

@endif
@if ($useDualForm)
@elseif ($type === 'textarea') @elseif ($type === 'text') @elseif ($type === 'option_with_range') @if ($rangeMin !== null && $rangeMax !== null)
{{-- Track warna + slider --}}
Nilai saat ini: {{ $rangeDefaultDisplay ?? $rangeMinDisplay }}
Atau isi manual
@else @endif @else @if (!empty($options)) @php $lainnyaWrapperRendered = false; @endphp
@foreach ($options as $optionIndex => $option) @php $optionId = 'jawaban-' . $detail->id . '-' . $optionIndex; $optionLabel = is_scalar($option) ? (string) $option : ''; $isLainnya = stripos($optionLabel, 'lainnya') !== false; $optionValue = $isLainnya && $oldOtherAnswer ? $oldOtherAnswer : $optionLabel; $shouldCheck = $currentAnswer === $optionValue || ($isLainnya && $shouldForceLainnyaSelection); @endphp
@if ($isLainnya) @php $lainnyaWrapperRendered = true; @endphp
@endif @endforeach
@if ($hasLainnyaOption || $type === 'option_with_other') Jika jawaban yang Anda cari tidak ada di daftar, pilih opsi "Lainnya" lalu isi sesuai kebutuhan. @endif @if (!$lainnyaWrapperRendered && $type === 'option_with_other')
@endif @else @endif @endif @error('jawaban.' . $detail->id)
{{ $message }}
@enderror @error('jawaban_lainnya.' . $detail->id)
{{ $message }}
@enderror
@empty
Belum ada pertanyaan pada halaman ini.
@endforelse @error('lms_mutu_soal_id')

{{ $message }}

@enderror @error('jawaban')

{{ $message }}

@enderror
@endsection @section('custom_js') @endsection