Completed
Push — master ( e5ba92...7a1e6c )
by Arjay
13:54
created

WidgetsDataTable::getColumns()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 2 Features 1
Metric Value
cc 1
eloc 21
c 3
b 2
f 1
nc 1
nop 0
dl 0
loc 29
rs 8.8571
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
            ->make(true);
27
    }
28
29
    /**
30
     * Get the query object to be processed by datatables.
31
     *
32
     * @return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder
33
     */
34
    public function query()
35
    {
36
        $users = Widget::query()
37
                       ->select('widgets.*')
38
                       ->with([
39
                           'extension' => function ($query) {
40
                               $query->select('id', 'name');
41
                           },
42
                       ])
43
                       ->withoutGlobalScope('menu_assignment');
44
45
        return $this->applyScopes($users);
46
    }
47
48
    /**
49
     * Optional method if you want to use html builder.
50
     *
51
     * @return \Yajra\Datatables\Html\Builder
52
     */
53 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...
54
    {
55
        return $this->builder()
56
                    ->columns($this->getColumns())
57
                    ->ajax('')
58
                    ->addAction(['width' => '104px'])
59
                    ->parameters($this->getBuilderParameters());
60
    }
61
62
    /**
63
     * Get columns.
64
     *
65
     * @return array
66
     */
67
    private function getColumns()
68
    {
69
        return [
70
            'id'             => ['width' => '20px', 'name' => 'widgets.id'],
71
            'title',
72
            'position'       => ['width' => '80px'],
73
            'extension.name' => [
74
                'width' => '60px',
75
                'title' => '<i class="fa fa-plug" data-toggle="tooltip" data-title="Widget Extension"></i> Ext.',
76
            ],
77
            'published'      => [
78
                'width' => '20px',
79
                'title' => '<i class="fa fa-check-circle" data-toggle="tooltip" data-title="Published"></i>',
80
            ],
81
            'authenticated'  => [
82
                'width' => '20px',
83
                'title' => '<i class="fa fa-key" data-toggle="tooltip" data-title="Authentication Required"></i>',
84
            ],
85
            'order'          => [
86
                'width' => '20px',
87
                'title' => '<i class="fa fa-list" data-toggle="tooltip" data-title="Sort/Order"></i>',
88
                'name'  => 'widgets.order',
89
            ],
90
            'updated_at'     => [
91
                'searchable' => false,
92
                'width'      => '100px',
93
            ],
94
        ];
95
    }
96
97
    /**
98
     * @return array
99
     */
100 View Code Duplication
    protected function getBuilderParameters()
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...
101
    {
102
        return [
103
            'stateSave' => true,
104
            'order'     => [0, 'desc'],
105
            'buttons'   => [
106
                [
107
                    'extend' => 'create',
108
                    'text'   => '<i class="fa fa-plus"></i>&nbsp;&nbsp;New Widget',
109
                ],
110
                'export',
111
                'print',
112
                'reset',
113
                'reload',
114
            ],
115
        ];
116
    }
117
118
    /**
119
     * Get filename for export.
120
     *
121
     * @return string
122
     */
123
    protected function filename()
124
    {
125
        return 'widgets';
126
    }
127
}
128