-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from ghonijee/hotfix/fixing-filter-relation
Fixing bug filter relation data
- Loading branch information
Showing
6 changed files
with
133 additions
and
30 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,55 @@ | ||
<?php | ||
|
||
namespace GhoniJee\DxAdapter\FilterClass; | ||
|
||
use Exception; | ||
use GhoniJee\DxAdapter\Data\FilterData; | ||
use GhoniJee\DxAdapter\Enums\ValueDataType; | ||
use GhoniJee\DxAdapter\FilterClass\QueryClass\BooleanFilter; | ||
use GhoniJee\DxAdapter\FilterClass\QueryClass\DateFilter; | ||
use GhoniJee\DxAdapter\FilterClass\QueryClass\NullFilter; | ||
use GhoniJee\DxAdapter\FilterClass\QueryClass\NumericFilter; | ||
use GhoniJee\DxAdapter\FilterClass\QueryClass\StringFilter; | ||
|
||
class BuilderRelationFilterQuery | ||
{ | ||
protected $query; | ||
|
||
protected FilterData $filterData; | ||
|
||
protected $conjungtion; | ||
|
||
public function __construct($query, FilterData $filterData, $conjungtion) | ||
{ | ||
$this->query = $query; | ||
$this->filterData = $filterData; | ||
$this->conjungtion = $conjungtion; | ||
} | ||
|
||
public static function fromDataType($query, FilterData $filterData, $conjungtion = null) | ||
{ | ||
return new self($query, $filterData, $conjungtion); | ||
} | ||
|
||
public function query() | ||
{ | ||
switch ($this->conjungtion) { | ||
case '!': | ||
$this->query->whereDoesntHave($this->filterData->relationMethod, function ($relationQuery) { | ||
$relationQuery = BuilderFilterQuery::fromDataType($relationQuery, $this->filterData)->query(); | ||
}); | ||
break; | ||
case 'or': | ||
$this->query->orWhereHas($this->filterData->relationMethod, function ($relationQuery) { | ||
$relationQuery = BuilderFilterQuery::fromDataType($relationQuery, $this->filterData)->query(); | ||
}); | ||
break; | ||
default: | ||
$this->query->whereHas($this->filterData->relationMethod, function ($relationQuery) { | ||
$relationQuery = BuilderFilterQuery::fromDataType($relationQuery, $this->filterData)->query(); | ||
}); | ||
break; | ||
} | ||
return $this->query; | ||
} | ||
} |
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