|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Moip\Helper; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class Filters. |
|
7
|
|
|
*/ |
|
8
|
|
|
class Filters |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @var array |
|
12
|
|
|
**/ |
|
13
|
|
|
private $filters = []; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Set filter to compare if field is greater than value. |
|
17
|
|
|
* |
|
18
|
|
|
* @param string $field field to setup filter. |
|
19
|
|
|
* @param int|Date $value value to setup filter. |
|
20
|
|
|
*/ |
|
21
|
|
|
public function greaterThan($field, $value) |
|
22
|
|
|
{ |
|
23
|
|
|
$this->filters[] = sprintf('%s::gt(%s)', $field, $value); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Set filter to compare if field is greater than or equal value. |
|
28
|
|
|
* |
|
29
|
|
|
* @param string $field field to setup filter. |
|
30
|
|
|
* @param int|Date $value value to setup filter. |
|
31
|
|
|
*/ |
|
32
|
|
|
public function greaterThanOrEqual($field, $value) |
|
33
|
|
|
{ |
|
34
|
|
|
$this->filters[] = sprintf('%s::ge(%s)', $field, $value); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Set filter to compare if field is less than value. |
|
39
|
|
|
* |
|
40
|
|
|
* @param string $field field to setup filter. |
|
41
|
|
|
* @param int|Date $value value to setup filter. |
|
42
|
|
|
*/ |
|
43
|
|
|
public function lessThan($field, $value) |
|
44
|
|
|
{ |
|
45
|
|
|
$this->filters[] = sprintf('%s::lt(%s)', $field, $value); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Set filter to compare if field is between both values. |
|
50
|
|
|
* |
|
51
|
|
|
* @param string $field field to setup filter. |
|
52
|
|
|
* @param string $value1 first value to setup filter. |
|
53
|
|
|
* @param string $value2 second value to setup filter. |
|
54
|
|
|
*/ |
|
55
|
|
|
public function between($field, $value1, $value2) |
|
56
|
|
|
{ |
|
57
|
|
|
$this->filters[] = sprintf('%s::bt(%s,%s)', $field, $value1, $value2); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Set filter to compare if field is in array. |
|
62
|
|
|
* |
|
63
|
|
|
* @param string $field field to setup filter. |
|
64
|
|
|
* @param array $values value to setup filter. |
|
65
|
|
|
*/ |
|
66
|
|
|
public function in($field, array $values) |
|
67
|
|
|
{ |
|
68
|
|
|
$this->filters[] = sprintf('%s::in(%s)', $field, implode(',', $values)); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Join filters in one string. |
|
73
|
|
|
* |
|
74
|
|
|
* @return string |
|
75
|
|
|
*/ |
|
76
|
|
|
public function __toString() |
|
77
|
|
|
{ |
|
78
|
|
|
return implode('|', $this->filters); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|