Level {{ $levelStar }}
{{ countCorrectAnswer($answerData, $answers->toArray()) }} / {{ $selectedParam['question_number'] }}
Câu {{ $loop->index + 1 }}:
Giải thích:
@extends('layout.app', ['title' => 'Kết quả kiểm tra']) @push('style') @vite(['resources/css/landing.css', 'resources/css/level-test.css']) @endpush @php use App\Enums\QuestionLabelEnum; function getImageQuestion($answers, $question_id): array|null { $question = collect($answers) ->map(function ($item) use ($question_id) { return $item->question->where('id', $question_id)->first(); }) ->first(); if ($question) { return [ // 'image_path' => $question->image_path, 'text' => $question->text, 'choices' => $question->choices ?? '[]', ]; } else { return [ 'text' => null, 'choices' => '[]', ]; } } function getCorrectAnswer($answers, $question_id) { $result = collect($answers)->where('id', $question_id); $dd = [ 'correct' => $result->pluck('result')->first(), 'text_answer' => $result->pluck('text')->first(), //Text cua cau tra loi dung(giai thich) // 'image_answer' => $result->pluck('image_path')->first(), //image cua cau tra loi dung(giai thich) ]; return $dd; } function getLabelClass($label, $answer, $correct) { if ($label === $correct && $correct === $answer) { return 'answered-correct'; // cau tra loi dung voi dap an va dung voi label } if ($label === $correct && $answer !== $correct) { return 'answer-correct'; // cau tra loi dung khong dung voi dap an va nhung dung voi label } if ($label === $answer && $answer !== $correct) { return 'answer-wrong'; // cau tra loi sai voi dap an va sai voi label } return ''; } // get so checkbox de hien thi dua vao truong choices // $answerLabel=["A","B","C",...] function getAnswerLabels($answers, $question_id): array { $findChoices = collect($answers)->map(function ($item) use ($question_id) { return $item->question->where('id', $question_id)->first(); }); $choices = $findChoices->pluck('choices')->first(); // choices cua cau hoi $choicesArray = json_decode($choices, true); return QuestionLabelEnum::getAnswerLabels(count($choicesArray)); } $levelStar = getLevelExercise( countCorrectAnswer($answerData, $answers->toArray()), $selectedParam['question_number'], ); $descriptions = [ 'Đặt ra mục tiêu, đam mê, và không ngừng nỗ lực - thành công sẽ là thành tựu của những ai kiên trì và không bao giờ từ bỏ.', 'Những nỗ lực hôm nay sẽ thắp sáng con đường tương lai của bạn. Hãy tin tưởng vào bản thân và tiến lên với mục tiêu rực rỡ!', 'Hãy kiên trì và nỗ lực, thành công sẽ đến với những ai không ngừng cố gắng.', 'Chăm chỉ hôm nay, thành công ngày mai – bạn đang trên đường chinh phục ước mơ!', ]; $randomDescription = $descriptions[array_rand($descriptions)]; @endphp @section('content')
Giải thích: