Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Issues (412)

src/lib/Default/AbstractMenu.php (1 issue)

Labels
Severity
1
<?php declare(strict_types=1);
2
3
use Smr\CombatLogType;
4
use Smr\Database;
5
use Smr\Pages\Account\NewsReadAdvanced;
6
use Smr\Pages\Account\NewsReadArchives;
7
use Smr\Pages\Player\Bank\AllianceBank;
8
use Smr\Pages\Player\Bank\AnonBank;
9
use Smr\Pages\Player\Bank\PersonalBank;
10
use Smr\Pages\Player\Bar\BarMain;
11
use Smr\Pages\Player\Bar\LottoBuyTicket;
12
use Smr\Pages\Player\Bar\PlayBlackjackBet;
13
use Smr\Pages\Player\CombatLogList;
14
use Smr\Pages\Player\Council\Embassy;
15
use Smr\Pages\Player\Council\MessageCouncil;
16
use Smr\Pages\Player\Council\PoliticalStatus;
17
use Smr\Pages\Player\Council\ViewCouncil;
18
use Smr\Pages\Player\Council\VotingCenter;
19
use Smr\Pages\Player\GalacticPost\ArticleWrite;
20
use Smr\Pages\Player\GalacticPost\CurrentEditionProcessor;
21
use Smr\Pages\Player\GalacticPost\EditorOptions;
22
use Smr\Pages\Player\GalacticPost\PastEditionSelect;
23
use Smr\Pages\Player\Headquarters\BountyClaimProcessor;
24
use Smr\Pages\Player\Headquarters\BountyPlace;
25
use Smr\Pages\Player\Headquarters\Government;
26
use Smr\Pages\Player\Headquarters\MilitaryPaymentClaimProcessor;
27
use Smr\Pages\Player\Headquarters\Underground;
28
use Smr\Pages\Player\NewsReadCurrent;
29
use Smr\Pages\Player\Planet\Construction;
30
use Smr\Pages\Player\Planet\Defense;
31
use Smr\Pages\Player\Planet\Financial;
32
use Smr\Pages\Player\Planet\Main;
33
use Smr\Pages\Player\Planet\Ownership;
34
use Smr\Pages\Player\Planet\Stockpile;
35
use Smr\Pages\Player\Rankings\AllianceDeaths;
36
use Smr\Pages\Player\Rankings\AllianceExperience;
37
use Smr\Pages\Player\Rankings\AllianceKills;
38
use Smr\Pages\Player\Rankings\AllianceProfit;
39
use Smr\Pages\Player\Rankings\AllianceVsAlliance;
40
use Smr\Pages\Player\Rankings\PlayerAssists;
41
use Smr\Pages\Player\Rankings\PlayerDeaths;
42
use Smr\Pages\Player\Rankings\PlayerExperience;
43
use Smr\Pages\Player\Rankings\PlayerKills;
44
use Smr\Pages\Player\Rankings\PlayerNpcKills;
45
use Smr\Pages\Player\Rankings\PlayerProfit;
46
use Smr\Pages\Player\Rankings\RaceDeaths;
47
use Smr\Pages\Player\Rankings\RaceExperience;
48
use Smr\Pages\Player\Rankings\RaceKills;
49
use Smr\Pages\Player\Rankings\SectorKills;
50
51
/**
52
 * Creates menu navigation bars.
53
 */
