@extends('layout.unit.unit_app') @push('style') @vite(['resources/css/layout/banner_main.css', 'resources/css/landing.css', 'resources/css/animate.css', 'resources/css/students/student.css', 'resources/css/unit/unit_detail.css', 'resources/css/unit/unit_exercise.css', 'resources/css/level-test.css']) @endpush @php use App\Enums\QuestionLabelEnum; use App\Enums\LevelExercise; use App\Enums\CourseType; if ($selectedExerciseParam['level'] != null) { switch ($selectedExerciseParam['level']) { case LevelExercise::NORMAL->value: $level = LevelExercise::NORMAL->name(); break; case LevelExercise::MEDIUM->value: $level = LevelExercise::MEDIUM->name(); break; default: $level = LevelExercise::ADVANCED->name(); } } else { $level = ''; } 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) { $label = strtoupper($label); $answer = strtoupper($answer); $correct = strtoupper($correct); if (($label === $correct && $correct === $answer) || ($label === $correct && $answer !== $correct)) { return 'answered-correct'; // cau tra loi dung voi dap an va dung voi label hoac 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)); } function getchoiceLabels($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 if (json_decode($choices, true)) { $choices = str_replace(['
', '<\/p>'], '', $choices);
$choicesArray = json_decode($choices, true);
if (is_null($choicesArray) || !is_array($choicesArray)) {
$choices = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'];
$choicesArray = json_decode(json_encode($choices), true);
}
} else {
$choices = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'];
$choicesArray = json_decode(json_encode($choices), true);
}
return $choicesArray;
}
$levelStar = getLevelExercise(
countCorrectAnswer($answerExerciseData, $answerExercises->toArray()),
$selectedExerciseParam['question_number'],
);
@endphp
@section('content')
{{ checkIsCourseSeftStudy($coursesPurchased['course_purchased']->course_type)['explain'] . ':' }}
{{ checkIsCourseSeftStudy($coursesPurchased['course_purchased']->course_type)['explain'] }}
chapter_id }}
data-unit-id={{ $unitData->id }} data-course-purchased-id={{ $coursesPurchased['course_purchased']->id }}>
@if ($levelStar == 0)
@else
@endif
{{ $level }}
{{ countCorrectAnswer($answerExerciseData, $answerExercises->toArray()) }}
/
{{ $selectedExerciseParam['question_number'] }}
@if ($coursesPurchased['course_purchased']->course_type === CourseType::COURSE_SELF_STUDY->value)
{{-- Khoa tu hoc online --}}
@if ($selectedExerciseParam['level'] == LevelExercise::NORMAL->value)
Bài Test Mới
{{ LevelExercise::MEDIUM->name() }}
Về Trang Của Bạn
{{ LevelExercise::ADVANCED->name() }}
@elseif ($selectedExerciseParam['level'] == LevelExercise::MEDIUM->value)
Bài Test Mới
{{ LevelExercise::NORMAL->name() }}
Về Trang Của Bạn
{{ LevelExercise::ADVANCED->name() }}
@else
Bài Test Mới
{{ LevelExercise::NORMAL->name() }}
Về Trang Của Bạn
{{ LevelExercise::MEDIUM->name() }}
@endif
@else
{{-- Khoa du hoc online --}}
Do More Test
{{ LevelExercise::ADVANCED->name() }}
About Your Page
{{ LevelExercise::ADVANCED->name() }}
@endif
@foreach ($answerExerciseData as $index => $ans)
@endforeach
{{ checkIsCourseSeftStudy($coursesPurchased['course_purchased']->course_type)['question'] }}
{{ $loop->index + 1 }}:
@if (!$ans['theory_answer'])
{{-- Truong hop tra loi trac nghiem A,B,C,D --}}
@foreach (getchoiceLabels($answerExercises, $ans['question_id']) as $label)
@if (getCorrectAnswer($answerExercises, $ans['question_id'])['text_answer'])
{{ checkIsCourseSeftStudy($coursesPurchased['course_purchased']->course_type)['see_explanation'] }}
@endforeach
@if (getLabelClass(substr(ltrim($label), 0, 1),
$ans['answer'],
getCorrectAnswer($answerExercises, $ans['question_id'])['correct']) === 'answered-correct')
@endif
@if (getLabelClass(substr(ltrim($label), 0, 1),
$ans['answer'],
getCorrectAnswer($answerExercises, $ans['question_id'])['correct']) === 'answer-wrong')
@endif
@else
{{ checkIsCourseSeftStudy($coursesPurchased['course_purchased']->course_type)['see_explanation'] }}
{{-- --}}
@endif
@else
{{-- Truong hop tra loi cau hoi tu luan --}}
{{-- --}}
{{-- --}}
@endif
{{-- --}}
@if ($ans['is_true'] == 1)
@endif
@if ($ans['is_true'] == 0)
@endif