Passed
Push — dev ( 1772b4...f43676 )
by Nico
05:33
created

getEndedAuctionsBuildplansPrestige()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 17
nc 1
nop 1
dl 0
loc 22
ccs 0
cts 15
cp 0
crap 2
rs 9.7
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 Stu\Component\Game\TimeConstants;
0 ignored issues
show
Bug introduced by
The type Stu\Component\Game\TimeConstants 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...
9
use Stu\Orm\Entity\Deals;
10
use Stu\Orm\Entity\Faction;
11
use Stu\Orm\Entity\User;
12
13
/**
14
 * @extends EntityRepository<Deals>
15
 */
16
final class DealsRepository extends EntityRepository implements DealsRepositoryInterface
17
{
18
    #[\Override]
19
    public function prototype(): Deals
20
    {
21
        return new Deals();
22
    }
23
24
    #[\Override]
25
    public function save(Deals $post): void
26
    {
27
        $em = $this->getEntityManager();
28
29
        $em->persist($post);
30
    }
31
32
    #[\Override]
33
    public function delete(Deals $post): void
34
    {
35
        $em = $this->getEntityManager();
36
37
        $em->remove($post);
38
        $em->flush();
39
    }
40
41 1
    #[\Override]
42
    public function hasActiveDeals(int $userId): bool
43
    {
44 1
        return $this->getEntityManager()
45 1
            ->createQuery(
46 1
                sprintf(
47 1
                    'SELECT count(d.id) FROM %s d
48
                    WHERE d.start < :actime AND d.end > :actime
49
                    AND d.auction = FALSE
50
                    AND (d.faction = (SELECT f FROM %s u JOIN u.faction f WHERE u.id = :userId)
51 1
                        OR d.faction IS NULL)',
52 1
                    Deals::class,
53 1
                    User::class
54 1
                )
55 1
            )
56 1
            ->setParameters([
57 1
                'actime' => time(),
58 1
                'userId' => $userId
59 1
            ])
60 1
            ->getSingleScalarResult() > 0;
61
    }
62
63
    #[\Override]
64
    public function getActiveDealsGoods(int $userId): array
65
    {
66
        return $this->getEntityManager()
67
            ->createQuery(
68
                sprintf(
69
                    'SELECT d FROM %s d
70
                    WHERE d.start < :actime AND d.end > :actime
71
                    AND d.auction = FALSE AND d.want_prestige IS NULL
72
                    AND d.buildplan_id IS NULL AND d.ship = FALSE
73
                    AND (d.faction = (SELECT f FROM %s u JOIN u.faction f WHERE u.id = :userId)
74
                        OR d.faction IS NULL) ORDER BY d.id ASC',
75
                    Deals::class,
76
                    User::class
77
                )
78
            )
79
            ->setParameters([
80
                'actime' => time(),
81
                'userId' => $userId
82
            ])
83
            ->getResult();
84
    }
85
86
    #[\Override]
87
    public function getActiveDealsShips(int $userId): array
88
    {
89
        return $this->getEntityManager()
90
            ->createQuery(
91
                sprintf(
92
                    'SELECT d FROM %s d
93
                    WHERE d.start < :actime AND d.end > :actime
94
                    AND d.auction = FALSE AND d.want_prestige IS NULL
95
                    AND d.buildplan_id > 0 AND d.ship = TRUE
96
                    AND (d.faction = (SELECT f FROM %s u JOIN u.faction f WHERE u.id = :userId)
97
                        OR d.faction IS NULL) ORDER BY d.id ASC',
98
                    Deals::class,
99
                    User::class
100
                )
101
            )
102
            ->setParameters([
103
                'actime' => time(),
104
                'userId' => $userId,
105
            ])
106
            ->getResult();
107
    }
108
109
    #[\Override]
110
    public function getActiveDealsBuildplans(int $userId): array
111
    {
112
        return $this->getEntityManager()
113
            ->createQuery(
114
                sprintf(
115
                    'SELECT d FROM %s d
116
                    WHERE d.start < :actime AND d.end > :actime AND d.auction = FALSE
117
                    AND d.want_prestige IS NULL AND d.buildplan_id > 0 AND d.ship = FALSE
118
                    AND (d.faction = (SELECT f FROM %s u JOIN u.faction f WHERE u.id = :userId)
119
                        OR d.faction IS NULL) ORDER BY d.id ASC',
120
                    Deals::class,
121
                    User::class
122
                )
123
            )
124
            ->setParameters([
125
                'actime' => time(),
126
                'userId' => $userId,
127
            ])
128
            ->getResult();
129
    }
130
131
    #[\Override]
132
    public function getActiveDealsGoodsPrestige(int $userId): array
133
    {
134
        return $this->getEntityManager()
135
            ->createQuery(
136
                sprintf(
137
                    'SELECT d FROM %s d
138
                    WHERE d.start < :actime AND d.end > :actime
139
                    AND d.auction = FALSE AND d.want_commodity IS NULL
140
                    AND d.buildplan_id IS NULL AND d.ship = FALSE
141
                    AND (d.faction = (SELECT f FROM %s u JOIN u.faction f WHERE u.id = :userId)
142
                        OR d.faction IS NULL) ORDER BY d.id ASC',
143
                    Deals::class,
144
                    User::class
145
                )
146
            )
147
            ->setParameters([
148
                'actime' => time(),
149
                'userId' => $userId,
150
            ])
151
            ->getResult();
152
    }
153
154
    #[\Override]
155
    public function getActiveDealsShipsPrestige(int $userId): array
156
    {
157
        return $this->getEntityManager()
158
            ->createQuery(
159
                sprintf(
160
                    'SELECT d FROM %s d
161
                     WHERE d.start < :actime AND d.end > :actime
162
                     AND d.auction = FALSE AND d.want_commodity IS NULL
163
                     AND d.buildplan_id > 0 AND d.ship = TRUE
164
                     AND (d.faction = (SELECT f FROM %s u JOIN u.faction f WHERE u.id = :userId)
165
                        OR d.faction IS NULL) ORDER BY d.id ASC',
166
                    Deals::class,
167
                    User::class
168
                )
169
            )
170
            ->setParameters([
171
                'actime' => time(),
172
                'userId' => $userId,
173
            ])
174
            ->getResult();
175
    }
176
177
    #[\Override]
178
    public function getActiveDealsBuildplansPrestige(int $userId): array
179
    {
180
        return $this->getEntityManager()
181
            ->createQuery(
182
                sprintf(
183
                    'SELECT d FROM %s d
184
                     WHERE d.start < :actime AND d.end > :actime AND d.auction = FALSE
185
                     AND d.want_commodity IS NULL AND d.buildplan_id > 0 AND d.ship = FALSE
186
                     AND (d.faction = (SELECT f FROM %s u JOIN u.faction f WHERE u.id = :userId)
187
                        OR d.faction IS NULL) ORDER BY d.id ASC',
188
                    Deals::class,
189
                    User::class
190
                )
191
            )
192
            ->setParameters([
193
                'actime' => time(),
194
                'userId' => $userId
195
            ])
196
            ->getResult();
197
    }
198
199 1
    #[\Override]
200
    public function hasActiveAuctions(int $userId): bool
201
    {
202 1
        return $this->getEntityManager()
203 1
            ->createQuery(
204 1
                sprintf(
205 1
                    'SELECT count(d.id) FROM %s d WHERE d.start < :actime
206
                        AND d.end > :actime AND d.auction = TRUE
207
                        AND (d.faction = (SELECT f FROM %s u JOIN u.faction f WHERE u.id = :userId)
208 1
                        OR d.faction IS NULL)',
209 1
                    Deals::class,
210 1
                    User::class
211 1
                )
212 1
            )
213 1
            ->setParameters([
214 1
                'actime' => time(),
215 1
                'userId' => $userId
216 1
            ])
217 1
            ->getSingleScalarResult() > 0;
218
    }
219
220
    #[\Override]
221
    public function getActiveAuctionsGoods(int $userId): array
222
    {
223
        return $this->getEntityManager()
224
            ->createQuery(
225
                sprintf(
226
                    'SELECT d FROM %s d
227
                     WHERE d.start < :actime AND d.end > :actime AND d.auction = TRUE
228
                     AND d.want_prestige IS NULL AND d.buildplan_id IS NULL AND d.ship = FALSE
229
                     AND (d.faction = (SELECT f FROM %s u JOIN u.faction f WHERE u.id = :userId)
230
                        OR d.faction IS NULL) ORDER BY d.id ASC',
231
                    Deals::class,
232
                    User::class
233
                )
234
            )
235
            ->setParameters([
236
                'actime' => time(),
237
                'userId' => $userId,
238
            ])
239
            ->getResult();
240
    }
241
242
    #[\Override]
243
    public function getActiveAuctionsShips(int $userId): array
244
    {
245
        return $this->getEntityManager()
246
            ->createQuery(
247
                sprintf(
248
                    'SELECT d FROM %s d
249
                     WHERE d.start < :actime AND d.end > :actime AND d.auction = TRUE
250
                     AND d.want_prestige IS NULL AND d.buildplan_id > 0 AND d.ship = TRUE
251
                     AND (d.faction = (SELECT f FROM %s u JOIN u.faction f WHERE u.id = :userId)
252
                        OR d.faction IS NULL) ORDER BY d.id ASC',
253
                    Deals::class,
254
                    User::class
255
                )
256
            )
257
            ->setParameters([
258
                'actime' => time(),
259
                'userId' => $userId,
260
            ])
261
            ->getResult();
262
    }
263
264
    #[\Override]
265
    public function getActiveAuctionsBuildplans(int $userId): array
266
    {
267
        return $this->getEntityManager()
268
            ->createQuery(
269
                sprintf(
270
                    'SELECT d FROM %s d
271
                    WHERE d.start < :actime AND d.end > :actime AND d.auction = TRUE
272
                    AND d.want_prestige IS NULL AND d.buildplan_id > 0 AND d.ship = FALSE
273
                    AND (d.faction = (SELECT f FROM %s u JOIN u.faction f WHERE u.id = :userId)
274
                        OR d.faction IS NULL) ORDER BY d.id ASC',
275
                    Deals::class,
276
                    User::class
277
                )
278
            )
279
            ->setParameters([
280
                'actime' => time(),
281
                'userId' => $userId,
282
            ])
283
            ->getResult();
284
    }
285
286
    #[\Override]
287
    public function getActiveAuctionsGoodsPrestige(int $userId): array
288
    {
289
        return $this->getEntityManager()
290
            ->createQuery(
291
                sprintf(
292
                    'SELECT d FROM %s d
293
                    WHERE d.start < :actime AND d.end > :actime AND d.auction = TRUE
294
                    AND d.want_commodity IS NULL AND d.buildplan_id IS NULL AND d.ship = FALSE
295
                    AND (d.faction = (SELECT f FROM %s u JOIN u.faction f WHERE u.id = :userId)
296
                        OR d.faction IS NULL) ORDER BY d.id ASC',
297
                    Deals::class,
298
                    User::class
299
                )
300
            )
301
            ->setParameters([
302
                'actime' => time(),
303
                'userId' => $userId,
304
            ])
305
            ->getResult();
306
    }
307
308
    #[\Override]
309
    public function getActiveAuctionsShipsPrestige(int $userId): array
310
    {
311
        return $this->getEntityManager()
312
            ->createQuery(
313
                sprintf(
314
                    'SELECT d FROM %s d
315
                    WHERE d.start < :actime AND d.end > :actime AND d.auction = TRUE
316
                    AND d.want_commodity IS NULL AND d.buildplan_id > 0 AND d.ship = TRUE
317
                    AND (d.faction = (SELECT f FROM %s u JOIN u.faction f WHERE u.id = :userId)
318
                        OR d.faction IS NULL) ORDER BY d.id ASC',
319
                    Deals::class,
320
                    User::class
321
                )
322
            )
323
            ->setParameters([
324
                'actime' => time(),
325
                'userId' => $userId,
326
            ])
327
            ->getResult();
328
    }
329
330
    #[\Override]
331
    public function getActiveAuctionsBuildplansPrestige(int $userId): array
332
    {
333
        return $this->getEntityManager()
334
            ->createQuery(
335
                sprintf(
336
                    'SELECT d FROM %s d
337
                     WHERE d.start < :actime AND d.end > :actime AND d.auction = TRUE
338
                     AND d.want_commodity IS NULL AND d.buildplan_id > 0 AND d.ship = FALSE
339
                     AND (d.faction = (SELECT f FROM %s u JOIN u.faction f WHERE u.id = :userId)
340
                        OR d.faction IS NULL) ORDER BY d.id ASC',
341
                    Deals::class,
342
                    User::class
343
                )
344
            )
345
            ->setParameters([
346
                'actime' => time(),
347
                'userId' => $userId,
348
            ])
349
            ->getResult();
350
    }
351
352 1
    #[\Override]
353
    public function hasEndedAuctions(int $userId): bool
354
    {
355 1
        return $this->getEntityManager()
356 1
            ->createQuery(
357 1
                sprintf(
358 1
                    'SELECT count(d.id) FROM %s d
359
                        WHERE d.end < :actime
360
                        AND (d.end + 2592000) > :actime
361
                        AND d.auction = TRUE
362
                        AND (d.auction_user != :userId OR d.taken_time IS NOT NULL)
363
                        AND (d.faction = (SELECT f FROM %s u JOIN u.faction f WHERE u.id = :userId)
364 1
                        OR d.faction IS NULL)',
365 1
                    Deals::class,
366 1
                    User::class
367 1
                )
368 1
            )
369 1
            ->setParameters([
370 1
                'actime' => time(),
371 1
                'userId' => $userId,
372 1
            ])
373 1
            ->getSingleScalarResult() > 0;
374
    }
375
376 1
    #[\Override]
377
    public function hasOwnAuctionsToTake(int $userId): bool
378
    {
379 1
        $time = time();
380
381 1
        return $this->getEntityManager()
382 1
            ->createQuery(
383 1
                sprintf(
384 1
                    'SELECT count(d.id) FROM %s d
385
                    WHERE d.end BETWEEN :threshold AND :actime
386
                    AND d.taken_time IS NULL
387
                    AND d.auction = TRUE
388 1
                    AND d.auction_user = :userId',
389 1
                    Deals::class
390 1
                )
391 1
            )
392 1
            ->setParameters([
393 1
                'actime' => $time,
394 1
                'threshold' => $time - 30 * TimeConstants::ONE_DAY_IN_SECONDS,
395 1
                'userId' => $userId,
396 1
            ])
397 1
            ->getSingleScalarResult() > 0;
398
    }
399
400
    #[\Override]
401
    public function getEndedAuctionsGoods(int $userId): array
402
    {
403
        return $this->getEntityManager()
404
            ->createQuery(
405
                sprintf(
406
                    'SELECT d FROM %s d
407
                    WHERE d.end < :actime
408
                    AND (d.end + 2592000) > :actime
409
                    AND (d.auction_user != :userId OR d.taken_time IS NOT NULL)
410
                    AND d.auction = TRUE AND d.want_prestige IS NULL AND d.buildplan_id IS NULL AND d.ship = FALSE
411
                    AND (d.faction = (SELECT f FROM %s u JOIN u.faction f WHERE u.id = :userId)
412
                        OR d.faction IS NULL) ORDER BY d.end DESC',
413
                    Deals::class,
414
                    User::class
415
                )
416
            )
417
            ->setParameters([
418
                'actime' => time(),
419
                'userId' => $userId,
420
            ])
421
            ->getResult();
422
    }
423
424
    #[\Override]
425
    public function getEndedAuctionsShips(int $userId): array
426
    {
427
        return $this->getEntityManager()
428
            ->createQuery(
429
                sprintf(
430
                    'SELECT d FROM %s d
431
                     WHERE d.end < :actime
432
                     AND (d.end + 2592000) > :actime
433
                     AND (d.auction_user != :userId OR d.taken_time IS NOT NULL)
434
                     AND d.auction = TRUE AND d.want_prestige IS NULL AND d.buildplan_id > 0
435
                     AND d.ship = TRUE
436
                     AND (d.faction = (SELECT f FROM %s u JOIN u.faction f WHERE u.id = :userId)
437
                        OR d.faction IS NULL) ORDER BY d.end DESC',
438
                    Deals::class,
439
                    User::class
440
                )
441
            )
442
            ->setParameters([
443
                'actime' => time(),
444
                'userId' => $userId,
445
            ])
446
            ->getResult();
447
    }
448
449
    #[\Override]
450
    public function getEndedAuctionsBuildplans(int $userId): array
451
    {
452
        return $this->getEntityManager()
453
            ->createQuery(
454
                sprintf(
455
                    'SELECT d FROM %s d
456
                     WHERE d.end < :actime AND (d.end + 2592000) > :actime
457
                     AND (d.auction_user != :userId OR d.taken_time IS NOT NULL)
458
                     AND d.auction = TRUE AND d.want_prestige IS NULL AND d.buildplan_id > 0
459
                     AND d.ship = FALSE
460
                     AND (d.faction = (SELECT f FROM %s u JOIN u.faction f WHERE u.id = :userId)
461
                        OR d.faction IS NULL) ORDER BY d.end DESC',
462
                    Deals::class,
463
                    User::class
464
                )
465
            )
466
            ->setParameters([
467
                'actime' => time(),
468
                'userId' => $userId,
469
            ])
470
            ->getResult();
471
    }
472
473
    #[\Override]
474
    public function getEndedAuctionsGoodsPrestige(int $userId): array
475
    {
476
        return $this->getEntityManager()
477
            ->createQuery(
478
                sprintf(
479
                    'SELECT d FROM %s d
480
                      WHERE d.end < :actime AND (d.end + 2592000) > :actime
481
                      AND (d.auction_user != :userId OR d.taken_time IS NOT NULL)
482
                      AND d.auction = TRUE AND d.want_commodity IS NULL
483
                      AND d.buildplan_id IS NULL AND d.ship = FALSE
484
                      AND (d.faction = (SELECT f FROM %s u JOIN u.faction f WHERE u.id = :userId)
485
                        OR d.faction IS NULL) ORDER BY d.end DESC',
486
                    Deals::class,
487
                    User::class
488
                )
489
            )
490
            ->setParameters([
491
                'actime' => time(),
492
                'userId' => $userId,
493
            ])
494
            ->getResult();
495
    }
496
497
    #[\Override]
498
    public function getEndedAuctionsShipsPrestige(int $userId): array
499
    {
500
        return $this->getEntityManager()
501
            ->createQuery(
502
                sprintf(
503
                    'SELECT d FROM %s d
504
                     WHERE d.end < :actime AND (d.end + 2592000) > :actime
505
                     AND (d.auction_user != :userId OR d.taken_time IS NOT NULL)
506
                     AND d.auction = TRUE AND d.want_commodity IS NULL AND d.buildplan_id > 0
507
                     AND d.ship = TRUE
508
                     AND (d.faction = (SELECT f FROM %s u JOIN u.faction f WHERE u.id = :userId)
509
                        OR d.faction IS NULL) ORDER BY d.end DESC',
510
                    Deals::class,
511
                    User::class
512
                )
513
            )
514
            ->setParameters([
515
                'actime' => time(),
516
                'userId' => $userId,
517
            ])
518
            ->getResult();
519
    }
520
521
    #[\Override]
522
    public function getEndedAuctionsBuildplansPrestige(int $userId): array
523
    {
524
        return $this->getEntityManager()
525
            ->createQuery(
526
                sprintf(
527
                    'SELECT d FROM %s d
528
                     WHERE d.end < :actime AND (d.end + 2592000) > :actime
529
                     AND (d.auction_user != :userId OR d.taken_time IS NOT NULL)
530
                     AND d.auction = TRUE AND d.want_commodity IS NULL
531
                     AND d.buildplan_id > 0 AND d.ship = FALSE
532
                     AND (d.faction = (SELECT f FROM %s u JOIN u.faction f WHERE u.id = :userId)
533
                        OR d.faction IS NULL) ORDER BY d.end DESC',
534
                    Deals::class,
535
                    User::class
536
                )
537
            )
538
            ->setParameters([
539
                'actime' => time(),
540
                'userId' => $userId,
541
            ])
542
            ->getResult();
543
    }
544
545
    #[\Override]
546
    public function getOwnEndedAuctionsGoods(int $userId): array
547
    {
548
        $time = time();
549
550
        return $this->getEntityManager()
551
            ->createQuery(
552
                sprintf(
553
                    'SELECT d FROM %s d
554
                    WHERE d.end BETWEEN :threshold AND :actime
555
                    AND d.taken_time IS NULL
556
                    AND d.auction_user = :userId
557
                    AND d.auction = TRUE
558
                    AND d.want_prestige IS NULL
559
                    AND d.buildplan_id IS NULL
560
                    AND d.ship = FALSE ORDER BY d.end DESC',
561
                    Deals::class
562
                )
563
            )
564
            ->setParameters([
565
                'actime' => $time,
566
                'threshold' => $time - 30 * TimeConstants::ONE_DAY_IN_SECONDS,
567
                'userId' => $userId,
568
            ])
569
            ->getResult();
570
    }
571
572
    #[\Override]
573
    public function getOwnEndedAuctionsShips(int $userId): array
574
    {
575
        $time = time();
576
577
        return $this->getEntityManager()
578
            ->createQuery(
579
                sprintf(
580
                    'SELECT d FROM %s d
581
                    WHERE d.end BETWEEN :threshold AND :actime
582
                    AND d.taken_time IS NULL
583
                    AND d.auction_user = :userId
584
                    AND d.auction = TRUE
585
                    AND d.want_prestige IS NULL
586
                    AND d.buildplan_id > 0
587
                    AND d.ship = TRUE ORDER BY d.end DESC',
588
                    Deals::class
589
                )
590
            )
591
            ->setParameters([
592
                'actime' => $time,
593
                'threshold' => $time - 30 * TimeConstants::ONE_DAY_IN_SECONDS,
594
                'userId' => $userId,
595
            ])
596
            ->getResult();
597
    }
598
599
    #[\Override]
600
    public function getOwnEndedAuctionsBuildplans(int $userId): array
601
    {
602
        $time = time();
603
604
        return $this->getEntityManager()
605
            ->createQuery(
606
                sprintf(
607
                    'SELECT d FROM %s d
608
                    WHERE d.end BETWEEN :threshold AND :actime
609
                    AND d.taken_time IS NULL
610
                    AND d.auction_user = :userId
611
                    AND d.auction = TRUE
612
                    AND d.want_prestige IS NULL
613
                    AND d.buildplan_id > 0
614
                    AND d.ship = FALSE ORDER BY d.end DESC',
615
                    Deals::class
616
                )
617
            )
618
            ->setParameters([
619
                'actime' => $time,
620
                'threshold' => $time - 30 * TimeConstants::ONE_DAY_IN_SECONDS,
621
                'userId' => $userId,
622
            ])
623
            ->getResult();
624
    }
625
626
    #[\Override]
627
    public function getOwnEndedAuctionsGoodsPrestige(int $userId): array
628
    {
629
        $time = time();
630
631
        return $this->getEntityManager()
632
            ->createQuery(
633
                sprintf(
634
                    'SELECT d FROM %s d
635
                    WHERE d.end BETWEEN :threshold AND :actime
636
                    AND d.taken_time IS NULL
637
                    AND d.auction_user = :userId
638
                    AND d.auction = TRUE
639
                    AND d.want_commodity IS NULL
640
                    AND d.buildplan_id IS NULL
641
                    AND d.ship = FALSE ORDER BY d.end DESC',
642
                    Deals::class
643
                )
644
            )
645
            ->setParameters([
646
                'actime' => $time,
647
                'threshold' => $time - 30 * TimeConstants::ONE_DAY_IN_SECONDS,
648
                'userId' => $userId,
649
            ])
650
            ->getResult();
651
    }
652
653
    #[\Override]
654
    public function getOwnEndedAuctionsShipsPrestige(int $userId): array
655
    {
656
        $time = time();
657
658
        return $this->getEntityManager()
659
            ->createQuery(
660
                sprintf(
661
                    'SELECT d FROM %s d
662
                    WHERE d.end BETWEEN :threshold AND :actime
663
                    AND d.taken_time IS NULL
664
                    AND d.auction_user = :userId
665
                    AND d.auction = TRUE
666
                    AND d.want_commodity IS NULL
667
                    AND d.buildplan_id > 0
668
                    AND d.ship = TRUE ORDER BY d.end DESC',
669
                    Deals::class
670
                )
671
            )
672
            ->setParameters([
673
                'actime' => $time,
674
                'threshold' => $time - 30 * TimeConstants::ONE_DAY_IN_SECONDS,
675
                'userId' => $userId,
676
            ])
677
            ->getResult();
678
    }
679
680
    #[\Override]
681
    public function getOwnEndedAuctionsBuildplansPrestige(int $userId): array
682
    {
683
        $time = time();
684
685
        return $this->getEntityManager()
686
            ->createQuery(
687
                sprintf(
688
                    'SELECT d FROM %s d
689
                    WHERE d.end BETWEEN :threshold AND :actime
690
                    AND d.taken_time IS NULL
691
                    AND d.auction_user = :userId
692
                    AND d.auction = TRUE
693
                    AND d.want_commodity IS NULL
694
                    AND d.buildplan_id > 0
695
                    AND d.ship = FALSE ORDER BY d.end DESC',
696
                    Deals::class
697
                )
698
            )
699
            ->setParameters([
700
                'actime' => $time,
701
                'threshold' => $time - 30 * TimeConstants::ONE_DAY_IN_SECONDS,
702
                'userId' => $userId,
703
            ])
704
            ->getResult();
705
    }
706
707 1
    #[\Override]
708
    public function getRecentlyStartedDeals(int $timeThreshold): array
709
    {
710 1
        return $this->getEntityManager()
711 1
            ->createQuery(
712 1
                sprintf(
713 1
                    'SELECT d FROM %s d
714
                    WHERE d.start BETWEEN :threshold AND :actime
715 1
                    ORDER BY d.id ASC',
716 1
                    Deals::class
717 1
                )
718 1
            )
719 1
            ->setParameters([
720 1
                'actime' => time(),
721 1
                'threshold' => $timeThreshold,
722 1
            ])
723 1
            ->getResult();
724
    }
725
}
726