54
class AbstractMenu {
55
56
	public static function headquarters(int $locationTypeID): void {
57
		$gameID = Smr\Session::getInstance()->getGameID();
58
59
		$links = [];
60
		$location = SmrLocation::getLocation($gameID, $locationTypeID);
61
		if ($location->isHQ()) {
62
			$links[] = [Government::class, 'Government'];
63
			$links[] = [MilitaryPaymentClaimProcessor::class, 'Claim Military Payment'];
64
		} elseif ($location->isUG()) {
65
			$links[] = [Underground::class, 'Underground'];
66
		} else {
67
			throw new Exception('Location is not HQ or UG: ' . $location->getName());
68
		}
69
70
		// No bounties in Semi Wars games
71
		if (!SmrGame::getGame($gameID)->isGameType(SmrGame::GAME_TYPE_SEMI_WARS)) {
72
			$links[] = [BountyClaimProcessor::class, 'Claim Bounty'];
73
			$links[] = [BountyPlace::class, 'Place Bounty'];
74
		}
75
76
		$menuItems = [];
77
		foreach ($links as [$class, $text]) {
78
			$container = new $class($locationTypeID);
79
			$menuItems[] = [
80
				'Link' => $container->href(),
81
				'Text' => $text,
82
			];
83
		}
84
		$template = Smr\Template::getInstance();
85
		$template->assign('MenuItems', $menuItems);
86
	}
87
88
	public static function planetList(int $alliance_id, int $selected_index): void {
89
		$menuItems = [];
90
		$menuItems[] = ['Link' => Globals::getPlanetListHREF($alliance_id), 'Text' => 'Defense'];
91
		$menuItems[] = ['Link' => Globals::getPlanetListFinancialHREF($alliance_id), 'Text' => 'Financial'];
92
		// make the selected index bold
93
		$boldItem =& $menuItems[$selected_index]['Text'];
94
		$boldItem = '<span class="bold">' . $boldItem . '</span>';
95
96
		$template = Smr\Template::getInstance();
97
		$template->assign('MenuItems', $menuItems);
98
	}
99
100
	public static function alliance(int $alliance_id): void {
101
		$db = Database::getInstance();
102
		$player = Smr\Session::getInstance()->getPlayer();
103
104
		$in_alliance = ($alliance_id == $player->getAllianceID() || in_array($player->getAccountID(), Globals::getHiddenPlayers()));
105
106
		// Some pages are visible to all alliance members
107
		$canReadMb = $in_alliance;
108
		$canReadMotd = $in_alliance;
109
		$canSeePlanetList = $in_alliance;
110
111
		// Check if player has permissions through an alliance treaty
112
		if (!$in_alliance) {
113
			$dbResult = $db->read('SELECT mb_read, mod_read, planet_land FROM alliance_treaties
114
							WHERE (alliance_id_1 = ' . $db->escapeNumber($alliance_id) . ' OR alliance_id_1 = ' . $db->escapeNumber($player->getAllianceID()) . ')
115
							AND (alliance_id_2 = ' . $db->escapeNumber($alliance_id) . ' OR alliance_id_2 = ' . $db->escapeNumber($player->getAllianceID()) . ')
116
							AND game_id = ' . $db->escapeNumber($player->getGameID()) . '
117
							AND (mb_read = 1 OR mod_read = 1 OR planet_land = 1) AND official = \'TRUE\'');
118
			if ($dbResult->hasRecord()) {
119
				$dbRecord = $dbResult->record();
120
				$canReadMb = $dbRecord->getBoolean('mb_read');
121
				$canReadMotd = $dbRecord->getBoolean('mod_read');
122
				$canSeePlanetList = $dbRecord->getBoolean('planet_land');
123
			}
124
		}
125
126
		$role_id = $player->getAllianceRole($alliance_id);
127
		$dbResult = $db->read('SELECT send_alliance_msg FROM alliance_has_roles WHERE alliance_id = ' . $db->escapeNumber($alliance_id) . ' AND game_id = ' . $db->escapeNumber($player->getGameID()) . ' AND role_id = ' . $db->escapeNumber($role_id));
128
		if ($dbResult->hasRecord()) {
129
			$send_alliance_msg = $dbResult->record()->getBoolean('send_alliance_msg');
130
		} else {
131
			$send_alliance_msg = false;
132
		}
133
134
		$menuItems = [];
135
		if ($canReadMotd) {
136
			$menuItems[] = ['Link' => Globals::getAllianceMotdHREF($alliance_id), 'Text' => 'Message of the Day'];
137
		}
138
		$menuItems[] = ['Link' => Globals::getAllianceRosterHREF($alliance_id), 'Text' => 'Roster'];
139
		if ($send_alliance_msg) {
140
			$menuItems[] = ['Link' => Globals::getAllianceMessageHREF($alliance_id), 'Text' => 'Send Message'];
141
		}
142
		if ($canReadMb) {
143
			$menuItems[] = ['Link' => Globals::getAllianceMessageBoardHREF($alliance_id), 'Text' => 'Message Board'];
144
		}
145
		if ($canSeePlanetList) {
146
			$menuItems[] = ['Link' => Globals::getPlanetListHREF($alliance_id), 'Text' => 'Planets'];
147
		}
148
		if ($in_alliance) {
149
			$menuItems[] = ['Link' => Globals::getAllianceForcesHREF($alliance_id), 'Text' => 'Forces'];
150
			$menuItems[] = ['Link' => Globals::getAllianceOptionsHREF(), 'Text' => 'Options'];
151
		}
152
		$menuItems[] = ['Link' => Globals::getAllianceListHREF(), 'Text' => 'List Alliances'];
153
		$menuItems[] = ['Link' => Globals::getAllianceNewsHREF($player->getGameID(), $alliance_id), 'Text' => 'View News'];
154
155
		$template = Smr\Template::getInstance();
156
		$template->assign('MenuItems', $menuItems);
157
	}
158
159
	public static function galacticPost(): void {
160
		$player = Smr\Session::getInstance()->getPlayer();
161
162
		$menuItems = [];
163
		$menuItems[] = ['Link' => (new CurrentEditionProcessor())->href(), 'Text' => 'Current Edition'];
164
		$menuItems[] = ['Link' => (new PastEditionSelect($player->getGameID()))->href(), 'Text' => 'Past Editions'];
165
		$menuItems[] = ['Link' => (new ArticleWrite())->href(), 'Text' => 'Write an article'];
166
		if ($player->isGPEditor()) {
167
			$menuItems[] = ['Link' => (new EditorOptions())->href(), 'Text' => 'Editor Options'];
168
		}
169
170
		$template = Smr\Template::getInstance();
171
		$template->assign('MenuItems', $menuItems);
172
	}
173
174
	public static function messages(): void {
175
		$player = Smr\Session::getInstance()->getPlayer();
176
177
		$menuItems = [];
178
		$menuItems[] = ['Link' => Globals::getViewMessageBoxesHREF(), 'Text' => 'View Messages'];
179
		$menuItems[] = ['Link' => Globals::getSendGlobalMessageHREF(), 'Text' => 'Send Global Message'];
180
		if ($player->isOnCouncil()) {
181
			$menuItems[] = ['Link' => Globals::getSendCouncilMessageHREF($player->getRaceID()), 'Text' => 'Send Council Message'];
182
		}
183
		$menuItems[] = ['Link' => Globals::getManageBlacklistHREF(), 'Text' => 'Manage Blacklist'];
184
185
		$template = Smr\Template::getInstance();
186
		$template->assign('MenuItems', $menuItems);
187
	}
188
189
	public static function combatLog(): void {
190
		$menuItems = [];
191
192
		foreach (CombatLogType::cases() as $type) {
193
			$container = new CombatLogList($type);
194
			$menuItems[] = ['Link' => $container->href(), 'Text' => $type->name];
0 ignored issues
show
The property name does not seem to exist on Smr\CombatLogType.
Loading history...
195
		}
196
197
		$template = Smr\Template::getInstance();
198
		$template->assign('MenuItems', $menuItems);
199
	}
200
201
	public static function trader(): void {
202
		$player = Smr\Session::getInstance()->getPlayer();
203
204
		$template = Smr\Template::getInstance();
205
		$template->assign('MenuItems', [
206
						['Link' => Globals::getTraderStatusHREF(), 'Text' => 'Trader Status'],
207
						['Link' => Globals::getPlanetListHREF($player->getAllianceID()), 'Text' => 'Planets'],
208
						['Link' => Globals::getAllianceHREF($player->getAllianceID()), 'Text' => 'Alliance'],
209
						['Link' => Globals::getCouncilHREF($player->getRaceID()), 'Text' => 'Politics'],
210
						['Link' => Globals::getTraderRelationsHREF(), 'Text' => 'Relations'],
211
						['Link' => Globals::getTraderBountiesHREF(), 'Text' => 'Bounties']]);
212
	}
213
214
	public static function planet(SmrPlanet $planet): void {
215
		$menu_array = [];
216
		$menu_array[] = ['Link' => (new Main())->href(), 'Text' => 'Planet Main'];
217
		if ($planet->hasMenuOption('CONSTRUCTION')) {
218
			$menu_array[] = ['Link' => (new Construction())->href(), 'Text' => 'Construction'];
219
		}
220
		if ($planet->hasMenuOption('DEFENSE')) {
221
			$menu_array[] = ['Link' => (new Defense())->href(), 'Text' => 'Defense'];
222
		}
223
		if ($planet->hasMenuOption('OWNERSHIP')) {
224
			$menu_array[] = ['Link' => (new Ownership())->href(), 'Text' => 'Ownership'];
225
		}
226
		if ($planet->hasMenuOption('STOCKPILE')) {
227
			$menu_array[] = ['Link' => (new Stockpile())->href(), 'Text' => 'Stockpile'];
228
		}
229
		if ($planet->hasMenuOption('FINANCE')) {
230
			$menu_array[] = ['Link' => (new Financial())->href(), 'Text' => 'Financial'];
231
		}
232
233
		$template = Smr\Template::getInstance();
234
		$template->assign('MenuItems', $menu_array);
235
	}
236
237
	/*
238
	 * $active_level1 - the id of the active menu on the first level
239
	 * $active_level1 - the id of the active menu on the second level
240
	 */
241
	public static function rankings(int $active_level1 = 0, int $active_level2 = 0): void {
242
243
		$menu = [];
244
245
		// player rankings
246
		$menu_item = [];
247
		$menu_item['entry'] = create_link(new PlayerExperience(), 'Player Rankings', 'nav');
248
249
		$menu_subitem = [];
250
		$menu_subitem[] = create_link(new PlayerExperience(), 'Experience', 'nav');
251
		$menu_subitem[] = create_link(new PlayerProfit(), 'Profit', 'nav');
252
		$menu_subitem[] = create_link(new PlayerKills(), 'Kills', 'nav');
253
		$menu_subitem[] = create_link(new PlayerDeaths(), 'Deaths', 'nav');
254
		$menu_subitem[] = create_link(new PlayerAssists(), 'Assists', 'nav');
255
		$menu_subitem[] = create_link(new PlayerNpcKills(), 'NPC Kills', 'nav');
256
257
		$menu_item['submenu'] = $menu_subitem;
258
259
		$menu[] = $menu_item;
260
261
		// alliance rankings
262
		$menu_item = [];
263
		$menu_item['entry'] = create_link(new AllianceExperience(), 'Alliance Rankings', 'nav');
264
265
		$menu_subitem = [];
266
		$menu_subitem[] = create_link(new AllianceExperience(), 'Experience', 'nav');
267
		$menu_subitem[] = create_link(new AllianceProfit(), 'Profit', 'nav');
268
		$menu_subitem[] = create_link(new AllianceKills(), 'Kills', 'nav');
269
		$menu_subitem[] = create_link(new AllianceDeaths(), 'Deaths', 'nav');
270
		$menu_subitem[] = create_link(new AllianceVsAlliance(), 'Versus', 'nav');
271
272
		$menu_item['submenu'] = $menu_subitem;
273
274
		$menu[] = $menu_item;
275
276
		// racial rankings
277
		$menu_item = [];
278
		$menu_item['entry'] = create_link(new RaceExperience(), 'Racial Standings', 'nav');
279
280
		$menu_subitem = [];
281
		$menu_subitem[] = create_link(new RaceExperience(), 'Experience', 'nav');
282
		$menu_subitem[] = create_link(new RaceKills(), 'Kills', 'nav');
283
		$menu_subitem[] = create_link(new RaceDeaths(), 'Deaths', 'nav');
284
285
		$menu_item['submenu'] = $menu_subitem;
286
287
		$menu[] = $menu_item;
288
289
		// sector rankings
290
		$menu_item = [];
291
		$menu_item['entry'] = create_link(new SectorKills(), 'Sector Kills', 'nav');
292
		$menu[] = $menu_item;
293
294
		create_sub_menu($menu, $active_level1, $active_level2);
295
	}
296
297
	public static function bank(): void {
298
		$player = Smr\Session::getInstance()->getPlayer();
299
300
		$links = [];
301
		$links[] = [new PersonalBank(), 'Personal Account'];
302
		if ($player->hasAlliance()) {
303
			$links[] = [new AllianceBank($player->getAllianceID()), 'Alliance Account'];
304
		}
305
		$links[] = [new AnonBank(), 'Anonymous Account'];
306
307
		$menuItems = [];
308
		foreach ($links as [$container, $label]) {
309
			$menuItems[] = [
310
				'Link' => $container->href(),
311
				'Text' => $label,
312
			];
313
		}
314
315
		$template = Smr\Template::getInstance();
316
		$template->assign('MenuItems', $menuItems);
317
	}
318
319
	public static function council(int $race_id): void {
320
		$player = Smr\Session::getInstance()->getPlayer();
321
322
		$container = new ViewCouncil($race_id);
323
		$menu_items = [];
324
		$menu_items[] = [
325
			'Link' => $container->href(),
326
			'Text' => 'View Council',
327
		];
328
329
		$container = new PoliticalStatus($race_id);
330
		$menu_items[] = [
331
			'Link' => $container->href(),
332
			'Text' => 'Political Status',
333
		];
334
335
		$container = new MessageCouncil($race_id);
336
		$menu_items[] = [
337
			'Link' => $container->href(),
338
			'Text' => 'Send Message',
339
		];
340
341
		if ($player->getRaceID() == $race_id) {
342
			if ($player->isOnCouncil()) {
343
				$container = new VotingCenter();
344
				$menu_items[] = [
345
					'Link' => $container->href(),
346
					'Text' => 'Voting Center',
347
				];
348
			}
349
			if ($player->isPresident()) {
350
				$container = new Embassy();
351
				$menu_items[] = [
352
					'Link' => $container->href(),
353
					'Text' => 'Embassy',
354
				];
355
			}
356
		}
357
358
		$template = Smr\Template::getInstance();
359
		$template->assign('MenuItems', $menu_items);
360
	}
361
362
	public static function bar(int $locationID): void {
363
		$template = Smr\Template::getInstance();
364
		$template->assign('MenuItems', [
365
			['Link' => (new BarMain($locationID))->href(), 'Text' => 'Bar Main'],
366
			['Link' => (new LottoBuyTicket($locationID))->href(), 'Text' => 'Lotto'],
367
			['Link' => (new PlayBlackjackBet($locationID))->href(), 'Text' => 'BlackJack'],
368
		]);
369
	}
370
371
	public static function news(int $gameID): void {
372
		$session = Smr\Session::getInstance();
373
374
		$menuItems = [];
375
		if ($session->getGameID() == $gameID) {
376
			$menuItems[] = [
377
				'Link' => (new NewsReadCurrent())->href(),
378
				'Text' => 'Read Current News',
379
			];
380
		}
381
		$menuItems[] = [
382
			'Link' => (new NewsReadArchives($gameID))->href(),
383
			'Text' => 'Read Latest News',
384
		];
385
		$menuItems[] = [
386
			'Link' => (new NewsReadAdvanced($gameID))->href(),
387
			'Text' => 'Advanced News',
388
		];
389
390
		$template = Smr\Template::getInstance();
391
		$template->assign('MenuItems', $menuItems);
392
	}
393
394
	public static function navigation(AbstractSmrPlayer $player): void {
395
		$menuItems = [];
396
		$menuItems[] = ['Link' => Globals::getPlotCourseHREF(), 'Text' => 'Plot A Course'];
397
		if (!$player->isLandedOnPlanet()) {
398
			$menuItems[] = ['Link' => Globals::getLocalMapHREF(), 'Text' => 'Local Map'];
399
		}
400
		$menuItems[] = ['Link' => 'map_galaxy.php" target="gal_map', 'Text' => 'Galaxy Map'];
401
402
		$template = Smr\Template::getInstance();
403
		$template->assign('MenuItems', $menuItems);
404
	}
405
406
}
407
408
/**
409
 * @param array<array<string, mixed>> $menu
410
 */
