Completed
Pull Request — master (#95)
by
unknown
01:30
created

SectionRepository::findByNamePart()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 8
nc 1
nop 2
1
<?php
2
3
/**
4
 * This file was created by the developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * another great project.
7
 * You can find more information about us on https://bitbag.shop and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace BitBag\SyliusCmsPlugin\Repository;
14
15
use Doctrine\ORM\QueryBuilder;
16
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
17
18
/**
19
 * @author Patryk Drapik <[email protected]>
20
 */
21
class SectionRepository extends EntityRepository implements SectionRepositoryInterface
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function createListQueryBuilder(): QueryBuilder
27
    {
28
        return $this->createQueryBuilder('o')
29
            ->leftJoin('o.translations', 'translation')
30
        ;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function findByNamePart(string $phrase, ?string $locale = null): array
37
    {
38
        return $this->createQueryBuilder('o')
39
            ->innerJoin('o.translations', 'translation', 'WITH', 'translation.locale = :locale')
40
            ->andWhere('translation.name LIKE :name')
41
            ->setParameter('name', '%'.$phrase.'%')
42
            ->setParameter('locale', $locale)
43
            ->getQuery()
44
            ->getResult()
45
        ;
46
    }
47
}
48