Completed
Push — master ( b77bbc...7eba37 )
by Mikołaj
02:49 queued 01:41
created

PageRepository::findEnabledByCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 7
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\PageInterface;
16
use Doctrine\ORM\QueryBuilder;
17
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
18
use Sylius\Component\Core\Model\ChannelInterface;
19
20
/**
21
 * @author Patryk Drapik <[email protected]>
22
 */
23
class PageRepository extends EntityRepository implements PageRepositoryInterface
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): ?PageInterface
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 findEnabledBySlug(string $slug, string $localeCode): ?PageInterface
55
    {
56
        return $this->createQueryBuilder('o')
57
            ->addSelect('translation')
58
            ->innerJoin('o.translations', 'translation', 'WITH', 'translation.locale = :locale')
59
            ->andWhere('translation.slug = :slug')
60
            ->andWhere('o.enabled = true')
61
            ->setParameter('locale', $localeCode)
62
            ->setParameter('slug', $slug)
63
            ->getQuery()
64
            ->getOneOrNullResult()
65
        ;
66
    }
67
}
68