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 |
|
if (!request::has('uid')) { |
47
|
|
|
$user = $game->getUser(); |
48
|
|
|
} else { |
49
|
2 |
|
$userId = request::getIntFatal('uid'); |
50
|
|
|
|
51
|
2 |
|
$user = $this->userRepository->find($userId); |
52
|
2 |
|
if ($user === null) { |
53
|
1 |
|
throw new ItemNotFoundException(); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
1 |
|
$visitor = $game->getUser(); |
58
|
|
|
|
59
|
1 |
|
$this->profileVisitorRegistration->register($user, $visitor); |
60
|
|
|
|
61
|
1 |
|
$game->setTemplateVar('PROFILE', $user); |
62
|
1 |
|
$game->setTemplateVar( |
63
|
1 |
|
'DESCRIPTION', |
64
|
1 |
|
$this->parserWithImage->parse($user->getDescription())->getAsHTML() |
65
|
1 |
|
); |
66
|
1 |
|
$game->setTemplateVar( |
67
|
1 |
|
'IS_PROFILE_CURRENT_USER', |
68
|
1 |
|
$user === $visitor |
69
|
1 |
|
); |
70
|
1 |
|
$game->setTemplateVar( |
71
|
1 |
|
'RPG_PLOTS', |
72
|
1 |
|
$this->rpgPlotMemberRepository->getByUser($user) |
73
|
1 |
|
); |
74
|
1 |
|
$game->setTemplateVar( |
75
|
1 |
|
'CONTACT', |
76
|
1 |
|
$this->contactRepository->getByUserAndOpponent( |
77
|
1 |
|
$visitor->getId(), |
78
|
1 |
|
$user->getId() |
79
|
1 |
|
) |
80
|
1 |
|
); |
81
|
1 |
|
$game->setTemplateVar( |
82
|
1 |
|
'FRIENDS', |
83
|
1 |
|
$this->userRepository->getFriendsByUserAndAlliance( |
84
|
1 |
|
$user, |
85
|
1 |
|
$user->getAlliance() |
86
|
1 |
|
) |
87
|
1 |
|
); |
88
|
1 |
|
$game->setTemplateVar('CONTACT_LIST_MODES', ContactListModeEnum::cases()); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|