|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Module\Game\Lib\View\Provider; |
|
6
|
|
|
|
|
7
|
|
|
use Override; |
|
|
|
|
|
|
8
|
|
|
use request; |
|
9
|
|
|
use Stu\Component\Game\GameEnum; |
|
|
|
|
|
|
10
|
|
|
use Stu\Lib\ParserWithImageInterface; |
|
11
|
|
|
use Stu\Module\Control\Exception\ItemNotFoundException; |
|
12
|
|
|
use Stu\Module\Control\GameControllerInterface; |
|
13
|
|
|
use Stu\Module\Message\Lib\ContactListModeEnum; |
|
14
|
|
|
use Stu\Module\PlayerProfile\Lib\ProfileVisitorRegistrationInterface; |
|
15
|
|
|
use Stu\Orm\Entity\ColonyScanInterface; |
|
16
|
|
|
use Stu\Orm\Entity\UserInterface; |
|
17
|
|
|
use Stu\Orm\Repository\ContactRepositoryInterface; |
|
18
|
|
|
use Stu\Orm\Repository\RpgPlotMemberRepositoryInterface; |
|
19
|
|
|
use Stu\Orm\Repository\UserRepositoryInterface; |
|
20
|
|
|
|
|
21
|
|
|
final class UserProfileProvider implements ViewComponentProviderInterface |
|
22
|
|
|
{ |
|
23
|
2 |
|
public function __construct( |
|
24
|
|
|
private RpgPlotMemberRepositoryInterface $rpgPlotMemberRepository, |
|
25
|
|
|
private ContactRepositoryInterface $contactRepository, |
|
26
|
|
|
private UserRepositoryInterface $userRepository, |
|
27
|
|
|
private ParserWithImageInterface $parserWithImage, |
|
28
|
|
|
private ProfileVisitorRegistrationInterface $profileVisitorRegistration |
|
29
|
|
|
) { |
|
30
|
2 |
|
} |
|
31
|
|
|
|
|
32
|
2 |
|
#[Override] |
|
33
|
|
|
public function setTemplateVariables(GameControllerInterface $game): void |
|
34
|
|
|
{ |
|
35
|
2 |
|
if (!request::has('uid')) { |
|
36
|
|
|
$user = $game->getUser(); |
|
37
|
|
|
} else { |
|
38
|
2 |
|
$userId = request::getIntFatal('uid'); |
|
39
|
|
|
|
|
40
|
2 |
|
$user = $this->userRepository->find($userId); |
|
41
|
2 |
|
if ($user === null) { |
|
42
|
1 |
|
throw new ItemNotFoundException(); |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
1 |
|
$visitor = $game->getUser(); |
|
47
|
|
|
|
|
48
|
1 |
|
$this->profileVisitorRegistration->register($user, $visitor); |
|
49
|
|
|
|
|
50
|
1 |
|
$game->setTemplateVar('PROFILE', $user); |
|
51
|
1 |
|
$game->setTemplateVar('COLONYSCANLIST', $this->getColonyScanList($user, $visitor)); |
|
52
|
1 |
|
$game->setTemplateVar( |
|
53
|
1 |
|
'DESCRIPTION', |
|
54
|
1 |
|
$this->parserWithImage->parse($user->getDescription())->getAsHTML() |
|
55
|
1 |
|
); |
|
56
|
1 |
|
$game->setTemplateVar( |
|
57
|
1 |
|
'IS_PROFILE_CURRENT_USER', |
|
58
|
1 |
|
$user === $visitor |
|
59
|
1 |
|
); |
|
60
|
1 |
|
$game->setTemplateVar( |
|
61
|
1 |
|
'RPG_PLOTS', |
|
62
|
1 |
|
$this->rpgPlotMemberRepository->getByUser($user) |
|
63
|
1 |
|
); |
|
64
|
1 |
|
$game->setTemplateVar( |
|
65
|
1 |
|
'CONTACT', |
|
66
|
1 |
|
$this->contactRepository->getByUserAndOpponent( |
|
67
|
1 |
|
$visitor->getId(), |
|
68
|
1 |
|
$user->getId() |
|
69
|
1 |
|
) |
|
70
|
1 |
|
); |
|
71
|
1 |
|
$game->setTemplateVar( |
|
72
|
1 |
|
'FRIENDS', |
|
73
|
1 |
|
$this->userRepository->getFriendsByUserAndAlliance( |
|
74
|
1 |
|
$user, |
|
75
|
1 |
|
$user->getAlliance() |
|
76
|
1 |
|
) |
|
77
|
1 |
|
); |
|
78
|
1 |
|
$game->setTemplateVar('CONTACT_LIST_MODES', ContactListModeEnum::cases()); |
|
79
|
1 |
|
$game->addExecuteJS("initTranslations();", GameEnum::JS_EXECUTION_AFTER_RENDER); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @return array<int, ColonyScanInterface> |
|
84
|
|
|
*/ |
|
85
|
1 |
|
public function getColonyScanList(UserInterface $user, UserInterface $visitor): array |
|
86
|
|
|
{ |
|
87
|
1 |
|
$alliance = $visitor->getAlliance(); |
|
88
|
|
|
|
|
89
|
1 |
|
if ($alliance !== null) { |
|
90
|
|
|
$unfilteredScans = array_merge(...$alliance->getMembers()->map(fn (UserInterface $user) => $user->getColonyScans()->toArray())); |
|
91
|
|
|
} else { |
|
92
|
1 |
|
$unfilteredScans = $visitor->getColonyScans()->toArray(); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
1 |
|
$filteredScans = array_filter( |
|
96
|
1 |
|
$unfilteredScans, |
|
97
|
1 |
|
fn (ColonyScanInterface $scan): bool => $scan->getColonyUserId() === $user->getId() |
|
98
|
1 |
|
); |
|
99
|
|
|
|
|
100
|
1 |
|
$scansByColony = []; |
|
101
|
1 |
|
foreach ($filteredScans as $scan) { |
|
102
|
1 |
|
$colonyId = $scan->getColony()->getId(); |
|
103
|
1 |
|
if (!isset($scansByColony[$colonyId])) { |
|
104
|
1 |
|
$scansByColony[$colonyId] = []; |
|
105
|
|
|
} |
|
106
|
1 |
|
$scansByColony[$colonyId][] = $scan; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
1 |
|
$latestScans = []; |
|
110
|
1 |
|
foreach ($scansByColony as $colonyId => $scans) { |
|
111
|
1 |
|
usort($scans, fn ($a, $b) => $b->getDate() <=> $a->getDate()); |
|
112
|
1 |
|
$latestScans[] = $scans[0]; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
1 |
|
return $latestScans; |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths