Skip to content

Commit

Permalink
Merge 4.x into 5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
SonataCI authored Apr 25, 2024
2 parents 9bbbf54 + 3d6b27c commit 639ff4b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [4.17.1](https://github.com/sonata-project/SonataDoctrineORMAdminBundle/compare/4.17.0...4.17.1) - 2024-04-24
### Fixed
- [[#1807](https://github.com/sonata-project/SonataDoctrineORMAdminBundle/pull/1807)] DateTimeRangeFilter when both the `start` or `end` field are not empty. ([@VincentLanglet](https://github.com/VincentLanglet))

## [4.17.0](https://github.com/sonata-project/SonataDoctrineORMAdminBundle/compare/4.16.1...4.17.0) - 2024-04-13
### Added
- [[#1805](https://github.com/sonata-project/SonataDoctrineORMAdminBundle/pull/1805)] Allow to pass extra field options in ClassFilter ([@VincentLanglet](https://github.com/VincentLanglet))
Expand Down
6 changes: 0 additions & 6 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ parameters:
- # https://github.com/phpstan/phpstan-strict-rules/issues/130
message: '#^Call to static method PHPUnit\\Framework\\Assert::.* will always evaluate to true\.$#'
path: tests/
- # https://github.com/doctrine/orm/pull/8767
message: '#Method Sonata\\DoctrineORMAdminBundle\\FieldDescription\\FieldDescriptionFactory::getMetadata\(\) should return Doctrine\\ORM\\Mapping\\ClassMetadata\<TObject of object\> but returns Doctrine\\ORM\\Mapping\\ClassMetadata\<object\>\.$#'
path: src/FieldDescription/FieldDescriptionFactory.php
- # https://github.com/doctrine/orm/pull/8767
message: '#Method Sonata\\DoctrineORMAdminBundle\\Model\\ModelManager::getMetadata\(\) should return Doctrine\\ORM\\Mapping\\ClassMetadata\<TObject of object\> but returns Doctrine\\ORM\\Mapping\\ClassMetadata\<object\>\.$#'
path: src/Model/ModelManager.php
- # https://github.com/doctrine/orm/pull/9778
message: '#Parameter \#1 \$className of method Doctrine\\Persistence\\Mapping\\AbstractClassMetadataFactory<Doctrine\\ORM\\Mapping\\ClassMetadata>::getMetadataFor\(\) expects class-string, string given.#'
path: src/Datagrid/ProxyQuery.php
8 changes: 4 additions & 4 deletions src/Filter/AbstractDateFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,11 @@ private function filterRange(ProxyQueryInterface $query, string $alias, string $
$endDateParameterName = $this->getNewParameterName($query);

if (DateRangeOperatorType::TYPE_NOT_BETWEEN === $type) {
if (null !== $value['start']) {
if (null !== $value['start'] && null !== $value['end']) {
$this->applyWhere($query, sprintf('%s.%s < :%s OR %s.%s > :%s', $alias, $field, $startDateParameterName, $alias, $field, $endDateParameterName));
} elseif (null !== $value['start']) {
$this->applyWhere($query, sprintf('%s.%s %s :%s', $alias, $field, '<', $startDateParameterName));
}

if (null !== $value['end']) {
} elseif (null !== $value['end']) {
$this->applyWhere($query, sprintf('%s.%s %s :%s', $alias, $field, '>', $endDateParameterName));
}
} else {
Expand Down
23 changes: 23 additions & 0 deletions tests/Filter/DateTimeRangeFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,27 @@ public function testFilterNotBetweenEndDate(): void
self::assertSameQueryParameters(['field_name_1' => $endDateTime], $proxyQuery);
static::assertTrue($filter->isActive());
}

public function testFilterNotBetweenStartAndEndDate(): void
{
$filter = new DateTimeRangeFilter();
$filter->initialize('field_name', ['field_options' => ['class' => 'FooBar']]);

$proxyQuery = new ProxyQuery($this->createQueryBuilderStub());

$startDateTime = new \DateTime('2023-10-03T11:00:01');
$endDateTime = new \DateTime('2023-10-03T12:00:01');

$filter->filter($proxyQuery, 'alias', 'field', FilterData::fromArray([
'type' => DateRangeOperatorType::TYPE_NOT_BETWEEN,
'value' => [
'start' => $startDateTime,
'end' => $endDateTime,
],
]));

self::assertSameQuery(['WHERE alias.field < :field_name_0 OR alias.field > :field_name_1'], $proxyQuery);
self::assertSameQueryParameters(['field_name_0' => $startDateTime, 'field_name_1' => $endDateTime], $proxyQuery);
static::assertTrue($filter->isActive());
}
}

0 comments on commit 639ff4b

Please sign in to comment.