Completed
Push — taxon-parent-form ( 0ec4cc...456861 )
by Kamil
20:21
created

TaxonRepository::findNodesTreeSorted()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 11
nc 2
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\TaxonomyBundle\Doctrine\ORM;
13
14
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
15
use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface;
16
17
/**
18
 * @author Aram Alipoor <[email protected]>
19
 */
20
class TaxonRepository extends EntityRepository implements TaxonRepositoryInterface
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function findChildren($parentCode, $locale)
26
    {
27
        return $this->createQueryBuilder('o')
28
            ->addSelect('translation')
29
            ->addSelect('child')
30
            ->innerJoin('o.parent', 'parent')
31
            ->innerJoin('o.translations', 'translation', 'WITH', 'translation.locale = :locale')
32
            ->leftJoin('o.children', 'child')
33
            ->andWhere('parent.code = :parentCode')
34
            ->addOrderBy('o.position')
35
            ->setParameter('parentCode', $parentCode)
36
            ->setParameter('locale', $locale)
37
            ->getQuery()
38
            ->getResult()
39
        ;
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function findOneBySlug($slug, $locale)
46
    {
47
        return $this->createQueryBuilder('o')
48
            ->addSelect('translation')
49
            ->innerJoin('o.translations', 'translation')
50
            ->andWhere('translation.slug = :slug')
51
            ->andWhere('translation.locale = :locale')
52
            ->setParameter('slug', $slug)
53
            ->setParameter('locale', $locale)
54
            ->getQuery()
55
            ->getOneOrNullResult()
56
        ;
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function findByName($name, $locale)
63
    {
64
        return $this->createQueryBuilder('o')
65
            ->addSelect('translation')
66
            ->innerJoin('o.translations', 'translation')
67
            ->andWhere('translation.name = :name')
68
            ->andWhere('translation.locale = :locale')
69
            ->setParameter('name', $name)
70
            ->setParameter('locale', $locale)
71
            ->getQuery()
72
            ->getResult()
73
        ;
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79
    public function findRootNodes()
80
    {
81
        return $this->createQueryBuilder('o')
82
            ->andWhere('o.parent IS NULL')
83
            ->addOrderBy('o.position')
84
            ->getQuery()
85
            ->getResult()
86
        ;
87
    }
88
89
    /**
90
     * {@inheritdoc}
91
     */
92
    public function findByNamePart($phrase, $locale)
93
    {
94
        return $this->createQueryBuilder('o')
95
            ->addSelect('translation')
96
            ->innerJoin('o.translations', 'translation')
97
            ->andWhere('translation.name LIKE :name')
98
            ->andWhere('translation.locale = :locale')
99
            ->setParameter('name', '%'.$phrase.'%')
100
            ->setParameter('locale', $locale)
101
            ->getQuery()
102
            ->getResult()
103
        ;
104
    }
105
106
    /**
107
     * {@inheritdoc}
108
     */
109
    public function createListQueryBuilder()
110
    {
111
        return $this->createQueryBuilder('o')->leftJoin('o.translations', 'translation');
112
    }
113
}
114