1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Smr\Pages\Account; |
4
|
|
|
|
5
|
|
|
use Menu; |
6
|
|
|
use Smr\Database; |
7
|
|
|
use Smr\News; |
8
|
|
|
use Smr\Page\AccountPage; |
9
|
|
|
use Smr\Page\ReusableTrait; |
10
|
|
|
use Smr\Template; |
11
|
|
|
use SmrAccount; |
12
|
|
|
|
13
|
|
|
class NewsReadAdvanced extends AccountPage { |
14
|
|
|
|
15
|
|
|
use ReusableTrait; |
16
|
|
|
|
17
|
|
|
public string $file = 'news_read_advanced.php'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @param ?array<int> $accountIDs |
21
|
|
|
* @param ?array<int> $allianceIDs |
22
|
|
|
*/ |
23
|
|
|
public function __construct( |
24
|
|
|
private readonly int $gameID, |
25
|
|
|
private readonly ?string $submit = null, |
26
|
|
|
private readonly ?string $label = null, |
27
|
|
|
private readonly ?array $accountIDs = null, |
28
|
|
|
private readonly ?array $allianceIDs = null, |
29
|
|
|
) {} |
30
|
|
|
|
31
|
|
|
public function build(SmrAccount $account, Template $template): void { |
32
|
|
|
$gameID = $this->gameID; |
33
|
|
|
|
34
|
|
|
$db = Database::getInstance(); |
35
|
|
|
$dbResult = $db->read('SELECT alliance_id, alliance_name |
36
|
|
|
FROM alliance |
37
|
|
|
WHERE game_id = ' . $db->escapeNumber($gameID)); |
38
|
|
|
|
39
|
|
|
$newsAlliances = [0 => 'None']; |
40
|
|
|
foreach ($dbResult->records() as $dbRecord) { |
41
|
|
|
$newsAlliances[$dbRecord->getInt('alliance_id')] = htmlentities($dbRecord->getString('alliance_name')); |
42
|
|
|
} |
43
|
|
|
$template->assign('NewsAlliances', $newsAlliances); |
44
|
|
|
|
45
|
|
|
$template->assign('AdvancedNewsFormHref', (new NewsReadAdvancedProcessor($this->gameID))->href()); |
46
|
|
|
|
47
|
|
|
// No submit value when first navigating to the page |
48
|
|
|
$submit_value = $this->submit; |
49
|
|
|
|
50
|
|
|
if ($submit_value == 'Search For Player') { |
51
|
|
|
$template->assign('ResultsFor', $this->label); |
52
|
|
|
$dbResult = $db->read('SELECT * FROM news WHERE game_id = ' . $db->escapeNumber($gameID) . ' AND (killer_id IN (' . $db->escapeArray($this->accountIDs) . ') OR dead_id IN (' . $db->escapeArray($this->accountIDs) . ')) ORDER BY news_id DESC'); |
|
|
|
|
53
|
|
|
} elseif ($submit_value == 'Search For Alliance') { |
54
|
|
|
$allianceID = $this->allianceIDs[0]; |
55
|
|
|
$template->assign('ResultsFor', $newsAlliances[$allianceID]); |
56
|
|
|
$dbResult = $db->read('SELECT * FROM news WHERE game_id = ' . $db->escapeNumber($gameID) . ' AND ((killer_alliance = ' . $db->escapeNumber($allianceID) . ' AND killer_id != ' . $db->escapeNumber(ACCOUNT_ID_PORT) . ') OR (dead_alliance = ' . $db->escapeNumber($allianceID) . ' AND dead_id != ' . $db->escapeNumber(ACCOUNT_ID_PORT) . ')) ORDER BY news_id DESC'); |
57
|
|
|
} elseif ($submit_value == 'Search For Players') { |
58
|
|
|
$template->assign('ResultsFor', $this->label); |
59
|
|
|
$dbResult = $db->read('SELECT * FROM news |
60
|
|
|
WHERE game_id = ' . $db->escapeNumber($gameID) . ' |
61
|
|
|
AND ( |
62
|
|
|
killer_id IN (' . $db->escapeArray($this->accountIDs) . ') AND dead_id IN (' . $db->escapeArray($this->accountIDs) . ') |
63
|
|
|
) ORDER BY news_id DESC'); |
64
|
|
|
} elseif ($submit_value == 'Search For Alliances') { |
65
|
|
|
$allianceID1 = $this->allianceIDs[0]; |
66
|
|
|
$allianceID2 = $this->allianceIDs[1]; |
67
|
|
|
$template->assign('ResultsFor', $newsAlliances[$allianceID1] . ' vs. ' . $newsAlliances[$allianceID2]); |
68
|
|
|
$dbResult = $db->read('SELECT * FROM news |
69
|
|
|
WHERE game_id = ' . $db->escapeNumber($gameID) . ' |
70
|
|
|
AND ( |
71
|
|
|
(killer_alliance = ' . $db->escapeNumber($allianceID1) . ' AND dead_alliance = ' . $db->escapeNumber($allianceID2) . ') |
72
|
|
|
OR |
73
|
|
|
(killer_alliance = ' . $db->escapeNumber($allianceID2) . ' AND dead_alliance = ' . $db->escapeNumber($allianceID1) . ') |
74
|
|
|
) ORDER BY news_id DESC'); |
75
|
|
|
} else { |
76
|
|
|
$dbResult = $db->read('SELECT * FROM news WHERE game_id = ' . $db->escapeNumber($gameID) . ' ORDER BY news_id DESC LIMIT 50'); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
$template->assign('NewsItems', News::getNewsItems($dbResult)); |
80
|
|
|
|
81
|
|
|
$template->assign('PageTopic', 'Advanced News'); |
82
|
|
|
Menu::news($gameID); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
} |
86
|
|
|
|