Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug refile #15

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
26 changes: 25 additions & 1 deletion src/Filter/OrFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,22 @@ class OrFilter extends Filter
*/
public $filters = [];

/**
* @var string
*/
public $chainType;

/**
* @param Filter[] $filters
*/
public function __construct(array $filters = [])
public function __construct(array $filters = [], $chainType = 'OR')
{
if ($filters) {
$this->setFilters($filters);
}
if ($chainType) {
$this->setChainType($chainType);
}
}

/**
Expand All @@ -43,4 +51,20 @@ public function addFilter(Filter $filter)
{
$this->filters[] = $filter;
}

/**
* @return string
*/
public function getChainType()
{
return $this->chainType;
}

/**
* @param string $chainType
*/
public function setChainType($chainType)
{
$this->chainType = $chainType;
}
}
25 changes: 18 additions & 7 deletions src/Model/ModelTrait/DBReadTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ protected function getOperator(Filter $filter)
* @param int $count
* @param Filter $filter
* @param ExtendedSelectStatement $selectStatement
* @param string $chainType
*
* @return bool
*/
protected function applyOrWhere($count, Filter $filter, ExtendedSelectStatement $selectStatement)
protected function applyOrWhere($count, Filter $filter, ExtendedSelectStatement $selectStatement, $chainType = 'OR')
{
if (!$count) {
$selectStatement->where(
Expand All @@ -89,11 +90,19 @@ protected function applyOrWhere($count, Filter $filter, ExtendedSelectStatement
return true;
}

$selectStatement->orWhere(
$this->translateDbName($filter->getFilterColumn()),
$this->getOperator($filter),
$filter->getFilterValue()
);
if ($chainType === 'OR') {
$selectStatement->orWhere(
$this->translateDbName($filter->getFilterColumn()),
$this->getOperator($filter),
$filter->getFilterValue()
);
} else if ($chainType === 'AND') {
$selectStatement->where(
$this->translateDbName($filter->getFilterColumn()),
$this->getOperator($filter),
$filter->getFilterValue()
);
}

return true;
}
Expand All @@ -106,8 +115,10 @@ protected function addOrWhere(OrFilter $filter, ExtendedSelectStatement $selectS
{
$selectStatement->addParenthesis();

$chainType = $filter->getChainType();

foreach ($filter->getFilters() as $count => $filter) {
$this->applyOrWhere($count, $filter, $selectStatement);
$this->applyOrWhere($count, $filter, $selectStatement, $chainType);
}

$selectStatement->closeParenthesis();
Expand Down