@csrf @php $stepCount = 1; @endphp
{{ $topicCount }}. {{ $courseTopic->topic->title }}
@php // Collect all statuses (include $status2 only if has video) $statuses = [$status1, $status3]; if ($hasVideo) $statuses[] = $status2; // Decide module status if ($status1 === 'inprogress') { $moduleStatus = 'In Progress'; } elseif (count(array_unique($statuses)) === 1 && $statuses[0] === 'pending') { $moduleStatus = 'Pending'; } elseif (count(array_unique($statuses)) === 1 && $statuses[0] === 'complete') { $moduleStatus = 'Completed'; } else { $moduleStatus = 'In Progress'; } @endphp

Module {{ $moduleStatus }}

{{-- STEP 1: READ BOOK --}} @php $topicPdfs = $courseTopic->topic->pdfs->sortBy(fn($p) => $p->sequence_number ?? 0)->values(); $totalPdfs = $topicPdfs->count(); $hasPdfs = $totalPdfs > 0; $statusRow = \App\Models\CoursePurchasedTopicStatus::where('course_purchase_id', $checkCoursePurchase->id) ->where('topic_id', $courseTopic->topic->id) ->where('type', 'read_book') ->first(); $pdfDetails = $statusRow && $statusRow->topic_pdfs_details ? json_decode($statusRow->topic_pdfs_details, true) : []; $completedCount = collect($pdfDetails) ->filter(function ($status) { return $status === 'completed'; }) ->count(); $allPdfsRead = $completedCount >= $totalPdfs; @endphp {{-- @if($totalPdfs > 0) --}} @php $stepCount++; @endphp {{-- @endif --}} @foreach($topicPdfs as $index => $topicPdf) @php $pdfState = $pdfDetails[$topicPdf->id] ?? null; // null | reading | completed $isReading = $pdfState === 'reading'; $isCompleted = $pdfState === 'completed'; $prevCompleted = true; if ($index > 0) { $prevPdfId = $topicPdfs[$index - 1]->id; $prevCompleted = isset($pdfDetails[$prevPdfId]) && $pdfDetails[$prevPdfId] === 'completed'; } @endphp @endforeach {{-- STEP 2: WATCH VIDEO --}} @php // $videos = $workshop->videos ?? []; $videos = $courseTopic->topic->video->sortBy(function($vid) { return $vid->pivot->sequence_number ?? 0; })->values(); // reindex array @endphp @if($videos->count() > 0 && $checkCoursePurchase->course->is_government_course == 0) @php $stepCount++; @endphp {{-- Hidden video list (will appear after Start) --}} @foreach($videos as $index => $vid) @php $token = \Illuminate\Support\Str::uuid()->toString(); $secureUrl = \URL::temporarySignedRoute( 'secure.video', now()->addMinutes(120), ['filename' => $vid->video_upload, 'token' => $token] ); $watched = \App\Models\CoursePurchasedTopicStatus::where('course_purchase_id', $checkCoursePurchase->id) ->where('topic_id', $courseTopic->topic->id) ->where('type', 'watch_video') ->whereRaw("JSON_EXTRACT(video_details, '$.\"{$vid->id}\"') IS NOT NULL") ->exists(); @endphp @endforeach @endif {{-- STEP 3: MCQ --}} @php $stepCount++; @endphp
Step {{ $stepCount }} Read Book @if ($status1 == 'complete') @elseif($status1 == 'inprogress') @if($allPdfsRead) @else @endif @elseif($status1 === 'pending') @endif @if ($status1 == 'complete')
doneCompleted
@else
{{ $status1 == 'inprogress' ? 'In Progress' : ucfirst($status1) }}
@endif
Read PDF {{ $index + 1 }} {{-- COMPLETED --}} @if($isCompleted) Read {{-- READING (PAGE REFRESH SAFE) --}} @elseif($isReading) Read {{-- NOT STARTED --}} @else Read @endif @if($isCompleted)
doneCompleted
@else
Pending
@endif
Step {{$stepCount}} Watch Video @if($status2 === 'complete') @else @if($status2 === 'pending') @else @endif @endif @if($status2 === 'complete')
doneCompleted
@else
{{ ucfirst($status2) }}
@endif
Watch Video {{ $index + 1 }} @if ($watched) @endif 0) disabled @endif> {{ $watched ? 'Rewatch' : 'View' }} @if ($watched)
doneCompleted
@else
Pending
@endif
Step {{$stepCount}} MCQ @php // Your existing MCQ enable logic remains $videoStepEnabled = $hasVideo && $checkCoursePurchase->course->is_government_course == 0; // $mcqEnabled = $canStartTopic && // ($status1 === 'complete') && // (!$hasVideo || $status2 === 'complete'); $mcqEnabled = $canStartTopic && ($status1 === 'complete') && (!$videoStepEnabled || $status2 === 'complete' ); // Check if any attempt passed (≥60) $currentTopicId = $courseTopic->topic->id; // $hasPassingScore = isset($examScores[$currentTopicId]) && // $examScores[$currentTopicId] >= env('EXAM_PASS_SCORE'); $hasPassingScore = isset($examAttempts[$currentTopicId]) && $examAttempts[$topicId]->firstWhere('status', 'pass') !== null; $latestScore = 0; if (isset($examAttempts[$currentTopicId]) && $examAttempts[$currentTopicId]->isNotEmpty()) { $latestScore = $examAttempts[$currentTopicId]->first()['score']; } @endphp @if ($status3 === 'complete') @if($hasPassingScore) {{-- Passed state (your existing code) --}} @if($checkCoursePurchase->course_status != 'completed') @endif @else {{-- NEW: Failed state --}} @endif @else {{-- Your existing first attempt button --}} @endif @if ($status3 == 'complete') @if($hasPassingScore)
doneCompleted
@else
warning {{ $examScores[$courseTopic->topic->id] ?? 0 }}%
@endif @else
@endif