1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Module\Database\View\SatisfiedWorkerRanking; |
6
|
|
|
|
7
|
|
|
use Stu\Module\Colony\Lib\ColonyLibFactoryInterface; |
8
|
|
|
use Stu\Module\Commodity\CommodityTypeEnum; |
9
|
|
|
use Stu\Module\Control\GameControllerInterface; |
10
|
|
|
use Stu\Module\Control\ViewControllerInterface; |
11
|
|
|
use Stu\Module\Database\Lib\DatabaseTopListWithPoints; |
12
|
|
|
use Stu\Module\Database\Lib\DatabaseUiFactoryInterface; |
13
|
|
|
use Stu\Module\Logging\LoggerUtilFactoryInterface; |
14
|
|
|
use Stu\Module\Logging\LoggerUtilInterface; |
15
|
|
|
use Stu\Orm\Repository\ColonyRepositoryInterface; |
16
|
|
|
|
17
|
|
|
final class SatisfiedWorkerRanking implements ViewControllerInterface |
18
|
|
|
{ |
19
|
|
|
public const VIEW_IDENTIFIER = 'SHOW_SATISFIED_WORKER'; |
20
|
|
|
|
21
|
|
|
private DatabaseUiFactoryInterface $databaseUiFactory; |
22
|
|
|
|
23
|
|
|
private ColonyRepositoryInterface $colonyRepository; |
24
|
|
|
|
25
|
|
|
private ColonyLibFactoryInterface $colonyLibFactory; |
26
|
|
|
|
27
|
|
|
private LoggerUtilInterface $loggerUtil; |
28
|
|
|
|
29
|
|
|
public function __construct( |
30
|
|
|
DatabaseUiFactoryInterface $databaseUiFactory, |
31
|
|
|
ColonyRepositoryInterface $colonyRepository, |
32
|
|
|
ColonyLibFactoryInterface $colonyLibFactory, |
33
|
|
|
LoggerUtilFactoryInterface $loggerUtilFactory |
34
|
|
|
) { |
35
|
|
|
$this->databaseUiFactory = $databaseUiFactory; |
36
|
|
|
$this->colonyRepository = $colonyRepository; |
37
|
|
|
$this->colonyLibFactory = $colonyLibFactory; |
38
|
|
|
$this->loggerUtil = $loggerUtilFactory->getLoggerUtil(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function handle(GameControllerInterface $game): void |
42
|
|
|
{ |
43
|
|
|
$game->setNavigation([ |
44
|
|
|
[ |
45
|
|
|
'url' => 'database.php', |
46
|
|
|
'title' => 'Datenbank' |
47
|
|
|
], |
48
|
|
|
[ |
49
|
|
|
'url' => sprintf('database.php?%s=1', static::VIEW_IDENTIFIER), |
50
|
|
|
'title' => 'Die Top 10 der besten Arbeitgeber' |
51
|
|
|
] |
52
|
|
|
]); |
53
|
|
|
$game->setPageTitle('/ Datenbank / Die Top 10 besten Arbeitgeber'); |
54
|
|
|
$game->showMacro('html/database.xhtml/top_employer'); |
55
|
|
|
|
56
|
|
|
$game->setTemplateVar( |
57
|
|
|
'EMPLOYER_LIST', |
58
|
|
|
array_map( |
59
|
|
|
fn (array $data): DatabaseTopListWithPoints => $this->databaseUiFactory->createDatabaseTopListWithPoints($data['user_id'], (string)$data['satisfied']), |
60
|
|
|
$this->colonyRepository->getSatisfiedWorkerTop10() |
61
|
|
|
) |
62
|
|
|
); |
63
|
|
|
|
64
|
|
|
$this->setPointsForUser($game); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
private function setPointsForUser(GameControllerInterface $game): void |
68
|
|
|
{ |
69
|
|
|
$user = $game->getUser(); |
70
|
|
|
|
71
|
|
|
$colonies = $user->getColonies(); |
72
|
|
|
if ($colonies->isEmpty()) { |
73
|
|
|
return; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$satisfiedWorkers = 0; |
77
|
|
|
|
78
|
|
|
foreach ($colonies as $colony) { |
79
|
|
|
$workers = $colony->getWorkers(); |
80
|
|
|
|
81
|
|
|
$colonyProduction = $this->colonyLibFactory->createColonyCommodityProduction($colony)->getProduction(); |
82
|
|
|
if (array_key_exists(CommodityTypeEnum::COMMODITY_EFFECT_LIFE_STANDARD, $colonyProduction)) { |
83
|
|
|
$lifestandard = $colonyProduction[CommodityTypeEnum::COMMODITY_EFFECT_LIFE_STANDARD]->getProduction(); |
84
|
|
|
} else { |
85
|
|
|
$lifestandard = 0; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
$this->loggerUtil->log(sprintf('colony: %s, lifestandard: %d', $colony->getName(), $lifestandard)); |
89
|
|
|
|
90
|
|
|
$satisfiedWorkers += min($workers, $lifestandard); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
$game->setTemplateVar('USER_POINTS', (string) $satisfiedWorkers); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|