|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Yajra\CMS\DataTables; |
|
4
|
|
|
|
|
5
|
|
|
use Yajra\CMS\Entities\Extension; |
|
6
|
|
|
use Yajra\Datatables\Services\DataTable; |
|
7
|
|
|
|
|
8
|
|
|
class ExtensionsDataTable 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
|
|
|
->addColumn('action', 'administrator.extensions.datatables.action') |
|
20
|
|
|
->editColumn('name', function ($extension) { |
|
21
|
|
|
return "<h3 class=\"lead no-margin\">{$extension->name} <small>{$extension->version}</small></h3> |
|
22
|
|
|
<p>{$extension->description}</p>"; |
|
23
|
|
|
}) |
|
24
|
|
|
->editColumn('enabled', function ($extension) { |
|
25
|
|
|
return $extension->enabled ? 'Y' : 'N'; |
|
26
|
|
|
}) |
|
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 = Extension::query(); |
|
38
|
|
|
|
|
39
|
|
|
return $this->applyScopes($users); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Optional method if you want to use html builder. |
|
44
|
|
|
* |
|
45
|
|
|
* @return \Yajra\Datatables\Html\Builder |
|
46
|
|
|
*/ |
|
47
|
|
|
public function html() |
|
48
|
|
|
{ |
|
49
|
|
|
return $this->builder() |
|
50
|
|
|
->columns($this->getColumns()) |
|
51
|
|
|
->ajax('') |
|
52
|
|
|
->addAction(['width' => '80px']) |
|
53
|
|
|
->parameters($this->getBuilderParameters()); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Get columns. |
|
58
|
|
|
* |
|
59
|
|
|
* @return array |
|
60
|
|
|
*/ |
|
61
|
|
|
private function getColumns() |
|
62
|
|
|
{ |
|
63
|
|
|
return [ |
|
64
|
|
|
'id' => ['width' => '20px', 'title' => trans('cms::extension.table.id')], |
|
65
|
|
|
'name' => ['title' => trans('cms::extension.table.name')], |
|
66
|
|
|
'type' => ['width' => '60px', 'title' => trans('cms::extension.table.type')], |
|
67
|
|
|
'enabled' => ['width' => '20px', 'title' => trans('cms::extension.table.enabled')], |
|
68
|
|
|
]; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Get filename for export. |
|
73
|
|
|
* |
|
74
|
|
|
* @return string |
|
75
|
|
|
*/ |
|
76
|
|
|
protected function filename() |
|
77
|
|
|
{ |
|
78
|
|
|
return 'extensions'; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|