1 | <?php |
||
50 | abstract class AbstractController extends BaseController { |
||
51 | |||
52 | /** |
||
53 | * Build a response. |
||
54 | * |
||
55 | * @param Request $request The request. |
||
56 | * @param string $name The provider name. |
||
57 | * @param ActionResponse $output The output. |
||
58 | * @return Response Returns the response. |
||
59 | */ |
||
60 | protected function buildDataTablesResponse(Request $request, $name, ActionResponse $output) { |
||
83 | |||
84 | /** |
||
85 | * Dispatch an event. |
||
86 | * |
||
87 | * @param string $eventName The event name. |
||
88 | * @param array $entities The entities. |
||
89 | * @return DataTablesEvent|null Returns the event in case of success, null otherwise. |
||
90 | */ |
||
91 | protected function dispatchDataTablesEvent($eventName, array $entities) { |
||
94 | |||
95 | /** |
||
96 | * Export callback. |
||
97 | * |
||
98 | * @param DataTablesProviderInterface $dtProvider The provider. |
||
99 | * @param DataTablesRepositoryInterface $repository The repository. |
||
100 | * @param DataTablesCSVExporterInterface $dtExporter The exporter. |
||
101 | * @param bool $windows Windows ? |
||
102 | * @return void |
||
103 | */ |
||
104 | protected function exportDataTablesCallback(DataTablesProviderInterface $dtProvider, DataTablesRepositoryInterface $repository, DataTablesCSVExporterInterface $dtExporter, $windows) { |
||
141 | |||
142 | /** |
||
143 | * Get a CSV exporter. |
||
144 | * |
||
145 | * @param DataTablesProviderInterface $dtProvider The provider. |
||
146 | * @return DataTablesCSVExporterInterface Returns the CSV exporter. |
||
147 | * @throws BadDataTablesCSVExporterException Throws a bad CSV exporter exception. |
||
148 | */ |
||
149 | protected function getDataTablesCSVExporter(DataTablesProviderInterface $dtProvider) { |
||
169 | |||
170 | /** |
||
171 | * Get a column. |
||
172 | * |
||
173 | * @param DataTablesProviderInterface $dtProvider The provider. |
||
174 | * @param string $data The data. |
||
175 | * @return DataTablesColumnInterface Returns the column. |
||
176 | * @throws BadDataTablesColumnException Throws a bad column exception. |
||
177 | */ |
||
178 | protected function getDataTablesColumn(DataTablesProviderInterface $dtProvider, $data) { |
||
201 | |||
202 | /** |
||
203 | * Get an editor. |
||
204 | * |
||
205 | * @param DataTablesProviderInterface $dtProvider The provider. |
||
206 | * @return DataTablesEditorInterface Returns the editor. |
||
207 | * @throws BadDataTablesEditorException Throws a bad editor exception. |
||
208 | */ |
||
209 | protected function getDataTablesEditor(DataTablesProviderInterface $dtProvider) { |
||
229 | |||
230 | /** |
||
231 | * Get an entity by id. |
||
232 | * |
||
233 | * @param DataTablesProviderInterface $dtProvider The provider. |
||
234 | * @param int $id The entity id. |
||
235 | * @return object Returns the entity. |
||
236 | * @throws BadDataTablesRepositoryException Throws a bad repository exception. |
||
237 | * @throws EntityNotFoundException Throws an Entity not found exception. |
||
238 | */ |
||
239 | protected function getDataTablesEntityById(DataTablesProviderInterface $dtProvider, $id) { |
||
262 | |||
263 | /** |
||
264 | * Get the manager. |
||
265 | * |
||
266 | * @return DataTablesManager Returns the manager. |
||
267 | */ |
||
268 | protected function getDataTablesManager() { |
||
271 | |||
272 | /** |
||
273 | * Get the provider. |
||
274 | * |
||
275 | * @param string $name The provider name. |
||
276 | * @return DataTablesProviderInterface Returns the provider. |
||
277 | * @throws UnregisteredDataTablesProviderException Throws an unregistered provider exception. |
||
278 | */ |
||
279 | protected function getDataTablesProvider($name) { |
||
298 | |||
299 | /** |
||
300 | * Get a repository. |
||
301 | * |
||
302 | * @param DataTablesProviderInterface $dtProvider The provider. |
||
303 | * @return DataTablesRepositoryInterface Returns the repository. |
||
304 | * @throws BadDataTablesRepositoryException Throws a bad repository exception. |
||
305 | */ |
||
306 | protected function getDataTablesRepository(DataTablesProviderInterface $dtProvider) { |
||
330 | |||
331 | /** |
||
332 | * Get a serializer. |
||
333 | * |
||
334 | * @return Serializer Returns the serializer. |
||
335 | */ |
||
336 | protected function getDataTablesSerializer() { |
||
339 | |||
340 | /** |
||
341 | * Get an URL. |
||
342 | * |
||
343 | * @param DataTablesProviderInterface $dtProvider The provider. |
||
344 | * @return string Returns the URL. |
||
345 | */ |
||
346 | protected function getDataTablesUrl(DataTablesProviderInterface $dtProvider) { |
||
347 | |||
348 | $context = [ |
||
349 | "_controller" => get_class($this), |
||
350 | "_provider" => get_class($dtProvider), |
||
351 | ]; |
||
352 | |||
353 | $this->logInfo(sprintf("DataTables controller search for an URL with name \"%s\"", $dtProvider->getName()), $context); |
||
354 | |||
355 | if (false === ($dtProvider instanceof DataTablesRouterInterface)) { |
||
356 | return $this->getRouter()->generate("wbw_jquery_datatables_index", ["name" => $dtProvider->getName()]); |
||
357 | } |
||
358 | |||
359 | $url = $dtProvider->getUrl(); |
||
360 | |||
361 | $context["_url"] = $url; |
||
362 | |||
363 | $this->logInfo(sprintf("DataTables controller found for an URL with name \"%s\"", $dtProvider->getName()), $context); |
||
364 | |||
365 | return $url; |
||
366 | } |
||
367 | |||
368 | /** |
||
369 | * Get a wrapper. |
||
370 | * |
||
371 | * @param DataTablesProviderInterface $dtProvider The provider. |
||
372 | * @return DataTablesWrapperInterface Returns the wrapper. |
||
373 | */ |
||
374 | protected function getDataTablesWrapper(DataTablesProviderInterface $dtProvider) { |
||
397 | |||
398 | /** |
||
399 | * Handle an exception. |
||
400 | * |
||
401 | * @param Exception $ex The exception. |
||
402 | * @param string $notificationBaseId The notification base id. |
||
403 | * @return ActionResponse Returns the action response. |
||
404 | */ |
||
405 | protected function handleDataTablesException(Exception $ex, $notificationBaseId) { |
||
415 | |||
416 | /** |
||
417 | * Log an info. |
||
418 | * |
||
419 | * @param string $message The message. |
||
420 | * @param array $context The context. |
||
421 | * @return AbstractController Returns this controller. |
||
422 | */ |
||
423 | protected function logInfo($message, array $context = []) { |
||
427 | |||
428 | /** |
||
429 | * Prepare an action response. |
||
430 | * |
||
431 | * @param int $status The status. |
||
432 | * @param string $notificationId The notification id. |
||
433 | * @return ActionResponse Returns the action response. |
||
434 | */ |
||
435 | protected function prepareActionResponse($status, $notificationId) { |
||
445 | } |
||
446 |