1 | <?php |
||
18 | class CollectionProvider implements Provider |
||
19 | { |
||
20 | /** |
||
21 | * @var Collection The underlying data |
||
22 | */ |
||
23 | private $collection; |
||
24 | |||
25 | /** |
||
26 | * @var QueryConfiguration |
||
27 | */ |
||
28 | private $queryConfiguration; |
||
29 | |||
30 | /** |
||
31 | * @var callable the default global function to check if a row should be included |
||
32 | */ |
||
33 | private $defaultGlobalSearchFunction; |
||
34 | |||
35 | /** |
||
36 | * @var callable the default global order function |
||
37 | */ |
||
38 | private $defaultGlobalOrderFunction; |
||
39 | |||
40 | /** |
||
41 | * @var array an array of callables with local search functions to check if the row should be included |
||
42 | */ |
||
43 | private $columnSearchFunction = []; |
||
44 | |||
45 | /** |
||
46 | * @var array an array that will hold the search functions for each column |
||
47 | */ |
||
48 | private $columnConfiguration = []; |
||
49 | |||
50 | /** |
||
51 | * @var int the initial count of the items before processing |
||
52 | */ |
||
53 | private $totalInitialDataCount; |
||
54 | |||
55 | /** |
||
56 | * CollectionProvider constructor. |
||
57 | * @param Collection $collection The collection with the initial data |
||
58 | */ |
||
59 | public function __construct(Collection $collection) |
||
67 | |||
68 | /** |
||
69 | * Here the DTQueryConfiguration is passed to prepare the provider for the processing of the request. |
||
70 | * This will only be called when the DTProvider needs to handle the request. |
||
71 | * It will never be called when the DTProvider does not need to handle the request. |
||
72 | * |
||
73 | * @param QueryConfiguration $queryConfiguration |
||
74 | * @param ColumnConfiguration[] $columnConfiguration |
||
75 | * @return mixed |
||
76 | */ |
||
77 | public function prepareForProcessing(QueryConfiguration $queryConfiguration, array $columnConfiguration) |
||
94 | |||
95 | /** |
||
96 | * This method should process all configurations and prepare the underlying data for the view. It will arrange the |
||
97 | * data and provide the results in a DTData object. |
||
98 | * It will be called after {@link #prepareForProcessing} has been called and needs to return the processed data in |
||
99 | * a DTData object so the Composer can further handle the data. |
||
100 | * |
||
101 | * @return ResponseData The processed data |
||
102 | * |
||
103 | */ |
||
104 | public function process() |
||
127 | |||
128 | |||
129 | /** |
||
130 | * Will compile the collection into the final collection where operations like search and order can be applied. |
||
131 | * @param ColumnConfiguration[] $columnConfiguration |
||
132 | */ |
||
133 | private function compileCollection(array $columnConfiguration) |
||
143 | |||
144 | /** |
||
145 | * Transform collection data. Used for searches. |
||
146 | * |
||
147 | * @param ColumnConfiguration[] $columnConfiguration |
||
148 | * @param $searchFunc |
||
149 | */ |
||
150 | private function transformCollectionData($columnConfiguration, $searchFunc) |
||
179 | |||
180 | /** |
||
181 | * Remove the empty rows from the collection |
||
182 | * |
||
183 | * @see compileCollection |
||
184 | */ |
||
185 | private function removeEmptyRowsFromCollection() |
||
195 | |||
196 | /** |
||
197 | * Will accept a search function that should be called for the column with the given name. |
||
198 | * If the function returns true, it will be accepted as search matching |
||
199 | * |
||
200 | * @param string $columnName the name of the column to pass this function to |
||
201 | * @param callable $searchFunction the function for the searching |
||
202 | * @return $this |
||
203 | */ |
||
204 | public function searchColumn($columnName, callable $searchFunction) |
||
209 | |||
210 | /** |
||
211 | * Will accept a global search function for all columns. |
||
212 | * @param callable $searchFunction the search function to determine if a row should be included |
||
213 | * @return $this |
||
214 | */ |
||
215 | public function search(callable $searchFunction) |
||
220 | |||
221 | /** |
||
222 | * Will accept a global search function for all columns. |
||
223 | * @param callable $orderFunction the order function to determine the order of the table |
||
224 | * @return $this |
||
225 | */ |
||
226 | public function order(callable $orderFunction) |
||
231 | |||
232 | /** |
||
233 | * Will sort the internal collection based on the given query configuration. |
||
234 | * Most tables only support the ordering by just one column, but we will enable sorting on all columns here |
||
235 | */ |
||
236 | private function sortCollection() |
||
246 | |||
247 | public function setupSearch() |
||
266 | |||
267 | public function setupOrder() |
||
291 | } |