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

findOneEnabledByCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 7
nc 1
nop 1
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 BitBag\SyliusCmsPlugin\Entity\FrequentlyAskedQuestionInterface;
16
use Doctrine\ORM\QueryBuilder;
17
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
18
19
/**
20
 * @author Mikołaj Król <[email protected]>
21
 */
22
final class FrequentlyAskedQuestionRepository extends EntityRepository implements FrequentlyAskedQuestionRepositoryInterface
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function createListQueryBuilder(string $locale): QueryBuilder
28
    {
29
        return $this->createQueryBuilder('o')
30
            ->innerJoin('o.translations', 'translation')
31
            ->where('translation.locale = :locale')
32
            ->setParameter('locale', $locale)
33
        ;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function findEnabledOrderedByPosition(string $localeCode): array
40
    {
41
        return $this->createQueryBuilder('o')
42
            ->leftJoin('o.translations', 'translation')
43
            ->where('translation.locale = :localeCode')
44
            ->andWhere('o.enabled = true')
45
            ->orderBy('o.position', 'ASC')
46
            ->setParameter('localeCode', $localeCode)
47
            ->getQuery()
48
            ->getResult()
49
        ;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function findOneEnabledByCode(string $code): ?FrequentlyAskedQuestionInterface
56
    {
57
        return $this->createQueryBuilder('o')
58
            ->where('o.code = :code')
59
            ->andWhere('o.enabled = true')
60
            ->setParameter('code', $code)
61
            ->getQuery()
62
            ->getOneOrNullResult()
63
        ;
64
    }
65
}
66