Completed
Pull Request — master (#152)
by
unknown
24:07
created

PageRepository::findByEnabled()   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
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file has been created by 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\PageInterface;
16
use Doctrine\ORM\QueryBuilder;
17
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
18
19
class PageRepository extends EntityRepository implements PageRepositoryInterface
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function createListQueryBuilder(string $locale): QueryBuilder
25
    {
26
        return $this->createQueryBuilder('o')
27
            ->innerJoin('o.translations', 'translation')
28
            ->where('translation.locale = :locale')
29
            ->setParameter('locale', $locale)
30
        ;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function findByEnabled(bool $enabled): array
37
    {
38
        return $this->createQueryBuilder('o')
39
            ->addSelect('translation')
40
            ->innerJoin('o.translations', 'translation')
41
            ->andWhere('o.enabled = :enabled')
42
            ->setParameter('enabled', $enabled)
43
            ->getQuery()
44
            ->getResult()
45
        ;
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function findOneEnabledByCode(string $code, ?string $localeCode): ?PageInterface
52
    {
53
        return $this->createQueryBuilder('o')
54
            ->leftJoin('o.translations', 'translation')
55
            ->where('translation.locale = :localeCode')
56
            ->andWhere('o.code = :code')
57
            ->andWhere('o.enabled = true')
58
            ->setParameter('code', $code)
59
            ->setParameter('localeCode', $localeCode)
60
            ->getQuery()
61
            ->getOneOrNullResult()
62
        ;
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    public function findOneEnabledBySlug(string $slug, ?string $localeCode): ?PageInterface
69
    {
70
        return $this->createQueryBuilder('o')
71
            ->leftJoin('o.translations', 'translation')
72
            ->where('translation.locale = :localeCode')
73
            ->andWhere('translation.slug = :slug')
74
            ->andWhere('o.enabled = true')
75
            ->setParameter('localeCode', $localeCode)
76
            ->setParameter('slug', $slug)
77
            ->getQuery()
78
            ->getOneOrNullResult()
79
        ;
80
    }
81
82
    /**
83
     * {@inheritdoc}
84
     */
85
    public function createShopListQueryBuilder(string $sectionCode): QueryBuilder
86
    {
87
        return $this->createQueryBuilder('o')
88
            ->innerJoin('o.sections', 'section')
89
            ->where('section.code = :sectionCode')
90
            ->andWhere('o.enabled = true')
91
            ->setParameter('sectionCode', $sectionCode)
92
        ;
93
    }
94
}
95