|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
-
- namespace Lc\SovBundle\Field\Filter;
-
- use Doctrine\ORM\QueryBuilder;
- use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto;
- use Symfony\Component\Form\Extension\Core\Type\DateType;
- use Symfony\Component\Form\Extension\Core\Type\FormType;
- use Symfony\Component\Form\FormBuilderInterface;
-
- /**
- * @author La clic ! <contact@laclic.fr>
- */
- 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);
- }
- }
- }
|