1<?php
2
3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
4// See the LICENCE file in the repository root for full licence text.
5
6namespace App\Http\Controllers\Users;
7
8use App\Http\Controllers\Controller;
9use App\Libraries\ModdingHistoryEventsBundle;
10use App\Libraries\User\FindForProfilePage;
11use App\Models\BeatmapDiscussionPost;
12use App\Models\BeatmapDiscussionVote;
13use Illuminate\Pagination\LengthAwarePaginator;
14
15class ModdingHistoryController extends Controller
16{
17 protected $searchParams;
18 protected $user;
19
20 public function __construct()
21 {
22 $this->middleware(function ($request, $next) {
23 $this->user = FindForProfilePage::find($request->route('user'));
24
25 $userId = $this->user->getKey();
26 $this->searchParams = array_merge(request()->query(), [
27 'current_user_id' => $userId,
28 'user' => $userId,
29 ]);
30
31 // This bit isn't needed when ModdingHistoryEventsBundle is used.
32 $this->searchParams['is_moderator'] = priv_check('BeatmapDiscussionModerate')->can();
33 $this->searchParams['is_kudosu_moderator'] = priv_check('BeatmapDiscussionAllowOrDenyKudosu')->can();
34 if (!$this->searchParams['is_moderator']) {
35 $this->searchParams['with_deleted'] = false;
36 }
37
38 return $next($request);
39 });
40
41 parent::__construct();
42 }
43
44 public function index()
45 {
46 $user = $this->user;
47
48 $jsonChunks = ModdingHistoryEventsBundle::forProfile($user, $this->searchParams)->toArray();
49
50 set_opengraph($this->user, 'modding');
51
52 return ext_view('users.beatmapset_activities', compact(
53 'jsonChunks',
54 'user'
55 ));
56 }
57
58 public function posts()
59 {
60 $user = $this->user;
61
62 $search = BeatmapDiscussionPost::search($this->searchParams);
63 unset($search['params']['user']);
64 $posts = new LengthAwarePaginator(
65 $search['query']->with([
66 'user',
67 'beatmapset',
68 'beatmapDiscussion',
69 'beatmapDiscussion.beatmapset',
70 'beatmapDiscussion.user',
71 'beatmapDiscussion.startingPost',
72 ])->get(),
73 $search['query']->realCount(),
74 $search['params']['limit'],
75 $search['params']['page'],
76 [
77 'path' => LengthAwarePaginator::resolveCurrentPath(),
78 'query' => $search['params'],
79 ]
80 );
81
82 return ext_view('beatmap_discussion_posts.index', compact('posts', 'user'));
83 }
84
85 public function votesGiven()
86 {
87 $user = $this->user;
88
89 $search = BeatmapDiscussionVote::search($this->searchParams);
90 unset($search['params']['user']);
91 $votes = new LengthAwarePaginator(
92 $search['query']->with([
93 'user',
94 'beatmapDiscussion',
95 'beatmapDiscussion.user',
96 'beatmapDiscussion.beatmapset',
97 'beatmapDiscussion.startingPost',
98 ])->get(),
99 $search['query']->realCount(),
100 $search['params']['limit'],
101 $search['params']['page'],
102 [
103 'path' => LengthAwarePaginator::resolveCurrentPath(),
104 'query' => $search['params'],
105 ]
106 );
107
108 return ext_view('beatmapset_discussion_votes.index', compact('votes', 'user'));
109 }
110
111 public function votesReceived()
112 {
113 $user = $this->user;
114 // quick workaround for existing call
115 $this->searchParams['receiver'] = $user->getKey();
116 unset($this->searchParams['user']);
117
118 $search = BeatmapDiscussionVote::search($this->searchParams);
119 unset($search['params']['user']);
120 $votes = new LengthAwarePaginator(
121 $search['query']->with([
122 'user',
123 'beatmapDiscussion',
124 'beatmapDiscussion.user',
125 'beatmapDiscussion.beatmapset',
126 'beatmapDiscussion.startingPost',
127 ])->get(),
128 $search['query']->realCount(),
129 $search['params']['limit'],
130 $search['params']['page'],
131 [
132 'path' => LengthAwarePaginator::resolveCurrentPath(),
133 'query' => $search['params'],
134 ]
135 );
136
137 return ext_view('beatmapset_discussion_votes.index', compact('votes', 'user'));
138 }
139}