Completed
Push — master ( db8d28...797ef7 )
by wen
11:20
created

Filter::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Sco\Admin\View\Filters;
4
5
use Illuminate\Database\Eloquent\Builder;
6
use Sco\Admin\Contracts\View\Filters\FilterInterface;
7
8
abstract class Filter implements FilterInterface
9
{
10
    protected $type;
11
12
    protected $value;
13
14
    protected $name;
15
16
    protected $title;
17
18
    public function __construct($name, $title)
19
    {
20
        $this->setName($name)->setTitle($title);
21
    }
22
23
    /**
24
     * @return mixed
25
     */
26
    public function getValue()
27
    {
28
        return $this->value;
29
    }
30
31
    /**
32
     * @param mixed $value
33
     *
34
     * @return $this
35
     */
36
    public function setValue($value)
37
    {
38
        $this->value = $value;
39
40
        return $this;
41
    }
42
43
    /**
44
     * @return mixed
45
     */
46
    public function getName()
47
    {
48
        return $this->name;
49
    }
50
51
    /**
52
     * @param mixed $name
53
     *
54
     * @return Filter
55
     */
56
    public function setName($name)
57
    {
58
        $this->name = $name;
59
        return $this;
60
    }
61
62
    /**
63
     * @return mixed
64
     */
65
    public function getTitle()
66
    {
67
        return $this->title;
68
    }
69
70
    /**
71
     * @param mixed $title
72
     *
73
     * @return Filter
74
     */
75
    public function setTitle($title)
76
    {
77
        $this->title = $title;
78
        return $this;
79
    }
80
81
    public function isActive()
82
    {
83
        return !is_null($this->value);
84
    }
85
86
    /**
87
     * Apply filter to the query.
88
     *
89
     * @param Builder $query
90
     */
91
    public function apply(Builder $query)
92
    {
93
94
    }
95
96
    public function toArray()
97
    {
98
        return [
99
            'name'  => $this->getName(),
100
            'title' => $this->getTitle(),
101
            'type'  => $this->type,
102
        ];
103
    }
104
105
    public function jsonSerialize()
106
    {
107
        return $this->toArray();
108
    }
109
110
    public function toJson($options = 0)
111
    {
112
        return json_encode($this->jsonSerialize(), $options);
113
    }
114
115
    public function __toString()
116
    {
117
        return $this->toJson();
118
    }
119
}
120