ExtensionsDataTable::ajax()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 13
nc 1
nop 0
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
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 text-blue\">{$extension->name} <small>{$extension->version}</small></h3>
22
                            <p>{$extension->description}</p>";
23
            })
24
            ->editColumn('type', function ($extension) {
25
                return dt_label($extension->type, 'danger');
26
            })
27
            ->editColumn('enabled', function ($extension) {
28
                return dt_check($extension->enabled);
29
            })
30
            ->rawColumns(['action', 'name', 'type', 'enabled'])
31
            ->make(true);
32
    }
33
34
    /**
35
     * Get the query object to be processed by datatables.
36
     *
37
     * @return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder
38
     */
39
    public function query()
40
    {
41
        $users = Extension::query();
42
43
        return $this->applyScopes($users);
44
    }
45
46
    /**
47
     * Optional method if you want to use html builder.
48
     *
49
     * @return \Yajra\Datatables\Html\Builder
50
     */
51 View Code Duplication
    public function html()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
52
    {
53
        return $this->builder()
54
                    ->columns($this->getColumns())
55
                    ->ajax('')
56
                    ->addAction(['width' => '80px'])
57
                    ->parameters([
58
                        'order'   => [[0, 'desc']],
59
                        'buttons' => [
60
                            'export',
61
                            'print',
62
                            'reset',
63
                            'reload',
64
                        ],
65
                    ]);
66
    }
67
68
    /**
69
     * Get columns.
70
     *
71
     * @return array
72
     */
73
    protected function getColumns()
74
    {
75
        return [
76
            'id'      => ['width' => '20px', 'title' => trans('cms::extension.table.id')],
77
            'name'    => ['title' => trans('cms::extension.table.name')],
78
            'type'    => ['width' => '60px', 'title' => trans('cms::extension.table.type')],
79
            'enabled' => ['width' => '20px', 'title' => trans('cms::extension.table.enabled')],
80
        ];
81
    }
82
83
    /**
84
     * Get filename for export.
85
     *
86
     * @return string
87
     */
88
    protected function filename()
89
    {
90
        return 'extensions';
91
    }
92
}
93