3 namespace Wallabag\CoreBundle\Event\Subscriber
;
5 use Lexik\Bundle\FormFilterBundle\Event\GetFilterConditionEvent
;
6 use Lexik\Bundle\FormFilterBundle\Event\Subscriber\DoctrineORMSubscriber
;
7 use Symfony\Component\EventDispatcher\EventSubscriberInterface
;
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).
13 class CustomDoctrineORMSubscriber
extends DoctrineORMSubscriber
implements EventSubscriberInterface
16 * @param GetFilterConditionEvent $event
18 public function filterDateRange(GetFilterConditionEvent
$event)
20 $expr = $event->getFilterQuery()->getExpressionBuilder();
21 $values = $event->getValues();
22 $value = $values['value'];
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);
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);
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]));