|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Cortex\Pages\DataTables\Tenantarea; |
|
6
|
|
|
|
|
7
|
|
|
use Rinvex\Pages\Contracts\PageContract; |
|
8
|
|
|
use Cortex\Foundation\DataTables\AbstractDataTable; |
|
9
|
|
|
use Cortex\Pages\Transformers\Tenantarea\PageTransformer; |
|
10
|
|
|
|
|
11
|
|
|
class PagesDataTable extends AbstractDataTable |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* {@inheritdoc} |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $model = PageContract::class; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* {@inheritdoc} |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $transformer = PageTransformer::class; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Get the query object to be processed by dataTables. |
|
25
|
|
|
* |
|
26
|
|
|
* @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|\Illuminate\Support\Collection |
|
|
|
|
|
|
27
|
|
|
*/ |
|
28
|
|
|
public function query() |
|
29
|
|
|
{ |
|
30
|
|
|
$locale = app()->getLocale(); |
|
31
|
|
|
$query = app($this->model)->query()->orderBy('sort_order', 'ASC')->orderBy("title->\${$locale}", 'ASC'); |
|
32
|
|
|
|
|
33
|
|
|
return $this->applyScopes($query); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Get parameters. |
|
38
|
|
|
* |
|
39
|
|
|
* @return array |
|
|
|
|
|
|
40
|
|
|
*/ |
|
41
|
|
|
protected function getParameters() |
|
42
|
|
|
{ |
|
43
|
|
|
return [ |
|
44
|
|
|
'keys' => true, |
|
45
|
|
|
'autoWidth' => false, |
|
46
|
|
|
'dom' => "<'row'<'col-sm-6'B><'col-sm-6'f>> <'row'r><'row'<'col-sm-12't>> <'row'<'col-sm-5'i><'col-sm-7'p>>", |
|
|
|
|
|
|
47
|
|
|
'buttons' => [ |
|
48
|
|
|
['extend' => 'create', 'text' => '<i class="fa fa-plus"></i> '.trans('cortex/foundation::common.new')], 'print', 'reset', 'reload', 'export', |
|
|
|
|
|
|
49
|
|
|
['extend' => 'colvis', 'text' => '<i class="fa fa-columns"></i> '.trans('cortex/foundation::common.columns').' <span class="caret"/>'], |
|
|
|
|
|
|
50
|
|
|
], |
|
51
|
|
|
]; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Display ajax response. |
|
56
|
|
|
* |
|
57
|
|
|
* @return \Illuminate\Http\JsonResponse |
|
58
|
|
|
*/ |
|
59
|
|
|
public function ajax() |
|
60
|
|
|
{ |
|
61
|
|
|
$transformer = app($this->transformer); |
|
62
|
|
|
|
|
63
|
|
|
return datatables()->eloquent($this->query()) |
|
|
|
|
|
|
64
|
|
|
->setTransformer($transformer) |
|
65
|
|
|
->orderColumn('title', 'title->"$.'.app()->getLocale().'" $1') |
|
66
|
|
|
->make(true); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Get columns. |
|
71
|
|
|
* |
|
72
|
|
|
* @return array |
|
|
|
|
|
|
73
|
|
|
*/ |
|
74
|
|
|
protected function getColumns() |
|
75
|
|
|
{ |
|
76
|
|
|
$link = config('cortex.foundation.route.locale_prefix') |
|
77
|
|
|
? '"<a href=\""+routes.route(\'tenantarea.pages.edit\', {page: full.slug, locale: \''.$this->request->segment(1).'\'})+"\">"+data+"</a>"' |
|
|
|
|
|
|
78
|
|
|
: '"<a href=\""+routes.route(\'tenantarea.pages.edit\', {page: full.slug})+"\">"+data+"</a>"'; |
|
79
|
|
|
|
|
80
|
|
|
return [ |
|
81
|
|
|
'title' => ['title' => trans('cortex/pages::common.title'), 'render' => $link, 'responsivePriority' => 0], |
|
82
|
|
|
'uri' => ['title' => trans('cortex/pages::common.uri')], |
|
83
|
|
|
'route' => ['title' => trans('cortex/pages::common.route')], |
|
84
|
|
|
'view' => ['title' => trans('cortex/pages::common.view')], |
|
85
|
|
|
'middleware' => ['title' => trans('cortex/pages::common.middleware')], |
|
86
|
|
|
'created_at' => ['title' => trans('cortex/pages::common.created_at'), 'render' => "moment(data).format('MMM Do, YYYY')"], |
|
|
|
|
|
|
87
|
|
|
'updated_at' => ['title' => trans('cortex/pages::common.updated_at'), 'render' => "moment(data).format('MMM Do, YYYY')"], |
|
|
|
|
|
|
88
|
|
|
]; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.