|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Smr\Pages\Account; |
|
4
|
|
|
|
|
5
|
|
|
use Smr\Exceptions\PlayerNotFound; |
|
6
|
|
|
use Smr\HallOfFame; |
|
7
|
|
|
use Smr\Page\AccountPage; |
|
8
|
|
|
use Smr\Page\ReusableTrait; |
|
9
|
|
|
use Smr\Template; |
|
10
|
|
|
use SmrAccount; |
|
11
|
|
|
use SmrGame; |
|
12
|
|
|
use SmrPlayer; |
|
13
|
|
|
|
|
14
|
|
|
class HallOfFamePersonal extends AccountPage { |
|
15
|
|
|
|
|
16
|
|
|
use ReusableTrait; |
|
17
|
|
|
|
|
18
|
|
|
public string $file = 'hall_of_fame_player_detail.php'; |
|
19
|
|
|
|
|
20
|
|
|
public function __construct( |
|
21
|
|
|
private readonly int $hofAccountID, |
|
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->hofAccountID, $this->gameID, $viewType); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function build(SmrAccount $account, Template $template): void { |
|
35
|
|
|
$account_id = $this->hofAccountID; |
|
36
|
|
|
$game_id = $this->gameID; |
|
37
|
|
|
$player = null; |
|
38
|
|
|
|
|
39
|
|
|
if (isset($game_id)) { |
|
40
|
|
|
try { |
|
41
|
|
|
$player = SmrPlayer::getPlayer($account->getAccountID(), $game_id); |
|
42
|
|
|
} catch (PlayerNotFound) { |
|
43
|
|
|
// Session user is not in this game, $player remains null |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
try { |
|
47
|
|
|
$hofPlayer = SmrPlayer::getPlayer($account_id, $game_id); |
|
48
|
|
|
} catch (PlayerNotFound) { |
|
49
|
|
|
create_error('That player has not yet joined this game.'); |
|
50
|
|
|
} |
|
51
|
|
|
$template->assign('PageTopic', htmlentities($hofPlayer->getPlayerName()) . '\'s Personal Hall of Fame: ' . SmrGame::getGame($game_id)->getDisplayName()); |
|
52
|
|
|
} else { |
|
53
|
|
|
$hofName = SmrAccount::getAccount($account_id)->getHofDisplayName(); |
|
54
|
|
|
$template->assign('PageTopic', $hofName . '\'s All Time Personal Hall of Fame'); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$breadcrumb = HallOfFame::buildBreadcrumb($this, 'Personal HoF'); |
|
58
|
|
|
$template->assign('Breadcrumb', $breadcrumb); |
|
59
|
|
|
|
|
60
|
|
|
$viewType = $this->viewType ?? ''; |
|
61
|
|
|
$hofVis = SmrPlayer::getHOFVis(); |
|
62
|
|
|
|
|
63
|
|
|
if (!isset($hofVis[$viewType])) { |
|
64
|
|
|
// Not a complete HOF type, so continue to show categories |
|
65
|
|
|
$allowedVis = [HOF_PUBLIC]; |
|
66
|
|
|
if ($account->getAccountID() == $account_id) { |
|
67
|
|
|
$allowedVis[] = HOF_ALLIANCE; |
|
68
|
|
|
$allowedVis[] = HOF_PRIVATE; |
|
69
|
|
|
} elseif (isset($hofPlayer) && $hofPlayer->sameAlliance($player)) { |
|
70
|
|
|
$allowedVis[] = HOF_ALLIANCE; |
|
71
|
|
|
} |
|
72
|
|
|
$categories = HallOfFame::getHofCategories($this, $allowedVis, $game_id, $account_id); |
|
73
|
|
|
$template->assign('Categories', $categories); |
|
74
|
|
|
|
|
75
|
|
|
} else { |
|
76
|
|
|
// Rankings page |
|
77
|
|
|
$hofRank = HallOfFame::getHofRank($viewType, $account_id, $game_id); |
|
78
|
|
|
$rows = [HallOfFame::displayHOFRow($hofRank['Rank'], $account_id, $game_id, $hofRank['Amount'])]; |
|
79
|
|
|
|
|
80
|
|
|
if ($account->getAccountID() != $account_id) { |
|
81
|
|
|
//current player's score. |
|
82
|
|
|
$playerRank = HallOfFame::getHofRank($viewType, $account->getAccountID(), $game_id); |
|
83
|
|
|
$row = HallOfFame::displayHOFRow($playerRank['Rank'], $account->getAccountID(), $game_id, $playerRank['Amount']); |
|
84
|
|
|
if ($playerRank['Rank'] >= $hofRank['Rank']) { |
|
85
|
|
|
$rows[] = $row; |
|
86
|
|
|
} else { |
|
87
|
|
|
array_unshift($rows, $row); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
$template->assign('Rows', $rows); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
} |
|
95
|
|
|
|