|
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\NPCQuestLog; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @extends EntityRepository<NPCQuestLog> |
|
12
|
|
|
*/ |
|
13
|
|
|
final class NPCQuestLogRepository extends EntityRepository implements NPCQuestLogRepositoryInterface |
|
14
|
|
|
{ |
|
15
|
|
|
#[\Override] |
|
16
|
|
|
public function prototype(): NPCQuestLog |
|
17
|
|
|
{ |
|
18
|
|
|
return new NPCQuestLog(); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
#[\Override] |
|
22
|
|
|
public function save(NPCQuestLog $log): void |
|
23
|
|
|
{ |
|
24
|
|
|
$em = $this->getEntityManager(); |
|
25
|
|
|
|
|
26
|
|
|
$em->persist($log); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
#[\Override] |
|
30
|
|
|
public function delete(NPCQuestLog $log): void |
|
31
|
|
|
{ |
|
32
|
|
|
$em = $this->getEntityManager(); |
|
33
|
|
|
|
|
34
|
|
|
$em->remove($log); |
|
35
|
|
|
$em->flush(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
#[\Override] |
|
39
|
|
|
public function getByQuest(int $questId): array |
|
40
|
|
|
{ |
|
41
|
|
|
return $this->findBy( |
|
42
|
|
|
['quest_id' => $questId], |
|
43
|
|
|
['date' => 'DESC'] |
|
44
|
|
|
); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
#[\Override] |
|
48
|
|
|
public function getByUser(int $userId): array |
|
49
|
|
|
{ |
|
50
|
|
|
return $this->findBy( |
|
51
|
|
|
['user_id' => $userId], |
|
52
|
|
|
['date' => 'DESC'] |
|
53
|
|
|
); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
#[\Override] |
|
57
|
|
|
public function getByQuestAndUser(int $questId, int $userId): array |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->findBy( |
|
60
|
|
|
[ |
|
61
|
|
|
'quest_id' => $questId, |
|
62
|
|
|
'user_id' => $userId |
|
63
|
|
|
], |
|
64
|
|
|
['date' => 'DESC'] |
|
65
|
|
|
); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
#[\Override] |
|
69
|
|
|
public function getActiveByQuest(int $questId): array |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->getEntityManager() |
|
72
|
|
|
->createQuery( |
|
73
|
|
|
sprintf( |
|
74
|
|
|
'SELECT l FROM %s l |
|
75
|
|
|
WHERE l.quest_id = :questId |
|
76
|
|
|
AND l.deleted IS NULL |
|
77
|
|
|
ORDER BY l.date DESC', |
|
78
|
|
|
NPCQuestLog::class |
|
79
|
|
|
) |
|
80
|
|
|
) |
|
81
|
|
|
->setParameter('questId', $questId) |
|
82
|
|
|
->getResult(); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
#[\Override] |
|
86
|
|
|
public function getActiveByQuestAndUser(int $questId, int $userId): array |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->getEntityManager() |
|
89
|
|
|
->createQuery( |
|
90
|
|
|
sprintf( |
|
91
|
|
|
'SELECT l FROM %s l |
|
92
|
|
|
WHERE l.quest_id = :questId |
|
93
|
|
|
AND l.user_id = :userId |
|
94
|
|
|
AND l.deleted IS NULL |
|
95
|
|
|
ORDER BY l.date DESC', |
|
96
|
|
|
NPCQuestLog::class |
|
97
|
|
|
) |
|
98
|
|
|
) |
|
99
|
|
|
->setParameters([ |
|
100
|
|
|
'questId' => $questId, |
|
101
|
|
|
'userId' => $userId |
|
102
|
|
|
]) |
|
103
|
|
|
->getResult(); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
#[\Override] |
|
107
|
|
|
public function truncateByQuest(int $questId): void |
|
108
|
|
|
{ |
|
109
|
|
|
$this->getEntityManager() |
|
110
|
|
|
->createQuery( |
|
111
|
|
|
sprintf( |
|
112
|
|
|
'DELETE FROM %s l WHERE l.quest_id = :questId', |
|
113
|
|
|
NPCQuestLog::class |
|
114
|
|
|
) |
|
115
|
|
|
) |
|
116
|
|
|
->setParameter('questId', $questId) |
|
117
|
|
|
->execute(); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
#[\Override] |
|
121
|
|
|
public function truncateByUser(int $userId): void |
|
122
|
|
|
{ |
|
123
|
|
|
$this->getEntityManager() |
|
124
|
|
|
->createQuery( |
|
125
|
|
|
sprintf( |
|
126
|
|
|
'DELETE FROM %s l WHERE l.user_id = :userId', |
|
127
|
|
|
NPCQuestLog::class |
|
128
|
|
|
) |
|
129
|
|
|
) |
|
130
|
|
|
->setParameter('userId', $userId) |
|
131
|
|
|
->execute(); |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|