Completed
Push — develop ( a8c0b8...91aaeb )
by Neil
17:22
created

EventlogDataTable::query()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

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 5
ccs 0
cts 3
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * app/DataTables/General/EventlogDataTable.php
4
 *
5
 * Datatable for eventlogs
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\Eventlog;
29
use Yajra\Datatables\Services\DataTable;
30
31
class EventlogDataTable 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
        $eventlogs = Eventlog::query()->with('device')->select('eventlog.*');
56
        return $this->applyScopes($eventlogs);
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
            'type'      => [
83 1
                'title' => trans('general.text.type'),
84 1
                'name'  => 'eventlog.type',
85 1
            ],
86
            'message'   => [
87 1
                'title' => trans('general.text.message'),
88 1
            ],
89
            'datetime'  => [
90 1
                'title' => trans('general.text.timestamp'),
91 1
            ],
92 1
        ];
93
    }
94
95
    /**
96
     * Get filename for export.
97
     *
98
     * @return string
99
     */
100
    protected function filename()
101
    {
102
        return 'eventlog';
103
    }
104
105
    /**
106
     * Get Builder Params
107
     *
108
     * @return array
109
     */
110 1
    protected function getBuilderParameters()
111
    {
112
        return [
113 1
            'dom' => 'Blfrtip',
114 1
            'lengthMenu' => [[25, 50, 100, -1], [25, 50, 100, "All"]],
115
            'buttons' => [
116 1
                'csv', 'excel', 'pdf', 'print', 'reset', 'reload',
117 1
            ],
118 1
        ];
119
    }
120
121
}
122