-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add three and four level relation handlers (#11)
* Add three and four level relation handlers Upgrade to PHP8 * Update README.md * Fix unit test issues * Fix unit test issues --------- Co-authored-by: mojtaba gheytasi <mojtaba.g@bugloos.com>
- Loading branch information
1 parent
29ac3b0
commit cb10f03
Showing
7 changed files
with
144 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bugloos\QuerySortingBundle\SortingHandler; | ||
|
||
use Bugloos\QuerySortingBundle\SortingHandler\Contract\AbstractSortingHandler; | ||
use Bugloos\QuerySortingBundle\SortingHandler\Contract\WithRelationInterface; | ||
|
||
/** | ||
* @author Milad Ghofrani <milad.ghofrani@gmail.com> | ||
*/ | ||
class FourLevelRelationHandler extends AbstractSortingHandler implements WithRelationInterface | ||
{ | ||
public function getSortProperty($rootAlias, $rootClass, $relationsAndFieldName): string | ||
{ | ||
[$relationAlias, $secondRelationAlias, $thirdRelationAlias, $fourthRelationAlias, $subRelationField] = $relationsAndFieldName; | ||
|
||
$this->validateRelationNames($relationAlias, $rootClass); | ||
|
||
$relationClass = $this->getRelationClass($rootClass, $relationAlias); | ||
$this->validateRelationNames($secondRelationAlias, $relationClass); | ||
|
||
$secondRelationClass = $this->getRelationClass($relationClass, $secondRelationAlias); | ||
$this->validateRelationNames($subRelationField, $secondRelationClass); | ||
|
||
$thirdRelationClass = $this->getRelationClass($secondRelationClass, $thirdRelationAlias); | ||
$this->validateFieldNames($subRelationField, $thirdRelationClass); | ||
|
||
$fourthRelationClass = $this->getRelationClass($thirdRelationClass, $fourthRelationAlias); | ||
$this->validateFieldNames($subRelationField, $fourthRelationClass); | ||
|
||
return $this->createOrderBySyntax($fourthRelationAlias, $subRelationField); | ||
} | ||
|
||
public function getRelationJoin($relationJoins, $rootAlias, $rootClass, $relationsAndFieldName): array | ||
{ | ||
[$relationAlias, $subRelationAlias, $thirdRelationAlias, $fourthRelationAlias] = $relationsAndFieldName; | ||
|
||
$relationJoins = $this->addRelationJoin($relationJoins, $rootAlias, $relationAlias); | ||
|
||
$relationJoins = $this->addRelationJoin($relationJoins, $relationAlias, $subRelationAlias); | ||
|
||
$relationJoins = $this->addRelationJoin($relationJoins, $subRelationAlias, $thirdRelationAlias); | ||
|
||
return $this->addRelationJoin($relationJoins, $thirdRelationAlias, $fourthRelationAlias); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bugloos\QuerySortingBundle\SortingHandler; | ||
|
||
use Bugloos\QuerySortingBundle\SortingHandler\Contract\AbstractSortingHandler; | ||
use Bugloos\QuerySortingBundle\SortingHandler\Contract\WithRelationInterface; | ||
|
||
/** | ||
* @author Milad Ghofrani <milad.ghofrani@gmail.com> | ||
*/ | ||
class ThreeLevelRelationHandler extends AbstractSortingHandler implements WithRelationInterface | ||
{ | ||
public function getSortProperty($rootAlias, $rootClass, $relationsAndFieldName): string | ||
{ | ||
[$relationAlias, $secondRelationAlias, $thirdRelationAlias, $subRelationField] = $relationsAndFieldName; | ||
|
||
$this->validateRelationNames($relationAlias, $rootClass); | ||
|
||
$relationClass = $this->getRelationClass($rootClass, $relationAlias); | ||
$this->validateRelationNames($secondRelationAlias, $relationClass); | ||
|
||
$secondRelationClass = $this->getRelationClass($relationClass, $secondRelationAlias); | ||
$this->validateRelationNames($subRelationField, $secondRelationClass); | ||
|
||
$thirdRelationClass = $this->getRelationClass($secondRelationClass, $thirdRelationAlias); | ||
$this->validateFieldNames($subRelationField, $thirdRelationClass); | ||
|
||
return $this->createOrderBySyntax($thirdRelationAlias, $subRelationField); | ||
} | ||
|
||
public function getRelationJoin($relationJoins, $rootAlias, $rootClass, $relationsAndFieldName): array | ||
{ | ||
[$relationAlias, $subRelationAlias, $thirdRelationAlias] = $relationsAndFieldName; | ||
|
||
$relationJoins = $this->addRelationJoin($relationJoins, $rootAlias, $relationAlias); | ||
|
||
$relationJoins = $this->addRelationJoin($relationJoins, $relationAlias, $subRelationAlias); | ||
|
||
return $this->addRelationJoin($relationJoins, $subRelationAlias, $thirdRelationAlias); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters