1 | <?php |
||
13 | class WhereStatement extends Statement |
||
14 | { |
||
15 | /** |
||
16 | * @var bool |
||
17 | */ |
||
18 | protected $having; |
||
19 | |||
20 | /** |
||
21 | * @var array |
||
22 | */ |
||
23 | protected $conditions = []; |
||
24 | |||
25 | /** |
||
26 | * @param bool $having when true, statement becomes a having statement |
||
27 | */ |
||
28 | public function __construct($having = false) |
||
32 | |||
33 | /** |
||
34 | * Tells whether this statement is a HAVING statement. |
||
35 | * |
||
36 | * @return bool true: is HAVING, false: is WHERE |
||
37 | */ |
||
38 | public function isHaving() |
||
42 | |||
43 | /** |
||
44 | * Adds a condition to the statement. |
||
45 | * |
||
46 | * Accepts the following forms: |
||
47 | * 1. Equality comparison: |
||
48 | * addCondition('username', 'john') |
||
49 | * 2. Comparison with custom operator: |
||
50 | * addCondition('balance', 100, '>') |
||
51 | * 3. IN statement: |
||
52 | * addCondition('group', ['admin', 'owner']) |
||
53 | * 4. SQL fragment: |
||
54 | * addCondition('name LIKE "%john%"') |
||
55 | * 5. List of conditions to add: |
||
56 | * addCondition([['balance', 100, '>'], |
||
57 | * ['user_id', 5]]) |
||
58 | * 6. Map of equality comparisons: |
||
59 | * addCondition(['username' => 'john', |
||
60 | * 'user_id' => 5]) |
||
61 | * 7. List of SQL fragments: |
||
62 | * addCondition(['first_name LIKE "%john%"', |
||
63 | * 'last_name LIKE "%doe%"']) |
||
64 | * |
||
65 | * @param array|string $field |
||
66 | * @param string|bool $value condition value (optional) |
||
67 | * @param string $operator operator (optional) |
||
68 | * |
||
69 | * @return self |
||
70 | */ |
||
71 | public function addCondition($field, $value = false, $operator = '=') |
||
110 | |||
111 | public function addConditionOr($field, $value = false, $operator = '=') |
||
117 | |||
118 | /** |
||
119 | * Adds a between condition to the query. |
||
120 | * |
||
121 | * @param string $field |
||
122 | * @param mixed $a first between value |
||
123 | * @param mixed $b second between value |
||
124 | * |
||
125 | * @return self |
||
126 | */ |
||
127 | public function addBetweenCondition($field, $a, $b) |
||
133 | |||
134 | /** |
||
135 | * Adds a not between condition to the query. |
||
136 | * |
||
137 | * @param string $field |
||
138 | * @param mixed $a first between value |
||
139 | * @param mixed $b second between value |
||
140 | * |
||
141 | * @return self |
||
142 | */ |
||
143 | public function addNotBetweenCondition($field, $a, $b) |
||
149 | |||
150 | /** |
||
151 | * Gets the conditions for this statement. |
||
152 | * |
||
153 | * @return array |
||
154 | */ |
||
155 | public function getConditions() |
||
159 | |||
160 | public function build() |
||
182 | |||
183 | /** |
||
184 | * Builds a parameterized and escaped SQL fragment |
||
185 | * for a condition that uses our own internal |
||
186 | * representation. |
||
187 | * |
||
188 | * A condition is represented by an array, and can be |
||
189 | * have one of the following forms: |
||
190 | * i) ['SQL fragment'] |
||
191 | * ii) ['identifier', '=', 'value'] |
||
192 | * iii) ['identifier', 'BETWEEN', 'value', 'value'] |
||
193 | * |
||
194 | * @param array $cond |
||
195 | * |
||
196 | * @return string generated SQL fragment |
||
197 | */ |
||
198 | protected function buildClause(array $cond) |
||
239 | |||
240 | protected function implodeClauses(array $clauses) |
||
265 | } |
||
266 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.