1 | <?php |
||
22 | class QueryBuilderProvider implements Provider |
||
23 | { |
||
24 | /** |
||
25 | * @var QueryBuilder The original query, as passed to us. |
||
26 | */ |
||
27 | private $originalQuery; |
||
28 | |||
29 | /** |
||
30 | * @var QueryBuilder The query, before limits are applied |
||
31 | */ |
||
32 | private $queryBeforeLimits; |
||
33 | |||
34 | /** |
||
35 | * @var QueryBuilder The underlying query |
||
36 | */ |
||
37 | private $query; |
||
38 | |||
39 | /** |
||
40 | * @var QueryConfiguration |
||
41 | */ |
||
42 | private $queryConfiguration; |
||
43 | |||
44 | /** |
||
45 | * @var array an array that will hold the search functions for each column |
||
46 | */ |
||
47 | private $columnConfiguration = []; |
||
48 | |||
49 | /** |
||
50 | * CollectionProvider constructor. |
||
51 | * @param QueryBuilder $query The query to base the built query on |
||
52 | */ |
||
53 | public function __construct(QueryBuilder $query) |
||
58 | |||
59 | /** |
||
60 | * Here the DTQueryConfiguration is passed to prepare the provider for the processing of the request. |
||
61 | * This will only be called when the DTProvider needs to handle the request. |
||
62 | * It will never be called when the DTProvider does not need to handle the request. |
||
63 | * |
||
64 | * @param QueryConfiguration $queryConfiguration |
||
65 | * @param ColumnConfiguration[] $columnConfiguration |
||
66 | * @return mixed |
||
67 | */ |
||
68 | public function prepareForProcessing(QueryConfiguration $queryConfiguration, array $columnConfiguration) |
||
79 | |||
80 | /** |
||
81 | * This method should process all configurations and prepare the underlying data for the view. It will arrange the |
||
82 | * data and provide the results in a DTData object. |
||
83 | * It will be called after {@link #prepareForProcessing} has been called and needs to return the processed data in |
||
84 | * a DTData object so the Composer can further handle the data. |
||
85 | * |
||
86 | * @return ResponseData The processed data |
||
87 | * |
||
88 | */ |
||
89 | public function process() |
||
114 | |||
115 | /** |
||
116 | * Get the total number of rows for the original query. |
||
117 | * @return int |
||
118 | */ |
||
119 | private function getTotalNumberOfRows() |
||
123 | |||
124 | /** |
||
125 | * Will compile the collection into the final collection where operations like search and order can be applied. |
||
126 | * |
||
127 | * @return QueryBuilder |
||
128 | * @throws DatatableException |
||
129 | */ |
||
130 | private function compileQuery() |
||
138 | |||
139 | /** |
||
140 | * When a global (single) search has been done against data in the datatable. |
||
141 | * |
||
142 | * @return QueryBuilder |
||
143 | * @throws DatatableException |
||
144 | */ |
||
145 | private function compileGlobalQuery() |
||
151 | |||
152 | /** |
||
153 | * When a global query is being performed (ie, a query against a single column) |
||
154 | * |
||
155 | * @return QueryBuilder |
||
156 | * @throws DatatableException |
||
157 | */ |
||
158 | private function compileColumnQuery() |
||
171 | |||
172 | /** |
||
173 | * Create the query w/ QueryBuilder |
||
174 | * @param ColumnConfiguration $column |
||
175 | * @param $searchValue |
||
176 | * @return QueryBuilder |
||
177 | * @throws DatatableException |
||
178 | */ |
||
179 | private function createQueryForColumn(ColumnConfiguration $column, $searchValue) |
||
196 | |||
197 | /** |
||
198 | * Get the requested column configuration from the name of a column |
||
199 | * @param string $name |
||
200 | * @return ColumnConfiguration |
||
201 | * @throws DatatableException when a column is not found |
||
202 | */ |
||
203 | private function getColumnFromName($name) |
||
216 | |||
217 | /** |
||
218 | * Get a list of all the column names for the SELECT query. |
||
219 | */ |
||
220 | private function compileColumnNames() |
||
229 | |||
230 | /** |
||
231 | * Will sort the query based on the given datatable query configuration. |
||
232 | */ |
||
233 | private function sortQuery() |
||
243 | |||
244 | /** |
||
245 | * Will limit a query based on the start and length given |
||
246 | */ |
||
247 | private function limitQuery() |
||
252 | } |