diff --git a/app/Filament/Training/Pages/Exam/ExamHistory.php b/app/Filament/Training/Pages/Exam/ExamHistory.php index 6c86d0c8f..6f41bcbc5 100644 --- a/app/Filament/Training/Pages/Exam/ExamHistory.php +++ b/app/Filament/Training/Pages/Exam/ExamHistory.php @@ -100,6 +100,24 @@ public function table(Table $table): Table }); })); })->label('Position'), + Filter::make('conducted_by_me')->form([ + Forms\Components\Checkbox::make('conducted_by_me') + ->label('Show exams I conducted'), + ])->query(function ($query, array $data) { + if ($data['conducted_by_me']) { + $userCid = auth()->user()->id; + + return $query->whereHas('examBooking.examiners', function ($q) use ($userCid) { + $q->where(function ($subQuery) use ($userCid) { + $subQuery->whereHas('primaryExaminer', fn ($sq) => $sq->where('cid', $userCid)) + ->orWhereHas('secondaryExaminer', fn ($sq) => $sq->where('cid', $userCid)) + ->orWhereHas('traineeExaminer', fn ($sq) => $sq->where('cid', $userCid)); + }); + }); + } + + return $query; + })->label('Conducted by me'), ]); } }