1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Class RangeFilter |
5
|
|
|
* |
6
|
|
|
* @package dms |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
class RangeFilter extends SearchFilter |
|
|
|
|
10
|
|
|
{ |
11
|
|
View Code Duplication |
protected function applyMany(DataQuery $query) |
|
|
|
|
12
|
|
|
{ |
13
|
|
|
$this->model = $query->applyRelation($this->relation); |
|
|
|
|
14
|
|
|
$where = array(); |
15
|
|
|
$value = $this->getValue(); |
16
|
|
|
$dbName = $this->getDbName(); |
17
|
|
|
if (isset($value['min']) && $value['min']) { |
18
|
|
|
$where[] = sprintf("%s > '%s'", $dbName, Convert::raw2sql($value['min'])); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
if (isset($value['max']) && $value['max']) { |
22
|
|
|
$where[] = sprintf("%s <= '%s'", $dbName, Convert::raw2sql($value['max'])); |
23
|
|
|
} |
24
|
|
|
return $query->where(implode(' AND ', $where)); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function isEmpty() |
28
|
|
|
{ |
29
|
|
|
$value = $this->getValue(); |
30
|
|
|
return !(isset($value['min']) && $value['min']) && !(isset($value['max']) && $value['max']); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
// @codeCoverageIgnoreStart |
34
|
|
|
protected function applyOne(DataQuery $query) |
35
|
|
|
{ |
36
|
|
|
$this->model = $query->applyRelation($this->relation); |
|
|
|
|
37
|
|
|
$where = array(); |
|
|
|
|
38
|
|
|
$value = $this->getValue(); |
39
|
|
|
$dbName = $this->getDbName(); |
40
|
|
|
if (isset($value['min']) && $value['min']) { |
41
|
|
|
$filter = sprintf("%s > '%s'", $dbName, Convert::raw2sql($value['min'])); |
42
|
|
|
} elseif (isset($value['max']) && $value['max']) { |
43
|
|
|
$filter = sprintf("%s <= '%s'", $dbName, Convert::raw2sql($value['max'])); |
44
|
|
|
} |
45
|
|
|
return $query->where($filter); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
protected function excludeOne(DataQuery $query) |
48
|
|
|
{ |
49
|
|
|
$this->model = $query->applyRelation($this->relation); |
|
|
|
|
50
|
|
|
$where = array(); |
|
|
|
|
51
|
|
|
$value = $this->getValue(); |
52
|
|
|
$dbName = $this->getDbName(); |
53
|
|
|
if (isset($value['min']) && $value['min']) { |
54
|
|
|
$filter = sprintf("%s <= '%s'", $dbName, Convert::raw2sql($value['min'])); |
55
|
|
|
} elseif (isset($value['max']) && $value['max']) { |
56
|
|
|
$filter = sprintf("%s > '%s'", $dbName, Convert::raw2sql($value['max'])); |
57
|
|
|
} |
58
|
|
|
return $query->where($filter); |
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
View Code Duplication |
protected function excludeMany(DataQuery $query) |
|
|
|
|
62
|
|
|
{ |
63
|
|
|
$this->model = $query->applyRelation($this->relation); |
|
|
|
|
64
|
|
|
$where = array(); |
65
|
|
|
$value = $this->getValue(); |
66
|
|
|
$dbName = $this->getDbName(); |
67
|
|
|
if (isset($value['min']) && $value['min']) { |
68
|
|
|
$where[] = sprintf("%s <= '%s'", $dbName, Convert::raw2sql($value['min'])); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
if (isset($value['max']) && $value['max']) { |
72
|
|
|
$where[] = sprintf("%s > '%s'", $dbName, Convert::raw2sql($value['max'])); |
73
|
|
|
} |
74
|
|
|
return $query->where(implode(' AND ', $where)); |
75
|
|
|
} |
76
|
|
|
// @codeCoverageIgnoreEnd |
77
|
|
|
|
78
|
|
|
public function setValue($value) |
79
|
|
|
{ |
80
|
|
View Code Duplication |
if (isset($value['min']) && $value['min']) { |
|
|
|
|
81
|
|
|
$this->value['min'] = $value['min']." 00:00:00"; |
82
|
|
|
} |
83
|
|
View Code Duplication |
if (isset($value['max']) && $value['max']) { |
|
|
|
|
84
|
|
|
$this->value['max'] = $value['max']." 23:59:59"; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.