diff --git a/app/config/services.yml b/app/config/services.yml index af22d3818..b3ec7c513 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -4,6 +4,7 @@ parameters: security.authentication.provider.dao.class: Wallabag\CoreBundle\Security\Authentication\Provider\WallabagAuthenticationProvider security.encoder.digest.class: Wallabag\CoreBundle\Security\Authentication\Encoder\WallabagPasswordEncoder security.validator.user_password.class: Wallabag\CoreBundle\Security\Validator\WallabagUserPasswordValidator + lexik_form_filter.get_filter.doctrine_orm.class: Wallabag\CoreBundle\Event\Subscriber\CustomDoctrineORMSubscriber services: # used for tests diff --git a/src/Wallabag/CoreBundle/Event/Subscriber/CustomDoctrineORMSubscriber.php b/src/Wallabag/CoreBundle/Event/Subscriber/CustomDoctrineORMSubscriber.php new file mode 100644 index 000000000..cfdbfe973 --- /dev/null +++ b/src/Wallabag/CoreBundle/Event/Subscriber/CustomDoctrineORMSubscriber.php @@ -0,0 +1,38 @@ +getFilterQuery()->getExpressionBuilder(); + $values = $event->getValues(); + $value = $values['value']; + + // left date should start at midnight + if (isset($value['left_date'][0]) && $value['left_date'][0] instanceof \DateTime) { + $value['left_date'][0]->setTime(0, 0, 0); + } + + // right adte should end one second before midnight + if (isset($value['right_date'][0]) && $value['right_date'][0] instanceof \DateTime) { + $value['right_date'][0]->setTime(23, 59, 59); + } + + if (isset($value['left_date'][0]) || isset($value['right_date'][0])) { + $event->setCondition($expr->dateTimeInRange($event->getField(), $value['left_date'][0], $value['right_date'][0])); + } + } +} diff --git a/src/Wallabag/CoreBundle/Filter/EntryFilterType.php b/src/Wallabag/CoreBundle/Filter/EntryFilterType.php index ff51785b8..85d1a0610 100644 --- a/src/Wallabag/CoreBundle/Filter/EntryFilterType.php +++ b/src/Wallabag/CoreBundle/Filter/EntryFilterType.php @@ -27,8 +27,9 @@ class EntryFilterType extends AbstractType ), 'format' => 'dd/MM/yyyy', 'widget' => 'single_text', - ), - )) + ), + ) + ) ->add('domainName', 'filter_text', array( 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { $value = $values['value']; diff --git a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php index 5f0a60763..a09662858 100644 --- a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php +++ b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php @@ -278,6 +278,15 @@ class EntryControllerTest extends WallabagCoreTestCase $this->assertCount(5, $crawler->filter('div[class=entry]')); + $data = array( + 'entry_filter[createdAt][left_date]' => date('d/m/Y'), + 'entry_filter[createdAt][right_date]' => date('d/m/Y'), + ); + + $crawler = $client->submit($form, $data); + + $this->assertCount(5, $crawler->filter('div[class=entry]')); + $data = array( 'entry_filter[createdAt][left_date]' => '01/01/1970', 'entry_filter[createdAt][right_date]' => '01/01/1970',