1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Yajra\CMS\DataTables; |
4
|
|
|
|
5
|
|
|
use Yajra\CMS\Entities\Widget; |
6
|
|
|
use Yajra\Datatables\Services\DataTable; |
7
|
|
|
|
8
|
|
|
class WidgetsDataTable extends DataTable |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Display ajax response. |
12
|
|
|
* |
13
|
|
|
* @return \Illuminate\Http\JsonResponse |
14
|
|
|
*/ |
15
|
|
|
public function ajax() |
16
|
|
|
{ |
17
|
|
|
return $this->datatables |
18
|
|
|
->eloquent($this->query()) |
19
|
|
|
->editColumn('published', function (Widget $widget) { |
20
|
|
|
return dt_check($widget->published); |
21
|
|
|
}) |
22
|
|
|
->editColumn('authenticated', function (Widget $widget) { |
23
|
|
|
return dt_check($widget->authenticated); |
24
|
|
|
}) |
25
|
|
|
->addColumn('action', 'administrator.widgets.datatables.action') |
26
|
|
|
->rawColumns(['published', 'authenticated', 'action']) |
27
|
|
|
->make(true); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Get the query object to be processed by datatables. |
32
|
|
|
* |
33
|
|
|
* @return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder |
34
|
|
|
*/ |
35
|
|
|
public function query() |
36
|
|
|
{ |
37
|
|
|
$users = Widget::query() |
|
|
|
|
38
|
|
|
->select('widgets.*') |
39
|
|
|
->with([ |
40
|
|
|
'extension' => function ($query) { |
41
|
|
|
$query->select('id', 'name'); |
42
|
|
|
}, |
43
|
|
|
]) |
44
|
|
|
->withoutGlobalScope('menu_assignment'); |
45
|
|
|
|
46
|
|
|
return $this->applyScopes($users); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Optional method if you want to use html builder. |
51
|
|
|
* |
52
|
|
|
* @return \Yajra\Datatables\Html\Builder |
53
|
|
|
*/ |
54
|
|
View Code Duplication |
public function html() |
|
|
|
|
55
|
|
|
{ |
56
|
|
|
return $this->builder() |
57
|
|
|
->columns($this->getColumns()) |
58
|
|
|
->ajax('') |
59
|
|
|
->addAction(['width' => '104px']) |
60
|
|
|
->parameters($this->getBuilderParameters()); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Get columns. |
65
|
|
|
* |
66
|
|
|
* @return array |
67
|
|
|
*/ |
68
|
|
|
private function getColumns() |
69
|
|
|
{ |
70
|
|
|
return [ |
71
|
|
|
'id' => ['width' => '20px', 'name' => 'widgets.id'], |
72
|
|
|
'title', |
73
|
|
|
'position' => ['width' => '80px'], |
74
|
|
|
'extension.name' => [ |
75
|
|
|
'width' => '60px', |
76
|
|
|
'title' => '<i class="fa fa-plug" data-toggle="tooltip" data-title="' . trans('cms::widget.datatable.columns.extensionName') . '"></i> Ext.', |
77
|
|
|
], |
78
|
|
|
'published' => [ |
79
|
|
|
'width' => '20px', |
80
|
|
|
'title' => '<i class="fa fa-check-circle" data-toggle="tooltip" data-title="' . trans('cms::widget.datatable.columns.published') . '"></i>', |
81
|
|
|
], |
82
|
|
|
'authenticated' => [ |
83
|
|
|
'width' => '20px', |
84
|
|
|
'title' => '<i class="fa fa-key" data-toggle="tooltip" data-title="' . trans('cms::widget.datatable.columns.authenticated') . '"></i>', |
85
|
|
|
], |
86
|
|
|
'order' => [ |
87
|
|
|
'width' => '20px', |
88
|
|
|
'title' => '<i class="fa fa-list" data-toggle="tooltip" data-title="' . trans('cms::widget.datatable.columns.order') . '"></i>', |
89
|
|
|
'name' => 'widgets.order', |
90
|
|
|
], |
91
|
|
|
'updated_at' => [ |
92
|
|
|
'searchable' => false, |
93
|
|
|
'width' => '100px', |
94
|
|
|
], |
95
|
|
|
]; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @return array |
100
|
|
|
*/ |
101
|
|
View Code Duplication |
protected function getBuilderParameters() |
|
|
|
|
102
|
|
|
{ |
103
|
|
|
return [ |
104
|
|
|
'stateSave' => true, |
105
|
|
|
'order' => [0, 'desc'], |
106
|
|
|
'buttons' => [ |
107
|
|
|
[ |
108
|
|
|
'extend' => 'create', |
109
|
|
|
'text' => '<i class="fa fa-plus"></i> ' . trans('cms::widget.datatable.buttons.create'), |
110
|
|
|
], |
111
|
|
|
'export', |
112
|
|
|
'print', |
113
|
|
|
'reset', |
114
|
|
|
'reload', |
115
|
|
|
], |
116
|
|
|
]; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Get filename for export. |
121
|
|
|
* |
122
|
|
|
* @return string |
123
|
|
|
*/ |
124
|
|
|
protected function filename() |
125
|
|
|
{ |
126
|
|
|
return 'widgets'; |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.