|
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\NPCQuestUser; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @extends EntityRepository<NPCQuestUser> |
|
12
|
|
|
*/ |
|
13
|
|
|
final class NPCQuestUserRepository extends EntityRepository implements NPCQuestUserRepositoryInterface |
|
14
|
|
|
{ |
|
15
|
|
|
#[\Override] |
|
16
|
|
|
public function prototype(): NPCQuestUser |
|
17
|
|
|
{ |
|
18
|
|
|
return new NPCQuestUser(); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
#[\Override] |
|
22
|
|
|
public function save(NPCQuestUser $questUser): void |
|
23
|
|
|
{ |
|
24
|
|
|
$em = $this->getEntityManager(); |
|
25
|
|
|
|
|
26
|
|
|
$em->persist($questUser); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
#[\Override] |
|
30
|
|
|
public function delete(NPCQuestUser $questUser): void |
|
31
|
|
|
{ |
|
32
|
|
|
$em = $this->getEntityManager(); |
|
33
|
|
|
|
|
34
|
|
|
$em->remove($questUser); |
|
35
|
|
|
$em->flush(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
#[\Override] |
|
39
|
|
|
public function getByQuest(int $questId): array |
|
40
|
|
|
{ |
|
41
|
|
|
return $this->findBy( |
|
42
|
|
|
['quest_id' => $questId], |
|
43
|
|
|
['id' => 'ASC'] |
|
44
|
|
|
); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
#[\Override] |
|
48
|
|
|
public function getByUser(int $userId): array |
|
49
|
|
|
{ |
|
50
|
|
|
return $this->findBy( |
|
51
|
|
|
['user_id' => $userId], |
|
52
|
|
|
['id' => 'DESC'] |
|
53
|
|
|
); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
#[\Override] |
|
57
|
|
|
public function getByQuestAndUser(int $questId, int $userId): ?NPCQuestUser |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->findOneBy([ |
|
60
|
|
|
'quest_id' => $questId, |
|
61
|
|
|
'user_id' => $userId |
|
62
|
|
|
]); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
#[\Override] |
|
66
|
|
|
public function getByQuestAndMode(int $questId, int $mode): array |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->findBy([ |
|
69
|
|
|
'quest_id' => $questId, |
|
70
|
|
|
'mode' => $mode |
|
71
|
|
|
]); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
#[\Override] |
|
75
|
|
|
public function getUnrewardedByQuest(int $questId): array |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->findBy([ |
|
78
|
|
|
'quest_id' => $questId, |
|
79
|
|
|
'reward_received' => false |
|
80
|
|
|
]); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
#[\Override] |
|
84
|
|
|
public function truncateByQuest(int $questId): void |
|
85
|
|
|
{ |
|
86
|
|
|
$this->getEntityManager() |
|
87
|
|
|
->createQuery( |
|
88
|
|
|
sprintf( |
|
89
|
|
|
'DELETE FROM %s qu WHERE qu.quest_id = :questId', |
|
90
|
|
|
NPCQuestUser::class |
|
91
|
|
|
) |
|
92
|
|
|
) |
|
93
|
|
|
->setParameter('questId', $questId) |
|
94
|
|
|
->execute(); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
#[\Override] |
|
98
|
|
|
public function truncateByUser(int $userId): void |
|
99
|
|
|
{ |
|
100
|
|
|
$this->getEntityManager() |
|
101
|
|
|
->createQuery( |
|
102
|
|
|
sprintf( |
|
103
|
|
|
'DELETE FROM %s qu WHERE qu.user_id = :userId', |
|
104
|
|
|
NPCQuestUser::class |
|
105
|
|
|
) |
|
106
|
|
|
) |
|
107
|
|
|
->setParameter('userId', $userId) |
|
108
|
|
|
->execute(); |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|