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\Model\TaxonInterface; |
16
|
|
|
use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface; |
17
|
|
|
use Webmozart\Assert\Assert; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Aram Alipoor <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class TaxonRepository extends EntityRepository implements TaxonRepositoryInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* {@inheritdoc} |
26
|
|
|
*/ |
27
|
|
|
public function findChildren(TaxonInterface $taxon) |
28
|
|
|
{ |
29
|
|
|
$root = $taxon->isRoot() ? $taxon : $taxon->getRoot(); |
30
|
|
|
|
31
|
|
|
$queryBuilder = $this->createQueryBuilder('o'); |
32
|
|
|
$queryBuilder |
33
|
|
|
->andWhere($queryBuilder->expr()->eq('o.root', ':root')) |
34
|
|
|
->andWhere($queryBuilder->expr()->lt('o.right', ':right')) |
35
|
|
|
->andWhere($queryBuilder->expr()->gt('o.left', ':left')) |
36
|
|
|
->setParameter('root', $root) |
37
|
|
|
->setParameter('left', $taxon->getLeft()) |
38
|
|
|
->setParameter('right', $taxon->getRight()) |
39
|
|
|
; |
40
|
|
|
|
41
|
|
|
return $queryBuilder->getQuery()->getResult(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritdoc} |
46
|
|
|
*/ |
47
|
|
|
public function findChildrenByRootCode($code) |
48
|
|
|
{ |
49
|
|
|
$root = $this->findOneBy(['code' => $code]); |
50
|
|
|
|
51
|
|
|
Assert::notNull($root, sprintf('Taxon with code "%s" not found.', $code)); |
52
|
|
|
|
53
|
|
|
return $this->findChildren($root); |
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* {@inheritdoc} |
58
|
|
|
*/ |
59
|
|
|
public function findOneByPermalink($permalink) |
60
|
|
|
{ |
61
|
|
|
return $this->createQueryBuilder('o') |
62
|
|
|
->addSelect('translation') |
63
|
|
|
->leftJoin('o.translations', 'translation') |
64
|
|
|
->where('translation.permalink = :permalink') |
65
|
|
|
->setParameter('permalink', $permalink) |
66
|
|
|
->orderBy('o.left') |
67
|
|
|
->getQuery() |
68
|
|
|
->getOneOrNullResult() |
69
|
|
|
; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* {@inheritdoc} |
74
|
|
|
*/ |
75
|
|
|
public function findOneByName($name) |
76
|
|
|
{ |
77
|
|
|
return $this->createQueryBuilder('o') |
78
|
|
|
->addSelect('translation') |
79
|
|
|
->leftJoin('o.translations', 'translation') |
80
|
|
|
->where('translation.name = :name') |
81
|
|
|
->setParameter('name', $name) |
82
|
|
|
->getQuery() |
83
|
|
|
->getOneOrNullResult() |
84
|
|
|
; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* {@inheritdoc} |
89
|
|
|
*/ |
90
|
|
|
public function findRootNodes() |
91
|
|
|
{ |
92
|
|
|
$queryBuilder = $this->createQueryBuilder('o'); |
93
|
|
|
$queryBuilder |
94
|
|
|
->andWhere($queryBuilder->expr()->isNull($this->getPropertyName('parent'))) |
95
|
|
|
; |
96
|
|
|
|
97
|
|
|
return $queryBuilder->getQuery()->getResult(); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* {@inheritdoc} |
102
|
|
|
*/ |
103
|
|
|
public function getFormQueryBuilder() |
104
|
|
|
{ |
105
|
|
|
return $this->createQueryBuilder('o'); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: