1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Orm\Repository; |
6
|
|
|
|
7
|
|
|
use Doctrine\ORM\EntityRepository; |
8
|
|
|
use Stu\Orm\Entity\KnPostArchiv; |
9
|
|
|
use Stu\Orm\Entity\RpgPlotArchiv; |
10
|
|
|
use Stu\Orm\Entity\RpgPlotArchivInterface; |
11
|
|
|
use Stu\Orm\Entity\RpgPlotMemberArchiv; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @extends EntityRepository<RpgPlotArchiv> |
15
|
|
|
*/ |
16
|
|
|
final class RpgPlotArchivRepository extends EntityRepository implements RpgPlotArchivRepositoryInterface |
17
|
|
|
{ |
18
|
|
|
public function getByFoundingUser(int $userId): array |
19
|
|
|
{ |
20
|
|
|
return $this->findBy([ |
21
|
|
|
'user_id' => $userId, |
22
|
|
|
]); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function prototype(): RpgPlotArchivInterface |
26
|
|
|
{ |
27
|
|
|
return new RpgPlotArchivInterface(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function save(RpgPlotArchivInterface $rpgPlot): void |
31
|
|
|
{ |
32
|
|
|
$em = $this->getEntityManager(); |
33
|
|
|
|
34
|
|
|
$em->persist($rpgPlot); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function delete(RpgPlotArchivInterface $rpgPlot): void |
38
|
|
|
{ |
39
|
|
|
$em = $this->getEntityManager(); |
40
|
|
|
|
41
|
|
|
$em->remove($rpgPlot); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function getActiveByUser(int $userId): array |
45
|
|
|
{ |
46
|
|
|
return $this->getEntityManager() |
|
|
|
|
47
|
|
|
->createQuery( |
48
|
|
|
sprintf( |
49
|
|
|
'SELECT p FROM %s p WHERE p.end_date IS NULL AND p.id IN ( |
50
|
|
|
SELECT pm.plot_id FROM %s pm WHERE pm.user_id = :userId |
51
|
|
|
) ORDER BY p.start_date DESC', |
52
|
|
|
RpgPlotArchiv::class, |
53
|
|
|
RpgPlotMemberArchiv::class |
54
|
|
|
) |
55
|
|
|
) |
56
|
|
|
->setParameters(['userId' => $userId]) |
57
|
|
|
->getResult(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function getEmptyOldPlots(int $maxAge): array |
61
|
|
|
{ |
62
|
|
|
return $this->getEntityManager() |
|
|
|
|
63
|
|
|
->createQuery( |
64
|
|
|
sprintf( |
65
|
|
|
'SELECT pl |
66
|
|
|
FROM %s pl |
67
|
|
|
WHERE NOT EXISTS (SELECT kn.id |
68
|
|
|
FROM %s kn |
69
|
|
|
WHERE kn.plot_id = pl.id) |
70
|
|
|
AND pl.start_date < :deletionThreshold', |
71
|
|
|
RpgPlotArchiv::class, |
72
|
|
|
KnPostArchiv::class |
73
|
|
|
) |
74
|
|
|
) |
75
|
|
|
->setParameters(['deletionThreshold' => time() - $maxAge]) |
76
|
|
|
->getResult(); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function getOrderedList(): array |
80
|
|
|
{ |
81
|
|
|
return $this->findBy([], ['start_date' => 'asc']); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function truncateAllEntities(): void |
85
|
|
|
{ |
86
|
|
|
$this->getEntityManager()->createQuery( |
87
|
|
|
sprintf( |
88
|
|
|
'DELETE FROM %s rp', |
89
|
|
|
RpgPlotArchiv::class |
90
|
|
|
) |
91
|
|
|
)->execute(); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|