Completed
Pull Request — master (#83)
by Mikołaj
01:18
created

findEnabledByCode()   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\CmsPlugin\Repository;
14
15
use BitBag\CmsPlugin\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(): QueryBuilder
28
    {
29
        return $this->createQueryBuilder('o')
30
            ->leftJoin('o.translations', 'translation')
31
        ;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function findEnabledOrderedByPosition(string $localeCode): ?array
38
    {
39
        return $this->createQueryBuilder('o')
40
            ->leftJoin('o.translations', 'translation')
41
            ->where('translation.locale = :localeCode')
42
            ->andWhere('o.enabled = true')
43
            ->orderBy('o.position', 'DESC')
44
            ->setParameter('localeCode', $localeCode)
45
            ->getQuery()
46
            ->getResult()
47
        ;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function findOneEnabledByCode(string $code): ?FrequentlyAskedQuestionInterface
54
    {
55
        return $this->createQueryBuilder('o')
56
            ->where('o.code = :code')
57
            ->andWhere('o.enabled = true')
58
            ->setParameter('code', $code)
59
            ->getQuery()
60
            ->getOneOrNullResult()
61
        ;
62
    }
63
}
64