DateRange::getTemplate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Boduch\Grid\Filters;
4
5
class DateRange extends Filter
6
{
7
    /**
8
     * @var string
9
     */
10
    protected $template = 'laravel-grid::filters.date_range';
11
12
    /**
13
     * @var string
14
     */
15
    protected $separator = ' - ';
16
17
    /**
18
     * @return string
19
     */
20
    public function render()
21
    {
22
        return $this->column->getGrid()->getGridHelper()->getView()->make($this->template, [
23
            'name' => $this->getName(),
24
            'input' => $this->getInput(),
25
            'separator' => $this->separator
26
        ]);
27
    }
28
29
    /**
30
     * @return string
31
     */
32
    public function getTemplate(): string
33
    {
34
        return $this->template;
35
    }
36
37
    /**
38
     * @param string $template
39
     * @return $this
40
     */
41
    public function setTemplate(string $template)
42
    {
43
        $this->template = $template;
44
45
        return $this;
46
    }
47
48
    /**
49
     * @return string
50
     */
51
    public function getSeparator(): string
52
    {
53
        return $this->separator;
54
    }
55
56
    /**
57
     * @param string $separator
58
     * @return $this
59
     */
60
    public function setSeparator(string $separator)
61
    {
62
        $this->separator = $separator;
63
64
        return $this;
65
    }
66
67
    /**
68
     * @return string
69
     */
70
    public function getOperator()
71
    {
72
        if (!empty($this->getInput()['from']) && !empty($this->getInput()['to'])) {
73
            return FilterOperator::OPERATOR_BETWEEN;
74
        } elseif (empty($this->getInput()['to'])) {
75
            return FilterOperator::OPERATOR_GTE;
76
        } else {
77
            return FilterOperator::OPERATOR_LTE;
78
        }
79
    }
80
}
81