Completed
Push — master ( ffe767...90fa06 )
by Brandon
02:24
created

DevicesDataTable::filename()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace App\DataTables;
4
5
use App\Device;
6
use Yajra\Datatables\Services\DataTable;
7
8
class DevicesDataTable extends DataTable
9
{
10
    /**
11
     * Build DataTable class.
12
     *
13
     * @return \Yajra\Datatables\Engines\BaseEngine
14
     */
15
    public function dataTable()
16
    {
17
        return $this->datatables
18
            ->eloquent($this->query())
19
            ->addColumn('action', 'device.action')
20
            ->blacklist(['action'])
21
            ->setRowClass(function ($device) {
22
                return $device->trashed() ? 'alert-danger' : "";
23
            });
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 = Device::query()
0 ignored issues
show
Bug introduced by
The method select() does not exist on Illuminate\Database\Eloquent\Builder. Did you maybe mean createSelectWithConstraint()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
34
                        ->select([
35
                            'devices.id as id',
36
                            'devices.name as name',
37
                            'locations.name as location',
38
                            'sites.name as site'
39
                        ])
40
                        ->leftJoin('locations', 'devices.location_id', '=', 'locations.id')
41
                        ->leftJoin('sites', 'locations.site_id', '=', 'sites.id');
42
    
43
    
44
        return $this->applyScopes($query);
45
    }
46
47
    /**
48
     * Optional method if you want to use html builder.
49
     *
50
     * @return \Yajra\Datatables\Html\Builder
51
     */
52 View Code Duplication
    public function html()
1 ignored issue
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...
53
    {
54
        return $this->builder()
55
                    ->columns($this->getColumns())
56
                    //->minifiedAjax('')
57
                    //->addAction(['width' => '160px'])
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
58
                    ->parameters([
59
                        'dom'     => 'Bfrtip',
60
                        'order'   => [[0, 'asc']],
61
                        'buttons' => [
62
                            'export',
63
                            'print',
64
                            'reset',
65
                            'reload',
66
                        ],
67
                        'paging' => true,
68
                        'searching' => true,
69
                        'info' => true,
70
                        'searchDelay' => 500,
71
                    ]);
72
    }
73
74
    /**
75
     * Get columns.
76
     *
77
     * @return array
78
     */
79
    protected function getColumns()
80
    {
81
        return [
82
            'id',
83
            'name',
84
            'location',
85
            'site',
86
            ['name' => 'action', 'data' => 'action', 'title' => 'Actions', 'render' => null, 'searchable' => false, 'orderable' => false, 'exportable' => false, 'printable' => true, 'footer' => ''],
87
        ];
88
    }
89
90
    /**
91
     * Get filename for export.
92
     *
93
     * @return string
94
     */
95
    protected function filename()
96
    {
97
        return 'devices_' . time();
98
    }
99
}
100