1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Module\Trade\Action\SearchOffers; |
6
|
|
|
|
7
|
|
|
use request; |
8
|
|
|
|
9
|
|
|
use Stu\Component\Game\GameEnum; |
10
|
|
|
use Stu\Component\Game\ModuleViewEnum; |
11
|
|
|
use Stu\Component\Trade\TradeEnum; |
12
|
|
|
use Stu\Lib\SessionInterface; |
13
|
|
|
use Stu\Module\Control\ActionControllerInterface; |
14
|
|
|
use Stu\Module\Control\GameControllerInterface; |
15
|
|
|
use Stu\Module\Trade\Lib\TradeOfferItem; |
16
|
|
|
use Stu\Module\Trade\Lib\TradeOfferItemInterface; |
17
|
|
|
use Stu\Orm\Entity\TradeOfferInterface; |
18
|
|
|
use Stu\Orm\Repository\CommodityRepositoryInterface; |
19
|
|
|
use Stu\Orm\Repository\TradeLicenseRepositoryInterface; |
20
|
|
|
use Stu\Orm\Repository\TradeOfferRepositoryInterface; |
21
|
|
|
|
22
|
|
|
final class SearchOffer implements ActionControllerInterface |
23
|
|
|
{ |
24
|
|
|
public const ACTION_IDENTIFIER = 'B_TRADE_SEARCH_OFFER'; |
25
|
|
|
|
26
|
|
|
private TradeLicenseRepositoryInterface $tradeLicenseRepository; |
27
|
|
|
|
28
|
|
|
private TradeOfferRepositoryInterface $tradeOfferRepository; |
29
|
|
|
|
30
|
|
|
private CommodityRepositoryInterface $commodityRepository; |
31
|
|
|
|
32
|
|
|
private SessionInterface $session; |
33
|
|
|
|
34
|
|
|
public function __construct( |
35
|
|
|
TradeLicenseRepositoryInterface $tradeLicenseRepository, |
36
|
|
|
TradeOfferRepositoryInterface $tradeOfferRepository, |
37
|
|
|
CommodityRepositoryInterface $commodityRepository, |
38
|
|
|
SessionInterface $session |
39
|
|
|
) { |
40
|
|
|
$this->tradeLicenseRepository = $tradeLicenseRepository; |
41
|
|
|
$this->tradeOfferRepository = $tradeOfferRepository; |
42
|
|
|
$this->commodityRepository = $commodityRepository; |
43
|
|
|
$this->session = $session; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function handle(GameControllerInterface $game): void |
47
|
|
|
{ |
48
|
|
|
$user = $game->getUser(); |
49
|
|
|
$userId = $user->getId(); |
50
|
|
|
|
51
|
|
|
$commodityId = request::postIntFatal('cid'); |
52
|
|
|
$postId = request::postIntFatal('pid') > 0 ? request::postIntFatal('pid') : null; |
53
|
|
|
|
54
|
|
|
$game->appendNavigationPart( |
55
|
|
|
'trade.php', |
56
|
|
|
_('Handel') |
57
|
|
|
); |
58
|
|
|
|
59
|
|
|
$game->setView(ModuleViewEnum::TRADE, ['FILTER_ACTIVE' => true]); |
60
|
|
|
|
61
|
|
|
$game->setTemplateVar('POST_ID', request::postIntFatal('pid')); |
62
|
|
|
$game->setTemplateVar('COMMODITY_ID', $commodityId); |
63
|
|
|
|
64
|
|
|
$this->session->deleteSessionData('trade_filter_cid'); |
65
|
|
|
$this->session->deleteSessionData('trade_filter_pid'); |
66
|
|
|
$this->session->deleteSessionData('trade_filter_dir'); |
67
|
|
|
|
68
|
|
|
$this->session->storeSessionData('trade_filter_cid', $commodityId, true); |
69
|
|
|
$this->session->storeSessionData('trade_filter_pid', $postId, true); |
70
|
|
|
$this->session->storeSessionData('trade_filter_dir', TradeEnum::FILTER_COMMODITY_IN_OFFER, true); |
71
|
|
|
|
72
|
|
|
$tradeLicenses = $this->tradeLicenseRepository->getByUser($userId); |
73
|
|
|
$game->setTemplateVar('TRADE_LICENSES', $tradeLicenses); |
74
|
|
|
$game->setTemplateVar('TRADE_LICENSE_COUNT', count($tradeLicenses)); |
75
|
|
|
|
76
|
|
|
$commodityList = $this->commodityRepository->getTradeable(); |
77
|
|
|
$game->setTemplateVar('SELECTABLE_COMMODITIES', $commodityList); |
78
|
|
|
|
79
|
|
|
$game->setTemplateVar('MAX_TRADE_LICENSE_COUNT', GameEnum::MAX_TRADELICENSE_COUNT); |
80
|
|
|
$game->setTemplateVar( |
81
|
|
|
'OFFER_LIST', |
82
|
|
|
array_map( |
83
|
|
|
fn (TradeOfferInterface $tradeOffer): TradeOfferItemInterface => new TradeOfferItem($tradeOffer, $user), |
84
|
|
|
$this->tradeOfferRepository->getByUserLicenses($userId, $commodityId, $postId, TradeEnum::FILTER_COMMODITY_IN_OFFER) |
85
|
|
|
) |
86
|
|
|
); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function performSessionCheck(): bool |
90
|
|
|
{ |
91
|
|
|
return true; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|