|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Sonata Project package. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Thomas Rabaix <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Sonata\DoctrineMongoDBAdminBundle\Filter; |
|
15
|
|
|
|
|
16
|
|
|
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface; |
|
17
|
|
|
use Symfony\Component\Form\Extension\Core\Type\DateTimeType; |
|
18
|
|
|
|
|
19
|
|
|
class DateTimeFilter extends AbstractDateFilter |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* Flag indicating that filter will filter by datetime instead by date. |
|
23
|
|
|
* |
|
24
|
|
|
* @var bool |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $time = true; |
|
27
|
|
|
|
|
28
|
|
|
public function getFieldType(): string |
|
29
|
|
|
{ |
|
30
|
|
|
return $this->getOption('field_type', DateTimeType::class); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param string $field |
|
35
|
|
|
* @param array $data |
|
36
|
|
|
*/ |
|
37
|
|
|
protected function applyTypeIsLessEqual(ProxyQueryInterface $queryBuilder, $field, $data): void |
|
38
|
|
|
{ |
|
39
|
|
|
// Add a minute so less then equal selects all seconds. |
|
40
|
|
|
$data['value']->add(new \DateInterval('PT1M')); |
|
41
|
|
|
|
|
42
|
|
|
$this->applyType($queryBuilder, $this->getOperator($data['type']), $field, $data['value']); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param string $field |
|
47
|
|
|
* @param array $data |
|
48
|
|
|
*/ |
|
49
|
|
|
protected function applyTypeIsGreaterThan(ProxyQueryInterface $queryBuilder, $field, $data): void |
|
50
|
|
|
{ |
|
51
|
|
|
// Add 59 seconds so anything above the minute is selected |
|
52
|
|
|
$data['value']->add(new \DateInterval('PT59S')); |
|
53
|
|
|
|
|
54
|
|
|
$this->applyType($queryBuilder, $this->getOperator($data['type']), $field, $data['value']); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Because we lack a second variable we select a range covering the entire minute. |
|
59
|
|
|
* |
|
60
|
|
|
* @param string $field |
|
61
|
|
|
* @param array $data |
|
62
|
|
|
*/ |
|
63
|
|
|
protected function applyTypeIsEqual(ProxyQueryInterface $queryBuilder, $field, $data): void |
|
64
|
|
|
{ |
|
65
|
|
|
/** @var \DateTime $end */ |
|
66
|
|
|
$end = clone $data['value']; |
|
67
|
|
|
$end->add(new \DateInterval('PT1M')); |
|
68
|
|
|
|
|
69
|
|
|
$queryBuilder->field($field)->range($data['value'], $end); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|