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