Passed
Push — develop ( 0fc46b...6b7c8d )
by Tony
04:19
created

DeviceGroupDataTable::ajax()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 10
ccs 0
cts 0
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * DeviceGroupDataTable.php
4
 *
5
 * -Description-
6
 *
7
 * This program is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation, either version 3 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 *
20
 * @package    LibreNMS
21
 * @link       http://librenms.org
22
 * @copyright  2016 Tony Murray
23
 * @author     Tony Murray <[email protected]>
24
 */
25
26
namespace App\DataTables;
27
28
use App\Models\DeviceGroup;
29
30
class DeviceGroupDataTable extends BaseDataTable
31
{
32
    /**
33
     * Display ajax response.
34
     *
35
     * @return \Illuminate\Http\JsonResponse
36
     */
37
    public function ajax()
38
    {
39
        return $this->datatables
40
            ->eloquent($this->query())
41
            ->editColumn('name', 'datatables.device-group.link')
42
            ->editColumn('count', 'datatables.device-group.count')
43
            ->addColumn('actions', 'datatables.device-group.actions')
44
            ->rawColumns(['name', 'count', 'actions'])
45
            ->make(true);
46
    }
47
48
    /**
49
     * Get the query object to be processed by datatables.
50
     *
51
     * @return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder
52
     */
53
    public function query()
54
    {
55
        $devicegroups = DeviceGroup::with('deviceCountRelation')->select('device_groups.*');
56
        return $this->applyScopes($devicegroups);
57
    }
58
59
    /**
60
     * Get columns.
61
     *
62
     * @return array
63
     */
64 1
    public function getColumns()
65
    {
66
        return [
67
            'id'         => [
68
                'visible' => false,
69 1
            ],
70
            'name'       => [
71 1
                'title' => trans('devices.groups.name'),
72
            ],
73
            'count'      => [
74
                'title'      => '',
75
                'searchable' => false,
76
            ],
77
            'desc'       => [
78 1
                'title' => trans('devices.groups.desc'),
79
            ],
80
            'patternSql' => [
81 1
                'title' => trans('devices.groups.pattern'),
82
            ],
83
            'actions'    => [
84 1
                'title' => trans('devices.groups.actions'),
85
            ],
86
        ];
87
    }
88
89
    /**
90
     * Get filename for export.
91
     *
92
     * @return string
93
     */
94
    protected function filename()
95
    {
96
        return 'devicegroups';
97
    }
98
}
99