Passed
Push — master ( 1d5530...fba2a1 )
by Nico
56:37 queued 25:57
created

MapRepository::getShipSubspaceLayerData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 34
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 32
nc 1
nop 3
dl 0
loc 34
ccs 0
cts 13
cp 0
crap 2
rs 9.408
c 0
b 0
f 0
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;
0 ignored issues
show
Bug introduced by
The type Override was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use RuntimeException;
11
use Stu\Component\Ship\FlightSignatureVisibilityEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Component\Ship\FlightSignatureVisibilityEnum was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Stu\Component\Ship\System\ShipSystemTypeEnum;
13
use Stu\Lib\Map\VisualPanel\PanelBoundaries;
14
use Stu\Module\PlayerSetting\Lib\UserSettingEnum;
15
use Stu\Module\Starmap\Lib\ExploreableStarMap;
16
use Stu\Orm\Entity\LayerInterface;
17
use Stu\Orm\Entity\Location;
18
use Stu\Orm\Entity\Map;
19
use Stu\Orm\Entity\MapInterface;
20
21
/**
22
 * @extends EntityRepository<Map>
23
 */
24
final class MapRepository extends EntityRepository implements MapRepositoryInterface
25
{
26
    #[Override]
27
    public function getAmountByLayer(LayerInterface $layer): int
28
    {
29
        return $this->count([
30
            'layer_id' => $layer->getId()
31
        ]);
32
    }
33
34
    #[Override]
35
    public function getAllOrdered(int $layerId): array
36
    {
37
        return $this->getEntityManager()
38
            ->createQuery(
39
                sprintf(
40
                    'SELECT m FROM %s m
41
                    JOIN %s l
42
                    WITH m.id = l.id
43
                    WHERE l.layer_id = :layerId
44
                    ORDER BY l.cy, l.cx',
45
                    Map::class,
46
                    Location::class
47
                )
48
            )
49
            ->setParameters([
50
                'layerId' => $layerId
51
            ])
52
            ->getResult();
53
    }
54
55
    #[Override]
56
    public function getAllWithSystem(int $layerId): array
57
    {
58
        return $this->getEntityManager()
59
            ->createQuery(
60
                sprintf(
61
                    'SELECT m FROM %s m INDEX BY m.id
62
                    JOIN %s l
63
                    WITH m.id = l.id
64
                    WHERE l.layer_id = :layerId
65
                    AND m.systems_id IS NOT null',
66
                    Map::class,
67
                    Location::class
68
                )
69
            )
70
            ->setParameters([
71
                'layerId' => $layerId
72
            ])
73
            ->getResult();
74
    }
75
76
    #[Override]
77
    public function getAllWithoutSystem(int $layerId): array
78
    {
79
        return $this->getEntityManager()
80
            ->createQuery(
81
                sprintf(
82
                    'SELECT m FROM %s m INDEX BY m.id
83
                    JOIN %s l
84
                    WITH m.id = l.id
85
                    WHERE l.layer_id = :layerId
86
                    AND m.systems_id IS null',
87
                    Map::class,
88
                    Location::class
89
                )
90
            )
91
            ->setParameters([
92
                'layerId' => $layerId
93
            ])
94
            ->getResult();
95
    }
96
97
    #[Override]
98
    public function getByCoordinates(?LayerInterface $layer, int $cx, int $cy): ?MapInterface
99
    {
100
        if ($layer === null) {
101
            return null;
102
        }
103
104
        return $this->findOneBy([
105
            'layer_id' => $layer->getId(),
106
            'cx' => $cx,
107
            'cy' => $cy
108
        ]);
109
    }
110
111
    #[Override]
112
    public function getByCoordinateRange(
113
        int $layerId,
114
        int $startCx,
115
        int $endCx,
116
        int $startCy,
117
        int $endCy,
118
        bool $sortAscending = true
119
    ): array {
120
        return $this->getEntityManager()
121
            ->createQuery(
122
                sprintf(
123
                    'SELECT m FROM %s m
124
                    JOIN %s l
125
                    WITH m.id = l.id
126
                    WHERE l.cx BETWEEN :startCx AND :endCx
127
                    AND l.cy BETWEEN :startCy AND :endCy
128
                    AND l.layer_id = :layerId
129
                    ORDER BY l.cy %3$s, l.cx %3$s',
130
                    Map::class,
131
                    Location::class,
132
                    $sortAscending ? 'ASC' : 'DESC'
133
                )
134
            )
135
            ->setParameters([
136
                'layerId' => $layerId,
137
                'startCx' => $startCx,
138
                'endCx' => $endCx,
139
                'startCy' => $startCy,
140
                'endCy' => $endCy
141
            ])
142
            ->getResult();
143
    }
144
145
    #[Override]
146
    public function save(MapInterface $map): void
147
    {
148
        $em = $this->getEntityManager();
149
150
        $em->persist($map);
151
    }
152
153
    #[Override]
154
    public function getBorderData(PanelBoundaries $boundaries, ResultSetMapping $rsm): array
155
    {
156
        return $this->getEntityManager()->createNativeQuery(
157
            'SELECT l.cx AS x, l.cy AS y,
158
                (SELECT al.rgb_code FROM stu_alliances al
159
                    JOIN stu_user u ON al.id = u.allys_id
160
                    JOIN stu_ships s ON u.id = s.user_id
161
                    JOIN stu_map ma ON ma.influence_area_id = s.influence_area_id
162
                    WHERE ma.id = m.id AND ma.bordertype_id IS NULL AND ma.admin_region_id IS NULL)
163
                            AS allycolor,
164
                (SELECT COALESCE(us.value, \'\') FROM stu_user u
165
                    LEFT JOIN stu_user_setting us ON u.id = us.user_id
166
                    JOIN stu_ships s ON u.id = s.user_id
167
                    JOIN stu_map mu ON mu.influence_area_id = s.influence_area_id
168
                    WHERE us.setting = :rgbCodeSetting
169
                    AND mu.id = m.id AND mu.bordertype_id IS NULL AND mu.admin_region_id IS NULL)
170
                        as usercolor,
171
                (SELECT mbt.color FROM stu_map_bordertypes mbt
172
                    JOIN stu_map mb ON mb.bordertype_id = mbt.id
173
                    WHERE mb.id = m.id AND mb.bordertype_id IS NOT NULL)
174
                        AS factioncolor
175
            FROM stu_map m
176
            JOIN stu_location l
177
            ON m.id = l.id
178
            WHERE l.cx BETWEEN :xStart AND :xEnd
179
            AND l.cy BETWEEN :yStart AND :yEnd
180
            AND l.layer_id = :layerId',
181
            $rsm
182
        )->setParameters([
183
            'xStart' => $boundaries->getMinX(),
184
            'xEnd' => $boundaries->getMaxX(),
185
            'yStart' => $boundaries->getMinY(),
186
            'yEnd' => $boundaries->getMaxY(),
187
            'layerId' => $boundaries->getParentId(),
188
            'rgbCodeSetting' => UserSettingEnum::RGB_CODE->value
189
        ])->getResult();
190
    }
191
192
    #[Override]
193
    public function getShipCountLayerData(PanelBoundaries $boundaries, ResultSetMapping $rsm): array
194
    {
195
        return $this->getEntityManager()->createNativeQuery(
196
            'SELECT l.cx as x, l.cy AS y,
197
                (SELECT count(DISTINCT b.id) FROM stu_ships b
198
                    JOIN stu_location l2
199
                    ON b.location_id = l2.id
200
                    WHERE l2.layer_id = l.layer_id 
201
                    AND l2.cx = l.cx
202
                    AND l2.cy = l.cy
203
                    AND NOT EXISTS (SELECT ss.id
204
                                        FROM stu_ship_system ss
205
                                        WHERE b.id = ss.ship_id
206
                                        AND ss.system_type = :cloakSystemId
207
                                        AND ss.mode > 1)) AS shipcount,
208
                (SELECT count(DISTINCT c.id) FROM stu_ships c
209
                    JOIN stu_location l2
210
                    ON c.location_id = l2.id
211
                    WHERE l2.layer_id = l.layer_id 
212
                    AND l2.cx = l.cx
213
                    AND l2.cy = l.cy
214
                    AND EXISTS (SELECT ss2.id
215
                                        FROM stu_ship_system ss2
216
                                        WHERE c.id = ss2.ship_id
217
                                        AND ss2.system_type = :cloakSystemId
218
                                        AND ss2.mode > 1)) AS cloakcount
219
            FROM stu_location l
220
            WHERE l.cx BETWEEN :xStart AND :xEnd AND l.cy BETWEEN :yStart AND :yEnd
221
            AND l.layer_id = :layerId
222
            GROUP BY layer_id, x, y',
223
            $rsm
224
        )->setParameters([
225
            'xStart' => $boundaries->getMinX(),
226
            'xEnd' => $boundaries->getMaxX(),
227
            'yStart' => $boundaries->getMinY(),
228
            'yEnd' => $boundaries->getMaxY(),
229
            'layerId' => $boundaries->getParentId(),
230
            'cloakSystemId' => ShipSystemTypeEnum::SYSTEM_CLOAK->value
231
        ])->getResult();
232
    }
233
234
235
    #[Override]
236
    public function getMapLayerData(PanelBoundaries $boundaries, ResultSetMapping $rsm): array
237
    {
238
        return $this->getEntityManager()->createNativeQuery(
239
            'SELECT l.cx as x, l.cy AS y, ft.type
240
                FROM stu_map m
241
                JOIN stu_location l
242
                ON m.id = l.id
243
                JOIN stu_map_ftypes ft ON ft.id = l.field_id
244
                WHERE l.cx BETWEEN :xStart AND :xEnd AND l.cy BETWEEN :yStart AND :yEnd
245
                AND l.layer_id = :layerId',
246
            $rsm
247
        )->setParameters([
248
            'xStart' => $boundaries->getMinX(),
249
            'xEnd' => $boundaries->getMaxX(),
250
            'yStart' => $boundaries->getMinY(),
251
            'yEnd' => $boundaries->getMaxY(),
252
            'layerId' => $boundaries->getParentId(),
253
        ])->getResult();
254
    }
255
256
    #[Override]
257
    public function getExplored(int $userId, int $layerId, int $startX, int $endX, int $cy): array
258
    {
259
        $rsm = new ResultSetMapping();
260
        $rsm->addEntityResult(ExploreableStarMap::class, 'm');
261
        $rsm->addFieldResult('m', 'id', 'id');
262
        $rsm->addFieldResult('m', 'cx', 'cx');
263
        $rsm->addFieldResult('m', 'cy', 'cy');
264
        $rsm->addFieldResult('m', 'field_id', 'field_id');
265
        $rsm->addFieldResult('m', 'bordertype_id', 'bordertype_id');
266
        $rsm->addFieldResult('m', 'user_id', 'user_id');
267
        $rsm->addFieldResult('m', 'mapped', 'mapped');
268
        $rsm->addFieldResult('m', 'system_name', 'system_name');
269
        $rsm->addFieldResult('m', 'influence_area_id', 'influence_area_id');
270
        $rsm->addFieldResult('m', 'region_id', 'region_id');
271
        $rsm->addFieldResult('m', 'tradepost_id', 'tradepost_id');
272
        $rsm->addFieldResult('m', 'region_description', 'region_description');
273
        $rsm->addFieldResult('m', 'layer_id', 'layer_id');
274
275
        return $this->getEntityManager()
276
            ->createNativeQuery(
277
                'SELECT m.id, l.cx, l.cy, l.field_id, m.systems_id, m.bordertype_id, um.user_id,
278
                    dbu.database_id as mapped, m.influence_area_id as influence_area_id, m.admin_region_id as region_id,
279
                    sys.name as system_name, l.layer_id,
280
                    (SELECT tp.id FROM stu_ships s JOIN stu_trade_posts tp ON s.id = tp.ship_id WHERE s.location_id = m.id) as tradepost_id,
281
                    (SELECT mr.description FROM stu_map_regions mr JOIN stu_database_user dbu on dbu.user_id = :userId and mr.database_id = dbu.database_id WHERE m.region_id = mr.id) as region_description
282
                FROM stu_map m
283
                JOIN stu_location l
284
                ON m.id = l.id
285
                LEFT JOIN stu_user_map um
286
                    ON um.cy = l.cy AND um.cx = l.cx AND um.user_id = :userId AND um.layer_id = l.layer_id
287
                LEFT JOIN stu_systems sys
288
                    ON m.systems_id = sys.id
289
                LEFT JOIN stu_database_user dbu
290
                    ON dbu.user_id = :userId
291
                    AND sys.database_id = dbu.database_id
292
                WHERE l.cx BETWEEN :startX AND :endX
293
                AND l.cy = :cy
294
                AND l.layer_id = :layerId
295
                ORDER BY l.cx ASC',
296
                $rsm
297
            )
298
            ->setParameters([
299
                'layerId' => $layerId,
300
                'userId' => $userId,
301
                'startX' => $startX,
302
                'endX' => $endX,
303
                'cy' => $cy
304
            ])
305
            ->getResult();
306
    }
307
308
    #[Override]
309
    public function getWithEmptySystem(LayerInterface $layer): array
310
    {
311
        return $this->getEntityManager()
312
            ->createQuery(
313
                sprintf(
314
                    'SELECT m from %s m
315
                    JOIN %s l
316
                    WITH m.id = l.id
317
                    WHERE m.system_type_id IS NOT NULL
318
                    AND m.systems_id IS NULL
319
                    AND l.layer = :layer',
320
                    Map::class,
321
                    Location::class
322
                )
323
            )
324
            ->setParameters([
325
                'layer' => $layer
326
            ])
327
            ->getResult();
328
    }
329
330
    #[Override]
331
    public function getRandomMapIdsForAstroMeasurement(int $regionId, int $maxPercentage): array
332
    {
333
        $rsm = new ResultSetMapping();
334
        $rsm->addScalarResult('id', 'id', 'integer');
335
336
        $mapIdResultSet = $this->getEntityManager()
337
            ->createNativeQuery(
338
                'SELECT m.id FROM stu_map m
339
                JOIN stu_location l
340
                ON m.id = l.id
341
                JOIN stu_map_ftypes mf
342
                ON l.field_id = mf.id
343
                WHERE m.region_id = :regionId
344
                AND mf.passable IS true
345
                ORDER BY RANDOM()',
346
                $rsm
347
            )
348
            ->setParameters([
349
                'regionId' => $regionId,
350
            ])
351
            ->getResult();
352
353
        $amount = (int)ceil(count($mapIdResultSet) * $maxPercentage / 100);
354
        $subset = array_slice($mapIdResultSet, 0, $amount);
355
356
        return array_map(fn (array $data) => $data['id'], $subset);
357
    }
358
359
    #[Override]
360
    public function getRandomPassableUnoccupiedWithoutDamage(LayerInterface $layer, bool $isAtBorder = false): MapInterface
361
    {
362
        $rsm = new ResultSetMapping();
363
        $rsm->addScalarResult('id', 'id', 'integer');
364
365
        $borderCriteria = $isAtBorder ?
366
            sprintf(
367
                'AND (l.cx in (1, %d) OR l.cy in (1, %d))',
368
                $layer->getWidth(),
369
                $layer->getHeight()
370
            ) : '';
371
372
        $randomMapId =  (int)$this->getEntityManager()
373
            ->createNativeQuery(
374
                sprintf(
375
                    'SELECT m.id
376
                    FROM stu_map m
377
                    JOIN stu_location l
378
                    ON m.id = l.id
379
                    JOIN stu_map_ftypes mft
380
                    ON l.field_id = mft.id
381
                    WHERE NOT EXISTS (SELECT s.id FROM stu_ships s WHERE s.location_id = m.id)
382
                    AND l.layer_id = :layerId
383
                    AND mft.x_damage = 0
384
                    AND mft.passable = true
385
                    %s
386
                    ORDER BY RANDOM()
387
                    LIMIT 1',
388
                    $borderCriteria
389
                ),
390
                $rsm
391
            )
392
            ->setParameter('layerId', $layer->getId())
393
            ->getSingleScalarResult();
394
395
        $map = $this->find($randomMapId);
396
        if ($map === null) {
397
            throw new RuntimeException('this should not happen');
398
        }
399
400
        return $map;
401
    }
402
403
    #[Override]
404
    public function getIgnoringSubspaceLayerData(PanelBoundaries $boundaries, int $ignoreId, ResultSetMapping $rsm): array
405
    {
406
        $maxAge = time() - FlightSignatureVisibilityEnum::SIG_VISIBILITY_UNCLOAKED;
407
408
        return $this->getEntityManager()->createNativeQuery(
409
            sprintf(
410
                'SELECT l.cx AS x, l.cy AS y,
411
                (SELECT count(distinct fs1.ship_id) from stu_flight_sig fs1
412
                WHERE fs1.location_id = l.id
413
                AND fs1.user_id != %1$d
414
                AND (fs1.from_direction = 1 OR fs1.to_direction = 1)
415
                AND fs1.time > %2$d) as d1c,
416
                (SELECT count(distinct fs2.ship_id) from stu_flight_sig fs2
417
                WHERE fs2.location_id = l.id
418
                AND fs2.user_id != %1$d
419
                AND (fs2.from_direction = 2 OR fs2.to_direction = 2)
420
                AND fs2.time > %2$d) as d2c,
421
                (SELECT count(distinct fs3.ship_id) from stu_flight_sig fs3
422
                WHERE fs3.location_id = l.id
423
                AND fs3.user_id != %1$d
424
                AND (fs3.from_direction = 3 OR fs3.to_direction = 3)
425
                AND fs3.time > %2$d) as d3c,
426
                (SELECT count(distinct fs4.ship_id) from stu_flight_sig fs4
427
                WHERE fs4.location_id = l.id
428
                AND fs4.user_id != %1$d
429
                AND (fs4.from_direction = 4 OR fs4.to_direction = 4)
430
                AND fs4.time > %2$d) as d4c 
431
                FROM stu_location l
432
                WHERE l.cx BETWEEN :xStart AND :xEnd
433
                AND l.cy BETWEEN :yStart AND :yEnd
434
                AND l.layer_id = :layerId',
435
                $ignoreId,
436
                $maxAge
437
            ),
438
            $rsm
439
        )->setParameters([
440
            'xStart' => $boundaries->getMinX(),
441
            'xEnd' => $boundaries->getMaxX(),
442
            'yStart' => $boundaries->getMinY(),
443
            'yEnd' => $boundaries->getMaxY(),
444
            'layerId' => $boundaries->getParentId(),
445
        ])->getResult();
446
    }
447
448
    #[Override]
449
    public function getSubspaceLayerData(PanelBoundaries $boundaries, ResultSetMapping $rsm): array
450
    {
451
        return $this->getEntityManager()->createNativeQuery(
452
            'SELECT l.cx as x, l.cy as y,
453
            (SELECT count(distinct fs1.ship_id) from stu_flight_sig fs1
454
                WHERE fs1.location_id = l.id
455
                AND (fs1.from_direction = 1 OR fs1.to_direction = 1)) as d1c,
456
            (SELECT count(distinct fs2.ship_id) from stu_flight_sig fs2
457
                WHERE fs2.location_id = l.id
458
                AND (fs2.from_direction = 2 OR fs2.to_direction = 2)) as d2c,
459
            (SELECT count(distinct fs3.ship_id) from stu_flight_sig fs3
460
                WHERE fs3.location_id = l.id
461
                AND (fs3.from_direction = 3 OR fs3.to_direction = 3)) as d3c,
462
            (SELECT count(distinct fs4.ship_id) from stu_flight_sig fs4
463
                WHERE fs4.location_id = l.id
464
                AND (fs4.from_direction = 4 OR fs4.to_direction = 4)) as d4c 
465
            FROM stu_location l
466
            WHERE l.cx BETWEEN :xStart AND :xEnd
467
            AND l.cy BETWEEN :yStart AND :yEnd
468
            AND l.layer_id = :layerId',
469
            $rsm
470
        )->setParameters([
471
            'xStart' => $boundaries->getMinX(),
472
            'xEnd' => $boundaries->getMaxX(),
473
            'yStart' => $boundaries->getMinY(),
474
            'yEnd' => $boundaries->getMaxY(),
475
            'layerId' => $boundaries->getParentId()
476
        ])->getResult();
477
    }
478
479
    #[Override]
480
    public function getUserSubspaceLayerData(PanelBoundaries $boundaries, int $userId, ResultSetMapping $rsm): array
481
    {
482
        return $this->getEntityManager()->createNativeQuery(
483
            'SELECT l.cx as x, l.cy as y,
484
            (SELECT count(distinct fs1.ship_id) from stu_flight_sig fs1
485
                WHERE fs1.location_id = l.id
486
                AND fs1.user_id = :userId
487
                AND (fs1.from_direction = 1 OR fs1.to_direction = 1)) as d1c,
488
            (SELECT count(distinct fs2.ship_id) from stu_flight_sig fs2
489
                WHERE fs2.location_id = l.id
490
                AND fs2.user_id = :userId
491
                AND (fs2.from_direction = 2 OR fs2.to_direction = 2)) as d2c,
492
            (SELECT count(distinct fs3.ship_id) from stu_flight_sig fs3
493
                WHERE fs3.location_id = l.id
494
                AND fs3.user_id = :userId
495
                AND (fs3.from_direction = 3 OR fs3.to_direction = 3)) as d3c,
496
            (SELECT count(distinct fs4.ship_id) from stu_flight_sig fs4
497
                WHERE fs4.location_id = l.id
498
                AND fs4.user_id = :userId
499
                AND (fs4.from_direction = 4 OR fs4.to_direction = 4)) as d4c 
500
            FROM stu_location l
501
            WHERE l.cx BETWEEN :xStart AND :xEnd
502
            AND l.cy BETWEEN :yStart AND :yEnd
503
            AND l.layer_id = :layerId',
504
            $rsm
505
        )->setParameters([
506
            'xStart' => $boundaries->getMinX(),
507
            'xEnd' => $boundaries->getMaxX(),
508
            'yStart' => $boundaries->getMinY(),
509
            'yEnd' => $boundaries->getMaxY(),
510
            'layerId' => $boundaries->getParentId(),
511
            'userId' => $userId
512
        ])->getResult();
513
    }
514
515
    #[Override]
516
    public function getShipSubspaceLayerData(PanelBoundaries $boundaries, int $shipId, ResultSetMapping $rsm): array
517
    {
518
        return $this->getEntityManager()->createNativeQuery(
519
            'SELECT l.cx as x, l.cy as y,
520
            (SELECT count(distinct fs1.ship_id) from stu_flight_sig fs1
521
                WHERE fs1.location_id = l.id
522
                AND fs1.ship_id = :shipId
523
                AND (fs1.from_direction = 1 OR fs1.to_direction = 1)) as d1c,
524
            (SELECT count(distinct fs2.ship_id) from stu_flight_sig fs2
525
                WHERE fs2.location_id = l.id
526
                AND fs2.ship_id = :shipId
527
                AND (fs2.from_direction = 2 OR fs2.to_direction = 2)) as d2c,
528
            (SELECT count(distinct fs3.ship_id) from stu_flight_sig fs3
529
                WHERE fs3.location_id = l.id
530
                AND fs3.ship_id = :shipId
531
                AND (fs3.from_direction = 3 OR fs3.to_direction = 3)) as d3c,
532
            (SELECT count(distinct fs4.ship_id) from stu_flight_sig fs4
533
                WHERE fs4.location_id = l.id
534
                AND fs4.ship_id = :shipId
535
                AND (fs4.from_direction = 4 OR fs4.to_direction = 4)) as d4c 
536
            FROM stu_location l
537
            WHERE l.cx BETWEEN :xStart AND :xEnd
538
            AND l.cy BETWEEN :yStart AND :yEnd
539
            AND l.layer_id = :layerId',
540
            $rsm
541
        )->setParameters([
542
            'xStart' => $boundaries->getMinX(),
543
            'xEnd' => $boundaries->getMaxX(),
544
            'yStart' => $boundaries->getMinY(),
545
            'yEnd' => $boundaries->getMaxY(),
546
            'layerId' => $boundaries->getParentId(),
547
            'shipId' => $shipId
548
        ])->getResult();
549
    }
550
551
    #[Override]
552
    public function getAllianceSubspaceLayerData(PanelBoundaries $boundaries, int $allianceId, ResultSetMapping $rsm): array
553
    {
554
        return $this->getEntityManager()->createNativeQuery(
555
            'SELECT l.id, l.cx as x, l.cy as y,
556
            (SELECT count(distinct fs1.ship_id) from stu_flight_sig fs1
557
                JOIN stu_user u1 ON fs1.user_id = u1.id
558
                WHERE fs1.location_id = l.id
559
                AND u1.allys_id = :allyId
560
                AND (fs1.from_direction = 1 OR fs1.to_direction = 1)) as d1c,
561
            (SELECT count(distinct fs2.ship_id) from stu_flight_sig fs2
562
                JOIN stu_user u2 ON fs2.user_id = u2.id
563
                WHERE fs2.location_id = l.id
564
                AND u2.allys_id = :allyId
565
                AND (fs2.from_direction = 2 OR fs2.to_direction = 2)) as d2c,
566
            (SELECT count(distinct fs3.ship_id) from stu_flight_sig fs3
567
                JOIN stu_user u3 ON fs3.user_id = u3.id
568
                WHERE fs3.location_id = l.id
569
                AND u3.allys_id = :allyId
570
                AND (fs3.from_direction = 3 OR fs3.to_direction = 3)) as d3c,
571
            (SELECT count(distinct fs4.ship_id) from stu_flight_sig fs4
572
                JOIN stu_user u4 ON fs4.user_id = u4.id
573
                WHERE fs4.location_id = l.id
574
                AND u4.allys_id = :allyId
575
                AND (fs4.from_direction = 4 OR fs4.to_direction = 4)) as d4c 
576
            FROM stu_location l
577
            WHERE l.cx BETWEEN :xStart AND :xEnd
578
            AND l.cy BETWEEN :yStart AND :yEnd
579
            AND l.layer_id = :layerId',
580
            $rsm
581
        )->setParameters([
582
            'xStart' => $boundaries->getMinX(),
583
            'xEnd' => $boundaries->getMaxX(),
584
            'yStart' => $boundaries->getMinY(),
585
            'yEnd' => $boundaries->getMaxY(),
586
            'layerId' => $boundaries->getParentId(),
587
            'allyId' => $allianceId
588
        ])->getResult();
589
    }
590
}
591