InventoryDataTable   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 68
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A ajax() 0 8 1
A query() 0 9 1
A getColumns() 0 21 1
A filename() 0 4 1
1
<?php
2
/**
3
 * app/DataTables/General/InventoryDataTable.php
4
 *
5
 * Datatable for inventory
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 Neil Lathwood
23
 * @author     Neil Lathwood <[email protected]>
24
 */
25
26
namespace App\DataTables\General;
27
28
use App\DataTables\BaseDataTable;
29
use App\Models\General\Inventory;
30
31
class InventoryDataTable extends BaseDataTable
32
{
33
    /**
34
     * Display ajax response.
35
     *
36
     * @return \Illuminate\Http\JsonResponse
37
     */
38
    public function ajax()
39
    {
40
        return $this->datatables
41
            ->eloquent($this->query())
42
            ->editColumn('hostname', 'datatables.generic.hostname')
43
            ->rawColumns(['hostname'])
44
            ->make(true);
45
    }
46
47
    /**
48
     * Get the query object to be processed by datatables.
49
     *
50
     * @return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder
51
     */
52
    public function query()
53
    {
54
        $inventory = Inventory::with([
55
            'device' => function ($query) {
56
                return $query->addSelect(['device_id', 'hostname']);
57
            },
58
        ])->select('entPhysical.*');
59
        return $this->applyScopes($inventory);
60
    }
61
62
    /**
63
     * Get columns.
64
     *
65
     * @return array
66
     */
67 1
    public function getColumns()
68
    {
69
        return [
70
            'hostname'             => [
71 1
                'title'     => trans('devices.label.hostname'),
72
                'orderable' => false,
73 1
            ],
74
            'entPhysicalDescr'     => [
75 1
                'title' => trans('general.text.description'),
76
            ],
77
            'entPhysicalName'      => [
78 1
                'title' => trans('general.text.name'),
79
            ],
80
            'entPhysicalModelName' => [
81 1
                'title' => trans('general.text.model'),
82
            ],
83
            'entPhysicalSerialNum' => [
84 1
                'title' => trans('general.text.serial'),
85
            ],
86
        ];
87
    }
88
89
    /**
90
     * Get filename for export.
91
     *
92
     * @return string
93
     */
94
    protected function filename()
95
    {
96
        return 'inventory';
97
    }
98
}
99