Alert::user()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * app/Models/Alerting/Alert.php
4
 *
5
 * Model for access to alerts table data
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\Models\Alerting;
27
28
use Illuminate\Database\Eloquent\Builder;
29
use Illuminate\Database\Eloquent\Model;
30
31
/**
32
 * App\Models\Alerting\Alert
33
 *
34
 * @property integer $id
35
 * @property integer $device_id
36
 * @property integer $rule_id
37
 * @property integer $state
38
 * @property integer $alerted
39
 * @property integer $open
40
 * @property string $timestamp
41
 * @property-read \App\Models\Device $device
42
 * @property-read \App\Models\Alerting\Rule $rule
43
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\User[] $user
44
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Alerting\Alert whereId($value)
45
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Alerting\Alert whereDeviceId($value)
46
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Alerting\Alert whereRuleId($value)
47
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Alerting\Alert whereState($value)
48
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Alerting\Alert whereAlerted($value)
49
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Alerting\Alert whereOpen($value)
50
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Alerting\Alert whereTimestamp($value)
51
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Alerting\Alert active()
52
 * @mixin \Eloquent
53
 */
54
class Alert extends Model
55
{
56
    /**
57
     * Indicates if the model should be timestamped.
58
     *
59
     * @var bool
60
     */
61
    public $timestamps = false;
62
    /**
63
     * The table associated with the model.
64
     *
65
     * @var string
66
     */
67
    protected $table = 'alerts';
68
    /**
69
     * The primary key column name.
70
     *
71
     * @var string
72
     */
73
    protected $primaryKey = 'id';
74
75
    // ---- Query scopes ----
76
77
    /**
78
     * Only select active alerts
79
     */
80 1
    public function scopeActive(Builder $query)
81
    {
82 1
        return $query->where('state', '!=', '0');
83
    }
84
85
    // ---- Define Relationships ----
86
87
    /**
88
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
89
     */
90
    public function device()
91
    {
92
        return $this->belongsTo('App\Models\Device', 'device_id');
93
    }
94
95
    /**
96
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
97
     */
98
    public function rule()
99
    {
100
        return $this->belongsTo('App\Models\Alerting\Rule', 'rule_id', 'id');
101
    }
102
103
    /**
104
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
105
     */
106
    public function user()
107
    {
108
        return $this->belongsToMany('App\Models\User', 'devices_perms', 'device_id', 'user_id');
109
    }
110
}
111