Completed
Pull Request — develop (#107)
by Neil
20:59
created

SyslogDataTable::ajax()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
ccs 0
cts 7
cp 0
rs 9.6666
cc 1
eloc 6
nc 1
nop 0
crap 2
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\Models\General\Syslog;
29
use Yajra\Datatables\Services\DataTable;
30
31
class SyslogDataTable extends DataTable
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($this) {
0 ignored issues
show
Documentation introduced by
function ($this) { r...'hostname'] . '</a>'; } is of type object<Closure>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
43
                return '<a href="'.url("devices/".$this['device']['device_id']).'">'.$this['device']['hostname'].'</a>';
44
            })
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
        $syslog = Syslog::with('device')->select('syslog.*');
56
        return $this->applyScopes($syslog);
57
    }
58
59
    /**
60
     * Optional method if you want to use html builder.
61
     *
62
     * @return \Yajra\Datatables\Html\Builder
63
     */
64 1
    public function html()
65
    {
66 1
        return $this->builder()
67 1
                    ->columns($this->getColumns())
68 1
                    ->parameters($this->getBuilderParameters());
69
    }
70
71
    /**
72
     * Get columns.
73
     *
74
     * @return array
75
     */
76 1
    private function getColumns()
77
    {
78
        return [
79
            'device.hostname' => [
80 1
                'title'       => trans('devices.label.hostname'),
81 1
            ],
82
            'program'      => [
83 1
                'title' => trans('general.text.program'),
84 1
            ],
85
            'msg'   => [
86 1
                'title' => trans('general.text.message'),
87 1
            ],
88
            'timestamp'  => [
89 1
                'title' => trans('general.text.timestamp'),
90 1
            ],
91 1
        ];
92
    }
93
94
    /**
95
     * Get filename for export.
96
     *
97
     * @return string
98
     */
99
    protected function filename()
100
    {
101
        return 'syslog';
102
    }
103
104
    /**
105
     * Get Builder Params
106
     *
107
     * @return array
108
     */
109 1
    protected function getBuilderParameters()
110
    {
111
        return [
112 1
            'dom' => 'Blfrtip',
113 1
            'lengthMenu' => [[25, 50, 100, -1], [25, 50, 100, "All"]],
114
            'buttons' => [
115 1
                'csv', 'excel', 'pdf', 'print', 'reset', 'reload',
116 1
            ],
117 1
        ];
118
    }
119
120
}
121