1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Bugloos\QuerySortingBundle\SortingHandler; |
6
|
|
|
|
7
|
|
|
use Bugloos\QuerySortingBundle\SortingHandler\Contract\AbstractSortingHandler; |
8
|
|
|
use Bugloos\QuerySortingBundle\SortingHandler\Contract\WithRelationInterface; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @author Milad Ghofrani <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
class ThreeLevelRelationHandler extends AbstractSortingHandler implements WithRelationInterface |
14
|
|
|
{ |
15
|
|
|
public function getSortProperty($rootAlias, $rootClass, $relationsAndFieldName): string |
16
|
|
|
{ |
17
|
|
|
[$relationAlias, $secondRelationAlias, $thirdRelationAlias, $subRelationField] = $relationsAndFieldName; |
18
|
|
|
|
19
|
|
|
$this->validateRelationNames($relationAlias, $rootClass); |
20
|
|
|
|
21
|
|
|
$relationClass = $this->getRelationClass($rootClass, $relationAlias); |
22
|
|
|
$this->validateRelationNames($secondRelationAlias, $relationClass); |
23
|
|
|
|
24
|
|
|
$secondRelationClass = $this->getRelationClass($relationClass, $secondRelationAlias); |
25
|
|
|
$this->validateRelationNames($subRelationField, $secondRelationClass); |
26
|
|
|
|
27
|
|
|
$thirdRelationClass = $this->getRelationClass($secondRelationClass, $thirdRelationAlias); |
28
|
|
|
$this->validateFieldNames($subRelationField, $thirdRelationClass); |
29
|
|
|
|
30
|
|
|
return $this->createOrderBySyntax($thirdRelationAlias, $subRelationField); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function getRelationJoin($relationJoins, $rootAlias, $rootClass, $relationsAndFieldName): array |
34
|
|
|
{ |
35
|
|
|
[$relationAlias, $subRelationAlias, $thirdRelationAlias] = $relationsAndFieldName; |
36
|
|
|
|
37
|
|
|
$relationJoins = $this->addRelationJoin($relationJoins, $rootAlias, $relationAlias); |
38
|
|
|
|
39
|
|
|
$relationJoins = $this->addRelationJoin($relationJoins, $relationAlias, $subRelationAlias); |
40
|
|
|
|
41
|
|
|
return $this->addRelationJoin($relationJoins, $subRelationAlias, $thirdRelationAlias); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|