From 3d67eedf0cfd2a03574c9d45ff2a87598d623f46 Mon Sep 17 00:00:00 2001 From: Ahmed Darrazi Date: Fri, 19 Dec 2025 01:37:38 +0100 Subject: [PATCH] bugfix --- .../Controllers/Course/PlayerController.php | 33 ++++++++++++++----- resources/js/types/exam.d.ts | 2 +- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/Course/PlayerController.php b/app/Http/Controllers/Course/PlayerController.php index 38976e3c..e55ceefb 100644 --- a/app/Http/Controllers/Course/PlayerController.php +++ b/app/Http/Controllers/Course/PlayerController.php @@ -49,9 +49,8 @@ class PlayerController extends Controller try { $user = Auth::user(); - $section_id = $watch_history->current_section_id; - $watching_id = $lesson_id ?? $watch_history->current_watching_id; - $watching_type = $watch_history->current_watching_type ?? $type; + $watching_id = $lesson_id ?: $watch_history->current_watching_id; + $watching_type = in_array($type, ['lesson', 'quiz'], true) ? $type : ($watch_history->current_watching_type ?? 'lesson'); $course = $this->courseService->getUserCourseById($watch_history->course_id, $user); $watching = $this->coursePlay->getWatchingLesson($watching_id, $watching_type); @@ -60,18 +59,14 @@ class PlayerController extends Controller $totalReviews = $this->reviewService->totalReviews($course->id); $zoomConfig = $this->zoomLiveService->zoomConfig; - $section = null; $totalContent = 0; foreach ($course->sections as $courseSection) { $totalContent += count($courseSection->section_lessons) + count($courseSection->section_quizzes); - - if ($courseSection->id == $section_id) { - $section = $courseSection; - } } $watchHistory = $this->coursePlay->watchHistory($course, $watching_id, $watching_type, $user->id); + $section = $course->sections->firstWhere('id', $watchHistory->current_section_id); // $submissions = null; // if ($assignment) { @@ -91,6 +86,28 @@ class PlayerController extends Controller 'zoomConfig' => $zoomConfig, ]); } catch (ModelNotFoundException $th) { + $fallbackId = $watch_history->current_watching_id; + $fallbackType = $watch_history->current_watching_type; + $requestedType = $watching_type ?? $type; + + if ($fallbackId && in_array($fallbackType, ['lesson', 'quiz'], true)) { + $isDifferentFromRequested = ((string) $fallbackId !== (string) $lesson_id) || ($fallbackType !== $requestedType); + + if ($isDifferentFromRequested) { + try { + $this->coursePlay->getWatchingLesson((string) $fallbackId, $fallbackType); + + return redirect()->route('course.player', [ + 'type' => $fallbackType, + 'watch_history' => $watch_history->id, + 'lesson_id' => $fallbackId, + ]); + } catch (ModelNotFoundException $fallbackException) { + // Fall through to generic error below. + } + } + } + return redirect()->route('category.courses', ['category' => 'all'])->with('error', 'The requested content could not be found.'); } catch (\Throwable $th) { return redirect()->route('category.courses', ['category' => 'all'])->with('error', $th->getMessage()); diff --git a/resources/js/types/exam.d.ts b/resources/js/types/exam.d.ts index f18d3e32..b4bb18ce 100644 --- a/resources/js/types/exam.d.ts +++ b/resources/js/types/exam.d.ts @@ -251,7 +251,7 @@ interface EnrollmentProgress { enrollment: ExamEnrollment; is_active: boolean; attempts_used: number; - attempts_remaining: number; + attempts_remaining: number | null; completed_attempts: number; best_score: number; has_passed: boolean;