Completed
Pull Request — master (#81)
by Mikołaj
01:17
created

BlockRepository::createListQueryBuilder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 5
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\BlockInterface;
16
use Doctrine\ORM\QueryBuilder;
17
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
18
19
/**
20
 * @author Patryk Drapik <[email protected]>
21
 * @author Mikołaj Król <[email protected]>
22
 */
23
class BlockRepository extends EntityRepository implements BlockRepositoryInterface
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function createListQueryBuilder(string $locale): QueryBuilder
29
    {
30
        return $this->createQueryBuilder('o')
31
            ->innerJoin('o.translations', 'translation')
32
            ->where('translation.locale = :locale')
33
            ->setParameter('locale', $locale)
34
        ;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function findEnabledByCode(string $code): ?BlockInterface
41
    {
42
        return $this->createQueryBuilder('o')
43
            ->where('o.code = :code')
44
            ->andWhere('o.enabled = true')
45
            ->setParameter('code', $code)
46
            ->getQuery()
47
            ->getOneOrNullResult()
48
        ;
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function findEnabledByCodeAndContent(string $code, string $content): ?BlockInterface
55
    {
56
        return $this->createQueryBuilder('o')
57
            ->leftJoin('o.translations', 'translation')
58
            ->where('o.code = :code')
59
            ->andWhere('o.enabled = true')
60
            ->andWhere('translation.content = :content')
61
            ->setParameter('code', $code)
62
            ->setParameter('content', $content)
63
            ->getQuery()
64
            ->getOneOrNullResult()
65
        ;
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function findOneByTypeAndContent(string $type, string $content): ?BlockInterface
72
    {
73
        return $this->createQueryBuilder('o')
74
            ->leftJoin('o.translations', 'translation')
75
            ->where('o.type = :type')
76
            ->andWhere('o.enabled = true')
77
            ->andWhere('translation.content = :content')
78
            ->setParameter('type', $type)
79
            ->setParameter('content', $content)
80
            ->getQuery()
81
            ->getOneOrNullResult()
82
        ;
83
    }
84
85
    /**
86
     * {@inheritdoc}
87
     */
88
    public function createEnabledBySectionCodeListQueryBuilder(string $code): QueryBuilder
89
    {
90
        return $this->createQueryBuilder('o')
91
            ->innerJoin('o.sections', 'section')
92
            ->andWhere('section.code = :sectionCode')
93
            ->andWhere('o.enabled = true')
94
            ->setParameter('sectionCode', $code)
95
        ;
96
    }
97
}