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

Failed Conditions
Push — main ( 2c9538...02418a )
by Dan
38s queued 18s
created

AbstractMenu::planet()   A

Complexity

Conditions 6
Paths 32

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

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