|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Module\Database\View\PirateWrathRanking; |
|
6
|
|
|
|
|
7
|
|
|
use Stu\Module\Control\GameControllerInterface; |
|
8
|
|
|
use Stu\Module\Control\ViewControllerInterface; |
|
9
|
|
|
use Stu\Module\Database\Lib\DatabaseUiFactoryInterface; |
|
10
|
|
|
use Stu\Lib\ModuleScreen\GradientColorInterface; |
|
11
|
|
|
use Stu\Orm\Repository\PirateWrathRepositoryInterface; |
|
12
|
|
|
use Stu\Orm\Entity\PirateWrathInterface; |
|
13
|
|
|
use Stu\Orm\Repository\UserRepositoryInterface; |
|
14
|
|
|
|
|
15
|
|
|
final class PirateWrathRanking implements ViewControllerInterface |
|
16
|
|
|
{ |
|
17
|
|
|
public const VIEW_IDENTIFIER = 'SHOW_TOP_PIRATE_WRATH'; |
|
18
|
|
|
|
|
19
|
|
|
private DatabaseUiFactoryInterface $databaseUiFactory; |
|
20
|
|
|
|
|
21
|
|
|
private UserRepositoryInterface $userRepository; |
|
22
|
|
|
|
|
23
|
|
|
private PirateWrathRepositoryInterface $pirateWrathRepository; |
|
24
|
|
|
|
|
25
|
|
|
private GradientColorInterface $gradientColor; |
|
26
|
|
|
|
|
27
|
|
|
public function __construct( |
|
28
|
|
|
DatabaseUiFactoryInterface $databaseUiFactory, |
|
29
|
|
|
PirateWrathRepositoryInterface $pirateWrathRepository, |
|
30
|
|
|
GradientColorInterface $gradientColor, |
|
31
|
|
|
UserRepositoryInterface $userRepository |
|
32
|
|
|
) { |
|
33
|
|
|
$this->databaseUiFactory = $databaseUiFactory; |
|
34
|
|
|
$this->pirateWrathRepository = $pirateWrathRepository; |
|
35
|
|
|
$this->gradientColor = $gradientColor; |
|
36
|
|
|
$this->userRepository = $userRepository; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function handle(GameControllerInterface $game): void |
|
40
|
|
|
{ |
|
41
|
|
|
$game->appendNavigationPart( |
|
42
|
|
|
'database.php', |
|
43
|
|
|
'Datenbank' |
|
44
|
|
|
); |
|
45
|
|
|
$game->appendNavigationPart( |
|
46
|
|
|
sprintf( |
|
47
|
|
|
'database.php?%s=1', |
|
48
|
|
|
static::VIEW_IDENTIFIER |
|
49
|
|
|
), |
|
50
|
|
|
'Die 10 größten Feinde der Kazon' |
|
51
|
|
|
); |
|
52
|
|
|
$game->setPageTitle('/ Datenbank / Die 10 größten Feinde der Kazon'); |
|
53
|
|
|
$game->showMacro('html/database.xhtml/top_pirate_wrath_user'); |
|
54
|
|
|
$wrathList = $this->pirateWrathRepository->getPirateWrathTop10(); |
|
55
|
|
|
$wrathData = array_map( |
|
56
|
|
|
function ($wrathEntity) { |
|
57
|
|
|
$userId = $wrathEntity->getUser()->getId(); |
|
58
|
|
|
$wrath = $wrathEntity->getWrath(); |
|
59
|
|
|
|
|
60
|
|
|
return [ |
|
61
|
|
|
'user' => $this->userRepository->find($userId), |
|
62
|
|
|
'entry' => $this->databaseUiFactory->createDatabaseTopListWithColorGradient( |
|
63
|
|
|
$userId, |
|
64
|
|
|
$this->gradientColor->calculateGradientColor( |
|
65
|
|
|
$wrath, |
|
66
|
|
|
500, // Untergrenze |
|
67
|
|
|
2000 // Obergrenze |
|
68
|
|
|
) |
|
69
|
|
|
), |
|
70
|
|
|
]; |
|
71
|
|
|
}, |
|
72
|
|
|
$wrathList |
|
73
|
|
|
); |
|
74
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
$game->setTemplateVar('PIRATE_WRATH_LIST', $wrathData); |
|
77
|
|
|
|
|
78
|
|
|
$game->setTemplateVar( |
|
79
|
|
|
'USER_WRATH', |
|
80
|
|
|
($game->getUser()->getPirateWrath()?->getWrath() ?? PirateWrathInterface::DEFAULT_WRATH) / 10 |
|
81
|
|
|
); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|