Completed
Push — master ( fed948...6aff41 )
by Tony
10s
created

InventoryDataTable::getBuilderParameters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
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('device.hostname', function($inventory) {
43
                $hostname = is_null($inventory->device) ? trans('devices.text.deleted') : $inventory->device->hostname;
44
                return '<a href="'.url("devices/".$inventory->device_id).'">'.$hostname.'</a>';
45
            })
46
            ->make(true);
47
    }
48
49
    /**
50
     * Get the query object to be processed by datatables.
51
     *
52
     * @return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder
53
     */
54
    public function query()
55
    {
56
        $inventory = Inventory::with('device')->select('entPhysical.*');
57
        return $this->applyScopes($inventory);
58
    }
59
60
    /**
61
     * Get columns.
62
     *
63
     * @return array
64
     */
65
    public function getColumns()
66
    {
67
        return [
68
            'device.hostname' => [
69
                'title'       => trans('devices.label.hostname'),
70
            ],
71
            'entPhysicalDescr'      => [
72
                'title' => trans('general.text.description'),
73
            ],
74
            'entPhysicalName'   => [
75
                'title' => trans('general.text.name'),
76
            ],
77
            'entPhysicalModelName'  => [
78
                'title' => trans('general.text.model'),
79
            ],
80
            'entPhysicalSerialNum'  => [
81
                'title' => trans('general.text.serial'),
82
            ],
83
        ];
84
    }
85
86
    /**
87
     * Get filename for export.
88
     *
89
     * @return string
90
     */
91
    protected function filename()
92
    {
93
        return 'inventory';
94
    }
95
}
96