|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Filter for usage in models |
|
4
|
|
|
* |
|
5
|
|
|
* @file DbFilter.php |
|
6
|
|
|
* |
|
7
|
|
|
* PHP version 8.0+ |
|
8
|
|
|
* |
|
9
|
|
|
* @author Alexander Yancharuk <alex at itvault dot info> |
|
10
|
|
|
* @copyright © 2012-2021 Alexander Yancharuk |
|
11
|
|
|
* @date Втр Авг 07 23:14:17 2012 |
|
12
|
|
|
* @license The BSD 3-Clause License |
|
13
|
|
|
* <https://tldrlegal.com/license/bsd-3-clause-license-(revised)> |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
namespace Veles\DataBase; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Class DbFilter |
|
20
|
|
|
* |
|
21
|
|
|
* @author Alexander Yancharuk <alex at itvault dot info> |
|
22
|
|
|
*/ |
|
23
|
|
|
class DbFilter |
|
24
|
|
|
{ |
|
25
|
|
|
protected $where = ''; |
|
26
|
|
|
protected $group = ''; |
|
27
|
|
|
protected $having = ''; |
|
28
|
|
|
protected $order = ''; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Gets where conditions |
|
32
|
|
|
* |
|
33
|
|
|
* @return string |
|
34
|
|
|
*/ |
|
35
|
12 |
|
public function getWhere() |
|
36
|
|
|
{ |
|
37
|
12 |
|
return $this->where; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Gets group by conditions |
|
42
|
|
|
* @return string |
|
43
|
|
|
*/ |
|
44
|
12 |
|
public function getGroup() |
|
45
|
|
|
{ |
|
46
|
12 |
|
return $this->group; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Gets having conditions |
|
51
|
|
|
* |
|
52
|
|
|
* @return string |
|
53
|
|
|
*/ |
|
54
|
12 |
|
public function getHaving() |
|
55
|
|
|
{ |
|
56
|
12 |
|
return $this->having; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Gets order by conditions |
|
61
|
|
|
* |
|
62
|
|
|
* @return string |
|
63
|
|
|
*/ |
|
64
|
12 |
|
public function getOrder() |
|
65
|
|
|
{ |
|
66
|
12 |
|
return $this->order; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Sets where conditions |
|
71
|
|
|
* |
|
72
|
|
|
* @param string $where WHERE для sql-запроса |
|
73
|
|
|
* |
|
74
|
|
|
* @return $this |
|
75
|
|
|
*/ |
|
76
|
11 |
|
public function setWhere($where) |
|
77
|
|
|
{ |
|
78
|
11 |
|
$this->where = "WHERE $where"; |
|
79
|
|
|
|
|
80
|
11 |
|
return $this; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Sets group by conditions |
|
85
|
|
|
* |
|
86
|
|
|
* @param string $group GROUP BY для sql-запроса |
|
87
|
|
|
* |
|
88
|
|
|
* @return $this |
|
89
|
|
|
*/ |
|
90
|
1 |
|
public function setGroup($group) |
|
91
|
|
|
{ |
|
92
|
1 |
|
$this->group = "GROUP BY $group"; |
|
93
|
|
|
|
|
94
|
1 |
|
return $this; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Sets having conditions |
|
99
|
|
|
* |
|
100
|
|
|
* @param string $having HAVING для sql-запроса |
|
101
|
|
|
* |
|
102
|
|
|
* @return $this |
|
103
|
|
|
*/ |
|
104
|
1 |
|
public function setHaving($having) |
|
105
|
|
|
{ |
|
106
|
1 |
|
$this->having = "HAVING $having"; |
|
107
|
|
|
|
|
108
|
1 |
|
return $this; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Sets order by conditions |
|
113
|
|
|
* |
|
114
|
|
|
* @param string $order ORDER BY для sql-запроса |
|
115
|
|
|
* |
|
116
|
|
|
* @return $this |
|
117
|
|
|
*/ |
|
118
|
1 |
|
public function setOrder($order) |
|
119
|
|
|
{ |
|
120
|
1 |
|
$this->order = "ORDER BY $order"; |
|
121
|
|
|
|
|
122
|
1 |
|
return $this; |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|