1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Module\Starmap\Lib; |
6
|
|
|
|
7
|
|
|
use RuntimeException; |
8
|
|
|
use Stu\Component\Map\EncodedMapInterface; |
9
|
|
|
use Stu\Orm\Entity\LayerInterface; |
10
|
|
|
use Stu\Orm\Entity\UserInterface; |
11
|
|
|
use Stu\Orm\Repository\MapRepositoryInterface; |
12
|
|
|
use Stu\Orm\Repository\StarSystemMapRepositoryInterface; |
13
|
|
|
|
14
|
|
|
class UserYRow extends YRow |
15
|
|
|
{ |
16
|
|
|
private UserInterface $user; |
17
|
|
|
|
18
|
|
|
private MapRepositoryInterface $mapRepository; |
19
|
|
|
private StarmapUiFactoryInterface $starmapUiFactory; |
20
|
|
|
|
21
|
1 |
|
public function __construct( |
22
|
|
|
StarmapUiFactoryInterface $starmapUiFactory, |
23
|
|
|
MapRepositoryInterface $mapRepository, |
24
|
|
|
StarSystemMapRepositoryInterface $starSystemMapRepository, |
25
|
|
|
EncodedMapInterface $encodedMap, |
26
|
|
|
UserInterface $user, |
27
|
|
|
LayerInterface $layer, |
28
|
|
|
int $cury, |
29
|
|
|
int $minx, |
30
|
|
|
int $maxx, |
31
|
|
|
int $systemId = 0 |
32
|
|
|
) { |
33
|
1 |
|
parent::__construct( |
34
|
1 |
|
$mapRepository, |
35
|
1 |
|
$starSystemMapRepository, |
36
|
1 |
|
$encodedMap, |
37
|
1 |
|
$layer, |
38
|
1 |
|
$cury, |
39
|
1 |
|
$minx, |
40
|
1 |
|
$maxx, |
41
|
1 |
|
$systemId |
42
|
1 |
|
); |
43
|
1 |
|
$this->user = $user; |
44
|
1 |
|
$this->mapRepository = $mapRepository; |
45
|
1 |
|
$this->starmapUiFactory = $starmapUiFactory; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @return array<ExplorableStarMapItemInterface> |
50
|
|
|
*/ |
51
|
|
|
public function getFields(): array |
52
|
|
|
{ |
53
|
|
|
$layer = $this->layer; |
54
|
|
|
if ($layer === null) { |
55
|
|
|
throw new RuntimeException('this should not happen'); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$maps = $this->mapRepository->getExplored( |
59
|
|
|
$this->user->getId(), |
60
|
|
|
$layer->getId(), |
61
|
|
|
$this->minx, |
62
|
|
|
$this->maxx, |
63
|
|
|
$this->row |
64
|
|
|
); |
65
|
|
|
$hasExploredLayer = $this->user->hasExplored($layer->getId()); |
66
|
|
|
|
67
|
|
|
$result = []; |
68
|
|
|
|
69
|
|
|
foreach ($maps as $item) { |
70
|
|
|
|
71
|
|
|
$starmapItem = $this->starmapUiFactory->createExplorableStarmapItem($item, $layer); |
72
|
|
|
if (!$hasExploredLayer && $item->getUserId() === null) { |
73
|
|
|
$starmapItem->setHide(true); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$result[$item->getCx()] = $starmapItem; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
return $result; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|