Loading module/Application/src/Application/Search/Filter/StrReducedTextSearchFilter.php +13 −2 Original line number Diff line number Diff line Loading @@ -9,7 +9,12 @@ class StrReducedTextSearchFilter extends TextSearchFilter protected function applyToQueryBuilderUsingWhereField(QueryBuilder $qb) { $qb ->andWhere(sprintf("strReduce(%s) %s strReduce(:%s)", $this->whereField, $this->getOperator(), $paramName = uniqid('p'))) ->andWhere(sprintf( "strReduce(%s) %s strReduce(:%s)", $this->whereField, $this->getOperator(), $paramName = uniqid('p') )) ->setParameter($paramName, $this->getComparisonValue()); } Loading @@ -17,7 +22,13 @@ class StrReducedTextSearchFilter extends TextSearchFilter { $alias = current($qb->getRootAliases()); $qb ->andWhere(sprintf("strReduce(%s.%s) %s strReduce(:%s)", $alias, $this->getName(), $this->getOperator(), $paramName = uniqid('p'))) ->andWhere(sprintf( "strReduce(%s.%s) %s strReduce(:%s)", $alias, $this->getName(), $this->getOperator(), $paramName = uniqid('p') )) ->setParameter($paramName, $this->getComparisonValue()); } } module/Application/src/Application/Search/Filter/TextSearchFilter.php +14 −3 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ use Doctrine\ORM\QueryBuilder; class TextSearchFilter extends SearchFilter { protected bool $useLikeOperator = false; protected string $likeOperator = 'LIKE'; /** * @param bool $useLikeOperator Loading @@ -23,9 +24,19 @@ class TextSearchFilter extends SearchFilter return $this; } /** * @param string $likeOperator * @return self */ public function setLikeOperator(string $likeOperator): self { $this->likeOperator = $likeOperator; return $this; } protected function canApplyToQueryBuilder(): bool { $filterValue = $this->getValue(); $filterValue = trim($this->getValue()); return $filterValue !== null && strlen($filterValue) > 1; } Loading @@ -47,12 +58,12 @@ class TextSearchFilter extends SearchFilter protected function getOperator(): string { return $this->useLikeOperator ? 'LIKE' : '='; return $this->useLikeOperator ? $this->likeOperator : '='; } public function getComparisonValue(): string { $filterValue = $this->getValue(); $filterValue = trim($this->getValue()); return $this->useLikeOperator ? "%$filterValue%" : $filterValue; } Loading module/Application/src/Application/Search/SearchService.php +1 −1 Original line number Diff line number Diff line Loading @@ -335,7 +335,7 @@ abstract class SearchService implements SearchServiceInterface $qb = $this->createQueryBuilder(); foreach ($this->filters as $filter) { if ($filter->getValue()) { if ($filter->getValue() !== null) { $filter->applyToQueryBuilder($qb); } } Loading module/Doctorant/src/Doctorant/Search/DoctorantSearchFilter.php +1 −1 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ namespace Doctorant\Search; use Application\Search\Filter\TextSearchFilter; use Doctrine\ORM\QueryBuilder; class DoctorantSearchFilter extends TextSearchFilter class DoctorantSearchFilter extends TextSearchFilter // todo : hériter de StrReducedTextSearchFilter { const NAME = 'doctorant'; Loading Loading
module/Application/src/Application/Search/Filter/StrReducedTextSearchFilter.php +13 −2 Original line number Diff line number Diff line Loading @@ -9,7 +9,12 @@ class StrReducedTextSearchFilter extends TextSearchFilter protected function applyToQueryBuilderUsingWhereField(QueryBuilder $qb) { $qb ->andWhere(sprintf("strReduce(%s) %s strReduce(:%s)", $this->whereField, $this->getOperator(), $paramName = uniqid('p'))) ->andWhere(sprintf( "strReduce(%s) %s strReduce(:%s)", $this->whereField, $this->getOperator(), $paramName = uniqid('p') )) ->setParameter($paramName, $this->getComparisonValue()); } Loading @@ -17,7 +22,13 @@ class StrReducedTextSearchFilter extends TextSearchFilter { $alias = current($qb->getRootAliases()); $qb ->andWhere(sprintf("strReduce(%s.%s) %s strReduce(:%s)", $alias, $this->getName(), $this->getOperator(), $paramName = uniqid('p'))) ->andWhere(sprintf( "strReduce(%s.%s) %s strReduce(:%s)", $alias, $this->getName(), $this->getOperator(), $paramName = uniqid('p') )) ->setParameter($paramName, $this->getComparisonValue()); } }
module/Application/src/Application/Search/Filter/TextSearchFilter.php +14 −3 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ use Doctrine\ORM\QueryBuilder; class TextSearchFilter extends SearchFilter { protected bool $useLikeOperator = false; protected string $likeOperator = 'LIKE'; /** * @param bool $useLikeOperator Loading @@ -23,9 +24,19 @@ class TextSearchFilter extends SearchFilter return $this; } /** * @param string $likeOperator * @return self */ public function setLikeOperator(string $likeOperator): self { $this->likeOperator = $likeOperator; return $this; } protected function canApplyToQueryBuilder(): bool { $filterValue = $this->getValue(); $filterValue = trim($this->getValue()); return $filterValue !== null && strlen($filterValue) > 1; } Loading @@ -47,12 +58,12 @@ class TextSearchFilter extends SearchFilter protected function getOperator(): string { return $this->useLikeOperator ? 'LIKE' : '='; return $this->useLikeOperator ? $this->likeOperator : '='; } public function getComparisonValue(): string { $filterValue = $this->getValue(); $filterValue = trim($this->getValue()); return $this->useLikeOperator ? "%$filterValue%" : $filterValue; } Loading
module/Application/src/Application/Search/SearchService.php +1 −1 Original line number Diff line number Diff line Loading @@ -335,7 +335,7 @@ abstract class SearchService implements SearchServiceInterface $qb = $this->createQueryBuilder(); foreach ($this->filters as $filter) { if ($filter->getValue()) { if ($filter->getValue() !== null) { $filter->applyToQueryBuilder($qb); } } Loading
module/Doctorant/src/Doctorant/Search/DoctorantSearchFilter.php +1 −1 Original line number Diff line number Diff line Loading @@ -5,7 +5,7 @@ namespace Doctorant\Search; use Application\Search\Filter\TextSearchFilter; use Doctrine\ORM\QueryBuilder; class DoctorantSearchFilter extends TextSearchFilter class DoctorantSearchFilter extends TextSearchFilter // todo : hériter de StrReducedTextSearchFilter { const NAME = 'doctorant'; Loading