-
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.
- Loading branch information
1 parent
8a1b6e1
commit 5082cf6
Showing
1 changed file
with
88 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* Copyright Humbly Arrogant Software Limited 2020-2023. | ||
* | ||
* Use of this software is governed by the Business Source License included in the LICENSE file and at https://getparthenon.com/docs/next/license. | ||
* | ||
* Change Date: 26.06.2026 ( 3 years after 2.2.0 release ) | ||
* | ||
* On the date above, in accordance with the Business Source License, use of this software will be governed by the open source license specified in the LICENSE file. | ||
*/ | ||
|
||
namespace App\Parthenon\Athena\Filters; | ||
|
||
use Doctrine\ORM\Query; | ||
use Doctrine\ORM\QueryBuilder; | ||
use Parthenon\Athena\Filters\DoctrineFilterInterface; | ||
use Parthenon\Athena\Filters\FilterInterface; | ||
use Parthenon\Athena\Filters\QueryBuilderTrait; | ||
|
||
class LessThanFilter implements DoctrineFilterInterface | ||
{ | ||
use QueryBuilderTrait; | ||
|
||
public const NAME = 'less_than'; | ||
|
||
protected string $fieldName; | ||
|
||
private $data; | ||
|
||
public function modifyQueryBuilder(QueryBuilder $queryBuilder) | ||
{ | ||
if (!$this->data) { | ||
return; | ||
} | ||
[$alias, $fieldName] = $this->readyQueryBuilderForAliasAndFieldName($queryBuilder); | ||
$queryBuilder->andWhere($alias.'.'.$fieldName.' < :'.$this->getSafeFieldName()); | ||
} | ||
|
||
public function modifyQuery(Query $query) | ||
{ | ||
if (!$this->data) { | ||
return; | ||
} | ||
$query->setParameter(':'.$this->getSafeFieldName(), $this->data); | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return static::NAME; | ||
} | ||
|
||
public function setData($data): FilterInterface | ||
{ | ||
$this->data = $data; | ||
|
||
return $this; | ||
} | ||
|
||
public function setFieldName(string $fieldName): FilterInterface | ||
{ | ||
$this->fieldName = $fieldName; | ||
|
||
return $this; | ||
} | ||
|
||
public function getFieldName(): string | ||
{ | ||
return $this->fieldName; | ||
} | ||
|
||
public function getHeaderName(): string | ||
{ | ||
return ucwords(str_replace('_', ' ', $this->fieldName)); | ||
} | ||
|
||
public function getData() | ||
{ | ||
return $this->data; | ||
} | ||
|
||
public function hasData(): bool | ||
{ | ||
return isset($this->data); | ||
} | ||
} |