|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Module\Spacecraft\View\ShowTradeMenu; |
|
6
|
|
|
|
|
7
|
|
|
use Override; |
|
8
|
|
|
use request; |
|
9
|
|
|
use Stu\Exception\AccessViolationException; |
|
10
|
|
|
use Stu\Module\Control\GameControllerInterface; |
|
11
|
|
|
use Stu\Module\Control\ViewContextTypeEnum; |
|
12
|
|
|
use Stu\Module\Control\ViewControllerInterface; |
|
13
|
|
|
use Stu\Module\Spacecraft\Lib\Interaction\InteractionCheckerInterface; |
|
14
|
|
|
use Stu\Module\Spacecraft\Lib\SpacecraftLoaderInterface; |
|
15
|
|
|
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface; |
|
16
|
|
|
use Stu\Module\Trade\Lib\TradeLibFactoryInterface; |
|
17
|
|
|
use Stu\Orm\Repository\CommodityRepositoryInterface; |
|
18
|
|
|
use Stu\Orm\Repository\TradeLicenseInfoRepositoryInterface; |
|
19
|
|
|
use Stu\Orm\Repository\TradeLicenseRepositoryInterface; |
|
20
|
|
|
use Stu\Orm\Repository\TradePostRepositoryInterface; |
|
21
|
|
|
|
|
22
|
|
|
final class ShowTradeMenu implements ViewControllerInterface |
|
23
|
|
|
{ |
|
24
|
|
|
public const string VIEW_IDENTIFIER = 'SHOW_TRADEMENU'; |
|
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @param SpacecraftLoaderInterface<SpacecraftWrapperInterface> $spaceCraftLoader |
|
28
|
|
|
*/ |
|
29
|
1 |
|
public function __construct( |
|
30
|
|
|
private TradeLicenseRepositoryInterface $tradeLicenseRepository, |
|
31
|
|
|
private TradeLicenseInfoRepositoryInterface $TradeLicenseInfoRepository, |
|
32
|
|
|
private TradeLibFactoryInterface $tradeLibFactory, |
|
33
|
|
|
private TradePostRepositoryInterface $tradePostRepository, |
|
34
|
|
|
private CommodityRepositoryInterface $commodityRepository, |
|
35
|
|
|
private InteractionCheckerInterface $interactionChecker, |
|
36
|
|
|
private SpacecraftLoaderInterface $spaceCraftLoader |
|
37
|
1 |
|
) {} |
|
38
|
|
|
|
|
39
|
1 |
|
#[Override] |
|
40
|
|
|
public function handle(GameControllerInterface $game): void |
|
41
|
|
|
{ |
|
42
|
1 |
|
$userId = $game->getUser()->getId(); |
|
43
|
|
|
|
|
44
|
1 |
|
$spacecraft = $this->spaceCraftLoader->getByIdAndUser(request::getIntFatal('id'), $userId); |
|
45
|
|
|
|
|
46
|
1 |
|
$tradepost = $this->tradePostRepository->find(request::indInt('postid')); |
|
47
|
1 |
|
if ($tradepost === null) { |
|
48
|
|
|
return; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
1 |
|
if (!$this->interactionChecker->checkPosition($spacecraft, $tradepost->getStation())) { |
|
52
|
|
|
throw new AccessViolationException(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
1 |
|
$game->setPageTitle(_('Handelstransfermenü')); |
|
56
|
1 |
|
if ($game->getViewContext(ViewContextTypeEnum::NO_AJAX) === true) { |
|
57
|
|
|
$game->showMacro('html/spacecraft/trademenu.twig'); |
|
58
|
|
|
} else { |
|
59
|
1 |
|
$game->setMacroInAjaxWindow('html/spacecraft/trademenu.twig'); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
1 |
|
$databaseEntryId = $tradepost->getStation()->getDatabaseId(); |
|
63
|
|
|
|
|
64
|
1 |
|
if ($databaseEntryId > 0) { |
|
65
|
|
|
$game->checkDatabaseItem($databaseEntryId); |
|
66
|
|
|
} |
|
67
|
1 |
|
$licenseInfo = $this->TradeLicenseInfoRepository->getLatestLicenseInfo($tradepost->getId()); |
|
68
|
|
|
|
|
69
|
1 |
|
if ($licenseInfo !== null) { |
|
70
|
1 |
|
$commodityId = $licenseInfo->getCommodityId(); |
|
71
|
1 |
|
$commodity = $this->commodityRepository->find($commodityId); |
|
72
|
1 |
|
$commodityName = $commodity !== null ? $commodity->getName() : ''; |
|
73
|
1 |
|
$licensecost = $licenseInfo->getAmount(); |
|
74
|
1 |
|
$licensedays = $licenseInfo->getDays(); |
|
75
|
|
|
} else { |
|
76
|
|
|
$commodityId = 1; |
|
77
|
|
|
$commodityName = 'Keine Ware'; |
|
78
|
|
|
$licensecost = 0; |
|
79
|
|
|
$licensedays = 0; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
1 |
|
$game->setTemplateVar('TRADEPOST', $this->tradeLibFactory->createTradeAccountWrapper($tradepost, $userId)); |
|
83
|
1 |
|
$game->setTemplateVar('SHIP', $spacecraft); |
|
84
|
1 |
|
$game->setTemplateVar( |
|
85
|
1 |
|
'HAS_LICENSE', |
|
86
|
1 |
|
$this->tradeLicenseRepository->hasLicenseByUserAndTradePost($userId, $tradepost->getId()) |
|
87
|
1 |
|
); |
|
88
|
1 |
|
$game->setTemplateVar( |
|
89
|
1 |
|
'CAN_BUY_LICENSE', |
|
90
|
1 |
|
$licenseInfo !== null |
|
91
|
1 |
|
); |
|
92
|
1 |
|
$game->setTemplateVar('LICENSECOMMODITY', $commodityId); |
|
93
|
1 |
|
$game->setTemplateVar('LICENSECOMMODITYNAME', $commodityName); |
|
94
|
1 |
|
$game->setTemplateVar('LICENSECOST', $licensecost); |
|
95
|
1 |
|
$game->setTemplateVar('LICENSEDAYS', $licensedays); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|