411
function create_sub_menu(array $menu, int $active_level1, int $active_level2): void {
412
	$return = ('<table class="fullwidth center">');
413
	$return .= ('<tr>');
414
	foreach ($menu as $number => $entry) {
415
		// insert spacer
416
		if ($number > 0) {
417
			$return .= ('<td>&nbsp;|&nbsp;</td>');
418
		}
419
420
		// if this is the active entry we mark it
421
		if ($number == $active_level1) {
422
			$active = ' class="bold"';
423
		} else {
424
			$active = '';
425
		}
426
427
		// echo entry itself
428
		$return .= ('<td ' . $active . '> ' . $entry['entry'] . '</td>');
429
430
	}
431
	$return .= ('</tr>');
432
433
	$return .= ('<tr>');
434
	foreach ($menu as $number => $entry) {
435
		// if this entry has a submenu and is the active one
436
		if (isset($entry['submenu']) && $number == $active_level1) {
437
			$return .= ('<td><small>');
438
			foreach ($entry['submenu'] as $sub_number => $sub_entry) {
439
				if ($sub_number > 0) {
440
					$return .= (' | ');
441
				}
442
443
				if ($sub_number == $active_level2) {
444
					$return .= ('<span class="bold">' . $sub_entry . '</span>');
445
				} else {
446
					$return .= ($sub_entry);
447
				}
448
			}
449
			$return .= ('</small></td>');
450
		} else {
451
			// if it's not the first entry we have to put
452
			// additional empty cell for the spacer
453
			//if ($number > 0)
454
				//echo ('<td>&nbsp;<td>');
455
456
			// emppty cell (no submenu)
457
			$return .= ('<td>&nbsp;<td>');
458
		}
459
	}
460
	$return .= ('</tr>');
461
462
	$return .= ('</table>');
463
464
	$template = Smr\Template::getInstance();
465
	$template->unassign('MenuItems');
466
	$template->assign('SubMenuBar', $return);
467
}
468