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. SQL fragment: |
||
52 | * addCondition('name LIKE "%john%"') |
||
53 | * 4. List of conditions to add: |
||
54 | * addCondition([['balance', 100, '>'], ['user_id', 5]]) |
||
55 | * 5. Map of equality comparisons: |
||
56 | * addCondition(['username' => 'john', 'user_id' => 5]) |
||
57 | * 6. List of SQL fragments: |
||
58 | * addCondition(['first_name LIKE "%john%"', 'last_name LIKE "%doe%"']) |
||
59 | * |
||
60 | * @param array|string $field |
||
61 | * @param string|bool $value condition value (optional) |
||
62 | * @param string $operator operator (optional) |
||
63 | * |
||
64 | * @return self |
||
65 | */ |
||
66 | public function addCondition($field, $value = false, $operator = '=') |
||
93 | |||
94 | /** |
||
95 | * Gets the conditions for this statement. |
||
96 | * |
||
97 | * @return array |
||
98 | */ |
||
99 | public function getConditions() |
||
103 | |||
104 | protected function buildClause(array $clause) |
||
113 | |||
114 | /** |
||
115 | * Generates the raw SQL string for the statement. |
||
116 | * |
||
117 | * @return string |
||
118 | */ |
||
119 | public function build() |
||
137 | } |
||
138 |