Skip to content

Commit

Permalink
[Athena] Add less than filter
Browse files Browse the repository at this point in the history
  • Loading branch information
that-guy-iain committed Nov 27, 2023
1 parent 8a1b6e1 commit 5082cf6
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions src/Parthenon/Athena/Filters/LessThanFilter.php
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);
}
}

0 comments on commit 5082cf6

Please sign in to comment.