|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Uxmp\Core\Orm\Repository; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\ORM\EntityRepository; |
|
8
|
|
|
use Uxmp\Core\Orm\Model\Artist; |
|
9
|
|
|
use Uxmp\Core\Orm\Model\ArtistInterface; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @extends EntityRepository<ArtistInterface> |
|
13
|
|
|
*/ |
|
14
|
|
|
final class ArtistRepository extends EntityRepository implements ArtistRepositoryInterface |
|
15
|
|
|
{ |
|
16
|
1 |
|
public function prototype(): ArtistInterface |
|
17
|
|
|
{ |
|
18
|
1 |
|
return new Artist(); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
1 |
|
public function save(ArtistInterface $artist): void |
|
22
|
|
|
{ |
|
23
|
1 |
|
$this->getEntityManager()->persist($artist); |
|
24
|
1 |
|
$this->getEntityManager()->flush(); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
1 |
|
public function delete(ArtistInterface $artist): void |
|
28
|
|
|
{ |
|
29
|
1 |
|
$this->getEntityManager()->remove($artist); |
|
30
|
1 |
|
$this->getEntityManager()->flush(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
1 |
|
public function findByMbId(string $mbid): ?ArtistInterface |
|
34
|
|
|
{ |
|
35
|
1 |
|
return $this->findOneBy([ |
|
36
|
1 |
|
'mbid' => $mbid, |
|
37
|
1 |
|
]); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
1 |
|
public function getAllHavingNoRelations(): iterable |
|
41
|
|
|
{ |
|
42
|
1 |
|
return $this->getEntityManager() |
|
43
|
1 |
|
->createQuery( |
|
44
|
1 |
|
<<<DQL |
|
45
|
|
|
SELECT artist |
|
46
|
|
|
FROM Uxmp\Core\Orm\Model\Artist artist |
|
47
|
|
|
LEFT JOIN Uxmp\Core\Orm\Model\Album album |
|
48
|
|
|
WITH album.artist_id = artist.id |
|
49
|
|
|
GROUP BY artist HAVING COUNT(album.id) = 0 |
|
50
|
1 |
|
DQL |
|
51
|
1 |
|
) |
|
52
|
1 |
|
->toIterable(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function search(string $searchTerm): array |
|
56
|
|
|
{ |
|
57
|
|
|
$qb = $this->getEntityManager()->createQueryBuilder(); |
|
58
|
|
|
|
|
59
|
|
|
$qb |
|
60
|
|
|
->select('a') |
|
61
|
|
|
->from(Artist::class, 'a') |
|
62
|
|
|
->where( |
|
63
|
|
|
$qb->expr()->like('a.title', ':searchTerm') |
|
64
|
|
|
) |
|
65
|
|
|
->setParameter('searchTerm', sprintf('%%%s%%', $searchTerm)) |
|
66
|
|
|
; |
|
67
|
|
|
|
|
68
|
|
|
return $qb->getQuery()->getResult(); |
|
|
|
|
|
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|