@@ -42,6 +42,7 @@ class QueryEngine extends BaseEngine {
42
42
'noGroupByOnCount ' => false ,
43
43
'distinctCountGroup ' => false ,
44
44
'emptyAtEnd ' => false ,
45
+ 'returnQuery ' => false ,
45
46
);
46
47
47
48
function __construct ($ builder )
@@ -96,9 +97,9 @@ public function setSearchOperator($value = "LIKE")
96
97
return $ this ;
97
98
}
98
99
99
- public function setSearchWithAlias ()
100
+ public function setSearchWithAlias ($ value = true )
100
101
{
101
- $ this ->options ['searchWithAlias ' ] = true ;
102
+ $ this ->options ['searchWithAlias ' ] = ( bool ) $ value ;
102
103
return $ this ;
103
104
}
104
105
@@ -108,9 +109,9 @@ public function setEmptyAtEnd()
108
109
return $ this ;
109
110
}
110
111
111
- public function setNoGroupByOnCount ()
112
+ public function setNoGroupByOnCount ($ value = true )
112
113
{
113
- $ this ->options ['noGroupByOnCount ' ] = true ;
114
+ $ this ->options ['noGroupByOnCount ' ] = ( bool ) $ value ;
114
115
return $ this ;
115
116
}
116
117
@@ -121,14 +122,40 @@ public function setNoGroupByOnCount()
121
122
*
122
123
* Instead of counting all of the rows, the distinct rows in the group by will be counted instead.
123
124
*
125
+ * @param bool $value should this option be enabled?
124
126
* @return $this
125
127
*/
126
128
public function setDistinctCountGroup ($ value = true )
127
129
{
128
- $ this ->options ['distinctCountGroup ' ] = $ value ;
130
+ $ this ->options ['distinctCountGroup ' ] = ( bool ) $ value ;
129
131
return $ this ;
130
132
}
131
133
134
+ /**
135
+ * Let internalMake return a QueryBuilder, instead of a collection.
136
+ *
137
+ * @param bool $value
138
+ * @return $this
139
+ */
140
+ public function setReturnQuery ($ value = true )
141
+ {
142
+ $ this ->options ['returnQuery ' ] = $ value ;
143
+ return $ this ;
144
+ }
145
+
146
+ /**
147
+ * Get a Builder object back from the engine. Don't return a collection.
148
+ *
149
+ * @return Query\Builder
150
+ */
151
+ public function getQueryBuilder ()
152
+ {
153
+ $ this ->prepareEngine ();
154
+ $ this ->setReturnQuery ();
155
+
156
+ return $ this ->internalMake ($ this ->columns , $ this ->searchColumns );
157
+ }
158
+
132
159
//--------PRIVATE FUNCTIONS
133
160
134
161
protected function internalMake (Collection $ columns , array $ searchColumns = array ())
@@ -165,6 +192,10 @@ protected function internalMake(Collection $columns, array $searchColumns = arra
165
192
}
166
193
167
194
$ builder = $ this ->doInternalOrder ($ builder , $ columns );
195
+
196
+ if ($ this ->options ['returnQuery ' ])
197
+ return $ this ->getQuery ($ builder );
198
+
168
199
$ collection = $ this ->compile ($ builder , $ columns );
169
200
170
201
return $ collection ;
@@ -174,19 +205,27 @@ protected function internalMake(Collection $columns, array $searchColumns = arra
174
205
* @param $builder
175
206
* @return Collection
176
207
*/
177
- private function getCollection ($ builder )
208
+ private function getQuery ($ builder )
178
209
{
179
- if ($ this ->collection == null )
180
- {
181
- if ($ this ->skip > 0 )
182
- {
210
+ // dd($builder->toSql());
211
+ if ($ this ->collection == null ) {
212
+ if ($ this ->skip > 0 ) {
183
213
$ builder = $ builder ->skip ($ this ->skip );
184
214
}
185
- if ($ this ->limit > 0 )
186
- {
215
+ if ($ this ->limit > 0 ) {
187
216
$ builder = $ builder ->take ($ this ->limit );
188
217
}
189
- //dd($this->builder->toSql());
218
+ }
219
+
220
+ return $ builder ;
221
+ }
222
+
223
+ private function getCollection ($ builder )
224
+ {
225
+ $ builder = $ this ->getQuery ($ builder );
226
+
227
+ if ($ this ->collection == null )
228
+ {
190
229
$ this ->collection = $ builder ->get ();
191
230
192
231
if (is_array ($ this ->collection ))
@@ -207,6 +246,7 @@ private function doInternalSearch($builder, $columns)
207
246
208
247
return $ builder ;
209
248
}
249
+
210
250
private function buildSearchQuery ($ builder , $ columns )
211
251
{
212
252
$ like = $ this ->options ['searchOperator ' ];
0 commit comments