diff --git a/app/Http/Controllers/User/UserController.php b/app/Http/Controllers/User/UserController.php index 61f1e1a..c6ad84b 100644 --- a/app/Http/Controllers/User/UserController.php +++ b/app/Http/Controllers/User/UserController.php @@ -99,6 +99,41 @@ class UserController extends Controller ]); } + // New page: list of ThankCards received by the current user + public function receivedCards(Request $request): View + { + $selectedMonth = $request->input('month', Carbon::now()->format('Y-m')); + $user = Auth::user(); + $data = $this->userService->getReceivedPageData($user, $selectedMonth); + return view('user.received', $data); + } + + // New page: list of ThankCards sent by the current user + public function sentCards(Request $request): View + { + $selectedMonth = $request->input('month', Carbon::now()->format('Y-m')); + $user = Auth::user(); + $data = $this->userService->getSentPageData($user, $selectedMonth); + return view('user.sent', $data); + } + + // New page: ranking (both received and sent) with tabs + public function ranking(Request $request): View + { + $selectedMonth = $request->input('month', Carbon::now()->format('Y-m')); + $user = Auth::user(); + $receivedRanking = $this->userService->getRankingList('received', $selectedMonth, $user); + $sentRanking = $this->userService->getRankingList('sent', $selectedMonth, $user); + return view('user.ranking', [ + 'selectedMonth' => $selectedMonth, + 'receivedRankers' => $receivedRanking['rankers'], + 'receivedCurrentUserRankItem' => $receivedRanking['currentUserRankItem'], + 'sentRankers' => $sentRanking['rankers'], + 'sentCurrentUserRankItem' => $sentRanking['currentUserRankItem'], + ]); + } + + /** * Show the change password form. */ diff --git a/app/Services/User/UserService.php b/app/Services/User/UserService.php index 928e171..5d194ed 100644 --- a/app/Services/User/UserService.php +++ b/app/Services/User/UserService.php @@ -193,10 +193,10 @@ class UserService implements UserServiceInterface $currentUserRankItem = $userItem; } - if ($index < 4) { - $rankers[] = $userItem; - } + // Include every ranked user (no hard limit) + $rankers[] = $userItem; $rank++; + } if (!$currentUserRankItem) { @@ -214,6 +214,32 @@ class UserService implements UserServiceInterface ]; } + // Retrieve paginated list of received ThankCards for a user + public function getReceivedPageData(User $user, string $selectedMonth): array + { + $start = Carbon::parse($selectedMonth)->startOfMonth(); + $end = Carbon::parse($selectedMonth)->endOfMonth(); + $cards = Administration::where('msnv', $user->msnv) + ->whereBetween('date', [$start, $end]) + ->where('received', '>', 0) + ->orderBy('date', 'desc') + ->get(); + return ['cards' => $cards]; + } + + // Retrieve paginated list of sent ThankCards for a user + public function getSentPageData(User $user, string $selectedMonth): array + { + $start = Carbon::parse($selectedMonth)->startOfMonth(); + $end = Carbon::parse($selectedMonth)->endOfMonth(); + $cards = Administration::where('msnv', $user->msnv) + ->whereBetween('date', [$start, $end]) + ->where('sent', '>', 0) + ->orderBy('date', 'desc') + ->get(); + return ['cards' => $cards]; + } + public function updateProfile(User $user, array $data, ?\Illuminate\Http\UploadedFile $avatarFile = null): void { if (isset($data['name'])) { diff --git a/resources/views/user/ranking.blade.php b/resources/views/user/ranking.blade.php new file mode 100644 index 0000000..caf6ddf --- /dev/null +++ b/resources/views/user/ranking.blade.php @@ -0,0 +1,328 @@ +@extends('layouts.app') + +@section('title', 'Bảng xếp hạng') + +@section('content') +
Tôn vinh những cá nhân lan tỏa văn hóa cảm ơn và ghi nhận trong tổ chức.
+Thành tích của bạn (Nhận)
+{{ $receivedCurrentUserRankItem->name }}
+{{ $receivedCurrentUserRankItem->score }}
+Điểm
+{{ $group->count() }} người đồng hạng
+{{ $user->name }}
+{{ $user->department }}
+Các lời cảm ơn mà đồng nghiệp đã gửi đến bạn.
+{{ $c->received }} thẻ
+Các lời cảm ơn bạn đã gửi tới đồng nghiệp.
+{{ $c->sent }} thẻ
+