Completed
Pull Request — develop (#121)
by Neil
03:16
created

SyslogDataTable   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 53.85%

Importance

Changes 7
Bugs 1 Features 1
Metric Value
wmc 6
c 7
b 1
f 1
lcom 1
cbo 4
dl 0
loc 73
ccs 14
cts 26
cp 0.5385
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A ajax() 0 10 2
A query() 0 5 1
A getColumns() 0 17 1
A filename() 0 4 1
A getAjax() 0 4 1
1
<?php
2
/**
3
 * app/DataTables/General/SyslogDataTable.php
4
 *
5
 * Datatable for syslog
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\Syslog;
30
31
class SyslogDataTable 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($syslog) {
43
                $hostname = is_null($syslog->device) ? trans('devices.text.deleted') : $syslog->device->hostname;
44
                return '<a href="'.url("devices/".$syslog->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
        $syslog = Syslog::with('device')->select('syslog.*');
57
        return $this->applyScopes($syslog);
58
    }
59
60
    /**
61
     * Get columns.
62
     *
63
     * @return array
64 1
     */
65
    public function getColumns()
66 1
    {
67 1
        return [
68 1
            'device.hostname' => [
69
                'title'       => trans('devices.label.hostname'),
70
            ],
71
            'program'      => [
72
                'title' => trans('general.text.program'),
73
            ],
74
            'msg'   => [
75
                'title' => trans('general.text.message'),
76 1
            ],
77
            'timestamp'  => [
78
                'title' => trans('general.text.timestamp'),
79
            ],
80 1
        ];
81 1
    }
82
83 1
    /**
84 1
     * Get filename for export.
85
     *
86 1
     * @return string
87 1
     */
88
    protected function filename()
89 1
    {
90 1
        return 'syslog';
91 1
    }
92
93
    /**
94
     * Get ajax url.
95
     *
96
     * @return \Illuminate\Contracts\Routing\UrlGenerator|string
97
     */
98
    public function getAjax()
99
    {
100
        return url('syslog');
101
    }
102
103
}
104