@extends('frontend.maintemplate.maintemplate') @section('title', 'Answer key' . ' :: AgeLess Institute') @section('content')
@php use Carbon\Carbon; // Round score to nearest 10 $progressScore = round($exam->score ?? 0, -1); $examScore = (int) ($exam->score ?? 0); // Time taken calculation $start = Carbon::parse($exam->start_exam); $end = Carbon::parse($exam->end_exam); $durationInSeconds = $start->diffInSeconds($end); $minutes = floor($durationInSeconds / 60); $seconds = $durationInSeconds % 60; $formattedDuration = "{$minutes}m {$seconds}s"; // Initialize answer statistics $correctCount = 0; $wrongCount = 0; $total = count($examQuestions); // Count correct and wrong answers foreach ($examQuestions as $examQuestion) { $answer = $examQuestion->answer; $answerValue = $answer->answer_value ?? 'undefined'; $selectedOption = null; $correctOption = null; $isCorrect = false; if ($examQuestion->question->answer_type == 8) { $selectedOption = $examQuestion->question->mcqOptions->where('id', (int) $answerValue)->first(); $correctOption = $examQuestion->question->mcqOptions->where('is_correct', 1)->first(); if ($selectedOption && $correctOption && $selectedOption->id == $correctOption->id) { $isCorrect = true; $correctCount++; } else { $wrongCount++; } } else { if ($answerValue !== 'undefined') { $wrongCount++; } } } @endphp
Student Name
{{ $exam->student->full_name }}
@if(!empty($exam->workshop_id))
Workshop Name :
{{ $exam->workshop->title ?? '' }}
@else
Course Path
{{ $exam->course->category->name ?? '' }} > {{ $exam->course->subcategory->name ?? '' }} > {{ $exam->course->name ?? '' }}
@endif
{{ $examScore }}%
{{ ucfirst($exam->status) }}
done

{{ $correctCount }} / {{ $total }}

Correct Answers

close

{{ $wrongCount }} / {{ $total }}

Incorrect Answers

{{ $formattedDuration }}

Time Taken

Detailed Results

@foreach ($examQuestions as $key => $examQuestion) @php $answer = $examQuestion->answer; $answerValue = $answer->answer_value ?? 'undefined'; $selectedOption = null; $correctOption = null; $isCorrect = false; if ($examQuestion->question->answer_type == 8) { $selectedOption = $examQuestion->question->mcqOptions->where('id', (int) $answerValue)->first(); $correctOption = $examQuestion->question->mcqOptions->where('is_correct', 1)->first(); if ($selectedOption && $correctOption && $selectedOption->id == $correctOption->id) { $isCorrect = true; } } @endphp
Q.{{ $key + 1 }} - {!! $examQuestion->question->question_title !!} @if ($examQuestion->question->question_mark) ({{ $examQuestion->question->question_mark }} marks) @endif
{{ ($answerValue === 'undefined' || !$isCorrect) ? 'close' : 'done' }}
Your Answer: {{ $selectedOption->title ?? ($answerValue === 'undefined' ? 'Not Attempted' : $answerValue) }}
@if (!$isCorrect && $examQuestion->question->answer_type == 8 && $correctOption)
Correct Answer: {{ $correctOption->title }}
@endif
@endforeach
@endsection @section('scripts') @endsection