1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Orm\Repository; |
6
|
|
|
|
7
|
|
|
use Doctrine\ORM\EntityRepository; |
8
|
|
|
use Doctrine\ORM\Query\ResultSetMapping; |
9
|
|
|
use Override; |
|
|
|
|
10
|
|
|
use Stu\Component\Spacecraft\SpacecraftRumpEnum; |
|
|
|
|
11
|
|
|
use Stu\Component\Spacecraft\System\SpacecraftSystemModeEnum; |
12
|
|
|
use Stu\Component\Spacecraft\System\SpacecraftSystemTypeEnum; |
13
|
|
|
use Stu\Module\PlayerSetting\Lib\UserEnum; |
|
|
|
|
14
|
|
|
use Stu\Module\Ship\Lib\TFleetShipItem; |
15
|
|
|
use Stu\Module\Ship\Lib\TShipItem; |
16
|
|
|
use Stu\Orm\Entity\Crew; |
17
|
|
|
use Stu\Orm\Entity\Location; |
18
|
|
|
use Stu\Orm\Entity\Map; |
19
|
|
|
use Stu\Orm\Entity\MapInterface; |
20
|
|
|
use Stu\Orm\Entity\CrewAssignment; |
21
|
|
|
use Stu\Orm\Entity\LocationInterface; |
22
|
|
|
use Stu\Orm\Entity\SpacecraftRump; |
23
|
|
|
use Stu\Orm\Entity\SpacecraftRumpInterface; |
24
|
|
|
use Stu\Orm\Entity\Spacecraft; |
25
|
|
|
use Stu\Orm\Entity\SpacecraftInterface; |
26
|
|
|
use Stu\Orm\Entity\SpacecraftSystem; |
27
|
|
|
use Stu\Orm\Entity\StarSystemMap; |
28
|
|
|
use Stu\Orm\Entity\StarSystemMapInterface; |
29
|
|
|
use Stu\Orm\Entity\Station; |
30
|
|
|
use Stu\Orm\Entity\StationInterface; |
31
|
|
|
use Stu\Orm\Entity\TradePost; |
32
|
|
|
use Stu\Orm\Entity\User; |
33
|
|
|
use Stu\Orm\Entity\UserInterface; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @extends EntityRepository<Station> |
37
|
|
|
*/ |
38
|
|
|
final class StationRepository extends EntityRepository implements StationRepositoryInterface |
39
|
|
|
{ |
40
|
|
|
#[Override] |
41
|
|
|
public function prototype(): StationInterface |
42
|
|
|
{ |
43
|
|
|
return new Station(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
#[Override] |
47
|
|
|
public function save(StationInterface $station): void |
48
|
|
|
{ |
49
|
|
|
$em = $this->getEntityManager(); |
50
|
|
|
|
51
|
|
|
$em->persist($station); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
#[Override] |
55
|
|
|
public function delete(StationInterface $station): void |
56
|
|
|
{ |
57
|
|
|
$em = $this->getEntityManager(); |
58
|
|
|
|
59
|
|
|
$em->remove($station); |
60
|
|
|
} |
61
|
|
|
|
62
|
1 |
|
#[Override] |
63
|
|
|
public function getByUser(int $userId): array |
64
|
|
|
{ |
65
|
1 |
|
return $this->findBy( |
66
|
1 |
|
[ |
67
|
1 |
|
'user_id' => $userId |
68
|
1 |
|
], |
69
|
1 |
|
['max_huelle' => 'desc', 'id' => 'asc'] |
70
|
1 |
|
); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
#[Override] |
74
|
|
|
public function getForeignStationsInBroadcastRange(SpacecraftInterface $spacecraft): array |
75
|
|
|
{ |
76
|
|
|
$layer = $spacecraft->getLayer(); |
77
|
|
|
$systemMap = $spacecraft->getStarsystemMap(); |
78
|
|
|
$map = $spacecraft->getMap(); |
79
|
|
|
|
80
|
|
|
return $this->getEntityManager() |
81
|
|
|
->createQuery( |
82
|
|
|
sprintf( |
83
|
|
|
'SELECT st FROM %s st |
84
|
|
|
JOIN %s s |
85
|
|
|
WITH st.id = s.id |
86
|
|
|
LEFT JOIN %s m |
87
|
|
|
WITH s.location_id = m.id |
88
|
|
|
LEFT JOIN %s l |
89
|
|
|
WITH m.id = l.id |
90
|
|
|
LEFT JOIN %s sm |
91
|
|
|
WITH s.location_id = sm.id |
92
|
|
|
WHERE s.user_id NOT IN (:ignoreIds) |
93
|
|
|
AND (:layerId = 0 OR (l.layer_id = :layerId |
94
|
|
|
AND l.cx BETWEEN (:cx - 1) AND (:cx + 1) |
95
|
|
|
AND l.cy BETWEEN (:cy - 1) AND (:cy + 1))) |
96
|
|
|
AND (:systemId = 0 OR (sm.systems_id = :systemId |
97
|
|
|
AND sm.sx BETWEEN (:sx - 1) AND (:sx + 1) |
98
|
|
|
AND sm.sy BETWEEN (:sy - 1) AND (:sy + 1)))', |
99
|
|
|
Station::class, |
100
|
|
|
Spacecraft::class, |
101
|
|
|
Map::class, |
102
|
|
|
Location::class, |
103
|
|
|
StarSystemMap::class |
104
|
|
|
) |
105
|
|
|
) |
106
|
|
|
->setParameters([ |
107
|
|
|
'ignoreIds' => [$spacecraft->getUser()->getId(), UserEnum::USER_NOONE], |
108
|
|
|
'systemId' => $systemMap === null ? 0 : $systemMap->getSystem()->getId(), |
109
|
|
|
'sx' => $systemMap === null ? 0 : $systemMap->getSx(), |
110
|
|
|
'sy' => $systemMap === null ? 0 : $systemMap->getSy(), |
111
|
|
|
'layerId' => ($systemMap !== null || $layer === null) ? 0 : $layer->getId(), |
112
|
|
|
'cx' => ($systemMap !== null || $map === null) ? 0 : $map->getCx(), |
113
|
|
|
'cy' => ($systemMap !== null || $map === null) ? 0 : $map->getCy() |
114
|
|
|
]) |
115
|
|
|
->getResult(); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
#[Override] |
119
|
|
|
public function getTradePostsWithoutDatabaseEntry(): array |
120
|
|
|
{ |
121
|
|
|
return $this->getEntityManager()->createQuery( |
122
|
|
|
sprintf( |
123
|
|
|
'SELECT s FROM %s s |
124
|
|
|
JOIN %s tp |
125
|
|
|
WITH s.tradePost = tp |
126
|
|
|
WHERE s.database_id is null', |
127
|
|
|
Station::class, |
128
|
|
|
TradePost::class |
129
|
|
|
) |
130
|
|
|
)->getResult(); |
131
|
|
|
} |
132
|
|
|
|
133
|
1 |
|
#[Override] |
134
|
|
|
public function getByUplink(int $userId): array |
135
|
|
|
{ |
136
|
1 |
|
return $this->getEntityManager()->createQuery( |
137
|
1 |
|
sprintf( |
138
|
1 |
|
'SELECT s FROM %s s |
139
|
|
|
JOIN %s sp |
140
|
|
|
WITH s.id = sp.id |
141
|
|
|
JOIN %s sc |
142
|
|
|
WITH s.id = sc.spacecraft_id |
143
|
|
|
JOIN %s c |
144
|
|
|
WITH sc.crew_id = c.id |
145
|
|
|
JOIN %s ss |
146
|
|
|
WITH ss.spacecraft_id = s.id |
147
|
|
|
JOIN %s u |
148
|
|
|
WITH sp.user_id = u.id |
149
|
|
|
WHERE sp.user_id != :userId |
150
|
|
|
AND c.user_id = :userId |
151
|
|
|
AND ss.system_type = :systemType |
152
|
|
|
AND ss.mode >= :mode |
153
|
1 |
|
AND (u.vac_active = :false OR u.vac_request_date > :vacationThreshold)', |
154
|
1 |
|
Station::class, |
155
|
1 |
|
Spacecraft::class, |
156
|
1 |
|
CrewAssignment::class, |
157
|
1 |
|
Crew::class, |
158
|
1 |
|
SpacecraftSystem::class, |
159
|
1 |
|
User::class |
160
|
1 |
|
) |
161
|
1 |
|
)->setParameters([ |
162
|
1 |
|
'userId' => $userId, |
163
|
1 |
|
'systemType' => SpacecraftSystemTypeEnum::UPLINK->value, |
164
|
1 |
|
'mode' => SpacecraftSystemModeEnum::MODE_ON->value, |
165
|
1 |
|
'vacationThreshold' => time() - UserEnum::VACATION_DELAY_IN_SECONDS, |
166
|
1 |
|
'false' => false |
167
|
1 |
|
]) |
168
|
1 |
|
->getResult(); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
#[Override] |
172
|
|
|
public function getStationConstructions(): array |
173
|
|
|
{ |
174
|
|
|
return $this->getEntityManager()->createQuery( |
175
|
|
|
sprintf( |
176
|
|
|
'SELECT s FROM %s s |
177
|
|
|
JOIN %s r |
178
|
|
|
WITH s.rump_id = r.id |
179
|
|
|
WHERE s.user_id > :firstUserId |
180
|
|
|
AND r.category_id = :catId', |
181
|
|
|
Spacecraft::class, |
182
|
|
|
SpacecraftRump::class |
183
|
|
|
) |
184
|
|
|
)->setParameters([ |
185
|
|
|
'catId' => SpacecraftRumpEnum::SHIP_CATEGORY_CONSTRUCTION, |
186
|
|
|
'firstUserId' => UserEnum::USER_FIRST_ID |
187
|
|
|
]) |
188
|
|
|
->getResult(); |
189
|
|
|
} |
190
|
|
|
|
191
|
1 |
|
#[Override] |
192
|
|
|
public function getStationScannerResults( |
193
|
|
|
SpacecraftInterface $spacecraft, |
194
|
|
|
bool $showCloaked = false, |
195
|
|
|
MapInterface|StarSystemMapInterface|null $field = null |
196
|
|
|
): array { |
197
|
|
|
|
198
|
1 |
|
$rsm = new ResultSetMapping(); |
199
|
1 |
|
$rsm->addEntityResult(TShipItem::class, 's'); |
200
|
1 |
|
TFleetShipItem::addTSpacecraftItemFields($rsm); |
201
|
|
|
|
202
|
1 |
|
$location = $field ?? $spacecraft->getLocation(); |
203
|
|
|
|
204
|
1 |
|
$query = $this->getEntityManager()->createNativeQuery( |
205
|
1 |
|
sprintf( |
206
|
1 |
|
'SELECT s.id as shipid, s.rump_id as rumpid , ss.mode as warpstate, |
207
|
|
|
COALESCE(ss2.mode,0) as cloakstate, ss3.mode as shieldstate, COALESCE(ss4.status,0) as uplinkstate, |
208
|
|
|
s.type as spacecrafttype, s.name as shipname, s.huelle as hull, s.max_huelle as maxhull, |
209
|
|
|
s.schilde as shield, s.holding_web_id as webid, tw.finished_time as webfinishtime, u.id as userid, u.username, |
210
|
|
|
r.category_id as rumpcategoryid, r.name as rumpname, r.role_id as rumproleid, |
211
|
|
|
(SELECT count(*) > 0 FROM stu_ship_log sl WHERE sl.spacecraft_id = s.id AND sl.is_private = :false) as haslogbook, |
212
|
|
|
(SELECT count(*) > 0 FROM stu_crew_assign ca WHERE ca.spacecraft_id = s.id) as hascrew |
213
|
|
|
FROM stu_spacecraft s |
214
|
|
|
JOIN stu_station st |
215
|
|
|
ON s.id = st.id |
216
|
|
|
LEFT JOIN stu_spacecraft_system ss |
217
|
|
|
ON s.id = ss.spacecraft_id |
218
|
|
|
AND ss.system_type = :warpdriveType |
219
|
|
|
LEFT JOIN stu_spacecraft_system ss2 |
220
|
|
|
ON s.id = ss2.spacecraft_id |
221
|
|
|
AND ss2.system_type = :cloakType |
222
|
|
|
LEFT JOIN stu_spacecraft_system ss3 |
223
|
|
|
ON s.id = ss3.spacecraft_id |
224
|
|
|
AND ss3.system_type = :shieldType |
225
|
|
|
LEFT JOIN stu_spacecraft_system ss4 |
226
|
|
|
ON s.id = ss4.spacecraft_id |
227
|
|
|
AND ss4.system_type = :uplinkType |
228
|
|
|
JOIN stu_rump r |
229
|
|
|
ON s.rump_id = r.id |
230
|
|
|
LEFT OUTER JOIN stu_tholian_web tw |
231
|
|
|
ON s.holding_web_id = tw.id |
232
|
|
|
JOIN stu_user u |
233
|
|
|
ON s.user_id = u.id |
234
|
|
|
WHERE s.location_id = :locationId |
235
|
|
|
AND s.id != :ignoreId |
236
|
|
|
%s |
237
|
1 |
|
ORDER BY r.category_id ASC, r.role_id ASC, r.id ASC, s.name ASC', |
238
|
1 |
|
$showCloaked ? '' : sprintf(' AND (s.user_id = %d OR COALESCE(ss2.mode,0) < %d) ', $spacecraft->getUser()->getId(), SpacecraftSystemModeEnum::MODE_ON->value) |
239
|
1 |
|
), |
240
|
1 |
|
$rsm |
241
|
1 |
|
)->setParameters([ |
242
|
1 |
|
'locationId' => $location->getId(), |
|
|
|
|
243
|
1 |
|
'ignoreId' => $spacecraft->getId(), |
244
|
1 |
|
'cloakType' => SpacecraftSystemTypeEnum::CLOAK->value, |
245
|
1 |
|
'warpdriveType' => SpacecraftSystemTypeEnum::WARPDRIVE->value, |
246
|
1 |
|
'shieldType' => SpacecraftSystemTypeEnum::SHIELDS->value, |
247
|
1 |
|
'uplinkType' => SpacecraftSystemTypeEnum::UPLINK->value, |
248
|
1 |
|
'false' => false |
249
|
1 |
|
]); |
250
|
|
|
|
251
|
1 |
|
return $query->getResult(); |
252
|
|
|
} |
253
|
|
|
|
254
|
3 |
|
#[Override] |
255
|
|
|
public function getStationOnLocation(LocationInterface $location): ?StationInterface |
256
|
|
|
{ |
257
|
3 |
|
return $this->findOneBy(['location' => $location]); |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
#[Override] |
261
|
|
|
public function getStationsByUser(int $userId): array |
262
|
|
|
{ |
263
|
|
|
return $this->getEntityManager() |
264
|
|
|
->createQuery( |
265
|
|
|
sprintf( |
266
|
|
|
'SELECT s |
267
|
|
|
FROM %s s |
268
|
|
|
JOIN %s r |
269
|
|
|
WITH s.rump_id = r.id |
270
|
|
|
WHERE s.user_id = :userId |
271
|
|
|
AND r.category_id = :categoryId', |
272
|
|
|
Station::class, |
273
|
|
|
SpacecraftRump::class |
274
|
|
|
) |
275
|
|
|
) |
276
|
|
|
->setParameters([ |
277
|
|
|
'userId' => $userId, |
278
|
|
|
'categoryId' => SpacecraftRumpEnum::SHIP_CATEGORY_STATION |
279
|
|
|
]) |
280
|
|
|
->getResult(); |
281
|
|
|
} |
282
|
|
|
|
283
|
1 |
|
#[Override] |
284
|
|
|
public function getByUserAndRump(UserInterface $user, SpacecraftRumpInterface $rump): array |
285
|
|
|
{ |
286
|
1 |
|
return $this->findBy([ |
287
|
1 |
|
'user_id' => $user->getId(), |
288
|
1 |
|
'rump_id' => $rump->getId() |
289
|
1 |
|
], [ |
290
|
1 |
|
'location_id' => 'asc' |
291
|
1 |
|
]); |
292
|
|
|
} |
293
|
|
|
} |
294
|
|
|
|
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