-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFilter.php
153 lines (130 loc) · 2.56 KB
/
Filter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
namespace sporm;
class Filter {
private $sField;
private $sValue;
private $sComparitor;
/**
* @var Filter
*/
private $oAndFilter;
function __construct( $sField, $oAndFilter = false ) {
$this->sField = $sField;
$this->oAndFilter = $oAndFilter;
}
function hasAnd() {
return ( is_object( $this->oAndFilter ) );
}
function getAnd() {
return $this->oAndFilter;
}
/**
* @return Filter
*/
static function none() {
$oFilter = new Filter( "1" );
return $oFilter->isEqualTo( 1 );
}
/**
* @return Filter
*/
static function attribute( $sField ) {
return new Filter( $sField );
}
/**
* @return Filter
*/
function andAttribute( $sField ) {
return new Filter( $sField, $this );
}
/**
* @return Filter
*/
function isEqualTo( $sValue ) {
$this->sComparitor = '=';
$this->sValue = $sValue;
return $this;
}
/**
* @return Filter
*/
function isNotEqualTo( $sValue ) {
$this->sComparitor = '!=';
$this->sValue = $sValue;
return $this;
}
/**
* @return Filter
*/
function isLessThan( $sValue ) {
$this->sComparitor = '<';
$this->sValue = $sValue;
return $this;
}
/**
* @return Filter
*/
function isLessThanOrEqualTo( $sValue ) {
$this->sComparitor = '<=';
$this->sValue = $sValue;
return $this;
}
/**
* @return Filter
*/
function isGreaterThan( $sValue ) {
$this->sComparitor = '>';
$this->sValue = $sValue;
return $this;
}
/**
* @return Filter
*/
function isGreaterThanOrEqualTo( $sValue ) {
$this->sComparitor = '>=';
$this->sValue = $sValue;
return $this;
}
/**
* @return Filter
*/
function isNotNull() {
$this->sComparitor = 'IS NOT NULL';
$this->sValue = '!NULL!';
return $this;
}
function getValue() {
return $this->sValue;
}
function getComparitor() {
return $this->sComparitor;
}
function getField() {
return $this->sField;
}
function getFullVariableList( $aValues = array() ) {
$aValues[] = $this->sValue;
if ( $this->hasAnd() ) {
$aValues = $this->getAnd()->getFullVariableList( $aValues );
}
return $aValues;
}
function getFullVariableListWithoutNulls() {
$aReturnValues = array();
$aValues = $this->getFullVariableList();
foreach ( $aValues as $sValue ) {
if ( $sValue !== '!NULL!' ){
$aReturnValues[] = $sValue;
}
}
return $aReturnValues;
}
function getHash() {
$sHash = $this->getField().$this->getComparitor().$this->getValue();
$sAnd = '';
if ( $this->hasAnd() ) {
$sAnd = '&'.$this->getAnd()->getHash();
}
return $sHash.$sAnd;
}
}