|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Uxmp\Core\Orm\Repository; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\ORM\EntityRepository; |
|
8
|
|
|
use JetBrains\PhpStorm\Pure; |
|
9
|
|
|
use Uxmp\Core\Orm\Model\AlbumInterface; |
|
10
|
|
|
use Uxmp\Core\Orm\Model\GenreMap; |
|
11
|
|
|
use Uxmp\Core\Orm\Model\GenreMapEnum; |
|
12
|
|
|
use Uxmp\Core\Orm\Model\GenreMapInterface; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @extends EntityRepository<GenreMap> |
|
16
|
|
|
* |
|
17
|
|
|
* @method null|GenreMapInterface findOneBy(mixed[] $criteria) |
|
18
|
|
|
*/ |
|
19
|
|
|
final class GenreMapRepository extends EntityRepository implements GenreMapRepositoryInterface |
|
20
|
|
|
{ |
|
21
|
1 |
|
#[Pure] |
|
22
|
|
|
public function prototype(): GenreMapInterface |
|
23
|
|
|
{ |
|
24
|
1 |
|
return new GenreMap(); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
1 |
|
public function save(GenreMapInterface $genreMap): void |
|
28
|
|
|
{ |
|
29
|
1 |
|
$this->getEntityManager()->persist($genreMap); |
|
30
|
1 |
|
$this->getEntityManager()->flush(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
1 |
|
public function delete(GenreMapInterface $genreMap): void |
|
34
|
|
|
{ |
|
35
|
1 |
|
$this->getEntityManager()->remove($genreMap); |
|
36
|
1 |
|
$this->getEntityManager()->flush(); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @return iterable<GenreMapInterface> |
|
41
|
|
|
*/ |
|
42
|
1 |
|
public function findByAlbum(AlbumInterface $album): iterable |
|
43
|
|
|
{ |
|
44
|
1 |
|
return $this->findBy([ |
|
45
|
1 |
|
'mapped_item_type' => GenreMapEnum::ALBUM, |
|
46
|
1 |
|
'mapped_item_id' => $album->getId(), |
|
47
|
1 |
|
]); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
1 |
|
public function deleteByAlbum(AlbumInterface $album): void |
|
51
|
|
|
{ |
|
52
|
1 |
|
$this |
|
53
|
1 |
|
->getEntityManager() |
|
54
|
1 |
|
->createQueryBuilder() |
|
55
|
1 |
|
->delete(GenreMap::class, 'gm') |
|
56
|
1 |
|
->where('gm.mapped_item_type = :itemType') |
|
57
|
1 |
|
->andWhere('gm.mapped_item_id = :itemId') |
|
58
|
1 |
|
->setParameters([ |
|
59
|
1 |
|
'itemType' => GenreMapEnum::ALBUM, |
|
60
|
1 |
|
'itemId' => $album->getId(), |
|
61
|
1 |
|
]) |
|
62
|
1 |
|
->getQuery() |
|
63
|
1 |
|
->execute(); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|