|
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\KnPostArchivInterface; |
|
10
|
|
|
use Stu\Orm\Entity\RpgPlotArchivInterface; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @extends EntityRepository<KnPostArchiv> |
|
14
|
|
|
*/ |
|
15
|
|
|
final class KnPostArchivRepository extends EntityRepository implements KnPostArchivRepositoryInterface |
|
16
|
|
|
{ |
|
17
|
|
|
public function prototype(): KnPostArchivInterface |
|
18
|
|
|
{ |
|
19
|
|
|
return new KnPostArchiv(); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function save(KnPostArchivInterface $post): void |
|
23
|
|
|
{ |
|
24
|
|
|
$em = $this->getEntityManager(); |
|
25
|
|
|
|
|
26
|
|
|
$em->persist($post); |
|
27
|
|
|
$em->flush(); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function delete(KnPostArchivInterface $post): void |
|
31
|
|
|
{ |
|
32
|
|
|
$em = $this->getEntityManager(); |
|
33
|
|
|
|
|
34
|
|
|
$em->remove($post); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function getBy(int $offset, int $limit): array |
|
38
|
|
|
{ |
|
39
|
|
|
return $this->findBy( |
|
40
|
|
|
[], |
|
41
|
|
|
['date' => 'desc'], |
|
42
|
|
|
$limit, |
|
43
|
|
|
$offset |
|
44
|
|
|
); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function getByUser(int $userId): array |
|
48
|
|
|
{ |
|
49
|
|
|
return $this->findBy( |
|
50
|
|
|
['user_id' => $userId], |
|
51
|
|
|
['id' => 'desc'] |
|
52
|
|
|
); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function getByPlot(RpgPlotArchivInterface $plot, ?int $offset, ?int $limit): array |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->findBy( |
|
58
|
|
|
['plot_id' => $plot], |
|
59
|
|
|
['date' => 'desc'], |
|
60
|
|
|
$limit, |
|
61
|
|
|
$offset |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function getAmount(): int |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->count([]); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function getAmountByPlot(int $plotId): int |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->count([ |
|
73
|
|
|
'plot_id' => $plotId |
|
74
|
|
|
]); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function getAmountSince(int $postId): int |
|
78
|
|
|
{ |
|
79
|
|
|
return (int) $this->getEntityManager() |
|
80
|
|
|
->createQuery( |
|
81
|
|
|
sprintf( |
|
82
|
|
|
'SELECT COUNT(p.id) FROM %s p WHERE p.id > :postId', |
|
83
|
|
|
KnPostArchiv::class |
|
84
|
|
|
) |
|
85
|
|
|
) |
|
86
|
|
|
->setParameters(['postId' => $postId]) |
|
87
|
|
|
->getSingleScalarResult(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function getNewerThenMark(int $mark): array |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->getEntityManager() |
|
|
|
|
|
|
93
|
|
|
->createQuery( |
|
94
|
|
|
sprintf( |
|
95
|
|
|
'SELECT p FROM %s p WHERE p.id > :postId ORDER BY p.id ASC', |
|
96
|
|
|
KnPostArchiv::class |
|
97
|
|
|
) |
|
98
|
|
|
) |
|
99
|
|
|
->setMaxResults(3) |
|
100
|
|
|
->setParameters(['postId' => $mark]) |
|
101
|
|
|
->getResult(); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function searchByContent(string $content): array |
|
105
|
|
|
{ |
|
106
|
|
|
return $this->getEntityManager() |
|
|
|
|
|
|
107
|
|
|
->createQuery( |
|
108
|
|
|
sprintf( |
|
109
|
|
|
'SELECT p FROM %s p |
|
110
|
|
|
WHERE UPPER(p.text) like UPPER(:content) OR UPPER(p.titel) like UPPER(:content) |
|
111
|
|
|
ORDER BY p.id DESC', |
|
112
|
|
|
KnPostArchiv::class |
|
113
|
|
|
) |
|
114
|
|
|
) |
|
115
|
|
|
->setParameters(['content' => sprintf('%%%s%%', $content)]) |
|
116
|
|
|
->getResult(); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function truncateAllEntities(): void |
|
120
|
|
|
{ |
|
121
|
|
|
$this->getEntityManager()->createQuery( |
|
122
|
|
|
sprintf( |
|
123
|
|
|
'DELETE FROM %s kp', |
|
124
|
|
|
KnPostArchiv::class |
|
125
|
|
|
) |
|
126
|
|
|
)->execute(); |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|