*/ class DateFilter { use FilterTrait; public function buildProperty(FormBuilderInterface $builder, FieldDto $fieldDto, $options = array()) { $builder->add( $builder->create( str_replace('.', '_', $fieldDto->getProperty()), FormType::class, array('inherit_data' => true) ) ->add( 'dateStart', DateType::class, array( 'widget' => 'single_text', 'required' => false, ) ) ->add( 'dateEnd', DateType::class, array( 'widget' => 'single_text', 'required' => false, ) ) ); } public function applyFilter( QueryBuilder $queryBuilder, string $fieldProperty, \DateTime $dateStart = null, \DateTime $dateEnd = null ) { if ($dateStart) { $queryBuilder->andWhere( 'entity.'.$fieldProperty.' >= :dateStart' )->setParameter('dateStart', $dateStart); } if ($dateEnd) { $dateEnd->setTime(23, 59, 59); $queryBuilder->andWhere( 'entity.'.$fieldProperty.' <= :dateEnd' )->setParameter('dateEnd', $dateEnd); } } }