|
18 | 18 |
|
19 | 19 | namespace App\Admin\Filter;
|
20 | 20 |
|
| 21 | +use Doctrine\ORM\Query\Expr; |
21 | 22 | use Doctrine\ORM\QueryBuilder;
|
22 | 23 | use EasyCorp\Bundle\EasyAdminBundle\Contracts\Filter\FilterInterface;
|
23 | 24 | use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
|
@@ -45,12 +46,22 @@ public function apply(QueryBuilder $queryBuilder, FilterDataDto $filterDataDto,
|
45 | 46 | $comparison = 'IS NULL';
|
46 | 47 | $queryBuilder
|
47 | 48 | ->andWhere(sprintf('%s.%s %s', $filterDataDto->getEntityAlias(), 'confirmation1.timestamp', $comparison))
|
48 |
| - ->orWhere(sprintf('%s.%s %s', $filterDataDto->getEntityAlias(), 'confirmation2.timestamp', $comparison)); |
| 49 | + ->orWhere( |
| 50 | + $queryBuilder->expr()->andX( |
| 51 | + sprintf('%s.%s %s', $filterDataDto->getEntityAlias(), 'confirmation2.timestamp', $comparison), |
| 52 | + sprintf('%s.%s > 1', $filterDataDto->getEntityAlias(), 'requiredConfirmations') |
| 53 | + ) |
| 54 | + ); |
49 | 55 | } else {
|
50 | 56 | $comparison = 'IS NOT NULL';
|
51 | 57 | $queryBuilder
|
52 | 58 | ->andWhere(sprintf('%s.%s %s', $filterDataDto->getEntityAlias(), 'confirmation1.timestamp', $comparison))
|
53 |
| - ->andWhere(sprintf('%s.%s %s', $filterDataDto->getEntityAlias(), 'confirmation2.timestamp', $comparison)); |
| 59 | + ->andWhere( |
| 60 | + $queryBuilder->expr()->orX( |
| 61 | + sprintf('%s.%s %s', $filterDataDto->getEntityAlias(), 'confirmation2.timestamp', $comparison), |
| 62 | + //The second confirmation is not required, if only one confirmation is required |
| 63 | + sprintf('%s.%s < 2', $filterDataDto->getEntityAlias(), 'requiredConfirmations') |
| 64 | + )); |
54 | 65 | }
|
55 | 66 | }
|
56 | 67 | }
|
0 commit comments