This repository has been archived by the owner on Feb 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 234
/
Copy pathDateRangeFilter.php
78 lines (64 loc) · 1.98 KB
/
DateRangeFilter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/*
* This file is part of the SgDatatablesBundle package.
*
* (c) stwe <https://github.com/stwe/DatatablesBundle>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sg\DatatablesBundle\Datatable\Filter;
use DateTime;
use Doctrine\ORM\Query\Expr\Andx;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\OptionsResolver\OptionsResolver;
class DateRangeFilter extends AbstractFilter
{
//-------------------------------------------------
// FilterInterface
//-------------------------------------------------
/**
* {@inheritdoc}
*/
public function getTemplate()
{
return '@SgDatatables/filter/daterange.html.twig';
}
/**
* {@inheritdoc}
*/
public function addAndExpression(Andx $andExpr, QueryBuilder $qb, $searchField, $searchValue, $searchTypeOfField, &$parameterCounter)
{
list($_dateStart, $_dateEnd) = explode(' - ', $searchValue);
$dateStart = new DateTime($_dateStart);
$dateEnd = new DateTime($_dateEnd);
$dateEnd->setTime(23, 59, 59);
$andExpr = $this->getBetweenAndExpression($andExpr, $qb, $searchField, $dateStart->format('Y-m-d H:i:s'), $dateEnd->format('Y-m-d H:i:s'), $parameterCounter);
$parameterCounter += 2;
return $andExpr;
}
//-------------------------------------------------
// Options
//-------------------------------------------------
/**
* @return $this
*/
public function configureOptions(OptionsResolver $resolver)
{
parent::configureOptions($resolver);
$resolver->remove('search_type');
return $this;
}
//-------------------------------------------------
// Helper
//-------------------------------------------------
/**
* Returns the type for the <input> element.
*
* @return string
*/
public function getType()
{
return 'text';
}
}