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
|
3 |
|
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
|
3 |
|
} |
31
|
|
|
|
32
|
3 |
|
#[Override] |
33
|
|
|
public function setTemplateVariables(GameControllerInterface $game): void |
34
|
|
|
{ |
35
|
3 |
|
if (!request::has('uid')) { |
36
|
1 |
|
$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
|
2 |
|
$visitor = $game->getUser(); |
47
|
|
|
|
48
|
2 |
|
$this->profileVisitorRegistration->register($user, $visitor); |
49
|
|
|
|
50
|
2 |
|
$game->setTemplateVar('PROFILE', $user); |
51
|
2 |
|
$game->setTemplateVar('COLONYSCANLIST', $this->getColonyScanList($user, $visitor)); |
52
|
2 |
|
$game->setTemplateVar( |
53
|
2 |
|
'DESCRIPTION', |
54
|
2 |
|
$this->parserWithImage->parse($user->getDescription())->getAsHTML() |
55
|
2 |
|
); |
56
|
2 |
|
$game->setTemplateVar( |
57
|
2 |
|
'IS_PROFILE_CURRENT_USER', |
58
|
2 |
|
$user === $visitor |
59
|
2 |
|
); |
60
|
2 |
|
$game->setTemplateVar( |
61
|
2 |
|
'RPG_PLOTS', |
62
|
2 |
|
$this->rpgPlotMemberRepository->getByUser($user) |
63
|
2 |
|
); |
64
|
2 |
|
$game->setTemplateVar( |
65
|
2 |
|
'CONTACT', |
66
|
2 |
|
$this->contactRepository->getByUserAndOpponent( |
67
|
2 |
|
$visitor->getId(), |
68
|
2 |
|
$user->getId() |
69
|
2 |
|
) |
70
|
2 |
|
); |
71
|
2 |
|
$game->setTemplateVar( |
72
|
2 |
|
'FRIENDS', |
73
|
2 |
|
$this->userRepository->getFriendsByUserAndAlliance( |
74
|
2 |
|
$user, |
75
|
2 |
|
$user->getAlliance() |
76
|
2 |
|
) |
77
|
2 |
|
); |
78
|
2 |
|
$game->setTemplateVar('CONTACT_LIST_MODES', ContactListModeEnum::cases()); |
79
|
2 |
|
$game->addExecuteJS("initTranslations();", GameEnum::JS_EXECUTION_AFTER_RENDER); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return array<int, ColonyScanInterface> |
84
|
|
|
*/ |
85
|
2 |
|
public function getColonyScanList(UserInterface $user, UserInterface $visitor): array |
86
|
|
|
{ |
87
|
2 |
|
$alliance = $visitor->getAlliance(); |
88
|
|
|
|
89
|
2 |
|
if ($alliance !== null) { |
90
|
1 |
|
$unfilteredScans = array_merge(...$alliance->getMembers()->map(fn (UserInterface $user) => $user->getColonyScans()->toArray())); |
91
|
|
|
} else { |
92
|
1 |
|
$unfilteredScans = $visitor->getColonyScans()->toArray(); |
93
|
|
|
} |
94
|
|
|
|
95
|
2 |
|
$filteredScans = array_filter( |
96
|
2 |
|
$unfilteredScans, |
97
|
2 |
|
fn (ColonyScanInterface $scan): bool => $scan->getColonyUserId() === $user->getId() |
98
|
2 |
|
); |
99
|
|
|
|
100
|
2 |
|
$scansByColony = []; |
101
|
2 |
|
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
|
2 |
|
$latestScans = []; |
110
|
2 |
|
foreach ($scansByColony as $scans) { |
111
|
1 |
|
usort($scans, fn ($a, $b): int => $b->getDate() <=> $a->getDate()); |
112
|
1 |
|
$latestScans[] = $scans[0]; |
113
|
|
|
} |
114
|
|
|
|
115
|
2 |
|
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