Issues (2963)

includes/html/list/transports.inc.php (1 issue)

1
<?php
2
/**
3
 * transports.inc.php
4
 *
5
 * List transports
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 <https://www.gnu.org/licenses/>.
19
 *
20
 * @link       https://www.librenms.org
21
 *
22
 * @copyright  2018 Vivia Nguyen-Tran
23
 * @author     Vivia Nguyen-Tran <vivia@ualberta>
24
 */
25
if (! Auth::user()->hasGlobalRead()) {
0 ignored issues
show
The method hasGlobalRead() does not exist on Illuminate\Contracts\Auth\Authenticatable. It seems like you code against a sub-type of Illuminate\Contracts\Auth\Authenticatable such as Illuminate\Foundation\Auth\User. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

25
if (! Auth::user()->/** @scrutinizer ignore-call */ hasGlobalRead()) {
Loading history...
26
    return [];
27
}
28
29
$query = '';
30
$params = [];
31
32
if (! empty($vars['search'])) {
33
    $query .= ' WHERE `transport_name` LIKE ?';
34
    $params[] = '%' . $vars['search'] . '%';
35
}
36
37
$total = dbFetchCell("SELECT COUNT(*) FROM `alert_transports` $query", $params);
38
$more = false;
39
40
if (! empty($_REQUEST['limit'])) {
41
    $limit = (int) $vars['limit'];
42
    $page = isset($vars['page']) ? (int) $vars['page'] : 1;
43
    $offset = ($page - 1) * $limit;
44
45
    $query .= " LIMIT $offset, $limit";
46
} else {
47
    $offset = 0;
48
}
49
50
$sql = "SELECT `transport_id` AS `id`, `transport_name` AS `text`, `transport_type` AS `type` FROM `alert_transports` $query";
51
$transports = dbFetchRows($sql, $params);
52
53
$more = ($offset + count($transports)) < $total;
54
$transports = array_map(function ($transport) {
55
    $transport['text'] = ucfirst($transport['type']) . ': ' . $transport['text'];
56
    unset($transport['type']);
57
58
    return $transport;
59
}, $transports);
60
61
$data = [['text' => 'Transports', 'children' => $transports]];
62
63
return[$data, $more];
64