1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SleepingOwl\Admin\Display; |
4
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
6
|
|
|
use Illuminate\Routing\Router; |
7
|
|
|
use SleepingOwl\Admin\Contracts\WithRoutesInterface; |
8
|
|
|
|
9
|
|
|
class DisplayDatatablesAsyncAlterPaginate extends DisplayDatatablesAsync implements WithRoutesInterface |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Register display routes. |
13
|
|
|
* |
14
|
|
|
* @param Router $router |
15
|
|
|
* |
16
|
|
|
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
17
|
|
|
*/ |
18
|
|
|
public static function registerRoutes(Router $router) |
19
|
|
|
{ |
20
|
|
|
$routeName = 'admin.display.async.alter_paginate'; |
21
|
|
|
if (! $router->has($routeName)) { |
22
|
|
|
$router->get('{adminModel}/async/alter_paginate/{adminDisplayName?}', [ |
23
|
|
|
'as' => $routeName, |
24
|
|
|
'uses' => 'SleepingOwl\Admin\Http\Controllers\AlterPaginateDisplayController@async', |
|
|
|
|
25
|
|
|
]); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
$routeName = 'admin.display.async.inlineEdit'; |
29
|
|
|
if (! $router->has($routeName)) { |
30
|
|
|
$router->post('{adminModel}/async/{adminDisplayName?}', [ |
31
|
|
|
'as' => $routeName, |
32
|
|
|
'uses' => 'SleepingOwl\Admin\Http\Controllers\AdminController@inlineEdit', |
|
|
|
|
33
|
|
|
]); |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Render async request. |
39
|
|
|
* |
40
|
|
|
* @param \Illuminate\Http\Request $request |
41
|
|
|
* |
42
|
|
|
* @return array |
43
|
|
|
*/ |
44
|
|
|
public function renderAsync(Request $request) |
45
|
|
|
{ |
46
|
|
|
$query = $this->getRepository()->getQuery(); |
47
|
|
|
$totalCount = 0; |
48
|
|
|
$filteredCount = 0; |
49
|
|
|
|
50
|
|
|
if (! is_null($this->distinct)) { |
51
|
|
|
$filteredCount = $query->distinct()->count($this->getDistinct()); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$this->modifyQuery($query); |
55
|
|
|
$this->applySearch($query, $request); |
56
|
|
|
|
57
|
|
|
if (is_null($this->distinct)) { |
58
|
|
|
$countQuery = clone $query; |
59
|
|
|
$countQuery->getQuery()->orders = null; |
60
|
|
|
$filteredCount = 500; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$this->applyOffset($query, $request); |
|
|
|
|
64
|
|
|
$collection = $query->get(); |
65
|
|
|
|
66
|
|
|
return $this->prepareDatatablesStructure($request, $collection, $totalCount, $filteredCount); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
If there is a route defined but the controller class cannot be found there are two options: 1. the controller class needs to be implemented or 2. the route is outdated and can be removed.
If ?FooController? was found and ?BarController? is missing for the following example, either the controller should be implemented or the route should be removed: