Completed
Push — symfony3-wololo ( 5670c9...50a832 )
by Kamil
20:37
created

createEnabledForChannelQueryBuilder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Bundle\CoreBundle\Doctrine\ORM;
13
14
use Doctrine\ORM\QueryBuilder;
15
use Sylius\Bundle\ShippingBundle\Doctrine\ORM\ShippingMethodRepository as BaseShippingMethodRepository;
16
use Sylius\Component\Core\Model\ChannelInterface;
17
use Sylius\Component\Core\Repository\ShippingMethodRepositoryInterface;
18
19
/**
20
 * @author Michał Marcinkowski <[email protected]>
21
 */
22
class ShippingMethodRepository extends BaseShippingMethodRepository implements ShippingMethodRepositoryInterface
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function createListQueryBuilder($locale)
28
    {
29
        return $this->createQueryBuilder('o')
30
            ->leftJoin('o.translations', 'translation')
31
            ->andWhere('translation.locale = :locale')
32
            ->setParameter('locale', $locale)
33
        ;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function findEnabledForChannel(ChannelInterface $channel)
40
    {
41
        return $this
42
            ->createEnabledForChannelQueryBuilder($channel)
43
            ->getQuery()
44
            ->getResult()
45
        ;
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function findEnabledForZonesAndChannel(array $zones, ChannelInterface $channel)
52
    {
53
        return $this
54
            ->createEnabledForChannelQueryBuilder($channel)
55
            ->andWhere('o.zone IN (:zones)')
56
            ->setParameter('zones', $zones)
57
            ->orderBy('o.position', 'asc')
58
            ->getQuery()
59
            ->getResult()
60
        ;
61
    }
62
63
    /**
64
     * @param ChannelInterface $channel
65
     *
66
     * @return QueryBuilder
67
     */
68
    protected function createEnabledForChannelQueryBuilder(ChannelInterface $channel)
69
    {
70
        $queryBuilder = $this
71
            ->createQueryBuilder('o')
72
            ->where('o.enabled = true')
73
        ;
74
75
        $queryBuilder
76
            ->innerJoin('o.channels', 'channel')
77
            ->andWhere($queryBuilder->expr()->eq('channel', ':channel'))
78
            ->setParameter('channel', $channel)
79
        ;
80
81
        return $queryBuilder;
82
    }
83
}
84