|
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
|
|
|
use Stu\Component\Game\GameEnum; |
|
18
|
|
|
use Stu\Orm\Entity\UserInterface; |
|
19
|
|
|
use Stu\Orm\Repository\ColonyScanRepositoryInterface; |
|
20
|
|
|
use Stu\Orm\Entity\ColonyScanInterface; |
|
21
|
|
|
|
|
22
|
|
|
final class UserProfileProvider implements ViewComponentProviderInterface |
|
23
|
|
|
{ |
|
24
|
|
|
private RpgPlotMemberRepositoryInterface $rpgPlotMemberRepository; |
|
25
|
|
|
|
|
26
|
|
|
private ContactRepositoryInterface $contactRepository; |
|
27
|
|
|
|
|
28
|
|
|
private UserRepositoryInterface $userRepository; |
|
29
|
|
|
|
|
30
|
|
|
private ParserWithImageInterface $parserWithImage; |
|
31
|
|
|
|
|
32
|
|
|
private ColonyScanRepositoryInterface $colonyScanRepository; |
|
33
|
|
|
|
|
34
|
|
|
private ProfileVisitorRegistrationInterface $profileVisitorRegistration; |
|
35
|
|
|
|
|
36
|
2 |
|
public function __construct( |
|
37
|
|
|
RpgPlotMemberRepositoryInterface $rpgPlotMemberRepository, |
|
38
|
|
|
ColonyScanRepositoryInterface $colonyScanRepository, |
|
39
|
|
|
ContactRepositoryInterface $contactRepository, |
|
40
|
|
|
UserRepositoryInterface $userRepository, |
|
41
|
|
|
ParserWithImageInterface $parserWithImage, |
|
42
|
|
|
ProfileVisitorRegistrationInterface $profileVisitorRegistration |
|
43
|
|
|
) { |
|
44
|
2 |
|
$this->rpgPlotMemberRepository = $rpgPlotMemberRepository; |
|
45
|
2 |
|
$this->colonyScanRepository = $colonyScanRepository; |
|
46
|
2 |
|
$this->contactRepository = $contactRepository; |
|
47
|
2 |
|
$this->userRepository = $userRepository; |
|
48
|
2 |
|
$this->parserWithImage = $parserWithImage; |
|
49
|
2 |
|
$this->profileVisitorRegistration = $profileVisitorRegistration; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
2 |
|
public function setTemplateVariables(GameControllerInterface $game): void |
|
53
|
|
|
{ |
|
54
|
2 |
|
if (!request::has('uid')) { |
|
55
|
|
|
$user = $game->getUser(); |
|
56
|
|
|
} else { |
|
57
|
2 |
|
$userId = request::getIntFatal('uid'); |
|
58
|
|
|
|
|
59
|
2 |
|
$user = $this->userRepository->find($userId); |
|
60
|
2 |
|
if ($user === null) { |
|
61
|
1 |
|
throw new ItemNotFoundException(); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
1 |
|
$visitor = $game->getUser(); |
|
66
|
|
|
|
|
67
|
1 |
|
$this->profileVisitorRegistration->register($user, $visitor); |
|
68
|
|
|
|
|
69
|
1 |
|
$game->setTemplateVar('PROFILE', $user); |
|
70
|
1 |
|
$game->setTemplateVar('COLONYSCANLIST', $this->getColonyScanList($visitor, $user->getId())); |
|
71
|
1 |
|
$game->setTemplateVar( |
|
72
|
1 |
|
'DESCRIPTION', |
|
73
|
1 |
|
$this->parserWithImage->parse($user->getDescription())->getAsHTML() |
|
74
|
1 |
|
); |
|
75
|
1 |
|
$game->setTemplateVar( |
|
76
|
1 |
|
'IS_PROFILE_CURRENT_USER', |
|
77
|
1 |
|
$user === $visitor |
|
78
|
1 |
|
); |
|
79
|
1 |
|
$game->setTemplateVar( |
|
80
|
1 |
|
'RPG_PLOTS', |
|
81
|
1 |
|
$this->rpgPlotMemberRepository->getByUser($user) |
|
82
|
1 |
|
); |
|
83
|
1 |
|
$game->setTemplateVar( |
|
84
|
1 |
|
'CONTACT', |
|
85
|
1 |
|
$this->contactRepository->getByUserAndOpponent( |
|
86
|
1 |
|
$visitor->getId(), |
|
87
|
1 |
|
$user->getId() |
|
88
|
1 |
|
) |
|
89
|
1 |
|
); |
|
90
|
1 |
|
$game->setTemplateVar( |
|
91
|
1 |
|
'FRIENDS', |
|
92
|
1 |
|
$this->userRepository->getFriendsByUserAndAlliance( |
|
93
|
1 |
|
$user, |
|
94
|
1 |
|
$user->getAlliance() |
|
95
|
1 |
|
) |
|
96
|
1 |
|
); |
|
97
|
1 |
|
$game->setTemplateVar('CONTACT_LIST_MODES', ContactListModeEnum::cases()); |
|
98
|
1 |
|
$game->addExecuteJS("initTranslations();", GameEnum::JS_EXECUTION_AFTER_RENDER); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @return array<ColonyScanInterface> |
|
103
|
|
|
*/ |
|
104
|
1 |
|
public function getColonyScanList(UserInterface $visitor, int $user): iterable |
|
105
|
|
|
{ |
|
106
|
1 |
|
$scanlist = []; |
|
107
|
|
|
|
|
108
|
1 |
|
foreach ($this->colonyScanRepository->getEntryByUserAndVisitor($visitor->getId(), $user) as $element) { |
|
109
|
1 |
|
$i = $element->getColony()->getId(); |
|
110
|
1 |
|
$scanlist[$i] = $element; |
|
111
|
|
|
} |
|
112
|
1 |
|
return $scanlist; |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|