Completed
Pull Request — master (#74)
by
unknown
01:10
created

FrequentlyAskedQuestionRepository   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 57
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createListQueryBuilder() 0 6 1
A findEnabledOrderedByPosition() 0 12 1
A findEnabledByCode() 0 10 1
A findEnabledBySectionCode() 0 11 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 findEnabledByCode(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
    /**
65
     * {@inheritdoc}
66
     */
67
    public function findEnabledBySectionCode(string $code): array
68
    {
69
        return $this->createQueryBuilder('o')
70
            ->innerJoin('o.sections', 'section')
71
            ->andWhere('section.code = :sectionCode')
72
            ->andWhere('o.enabled = true')
73
            ->setParameter('sectionCode', $code)
74
            ->getQuery()
75
            ->getResult()
76
        ;
77
    }
78
}
79