|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace App\Movies\Repository; |
|
5
|
|
|
|
|
6
|
|
|
use App\Movies\Entity\Movie; |
|
7
|
|
|
use App\Movies\Entity\MovieTranslations; |
|
8
|
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; |
|
9
|
|
|
use Doctrine\Common\Collections\Criteria; |
|
10
|
|
|
use Doctrine\Common\Collections\Expr\Expression; |
|
11
|
|
|
use Doctrine\Common\Collections\ExpressionBuilder; |
|
12
|
|
|
use Symfony\Bridge\Doctrine\RegistryInterface; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @method Movie|null find($id, $lockMode = null, $lockVersion = null) |
|
16
|
|
|
* @method Movie|null findOneBy(array $criteria, array $orderBy = null) |
|
17
|
|
|
* @method Movie[] findAll() |
|
18
|
|
|
* @method Movie[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) |
|
19
|
|
|
*/ |
|
20
|
|
|
class MovieRepository extends ServiceEntityRepository |
|
21
|
|
|
{ |
|
22
|
1 |
|
public function __construct(RegistryInterface $registry) |
|
23
|
|
|
{ |
|
24
|
1 |
|
parent::__construct($registry, Movie::class); |
|
25
|
1 |
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function search(string $query) |
|
28
|
|
|
{ |
|
29
|
|
|
$query = mb_strtolower($query); |
|
30
|
|
|
$result = $this->createQueryBuilder('m') |
|
31
|
|
|
->leftJoin('m.translations', 't') |
|
32
|
|
|
->andWhere('LOWER(m.originalTitle) LIKE :title OR LOWER(t.title) LIKE :title') |
|
33
|
|
|
->setParameter('title', "%{$query}%") |
|
34
|
|
|
->getQuery()->getResult(); |
|
35
|
|
|
|
|
36
|
|
|
return $result; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function getTmdbIds(array $ids) |
|
40
|
|
|
{ |
|
41
|
|
|
$result = $this->createQueryBuilder('m') |
|
42
|
|
|
->select('m.tmdb.id') |
|
43
|
|
|
->where('m.tmdb.id IN (:ids)') |
|
44
|
|
|
->setParameter('ids', $ids) |
|
45
|
|
|
->getQuery()->getArrayResult(); |
|
46
|
|
|
|
|
47
|
|
|
return $result; |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|