Completed
Push — 3.x ( c43f1e...b382c8 )
by Jordi Sala
01:23
created

DateFilter::getFieldType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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\DateType;
18
19
class DateFilter extends AbstractDateFilter
20
{
21
    public function getFieldType(): string
22
    {
23
        return $this->getOption('field_type', DateType::class);
24
    }
25
26
    /**
27
     * @param string $field
28
     * @param array  $data
29
     */
30
    protected function applyTypeIsLessEqual(ProxyQueryInterface $queryBuilder, $field, $data)
31
    {
32
        $data['value']->add(new \DateInterval('P1D'));
33
34
        $this->applyType($queryBuilder, $this->getOperator($data['type']), $field, $data['value']);
35
    }
36
37
    /**
38
     * @param string $field
39
     * @param array  $data
40
     */
41
    protected function applyTypeIsGreaterThan(ProxyQueryInterface $queryBuilder, $field, $data)
42
    {
43
        $data['value']->add(new \DateInterval('P1D'));
44
45
        $this->applyType($queryBuilder, $this->getOperator($data['type']), $field, $data['value']);
46
    }
47
48
    /**
49
     * Because we lack a time variable we select a range from the days start to end.
50
     *
51
     * @author Wesley van Opdorp <[email protected]>
52
     *
53
     * @param string $field
54
     * @param array  $data
55
     */
56
    protected function applyTypeIsEqual(ProxyQueryInterface $queryBuilder, $field, $data)
57
    {
58
        $end = clone $data['value'];
59
        $end->add(new \DateInterval('P1D'));
60
61
        $queryBuilder->field($field)->range($data['value'], $end);
62
    }
63
}
64