LocationDataTable::filename()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace App\DataTables;
4
5
use Yajra\DataTables\Services\DataTable;
6
use App\Location;
7
8
class LocationDataTable 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($location) {
19
                return '<a href="'.route('location.show', $location->id).'">'.$location->name.'</a>';
20
            })
21
            ->editColumn('site_id', function($location) {
22
                return '<a href="'.route('site.show', $location->site_id).'">'.($location->site->name ?? '').'</a>';
23
            })
24
            ->addColumn('action', 'location.action')
25
            ->blacklist([ 'action' ])
26
            ->rawColumns([ 'site_id', 'name', 'action' ]);
27
    }
28
    
29
    /**
30
     * Get the query object to be processed by dataTables.
31
     *
32
     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|\Illuminate\Support\Collection
33
     */
34
    public function query()
35
    {
36
        $query = Location::query();
37
        return $this->applyScopes($query);
38
    }
39
    
40
    /**
41
     * Optional method if you want to use html builder.
42
     *
43
     * @return \Yajra\DataTables\Html\Builder
44
     */
45
    public function html()
46
    {
47
        return $this->builder()
48
            ->columns($this->getColumns())
49
            ->minifiedAjax()
50
            ->parameters($this->getBuilderParameters());
51
    }
52
    
53
    /**
54
     * Get columns.
55
     *
56
     * @return array
57
     */
58 View Code Duplication
    protected function getColumns()
59
    {
60
        return [
61
            'id',
62
            'name',
63
            [ 'data' => 'site_id', 'name' => 'site_id', 'title' => 'Site' ],
64
            [ 'data' => 'action', 'name' => 'action', 'title' => 'Action', 'searchable' => false, 'orderable' => false, 'exportable' => false, 'printable' => false ]
65
        ];
66
    }
67
    
68
    /**
69
     * Get builder parameters.
70
     *
71
     * @return array
72
     */
73 View Code Duplication
    protected function getBuilderParameters()
74
    {
75
        return [
76
            'dom'     => 'Bfrtip',
77
            'order'   => [ [ 0, 'asc' ] ],
78
            'buttons' => [
79
                'create',
80
                [ 'extend' => 'collection', 'text' => '<i class="fa fa-file-excel-o"></i> Export', 'buttons' => [ 
81
                    [ 'extend' => 'csv', 'exportOptions' => [ 'modifier' => [ 'search' => true ] ] ],
82
                    [ 'extend' => 'excel', 'exportOptions' => [ 'modifier' => [ 'search' => true ] ] ],
83
                ] ],
84
                [ 'extend' => 'print', 'exportOptions' => [ 'modifier' => [ 'search' => true ] ] ],
85
                'reset',
86
                'reload',
87
            ],
88
            'paging' => true,
89
            'searching' => true,
90
            'info' => true,
91
            'searchDelay' => 500,
92
        ];
93
    }
94
    
95
    /**
96
     * Get filename for export.
97
     *
98
     * @return string
99
     */
100
    protected function filename()
101
    {
102
        return 'location_'.time();
103
    }
104
}