1 | <?php |
||
14 | class Datatable19QueryParser extends QueryParser |
||
15 | { |
||
16 | |||
17 | /** |
||
18 | * Method to determine if this parser can handle the query parameters. If so then the parser should return true |
||
19 | * and be able to return a DTQueryConfiguration |
||
20 | * |
||
21 | * @param Request $request The current request, that should be investigated |
||
22 | * @return bool true if the parser is able to parse the query parameters and to return a DTQueryConfiguration |
||
23 | */ |
||
24 | public function canParse(Request $request) |
||
28 | |||
29 | /** |
||
30 | * Method that should parse the request and return a DTQueryConfiguration |
||
31 | * |
||
32 | * @param Request $request The current request that should be investigated |
||
33 | * @param ColumnConfiguration[] $columnConfiguration The configuration of the columns |
||
34 | * @return QueryConfiguration the configuration the provider can use to prepare the data |
||
35 | */ |
||
36 | public function parse(Request $request, array $columnConfiguration) |
||
37 | { |
||
38 | $query = $request->query; |
||
39 | $builder = QueryConfigurationBuilder::create(); |
||
40 | |||
41 | $this->getDrawCall($query, $builder); |
||
42 | |||
43 | $this->getStart($query, $builder); |
||
44 | |||
45 | $this->getLength($query, $builder); |
||
46 | |||
47 | $this->getSearch($query, $builder); |
||
48 | |||
49 | $this->determineSortableColumns($query, $builder, $columnConfiguration); |
||
50 | |||
51 | $this->getRegex($query, $builder); |
||
52 | |||
53 | $this->getSearchColumns($query, $builder, $columnConfiguration); |
||
54 | |||
55 | return $builder->build(); |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * Helper function that will check if a variable is empty |
||
60 | * @param mixed $string |
||
61 | * @return bool true if empty, false otherwise |
||
62 | */ |
||
63 | private function isEmpty($string) |
||
67 | |||
68 | /** |
||
69 | * Helper function that will check if a variable has a value |
||
70 | * |
||
71 | * NOTE: (this is almost the opposite of isEmpty, but it is *not* the same) |
||
72 | * |
||
73 | * @param mixed $string |
||
74 | * @return bool true if empty, false otherwise |
||
75 | */ |
||
76 | private function hasValue($string) |
||
80 | |||
81 | /** |
||
82 | * @param ParameterBag $query |
||
83 | * @param QueryConfigurationBuilder $builder |
||
84 | */ |
||
85 | public function getDrawCall($query, $builder) |
||
91 | |||
92 | /** |
||
93 | * @param ParameterBag $query |
||
94 | * @param QueryConfigurationBuilder $builder |
||
95 | */ |
||
96 | public function getStart($query, $builder) |
||
102 | |||
103 | /** |
||
104 | * @param ParameterBag $query |
||
105 | * @param QueryConfigurationBuilder $builder |
||
106 | */ |
||
107 | public function getLength($query, $builder) |
||
113 | |||
114 | /** |
||
115 | * @param ParameterBag $query |
||
116 | * @param QueryConfigurationBuilder $builder |
||
117 | */ |
||
118 | public function getSearch($query, $builder) |
||
124 | |||
125 | /** |
||
126 | * @param ParameterBag $query |
||
127 | * @param QueryConfigurationBuilder $builder |
||
128 | * @param ColumnConfiguration[] $columnConfiguration |
||
129 | */ |
||
130 | public function getSearchColumns($query, $builder, array $columnConfiguration) |
||
138 | |||
139 | /** |
||
140 | * @param ParameterBag $query |
||
141 | * @param QueryConfigurationBuilder $builder |
||
142 | * @param ColumnConfiguration $column |
||
143 | * @param integer $position position of the column in the columnConfiguration loop |
||
144 | */ |
||
145 | private function addColumnSearchToBuilderIfRequested($query, $builder, $column, $position) |
||
153 | |||
154 | /** |
||
155 | * @param ParameterBag $query |
||
156 | * @param QueryConfigurationBuilder $builder |
||
157 | * @param ColumnConfiguration[] $columnConfiguration |
||
158 | * @throws DatatableException when a column for sorting is out of bounds |
||
159 | * @return bool success? |
||
160 | */ |
||
161 | private function determineSortableColumns($query, $builder, array $columnConfiguration) |
||
176 | |||
177 | /** |
||
178 | * Find out how many columns we are sorting by for the sorting loop |
||
179 | * @see determineSortableColumns |
||
180 | * @param ParameterBag $query |
||
181 | * @return int |
||
182 | */ |
||
183 | private function getNumberOfSortingColumns(ParameterBag $query) |
||
190 | |||
191 | /** |
||
192 | * Add a column for ordering to the QueryConfigurationBuilder |
||
193 | * @see determineSortableColumns |
||
194 | * @param $builder |
||
195 | * @param $columnConfiguration |
||
196 | * @param $item |
||
197 | * @param $direction |
||
198 | * @throws DatatableException |
||
199 | */ |
||
200 | private function addColumnForOrdering($builder, $columnConfiguration, $item, $direction) |
||
208 | |||
209 | /** |
||
210 | * @param ColumnConfiguration[] $columnConfiguration |
||
211 | * @param int $item |
||
212 | * @return ColumnConfiguration a specific item from $ColumnConfiguration |
||
213 | * @throws DatatableException |
||
214 | */ |
||
215 | private function getColumnFromConfiguration(array $columnConfiguration, $item) |
||
225 | |||
226 | /** |
||
227 | * @param ParameterBag $query |
||
228 | * @param QueryConfigurationBuilder $builder |
||
229 | */ |
||
230 | public function getRegex($query, $builder) |
||
236 | } |
||
237 |