diff --git a/Modules/Certificate/app/Http/Controllers/CertificationSettingsController.php b/Modules/Certificate/app/Http/Controllers/CertificationSettingsController.php new file mode 100644 index 00000000..60524241 --- /dev/null +++ b/Modules/Certificate/app/Http/Controllers/CertificationSettingsController.php @@ -0,0 +1,30 @@ +validate([ + 'show_course_certificate' => ['sometimes', 'boolean'], + 'show_course_marksheet' => ['sometimes', 'boolean'], + ]); + + $system = Setting::where('type', 'system')->firstOrFail(); + $fields = $system->fields ?? []; + + foreach ($validated as $key => $value) { + $fields[$key] = (bool) $value; + } + + $system->update(['fields' => $fields]); + + return back()->with('success', 'Certification settings updated successfully.'); + } +} + diff --git a/Modules/Certificate/routes/web.php b/Modules/Certificate/routes/web.php index bededa45..8e21dad4 100644 --- a/Modules/Certificate/routes/web.php +++ b/Modules/Certificate/routes/web.php @@ -2,12 +2,15 @@ use Illuminate\Support\Facades\Route; use Modules\Certificate\Http\Controllers\CertificateController; +use Modules\Certificate\Http\Controllers\CertificationSettingsController; use Modules\Certificate\Http\Controllers\CertificateTemplateController; use Modules\Certificate\Http\Controllers\MarksheetTemplateController; Route::middleware(['auth', 'verified'])->group(function () { // Admin routes for managing certificate templates Route::middleware(['role:admin'])->prefix('dashboard/certification')->group(function () { + Route::post('settings', [CertificationSettingsController::class, 'update'])->name('certification.settings.update'); + Route::resource('certificate', CertificateTemplateController::class)->except(['show', 'create', 'update'])->names('certificate.templates'); Route::get('certificate/create-certificate', [CertificateTemplateController::class, 'create'])->name('certificate.templates.create'); Route::post('certificate/{id}', [CertificateTemplateController::class, 'update'])->name('certificate.templates.update'); diff --git a/app/Http/Controllers/StudentController.php b/app/Http/Controllers/StudentController.php index 22b87c13..7e436b54 100644 --- a/app/Http/Controllers/StudentController.php +++ b/app/Http/Controllers/StudentController.php @@ -60,6 +60,15 @@ class StudentController extends Controller public function show_course(int $id, string $tab) { + $system = app('system_settings'); + $fields = $system?->fields ?? []; + $showCourseCertificate = $fields['show_course_certificate'] ?? true; + $showCourseMarksheet = $fields['show_course_marksheet'] ?? true; + + if ($tab === 'certificate' && !$showCourseCertificate && !$showCourseMarksheet) { + return redirect()->route('student.course.show', ['id' => $id, 'tab' => 'modules']); + } + $user = Auth::user(); $course = $this->studentService->getEnrolledCourse($id, $user); $props = $this->studentService->getEnrolledCourseOverview($id, $tab, $user); diff --git a/app/Services/StudentService.php b/app/Services/StudentService.php index ce2da242..cb84dc00 100644 --- a/app/Services/StudentService.php +++ b/app/Services/StudentService.php @@ -185,15 +185,20 @@ class StudentService extends MediaService function getEnrolledCourseOverview(string $course_id, string $tab, User $user): array { + $system = app('system_settings'); + $fields = $system?->fields ?? []; + $showCourseCertificate = $fields['show_course_certificate'] ?? true; + $showCourseMarksheet = $fields['show_course_marksheet'] ?? true; + return [ 'modules' => $tab === 'modules' ? $this->getCourseModules($course_id) : null, 'live_classes' => $tab === 'live_classes' ? $this->getCourseLiveClasses($course_id) : null, 'assignments' => $tab === 'assignments' ? $this->getCourseAssignments($course_id, $user) : null, 'quizzes' => $tab === 'quizzes' ? $this->getCourseSectionQuizzes($course_id, $user) : null, 'resources' => $tab === 'resources' ? $this->getCourseLessonResources($course_id) : null, - 'certificateTemplate' => $tab === 'certificate' ? $this->certificate->getActiveCertificateTemplate('course') : null, - 'marksheetTemplate' => $tab === 'certificate' ? $this->certificate->getActiveMarksheetTemplate('course') : null, - 'studentMarks' => $tab === 'certificate' ? $this->calculateStudentMarks($course_id, $user->id) : null, + 'certificateTemplate' => $tab === 'certificate' && $showCourseCertificate ? $this->certificate->getActiveCertificateTemplate('course') : null, + 'marksheetTemplate' => $tab === 'certificate' && $showCourseMarksheet ? $this->certificate->getActiveMarksheetTemplate('course') : null, + 'studentMarks' => $tab === 'certificate' && $showCourseMarksheet ? $this->calculateStudentMarks($course_id, $user->id) : null, ]; } diff --git a/resources/js/pages/course-player/partials/content-list.tsx b/resources/js/pages/course-player/partials/content-list.tsx index b8742d0c..3e5598fc 100644 --- a/resources/js/pages/course-player/partials/content-list.tsx +++ b/resources/js/pages/course-player/partials/content-list.tsx @@ -27,8 +27,9 @@ interface ContentListProps { const ContentList = ({ completedContents, courseCompletion }: ContentListProps) => { const { props } = usePage(); - const { course, zoomConfig, section, watchHistory, translate, direction } = props; + const { course, zoomConfig, section, watchHistory, translate, direction, system } = props; const { button, common, frontend } = translate; + const showCourseCertificate = system?.fields?.show_course_certificate ?? true; // Get live classes from course data const liveClasses = course.live_classes || []; @@ -115,7 +116,7 @@ const ContentList = ({ completedContents, courseCompletion }: ContentListProps)