Completed
Push — master ( d15cf4...5163a0 )
by Valentyn
06:05
created

MovieRepository::getTmdbIds()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 7
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 1
crap 2
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