Completed
Push — master ( 6e8adf...c24137 )
by
unknown
27s
created

SiteDataTable::dataTable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 9
ccs 0
cts 8
cp 0
crap 2
rs 9.6666
c 1
b 0
f 0
1
<?php
2
3
namespace App\DataTables;
4
5
use Yajra\DataTables\Services\DataTable;
6
use App\Site;
7
8
class SiteDataTable extends DataTable
9
{
10
    /**
11
     * Build DataTable class.
12
     *
13
     * @return \Yajra\DataTables\Engines\BaseEngine
0 ignored issues
show
Bug introduced by
The type Yajra\DataTables\Engines\BaseEngine was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
     */
15
    public function dataTable($query)
16
    {
17
        return datatables($query)
18
            ->editColumn('name', function($site) {
19
                return '<a href="'.route('site.show', $site->id).'">'.$site->name.'</a>';
20
            })
21
            ->addColumn('action', 'site.action')
22
            ->blacklist([ 'action' ])
23
            ->rawColumns([ 'name', 'action' ]);
24
    }
25
    
26
    /**
27
     * Get the query object to be processed by dataTables.
28
     *
29
     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|\Illuminate\Support\Collection
30
     */
31
    public function query()
32
    {
33
        $query = Site::query();
34
        return $this->applyScopes($query);
35
    }
36
    
37
    /**
38
     * Optional method if you want to use html builder.
39
     *
40
     * @return \Yajra\DataTables\Html\Builder
41
     */
42
    public function html()
43
    {
44
        return $this->builder()
45
            ->columns($this->getColumns())
46
            ->minifiedAjax()
47
            ->parameters($this->getBuilderParameters());
48
    }
49
    
50
    /**
51
     * Get columns.
52
     *
53
     * @return array
54
     */
55
    protected function getColumns()
56
    {
57
        return [
58
            'id',
59
            'name',
60
            [ 'data' => 'action', 'name' => 'action', 'title' => 'Action', 'searchable' => false, 'orderable' => false, 'exportable' => false, 'printable' => false ]
61
        ];
62
    }
63
    
64
    /**
65
     * Get builder parameters.
66
     *
67
     * @return array
68
     */
69 View Code Duplication
    protected function getBuilderParameters()
70
    {
71
        return [
72
            'dom'     => 'Bfrtip',
73
            'order'   => [ [ 0, 'asc' ] ],
74
            'buttons' => [
75
                'create',
76
                [ 'extend' => 'collection', 'text' => '<i class="fa fa-file-excel-o"></i> Export', 'buttons' => [ 
77
                    [ 'extend' => 'csv', 'exportOptions' => [ 'modifier' => [ 'search' => true ] ] ],
78
                    [ 'extend' => 'excel', 'exportOptions' => [ 'modifier' => [ 'search' => true ] ] ],
79
                ] ],
80
                [ 'extend' => 'print', 'exportOptions' => [ 'modifier' => [ 'search' => true ] ] ],
81
                'reset',
82
                'reload',
83
            ],
84
            'paging' => true,
85
            'searching' => true,
86
            'info' => true,
87
            'searchDelay' => 500,
88
        ];
89
    }
90
    
91
    /**
92
     * Get filename for export.
93
     *
94
     * @return string
95
     */
96
    protected function filename()
97
    {
98
        return 'site_'.time();
99
    }
100
}