Passed
Push — dev ( de632b...536e57 )
by Janko
28:46
created

MapRepository::getShipCountLayerData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 33
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 31
nc 1
nop 2
dl 0
loc 33
ccs 0
cts 13
cp 0
crap 2
rs 9.424
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
                    WHERE b.location_id = m.id
199
                    AND NOT EXISTS (SELECT ss.id
200
                                        FROM stu_ship_system ss
201
                                        WHERE b.id = ss.ship_id
202
                                        AND ss.system_type = :cloakSystemId
203
                                        AND ss.mode > 1)) AS shipcount,
204
                (SELECT count(DISTINCT c.id) FROM stu_ships c
205
                    WHERE c.location_id = m.id
206
                    AND EXISTS (SELECT ss2.id
207
                                        FROM stu_ship_system ss2
208
                                        WHERE c.id = ss2.ship_id
209
                                        AND ss2.system_type = :cloakSystemId
210
                                        AND ss2.mode > 1)) AS cloakcount
211
            FROM stu_map m
212
            JOIN stu_location l
213
            ON m.id = l.id
214
            WHERE l.cx BETWEEN :xStart AND :xEnd AND l.cy BETWEEN :yStart AND :yEnd
215
            AND l.layer_id = :layerId',
216
            $rsm
217
        )->setParameters([
218
            'xStart' => $boundaries->getMinX(),
219
            'xEnd' => $boundaries->getMaxX(),
220
            'yStart' => $boundaries->getMinY(),
221
            'yEnd' => $boundaries->getMaxY(),
222
            'layerId' => $boundaries->getParentId(),
223
            'cloakSystemId' => ShipSystemTypeEnum::SYSTEM_CLOAK->value
224
        ])->getResult();
225
    }
226
227
228
    #[Override]
229
    public function getMapLayerData(PanelBoundaries $boundaries, ResultSetMapping $rsm): array
230
    {
231
        return $this->getEntityManager()->createNativeQuery(
232
            'SELECT l.cx as x, l.cy AS y, ft.type
233
                FROM stu_map m
234
                JOIN stu_location l
235
                ON m.id = l.id
236
                JOIN stu_map_ftypes ft ON ft.id = l.field_id
237
                WHERE l.cx BETWEEN :xStart AND :xEnd AND l.cy BETWEEN :yStart AND :yEnd
238
                AND l.layer_id = :layerId',
239
            $rsm
240
        )->setParameters([
241
            'xStart' => $boundaries->getMinX(),
242
            'xEnd' => $boundaries->getMaxX(),
243
            'yStart' => $boundaries->getMinY(),
244
            'yEnd' => $boundaries->getMaxY(),
245
            'layerId' => $boundaries->getParentId(),
246
        ])->getResult();
247
    }
248
249
    #[Override]
250
    public function getExplored(int $userId, int $layerId, int $startX, int $endX, int $cy): array
