11<?php
22namespace HardeepVicky \QueryBuilder ;
33
4- class Where
4+ class Condition
55{
6- private $ op = null , $ fields = array (), $ where_list = array ();
6+ private $ op = null , $ fields = array (), $ Condition_list = array ();
77
88 /**
99 * @param String $op
@@ -16,11 +16,11 @@ public function __construct(String $op)
1616 /**
1717 * @param String $op
1818 *
19- * @return Where
19+ * @return Condition
2020 */
2121 public static function init (String $ op )
2222 {
23- return new Where ($ op );
23+ return new Condition ($ op );
2424 }
2525
2626 /**
@@ -29,7 +29,7 @@ public static function init(String $op)
2929 * @param String $operator
3030 * @param String $value_type
3131 *
32- * @return Where
32+ * @return Condition
3333 */
3434 public function add (String $ field , $ value , String $ operator = "= " , String $ value_type = "string " )
3535 {
@@ -158,7 +158,7 @@ private function _parseStringValue($value, $value_type = "string")
158158 * @param Array $arr
159159 * @param String $operator
160160 *
161- * @return Where
161+ * @return Condition
162162 */
163163 public function addList (Array $ arr , String $ operator = "= " )
164164 {
@@ -171,13 +171,13 @@ public function addList(Array $arr, String $operator = "=")
171171 }
172172
173173 /**
174- * @param Where $wh
174+ * @param Condition $wh
175175 *
176- * @return Where
176+ * @return Condition
177177 */
178- public function addWhere ( Where $ wh )
178+ public function addCondition ( Condition $ wh )
179179 {
180- $ this ->where_list [] = $ wh ;
180+ $ this ->Condition_list [] = $ wh ;
181181 return $ this ;
182182 }
183183
@@ -186,50 +186,41 @@ public function addWhere(Where $wh)
186186 *
187187 * @return String
188188 */
189- public function get (String $ table = "" )
189+ public function get (String $ table_name = "" )
190190 {
191- $ list = array () ;
191+ $ list = [] ;
192192
193193 foreach ($ this ->fields as $ field )
194194 {
195195 if (strlen ($ field ["value " ]) > 0 )
196196 {
197197 $ key = $ field ["field " ];
198198
199- if ($ table )
199+ if ($ table_name )
200200 {
201- $ key = $ table . ". " . $ key ;
201+ $ key = $ table_name . ". " . $ key ;
202202 }
203203
204204 if ($ field ["op " ])
205205 {
206206 $ key = $ key . " " . $ field ["op " ];
207207 }
208208
209- $ list [$ key ] = $ field ["value " ];
209+ $ list [] = $ key . " " . $ field ["value " ];
210210 }
211211 }
212212
213- $ list = $ this ->_listToStr ($ list );
214-
215- foreach ($ this ->where_list as $ wh )
213+ foreach ($ this ->Condition_list as $ wh )
216214 {
217- $ list [] = $ wh ->get ($ table );
215+ $ list [] = $ wh ->get ($ table_name );
218216 }
219-
220- return "( " . implode ($ this ->op , $ list ) . ") " ;
221- }
222-
223- private function _listToStr ($ data )
224- {
225- $ list = array ();
226-
227- foreach ($ data as $ k => $ v )
217+
218+ if (empty ($ list ))
228219 {
229- $ list [] = $ k . " " . $ v ;
220+ return "" ;
230221 }
231222
232- return $ list ;
223+ return " ( " . implode ( $ this -> op , $ list) . " ) " ;
233224 }
234225}
235226
0 commit comments