|
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\AllianceJob; |
|
9
|
|
|
use Stu\Orm\Entity\AllianceJobPermission; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @extends EntityRepository<AllianceJob> |
|
13
|
|
|
*/ |
|
14
|
|
|
final class AllianceJobRepository extends EntityRepository implements AllianceJobRepositoryInterface |
|
15
|
|
|
{ |
|
16
|
|
|
#[\Override] |
|
17
|
|
|
public function prototype(): AllianceJob |
|
18
|
|
|
{ |
|
19
|
|
|
return new AllianceJob(); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
#[\Override] |
|
23
|
|
|
public function save(AllianceJob $post): void |
|
24
|
|
|
{ |
|
25
|
|
|
$em = $this->getEntityManager(); |
|
26
|
|
|
$em->persist($post); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
#[\Override] |
|
30
|
|
|
public function delete(AllianceJob $post): void |
|
31
|
|
|
{ |
|
32
|
|
|
$em = $this->getEntityManager(); |
|
33
|
|
|
$em->remove($post); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
#[\Override] |
|
37
|
|
|
public function getByAlliance(int $allianceId): array |
|
38
|
|
|
{ |
|
39
|
|
|
return $this->createQueryBuilder('aj') |
|
40
|
|
|
->where('aj.alliance = :allianceId') |
|
41
|
|
|
->setParameter('allianceId', $allianceId) |
|
42
|
|
|
->orderBy('aj.sort', 'ASC') |
|
43
|
|
|
->getQuery() |
|
44
|
|
|
->getResult(); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
#[\Override] |
|
48
|
|
|
public function truncateByAlliance(int $allianceId): void |
|
49
|
|
|
{ |
|
50
|
|
|
$this->getEntityManager()->createQuery( |
|
51
|
|
|
sprintf( |
|
52
|
|
|
'DELETE FROM %s aj WHERE aj.alliance = :allianceId', |
|
53
|
|
|
AllianceJob::class |
|
54
|
|
|
) |
|
55
|
|
|
)->setParameters([ |
|
56
|
|
|
'allianceId' => $allianceId, |
|
57
|
|
|
])->execute(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
#[\Override] |
|
61
|
|
|
public function getJobsWithPermission(int $allianceId, int $permissionType): array |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->createQueryBuilder('aj') |
|
64
|
|
|
->innerJoin('aj.permissions', 'ajp') |
|
65
|
|
|
->where('aj.alliance = :allianceId') |
|
66
|
|
|
->andWhere('ajp.permission = :permissionType') |
|
67
|
|
|
->setParameter('allianceId', $allianceId) |
|
68
|
|
|
->setParameter('permissionType', $permissionType) |
|
69
|
|
|
->getQuery() |
|
70
|
|
|
->getResult(); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
#[\Override] |
|
74
|
|
|
public function getByAllianceAndTitle(int $allianceId, string $title): ?AllianceJob |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->createQueryBuilder('aj') |
|
77
|
|
|
->where('aj.alliance = :allianceId') |
|
78
|
|
|
->andWhere('aj.title = :title') |
|
79
|
|
|
->setParameter('allianceId', $allianceId) |
|
80
|
|
|
->setParameter('title', $title) |
|
81
|
|
|
->getQuery() |
|
82
|
|
|
->getOneOrNullResult(); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|