We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
1 | <?php declare(strict_types=1); |
||
2 | |||
3 | namespace Smr\Pages\Account; |
||
4 | |||
5 | use Smr\Database; |
||
6 | use Smr\Epoch; |
||
7 | use Smr\HallOfFame; |
||
8 | use Smr\Page\AccountPage; |
||
9 | use Smr\Page\ReusableTrait; |
||
10 | use Smr\Template; |
||
11 | use SmrAccount; |
||
12 | use SmrGame; |
||
13 | use SmrPlayer; |
||
14 | |||
15 | class HallOfFameAll extends AccountPage { |
||
16 | |||
17 | use ReusableTrait; |
||
18 | |||
19 | public string $file = 'hall_of_fame_new.php'; |
||
20 | |||
21 | public function __construct( |
||
22 | private readonly ?int $gameID = null, |
||
23 | public readonly ?string $viewType = null |
||
24 | ) {} |
||
25 | |||
26 | /** |
||
27 | * Construct a new object with the same properties, but a different |
||
28 | * viewType. |
||
29 | */ |
||
30 | public function withViewType(?string $viewType): self { |
||
31 | return new self($this->gameID, $viewType); |
||
32 | } |
||
33 | |||
34 | public function build(SmrAccount $account, Template $template): void { |
||
35 | $game_id = $this->gameID; |
||
36 | |||
37 | if (empty($game_id)) { |
||
38 | $topic = 'All Time Hall of Fame'; |
||
39 | } else { |
||
40 | $topic = 'Hall of Fame: ' . SmrGame::getGame($game_id)->getDisplayName(); |
||
41 | } |
||
42 | $template->assign('PageTopic', $topic); |
||
43 | |||
44 | $container = new HallOfFamePersonal($account->getAccountID(), $game_id); |
||
45 | $template->assign('PersonalHofHREF', $container->href()); |
||
46 | |||
47 | $breadcrumb = HallOfFame::buildBreadcrumb($this, isset($game_id) ? 'Current HoF' : 'Global HoF'); |
||
48 | $template->assign('Breadcrumb', $breadcrumb); |
||
49 | |||
50 | $viewType = $this->viewType; |
||
51 | $hofVis = SmrPlayer::getHOFVis(); |
||
52 | |||
53 | if (!isset($hofVis[$viewType])) { |
||
54 | // Not a complete HOF type, so continue to show categories |
||
55 | $allowedVis = [HOF_PUBLIC, HOF_ALLIANCE]; |
||
56 | $categories = HallOfFame::getHofCategories($this, $allowedVis, $game_id, $account->getAccountID()); |
||
57 | $template->assign('Categories', $categories); |
||
58 | |||
59 | } else { |
||
60 | // Rankings page |
||
61 | $db = Database::getInstance(); |
||
62 | $gameIDSql = ' AND game_id ' . (isset($game_id) ? '= ' . $db->escapeNumber($game_id) : 'IN (SELECT game_id FROM game WHERE end_time < ' . Epoch::time() . ' AND ignore_stats = ' . $db->escapeBoolean(false) . ')'); |
||
63 | |||
64 | $rank = 1; |
||
65 | $foundMe = false; |
||
66 | |||
67 | if ($viewType == HOF_TYPE_DONATION) { |
||
68 | $dbResult = $db->read('SELECT account_id, SUM(amount) as amount FROM account_donated |
||
69 | GROUP BY account_id ORDER BY amount DESC, account_id ASC LIMIT 25'); |
||
70 | } elseif ($viewType == HOF_TYPE_USER_SCORE) { |
||
71 | $statements = SmrAccount::getUserScoreCaseStatement($db); |
||
72 | $query = 'SELECT account_id, ' . $statements['CASE'] . ' amount FROM (SELECT account_id, type, SUM(amount) amount FROM player_hof WHERE type IN (' . $statements['IN'] . ')' . $gameIDSql . ' GROUP BY account_id,type) x GROUP BY account_id ORDER BY amount DESC, account_id ASC LIMIT 25'; |
||
73 | $dbResult = $db->read($query); |
||
74 | } else { |
||
75 | $dbResult = $db->read('SELECT account_id,SUM(amount) amount FROM player_hof WHERE type=' . $db->escapeString($viewType) . $gameIDSql . ' GROUP BY account_id ORDER BY amount DESC, account_id ASC LIMIT 25'); |
||
76 | } |
||
77 | $rows = []; |
||
78 | foreach ($dbResult->records() as $dbRecord) { |
||
79 | $accountID = $dbRecord->getInt('account_id'); |
||
80 | if ($accountID == $account->getAccountID()) { |
||
81 | $foundMe = true; |
||
82 | } |
||
83 | $amount = HallOfFame::applyHofVisibilityMask($dbRecord->getFloat('amount'), $hofVis[$viewType], $game_id, $accountID); |
||
84 | $rows[] = HallOfFame::displayHOFRow($rank++, $accountID, $game_id, $amount); |
||
85 | } |
||
86 | if (!$foundMe) { |
||
87 | $rank = HallOfFame::getHofRank($viewType, $account->getAccountID(), $game_id); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
88 | $rows[] = HallOfFame::displayHOFRow($rank['Rank'], $account->getAccountID(), $game_id, $rank['Amount']); |
||
89 | } |
||
90 | $template->assign('Rows', $rows); |
||
91 | } |
||
92 | } |
||
93 | |||
94 | } |
||
95 |