Added filters for creationDate and lastModified state

This commit is contained in:
Jan Böhmer 2022-08-20 00:10:41 +02:00
parent 798eb4c1bc
commit d3a42cd989
6 changed files with 137 additions and 9 deletions

View file

@ -0,0 +1,10 @@
<?php
namespace App\DataTables\Filters\Constraints;
/**
* An alias of NumberConstraint to use to filter on a DateTime
*/
class DateTimeConstraint extends NumberConstraint
{
}

View file

@ -12,13 +12,13 @@ class NumberConstraint extends AbstractConstraint
/**
* The value1 used for comparison (this is the main one used for all mono-value comparisons)
* @var float|null
* @var float|null|int|\DateTimeInterface
*/
protected $value1;
/**
* The second value used when operator is RANGE; this is the upper bound of the range
* @var float|null
* @var float|null|int|\DateTimeInterface
*/
protected $value2;
@ -28,7 +28,7 @@ class NumberConstraint extends AbstractConstraint
protected $operator;
/**
* @return float|mixed|null
* @return float|int|null|\DateTimeInterface
*/
public function getValue1()
{
@ -36,7 +36,7 @@ class NumberConstraint extends AbstractConstraint
}
/**
* @param float|mixed|null $value1
* @param float|int|\DateTimeInterface|null $value1
*/
public function setValue1($value1): void
{
@ -44,7 +44,7 @@ class NumberConstraint extends AbstractConstraint
}
/**
* @return float|mixed|null
* @return float|int|null
*/
public function getValue2()
{
@ -52,7 +52,7 @@ class NumberConstraint extends AbstractConstraint
}
/**
* @param float|mixed|null $value2
* @param float|int|null $value2
*/
public function setValue2($value2): void
{
@ -60,7 +60,7 @@ class NumberConstraint extends AbstractConstraint
}
/**
* @return mixed|string
* @return string
*/
public function getOperator(): string
{
@ -68,7 +68,7 @@ class NumberConstraint extends AbstractConstraint
}
/**
* @param mixed|string $operator
* @param string $operator
*/
public function setOperator(?string $operator): void
{

View file

@ -3,6 +3,7 @@
namespace App\DataTables\Filters;
use App\DataTables\Filters\Constraints\BooleanConstraint;
use App\DataTables\Filters\Constraints\DateTimeConstraint;
use App\DataTables\Filters\Constraints\NumberConstraint;
use App\DataTables\Filters\Constraints\TextConstraint;
use Doctrine\ORM\QueryBuilder;
@ -27,6 +28,12 @@ class PartFilter implements FilterInterface
/** @var NumberConstraint */
protected $mass;
/** @var DateTimeConstraint */
protected $lastModified;
/** @var DateTimeConstraint */
protected $addedDate;
/**
* @return BooleanConstraint|false
*/
@ -58,13 +65,33 @@ class PartFilter implements FilterInterface
return $this->description;
}
/**
* @return DateTimeConstraint
*/
public function getLastModified(): DateTimeConstraint
{
return $this->lastModified;
}
/**
* @return DateTimeConstraint
*/
public function getAddedDate(): DateTimeConstraint
{
return $this->addedDate;
}
public function __construct()
{
$this->favorite = new BooleanConstraint('part.favorite');
$this->favorite =
$this->needsReview = new BooleanConstraint('part.needs_review');
$this->mass = new NumberConstraint('part.mass');
$this->name = new TextConstraint('part.name');
$this->description = new TextConstraint('part.description');
$this->addedDate = new DateTimeConstraint('part.addedDate');
$this->lastModified = new DateTimeConstraint('part.lastModified');
}
public function apply(QueryBuilder $queryBuilder): void