Completed
Pull Request — master (#142)
by
unknown
07:20
created

PageRepository::findOneEnabledBySlug()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 10
nc 1
nop 2
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 findOneEnabledByCode(string $code, ?string $localeCode): ?PageInterface
37
    {
38
        return $this->createQueryBuilder('o')
39
            ->leftJoin('o.translations', 'translation')
40
            ->where('translation.locale = :localeCode')
41
            ->andWhere('o.code = :code')
42
            ->andWhere('o.enabled = true')
43
            ->setParameter('code', $code)
44
            ->setParameter('localeCode', $localeCode)
45
            ->getQuery()
46
            ->getOneOrNullResult()
47
        ;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function findOneEnabledBySlugAndChannelCode(string $slug, ?string $localeCode, string $channelCode): ?PageInterface
54
    {
55
        return $this->createQueryBuilder('o')
56
            ->leftJoin('o.translations', 'translation')
57
            ->innerJoin('o.channels', 'channels')
58
            ->where('translation.locale = :localeCode')
59
            ->andWhere('translation.slug = :slug')
60
            ->andWhere('channels.code = :channelCode')
61
            ->andWhere('o.enabled = true')
62
            ->setParameter('localeCode', $localeCode)
63
            ->setParameter('slug', $slug)
64
            ->setParameter('channelCode', $channelCode)
65
            ->getQuery()
66
            ->getOneOrNullResult()
67
        ;
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    public function createShopListQueryBuilder(string $sectionCode, string $channelCode): QueryBuilder
74
    {
75
        return $this->createQueryBuilder('o')
76
            ->innerJoin('o.sections', 'section')
77
            ->innerJoin('o.channels', 'channels')
78
            ->where('section.code = :sectionCode')
79
            ->andWhere('o.enabled = true')
80
            ->andWhere('channels.code = :channelCode')
81
            ->setParameter('sectionCode', $sectionCode)
82
            ->setParameter('channelCode', $channelCode)
83
        ;
84
    }
85
}
86