Skip to content

Commit

Permalink
Fix on same op (#144)
Browse files Browse the repository at this point in the history
Change-Id: I9bfc17c3899eacac24ec7de487705cfeeb91a81a
  • Loading branch information
smarcet committed May 18, 2023
1 parent ea0ca13 commit 13f9c6f
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions app/Http/Utils/Filters/DoctrineInstanceOfFilterMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,29 @@ private function translateClassName($value)
return $value;
}

private function buildWhere(QueryBuilder $query, FilterElement $filter):string{
$value = $filter->getValue();

if (is_array($value)) {
$where_components = [];

foreach ($value as $val) {
$where_components[] = str_replace(":class_name", $this->translateClassName($val), $this->where);
}

return implode(sprintf(" %s ", $filter->getSameFieldOp()), $where_components);
}
return str_replace(":class_name", $this->translateClassName($filter->getValue()), $this->where);
}

/**
* @param QueryBuilder $query
* @param FilterElement $filter
* @return QueryBuilder
*/
public function apply(QueryBuilder $query, FilterElement $filter): QueryBuilder
{
$where = str_replace(":class_name", $this->translateClassName($filter->getValue()), $this->where);
return $query->andWhere($where);
return $query->andWhere($this->buildWhere($query, $filter));
}

/**
Expand All @@ -65,8 +79,7 @@ public function apply(QueryBuilder $query, FilterElement $filter): QueryBuilder
*/
public function applyOr(QueryBuilder $query, FilterElement $filter): string
{
$where = str_replace(":class_name", $this->translateClassName($filter->getValue()), $this->where);
return $where;
return $this->buildWhere($query, $filter);
}

}

0 comments on commit 13f9c6f

Please sign in to comment.