|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Module\Game\Lib\View\Provider; |
|
6
|
|
|
|
|
7
|
|
|
use request; |
|
8
|
|
|
use Stu\Lib\ParserWithImageInterface; |
|
9
|
|
|
use Stu\Module\Control\Exception\ItemNotFoundException; |
|
10
|
|
|
use Stu\Module\Control\GameControllerInterface; |
|
11
|
|
|
use Stu\Module\Game\Lib\View\Provider\ViewComponentProviderInterface; |
|
12
|
|
|
use Stu\Module\Message\Lib\ContactListModeEnum; |
|
13
|
|
|
use Stu\Module\PlayerProfile\Lib\ProfileVisitorRegistrationInterface; |
|
14
|
|
|
use Stu\Orm\Repository\ContactRepositoryInterface; |
|
15
|
|
|
use Stu\Orm\Repository\RpgPlotMemberRepositoryInterface; |
|
16
|
|
|
use Stu\Orm\Repository\UserRepositoryInterface; |
|
17
|
|
|
|
|
18
|
|
|
final class UserProfileProvider implements ViewComponentProviderInterface |
|
19
|
|
|
{ |
|
20
|
|
|
private RpgPlotMemberRepositoryInterface $rpgPlotMemberRepository; |
|
21
|
|
|
|
|
22
|
|
|
private ContactRepositoryInterface $contactRepository; |
|
23
|
|
|
|
|
24
|
|
|
private UserRepositoryInterface $userRepository; |
|
25
|
|
|
|
|
26
|
|
|
private ParserWithImageInterface $parserWithImage; |
|
27
|
|
|
|
|
28
|
|
|
private ProfileVisitorRegistrationInterface $profileVisitorRegistration; |
|
29
|
|
|
|
|
30
|
2 |
|
public function __construct( |
|
31
|
|
|
RpgPlotMemberRepositoryInterface $rpgPlotMemberRepository, |
|
32
|
|
|
ContactRepositoryInterface $contactRepository, |
|
33
|
|
|
UserRepositoryInterface $userRepository, |
|
34
|
|
|
ParserWithImageInterface $parserWithImage, |
|
35
|
|
|
ProfileVisitorRegistrationInterface $profileVisitorRegistration |
|
36
|
|
|
) { |
|
37
|
2 |
|
$this->rpgPlotMemberRepository = $rpgPlotMemberRepository; |
|
38
|
2 |
|
$this->contactRepository = $contactRepository; |
|
39
|
2 |
|
$this->userRepository = $userRepository; |
|
40
|
2 |
|
$this->parserWithImage = $parserWithImage; |
|
41
|
2 |
|
$this->profileVisitorRegistration = $profileVisitorRegistration; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
2 |
|
public function setTemplateVariables(GameControllerInterface $game): void |
|
45
|
|
|
{ |
|
46
|
2 |
|
$playerId = request::getIntFatal('uid'); |
|
47
|
|
|
|
|
48
|
2 |
|
$player = $this->userRepository->find($playerId); |
|
49
|
2 |
|
if ($player === null) { |
|
50
|
1 |
|
throw new ItemNotFoundException(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
1 |
|
$user = $game->getUser(); |
|
54
|
1 |
|
$userId = $user->getId(); |
|
55
|
|
|
|
|
56
|
1 |
|
$this->profileVisitorRegistration->register($player, $user); |
|
57
|
|
|
|
|
58
|
1 |
|
$game->setTemplateVar('PROFILE', $player); |
|
59
|
1 |
|
$game->setTemplateVar( |
|
60
|
1 |
|
'DESCRIPTION', |
|
61
|
1 |
|
$this->parserWithImage->parse($player->getDescription())->getAsHTML() |
|
62
|
1 |
|
); |
|
63
|
1 |
|
$game->setTemplateVar( |
|
64
|
1 |
|
'IS_PROFILE_CURRENT_USER', |
|
65
|
1 |
|
$playerId === $userId |
|
66
|
1 |
|
); |
|
67
|
1 |
|
$game->setTemplateVar( |
|
68
|
1 |
|
'RPG_PLOTS', |
|
69
|
1 |
|
$this->rpgPlotMemberRepository->getByUser($player) |
|
70
|
1 |
|
); |
|
71
|
1 |
|
$game->setTemplateVar( |
|
72
|
1 |
|
'CONTACT', |
|
73
|
1 |
|
$this->contactRepository->getByUserAndOpponent( |
|
74
|
1 |
|
$userId, |
|
75
|
1 |
|
$playerId |
|
76
|
1 |
|
) |
|
77
|
1 |
|
); |
|
78
|
1 |
|
$game->setTemplateVar( |
|
79
|
1 |
|
'FRIENDS', |
|
80
|
1 |
|
$this->userRepository->getFriendsByUserAndAlliance( |
|
81
|
1 |
|
$player, |
|
82
|
1 |
|
$player->getAlliance() |
|
83
|
1 |
|
) |
|
84
|
1 |
|
); |
|
85
|
1 |
|
$game->setTemplateVar('CONTACT_LIST_MODES', ContactListModeEnum::cases()); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|