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

PageRepository::findEnabledBySlug()   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 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\PageInterface;
16
use Doctrine\ORM\QueryBuilder;
17
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
18
19
/**
20
 * @author Patryk Drapik <[email protected]>
21
 */
22
class PageRepository extends EntityRepository implements PageRepositoryInterface
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function createListQueryBuilder(string $locale): QueryBuilder
28
    {
29
        return $this->createQueryBuilder('o')
30
            ->innerJoin('o.translations', 'translation')
31
            ->where('translation.locale = :locale')
32
            ->setParameter('locale', $locale)
33
        ;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function findEnabledByCode(string $code): ?PageInterface
40
    {
41
        return $this->createQueryBuilder('o')
42
            ->where('o.code = :code')
43
            ->andWhere('o.enabled = true')
44
            ->setParameter('code', $code)
45
            ->getQuery()
46
            ->getOneOrNullResult()
47
        ;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function findEnabledBySlug(string $slug, string $localeCode): ?PageInterface
54
    {
55
        return $this->createQueryBuilder('o')
56
            ->addSelect('translation')
57
            ->innerJoin('o.translations', 'translation', 'WITH', 'translation.locale = :locale')
58
            ->andWhere('translation.slug = :slug')
59
            ->andWhere('o.enabled = true')
60
            ->setParameter('locale', $localeCode)
61
            ->setParameter('slug', $slug)
62
            ->getQuery()
63
            ->getOneOrNullResult()
64
        ;
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70
    public function createEnabledBySectionCodeListQueryBuilder(string $code): QueryBuilder
71
    {
72
        return $this->createQueryBuilder('o')
73
            ->innerJoin('o.sections', 'section')
74
            ->andWhere('section.code = :sectionCode')
75
            ->andWhere('o.enabled = true')
76
            ->setParameter('sectionCode', $code)
77
        ;
78
    }
79
}
80