aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2015-08-24 10:39:24 +0200
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2015-08-24 10:39:24 +0200
commit8bb1f3d69ac9a1d0adbbfa0cc689043ae1610fd1 (patch)
tree186571127dc8e98e941056e2f59915598f3fe690
parentbccb5bba75e3f2bf8e89fef6b939500757c3d2b1 (diff)
parentf90af145caa040d17f2fb01e78b645c4157c3781 (diff)
downloadwallabag-8bb1f3d69ac9a1d0adbbfa0cc689043ae1610fd1.tar.gz
wallabag-8bb1f3d69ac9a1d0adbbfa0cc689043ae1610fd1.tar.zst
wallabag-8bb1f3d69ac9a1d0adbbfa0cc689043ae1610fd1.zip
Merge pull request #1393 from wallabag/fix-filter-same-day
Fix date filter on same day
-rw-r--r--app/config/services.yml1
-rw-r--r--src/Wallabag/CoreBundle/Event/Subscriber/CustomDoctrineORMSubscriber.php38
-rw-r--r--src/Wallabag/CoreBundle/Filter/EntryFilterType.php5
-rw-r--r--src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php9
4 files changed, 51 insertions, 2 deletions
diff --git a/app/config/services.yml b/app/config/services.yml
index af22d381..b3ec7c51 100644
--- a/app/config/services.yml
+++ b/app/config/services.yml
@@ -4,6 +4,7 @@ parameters:
4 security.authentication.provider.dao.class: Wallabag\CoreBundle\Security\Authentication\Provider\WallabagAuthenticationProvider 4 security.authentication.provider.dao.class: Wallabag\CoreBundle\Security\Authentication\Provider\WallabagAuthenticationProvider
5 security.encoder.digest.class: Wallabag\CoreBundle\Security\Authentication\Encoder\WallabagPasswordEncoder 5 security.encoder.digest.class: Wallabag\CoreBundle\Security\Authentication\Encoder\WallabagPasswordEncoder
6 security.validator.user_password.class: Wallabag\CoreBundle\Security\Validator\WallabagUserPasswordValidator 6 security.validator.user_password.class: Wallabag\CoreBundle\Security\Validator\WallabagUserPasswordValidator
7 lexik_form_filter.get_filter.doctrine_orm.class: Wallabag\CoreBundle\Event\Subscriber\CustomDoctrineORMSubscriber
7 8
8services: 9services:
9 # used for tests 10 # 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 00000000..cfdbfe97
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Event/Subscriber/CustomDoctrineORMSubscriber.php
@@ -0,0 +1,38 @@
1<?php
2
3namespace Wallabag\CoreBundle\Event\Subscriber;
4
5use Lexik\Bundle\FormFilterBundle\Event\Subscriber\DoctrineORMSubscriber;
6use Lexik\Bundle\FormFilterBundle\Event\GetFilterConditionEvent;
7use Symfony\Component\EventDispatcher\EventSubscriberInterface;
8
9/**
10 * This custom class override the default behavior of LexikFilterBundle on `filter_date_range`
11 * It converts a date_range to date_time_range to add hour to be able to grab a whole day (from 00:00:00 to 23:59:59).
12 */
13class CustomDoctrineORMSubscriber extends DoctrineORMSubscriber implements EventSubscriberInterface
14{
15 /**
16 * @param GetFilterConditionEvent $event
17 */
18 public function filterDateRange(GetFilterConditionEvent $event)
19 {
20 $expr = $event->getFilterQuery()->getExpressionBuilder();
21 $values = $event->getValues();
22 $value = $values['value'];
23
24 // left date should start at midnight
25 if (isset($value['left_date'][0]) && $value['left_date'][0] instanceof \DateTime) {
26 $value['left_date'][0]->setTime(0, 0, 0);
27 }
28
29 // right adte should end one second before midnight
30 if (isset($value['right_date'][0]) && $value['right_date'][0] instanceof \DateTime) {
31 $value['right_date'][0]->setTime(23, 59, 59);
32 }
33
34 if (isset($value['left_date'][0]) || isset($value['right_date'][0])) {
35 $event->setCondition($expr->dateTimeInRange($event->getField(), $value['left_date'][0], $value['right_date'][0]));
36 }
37 }
38}
diff --git a/src/Wallabag/CoreBundle/Filter/EntryFilterType.php b/src/Wallabag/CoreBundle/Filter/EntryFilterType.php
index ff51785b..85d1a061 100644
--- a/src/Wallabag/CoreBundle/Filter/EntryFilterType.php
+++ b/src/Wallabag/CoreBundle/Filter/EntryFilterType.php
@@ -27,8 +27,9 @@ class EntryFilterType extends AbstractType
27 ), 27 ),
28 'format' => 'dd/MM/yyyy', 28 'format' => 'dd/MM/yyyy',
29 'widget' => 'single_text', 29 'widget' => 'single_text',
30 ), 30 ),
31 )) 31 )
32 )
32 ->add('domainName', 'filter_text', array( 33 ->add('domainName', 'filter_text', array(
33 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { 34 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) {
34 $value = $values['value']; 35 $value = $values['value'];
diff --git a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php
index 5f0a6076..a0966285 100644
--- a/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php
+++ b/src/Wallabag/CoreBundle/Tests/Controller/EntryControllerTest.php
@@ -279,6 +279,15 @@ class EntryControllerTest extends WallabagCoreTestCase
279 $this->assertCount(5, $crawler->filter('div[class=entry]')); 279 $this->assertCount(5, $crawler->filter('div[class=entry]'));
280 280
281 $data = array( 281 $data = array(
282 'entry_filter[createdAt][left_date]' => date('d/m/Y'),
283 'entry_filter[createdAt][right_date]' => date('d/m/Y'),
284 );
285
286 $crawler = $client->submit($form, $data);
287
288 $this->assertCount(5, $crawler->filter('div[class=entry]'));
289
290 $data = array(
282 'entry_filter[createdAt][left_date]' => '01/01/1970', 291 'entry_filter[createdAt][left_date]' => '01/01/1970',
283 'entry_filter[createdAt][right_date]' => '01/01/1970', 292 'entry_filter[createdAt][right_date]' => '01/01/1970',
284 ); 293 );