Мои курсы
+{{ $course->title }}
+ @if($course->category) + {{ $course->category->name }} + @endif +{{ Str::limit($course->description, 100) }}
+diff --git a/app/Http/Controllers/Student/CourseController.php b/app/Http/Controllers/Student/CourseController.php new file mode 100755 index 0000000..73d6bb8 --- /dev/null +++ b/app/Http/Controllers/Student/CourseController.php @@ -0,0 +1,84 @@ +middleware('auth'); + } + + public function index() + { + $user = Auth::user(); + + // Получаем назначения для пользователя + $query = CourseAssignment::with(['course', 'group', 'organization']) + ->where('is_active', true) + ->where(function($q) use ($user) { + // Индивидуальные назначения + $q->where('type', 'individual') + ->where('user_id', $user->id); + + // Или назначения группе пользователя + if ($user->groups->count() > 0) { + $q->orWhere(function($sub) use ($user) { + $sub->where('type', 'group') + ->whereIn('group_id', $user->groups->pluck('id')); + }); + } + + // Или назначения организации пользователя + if ($user->organization_id) { + $q->orWhere(function($sub) use ($user) { + $sub->where('type', 'organization') + ->where('organization_id', $user->organization_id); + }); + } + }); + + $assignments = $query->get(); + + // Группируем по курсам + $courses = $assignments->unique('course_id')->map(function($assignment) { + return $assignment->course; + }); + + return view('student.courses.index', compact('courses', 'assignments')); + } + + public function show(Course $course) + { + $user = Auth::user(); + + // Проверяем доступ к курсу + $hasAccess = CourseAssignment::where('course_id', $course->id) + ->where('is_active', true) + ->where(function($q) use ($user) { + $q->where('type', 'individual')->where('user_id', $user->id) + ->orWhere(function($sub) use ($user) { + $sub->where('type', 'group') + ->whereIn('group_id', $user->groups->pluck('id')); + }) + ->orWhere(function($sub) use ($user) { + $sub->where('type', 'organization') + ->where('organization_id', $user->organization_id); + }); + })->exists(); + + if (!$hasAccess) { + abort(403, 'У вас нет доступа к этому курсу'); + } + + $course->load(['tests', 'category']); + + return view('student.courses.show', compact('course')); + } +} diff --git a/app/Http/Controllers/Student/TestController.php b/app/Http/Controllers/Student/TestController.php new file mode 100755 index 0000000..2ed5c64 --- /dev/null +++ b/app/Http/Controllers/Student/TestController.php @@ -0,0 +1,71 @@ +middleware('auth'); + } + + public function index() + { + $user = Auth::user(); + + // Получаем тесты из доступных курсов + $courseIds = CourseAssignment::where('is_active', true) + ->where(function($q) use ($user) { + $q->where('type', 'individual')->where('user_id', $user->id) + ->orWhere(function($sub) use ($user) { + $sub->where('type', 'group') + ->whereIn('group_id', $user->groups->pluck('id')); + }) + ->orWhere(function($sub) use ($user) { + $sub->where('type', 'organization') + ->where('organization_id', $user->organization_id); + }); + })->pluck('course_id'); + + $tests = Test::with(['course']) + ->whereIn('course_id', $courseIds) + ->where('is_active', true) + ->get(); + + return view('student.tests.index', compact('tests')); + } + + public function show(Test $test) + { + $user = Auth::user(); + + // Проверяем доступ к тесту через курс + $hasAccess = CourseAssignment::where('course_id', $test->course_id) + ->where('is_active', true) + ->where(function($q) use ($user) { + $q->where('type', 'individual')->where('user_id', $user->id) + ->orWhere(function($sub) use ($user) { + $sub->where('type', 'group') + ->whereIn('group_id', $user->groups->pluck('id')); + }) + ->orWhere(function($sub) use ($user) { + $sub->where('type', 'organization') + ->where('organization_id', $user->organization_id); + }); + })->exists(); + + if (!$hasAccess) { + abort(403, 'У вас нет доступа к этому тесту'); + } + + $test->load(['questions.answers', 'course']); + + return view('student.tests.show', compact('test')); + } +} diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index 436dc10..41af60c 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -75,6 +75,23 @@ Панель управления + @if(Auth::user()->hasRole(['Administrator', 'Manager', 'Curator'])) +
{{ Str::limit($course->description, 100) }}
+{{ $course->description ?? '—' }}
+ + @if($course->objectives) +{{ $course->objectives }}
+ @endif +| Название | +Курс | +Вопросов | +Действия | +
|---|---|---|---|
| {{ $test->title }} | +{{ $test->course->title }} | +{{ $test->questions->count() }} | ++ + Начать + + | +
{{ $question->question_text }}
+ + @if($question->type === 'multiple_choice') +