251
    {
252
        $rsm = new ResultSetMapping();
253
        $rsm->addEntityResult(ExploreableStarMap::class, 'm');
254
        $rsm->addFieldResult('m', 'id', 'id');
255
        $rsm->addFieldResult('m', 'cx', 'cx');
256
        $rsm->addFieldResult('m', 'cy', 'cy');
257
        $rsm->addFieldResult('m', 'field_id', 'field_id');
258
        $rsm->addFieldResult('m', 'bordertype_id', 'bordertype_id');
259
        $rsm->addFieldResult('m', 'user_id', 'user_id');
260
        $rsm->addFieldResult('m', 'mapped', 'mapped');
261
        $rsm->addFieldResult('m', 'system_name', 'system_name');
262
        $rsm->addFieldResult('m', 'influence_area_id', 'influence_area_id');
263
        $rsm->addFieldResult('m', 'region_id', 'region_id');
264
        $rsm->addFieldResult('m', 'tradepost_id', 'tradepost_id');
265
        $rsm->addFieldResult('m', 'region_description', 'region_description');
266
        $rsm->addFieldResult('m', 'layer_id', 'layer_id');
267
268
        return $this->getEntityManager()
269
            ->createNativeQuery(
270
                'SELECT m.id, l.cx, l.cy, l.field_id, m.systems_id, m.bordertype_id, um.user_id,
271
                    dbu.database_id as mapped, m.influence_area_id as influence_area_id, m.admin_region_id as region_id,
272
                    sys.name as system_name, l.layer_id,
273
                    (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,
274
                    (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
275
                FROM stu_map m
276
                JOIN stu_location l
277
                ON m.id = l.id
278
                LEFT JOIN stu_user_map um
279
                    ON um.cy = l.cy AND um.cx = l.cx AND um.user_id = :userId AND um.layer_id = l.layer_id
280
                LEFT JOIN stu_systems sys
281
                    ON m.systems_id = sys.id
282
                LEFT JOIN stu_database_user dbu
283
                    ON dbu.user_id = :userId
284
                    AND sys.database_id = dbu.database_id
285
                WHERE l.cx BETWEEN :startX AND :endX
286
                AND l.cy = :cy
287
                AND l.layer_id = :layerId
288
                ORDER BY l.cx ASC',
289
                $rsm
290
            )
291
            ->setParameters([
292
                'layerId' => $layerId,
293
                'userId' => $userId,
294
                'startX' => $startX,
295
                'endX' => $endX,
296
                'cy' => $cy
297
            ])
298
            ->getResult();
299
    }
300
301
    #[Override]
302
    public function getWithEmptySystem(LayerInterface $layer): array
303
    {
304
        return $this->getEntityManager()
305
            ->createQuery(
306
                sprintf(
307
                    'SELECT m from %s m
308
                    JOIN %s l
309
                    WITH m.id = l.id
310
                    WHERE m.system_type_id IS NOT NULL
311
                    AND m.systems_id IS NULL
312
                    AND l.layer = :layer',
313
                    Map::class,
314
                    Location::class
315
                )
316
            )
317
            ->setParameters([
318
                'layer' => $layer
319
            ])
320
            ->getResult();
321
    }
322
323
    #[Override]
324
    public function getRandomMapIdsForAstroMeasurement(int $regionId, int $maxPercentage): array
325
    {
326
        $rsm = new ResultSetMapping();
327
        $rsm->addScalarResult('id', 'id', 'integer');
328
329
        $mapIdResultSet = $this->getEntityManager()
330
            ->createNativeQuery(
331
                'SELECT m.id FROM stu_map m
332
                JOIN stu_location l
333
                ON m.id = l.id
334
                JOIN stu_map_ftypes mf
335
                ON l.field_id = mf.id
336
                WHERE m.region_id = :regionId
337
                AND mf.passable IS true
338
                ORDER BY RANDOM()',
339
                $rsm
340
            )
341
            ->setParameters([
342
                'regionId' => $regionId,
343
            ])
344
            ->getResult();
345
346
        $amount = (int)ceil(count($mapIdResultSet) * $maxPercentage / 100);
347
        $subset = array_slice($mapIdResultSet, 0, $amount);
348
349
        return array_map(fn (array $data) => $data['id'], $subset);
350
    }
351
352
    #[Override]
353
    public function getRandomPassableUnoccupiedWithoutDamage(LayerInterface $layer, bool $isAtBorder = false): MapInterface
354
    {
355
        $rsm = new ResultSetMapping();
356
        $rsm->addScalarResult('id', 'id', 'integer');
357
358
        $borderCriteria = $isAtBorder ?
359
            sprintf(
360
                'AND (l.cx in (1, %d) OR l.cy in (1, %d))',
361
                $layer->getWidth(),
362
                $layer->getHeight()
363
            ) : '';
364
365
        $randomMapId =  (int)$this->getEntityManager()
366
            ->createNativeQuery(
367
                sprintf(
368
                    'SELECT m.id
369
                    FROM stu_map m
370
                    JOIN stu_location l
371
                    ON m.id = l.id
372
                    JOIN stu_map_ftypes mft
373
                    ON l.field_id = mft.id
374
                    WHERE NOT EXISTS (SELECT s.id FROM stu_ships s WHERE s.location_id = m.id)
375
                    AND l.layer_id = :layerId
376
                    AND mft.x_damage = 0
377
                    AND mft.passable = true
378
                    %s
379
                    ORDER BY RANDOM()
380
                    LIMIT 1',
381
                    $borderCriteria
382
                ),
383
                $rsm
384
            )
385
            ->setParameter('layerId', $layer->getId())
386
            ->getSingleScalarResult();
387
388
        $map = $this->find($randomMapId);
389
        if ($map === null) {
390
            throw new RuntimeException('this should not happen');
391
        }
392
393
        return $map;
394
    }
395
396
    #[Override]
397
    public function getIgnoringSubspaceLayerData(PanelBoundaries $boundaries, int $ignoreId, ResultSetMapping $rsm): array
398
    {
399
        $maxAge = time() - FlightSignatureVisibilityEnum::SIG_VISIBILITY_UNCLOAKED;
400
401
        return $this->getEntityManager()->createNativeQuery(
402
            sprintf(
403
                'SELECT l.cx AS x, l.cy AS y,
404
                (SELECT count(distinct fs1.ship_id) from stu_flight_sig fs1
405
                WHERE fs1.location_id = l.id
406
                AND fs1.user_id != %1$d
407
                AND (fs1.from_direction = 1 OR fs1.to_direction = 1)
408
                AND fs1.time > %2$d) as d1c,
409
                (SELECT count(distinct fs2.ship_id) from stu_flight_sig fs2
410
                WHERE fs2.location_id = l.id
411
                AND fs2.user_id != %1$d
412
                AND (fs2.from_direction = 2 OR fs2.to_direction = 2)
413
                AND fs2.time > %2$d) as d2c,
414
                (SELECT count(distinct fs3.ship_id) from stu_flight_sig fs3
415
                WHERE fs3.location_id = l.id
416
                AND fs3.user_id != %1$d
417
                AND (fs3.from_direction = 3 OR fs3.to_direction = 3)
418
                AND fs3.time > %2$d) as d3c,
419
                (SELECT count(distinct fs4.ship_id) from stu_flight_sig fs4
420
                WHERE fs4.location_id = l.id
421
                AND fs4.user_id != %1$d
422
                AND (fs4.from_direction = 4 OR fs4.to_direction = 4)
423
                AND fs4.time > %2$d) as d4c 
424
                FROM stu_location l
425
                WHERE l.cx BETWEEN :xStart AND :xEnd
426
                AND l.cy BETWEEN :yStart AND :yEnd
427
                AND l.layer_id = :layerId',
428
                $ignoreId,
429
                $maxAge
430
            ),
431
            $rsm
432
        )->setParameters([
433
            'xStart' => $boundaries->getMinX(),
434
            'xEnd' => $boundaries->getMaxX(),
435
            'yStart' => $boundaries->getMinY(),
436
            'yEnd' => $boundaries->getMaxY(),
437
            'layerId' => $boundaries->getParentId(),
438
        ])->getResult();
439
    }
440
441
    #[Override]
442
    public function getSubspaceLayerData(PanelBoundaries $boundaries, ResultSetMapping $rsm): array
443
    {
444
        return $this->getEntityManager()->createNativeQuery(
445
            'SELECT l.cx as x, l.cy as y,
446
            (SELECT count(distinct fs1.ship_id) from stu_flight_sig fs1
447
                WHERE fs1.location_id = l.id
448
                AND (fs1.from_direction = 1 OR fs1.to_direction = 1)) as d1c,
449
            (SELECT count(distinct fs2.ship_id) from stu_flight_sig fs2
450
                WHERE fs2.location_id = l.id
451
                AND (fs2.from_direction = 2 OR fs2.to_direction = 2)) as d2c,
452
            (SELECT count(distinct fs3.ship_id) from stu_flight_sig fs3
453
                WHERE fs3.location_id = l.id
454
                AND (fs3.from_direction = 3 OR fs3.to_direction = 3)) as d3c,
455
            (SELECT count(distinct fs4.ship_id) from stu_flight_sig fs4
456
                WHERE fs4.location_id = l.id
457
                AND (fs4.from_direction = 4 OR fs4.to_direction = 4)) as d4c 
458
            FROM stu_location l
459
            WHERE l.cx BETWEEN :xStart AND :xEnd
460
            AND l.cy BETWEEN :yStart AND :yEnd
461
            AND l.layer_id = :layerId',
462
            $rsm
463
        )->setParameters([
464
            'xStart' => $boundaries->getMinX(),
465
            'xEnd' => $boundaries->getMaxX(),
466
            'yStart' => $boundaries->getMinY(),
467
            'yEnd' => $boundaries->getMaxY(),
468
            'layerId' => $boundaries->getParentId()
469
        ])->getResult();
470
    }
471
472
    #[Override]
473
    public function getUserSubspaceLayerData(PanelBoundaries $boundaries, int $userId, ResultSetMapping $rsm): array
474
    {
475
        return $this->getEntityManager()->createNativeQuery(
476
            'SELECT l.cx as x, l.cy as y,
477
            (SELECT count(distinct fs1.ship_id) from stu_flight_sig fs1
478
                WHERE fs1.location_id = l.id
479
                AND fs1.user_id = :userId
480
                AND (fs1.from_direction = 1 OR fs1.to_direction = 1)) as d1c,
481
            (SELECT count(distinct fs2.ship_id) from stu_flight_sig fs2
482
                WHERE fs2.location_id = l.id
483
                AND fs2.user_id = :userId
484
                AND (fs2.from_direction = 2 OR fs2.to_direction = 2)) as d2c,
485
            (SELECT count(distinct fs3.ship_id) from stu_flight_sig fs3
486
                WHERE fs3.location_id = l.id
487
                AND fs3.user_id = :userId
488
                AND (fs3.from_direction = 3 OR fs3.to_direction = 3)) as d3c,
489
            (SELECT count(distinct fs4.ship_id) from stu_flight_sig fs4
490
                WHERE fs4.location_id = l.id
491
                AND fs4.user_id = :userId
492
                AND (fs4.from_direction = 4 OR fs4.to_direction = 4)) as d4c 
493
            FROM stu_location l
494
            WHERE l.cx BETWEEN :xStart AND :xEnd
495
            AND l.cy BETWEEN :yStart AND :yEnd
496
            AND l.layer_id = :layerId',
497
            $rsm
498
        )->setParameters([
499
            'xStart' => $boundaries->getMinX(),
500
            'xEnd' => $boundaries->getMaxX(),
501
            'yStart' => $boundaries->getMinY(),
502
            'yEnd' => $boundaries->getMaxY(),
503
            'layerId' => $boundaries->getParentId(),
504
            'userId' => $userId
505
        ])->getResult();
506
    }
507
508
    #[Override]
509
    public function getShipSubspaceLayerData(PanelBoundaries $boundaries, int $shipId, ResultSetMapping $rsm): array
510
    {
511
        return $this->getEntityManager()->createNativeQuery(
512
            'SELECT l.cx as x, l.cy as y,
513
            (SELECT count(distinct fs1.ship_id) from stu_flight_sig fs1
514
                WHERE fs1.location_id = l.id
515
                AND fs1.ship_id = :shipId
516
                AND (fs1.from_direction = 1 OR fs1.to_direction = 1)) as d1c,
517
            (SELECT count(distinct fs2.ship_id) from stu_flight_sig fs2
518
                WHERE fs2.location_id = l.id
519
                AND fs2.ship_id = :shipId
520
                AND (fs2.from_direction = 2 OR fs2.to_direction = 2)) as d2c,
521
            (SELECT count(distinct fs3.ship_id) from stu_flight_sig fs3
522
                WHERE fs3.location_id = l.id
523
                AND fs3.ship_id = :shipId
524
                AND (fs3.from_direction = 3 OR fs3.to_direction = 3)) as d3c,
525
            (SELECT count(distinct fs4.ship_id) from stu_flight_sig fs4
526
                WHERE fs4.location_id = l.id
527
                AND fs4.ship_id = :shipId
528
                AND (fs4.from_direction = 4 OR fs4.to_direction = 4)) as d4c 
529
            FROM stu_location l
530
            WHERE l.cx BETWEEN :xStart AND :xEnd
531
            AND l.cy BETWEEN :yStart AND :yEnd
532
            AND l.layer_id = :layerId',
533
            $rsm
534
        )->setParameters([
535
            'xStart' => $boundaries->getMinX(),
536
            'xEnd' => $boundaries->getMaxX(),
537
            'yStart' => $boundaries->getMinY(),
538
            'yEnd' => $boundaries->getMaxY(),
539
            'layerId' => $boundaries->getParentId(),
540
            'shipId' => $shipId
541
        ])->getResult();
542
    }
543
544
    #[Override]
545
    public function getAllianceSubspaceLayerData(PanelBoundaries $boundaries, int $allianceId, ResultSetMapping $rsm): array
546
    {
547
        return $this->getEntityManager()->createNativeQuery(
548
            'SELECT l.id, l.cx as x, l.cy as y,
549
            (SELECT count(distinct fs1.ship_id) from stu_flight_sig fs1
550
                JOIN stu_user u1 ON fs1.user_id = u1.id
551
                WHERE fs1.location_id = l.id
552
                AND u1.allys_id = :allyId
553
                AND (fs1.from_direction = 1 OR fs1.to_direction = 1)) as d1c,
554
            (SELECT count(distinct fs2.ship_id) from stu_flight_sig fs2
555
                JOIN stu_user u2 ON fs2.user_id = u2.id
556
                WHERE fs2.location_id = l.id
557
                AND u2.allys_id = :allyId
558
                AND (fs2.from_direction = 2 OR fs2.to_direction = 2)) as d2c,
559
            (SELECT count(distinct fs3.ship_id) from stu_flight_sig fs3
560
                JOIN stu_user u3 ON fs3.user_id = u3.id
561
                WHERE fs3.location_id = l.id
562
                AND u3.allys_id = :allyId
563
                AND (fs3.from_direction = 3 OR fs3.to_direction = 3)) as d3c,
564
            (SELECT count(distinct fs4.ship_id) from stu_flight_sig fs4
565
                JOIN stu_user u4 ON fs4.user_id = u4.id
566
                WHERE fs4.location_id = l.id
567
                AND u4.allys_id = :allyId
568
                AND (fs4.from_direction = 4 OR fs4.to_direction = 4)) as d4c 
569
            FROM stu_location l
570
            WHERE l.cx BETWEEN :xStart AND :xEnd
571
            AND l.cy BETWEEN :yStart AND :yEnd
572
            AND l.layer_id = :layerId',
573
            $rsm
574
        )->setParameters([
575
            'xStart' => $boundaries->getMinX(),
576
            'xEnd' => $boundaries->getMaxX(),
577
            'yStart' => $boundaries->getMinY(),
578
            'yEnd' => $boundaries->getMaxY(),
579
            'layerId' => $boundaries->getParentId(),
580
            'allyId' => $allianceId
581
        ])->getResult();
582
    }
583
}
584