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 {
@@ -100,7 +100,7 @@ public function add(String $field, $value, String $operator = "=", String $value
100100 * @param Array $arr
101101 * @param String $operator
102102 *
103- * @return Where
103+ * @return Condition
104104 */
105105 public function addList (Array $ arr , String $ operator = "= " )
106106 {
@@ -113,13 +113,13 @@ public function addList(Array $arr, String $operator = "=")
113113 }
114114
115115 /**
116- * @param Where $wh
116+ * @param Condition $wh
117117 *
118- * @return Where
118+ * @return Condition
119119 */
120- public function addWhere ( Where $ wh )
120+ public function addCondition ( Condition $ wh )
121121 {
122- $ this ->where_list [] = $ wh ;
122+ $ this ->Condition_list [] = $ wh ;
123123 return $ this ;
124124 }
125125
@@ -128,50 +128,41 @@ public function addWhere(Where $wh)
128128 *
129129 * @return String
130130 */
131- public function get (String $ table = "" )
131+ public function get (String $ table_name = "" )
132132 {
133- $ list = array () ;
133+ $ list = [] ;
134134
135135 foreach ($ this ->fields as $ field )
136136 {
137137 if (strlen ($ field ["value " ]) > 0 )
138138 {
139139 $ key = $ field ["field " ];
140140
141- if ($ table )
141+ if ($ table_name )
142142 {
143- $ key = $ table . ". " . $ key ;
143+ $ key = $ table_name . ". " . $ key ;
144144 }
145145
146146 if ($ field ["op " ])
147147 {
148148 $ key = $ key . " " . $ field ["op " ];
149149 }
150150
151- $ list [$ key ] = $ field ["value " ];
151+ $ list [] = $ key . " " . $ field ["value " ];
152152 }
153153 }
154154
155- $ list = $ this ->_listToStr ($ list );
156-
157- foreach ($ this ->where_list as $ wh )
155+ foreach ($ this ->Condition_list as $ wh )
158156 {
159- $ list [] = $ wh ->get ($ table );
157+ $ list [] = $ wh ->get ($ table_name );
160158 }
161-
162- return "( " . implode ($ this ->op , $ list ) . ") " ;
163- }
164-
165- private function _listToStr ($ data )
166- {
167- $ list = array ();
168-
169- foreach ($ data as $ k => $ v )
159+
160+ if (empty ($ list ))
170161 {
171- $ list [] = $ k . " " . $ v ;
162+ return "" ;
172163 }
173164
174- return $ list ;
165+ return " ( " . implode ( $ this -> op , $ list) . " ) " ;
175166 }
176167}
177168
0 commit comments